2 * Copyright (c) 2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2008 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.
17 * $Id: ah_eeprom_v1.c,v 1.4 2008/12/12 21:31:49 alc Exp $
22 #include "ah_internal.h"
23 #include "ah_eeprom_v1.h"
26 v1EepromGet(struct ath_hal
*ah
, int param
, void *val
)
28 HAL_EEPROM_v1
*ee
= AH_PRIVATE(ah
)->ah_eeprom
;
35 case AR_EEP_MACADDR
: /* Get MAC Address */
38 for (i
= 0; i
< 3; i
++) {
39 if (!ath_hal_eepromRead(ah
, AR_EEPROM_MAC(i
), &eeval
)) {
40 HALDEBUG(ah
, HAL_DEBUG_ANY
,
41 "%s: cannot read EEPROM location %u\n",
46 macaddr
[2*i
+ 0] = eeval
>> 8;
47 macaddr
[2*i
+ 1] = eeval
& 0xff;
49 if (sum
== 0 || sum
== 0xffff*3) {
50 HALDEBUG(ah
, HAL_DEBUG_ANY
, "%s: bad mac address %s\n",
51 __func__
, ath_hal_ether_sprintf(macaddr
));
56 *(uint16_t *) val
= ee
->ee_regDomain
[0];
59 HALASSERT(val
== AH_NULL
);
60 return ee
->ee_rfKill
? HAL_OK
: HAL_EIO
;
61 case AR_EEP_WRITEPROTECT
:
62 HALASSERT(val
== AH_NULL
);
63 return (ee
->ee_protect
& AR_EEPROM_PROTOTECT_WP_128_191
) ?
72 v1EepromSet(struct ath_hal
*ah
, int param
, int v
)
78 v1EepromDiag(struct ath_hal
*ah
, int request
,
79 const void *args
, uint32_t argsize
, void **result
, uint32_t *resultsize
)
81 HAL_EEPROM_v1
*ee
= AH_PRIVATE(ah
)->ah_eeprom
;
86 *resultsize
= sizeof(*ee
);
93 v1EepromGetSpurChan(struct ath_hal
*ah
, int ix
, HAL_BOOL is2GHz
)
99 * Reclaim any EEPROM-related storage.
102 v1EepromDetach(struct ath_hal
*ah
)
104 HAL_EEPROM_v1
*ee
= AH_PRIVATE(ah
)->ah_eeprom
;
107 AH_PRIVATE(ah
)->ah_eeprom
= AH_NULL
;
111 ath_hal_v1EepromAttach(struct ath_hal
*ah
)
113 HAL_EEPROM_v1
*ee
= AH_PRIVATE(ah
)->ah_eeprom
;
114 uint16_t athvals
[AR_EEPROM_ATHEROS_MAX
]; /* XXX off stack */
115 uint16_t protect
, eeprom_version
, eeval
;
119 HALASSERT(ee
== AH_NULL
);
121 if (!ath_hal_eepromRead(ah
, AR_EEPROM_MAGIC
, &eeval
)) {
122 HALDEBUG(ah
, HAL_DEBUG_ANY
,
123 "%s: cannot read EEPROM magic number\n", __func__
);
126 if (eeval
!= 0x5aa5) {
127 HALDEBUG(ah
, HAL_DEBUG_ANY
,
128 "%s: invalid EEPROM magic number 0x%x\n", __func__
, eeval
);
132 if (!ath_hal_eepromRead(ah
, AR_EEPROM_PROTECT
, &protect
)) {
133 HALDEBUG(ah
, HAL_DEBUG_ANY
,
134 "%s: cannot read EEPROM protection bits; read locked?\n",
138 HALDEBUG(ah
, HAL_DEBUG_ATTACH
, "EEPROM protect 0x%x\n", protect
);
139 /* XXX check proper access before continuing */
141 if (!ath_hal_eepromRead(ah
, AR_EEPROM_VERSION
, &eeprom_version
)) {
142 HALDEBUG(ah
, HAL_DEBUG_ANY
,
143 "%s: unable to read EEPROM version\n", __func__
);
146 if (((eeprom_version
>>12) & 0xf) != 1) {
148 * This code only groks the version 1 EEPROM layout.
150 HALDEBUG(ah
, HAL_DEBUG_ANY
,
151 "%s: unsupported EEPROM version 0x%x found\n",
152 __func__
, eeprom_version
);
153 return HAL_EEVERSION
;
157 * Read the Atheros EEPROM entries and calculate the checksum.
160 for (i
= 0; i
< AR_EEPROM_ATHEROS_MAX
; i
++) {
161 if (!ath_hal_eepromRead(ah
, AR_EEPROM_ATHEROS(i
), &athvals
[i
]))
166 HALDEBUG(ah
, HAL_DEBUG_ANY
, "%s: bad EEPROM checksum 0x%x\n",
172 * Valid checksum, fetch the regulatory domain and save values.
174 if (!ath_hal_eepromRead(ah
, AR_EEPROM_REG_DOMAIN
, &eeval
)) {
175 HALDEBUG(ah
, HAL_DEBUG_ANY
,
176 "%s: cannot read regdomain from EEPROM\n", __func__
);
180 ee
= ath_hal_malloc(sizeof(HAL_EEPROM_v1
));
186 ee
->ee_version
= eeprom_version
;
187 ee
->ee_protect
= protect
;
188 ee
->ee_antenna
= athvals
[2];
189 ee
->ee_biasCurrents
= athvals
[3];
190 ee
->ee_thresh62
= athvals
[4] & 0xff;
191 ee
->ee_xlnaOn
= (athvals
[4] >> 8) & 0xff;
192 ee
->ee_xpaOn
= athvals
[5] & 0xff;
193 ee
->ee_xpaOff
= (athvals
[5] >> 8) & 0xff;
194 ee
->ee_regDomain
[0] = (athvals
[6] >> 8) & 0xff;
195 ee
->ee_regDomain
[1] = athvals
[6] & 0xff;
196 ee
->ee_regDomain
[2] = (athvals
[7] >> 8) & 0xff;
197 ee
->ee_regDomain
[3] = athvals
[7] & 0xff;
198 ee
->ee_rfKill
= athvals
[8] & 0x1;
199 ee
->ee_devType
= (athvals
[8] >> 1) & 0x7;
201 for (i
= 0, loc
= AR_EEPROM_ATHEROS_TP_SETTINGS
; i
< AR_CHANNELS_MAX
; i
++, loc
+= AR_TP_SETTINGS_SIZE
) {
202 struct tpcMap
*chan
= &ee
->ee_tpc
[i
];
204 /* Copy pcdac and gain_f values from EEPROM */
205 chan
->pcdac
[0] = (athvals
[loc
] >> 10) & 0x3F;
206 chan
->gainF
[0] = (athvals
[loc
] >> 4) & 0x3F;
207 chan
->pcdac
[1] = ((athvals
[loc
] << 2) & 0x3C)
208 | ((athvals
[loc
+1] >> 14) & 0x03);
209 chan
->gainF
[1] = (athvals
[loc
+1] >> 8) & 0x3F;
210 chan
->pcdac
[2] = (athvals
[loc
+1] >> 2) & 0x3F;
211 chan
->gainF
[2] = ((athvals
[loc
+1] << 4) & 0x30)
212 | ((athvals
[loc
+2] >> 12) & 0x0F);
213 chan
->pcdac
[3] = (athvals
[loc
+2] >> 6) & 0x3F;
214 chan
->gainF
[3] = athvals
[loc
+2] & 0x3F;
215 chan
->pcdac
[4] = (athvals
[loc
+3] >> 10) & 0x3F;
216 chan
->gainF
[4] = (athvals
[loc
+3] >> 4) & 0x3F;
217 chan
->pcdac
[5] = ((athvals
[loc
+3] << 2) & 0x3C)
218 | ((athvals
[loc
+4] >> 14) & 0x03);
219 chan
->gainF
[5] = (athvals
[loc
+4] >> 8) & 0x3F;
220 chan
->pcdac
[6] = (athvals
[loc
+4] >> 2) & 0x3F;
221 chan
->gainF
[6] = ((athvals
[loc
+4] << 4) & 0x30)
222 | ((athvals
[loc
+5] >> 12) & 0x0F);
223 chan
->pcdac
[7] = (athvals
[loc
+5] >> 6) & 0x3F;
224 chan
->gainF
[7] = athvals
[loc
+5] & 0x3F;
225 chan
->pcdac
[8] = (athvals
[loc
+6] >> 10) & 0x3F;
226 chan
->gainF
[8] = (athvals
[loc
+6] >> 4) & 0x3F;
227 chan
->pcdac
[9] = ((athvals
[loc
+6] << 2) & 0x3C)
228 | ((athvals
[loc
+7] >> 14) & 0x03);
229 chan
->gainF
[9] = (athvals
[loc
+7] >> 8) & 0x3F;
230 chan
->pcdac
[10] = (athvals
[loc
+7] >> 2) & 0x3F;
231 chan
->gainF
[10] = ((athvals
[loc
+7] << 4) & 0x30)
232 | ((athvals
[loc
+8] >> 12) & 0x0F);
234 /* Copy Regulatory Domain and Rate Information from EEPROM */
235 chan
->rate36
= (athvals
[loc
+8] >> 6) & 0x3F;
236 chan
->rate48
= athvals
[loc
+8] & 0x3F;
237 chan
->rate54
= (athvals
[loc
+9] >> 10) & 0x3F;
238 chan
->regdmn
[0] = (athvals
[loc
+9] >> 4) & 0x3F;
239 chan
->regdmn
[1] = ((athvals
[loc
+9] << 2) & 0x3C)
240 | ((athvals
[loc
+10] >> 14) & 0x03);
241 chan
->regdmn
[2] = (athvals
[loc
+10] >> 8) & 0x3F;
242 chan
->regdmn
[3] = (athvals
[loc
+10] >> 2) & 0x3F;
245 AH_PRIVATE(ah
)->ah_eeprom
= ee
;
246 AH_PRIVATE(ah
)->ah_eeversion
= eeprom_version
;
247 AH_PRIVATE(ah
)->ah_eepromDetach
= v1EepromDetach
;
248 AH_PRIVATE(ah
)->ah_eepromGet
= v1EepromGet
;
249 AH_PRIVATE(ah
)->ah_eepromSet
= v1EepromSet
;
250 AH_PRIVATE(ah
)->ah_getSpurChan
= v1EepromGetSpurChan
;
251 AH_PRIVATE(ah
)->ah_eepromDiag
= v1EepromDiag
;