2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
16 diff --git a/hal/ar9300/ar9300_eeprom.c b/hal/ar9300/ar9300_eeprom.c
17 index 2fe5506..628026f 100644
18 --- a/hal/ar9300/ar9300_eeprom.c
19 +++ b/hal/ar9300/ar9300_eeprom.c
20 @@ -342,6 +342,8 @@ ar9300_otp_read(struct ath_hal *ah, u_int off, u_int32_t *data, HAL_BOOL is_wifi
24 + //ath_hal_printf(ah, "%s: reading offset 0x%x\n", __func__, off);
26 addr = (AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah))?
27 OTP_MEM_START_ADDRESS_WASP : OTP_MEM_START_ADDRESS;
29 @@ -372,6 +374,7 @@ ar9300_otp_read(struct ath_hal *ah, u_int off, u_int32_t *data, HAL_BOOL is_wifi
30 addr = BTOTP_STATUS1_EFUSE_READ_DATA;
32 *data = OS_REG_READ(ah, addr);
33 + //ath_hal_printf(ah, "%s: data=0x%x\n", __func__, *data);
37 @@ -603,6 +606,8 @@ ar9300_eeprom_attach(struct ath_hal *ah)
38 systime_t current_system_time = OS_GET_TIMESTAMP();
42 + ath_hal_printf(ah, "%s: starting\n", __func__);
46 @@ -679,10 +684,14 @@ ar9300_eeprom_attach(struct ath_hal *ah)
50 + ath_hal_printf(ah, "%s: calling ar9300_fill_eeprom\n", __func__);
51 if (!ar9300_fill_eeprom(ah)) {
55 + ath_hal_printf(ah, "%s: calibration data type = %d\n", __func__,
56 + AH9300(ah)->calibration_data_source);
59 /* return ar9300_check_eeprom(ah); */
61 @@ -704,6 +713,7 @@ ar9300_eeprom_attach(struct ath_hal *ah)
62 ahp->ah_eeprom.mac_addr[4] = 0xD0;
63 ahp->ah_eeprom.mac_addr[5] = 0x00;
65 + ath_hal_printf(ah, "%s: %s:%d\n", __func__, __FILE__, __LINE__);
69 @@ -764,13 +774,17 @@ ar9300_eeprom_attach(struct ath_hal *ah)
73 + ath_hal_printf(ah, "%s: %s:%d\n", __func__, __FILE__, __LINE__);
74 if (AR_SREV_HORNET(ah) || AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah)) {
78 + ath_hal_printf(ah, "%s: %s:%d\n", __func__, __FILE__, __LINE__);
79 if (!ar9300_eeprom_restore(ah)) {
80 + ath_hal_printf(ah, "%s: %s:%d\n", __func__, __FILE__, __LINE__);
83 + ath_hal_printf(ah, "%s: %s:%d\n", __func__, __FILE__, __LINE__);
87 @@ -3743,6 +3757,12 @@ ar9300_calibration_data_read_otp(struct ath_hal *ah, long address,
88 unsigned long byte_addr;
91 + ath_hal_printf(ah, "%s: called: address=%d, many=%d, is_wifi=%d\n",
97 if (((address) < 0) || ((address + many) > 0x400)) {
100 @@ -3802,6 +3822,8 @@ ar9300_calibration_data_read_array(struct ath_hal *ah, int address,
104 + ath_hal_printf(ah, "%s: address=%d, many=%d\n", __func__, address, many);
106 for (it = 0; it < many; it++) {
107 (void)ar9300_calibration_data_read(ah, address - it, buffer + it, 1);
109 @@ -4001,13 +4023,24 @@ ar9300_eeprom_restore_internal_address(struct ath_hal *ah,
111 u_int16_t checksum, mchecksum;
113 + ath_hal_printf(ah, "%s: called, cptr=0x%x, mdata_size=%d, blank=%d\n",
114 + __func__, cptr, mdata_size, blank);
117 for (it = 0; it < MSTATE; it++) {
118 (void) ar9300_calibration_data_read_array(
119 ah, cptr, word, compression_header_length);
120 + ath_hal_printf(ah, "%s: word = 0x%x, 0x%x, 0x%x, 0x%x\n",
126 if (word[0] == blank && word[1] == blank && word[2] == blank && word[3] == blank)
129 + ath_hal_printf(ah, "%s: word=blank, skipping\n", __func__);
130 + cptr -= compression_header_length;
133 ar9300_compression_header_unpack(
134 word, &code, &reference, &length, &major, &minor);
135 @@ -4143,19 +4176,18 @@ static int
136 ar9300_eeprom_restore_from_dram(struct ath_hal *ah, ar9300_eeprom_t *mptr,
140 struct ath_hal_9300 *ahp = AH9300(ah);
145 /* cal data in flash / DRAM isn't currently supported */
146 ath_hal_printf(ah, "%s: Cal data from DRAM isn't supported\n",
154 HALASSERT(mdata_size > 0);
156 /* if cal_in_flash is true, the address sent by LMAC to HAL
157 @@ -4164,14 +4196,17 @@ ar9300_eeprom_restore_from_dram(struct ath_hal *ah, ar9300_eeprom_t *mptr,
158 if(ar9300_eep_data_in_flash(ah))
162 /* check if LMAC sent DRAM address is valid */
163 if (!(uintptr_t)(AH_PRIVATE(ah)->ah_st)) {
168 /* When calibration data is from host, Host will copy the
169 compressed data to the predefined DRAM location saved at ah->ah_st */
170 ath_hal_printf(ah, "Restoring Cal data from DRAM\n");
173 ahp->ah_cal_mem = OS_REMAP(ah, (uintptr_t)(AH_PRIVATE(ah)->ah_st),
175 @@ -4184,6 +4219,20 @@ ar9300_eeprom_restore_from_dram(struct ath_hal *ah, ar9300_eeprom_t *mptr,
176 HALDEBUG(ah, HAL_DEBUG_EEPROM,"%s: can't remap dram region\n", __func__);
182 + * The atheros HAL passes in this buffer anyway, and we copy things
183 + * into it. However, the FreeBSD driver doesn't supply this
184 + * particular memory. So, let's just assume attach/detach will
185 + * provide us with a 16 kilobyte buffer for now, and hope the whole
188 + if (! ahp->ah_cal_mem) {
189 + ath_hal_printf(ah, "%s: FreeBSD: ah_cal_mem isn't set\n", __func__);
193 cal_ptr = &((char *)(ahp->ah_cal_mem))[AR9300_FLASH_CAL_START_OFFSET];
194 OS_MEMCPY(mptr, cal_ptr, mdata_size);
196 @@ -4201,7 +4250,6 @@ ar9300_eeprom_restore_from_dram(struct ath_hal *ah, ar9300_eeprom_t *mptr,
204 @@ -4290,6 +4338,11 @@ ar9300_eeprom_restore_from_flash(struct ath_hal *ah, ar9300_eeprom_t *mptr,
208 + ath_hal_printf(ah, "%s: eeprom version=%d, template version=%d\n",
210 + (int) mptr->eeprom_version,
211 + (int) mptr->template_version);
213 if (mptr->eeprom_version == 0xff ||
214 mptr->template_version == 0xff ||
215 mptr->eeprom_version == 0 ||
216 @@ -4321,10 +4374,11 @@ ar9300_eeprom_restore_internal(struct ath_hal *ah, ar9300_eeprom_t *mptr,
220 - if ((AH9300(ah)->calibration_data_try == calibration_data_none ||
221 + if (0 && (AH9300(ah)->calibration_data_try == calibration_data_none ||
222 AH9300(ah)->calibration_data_try == calibration_data_dram) &&
223 AH9300(ah)->try_dram && nptr < 0)
225 + ath_hal_printf(ah, "%s: trying dram\n", __func__);
226 AH9300(ah)->calibration_data_source = calibration_data_dram;
227 AH9300(ah)->calibration_data_source_address = 0;
228 nptr = ar9300_eeprom_restore_from_dram(ah, mptr, mdata_size);
229 @@ -4334,7 +4388,7 @@ ar9300_eeprom_restore_internal(struct ath_hal *ah, ar9300_eeprom_t *mptr,
233 - if ((AH9300(ah)->calibration_data_try == calibration_data_none ||
234 + if (0 && (AH9300(ah)->calibration_data_try == calibration_data_none ||
235 AH9300(ah)->calibration_data_try == calibration_data_eeprom) &&
236 AH9300(ah)->try_eeprom && nptr < 0)
238 @@ -4343,6 +4397,7 @@ ar9300_eeprom_restore_internal(struct ath_hal *ah, ar9300_eeprom_t *mptr,
239 * base_address=0x3ff where we used to write the data
241 AH9300(ah)->calibration_data_source = calibration_data_eeprom;
242 + ath_hal_printf(ah, "%s: trying eeprom\n", __func__);
243 if (AH9300(ah)->calibration_data_try_address != 0) {
244 AH9300(ah)->calibration_data_source_address =
245 AH9300(ah)->calibration_data_try_address;
246 @@ -4374,7 +4429,7 @@ ar9300_eeprom_restore_internal(struct ath_hal *ah, ar9300_eeprom_t *mptr,
247 * ##### should be an ifdef test for any AP usage,
248 * either in driver or in nart
250 - if ((AH9300(ah)->calibration_data_try == calibration_data_none ||
251 + if (0 && (AH9300(ah)->calibration_data_try == calibration_data_none ||
252 AH9300(ah)->calibration_data_try == calibration_data_flash) &&
253 AH9300(ah)->try_flash && nptr < 0)
255 @@ -4388,10 +4443,17 @@ ar9300_eeprom_restore_internal(struct ath_hal *ah, ar9300_eeprom_t *mptr,
260 + AH9300(ah)->calibration_data_try = calibration_data_otp;
261 + AH9300(ah)->calibration_data_try_address = 0x2ff;
263 if ((AH9300(ah)->calibration_data_try == calibration_data_none ||
264 AH9300(ah)->calibration_data_try == calibration_data_otp) &&
265 AH9300(ah)->try_otp && nptr < 0)
267 + ath_hal_printf(ah, "%s: trying OTP, try_address=0x%x\n",
269 + AH9300(ah)->calibration_data_try_address);
270 AH9300(ah)->calibration_data_source = calibration_data_otp;
271 if (AH9300(ah)->calibration_data_try_address != 0) {
272 AH9300(ah)->calibration_data_source_address =
273 @@ -4526,6 +4588,8 @@ ar9300_eeprom_restore(struct ath_hal *ah)
275 HAL_BOOL status = AH_FALSE;
277 + ath_hal_printf(ah, "%s: called\n", __func__);
279 mptr = &ahp->ah_eeprom;
280 mdata_size = ar9300_eeprom_struct_size();