2 * SPDX-License-Identifier: ISC
4 * Copyright (c) 2008 Sam Leffler, Errno Consulting
5 * Copyright (c) 2008 Atheros Communications, Inc.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include "ah_internal.h"
25 #include "ah_eeprom_v14.h"
28 v14EepromGet(struct ath_hal *ah, int param, void *val)
32 #define IS_VERS(op, v) ((pBase->version & AR5416_EEP_VER_MINOR_MASK) op (v))
33 HAL_EEPROM_v14 *ee = AH_PRIVATE(ah)->ah_eeprom;
34 const MODAL_EEP_HEADER *pModal = ee->ee_base.modalHeader;
35 const BASE_EEP_HEADER *pBase = &ee->ee_base.baseEepHeader;
41 case AR_EEP_NFTHRESH_5:
42 *(int16_t *)val = pModal[0].noiseFloorThreshCh[0];
44 case AR_EEP_NFTHRESH_2:
45 *(int16_t *)val = pModal[1].noiseFloorThreshCh[0];
47 case AR_EEP_MACADDR: /* Get MAC Address */
50 for (i = 0; i < 6; i++) {
51 macaddr[i] = pBase->macAddr[i];
52 sum += pBase->macAddr[i];
54 if (sum == 0 || sum == 0xffff*3) {
55 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad mac address %s\n",
56 __func__, ath_hal_ether_sprintf(macaddr));
61 return pBase->regDmn[0];
63 return pBase->regDmn[1];
65 return pBase->deviceCap;
67 return pBase->opCapFlags;
69 return pBase->rfSilent;
71 return pModal[CHAN_A_IDX].ob;
73 return pModal[CHAN_A_IDX].db;
75 return pModal[CHAN_B_IDX].ob;
77 return pModal[CHAN_B_IDX].db;
82 case AR_EEP_RXGAIN_TYPE:
83 return IS_VERS(>=, AR5416_EEP_MINOR_VER_17) ?
84 pBase->rxGainType : AR5416_EEP_RXGAIN_ORIG;
85 case AR_EEP_TXGAIN_TYPE:
86 return IS_VERS(>=, AR5416_EEP_MINOR_VER_19) ?
87 pBase->txGainType : AR5416_EEP_TXGAIN_ORIG;
88 case AR_EEP_FSTCLK_5G:
89 /* 5ghz fastclock is always enabled for Merlin minor <= 16 */
90 if (IS_VERS(<=, AR5416_EEP_MINOR_VER_16))
92 return pBase->fastClk5g ? HAL_OK : HAL_EIO;
93 case AR_EEP_OL_PWRCTRL:
94 HALASSERT(val == AH_NULL);
95 return pBase->openLoopPwrCntl ? HAL_OK : HAL_EIO;
96 case AR_EEP_DAC_HPWR_5G:
97 if (IS_VERS(>=, AR5416_EEP_MINOR_VER_20)) {
98 *(uint8_t *) val = pBase->dacHiPwrMode_5G;
102 case AR_EEP_FRAC_N_5G:
103 if (IS_VERS(>=, AR5416_EEP_MINOR_VER_22)) {
104 *(uint8_t *) val = pBase->frac_n_5g;
106 *(uint8_t *) val = 0;
109 HALASSERT(val == AH_NULL);
110 return pBase->opCapFlags & AR5416_OPFLAGS_11A ?
114 HALASSERT(val == AH_NULL);
115 return pBase->opCapFlags & AR5416_OPFLAGS_11G ?
117 case AR_EEP_32KHZCRYSTAL:
118 case AR_EEP_COMPRESS:
119 case AR_EEP_FASTFRAME: /* XXX policy decision, h/w can do it */
120 case AR_EEP_WRITEPROTECT: /* NB: no write protect bit */
121 HALASSERT(val == AH_NULL);
123 case AR_EEP_MAXQCU: /* NB: not in opCapFlags */
124 case AR_EEP_KCENTRIES: /* NB: not in opCapFlags */
129 case AR_EEP_TURBO5DISABLE:
130 case AR_EEP_TURBO2DISABLE:
131 HALASSERT(val == AH_NULL);
133 case AR_EEP_ANTGAINMAX_2:
134 *(int8_t *) val = ee->ee_antennaGainMax[1];
136 case AR_EEP_ANTGAINMAX_5:
137 *(int8_t *) val = ee->ee_antennaGainMax[0];
139 case AR_EEP_PWR_TABLE_OFFSET:
140 if (IS_VERS(>=, AR5416_EEP_MINOR_VER_21))
141 *(int8_t *) val = pBase->pwr_table_offset;
143 *(int8_t *) val = AR5416_PWR_TABLE_OFFSET_DB;
145 case AR_EEP_PWDCLKIND:
146 if (IS_VERS(>=, AR5416_EEP_MINOR_VER_10)) {
147 *(uint8_t *) val = pBase->pwdclkind;
162 v14EepromSet(struct ath_hal *ah, int param, int v)
164 HAL_EEPROM_v14 *ee = AH_PRIVATE(ah)->ah_eeprom;
167 case AR_EEP_ANTGAINMAX_2:
168 ee->ee_antennaGainMax[1] = (int8_t) v;
170 case AR_EEP_ANTGAINMAX_5:
171 ee->ee_antennaGainMax[0] = (int8_t) v;
178 v14EepromDiag(struct ath_hal *ah, int request,
179 const void *args, uint32_t argsize, void **result, uint32_t *resultsize)
181 HAL_EEPROM_v14 *ee = AH_PRIVATE(ah)->ah_eeprom;
184 case HAL_DIAG_EEPROM:
186 *resultsize = sizeof(HAL_EEPROM_v14);
192 /* Do structure specific swaps if Eeprom format is non native to host */
194 eepromSwap(struct ar5416eeprom *ee)
196 uint32_t integer, i, j;
198 MODAL_EEP_HEADER *pModal;
200 /* convert Base Eep header */
201 word = __bswap16(ee->baseEepHeader.length);
202 ee->baseEepHeader.length = word;
204 word = __bswap16(ee->baseEepHeader.checksum);
205 ee->baseEepHeader.checksum = word;
207 word = __bswap16(ee->baseEepHeader.version);
208 ee->baseEepHeader.version = word;
210 word = __bswap16(ee->baseEepHeader.regDmn[0]);
211 ee->baseEepHeader.regDmn[0] = word;
213 word = __bswap16(ee->baseEepHeader.regDmn[1]);
214 ee->baseEepHeader.regDmn[1] = word;
216 word = __bswap16(ee->baseEepHeader.rfSilent);
217 ee->baseEepHeader.rfSilent = word;
219 word = __bswap16(ee->baseEepHeader.blueToothOptions);
220 ee->baseEepHeader.blueToothOptions = word;
222 word = __bswap16(ee->baseEepHeader.deviceCap);
223 ee->baseEepHeader.deviceCap = word;
225 /* convert Modal Eep header */
226 for (j = 0; j < 2; j++) {
227 pModal = &ee->modalHeader[j];
229 /* XXX linux/ah_osdep.h only defines __bswap32 for BE */
230 integer = __bswap32(pModal->antCtrlCommon);
231 pModal->antCtrlCommon = integer;
233 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
234 integer = __bswap32(pModal->antCtrlChain[i]);
235 pModal->antCtrlChain[i] = integer;
237 for (i = 0; i < 3; i++) {
238 word = __bswap16(pModal->xpaBiasLvlFreq[i]);
239 pModal->xpaBiasLvlFreq[i] = word;
241 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
242 word = __bswap16(pModal->spurChans[i].spurChan);
243 pModal->spurChans[i].spurChan = word;
249 v14EepromGetSpurChan(struct ath_hal *ah, int ix, HAL_BOOL is2GHz)
251 HAL_EEPROM_v14 *ee = AH_PRIVATE(ah)->ah_eeprom;
253 HALASSERT(0 <= ix && ix < AR5416_EEPROM_MODAL_SPURS);
254 return ee->ee_base.modalHeader[is2GHz].spurChans[ix].spurChan;
257 /**************************************************************************
260 * Get channel value from binary representation held in eeprom
261 * RETURNS: the frequency in MHz
264 fbin2freq(uint8_t fbin, HAL_BOOL is2GHz)
267 * Reserved value 0xFF provides an empty definition both as
268 * an fbin and as a frequency - do not convert
270 if (fbin == AR5416_BCHAN_UNUSED)
272 return (uint16_t)((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
276 * Copy EEPROM Conformance Testing Limits contents
277 * into the allocated space
279 /* USE CTLS from chain zero */
283 v14EepromReadCTLInfo(struct ath_hal *ah, HAL_EEPROM_v14 *ee)
285 RD_EDGES_POWER *rep = ee->ee_rdEdgesPower;
288 HALASSERT(AR5416_NUM_CTLS <= sizeof(ee->ee_rdEdgesPower)/NUM_EDGES);
290 for (i = 0; ee->ee_base.ctlIndex[i] != 0 && i < AR5416_NUM_CTLS; i++) {
291 for (j = 0; j < NUM_EDGES; j ++) {
292 /* XXX Confirm this is the right thing to do when an invalid channel is stored */
293 if (ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].bChannel == AR5416_BCHAN_UNUSED) {
295 rep[j].twice_rdEdgePower = 0;
298 rep[j].rdEdge = fbin2freq(
299 ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].bChannel,
300 (ee->ee_base.ctlIndex[i] & CTL_MODE_M) != CTL_11A);
301 rep[j].twice_rdEdgePower = MS(ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].tPowerFlag, CAL_CTL_EDGES_POWER);
302 rep[j].flag = MS(ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].tPowerFlag, CAL_CTL_EDGES_FLAG) != 0;
308 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
309 "%s Numctls = %u\n",__func__,i);
313 * Reclaim any EEPROM-related storage.
316 v14EepromDetach(struct ath_hal *ah)
318 HAL_EEPROM_v14 *ee = AH_PRIVATE(ah)->ah_eeprom;
321 AH_PRIVATE(ah)->ah_eeprom = AH_NULL;
324 #define owl_get_eep_ver(_ee) \
325 (((_ee)->ee_base.baseEepHeader.version >> 12) & 0xF)
326 #define owl_get_eep_rev(_ee) \
327 (((_ee)->ee_base.baseEepHeader.version) & 0xFFF)
330 * Howl is (hopefully) a special case where the endian-ness of the EEPROM
331 * matches the native endian-ness; and that supplied EEPROMs don't have
332 * a magic value to check.
335 ath_hal_v14EepromAttach(struct ath_hal *ah)
337 #define NW(a) (sizeof(a) / sizeof(uint16_t))
338 HAL_EEPROM_v14 *ee = AH_PRIVATE(ah)->ah_eeprom;
339 uint16_t *eep_data, magic;
344 HALASSERT(ee == AH_NULL);
347 * Don't check magic if we're supplied with an EEPROM block,
348 * typically this is from Howl but it may also be from later
349 * boards w/ an embedded Merlin.
351 if (ah->ah_eepromdata == NULL) {
352 if (!ath_hal_eepromRead(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
353 HALDEBUG(ah, HAL_DEBUG_ANY,
354 "%s Error reading Eeprom MAGIC\n", __func__);
357 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s Eeprom Magic = 0x%x\n",
359 if (magic != AR5416_EEPROM_MAGIC) {
360 HALDEBUG(ah, HAL_DEBUG_ANY, "Bad magic number\n");
365 ee = ath_hal_malloc(sizeof(HAL_EEPROM_v14));
371 eep_data = (uint16_t *)&ee->ee_base;
372 for (w = 0; w < NW(struct ar5416eeprom); w++) {
373 off = owl_eep_start_loc + w; /* NB: AP71 starts at 0 */
374 if (!ath_hal_eepromRead(ah, off, &eep_data[w])) {
375 HALDEBUG(ah, HAL_DEBUG_ANY,
376 "%s eeprom read error at offset 0x%x\n",
381 /* Convert to eeprom native eeprom endian format */
382 /* XXX this is likely incorrect but will do for now to get howl/ap83 working. */
383 if (ah->ah_eepromdata == NULL && isBigEndian()) {
384 for (w = 0; w < NW(struct ar5416eeprom); w++)
385 eep_data[w] = __bswap16(eep_data[w]);
389 * At this point, we're in the native eeprom endian format
390 * Now, determine the eeprom endian by looking at byte 26??
392 need_swap = ((ee->ee_base.baseEepHeader.eepMisc & AR5416_EEPMISC_BIG_ENDIAN) != 0) ^ isBigEndian();
394 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
395 "Byte swap EEPROM contents.\n");
396 len = __bswap16(ee->ee_base.baseEepHeader.length);
398 len = ee->ee_base.baseEepHeader.length;
400 len = AH_MIN(len, sizeof(struct ar5416eeprom)) / sizeof(uint16_t);
402 /* Apply the checksum, done in native eeprom format */
403 /* XXX - Need to check to make sure checksum calculation is done
404 * in the correct endian format. Right now, it seems it would
405 * cast the raw data to host format and do the calculation, which may
406 * not be correct as the calculation may need to be done in the native
410 for (w = 0; w < len; w++)
412 /* Check CRC - Attach should fail on a bad checksum */
414 HALDEBUG(ah, HAL_DEBUG_ANY,
415 "Bad EEPROM checksum 0x%x (Len=%u)\n", sum, len);
420 eepromSwap(&ee->ee_base); /* byte swap multi-byte data */
422 /* swap words 0+2 so version is at the front */
424 eep_data[0] = eep_data[2];
427 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
428 "%s Eeprom Version %u.%u\n", __func__,
429 owl_get_eep_ver(ee), owl_get_eep_rev(ee));
431 /* NB: must be after all byte swapping */
432 if (owl_get_eep_ver(ee) != AR5416_EEP_VER) {
433 HALDEBUG(ah, HAL_DEBUG_ANY,
434 "Bad EEPROM version 0x%x\n", owl_get_eep_ver(ee));
438 v14EepromReadCTLInfo(ah, ee); /* Get CTLs */
440 AH_PRIVATE(ah)->ah_eeprom = ee;
441 AH_PRIVATE(ah)->ah_eeversion = ee->ee_base.baseEepHeader.version;
442 AH_PRIVATE(ah)->ah_eepromDetach = v14EepromDetach;
443 AH_PRIVATE(ah)->ah_eepromGet = v14EepromGet;
444 AH_PRIVATE(ah)->ah_eepromSet = v14EepromSet;
445 AH_PRIVATE(ah)->ah_getSpurChan = v14EepromGetSpurChan;
446 AH_PRIVATE(ah)->ah_eepromDiag = v14EepromDiag;