2 * SPDX-License-Identifier: ISC
4 * Copyright (c) 2008 Sam Leffler, Errno Consulting
5 * Copyright (c) 2010 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"
26 #include "ah_eeprom_9287.h"
29 v9287EepromGet(struct ath_hal *ah, int param, void *val)
33 #define IS_VERS(op, v) ((pBase->version & AR5416_EEP_VER_MINOR_MASK) op (v))
34 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
35 const MODAL_EEP_9287_HEADER *pModal = &ee->ee_base.modalHeader;
36 const BASE_EEP_9287_HEADER *pBase = &ee->ee_base.baseEepHeader;
42 case AR_EEP_NFTHRESH_2:
43 *(int16_t *)val = pModal->noiseFloorThreshCh[0];
45 case AR_EEP_MACADDR: /* Get MAC Address */
48 for (i = 0; i < 6; i++) {
49 macaddr[i] = pBase->macAddr[i];
50 sum += pBase->macAddr[i];
52 if (sum == 0 || sum == 0xffff*3) {
53 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad mac address %s\n",
54 __func__, ath_hal_ether_sprintf(macaddr));
59 return pBase->regDmn[0];
61 return pBase->regDmn[1];
63 return pBase->deviceCap;
65 return pBase->opCapFlags;
67 return pBase->rfSilent;
72 case AR_EEP_OL_PWRCTRL:
73 HALASSERT(val == AH_NULL);
74 return pBase->openLoopPwrCntl ? HAL_OK : HAL_EIO;
76 return HAL_EIO; /* no 5GHz for Kiwi */
79 HALASSERT(val == AH_NULL);
80 return pBase->opCapFlags & AR5416_OPFLAGS_11G ?
82 case AR_EEP_32KHZCRYSTAL:
84 case AR_EEP_FASTFRAME: /* XXX policy decision, h/w can do it */
85 case AR_EEP_WRITEPROTECT: /* NB: no write protect bit */
86 HALASSERT(val == AH_NULL);
88 case AR_EEP_MAXQCU: /* NB: not in opCapFlags */
89 case AR_EEP_KCENTRIES: /* NB: not in opCapFlags */
94 case AR_EEP_TURBO5DISABLE:
95 case AR_EEP_TURBO2DISABLE:
96 HALASSERT(val == AH_NULL);
98 case AR_EEP_ANTGAINMAX_2:
99 *(int8_t *) val = ee->ee_antennaGainMax[1];
101 case AR_EEP_PWR_TABLE_OFFSET:
102 *(int8_t *) val = pBase->pwrTableOffset;
104 case AR_EEP_TEMPSENSE_SLOPE:
105 if (IS_VERS(>=, AR9287_EEP_MINOR_VER_2))
106 *(int8_t *)val = pBase->tempSensSlope;
110 case AR_EEP_TEMPSENSE_SLOPE_PAL_ON:
111 if (IS_VERS(>=, AR9287_EEP_MINOR_VER_3))
112 *(int8_t *)val = pBase->tempSensSlopePalOn;
126 v9287EepromSet(struct ath_hal *ah, int param, int v)
128 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
131 case AR_EEP_ANTGAINMAX_2:
132 ee->ee_antennaGainMax[1] = (int8_t) v;
140 v9287EepromDiag(struct ath_hal *ah, int request,
141 const void *args, uint32_t argsize, void **result, uint32_t *resultsize)
143 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
146 case HAL_DIAG_EEPROM:
148 *resultsize = sizeof(HAL_EEPROM_9287);
154 /* Do structure specific swaps if Eeprom format is non native to host */
156 eepromSwap(HAL_EEPROM_9287 *ee)
160 MODAL_EEP_9287_HEADER *pModal;
162 /* convert Base Eep header */
163 word = __bswap16(ee->ee_base.baseEepHeader.length);
164 ee->ee_base.baseEepHeader.length = word;
166 word = __bswap16(ee->ee_base.baseEepHeader.checksum);
167 ee->ee_base.baseEepHeader.checksum = word;
169 word = __bswap16(ee->ee_base.baseEepHeader.version);
170 ee->ee_base.baseEepHeader.version = word;
172 word = __bswap16(ee->ee_base.baseEepHeader.regDmn[0]);
173 ee->ee_base.baseEepHeader.regDmn[0] = word;
175 word = __bswap16(ee->ee_base.baseEepHeader.regDmn[1]);
176 ee->ee_base.baseEepHeader.regDmn[1] = word;
178 word = __bswap16(ee->ee_base.baseEepHeader.rfSilent);
179 ee->ee_base.baseEepHeader.rfSilent = word;
181 word = __bswap16(ee->ee_base.baseEepHeader.blueToothOptions);
182 ee->ee_base.baseEepHeader.blueToothOptions = word;
184 word = __bswap16(ee->ee_base.baseEepHeader.deviceCap);
185 ee->ee_base.baseEepHeader.deviceCap = word;
187 /* convert Modal Eep header */
189 /* only 2.4ghz here; so only one modal header entry */
190 pModal = &ee->ee_base.modalHeader;
192 /* XXX linux/ah_osdep.h only defines __bswap32 for BE */
193 integer = __bswap32(pModal->antCtrlCommon);
194 pModal->antCtrlCommon = integer;
196 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
197 integer = __bswap32(pModal->antCtrlChain[i]);
198 pModal->antCtrlChain[i] = integer;
200 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
201 word = __bswap16(pModal->spurChans[i].spurChan);
202 pModal->spurChans[i].spurChan = word;
207 v9287EepromGetSpurChan(struct ath_hal *ah, int ix, HAL_BOOL is2GHz)
209 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
211 HALASSERT(is2GHz == AH_TRUE);
212 if (is2GHz != AH_TRUE)
213 return 0; /* XXX ? */
215 HALASSERT(0 <= ix && ix < AR5416_EEPROM_MODAL_SPURS);
216 return ee->ee_base.modalHeader.spurChans[ix].spurChan;
219 /**************************************************************************
222 * Get channel value from binary representation held in eeprom
223 * RETURNS: the frequency in MHz
226 fbin2freq(uint8_t fbin, HAL_BOOL is2GHz)
229 * Reserved value 0xFF provides an empty definition both as
230 * an fbin and as a frequency - do not convert
232 if (fbin == AR5416_BCHAN_UNUSED)
234 return (uint16_t)((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
239 * Copy EEPROM Conformance Testing Limits contents
240 * into the allocated space
242 /* USE CTLS from chain zero */
246 v9287EepromReadCTLInfo(struct ath_hal *ah, HAL_EEPROM_9287 *ee)
248 RD_EDGES_POWER *rep = ee->ee_rdEdgesPower;
251 HALASSERT(AR9287_NUM_CTLS <= sizeof(ee->ee_rdEdgesPower)/NUM_EDGES);
253 for (i = 0; ee->ee_base.ctlIndex[i] != 0 && i < AR9287_NUM_CTLS; i++) {
254 for (j = 0; j < NUM_EDGES; j ++) {
255 /* XXX Confirm this is the right thing to do when an invalid channel is stored */
256 if (ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].bChannel == AR5416_BCHAN_UNUSED) {
258 rep[j].twice_rdEdgePower = 0;
261 rep[j].rdEdge = fbin2freq(
262 ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].bChannel,
263 (ee->ee_base.ctlIndex[i] & CTL_MODE_M) != CTL_11A);
264 rep[j].twice_rdEdgePower = MS(ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].tPowerFlag, CAL_CTL_EDGES_POWER);
265 rep[j].flag = MS(ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].tPowerFlag, CAL_CTL_EDGES_FLAG) != 0;
271 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
272 "%s Numctls = %u\n",__func__,i);
276 * Reclaim any EEPROM-related storage.
279 v9287EepromDetach(struct ath_hal *ah)
281 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
284 AH_PRIVATE(ah)->ah_eeprom = AH_NULL;
287 #define owl_get_eep_ver(_ee) \
288 (((_ee)->ee_base.baseEepHeader.version >> 12) & 0xF)
289 #define owl_get_eep_rev(_ee) \
290 (((_ee)->ee_base.baseEepHeader.version) & 0xFFF)
293 ath_hal_9287EepromAttach(struct ath_hal *ah)
295 #define NW(a) (sizeof(a) / sizeof(uint16_t))
296 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
297 uint16_t *eep_data, magic;
302 HALASSERT(ee == AH_NULL);
305 * Don't check magic if we're supplied with an EEPROM block,
306 * typically this is from Howl but it may also be from later
307 * boards w/ an embedded WMAC.
309 if (ah->ah_eepromdata == NULL) {
310 if (!ath_hal_eepromRead(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
311 HALDEBUG(ah, HAL_DEBUG_ANY,
312 "%s Error reading Eeprom MAGIC\n", __func__);
315 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s Eeprom Magic = 0x%x\n",
317 if (magic != AR5416_EEPROM_MAGIC) {
318 HALDEBUG(ah, HAL_DEBUG_ANY, "Bad magic number\n");
323 ee = ath_hal_malloc(sizeof(HAL_EEPROM_9287));
329 eep_data = (uint16_t *) ee;
330 for (w = 0; w < NW(struct ar9287_eeprom); w++) {
331 off = AR9287_EEP_START_LOC + w;
332 if (!ath_hal_eepromRead(ah, off, &eep_data[w])) {
333 HALDEBUG(ah, HAL_DEBUG_ANY,
334 "%s eeprom read error at offset 0x%x\n",
339 /* Convert to eeprom native eeprom endian format */
341 * XXX this is likely incorrect but will do for now
342 * XXX to get embedded boards working.
344 if (ah->ah_eepromdata == NULL && isBigEndian()) {
345 for (w = 0; w < NW(HAL_EEPROM_9287); w++)
346 eep_data[w] = __bswap16(eep_data[w]);
350 * At this point, we're in the native eeprom endian format
351 * Now, determine the eeprom endian by looking at byte 26??
353 need_swap = ((ee->ee_base.baseEepHeader.eepMisc & AR5416_EEPMISC_BIG_ENDIAN) != 0) ^ isBigEndian();
355 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
356 "Byte swap EEPROM contents.\n");
357 len = __bswap16(ee->ee_base.baseEepHeader.length);
359 len = ee->ee_base.baseEepHeader.length;
361 len = AH_MIN(len, sizeof(HAL_EEPROM_9287)) / sizeof(uint16_t);
363 /* Apply the checksum, done in native eeprom format */
364 /* XXX - Need to check to make sure checksum calculation is done
365 * in the correct endian format. Right now, it seems it would
366 * cast the raw data to host format and do the calculation, which may
367 * not be correct as the calculation may need to be done in the native
371 for (w = 0; w < len; w++)
373 /* Check CRC - Attach should fail on a bad checksum */
375 HALDEBUG(ah, HAL_DEBUG_ANY,
376 "Bad EEPROM checksum 0x%x (Len=%u)\n", sum, len);
381 eepromSwap(ee); /* byte swap multi-byte data */
383 /* swap words 0+2 so version is at the front */
385 eep_data[0] = eep_data[2];
388 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
389 "%s Eeprom Version %u.%u\n", __func__,
390 owl_get_eep_ver(ee), owl_get_eep_rev(ee));
392 /* NB: must be after all byte swapping */
393 if (owl_get_eep_ver(ee) != AR5416_EEP_VER) {
394 HALDEBUG(ah, HAL_DEBUG_ANY,
395 "Bad EEPROM version 0x%x\n", owl_get_eep_ver(ee));
399 v9287EepromReadCTLInfo(ah, ee); /* Get CTLs */
401 AH_PRIVATE(ah)->ah_eeprom = ee;
402 AH_PRIVATE(ah)->ah_eeversion = ee->ee_base.baseEepHeader.version;
403 AH_PRIVATE(ah)->ah_eepromDetach = v9287EepromDetach;
404 AH_PRIVATE(ah)->ah_eepromGet = v9287EepromGet;
405 AH_PRIVATE(ah)->ah_eepromSet = v9287EepromSet;
406 AH_PRIVATE(ah)->ah_getSpurChan = v9287EepromGetSpurChan;
407 AH_PRIVATE(ah)->ah_eepromDiag = v9287EepromDiag;