2 * Copyright (c) 2009 Rui Paulo <rpaulo@FreeBSD.org>
3 * Copyright (c) 2008 Sam Leffler, Errno Consulting
4 * Copyright (c) 2008 Atheros Communications, Inc.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 #include "ah_internal.h"
24 #include "ah_eeprom_v14.h"
25 #include "ah_eeprom_v4k.h"
28 v4kEepromGet(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_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
34 const MODAL_EEP4K_HEADER *pModal = &ee->ee_base.modalHeader;
35 const BASE_EEP4K_HEADER *pBase = &ee->ee_base.baseEepHeader;
41 case AR_EEP_NFTHRESH_2:
42 *(int16_t *)val = pModal->noiseFloorThreshCh[0];
44 case AR_EEP_MACADDR: /* Get MAC Address */
47 for (i = 0; i < 6; i++) {
48 macaddr[i] = pBase->macAddr[i];
49 sum += pBase->macAddr[i];
51 if (sum == 0 || sum == 0xffff*3) {
52 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad mac address %s\n",
53 __func__, ath_hal_ether_sprintf(macaddr));
58 return pBase->regDmn[0];
60 return pBase->regDmn[1];
62 return pBase->deviceCap;
64 return pBase->opCapFlags;
66 return pBase->rfSilent;
75 case AR_EEP_RXGAIN_TYPE:
76 return AR5416_EEP_RXGAIN_ORIG;
77 case AR_EEP_TXGAIN_TYPE:
78 return pBase->txGainType;
79 case AR_EEP_OL_PWRCTRL:
80 HALASSERT(val == AH_NULL);
83 HALASSERT(val == AH_NULL);
84 return pBase->opCapFlags & AR5416_OPFLAGS_11A ?
88 HALASSERT(val == AH_NULL);
89 return pBase->opCapFlags & AR5416_OPFLAGS_11G ?
91 case AR_EEP_32KHZCRYSTAL:
93 case AR_EEP_FASTFRAME: /* XXX policy decision, h/w can do it */
94 case AR_EEP_WRITEPROTECT: /* NB: no write protect bit */
95 HALASSERT(val == AH_NULL);
97 case AR_EEP_MAXQCU: /* NB: not in opCapFlags */
98 case AR_EEP_KCENTRIES: /* NB: not in opCapFlags */
103 case AR_EEP_TURBO2DISABLE:
104 HALASSERT(val == AH_NULL);
106 case AR_EEP_ANTGAINMAX_2:
107 *(int8_t *) val = ee->ee_antennaGainMax;
119 v4kEepromSet(struct ath_hal *ah, int param, int v)
121 HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
124 case AR_EEP_ANTGAINMAX_2:
125 ee->ee_antennaGainMax = (int8_t) v;
132 v4kEepromDiag(struct ath_hal *ah, int request,
133 const void *args, uint32_t argsize, void **result, uint32_t *resultsize)
135 HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
138 case HAL_DIAG_EEPROM:
140 *resultsize = sizeof(HAL_EEPROM_v4k);
146 /* Do structure specific swaps if Eeprom format is non native to host */
148 eepromSwap(struct ar5416eeprom_4k *ee)
152 MODAL_EEP4K_HEADER *pModal;
154 /* convert Base Eep header */
155 word = __bswap16(ee->baseEepHeader.length);
156 ee->baseEepHeader.length = word;
158 word = __bswap16(ee->baseEepHeader.checksum);
159 ee->baseEepHeader.checksum = word;
161 word = __bswap16(ee->baseEepHeader.version);
162 ee->baseEepHeader.version = word;
164 word = __bswap16(ee->baseEepHeader.regDmn[0]);
165 ee->baseEepHeader.regDmn[0] = word;
167 word = __bswap16(ee->baseEepHeader.regDmn[1]);
168 ee->baseEepHeader.regDmn[1] = word;
170 word = __bswap16(ee->baseEepHeader.rfSilent);
171 ee->baseEepHeader.rfSilent = word;
173 word = __bswap16(ee->baseEepHeader.blueToothOptions);
174 ee->baseEepHeader.blueToothOptions = word;
176 word = __bswap16(ee->baseEepHeader.deviceCap);
177 ee->baseEepHeader.deviceCap = word;
179 /* convert Modal Eep header */
180 pModal = &ee->modalHeader;
182 /* XXX linux/ah_osdep.h only defines __bswap32 for BE */
183 integer = __bswap32(pModal->antCtrlCommon);
184 pModal->antCtrlCommon = integer;
186 for (i = 0; i < AR5416_4K_MAX_CHAINS; i++) {
187 integer = __bswap32(pModal->antCtrlChain[i]);
188 pModal->antCtrlChain[i] = integer;
191 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
192 word = __bswap16(pModal->spurChans[i].spurChan);
193 pModal->spurChans[i].spurChan = word;
198 v4kEepromGetSpurChan(struct ath_hal *ah, int ix, HAL_BOOL is2GHz)
200 HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
202 HALASSERT(0 <= ix && ix < AR5416_EEPROM_MODAL_SPURS);
204 return ee->ee_base.modalHeader.spurChans[ix].spurChan;
207 /**************************************************************************
210 * Get channel value from binary representation held in eeprom
211 * RETURNS: the frequency in MHz
214 fbin2freq(uint8_t fbin, HAL_BOOL is2GHz)
217 * Reserved value 0xFF provides an empty definition both as
218 * an fbin and as a frequency - do not convert
220 if (fbin == AR5416_BCHAN_UNUSED)
222 return (uint16_t)((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
226 * Copy EEPROM Conformance Testing Limits contents
227 * into the allocated space
229 /* USE CTLS from chain zero */
233 v4kEepromReadCTLInfo(struct ath_hal *ah, HAL_EEPROM_v4k *ee)
235 RD_EDGES_POWER *rep = ee->ee_rdEdgesPower;
238 HALASSERT(AR5416_4K_NUM_CTLS <= sizeof(ee->ee_rdEdgesPower)/NUM_EDGES);
240 for (i = 0; ee->ee_base.ctlIndex[i] != 0 && i < AR5416_4K_NUM_CTLS; i++) {
241 for (j = 0; j < NUM_EDGES; j ++) {
242 /* XXX Confirm this is the right thing to do when an invalid channel is stored */
243 if (ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].bChannel == AR5416_BCHAN_UNUSED) {
245 rep[j].twice_rdEdgePower = 0;
248 rep[j].rdEdge = fbin2freq(
249 ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].bChannel,
250 (ee->ee_base.ctlIndex[i] & CTL_MODE_M) != CTL_11A);
251 rep[j].twice_rdEdgePower = MS(ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].tPowerFlag, CAL_CTL_EDGES_POWER);
252 rep[j].flag = MS(ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].tPowerFlag, CAL_CTL_EDGES_FLAG) != 0;
258 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
259 "%s Numctls = %u\n",__func__,i);
263 * Reclaim any EEPROM-related storage.
266 v4kEepromDetach(struct ath_hal *ah)
268 HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
271 AH_PRIVATE(ah)->ah_eeprom = AH_NULL;
274 #define owl_get_eep_ver(_ee) \
275 (((_ee)->ee_base.baseEepHeader.version >> 12) & 0xF)
276 #define owl_get_eep_rev(_ee) \
277 (((_ee)->ee_base.baseEepHeader.version) & 0xFFF)
280 ath_hal_v4kEepromAttach(struct ath_hal *ah)
282 #define NW(a) (sizeof(a) / sizeof(uint16_t))
283 HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
284 uint16_t *eep_data, magic;
289 HALASSERT(ee == AH_NULL);
291 * Don't check magic if we're supplied with an EEPROM block,
292 * typically this is from Howl but it may also be from later
293 * boards w/ an embedded WMAC.
295 if (ah->ah_eepromdata == NULL) {
296 if (!ath_hal_eepromRead(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
297 HALDEBUG(ah, HAL_DEBUG_ANY,
298 "%s Error reading Eeprom MAGIC\n", __func__);
301 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s Eeprom Magic = 0x%x\n",
303 if (magic != AR5416_EEPROM_MAGIC) {
304 HALDEBUG(ah, HAL_DEBUG_ANY, "Bad magic number\n");
309 ee = ath_hal_malloc(sizeof(HAL_EEPROM_v4k));
315 eep_data = (uint16_t *)&ee->ee_base;
316 for (w = 0; w < NW(struct ar5416eeprom_4k); w++) {
317 off = owl_eep_start_loc + w; /* NB: AP71 starts at 0 */
318 if (!ath_hal_eepromRead(ah, off, &eep_data[w])) {
319 HALDEBUG(ah, HAL_DEBUG_ANY,
320 "%s eeprom read error at offset 0x%x\n",
325 /* Convert to eeprom native eeprom endian format */
327 * XXX this is likely incorrect but will do for now
328 * XXX to get embedded boards working.
330 if (ah->ah_eepromdata == NULL && isBigEndian()) {
331 for (w = 0; w < NW(struct ar5416eeprom_4k); w++)
332 eep_data[w] = __bswap16(eep_data[w]);
336 * At this point, we're in the native eeprom endian format
337 * Now, determine the eeprom endian by looking at byte 26??
339 need_swap = ((ee->ee_base.baseEepHeader.eepMisc & AR5416_EEPMISC_BIG_ENDIAN) != 0) ^ isBigEndian();
341 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
342 "Byte swap EEPROM contents.\n");
343 len = __bswap16(ee->ee_base.baseEepHeader.length);
345 len = ee->ee_base.baseEepHeader.length;
347 len = AH_MIN(len, sizeof(struct ar5416eeprom_4k)) / sizeof(uint16_t);
349 /* Apply the checksum, done in native eeprom format */
350 /* XXX - Need to check to make sure checksum calculation is done
351 * in the correct endian format. Right now, it seems it would
352 * cast the raw data to host format and do the calculation, which may
353 * not be correct as the calculation may need to be done in the native
357 for (w = 0; w < len; w++) {
360 /* Check CRC - Attach should fail on a bad checksum */
362 HALDEBUG(ah, HAL_DEBUG_ANY,
363 "Bad EEPROM checksum 0x%x (Len=%u)\n", sum, len);
368 eepromSwap(&ee->ee_base); /* byte swap multi-byte data */
370 /* swap words 0+2 so version is at the front */
372 eep_data[0] = eep_data[2];
375 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
376 "%s Eeprom Version %u.%u\n", __func__,
377 owl_get_eep_ver(ee), owl_get_eep_rev(ee));
379 /* NB: must be after all byte swapping */
380 if (owl_get_eep_ver(ee) != AR5416_EEP_VER) {
381 HALDEBUG(ah, HAL_DEBUG_ANY,
382 "Bad EEPROM version 0x%x\n", owl_get_eep_ver(ee));
386 v4kEepromReadCTLInfo(ah, ee); /* Get CTLs */
388 AH_PRIVATE(ah)->ah_eeprom = ee;
389 AH_PRIVATE(ah)->ah_eeversion = ee->ee_base.baseEepHeader.version;
390 AH_PRIVATE(ah)->ah_eepromDetach = v4kEepromDetach;
391 AH_PRIVATE(ah)->ah_eepromGet = v4kEepromGet;
392 AH_PRIVATE(ah)->ah_eepromSet = v4kEepromSet;
393 AH_PRIVATE(ah)->ah_getSpurChan = v4kEepromGetSpurChan;
394 AH_PRIVATE(ah)->ah_eepromDiag = v4kEepromDiag;