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 IS_VERS(>=, AR5416_EEP_MINOR_VER_19) ?
79 pBase->txGainType : AR5416_EEP_TXGAIN_ORIG;
80 case AR_EEP_OL_PWRCTRL:
81 HALASSERT(val == AH_NULL);
84 HALASSERT(val == AH_NULL);
85 return pBase->opCapFlags & AR5416_OPFLAGS_11A ?
89 HALASSERT(val == AH_NULL);
90 return pBase->opCapFlags & AR5416_OPFLAGS_11G ?
92 case AR_EEP_32KHZCRYSTAL:
94 case AR_EEP_FASTFRAME: /* XXX policy decision, h/w can do it */
95 case AR_EEP_WRITEPROTECT: /* NB: no write protect bit */
96 HALASSERT(val == AH_NULL);
98 case AR_EEP_MAXQCU: /* NB: not in opCapFlags */
99 case AR_EEP_KCENTRIES: /* NB: not in opCapFlags */
104 case AR_EEP_TURBO2DISABLE:
105 HALASSERT(val == AH_NULL);
107 case AR_EEP_ANTGAINMAX_2:
108 *(int8_t *) val = ee->ee_antennaGainMax;
120 v4kEepromSet(struct ath_hal *ah, int param, int v)
122 HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
125 case AR_EEP_ANTGAINMAX_2:
126 ee->ee_antennaGainMax = (int8_t) v;
133 v4kEepromDiag(struct ath_hal *ah, int request,
134 const void *args, uint32_t argsize, void **result, uint32_t *resultsize)
136 HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
139 case HAL_DIAG_EEPROM:
140 *result = &ee->ee_base;
141 *resultsize = sizeof(ee->ee_base);
147 /* Do structure specific swaps if Eeprom format is non native to host */
149 eepromSwap(struct ar5416eeprom_4k *ee)
153 MODAL_EEP4K_HEADER *pModal;
155 /* convert Base Eep header */
156 word = __bswap16(ee->baseEepHeader.length);
157 ee->baseEepHeader.length = word;
159 word = __bswap16(ee->baseEepHeader.checksum);
160 ee->baseEepHeader.checksum = word;
162 word = __bswap16(ee->baseEepHeader.version);
163 ee->baseEepHeader.version = word;
165 word = __bswap16(ee->baseEepHeader.regDmn[0]);
166 ee->baseEepHeader.regDmn[0] = word;
168 word = __bswap16(ee->baseEepHeader.regDmn[1]);
169 ee->baseEepHeader.regDmn[1] = word;
171 word = __bswap16(ee->baseEepHeader.rfSilent);
172 ee->baseEepHeader.rfSilent = word;
174 word = __bswap16(ee->baseEepHeader.blueToothOptions);
175 ee->baseEepHeader.blueToothOptions = word;
177 word = __bswap16(ee->baseEepHeader.deviceCap);
178 ee->baseEepHeader.deviceCap = word;
180 /* convert Modal Eep header */
181 pModal = &ee->modalHeader;
183 /* XXX linux/ah_osdep.h only defines __bswap32 for BE */
184 integer = __bswap32(pModal->antCtrlCommon);
185 pModal->antCtrlCommon = integer;
187 for (i = 0; i < AR5416_4K_MAX_CHAINS; i++) {
188 integer = __bswap32(pModal->antCtrlChain[i]);
189 pModal->antCtrlChain[i] = integer;
192 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
193 word = __bswap16(pModal->spurChans[i].spurChan);
194 pModal->spurChans[i].spurChan = word;
199 v4kEepromGetSpurChan(struct ath_hal *ah, int ix, HAL_BOOL is2GHz)
201 HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
203 HALASSERT(0 <= ix && ix < AR5416_EEPROM_MODAL_SPURS);
205 return ee->ee_base.modalHeader.spurChans[ix].spurChan;
208 /**************************************************************************
211 * Get channel value from binary representation held in eeprom
212 * RETURNS: the frequency in MHz
215 fbin2freq(uint8_t fbin, HAL_BOOL is2GHz)
218 * Reserved value 0xFF provides an empty definition both as
219 * an fbin and as a frequency - do not convert
221 if (fbin == AR5416_BCHAN_UNUSED)
223 return (uint16_t)((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
227 * Copy EEPROM Conformance Testing Limits contents
228 * into the allocated space
230 /* USE CTLS from chain zero */
234 v4kEepromReadCTLInfo(struct ath_hal *ah, HAL_EEPROM_v4k *ee)
236 RD_EDGES_POWER *rep = ee->ee_rdEdgesPower;
239 HALASSERT(AR5416_4K_NUM_CTLS <= sizeof(ee->ee_rdEdgesPower)/NUM_EDGES);
241 for (i = 0; ee->ee_base.ctlIndex[i] != 0 && i < AR5416_4K_NUM_CTLS; i++) {
242 for (j = 0; j < NUM_EDGES; j ++) {
243 /* XXX Confirm this is the right thing to do when an invalid channel is stored */
244 if (ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].bChannel == AR5416_BCHAN_UNUSED) {
246 rep[j].twice_rdEdgePower = 0;
249 rep[j].rdEdge = fbin2freq(
250 ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].bChannel,
251 (ee->ee_base.ctlIndex[i] & CTL_MODE_M) != CTL_11A);
252 rep[j].twice_rdEdgePower = MS(ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].tPowerFlag, CAL_CTL_EDGES_POWER);
253 rep[j].flag = MS(ee->ee_base.ctlData[i].ctlEdges[CTL_CHAIN][j].tPowerFlag, CAL_CTL_EDGES_FLAG) != 0;
259 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
260 "%s Numctls = %u\n",__func__,i);
264 * Reclaim any EEPROM-related storage.
267 v4kEepromDetach(struct ath_hal *ah)
269 HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
272 AH_PRIVATE(ah)->ah_eeprom = AH_NULL;
275 #define owl_get_eep_ver(_ee) \
276 (((_ee)->ee_base.baseEepHeader.version >> 12) & 0xF)
277 #define owl_get_eep_rev(_ee) \
278 (((_ee)->ee_base.baseEepHeader.version) & 0xFFF)
281 ath_hal_v4kEepromAttach(struct ath_hal *ah)
283 #define NW(a) (sizeof(a) / sizeof(uint16_t))
284 HAL_EEPROM_v4k *ee = AH_PRIVATE(ah)->ah_eeprom;
285 uint16_t *eep_data, magic;
290 HALASSERT(ee == AH_NULL);
292 if (!ath_hal_eepromRead(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
293 HALDEBUG(ah, HAL_DEBUG_ANY,
294 "%s Error reading Eeprom MAGIC\n", __func__);
297 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s Eeprom Magic = 0x%x\n",
299 if (magic != AR5416_EEPROM_MAGIC) {
300 HALDEBUG(ah, HAL_DEBUG_ANY, "Bad magic number\n");
304 ee = ath_hal_malloc(sizeof(HAL_EEPROM_v4k));
310 eep_data = (uint16_t *)&ee->ee_base;
311 for (w = 0; w < NW(struct ar5416eeprom_4k); w++) {
312 off = owl_eep_start_loc + w; /* NB: AP71 starts at 0 */
313 if (!ath_hal_eepromRead(ah, off, &eep_data[w])) {
314 HALDEBUG(ah, HAL_DEBUG_ANY,
315 "%s eeprom read error at offset 0x%x\n",
320 /* Convert to eeprom native eeprom endian format */
322 for (w = 0; w < NW(struct ar5416eeprom_4k); w++)
323 eep_data[w] = __bswap16(eep_data[w]);
327 * At this point, we're in the native eeprom endian format
328 * Now, determine the eeprom endian by looking at byte 26??
330 need_swap = ((ee->ee_base.baseEepHeader.eepMisc & AR5416_EEPMISC_BIG_ENDIAN) != 0) ^ isBigEndian();
332 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
333 "Byte swap EEPROM contents.\n");
334 len = __bswap16(ee->ee_base.baseEepHeader.length);
336 len = ee->ee_base.baseEepHeader.length;
338 len = AH_MIN(len, sizeof(struct ar5416eeprom_4k)) / sizeof(uint16_t);
340 /* Apply the checksum, done in native eeprom format */
341 /* XXX - Need to check to make sure checksum calculation is done
342 * in the correct endian format. Right now, it seems it would
343 * cast the raw data to host format and do the calculation, which may
344 * not be correct as the calculation may need to be done in the native
348 for (w = 0; w < len; w++) {
351 /* Check CRC - Attach should fail on a bad checksum */
353 HALDEBUG(ah, HAL_DEBUG_ANY,
354 "Bad EEPROM checksum 0x%x (Len=%u)\n", sum, len);
359 eepromSwap(&ee->ee_base); /* byte swap multi-byte data */
361 /* swap words 0+2 so version is at the front */
363 eep_data[0] = eep_data[2];
366 HALDEBUG(ah, HAL_DEBUG_ATTACH | HAL_DEBUG_EEPROM,
367 "%s Eeprom Version %u.%u\n", __func__,
368 owl_get_eep_ver(ee), owl_get_eep_rev(ee));
370 /* NB: must be after all byte swapping */
371 if (owl_get_eep_ver(ee) != AR5416_EEP_VER) {
372 HALDEBUG(ah, HAL_DEBUG_ANY,
373 "Bad EEPROM version 0x%x\n", owl_get_eep_ver(ee));
377 v4kEepromReadCTLInfo(ah, ee); /* Get CTLs */
379 AH_PRIVATE(ah)->ah_eeprom = ee;
380 AH_PRIVATE(ah)->ah_eeversion = ee->ee_base.baseEepHeader.version;
381 AH_PRIVATE(ah)->ah_eepromDetach = v4kEepromDetach;
382 AH_PRIVATE(ah)->ah_eepromGet = v4kEepromGet;
383 AH_PRIVATE(ah)->ah_eepromSet = v4kEepromSet;
384 AH_PRIVATE(ah)->ah_getSpurChan = v4kEepromGetSpurChan;
385 AH_PRIVATE(ah)->ah_eepromDiag = v4kEepromDiag;