2 * Copyright (c) 2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2010 Atheros Communications, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "ah_internal.h"
23 #include "ah_eeprom_v14.h"
24 #include "ah_eeprom_9287.h"
27 v9287EepromGet(struct ath_hal *ah, int param, void *val)
31 #define IS_VERS(op, v) ((pBase->version & AR5416_EEP_VER_MINOR_MASK) op (v))
32 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
33 const MODAL_EEP_9287_HEADER *pModal = &ee->ee_base.modalHeader;
34 const BASE_EEP_9287_HEADER *pBase = &ee->ee_base.baseEepHeader;
40 case AR_EEP_NFTHRESH_2:
41 *(int16_t *)val = pModal->noiseFloorThreshCh[0];
43 case AR_EEP_MACADDR: /* Get MAC Address */
46 for (i = 0; i < 6; i++) {
47 macaddr[i] = pBase->macAddr[i];
48 sum += pBase->macAddr[i];
50 if (sum == 0 || sum == 0xffff*3) {
51 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad mac address %s\n",
52 __func__, ath_hal_ether_sprintf(macaddr));
57 return pBase->regDmn[0];
59 return pBase->regDmn[1];
61 return pBase->deviceCap;
63 return pBase->opCapFlags;
65 return pBase->rfSilent;
70 case AR_EEP_OL_PWRCTRL:
71 HALASSERT(val == AH_NULL);
72 return pBase->openLoopPwrCntl ? HAL_OK : HAL_EIO;
74 return HAL_EIO; /* no 5GHz for Kiwi */
77 HALASSERT(val == AH_NULL);
78 return pBase->opCapFlags & AR5416_OPFLAGS_11G ?
80 case AR_EEP_32KHZCRYSTAL:
82 case AR_EEP_FASTFRAME: /* XXX policy decision, h/w can do it */
83 case AR_EEP_WRITEPROTECT: /* NB: no write protect bit */
84 HALASSERT(val == AH_NULL);
86 case AR_EEP_MAXQCU: /* NB: not in opCapFlags */
87 case AR_EEP_KCENTRIES: /* NB: not in opCapFlags */
92 case AR_EEP_TURBO5DISABLE:
93 case AR_EEP_TURBO2DISABLE:
94 HALASSERT(val == AH_NULL);
96 case AR_EEP_ANTGAINMAX_2:
97 *(int8_t *) val = ee->ee_antennaGainMax[1];
99 case AR_EEP_PWR_TABLE_OFFSET:
100 *(int8_t *) val = pBase->pwrTableOffset;
102 case AR_EEP_TEMPSENSE_SLOPE:
103 if (IS_VERS(>=, AR9287_EEP_MINOR_VER_2))
104 *(int8_t *)val = pBase->tempSensSlope;
108 case AR_EEP_TEMPSENSE_SLOPE_PAL_ON:
109 if (IS_VERS(>=, AR9287_EEP_MINOR_VER_3))
110 *(int8_t *)val = pBase->tempSensSlopePalOn;
124 v9287EepromSet(struct ath_hal *ah, int param, int v)
126 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
129 case AR_EEP_ANTGAINMAX_2:
130 ee->ee_antennaGainMax[1] = (int8_t) v;
138 v9287EepromDiag(struct ath_hal *ah, int request,
139 const void *args, uint32_t argsize, void **result, uint32_t *resultsize)
141 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
144 case HAL_DIAG_EEPROM:
146 *resultsize = sizeof(HAL_EEPROM_9287);
152 /* Do structure specific swaps if Eeprom format is non native to host */
154 eepromSwap(HAL_EEPROM_9287 *ee)
158 MODAL_EEP_9287_HEADER *pModal;
160 /* convert Base Eep header */
161 word = __bswap16(ee->ee_base.baseEepHeader.length);
162 ee->ee_base.baseEepHeader.length = word;
164 word = __bswap16(ee->ee_base.baseEepHeader.checksum);
165 ee->ee_base.baseEepHeader.checksum = word;
167 word = __bswap16(ee->ee_base.baseEepHeader.version);
168 ee->ee_base.baseEepHeader.version = word;
170 word = __bswap16(ee->ee_base.baseEepHeader.regDmn[0]);
171 ee->ee_base.baseEepHeader.regDmn[0] = word;
173 word = __bswap16(ee->ee_base.baseEepHeader.regDmn[1]);
174 ee->ee_base.baseEepHeader.regDmn[1] = word;
176 word = __bswap16(ee->ee_base.baseEepHeader.rfSilent);
177 ee->ee_base.baseEepHeader.rfSilent = word;
179 word = __bswap16(ee->ee_base.baseEepHeader.blueToothOptions);
180 ee->ee_base.baseEepHeader.blueToothOptions = word;
182 word = __bswap16(ee->ee_base.baseEepHeader.deviceCap);
183 ee->ee_base.baseEepHeader.deviceCap = word;
185 /* convert Modal Eep header */
187 /* only 2.4ghz here; so only one modal header entry */
188 pModal = &ee->ee_base.modalHeader;
190 /* XXX linux/ah_osdep.h only defines __bswap32 for BE */
191 integer = __bswap32(pModal->antCtrlCommon);
192 pModal->antCtrlCommon = integer;
194 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
195 integer = __bswap32(pModal->antCtrlChain[i]);
196 pModal->antCtrlChain[i] = integer;
198 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
199 word = __bswap16(pModal->spurChans[i].spurChan);
200 pModal->spurChans[i].spurChan = word;
205 v9287EepromGetSpurChan(struct ath_hal *ah, int ix, HAL_BOOL is2GHz)
207 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
209 HALASSERT(is2GHz == AH_TRUE);
210 if (is2GHz != AH_TRUE)
211 return 0; /* XXX ? */
213 HALASSERT(0 <= ix && ix < AR5416_EEPROM_MODAL_SPURS);
214 return ee->ee_base.modalHeader.spurChans[ix].spurChan;
217 /**************************************************************************
220 * Get channel value from binary representation held in eeprom
221 * RETURNS: the frequency in MHz
224 fbin2freq(uint8_t fbin, HAL_BOOL is2GHz)
227 * Reserved value 0xFF provides an empty definition both as
228 * an fbin and as a frequency - do not convert
230 if (fbin == AR5416_BCHAN_UNUSED)
232 return (uint16_t)((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
237 * Copy EEPROM Conformance Testing Limits contents
238 * into the allocated space
240 /* USE CTLS from chain zero */
244 v9287EepromReadCTLInfo(struct ath_hal *ah, HAL_EEPROM_9287 *ee)
246 RD_EDGES_POWER *rep = ee->ee_rdEdgesPower;
249 HALASSERT(AR9287_NUM_CTLS <= sizeof(ee->ee_rdEdgesPower)/NUM_EDGES);
251 for (i = 0; ee->ee_base.ctlIndex[i] != 0 && i < AR9287_NUM_CTLS; i++) {
252 for (j = 0; j < NUM_EDGES; j ++) {
253 /* XXX Confirm this is the right thing to do when an invalid channel is stored */
254 if (ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].bChannel == AR5416_BCHAN_UNUSED) {
256 rep[j].twice_rdEdgePower = 0;
259 rep[j].rdEdge = fbin2freq(
260 ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].bChannel,
261 (ee->ee_base.ctlIndex[i] & CTL_MODE_M) != CTL_11A);
262 rep[j].twice_rdEdgePower = MS(ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].tPowerFlag, CAL_CTL_EDGES_POWER);
263 rep[j].flag = MS(ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].tPowerFlag, CAL_CTL_EDGES_FLAG) != 0;
269 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
270 "%s Numctls = %u\n",__func__,i);
274 * Reclaim any EEPROM-related storage.
277 v9287EepromDetach(struct ath_hal *ah)
279 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
282 AH_PRIVATE(ah)->ah_eeprom = AH_NULL;
285 #define owl_get_eep_ver(_ee) \
286 (((_ee)->ee_base.baseEepHeader.version >> 12) & 0xF)
287 #define owl_get_eep_rev(_ee) \
288 (((_ee)->ee_base.baseEepHeader.version) & 0xFFF)
291 ath_hal_9287EepromAttach(struct ath_hal *ah)
293 #define NW(a) (sizeof(a) / sizeof(uint16_t))
294 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
295 uint16_t *eep_data, magic;
300 HALASSERT(ee == AH_NULL);
303 * Don't check magic if we're supplied with an EEPROM block,
304 * typically this is from Howl but it may also be from later
305 * boards w/ an embedded WMAC.
307 if (ah->ah_eepromdata == NULL) {
308 if (!ath_hal_eepromRead(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
309 HALDEBUG(ah, HAL_DEBUG_ANY,
310 "%s Error reading Eeprom MAGIC\n", __func__);
314 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s Eeprom Magic = 0x%x\n",
316 if (magic != AR5416_EEPROM_MAGIC) {
317 HALDEBUG(ah, HAL_DEBUG_ANY, "Bad magic number\n");
321 ee = ath_hal_malloc(sizeof(HAL_EEPROM_9287));
327 eep_data = (uint16_t *) ee;
328 for (w = 0; w < NW(struct ar9287_eeprom); w++) {
329 off = AR9287_EEP_START_LOC + w;
330 if (!ath_hal_eepromRead(ah, off, &eep_data[w])) {
331 HALDEBUG(ah, HAL_DEBUG_ANY,
332 "%s eeprom read error at offset 0x%x\n",
337 /* Convert to eeprom native eeprom endian format */
339 * XXX this is likely incorrect but will do for now
340 * XXX to get embedded boards working.
342 if (ah->ah_eepromdata == NULL && isBigEndian()) {
343 for (w = 0; w < NW(HAL_EEPROM_9287); w++)
344 eep_data[w] = __bswap16(eep_data[w]);
348 * At this point, we're in the native eeprom endian format
349 * Now, determine the eeprom endian by looking at byte 26??
351 need_swap = ((ee->ee_base.baseEepHeader.eepMisc & AR5416_EEPMISC_BIG_ENDIAN) != 0) ^ isBigEndian();
353 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
354 "Byte swap EEPROM contents.\n");
355 len = __bswap16(ee->ee_base.baseEepHeader.length);
357 len = ee->ee_base.baseEepHeader.length;
359 len = AH_MIN(len, sizeof(HAL_EEPROM_9287)) / sizeof(uint16_t);
361 /* Apply the checksum, done in native eeprom format */
362 /* XXX - Need to check to make sure checksum calculation is done
363 * in the correct endian format. Right now, it seems it would
364 * cast the raw data to host format and do the calculation, which may
365 * not be correct as the calculation may need to be done in the native
369 for (w = 0; w < len; w++)
371 /* Check CRC - Attach should fail on a bad checksum */
373 HALDEBUG(ah, HAL_DEBUG_ANY,
374 "Bad EEPROM checksum 0x%x (Len=%u)\n", sum, len);
379 eepromSwap(ee); /* byte swap multi-byte data */
381 /* swap words 0+2 so version is at the front */
383 eep_data[0] = eep_data[2];
386 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
387 "%s Eeprom Version %u.%u\n", __func__,
388 owl_get_eep_ver(ee), owl_get_eep_rev(ee));
390 /* NB: must be after all byte swapping */
391 if (owl_get_eep_ver(ee) != AR5416_EEP_VER) {
392 HALDEBUG(ah, HAL_DEBUG_ANY,
393 "Bad EEPROM version 0x%x\n", owl_get_eep_ver(ee));
397 v9287EepromReadCTLInfo(ah, ee); /* Get CTLs */
399 AH_PRIVATE(ah)->ah_eeprom = ee;
400 AH_PRIVATE(ah)->ah_eeversion = ee->ee_base.baseEepHeader.version;
401 AH_PRIVATE(ah)->ah_eepromDetach = v9287EepromDetach;
402 AH_PRIVATE(ah)->ah_eepromGet = v9287EepromGet;
403 AH_PRIVATE(ah)->ah_eepromSet = v9287EepromSet;
404 AH_PRIVATE(ah)->ah_getSpurChan = v9287EepromGetSpurChan;
405 AH_PRIVATE(ah)->ah_eepromDiag = v9287EepromDiag;