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.
20 #include "ah_internal.h"
23 #include "ah_desc.h" /* NB: for HAL_PHYERR* */
25 #include "ar9300/ar9300.h"
26 #include "ar9300/ar9300eep.h"
27 #include "ar9300/ar9300template_generic.h"
28 #include "ar9300/ar9300template_xb112.h"
29 #include "ar9300/ar9300template_hb116.h"
30 #include "ar9300/ar9300template_xb113.h"
31 #include "ar9300/ar9300template_hb112.h"
32 #include "ar9300/ar9300template_ap121.h"
33 #include "ar9300/ar9300template_osprey_k31.h"
34 #include "ar9300/ar9300template_wasp_2.h"
35 #include "ar9300/ar9300template_wasp_k31.h"
36 #include "ar9300/ar9300template_aphrodite.h"
37 #include "ar9300/ar9300reg.h"
38 #include "ar9300/ar9300phy.h"
42 #if AH_BYTE_ORDER == AH_BIG_ENDIAN
43 void ar9300_swap_eeprom(ar9300_eeprom_t *eep);
44 void ar9300_eeprom_template_swap(void);
47 static u_int16_t ar9300_eeprom_get_spur_chan(struct ath_hal *ah,
48 int spur_chan, HAL_BOOL is_2ghz);
50 static inline HAL_BOOL ar9300_fill_eeprom(struct ath_hal *ah);
51 static inline HAL_STATUS ar9300_check_eeprom(struct ath_hal *ah);
54 static ar9300_eeprom_t *default9300[] =
56 &ar9300_template_generic,
57 &ar9300_template_xb112,
58 &ar9300_template_hb116,
59 &ar9300_template_hb112,
60 &ar9300_template_xb113,
61 &ar9300_template_ap121,
62 &ar9300_template_wasp_2,
63 &ar9300_template_wasp_k31,
64 &ar9300_template_osprey_k31,
65 &ar9300_template_aphrodite,
69 * Different types of memory where the calibration data might be stored.
70 * All types are searched in ar9300_eeprom_restore()
71 * in the order flash, eeprom, otp.
72 * To disable searching a type, set its parameter to 0.
76 * This is where we look for the calibration data.
77 * must be set before ath_attach() is called
79 static int calibration_data_try = calibration_data_none;
80 static int calibration_data_try_address = 0;
83 * Set the type of memory used to store calibration data.
84 * Used by nart to force reading/writing of a specific type.
85 * The driver can normally allow autodetection
86 * by setting source to calibration_data_none=0.
88 void ar9300_calibration_data_set(struct ath_hal *ah, int32_t source)
91 AH9300(ah)->calibration_data_source = source;
93 calibration_data_try = source;
97 int32_t ar9300_calibration_data_get(struct ath_hal *ah)
100 return AH9300(ah)->calibration_data_source;
102 return calibration_data_try;
107 * Set the address of first byte used to store calibration data.
108 * Used by nart to force reading/writing at a specific address.
109 * The driver can normally allow autodetection by setting size=0.
111 void ar9300_calibration_data_address_set(struct ath_hal *ah, int32_t size)
114 AH9300(ah)->calibration_data_source_address = size;
116 calibration_data_try_address = size;
120 int32_t ar9300_calibration_data_address_get(struct ath_hal *ah)
123 return AH9300(ah)->calibration_data_source_address;
125 return calibration_data_try_address;
130 * This is the template that is loaded if ar9300_eeprom_restore()
131 * can't find valid data in the memory.
133 static int Ar9300_eeprom_template_preference = ar9300_eeprom_template_generic;
135 void ar9300_eeprom_template_preference(int32_t value)
137 Ar9300_eeprom_template_preference = value;
141 * Install the specified default template.
142 * Overwrites any existing calibration and configuration information in memory.
144 int32_t ar9300_eeprom_template_install(struct ath_hal *ah, int32_t value)
146 struct ath_hal_9300 *ahp = AH9300(ah);
147 ar9300_eeprom_t *mptr, *dptr;
150 mptr = &ahp->ah_eeprom;
151 mdata_size = ar9300_eeprom_struct_size();
154 calibration_data_source = calibration_data_none;
155 calibration_data_source_address = 0;
157 dptr = ar9300_eeprom_struct_default_find_by_id(value);
159 OS_MEMCPY(mptr, dptr, mdata_size);
167 ar9300_eeprom_restore_something(struct ath_hal *ah, ar9300_eeprom_t *mptr,
171 ar9300_eeprom_t *dptr;
176 * if we didn't find any blocks in the memory,
177 * put the prefered template in place
180 AH9300(ah)->calibration_data_source = calibration_data_none;
181 AH9300(ah)->calibration_data_source_address = 0;
182 dptr = ar9300_eeprom_struct_default_find_by_id(
183 Ar9300_eeprom_template_preference);
185 OS_MEMCPY(mptr, dptr, mdata_size);
190 * if we didn't find the prefered one,
191 * put the normal default template in place
194 AH9300(ah)->calibration_data_source = calibration_data_none;
195 AH9300(ah)->calibration_data_source_address = 0;
196 dptr = ar9300_eeprom_struct_default_find_by_id(
197 ar9300_eeprom_template_default);
199 OS_MEMCPY(mptr, dptr, mdata_size);
204 * if we can't find the best template, put any old template in place
205 * presume that newer ones are better, so search backwards
208 AH9300(ah)->calibration_data_source = calibration_data_none;
209 AH9300(ah)->calibration_data_source_address = 0;
210 for (it = ar9300_eeprom_struct_default_many() - 1; it >= 0; it--) {
211 dptr = ar9300_eeprom_struct_default(it);
213 OS_MEMCPY(mptr, dptr, mdata_size);
223 * Read 16 bits of data from offset into *data
226 ar9300_eeprom_read_word(struct ath_hal *ah, u_int off, u_int16_t *data)
228 if (AR_SREV_OSPREY(ah) || AR_SREV_POSEIDON(ah))
230 (void) OS_REG_READ(ah, AR9300_EEPROM_OFFSET + (off << AR9300_EEPROM_S));
231 if (!ath_hal_wait(ah,
232 AR_HOSTIF_REG(ah, AR_EEPROM_STATUS_DATA),
233 AR_EEPROM_STATUS_DATA_BUSY | AR_EEPROM_STATUS_DATA_PROT_ACCESS,
238 *data = MS(OS_REG_READ(ah,
239 AR_HOSTIF_REG(ah, AR_EEPROM_STATUS_DATA)), AR_EEPROM_STATUS_DATA_VAL);
251 ar9300_otp_read(struct ath_hal *ah, u_int off, u_int32_t *data, HAL_BOOL is_wifi)
257 if (AR_SREV_HONEYBEE(ah)){ /* no OTP for Honeybee */
260 addr = (AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah))?
261 OTP_MEM_START_ADDRESS_WASP : OTP_MEM_START_ADDRESS;
263 addr = BTOTP_MEM_START_ADDRESS;
265 addr += off * 4; /* OTP is 32 bit addressable */
266 (void) OS_REG_READ(ah, addr);
268 addr = (AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah)) ?
269 OTP_STATUS0_OTP_SM_BUSY_WASP : OTP_STATUS0_OTP_SM_BUSY;
271 addr = BTOTP_STATUS0_OTP_SM_BUSY;
273 while ((time_out > 0) && (!status)) { /* wait for access complete */
274 /* Read data valid, access not busy, sm not busy */
275 status = ((OS_REG_READ(ah, addr) & 0x7) == 0x4) ? 1 : 0;
279 HALDEBUG(ah, HAL_DEBUG_EEPROM,
280 "%s: Timed out during OTP Status0 validation\n", __func__);
284 addr = (AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah)) ?
285 OTP_STATUS1_EFUSE_READ_DATA_WASP : OTP_STATUS1_EFUSE_READ_DATA;
287 addr = BTOTP_STATUS1_EFUSE_READ_DATA;
289 *data = OS_REG_READ(ah, addr);
297 ar9300_flash_map(struct ath_hal *ah)
299 /* XXX disable flash remapping for now (ie, SoC support) */
300 ath_hal_printf(ah, "%s: unimplemented for now\n", __func__);
302 struct ath_hal_9300 *ahp = AH9300(ah);
303 #if defined(AR9100) || defined(__NetBSD__)
304 ahp->ah_cal_mem = OS_REMAP(ah, AR9300_EEPROM_START_ADDR, AR9300_EEPROM_MAX);
306 ahp->ah_cal_mem = OS_REMAP((uintptr_t)(AH_PRIVATE(ah)->ah_st),
307 (AR9300_EEPROM_MAX + AR9300_FLASH_CAL_START_OFFSET));
309 if (!ahp->ah_cal_mem) {
310 HALDEBUG(ah, HAL_DEBUG_EEPROM,
311 "%s: cannot remap eeprom region \n", __func__);
319 ar9300_flash_read(struct ath_hal *ah, u_int off, u_int16_t *data)
321 struct ath_hal_9300 *ahp = AH9300(ah);
323 *data = ((u_int16_t *)ahp->ah_cal_mem)[off];
328 ar9300_flash_write(struct ath_hal *ah, u_int off, u_int16_t data)
330 struct ath_hal_9300 *ahp = AH9300(ah);
332 ((u_int16_t *)ahp->ah_cal_mem)[off] = data;
337 ar9300_eeprom_attach(struct ath_hal *ah)
339 struct ath_hal_9300 *ahp = AH9300(ah);
343 #ifdef ATH_CAL_NAND_FLASH
348 ahp->calibration_data_source = calibration_data_none;
349 ahp->calibration_data_source_address = 0;
350 ahp->calibration_data_try = calibration_data_try;
351 ahp->calibration_data_try_address = 0;
354 * In case flash will be used for EEPROM. Otherwise ahp->ah_cal_mem
355 * must be set to NULL or the real EEPROM address.
357 ar9300_flash_map(ah);
359 * ###### This function always return NO SPUR.
360 * This is not true for many board designs.
361 * Does anyone use this?
363 AH_PRIVATE(ah)->ah_getSpurChan = ar9300_eeprom_get_spur_chan;
366 /* XXX Needs to be moved for dynamic selection */
367 ahp->ah_eeprom = *(default9300[ar9300_eeprom_template_default]);
370 if (AR_SREV_HORNET(ah)) {
371 /* Set default values for Hornet. */
372 ahp->ah_eeprom.base_eep_header.op_cap_flags.op_flags =
374 ahp->ah_eeprom.base_eep_header.txrx_mask = 0x11;
375 } else if (AR_SREV_POSEIDON(ah)) {
376 /* Set default values for Poseidon. */
377 ahp->ah_eeprom.base_eep_header.op_cap_flags.op_flags =
379 ahp->ah_eeprom.base_eep_header.txrx_mask = 0x11;
382 if (AH_PRIVATE(ah)->ah_config.ath_hal_skip_eeprom_read) {
383 ahp->ah_emu_eeprom = 1;
387 ahp->ah_emu_eeprom = 1;
392 if (!ar9300_fill_eeprom(ah)) {
397 /* return ar9300_check_eeprom(ah); */
399 ahp->ah_emu_eeprom = 1;
402 /*#ifdef MDK_AP*/ /* MDK_AP is defined only in NART AP build */
404 int caldata_check = 0;
406 ar9300_calibration_data_read_flash(
407 ah, FLASH_BASE_CALDATA_OFFSET, buffer, 4);
408 printf("flash caldata:: %x\n", buffer[0]);
409 if (buffer[0] != 0xff) {
412 if (!caldata_check) {
413 ar9300_eeprom_t *mptr;
415 if (AR_SREV_HORNET(ah)) {
416 /* XXX: For initial testing */
417 mptr = &ahp->ah_eeprom;
418 mdata_size = ar9300_eeprom_struct_size();
419 ahp->ah_eeprom = ar9300_template_ap121;
420 ahp->ah_emu_eeprom = 1;
421 /* need it to let art save in to flash ????? */
422 calibration_data_source = calibration_data_flash;
423 } else if (AR_SREV_WASP(ah)) {
424 /* XXX: For initial testing */
425 ath_hal_printf(ah, " wasp eep attach\n");
426 mptr = &ahp->ah_eeprom;
427 mdata_size = ar9300_eeprom_struct_size();
428 ahp->ah_eeprom = ar9300_template_generic;
429 ahp->ah_eeprom.mac_addr[0] = 0x00;
430 ahp->ah_eeprom.mac_addr[1] = 0x03;
431 ahp->ah_eeprom.mac_addr[2] = 0x7F;
432 ahp->ah_eeprom.mac_addr[3] = 0xBA;
433 ahp->ah_eeprom.mac_addr[4] = 0xD0;
434 ahp->ah_eeprom.mac_addr[5] = 0x00;
435 ahp->ah_emu_eeprom = 1;
436 ahp->ah_eeprom.base_eep_header.txrx_mask = 0x33;
437 ahp->ah_eeprom.base_eep_header.txrxgain = 0x10;
438 /* need it to let art save in to flash ????? */
439 calibration_data_source = calibration_data_flash;
444 if (AR_SREV_HORNET(ah) || AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah)
445 || AR_SREV_HONEYBEE(ah)) {
449 if (AR_SREV_HONEYBEE(ah)) {
453 if (!ar9300_eeprom_restore(ah)) {
461 ar9300_eeprom_get(struct ath_hal_9300 *ahp, EEPROM_PARAM param)
463 ar9300_eeprom_t *eep = &ahp->ah_eeprom;
464 OSPREY_BASE_EEP_HEADER *p_base = &eep->base_eep_header;
465 OSPREY_BASE_EXTENSION_1 *base_ext1 = &eep->base_ext1;
470 return p_modal[0].noise_floor_thresh_ch[0];
472 return p_modal[1].noise_floor_thresh_ch[0];
475 return eep->mac_addr[0] << 8 | eep->mac_addr[1];
477 return eep->mac_addr[2] << 8 | eep->mac_addr[3];
479 return eep->mac_addr[4] << 8 | eep->mac_addr[5];
481 return p_base->reg_dmn[0];
483 return p_base->reg_dmn[1];
485 return p_base->device_cap;
487 return p_base->op_cap_flags.op_flags;
489 return p_base->rf_silent;
492 return p_modal[0].ob;
494 return p_modal[0].db;
496 return p_modal[1].ob;
498 return p_modal[1].db;
500 return p_base->eeprom_version & AR9300_EEP_VER_MINOR_MASK;
503 return (p_base->txrx_mask >> 4) & 0xf;
505 return p_base->txrx_mask & 0xf;
508 return p_base->fast_clk5g;
509 case EEP_RXGAIN_TYPE:
510 return p_base->rx_gain_type;
512 case EEP_DRIVE_STRENGTH:
513 #define AR9300_EEP_BASE_DRIVE_STRENGTH 0x1
514 return p_base->misc_configuration & AR9300_EEP_BASE_DRIVE_STRENGTH;
515 case EEP_INTERNAL_REGULATOR:
516 /* Bit 4 is internal regulator flag */
517 return ((p_base->feature_enable & 0x10) >> 4);
519 return (p_base->swreg);
520 case EEP_PAPRD_ENABLED:
521 /* Bit 5 is paprd flag */
522 return ((p_base->feature_enable & 0x20) >> 5);
523 case EEP_ANTDIV_control:
524 return (u_int32_t)(base_ext1->ant_div_control);
525 case EEP_CHAIN_MASK_REDUCE:
526 return ((p_base->misc_configuration >> 3) & 0x1);
530 return p_base->device_type;
539 /******************************************************************************/
541 ** \brief EEPROM fixup code for INI values
543 ** This routine provides a place to insert "fixup" code for specific devices
544 ** that need to modify INI values based on EEPROM values, BEFORE the INI values
546 ** Certain registers in the INI file can only be written once without
547 ** undesired side effects, and this provides a place for EEPROM overrides
550 ** This is called at attach time once. It should not affect run time
551 ** performance at all
553 ** \param ah Pointer to HAL object (this)
554 ** \param p_eep_data Pointer to (filled in) eeprom data structure
555 ** \param reg register being inspected on this call
556 ** \param value value in INI file
558 ** \return Updated value for INI file.
561 ar9300_ini_fixup(struct ath_hal *ah, ar9300_eeprom_t *p_eep_data,
562 u_int32_t reg, u_int32_t value)
564 HALDEBUG(AH_NULL, HAL_DEBUG_UNMASKABLE,
565 "ar9300_eeprom_def_ini_fixup: FIXME\n");
567 BASE_EEPDEF_HEADER *p_base = &(p_eep_data->base_eep_header);
569 switch (AH_PRIVATE(ah)->ah_devid)
571 case AR9300_DEVID_AR9300_PCI:
573 ** Need to set the external/internal regulator bit to the proper value.
574 ** Can only write this ONCE.
580 ** Check for an EEPROM data structure of "0x0b" or better
583 HALDEBUG(ah, HAL_DEBUG_EEPROM, "ini VAL: %x EEPROM: %x\n",
584 value, (p_base->version & 0xff));
586 if ( (p_base->version & 0xff) > 0x0a) {
587 HALDEBUG(ah, HAL_DEBUG_EEPROM,
588 "PWDCLKIND: %d\n", p_base->pwdclkind);
589 value &= ~AR_AN_TOP2_PWDCLKIND;
591 AR_AN_TOP2_PWDCLKIND &
592 (p_base->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
594 HALDEBUG(ah, HAL_DEBUG_EEPROM, "PWDCLKIND Earlier Rev\n");
597 HALDEBUG(ah, HAL_DEBUG_EEPROM, "final ini VAL: %x\n", value);
610 * Returns the interpolated y value corresponding to the specified x value
611 * from the np ordered pairs of data (px,py).
612 * The pairs do not have to be in any order.
613 * If the specified x value is less than any of the px,
614 * the returned y value is equal to the py for the lowest px.
615 * If the specified x value is greater than any of the px,
616 * the returned y value is equal to the py for the highest px.
619 interpolate(int32_t x, int32_t *px, int32_t *py, u_int16_t np)
622 int lx = 0, ly = 0, lhave = 0;
623 int hx = 0, hy = 0, hhave = 0;
626 int bf, factor, plus;
631 * identify best lower and higher x calibration measurement
633 for (ip = 0; ip < np; ip++) {
635 /* this measurement is higher than our desired x */
637 if (!hhave || dx > (x - hx)) {
638 /* new best higher x measurement */
644 /* this measurement is lower than our desired x */
646 if (!lhave || dx < (x - lx)) {
647 /* new best lower x measurement */
654 /* the low x is good */
656 /* so is the high x */
658 /* they're the same, so just pick one */
662 /* interpolate with round off */
663 bf = (2 * (hy - ly) * (x - lx)) / (hx - lx);
666 y = ly + factor + plus;
669 /* only low is good, use it */
673 /* only high is good, use it */
676 /* nothing is good,this should never happen unless np=0, ???? */
684 ar9300_eeprom_get_legacy_trgt_pwr(struct ath_hal *ah, u_int16_t rate_index,
685 u_int16_t freq, HAL_BOOL is_2ghz)
687 u_int16_t num_piers, i;
688 int32_t target_power_array[OSPREY_NUM_5G_20_TARGET_POWERS];
689 int32_t freq_array[OSPREY_NUM_5G_20_TARGET_POWERS];
690 u_int8_t *p_freq_bin;
691 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
692 CAL_TARGET_POWER_LEG *p_eeprom_target_pwr;
695 num_piers = OSPREY_NUM_2G_20_TARGET_POWERS;
696 p_eeprom_target_pwr = eep->cal_target_power_2g;
697 p_freq_bin = eep->cal_target_freqbin_2g;
699 num_piers = OSPREY_NUM_5G_20_TARGET_POWERS;
700 p_eeprom_target_pwr = eep->cal_target_power_5g;
701 p_freq_bin = eep->cal_target_freqbin_5g;
705 * create array of channels and targetpower from
706 * targetpower piers stored on eeprom
708 for (i = 0; i < num_piers; i++) {
709 freq_array[i] = FBIN2FREQ(p_freq_bin[i], is_2ghz);
710 target_power_array[i] = p_eeprom_target_pwr[i].t_pow2x[rate_index];
713 /* interpolate to get target power for given frequency */
715 ((u_int8_t)interpolate(
716 (int32_t)freq, freq_array, target_power_array, num_piers));
720 ar9300_eeprom_get_ht20_trgt_pwr(struct ath_hal *ah, u_int16_t rate_index,
721 u_int16_t freq, HAL_BOOL is_2ghz)
723 u_int16_t num_piers, i;
724 int32_t target_power_array[OSPREY_NUM_5G_20_TARGET_POWERS];
725 int32_t freq_array[OSPREY_NUM_5G_20_TARGET_POWERS];
726 u_int8_t *p_freq_bin;
727 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
728 OSP_CAL_TARGET_POWER_HT *p_eeprom_target_pwr;
731 num_piers = OSPREY_NUM_2G_20_TARGET_POWERS;
732 p_eeprom_target_pwr = eep->cal_target_power_2g_ht20;
733 p_freq_bin = eep->cal_target_freqbin_2g_ht20;
735 num_piers = OSPREY_NUM_5G_20_TARGET_POWERS;
736 p_eeprom_target_pwr = eep->cal_target_power_5g_ht20;
737 p_freq_bin = eep->cal_target_freqbin_5g_ht20;
741 * create array of channels and targetpower from
742 * targetpower piers stored on eeprom
744 for (i = 0; i < num_piers; i++) {
745 freq_array[i] = FBIN2FREQ(p_freq_bin[i], is_2ghz);
746 target_power_array[i] = p_eeprom_target_pwr[i].t_pow2x[rate_index];
749 /* interpolate to get target power for given frequency */
751 ((u_int8_t)interpolate(
752 (int32_t)freq, freq_array, target_power_array, num_piers));
756 ar9300_eeprom_get_ht40_trgt_pwr(struct ath_hal *ah, u_int16_t rate_index,
757 u_int16_t freq, HAL_BOOL is_2ghz)
759 u_int16_t num_piers, i;
760 int32_t target_power_array[OSPREY_NUM_5G_40_TARGET_POWERS];
761 int32_t freq_array[OSPREY_NUM_5G_40_TARGET_POWERS];
762 u_int8_t *p_freq_bin;
763 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
764 OSP_CAL_TARGET_POWER_HT *p_eeprom_target_pwr;
767 num_piers = OSPREY_NUM_2G_40_TARGET_POWERS;
768 p_eeprom_target_pwr = eep->cal_target_power_2g_ht40;
769 p_freq_bin = eep->cal_target_freqbin_2g_ht40;
771 num_piers = OSPREY_NUM_5G_40_TARGET_POWERS;
772 p_eeprom_target_pwr = eep->cal_target_power_5g_ht40;
773 p_freq_bin = eep->cal_target_freqbin_5g_ht40;
777 * create array of channels and targetpower from
778 * targetpower piers stored on eeprom
780 for (i = 0; i < num_piers; i++) {
781 freq_array[i] = FBIN2FREQ(p_freq_bin[i], is_2ghz);
782 target_power_array[i] = p_eeprom_target_pwr[i].t_pow2x[rate_index];
785 /* interpolate to get target power for given frequency */
787 ((u_int8_t)interpolate(
788 (int32_t)freq, freq_array, target_power_array, num_piers));
792 ar9300_eeprom_get_cck_trgt_pwr(struct ath_hal *ah, u_int16_t rate_index,
795 u_int16_t num_piers = OSPREY_NUM_2G_CCK_TARGET_POWERS, i;
796 int32_t target_power_array[OSPREY_NUM_2G_CCK_TARGET_POWERS];
797 int32_t freq_array[OSPREY_NUM_2G_CCK_TARGET_POWERS];
798 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
799 u_int8_t *p_freq_bin = eep->cal_target_freqbin_cck;
800 CAL_TARGET_POWER_LEG *p_eeprom_target_pwr = eep->cal_target_power_cck;
803 * create array of channels and targetpower from
804 * targetpower piers stored on eeprom
806 for (i = 0; i < num_piers; i++) {
807 freq_array[i] = FBIN2FREQ(p_freq_bin[i], 1);
808 target_power_array[i] = p_eeprom_target_pwr[i].t_pow2x[rate_index];
811 /* interpolate to get target power for given frequency */
813 ((u_int8_t)interpolate(
814 (int32_t)freq, freq_array, target_power_array, num_piers));
818 * Set tx power registers to array of values passed in
821 ar9300_transmit_power_reg_write(struct ath_hal *ah, u_int8_t *p_pwr_array)
823 #define POW_SM(_r, _s) (((_r) & 0x3f) << (_s))
824 /* make sure forced gain is not set */
826 field_write("force_dac_gain", 0);
827 OS_REG_WRITE(ah, 0xa3f8, 0);
828 field_write("force_tx_gain", 0);
831 OS_REG_WRITE(ah, 0xa458, 0);
833 /* Write the OFDM power per rate set */
834 /* 6 (LSB), 9, 12, 18 (MSB) */
835 OS_REG_WRITE(ah, 0xa3c0,
836 POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 24)
837 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 16)
838 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 8)
839 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 0)
841 /* 24 (LSB), 36, 48, 54 (MSB) */
842 OS_REG_WRITE(ah, 0xa3c4,
843 POW_SM(p_pwr_array[ALL_TARGET_LEGACY_54], 24)
844 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_48], 16)
845 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_36], 8)
846 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 0)
849 /* Write the CCK power per rate set */
850 /* 1L (LSB), reserved, 2L, 2S (MSB) */
851 OS_REG_WRITE(ah, 0xa3c8,
852 POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 24)
853 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 16)
854 /* | POW_SM(tx_power_times2, 8)*/ /* this is reserved for Osprey */
855 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 0)
857 /* 5.5L (LSB), 5.5S, 11L, 11S (MSB) */
858 OS_REG_WRITE(ah, 0xa3cc,
859 POW_SM(p_pwr_array[ALL_TARGET_LEGACY_11S], 24)
860 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_11L], 16)
861 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_5S], 8)
862 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 0)
865 /* write the power for duplicated frames - HT40 */
866 /* dup40_cck (LSB), dup40_ofdm, ext20_cck, ext20_ofdm (MSB) */
867 OS_REG_WRITE(ah, 0xa3e0,
868 POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 24)
869 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 16)
870 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 8)
871 | POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 0)
874 /* Write the HT20 power per rate set */
875 /* 0/8/16 (LSB), 1-3/9-11/17-19, 4, 5 (MSB) */
876 OS_REG_WRITE(ah, 0xa3d0,
877 POW_SM(p_pwr_array[ALL_TARGET_HT20_5], 24)
878 | POW_SM(p_pwr_array[ALL_TARGET_HT20_4], 16)
879 | POW_SM(p_pwr_array[ALL_TARGET_HT20_1_3_9_11_17_19], 8)
880 | POW_SM(p_pwr_array[ALL_TARGET_HT20_0_8_16], 0)
883 /* 6 (LSB), 7, 12, 13 (MSB) */
884 OS_REG_WRITE(ah, 0xa3d4,
885 POW_SM(p_pwr_array[ALL_TARGET_HT20_13], 24)
886 | POW_SM(p_pwr_array[ALL_TARGET_HT20_12], 16)
887 | POW_SM(p_pwr_array[ALL_TARGET_HT20_7], 8)
888 | POW_SM(p_pwr_array[ALL_TARGET_HT20_6], 0)
891 /* 14 (LSB), 15, 20, 21 */
892 OS_REG_WRITE(ah, 0xa3e4,
893 POW_SM(p_pwr_array[ALL_TARGET_HT20_21], 24)
894 | POW_SM(p_pwr_array[ALL_TARGET_HT20_20], 16)
895 | POW_SM(p_pwr_array[ALL_TARGET_HT20_15], 8)
896 | POW_SM(p_pwr_array[ALL_TARGET_HT20_14], 0)
899 /* Mixed HT20 and HT40 rates */
900 /* HT20 22 (LSB), HT20 23, HT40 22, HT40 23 (MSB) */
901 OS_REG_WRITE(ah, 0xa3e8,
902 POW_SM(p_pwr_array[ALL_TARGET_HT40_23], 24)
903 | POW_SM(p_pwr_array[ALL_TARGET_HT40_22], 16)
904 | POW_SM(p_pwr_array[ALL_TARGET_HT20_23], 8)
905 | POW_SM(p_pwr_array[ALL_TARGET_HT20_22], 0)
908 /* Write the HT40 power per rate set */
909 /* correct PAR difference between HT40 and HT20/LEGACY */
910 /* 0/8/16 (LSB), 1-3/9-11/17-19, 4, 5 (MSB) */
911 OS_REG_WRITE(ah, 0xa3d8,
912 POW_SM(p_pwr_array[ALL_TARGET_HT40_5], 24)
913 | POW_SM(p_pwr_array[ALL_TARGET_HT40_4], 16)
914 | POW_SM(p_pwr_array[ALL_TARGET_HT40_1_3_9_11_17_19], 8)
915 | POW_SM(p_pwr_array[ALL_TARGET_HT40_0_8_16], 0)
918 /* 6 (LSB), 7, 12, 13 (MSB) */
919 OS_REG_WRITE(ah, 0xa3dc,
920 POW_SM(p_pwr_array[ALL_TARGET_HT40_13], 24)
921 | POW_SM(p_pwr_array[ALL_TARGET_HT40_12], 16)
922 | POW_SM(p_pwr_array[ALL_TARGET_HT40_7], 8)
923 | POW_SM(p_pwr_array[ALL_TARGET_HT40_6], 0)
926 /* 14 (LSB), 15, 20, 21 */
927 OS_REG_WRITE(ah, 0xa3ec,
928 POW_SM(p_pwr_array[ALL_TARGET_HT40_21], 24)
929 | POW_SM(p_pwr_array[ALL_TARGET_HT40_20], 16)
930 | POW_SM(p_pwr_array[ALL_TARGET_HT40_15], 8)
931 | POW_SM(p_pwr_array[ALL_TARGET_HT40_14], 0)
939 ar9300_selfgen_tpc_reg_write(struct ath_hal *ah, const struct ieee80211_channel *chan,
940 u_int8_t *p_pwr_array)
942 u_int32_t tpc_reg_val;
944 /* Set the target power values for self generated frames (ACK,RTS/CTS) to
945 * be within limits. This is just a safety measure.With per packet TPC mode
946 * enabled the target power value used with self generated frames will be
947 * MIN( TPC reg, BB_powertx_rate register)
950 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
951 tpc_reg_val = (SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], AR_TPC_ACK) |
952 SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], AR_TPC_CTS) |
953 SM(0x3f, AR_TPC_CHIRP) |
954 SM(0x3f, AR_TPC_RPT));
956 tpc_reg_val = (SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], AR_TPC_ACK) |
957 SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], AR_TPC_CTS) |
958 SM(0x3f, AR_TPC_CHIRP) |
959 SM(0x3f, AR_TPC_RPT));
961 OS_REG_WRITE(ah, AR_TPC, tpc_reg_val);
965 ar9300_set_target_power_from_eeprom(struct ath_hal *ah, u_int16_t freq,
966 u_int8_t *target_power_val_t2)
968 /* hard code for now, need to get from eeprom struct */
969 u_int8_t ht40_power_inc_for_pdadc = 0;
970 HAL_BOOL is_2ghz = 0;
976 target_power_val_t2[ALL_TARGET_LEGACY_6_24] =
977 ar9300_eeprom_get_legacy_trgt_pwr(
978 ah, LEGACY_TARGET_RATE_6_24, freq, is_2ghz);
979 target_power_val_t2[ALL_TARGET_LEGACY_36] =
980 ar9300_eeprom_get_legacy_trgt_pwr(
981 ah, LEGACY_TARGET_RATE_36, freq, is_2ghz);
982 target_power_val_t2[ALL_TARGET_LEGACY_48] =
983 ar9300_eeprom_get_legacy_trgt_pwr(
984 ah, LEGACY_TARGET_RATE_48, freq, is_2ghz);
985 target_power_val_t2[ALL_TARGET_LEGACY_54] =
986 ar9300_eeprom_get_legacy_trgt_pwr(
987 ah, LEGACY_TARGET_RATE_54, freq, is_2ghz);
988 target_power_val_t2[ALL_TARGET_LEGACY_1L_5L] =
989 ar9300_eeprom_get_cck_trgt_pwr(
990 ah, LEGACY_TARGET_RATE_1L_5L, freq);
991 target_power_val_t2[ALL_TARGET_LEGACY_5S] =
992 ar9300_eeprom_get_cck_trgt_pwr(
993 ah, LEGACY_TARGET_RATE_5S, freq);
994 target_power_val_t2[ALL_TARGET_LEGACY_11L] =
995 ar9300_eeprom_get_cck_trgt_pwr(
996 ah, LEGACY_TARGET_RATE_11L, freq);
997 target_power_val_t2[ALL_TARGET_LEGACY_11S] =
998 ar9300_eeprom_get_cck_trgt_pwr(
999 ah, LEGACY_TARGET_RATE_11S, freq);
1000 target_power_val_t2[ALL_TARGET_HT20_0_8_16] =
1001 ar9300_eeprom_get_ht20_trgt_pwr(
1002 ah, HT_TARGET_RATE_0_8_16, freq, is_2ghz);
1003 target_power_val_t2[ALL_TARGET_HT20_1_3_9_11_17_19] =
1004 ar9300_eeprom_get_ht20_trgt_pwr(
1005 ah, HT_TARGET_RATE_1_3_9_11_17_19, freq, is_2ghz);
1006 target_power_val_t2[ALL_TARGET_HT20_4] =
1007 ar9300_eeprom_get_ht20_trgt_pwr(
1008 ah, HT_TARGET_RATE_4, freq, is_2ghz);
1009 target_power_val_t2[ALL_TARGET_HT20_5] =
1010 ar9300_eeprom_get_ht20_trgt_pwr(
1011 ah, HT_TARGET_RATE_5, freq, is_2ghz);
1012 target_power_val_t2[ALL_TARGET_HT20_6] =
1013 ar9300_eeprom_get_ht20_trgt_pwr(
1014 ah, HT_TARGET_RATE_6, freq, is_2ghz);
1015 target_power_val_t2[ALL_TARGET_HT20_7] =
1016 ar9300_eeprom_get_ht20_trgt_pwr(
1017 ah, HT_TARGET_RATE_7, freq, is_2ghz);
1018 target_power_val_t2[ALL_TARGET_HT20_12] =
1019 ar9300_eeprom_get_ht20_trgt_pwr(
1020 ah, HT_TARGET_RATE_12, freq, is_2ghz);
1021 target_power_val_t2[ALL_TARGET_HT20_13] =
1022 ar9300_eeprom_get_ht20_trgt_pwr(
1023 ah, HT_TARGET_RATE_13, freq, is_2ghz);
1024 target_power_val_t2[ALL_TARGET_HT20_14] =
1025 ar9300_eeprom_get_ht20_trgt_pwr(
1026 ah, HT_TARGET_RATE_14, freq, is_2ghz);
1027 target_power_val_t2[ALL_TARGET_HT20_15] =
1028 ar9300_eeprom_get_ht20_trgt_pwr(
1029 ah, HT_TARGET_RATE_15, freq, is_2ghz);
1030 target_power_val_t2[ALL_TARGET_HT20_20] =
1031 ar9300_eeprom_get_ht20_trgt_pwr(
1032 ah, HT_TARGET_RATE_20, freq, is_2ghz);
1033 target_power_val_t2[ALL_TARGET_HT20_21] =
1034 ar9300_eeprom_get_ht20_trgt_pwr(
1035 ah, HT_TARGET_RATE_21, freq, is_2ghz);
1036 target_power_val_t2[ALL_TARGET_HT20_22] =
1037 ar9300_eeprom_get_ht20_trgt_pwr(
1038 ah, HT_TARGET_RATE_22, freq, is_2ghz);
1039 target_power_val_t2[ALL_TARGET_HT20_23] =
1040 ar9300_eeprom_get_ht20_trgt_pwr(
1041 ah, HT_TARGET_RATE_23, freq, is_2ghz);
1042 target_power_val_t2[ALL_TARGET_HT40_0_8_16] =
1043 ar9300_eeprom_get_ht40_trgt_pwr(
1044 ah, HT_TARGET_RATE_0_8_16, freq, is_2ghz) +
1045 ht40_power_inc_for_pdadc;
1046 target_power_val_t2[ALL_TARGET_HT40_1_3_9_11_17_19] =
1047 ar9300_eeprom_get_ht40_trgt_pwr(
1048 ah, HT_TARGET_RATE_1_3_9_11_17_19, freq, is_2ghz) +
1049 ht40_power_inc_for_pdadc;
1050 target_power_val_t2[ALL_TARGET_HT40_4] =
1051 ar9300_eeprom_get_ht40_trgt_pwr(
1052 ah, HT_TARGET_RATE_4, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1053 target_power_val_t2[ALL_TARGET_HT40_5] =
1054 ar9300_eeprom_get_ht40_trgt_pwr(
1055 ah, HT_TARGET_RATE_5, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1056 target_power_val_t2[ALL_TARGET_HT40_6] =
1057 ar9300_eeprom_get_ht40_trgt_pwr(
1058 ah, HT_TARGET_RATE_6, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1059 target_power_val_t2[ALL_TARGET_HT40_7] =
1060 ar9300_eeprom_get_ht40_trgt_pwr(
1061 ah, HT_TARGET_RATE_7, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1062 target_power_val_t2[ALL_TARGET_HT40_12] =
1063 ar9300_eeprom_get_ht40_trgt_pwr(
1064 ah, HT_TARGET_RATE_12, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1065 target_power_val_t2[ALL_TARGET_HT40_13] =
1066 ar9300_eeprom_get_ht40_trgt_pwr(
1067 ah, HT_TARGET_RATE_13, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1068 target_power_val_t2[ALL_TARGET_HT40_14] =
1069 ar9300_eeprom_get_ht40_trgt_pwr(
1070 ah, HT_TARGET_RATE_14, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1071 target_power_val_t2[ALL_TARGET_HT40_15] =
1072 ar9300_eeprom_get_ht40_trgt_pwr(
1073 ah, HT_TARGET_RATE_15, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1074 target_power_val_t2[ALL_TARGET_HT40_20] =
1075 ar9300_eeprom_get_ht40_trgt_pwr(
1076 ah, HT_TARGET_RATE_20, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1077 target_power_val_t2[ALL_TARGET_HT40_21] =
1078 ar9300_eeprom_get_ht40_trgt_pwr(
1079 ah, HT_TARGET_RATE_21, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1080 target_power_val_t2[ALL_TARGET_HT40_22] =
1081 ar9300_eeprom_get_ht40_trgt_pwr(
1082 ah, HT_TARGET_RATE_22, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1083 target_power_val_t2[ALL_TARGET_HT40_23] =
1084 ar9300_eeprom_get_ht40_trgt_pwr(
1085 ah, HT_TARGET_RATE_23, freq, is_2ghz) + ht40_power_inc_for_pdadc;
1091 HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: APPLYING TARGET POWERS\n", __func__);
1092 while (i < ar9300_rate_size) {
1093 HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: TPC[%02d] 0x%08x ",
1094 __func__, i, target_power_val_t2[i]);
1096 if (i == ar9300_rate_size) {
1099 HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: TPC[%02d] 0x%08x ",
1100 __func__, i, target_power_val_t2[i]);
1102 if (i == ar9300_rate_size) {
1105 HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: TPC[%02d] 0x%08x ",
1106 __func__, i, target_power_val_t2[i]);
1108 if (i == ar9300_rate_size) {
1111 HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: TPC[%02d] 0x%08x \n",
1112 __func__, i, target_power_val_t2[i]);
1119 u_int16_t *ar9300_regulatory_domain_get(struct ath_hal *ah)
1121 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1122 return eep->base_eep_header.reg_dmn;
1127 ar9300_eeprom_write_enable_gpio_get(struct ath_hal *ah)
1129 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1130 return eep->base_eep_header.eeprom_write_enable_gpio;
1134 ar9300_wlan_disable_gpio_get(struct ath_hal *ah)
1136 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1137 return eep->base_eep_header.wlan_disable_gpio;
1141 ar9300_wlan_led_gpio_get(struct ath_hal *ah)
1143 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1144 return eep->base_eep_header.wlan_led_gpio;
1148 ar9300_rx_band_select_gpio_get(struct ath_hal *ah)
1150 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1151 return eep->base_eep_header.rx_band_select_gpio;
1155 * since valid noise floor values are negative, returns 1 on error
1158 ar9300_noise_floor_cal_or_power_get(struct ath_hal *ah, int32_t frequency,
1159 int32_t ichain, HAL_BOOL use_cal)
1161 int nf_use = 1; /* start with an error return value */
1162 int32_t fx[OSPREY_NUM_5G_CAL_PIERS + OSPREY_NUM_2G_CAL_PIERS];
1163 int32_t nf[OSPREY_NUM_5G_CAL_PIERS + OSPREY_NUM_2G_CAL_PIERS];
1167 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1168 u_int8_t *p_cal_pier;
1169 OSP_CAL_DATA_PER_FREQ_OP_LOOP *p_cal_pier_struct;
1174 if (ichain < 0 || ichain >= OSPREY_MAX_CHAINS) {
1178 /* figure out which band we're using */
1179 is_2ghz = (frequency < 4000);
1181 npier = OSPREY_NUM_2G_CAL_PIERS;
1182 p_cal_pier = eep->cal_freq_pier_2g;
1183 p_cal_pier_struct = eep->cal_pier_data_2g[ichain];
1185 npier = OSPREY_NUM_5G_CAL_PIERS;
1186 p_cal_pier = eep->cal_freq_pier_5g;
1187 p_cal_pier_struct = eep->cal_pier_data_5g[ichain];
1189 /* look for valid noise floor values */
1191 for (ipier = 0; ipier < npier; ipier++) {
1192 fx[nnf] = FBIN2FREQ(p_cal_pier[ipier], is_2ghz);
1194 p_cal_pier_struct[ipier].rx_noisefloor_cal :
1195 p_cal_pier_struct[ipier].rx_noisefloor_power;
1201 * If we have some valid values, interpolate to find the value
1202 * at the desired frequency.
1205 nf_use = interpolate(frequency, fx, nf, nnf);
1212 * Return the Rx NF offset for specific channel.
1213 * The values saved in EEPROM/OTP/Flash is converted through the following way:
1214 * ((_p) - NOISE_PWR_DATA_OFFSET) << 2
1215 * So we need to convert back to the original values.
1217 int ar9300_get_rx_nf_offset(struct ath_hal *ah, struct ieee80211_channel *chan, int8_t *nf_pwr, int8_t *nf_cal) {
1218 HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, chan);
1219 int8_t rx_nf_pwr, rx_nf_cal;
1223 /* Fill 0 if valid internal channel is not found */
1224 if (ichan == AH_NULL) {
1225 OS_MEMZERO(nf_pwr, sizeof(nf_pwr[0])*OSPREY_MAX_CHAINS);
1226 OS_MEMZERO(nf_cal, sizeof(nf_cal[0])*OSPREY_MAX_CHAINS);
1230 for (i = 0; i < OSPREY_MAX_CHAINS; i++) {
1231 if ((rx_nf_pwr = ar9300_noise_floor_cal_or_power_get(ah, ichan->channel, i, 0)) == 1) {
1234 //printk("%s: raw nf_pwr[%d] = %d\n", __func__, i, rx_nf_pwr);
1235 nf_pwr[i] = NOISE_PWR_DBM_2_INT(rx_nf_pwr);
1238 if ((rx_nf_cal = ar9300_noise_floor_cal_or_power_get(ah, ichan->channel, i, 1)) == 1) {
1241 //printk("%s: raw nf_cal[%d] = %d\n", __func__, i, rx_nf_cal);
1242 nf_cal[i] = NOISE_PWR_DBM_2_INT(rx_nf_cal);
1249 int32_t ar9300_rx_gain_index_get(struct ath_hal *ah)
1251 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1253 return (eep->base_eep_header.txrxgain) & 0xf; /* bits 3:0 */
1257 int32_t ar9300_tx_gain_index_get(struct ath_hal *ah)
1259 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1261 return (eep->base_eep_header.txrxgain >> 4) & 0xf; /* bits 7:4 */
1264 HAL_BOOL ar9300_internal_regulator_apply(struct ath_hal *ah)
1266 struct ath_hal_9300 *ahp = AH9300(ah);
1267 int internal_regulator = ar9300_eeprom_get(ahp, EEP_INTERNAL_REGULATOR);
1268 int reg_pmu1, reg_pmu2, reg_pmu1_set, reg_pmu2_set;
1269 u_int32_t reg_PMU1, reg_PMU2;
1270 unsigned long eep_addr;
1271 u_int32_t reg_val, reg_usb = 0, reg_pmu = 0;
1272 int usb_valid = 0, pmu_valid = 0;
1273 unsigned char pmu_refv;
1275 if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {
1276 reg_PMU1 = AR_PHY_PMU1_JUPITER;
1277 reg_PMU2 = AR_PHY_PMU2_JUPITER;
1280 reg_PMU1 = AR_PHY_PMU1;
1281 reg_PMU2 = AR_PHY_PMU2;
1284 if (internal_regulator) {
1285 if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah)) {
1286 if (AR_SREV_HORNET(ah)) {
1287 /* Read OTP first */
1288 for (eep_addr = 0x14; ; eep_addr -= 0x10) {
1290 ar9300_otp_read(ah, eep_addr / 4, ®_val, 1);
1292 if ((reg_val & 0x80) == 0x80){
1294 reg_usb = reg_val & 0x000000ff;
1297 if ((reg_val & 0x80000000) == 0x80000000){
1299 reg_pmu = (reg_val & 0xff000000) >> 24;
1302 if (eep_addr == 0x4) {
1308 pmu_refv = reg_pmu & 0xf;
1315 * Usb_phy_ctrl2_tx_cal_en -> 0
1316 * Usb_phy_ctrl2_tx_cal_sel -> 0
1317 * Usb_phy_ctrl2_tx_man_cal -> 0, 1, 3, 7 or 15 from OTP
1321 OS_REG_RMW_FIELD(ah, 0x16c88, AR_PHY_CTRL2_TX_CAL_EN, 0x0);
1322 OS_REG_RMW_FIELD(ah, 0x16c88, AR_PHY_CTRL2_TX_CAL_SEL, 0x0);
1323 OS_REG_RMW_FIELD(ah, 0x16c88,
1324 AR_PHY_CTRL2_TX_MAN_CAL, (reg_usb & 0xf));
1331 /* Follow the MDK settings for Hornet PMU.
1333 * my $Nfdiv = 0x3; # xtal_freq = 25MHz
1334 * my $Nfdiv = 0x4; # xtal_freq = 40MHz
1335 * my $Refv = 0x7; # 0x5:1.22V; 0x8:1.29V
1336 * my $Gm1 = 0x3; #Poseidon $Gm1=1
1338 * my $Cc = 0x1; #Poseidon $Cc=7
1340 * my $ramp_slope = 0x1;
1342 * my $use_local_osc = 0x0;
1343 * my $force_xosc_stable = 0x0;
1344 * my $Selfb = 0x0; #Poseidon $Selfb=1
1345 * my $Filterfb = 0x3; #Poseidon $Filterfb=0
1346 * my $Filtervc = 0x0;
1348 * my $discdel = 0x4;
1351 * $pwd | ($Nfdiv<<1) | ($Refv<<4) | ($Gm1<<8) |
1352 * ($classb<<11) | ($Cc<<14) | ($Rc<<17) | ($ramp_slope<<20) |
1353 * ($Segm<<24) | ($use_local_osc<<26) |
1354 * ($force_xosc_stable<<27) | ($Selfb<<28) | ($Filterfb<<29);
1355 * $reg_PMU2 = $handle->reg_rd("ch0_PMU2");
1356 * $reg_PMU2 = ($reg_PMU2 & 0xfe3fffff) | ($Filtervc<<22);
1357 * $reg_PMU2 = ($reg_PMU2 & 0xe3ffffff) | ($discdel<<26);
1358 * $reg_PMU2 = ($reg_PMU2 & 0x1fffffff) | ($spare<<29);
1360 if (ahp->clk_25mhz) {
1362 (3 << 1) | (pmu_refv << 4) | (3 << 8) | (0 << 11) |
1363 (1 << 14) | (6 << 17) | (1 << 20) | (3 << 24) |
1364 (0 << 26) | (0 << 27) | (0 << 28) | (0 << 29);
1366 if (AR_SREV_POSEIDON(ah)) {
1368 (5 << 1) | (7 << 4) | (2 << 8) | (0 << 11) |
1369 (2 << 14) | (6 << 17) | (1 << 20) | (3 << 24) |
1370 (0 << 26) | (0 << 27) | (1 << 28) | (0 << 29) ;
1373 (4 << 1) | (7 << 4) | (3 << 8) | (0 << 11) |
1374 (1 << 14) | (6 << 17) | (1 << 20) | (3 << 24) |
1375 (0 << 26) | (0 << 27) | (0 << 28) | (0 << 29) ;
1378 OS_REG_RMW_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM, 0x0);
1380 OS_REG_WRITE(ah, reg_PMU1, reg_pmu1_set); /* 0x638c8376 */
1381 reg_pmu1 = OS_REG_READ(ah, reg_PMU1);
1382 while (reg_pmu1 != reg_pmu1_set) {
1383 OS_REG_WRITE(ah, reg_PMU1, reg_pmu1_set); /* 0x638c8376 */
1385 reg_pmu1 = OS_REG_READ(ah, reg_PMU1);
1389 (OS_REG_READ(ah, reg_PMU2) & (~0xFFC00000)) | (4 << 26);
1390 OS_REG_WRITE(ah, reg_PMU2, reg_pmu2_set);
1391 reg_pmu2 = OS_REG_READ(ah, reg_PMU2);
1392 while (reg_pmu2 != reg_pmu2_set) {
1393 OS_REG_WRITE(ah, reg_PMU2, reg_pmu2_set);
1395 reg_pmu2 = OS_REG_READ(ah, reg_PMU2);
1398 (OS_REG_READ(ah, reg_PMU2) & (~0x00200000)) | (1 << 21);
1399 OS_REG_WRITE(ah, reg_PMU2, reg_pmu2_set);
1400 reg_pmu2 = OS_REG_READ(ah, reg_PMU2);
1401 while (reg_pmu2 != reg_pmu2_set) {
1402 OS_REG_WRITE(ah, reg_PMU2, reg_pmu2_set);
1404 reg_pmu2 = OS_REG_READ(ah, reg_PMU2);
1407 } else if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {
1408 /* Internal regulator is ON. Write swreg register. */
1409 int swreg = ar9300_eeprom_get(ahp, EEP_SWREG);
1410 OS_REG_WRITE(ah, reg_PMU1, swreg);
1412 /* Internal regulator is ON. Write swreg register. */
1413 int swreg = ar9300_eeprom_get(ahp, EEP_SWREG);
1414 OS_REG_WRITE(ah, AR_RTC_REG_CONTROL1,
1415 OS_REG_READ(ah, AR_RTC_REG_CONTROL1) &
1416 (~AR_RTC_REG_CONTROL1_SWREG_PROGRAM));
1417 OS_REG_WRITE(ah, AR_RTC_REG_CONTROL0, swreg);
1418 /* Set REG_CONTROL1.SWREG_PROGRAM */
1419 OS_REG_WRITE(ah, AR_RTC_REG_CONTROL1,
1420 OS_REG_READ(ah, AR_RTC_REG_CONTROL1) |
1421 AR_RTC_REG_CONTROL1_SWREG_PROGRAM);
1424 if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah)) {
1425 OS_REG_RMW_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM, 0x0);
1426 reg_pmu2 = OS_REG_READ_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM);
1429 reg_pmu2 = OS_REG_READ_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM);
1431 OS_REG_RMW_FIELD(ah, reg_PMU1, AR_PHY_PMU1_PWD, 0x1);
1432 reg_pmu1 = OS_REG_READ_FIELD(ah, reg_PMU1, AR_PHY_PMU1_PWD);
1435 reg_pmu1 = OS_REG_READ_FIELD(ah, reg_PMU1, AR_PHY_PMU1_PWD);
1437 OS_REG_RMW_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM, 0x1);
1438 reg_pmu2 = OS_REG_READ_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM);
1441 reg_pmu2 = OS_REG_READ_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM);
1443 } else if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {
1444 OS_REG_RMW_FIELD(ah, reg_PMU1, AR_PHY_PMU1_PWD, 0x1);
1446 OS_REG_WRITE(ah, AR_RTC_SLEEP_CLK,
1447 (OS_REG_READ(ah, AR_RTC_SLEEP_CLK) |
1448 AR_RTC_FORCE_SWREG_PRD | AR_RTC_PCIE_RST_PWDN_EN));
1455 HAL_BOOL ar9300_drive_strength_apply(struct ath_hal *ah)
1457 struct ath_hal_9300 *ahp = AH9300(ah);
1461 drive_strength = ar9300_eeprom_get(ahp, EEP_DRIVE_STRENGTH);
1462 if (drive_strength) {
1463 reg = OS_REG_READ(ah, AR_PHY_65NM_CH0_BIAS1);
1471 OS_REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS1, reg);
1473 reg = OS_REG_READ(ah, AR_PHY_65NM_CH0_BIAS2);
1484 OS_REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS2, reg);
1486 reg = OS_REG_READ(ah, AR_PHY_65NM_CH0_BIAS4);
1491 OS_REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS4, reg);
1496 int32_t ar9300_xpa_bias_level_get(struct ath_hal *ah, HAL_BOOL is_2ghz)
1498 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1500 return eep->modal_header_2g.xpa_bias_lvl;
1502 return eep->modal_header_5g.xpa_bias_lvl;
1506 HAL_BOOL ar9300_xpa_bias_level_apply(struct ath_hal *ah, HAL_BOOL is_2ghz)
1509 * In ar9330 emu, we can't access radio registers,
1510 * merlin is used for radio part.
1513 bias = ar9300_xpa_bias_level_get(ah, is_2ghz);
1515 if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah) || AR_SREV_WASP(ah)) {
1516 OS_REG_RMW_FIELD(ah,
1517 AR_HORNET_CH0_TOP2, AR_HORNET_CH0_TOP2_XPABIASLVL, bias);
1518 } else if (AR_SREV_SCORPION(ah)) {
1519 OS_REG_RMW_FIELD(ah,
1520 AR_SCORPION_CH0_TOP, AR_SCORPION_CH0_TOP_XPABIASLVL, bias);
1521 } else if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {
1522 OS_REG_RMW_FIELD(ah,
1523 AR_PHY_65NM_CH0_TOP_JUPITER, AR_PHY_65NM_CH0_TOP_XPABIASLVL, bias);
1525 OS_REG_RMW_FIELD(ah,
1526 AR_PHY_65NM_CH0_TOP, AR_PHY_65NM_CH0_TOP_XPABIASLVL, bias);
1527 OS_REG_RMW_FIELD(ah,
1528 AR_PHY_65NM_CH0_THERM, AR_PHY_65NM_CH0_THERM_XPABIASLVL_MSB,
1530 OS_REG_RMW_FIELD(ah,
1531 AR_PHY_65NM_CH0_THERM, AR_PHY_65NM_CH0_THERM_XPASHORT2GND, 1);
1536 u_int32_t ar9300_ant_ctrl_common_get(struct ath_hal *ah, HAL_BOOL is_2ghz)
1538 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1540 return eep->modal_header_2g.ant_ctrl_common;
1542 return eep->modal_header_5g.ant_ctrl_common;
1546 ar9300_switch_com_spdt_get(struct ath_hal *ah, HAL_BOOL is_2ghz)
1548 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1550 return eep->modal_header_2g.switchcomspdt;
1552 return eep->modal_header_5g.switchcomspdt;
1555 u_int32_t ar9300_ant_ctrl_common2_get(struct ath_hal *ah, HAL_BOOL is_2ghz)
1557 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1559 return eep->modal_header_2g.ant_ctrl_common2;
1561 return eep->modal_header_5g.ant_ctrl_common2;
1565 u_int16_t ar9300_ant_ctrl_chain_get(struct ath_hal *ah, int chain,
1568 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1569 if (chain >= 0 && chain < OSPREY_MAX_CHAINS) {
1571 return eep->modal_header_2g.ant_ctrl_chain[chain];
1573 return eep->modal_header_5g.ant_ctrl_chain[chain];
1580 * Select the usage of antenna via the RF switch.
1581 * Default values are loaded from eeprom.
1583 HAL_BOOL ar9300_ant_swcom_sel(struct ath_hal *ah, u_int8_t ops,
1584 u_int32_t *common_tbl1, u_int32_t *common_tbl2)
1586 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1587 struct ath_hal_private *ap = AH_PRIVATE(ah);
1588 const struct ieee80211_channel *curchan = ap->ah_curchan;
1594 if (AR_SREV_JUPITER(ah) || AR_SREV_SCORPION(ah))
1600 #define AR_SWITCH_TABLE_COM_ALL (0xffff)
1601 #define AR_SWITCH_TABLE_COM_ALL_S (0)
1602 #define AR_SWITCH_TABLE_COM2_ALL (0xffffff)
1603 #define AR_SWITCH_TABLE_COM2_ALL_S (0)
1605 case ANT_SELECT_OPS_GET:
1606 *common_tbl1 = OS_REG_READ_FIELD(ah, AR_PHY_SWITCH_COM,
1607 AR_SWITCH_TABLE_COM_ALL);
1608 *common_tbl2 = OS_REG_READ_FIELD(ah, AR_PHY_SWITCH_COM_2,
1609 AR_SWITCH_TABLE_COM2_ALL);
1611 case ANT_SELECT_OPS_SET:
1612 OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM,
1613 AR_SWITCH_TABLE_COM_ALL, *common_tbl1);
1614 OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2,
1615 AR_SWITCH_TABLE_COM2_ALL, *common_tbl2);
1617 /* write back to eeprom */
1618 if (IEEE80211_IS_CHAN_2GHZ(curchan)) {
1619 eep->modal_header_2g.ant_ctrl_common = *common_tbl1;
1620 eep->modal_header_2g.ant_ctrl_common2 = *common_tbl2;
1622 eep->modal_header_5g.ant_ctrl_common = *common_tbl1;
1623 eep->modal_header_5g.ant_ctrl_common2 = *common_tbl2;
1634 HAL_BOOL ar9300_ant_ctrl_apply(struct ath_hal *ah, HAL_BOOL is_2ghz)
1637 struct ath_hal_9300 *ahp = AH9300(ah);
1639 struct ath_hal_private *ahpriv = AH_PRIVATE(ah);
1640 #if ATH_ANT_DIV_COMB
1641 HAL_CAPABILITIES *pcap = &ahpriv->ah_caps;
1642 #endif /* ATH_ANT_DIV_COMB */
1643 u_int32_t xlan_gpio_cfg;
1646 if (AR_SREV_POSEIDON(ah)) {
1647 xlan_gpio_cfg = ah->ah_config.ath_hal_ext_lna_ctl_gpio;
1648 if (xlan_gpio_cfg) {
1649 for (i = 0; i < 32; i++) {
1650 if (xlan_gpio_cfg & (1 << i)) {
1651 ath_hal_gpioCfgOutput(ah, i,
1652 HAL_GPIO_OUTPUT_MUX_PCIE_ATTENTION_LED);
1657 #define AR_SWITCH_TABLE_COM_ALL (0xffff)
1658 #define AR_SWITCH_TABLE_COM_ALL_S (0)
1659 #define AR_SWITCH_TABLE_COM_JUPITER_ALL (0xffffff)
1660 #define AR_SWITCH_TABLE_COM_JUPITER_ALL_S (0)
1661 #define AR_SWITCH_TABLE_COM_SCORPION_ALL (0xffffff)
1662 #define AR_SWITCH_TABLE_COM_SCORPION_ALL_S (0)
1663 #define AR_SWITCH_TABLE_COM_HONEYBEE_ALL (0xffffff)
1664 #define AR_SWITCH_TABLE_COM_HONEYBEE_ALL_S (0)
1665 #define AR_SWITCH_TABLE_COM_SPDT (0x00f00000)
1666 value = ar9300_ant_ctrl_common_get(ah, is_2ghz);
1667 if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {
1668 if (AR_SREV_JUPITER_10(ah)) {
1669 /* Force SPDT setting for Jupiter 1.0 chips. */
1670 value &= ~AR_SWITCH_TABLE_COM_SPDT;
1671 value |= 0x00100000;
1673 OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM,
1674 AR_SWITCH_TABLE_COM_JUPITER_ALL, value);
1676 else if (AR_SREV_SCORPION(ah)) {
1677 OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM,
1678 AR_SWITCH_TABLE_COM_SCORPION_ALL, value);
1680 else if (AR_SREV_HONEYBEE(ah)) {
1681 OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM,
1682 AR_SWITCH_TABLE_COM_HONEYBEE_ALL, value);
1685 OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM,
1686 AR_SWITCH_TABLE_COM_ALL, value);
1689 * Jupiter2.0 defines new switch table for BT/WLAN,
1690 * here's new field name in WB222.ref for both 2G and 5G.
1691 * Register: [GLB_CONTROL] GLB_CONTROL (@0x20044)
1692 * 15:12 R/W SWITCH_TABLE_COM_SPDT_WLAN_RX SWITCH_TABLE_COM_SPDT_WLAN_RX
1693 * 11:8 R/W SWITCH_TABLE_COM_SPDT_WLAN_TX SWITCH_TABLE_COM_SPDT_WLAN_TX
1694 * 7:4 R/W SWITCH_TABLE_COM_SPDT_WLAN_IDLE SWITCH_TABLE_COM_SPDT_WLAN_IDLE
1696 #define AR_SWITCH_TABLE_COM_SPDT_ALL (0x0000fff0)
1697 #define AR_SWITCH_TABLE_COM_SPDT_ALL_S (4)
1698 if (AR_SREV_JUPITER_20_OR_LATER(ah) || AR_SREV_APHRODITE(ah)) {
1699 value = ar9300_switch_com_spdt_get(ah, is_2ghz);
1700 OS_REG_RMW_FIELD(ah, AR_GLB_CONTROL,
1701 AR_SWITCH_TABLE_COM_SPDT_ALL, value);
1703 OS_REG_SET_BIT(ah, AR_GLB_CONTROL,
1704 AR_BTCOEX_CTRL_SPDT_ENABLE);
1705 //OS_REG_SET_BIT(ah, AR_GLB_CONTROL,
1706 // AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
1709 #define AR_SWITCH_TABLE_COM2_ALL (0xffffff)
1710 #define AR_SWITCH_TABLE_COM2_ALL_S (0)
1711 value = ar9300_ant_ctrl_common2_get(ah, is_2ghz);
1712 #if ATH_ANT_DIV_COMB
1713 if ( AR_SREV_POSEIDON(ah) && (ahp->ah_lna_div_use_bt_ant_enable == TRUE) ) {
1714 value &= ~AR_SWITCH_TABLE_COM2_ALL;
1715 value |= ah->ah_config.ath_hal_ant_ctrl_comm2g_switch_enable;
1716 HALDEBUG(ah, HAL_DEBUG_RESET, "%s: com2=0x%08x\n", __func__, value)
1718 #endif /* ATH_ANT_DIV_COMB */
1719 OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2, AR_SWITCH_TABLE_COM2_ALL, value);
1721 #define AR_SWITCH_TABLE_ALL (0xfff)
1722 #define AR_SWITCH_TABLE_ALL_S (0)
1723 value = ar9300_ant_ctrl_chain_get(ah, 0, is_2ghz);
1724 OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_CHAIN_0, AR_SWITCH_TABLE_ALL, value);
1726 if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah) && !AR_SREV_APHRODITE(ah)) {
1727 value = ar9300_ant_ctrl_chain_get(ah, 1, is_2ghz);
1728 OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_CHAIN_1, AR_SWITCH_TABLE_ALL, value);
1730 if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah)) {
1731 value = ar9300_ant_ctrl_chain_get(ah, 2, is_2ghz);
1732 OS_REG_RMW_FIELD(ah,
1733 AR_PHY_SWITCH_CHAIN_2, AR_SWITCH_TABLE_ALL, value);
1736 if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah)) {
1737 value = ar9300_eeprom_get(ahp, EEP_ANTDIV_control);
1738 /* main_lnaconf, alt_lnaconf, main_tb, alt_tb */
1739 regval = OS_REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
1740 regval &= (~ANT_DIV_CONTROL_ALL); /* clear bit 25~30 */
1741 regval |= (value & 0x3f) << ANT_DIV_CONTROL_ALL_S;
1743 regval &= (~MULTICHAIN_GAIN_CTRL__ENABLE_ANT_DIV_LNADIV__MASK);
1744 regval |= ((value >> 6) & 0x1) <<
1745 MULTICHAIN_GAIN_CTRL__ENABLE_ANT_DIV_LNADIV__SHIFT;
1746 #if ATH_ANT_DIV_COMB
1747 if ( AR_SREV_POSEIDON(ah) && (ahp->ah_lna_div_use_bt_ant_enable == TRUE) ) {
1748 regval |= ANT_DIV_ENABLE;
1750 #endif /* ATH_ANT_DIV_COMB */
1751 OS_REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
1753 /* enable fast_div */
1754 regval = OS_REG_READ(ah, AR_PHY_CCK_DETECT);
1755 regval &= (~BBB_SIG_DETECT__ENABLE_ANT_FAST_DIV__MASK);
1756 regval |= ((value >> 7) & 0x1) <<
1757 BBB_SIG_DETECT__ENABLE_ANT_FAST_DIV__SHIFT;
1758 #if ATH_ANT_DIV_COMB
1759 if ( AR_SREV_POSEIDON(ah) && (ahp->ah_lna_div_use_bt_ant_enable == TRUE) ) {
1760 regval |= FAST_DIV_ENABLE;
1762 #endif /* ATH_ANT_DIV_COMB */
1763 OS_REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
1766 #if ATH_ANT_DIV_COMB
1767 if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON_11_OR_LATER(ah)) {
1768 if (pcap->halAntDivCombSupport) {
1769 /* If support DivComb, set MAIN to LNA1, ALT to LNA2 at beginning */
1770 regval = OS_REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
1771 /* clear bit 25~30 main_lnaconf, alt_lnaconf, main_tb, alt_tb */
1772 regval &= (~(MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__MASK |
1773 MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__MASK |
1774 MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_GAINTB__MASK |
1775 MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_GAINTB__MASK));
1776 regval |= (HAL_ANT_DIV_COMB_LNA1 <<
1777 MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__SHIFT);
1778 regval |= (HAL_ANT_DIV_COMB_LNA2 <<
1779 MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__SHIFT);
1780 OS_REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
1784 #endif /* ATH_ANT_DIV_COMB */
1785 if (AR_SREV_POSEIDON(ah) && ( ahp->ah_diversity_control == HAL_ANT_FIXED_A
1786 || ahp->ah_diversity_control == HAL_ANT_FIXED_B))
1788 u_int32_t reg_val = OS_REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
1789 reg_val &= ~(MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__MASK |
1790 MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__MASK |
1791 MULTICHAIN_GAIN_CTRL__ANT_FAST_DIV_BIAS__MASK |
1792 MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_GAINTB__MASK |
1793 MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_GAINTB__MASK );
1795 switch (ahp->ah_diversity_control) {
1796 case HAL_ANT_FIXED_A:
1797 /* Enable first antenna only */
1798 reg_val |= (HAL_ANT_DIV_COMB_LNA1 <<
1799 MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__SHIFT);
1800 reg_val |= (HAL_ANT_DIV_COMB_LNA2 <<
1801 MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__SHIFT);
1802 /* main/alt gain table and Fast Div Bias all set to 0 */
1803 OS_REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, reg_val);
1804 regval = OS_REG_READ(ah, AR_PHY_CCK_DETECT);
1805 regval &= (~BBB_SIG_DETECT__ENABLE_ANT_FAST_DIV__MASK);
1806 OS_REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
1808 case HAL_ANT_FIXED_B:
1809 /* Enable second antenna only, after checking capability */
1810 reg_val |= (HAL_ANT_DIV_COMB_LNA2 <<
1811 MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__SHIFT);
1812 reg_val |= (HAL_ANT_DIV_COMB_LNA1 <<
1813 MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__SHIFT);
1814 /* main/alt gain table and Fast Div all set to 0 */
1815 OS_REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, reg_val);
1816 regval = OS_REG_READ(ah, AR_PHY_CCK_DETECT);
1817 regval &= (~BBB_SIG_DETECT__ENABLE_ANT_FAST_DIV__MASK);
1818 OS_REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
1819 /* For WB225, need to swith ANT2 from BT to Wifi
1820 * This will not affect HB125 LNA diversity feature.
1822 HALDEBUG(ah, HAL_DEBUG_RESET, "%s: com2=0x%08x\n", __func__,
1823 ah->ah_config.ath_hal_ant_ctrl_comm2g_switch_enable)
1824 OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2, AR_SWITCH_TABLE_COM2_ALL,
1825 ah->ah_config.ath_hal_ant_ctrl_comm2g_switch_enable);
1835 ar9300_attenuation_chain_get(struct ath_hal *ah, int chain, u_int16_t channel)
1839 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1840 if (chain >= 0 && chain < OSPREY_MAX_CHAINS) {
1841 if (channel < 4000) {
1842 return eep->modal_header_2g.xatten1_db[chain];
1844 if (eep->base_ext2.xatten1_db_low[chain] != 0) {
1845 t[0] = eep->base_ext2.xatten1_db_low[chain];
1847 t[1] = eep->modal_header_5g.xatten1_db[chain];
1849 t[2] = eep->base_ext2.xatten1_db_high[chain];
1851 value = interpolate(channel, f, t, 3);
1854 return eep->modal_header_5g.xatten1_db[chain];
1862 ar9300_attenuation_margin_chain_get(struct ath_hal *ah, int chain,
1867 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
1868 if (chain >= 0 && chain < OSPREY_MAX_CHAINS) {
1869 if (channel < 4000) {
1870 return eep->modal_header_2g.xatten1_margin[chain];
1872 if (eep->base_ext2.xatten1_margin_low[chain] != 0) {
1873 t[0] = eep->base_ext2.xatten1_margin_low[chain];
1875 t[1] = eep->modal_header_5g.xatten1_margin[chain];
1877 t[2] = eep->base_ext2.xatten1_margin_high[chain];
1879 value = interpolate(channel, f, t, 3);
1882 return eep->modal_header_5g.xatten1_margin[chain];
1890 HAL_BOOL ar9300_attenuation_apply(struct ath_hal *ah, u_int16_t channel)
1893 // struct ath_hal_private *ahpriv = AH_PRIVATE(ah);
1895 /* Test value. if 0 then attenuation is unused. Don't load anything. */
1896 value = ar9300_attenuation_chain_get(ah, 0, channel);
1897 OS_REG_RMW_FIELD(ah,
1898 AR_PHY_EXT_ATTEN_CTL_0, AR_PHY_EXT_ATTEN_CTL_XATTEN1_DB, value);
1899 value = ar9300_attenuation_margin_chain_get(ah, 0, channel);
1900 if (ar9300_rx_gain_index_get(ah) == 0
1901 && ah->ah_config.ath_hal_ext_atten_margin_cfg)
1905 OS_REG_RMW_FIELD(ah,
1906 AR_PHY_EXT_ATTEN_CTL_0, AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN, value);
1908 if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {
1909 value = ar9300_attenuation_chain_get(ah, 1, channel);
1910 OS_REG_RMW_FIELD(ah,
1911 AR_PHY_EXT_ATTEN_CTL_1, AR_PHY_EXT_ATTEN_CTL_XATTEN1_DB, value);
1912 value = ar9300_attenuation_margin_chain_get(ah, 1, channel);
1913 OS_REG_RMW_FIELD(ah,
1914 AR_PHY_EXT_ATTEN_CTL_1, AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,
1916 if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah)&& !AR_SREV_HONEYBEE(ah) ) {
1917 value = ar9300_attenuation_chain_get(ah, 2, channel);
1918 OS_REG_RMW_FIELD(ah,
1919 AR_PHY_EXT_ATTEN_CTL_2, AR_PHY_EXT_ATTEN_CTL_XATTEN1_DB, value);
1920 value = ar9300_attenuation_margin_chain_get(ah, 2, channel);
1921 OS_REG_RMW_FIELD(ah,
1922 AR_PHY_EXT_ATTEN_CTL_2, AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,
1930 ar9300_attenuation_apply(struct ath_hal *ah, u_int16_t channel)
1934 uint32_t ext_atten_reg[3] = {
1935 AR_PHY_EXT_ATTEN_CTL_0,
1936 AR_PHY_EXT_ATTEN_CTL_1,
1937 AR_PHY_EXT_ATTEN_CTL_2
1941 * If it's an AR9462 and we're receiving on the second
1942 * chain only, set the chain 0 details from chain 1
1945 * This is from ath9k.
1947 if (AR_SREV_JUPITER(ah) && (AH9300(ah)->ah_rx_chainmask == 0x2)) {
1948 value = ar9300_attenuation_chain_get(ah, 1, channel);
1949 OS_REG_RMW_FIELD(ah, ext_atten_reg[0],
1950 AR_PHY_EXT_ATTEN_CTL_XATTEN1_DB, value);
1951 value = ar9300_attenuation_margin_chain_get(ah, 1, channel);
1952 OS_REG_RMW_FIELD(ah, ext_atten_reg[0],
1953 AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN, value);
1957 * Now, loop over the configured transmit chains and
1958 * load in the attenuation/margin settings as appropriate.
1960 for (i = 0; i < 3; i++) {
1961 if ((AH9300(ah)->ah_tx_chainmask & (1 << i)) == 0)
1964 value = ar9300_attenuation_chain_get(ah, i, channel);
1965 OS_REG_RMW_FIELD(ah, ext_atten_reg[i],
1966 AR_PHY_EXT_ATTEN_CTL_XATTEN1_DB,
1969 if (AR_SREV_POSEIDON(ah) &&
1970 (ar9300_rx_gain_index_get(ah) == 0) &&
1971 ah->ah_config.ath_hal_ext_atten_margin_cfg) {
1974 value = ar9300_attenuation_margin_chain_get(ah, 0,
1979 * I'm not sure why it's loading in this setting into
1980 * the chain 0 margin regardless of the current chain.
1982 if (ah->ah_config.ath_hal_min_gainidx)
1983 OS_REG_RMW_FIELD(ah,
1984 AR_PHY_EXT_ATTEN_CTL_0,
1985 AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,
1988 OS_REG_RMW_FIELD(ah,
1990 AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,
1998 static u_int16_t ar9300_quick_drop_get(struct ath_hal *ah,
1999 int chain, u_int16_t channel)
2003 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
2005 if (channel < 4000) {
2006 return eep->modal_header_2g.quick_drop;
2008 t[0] = eep->base_ext1.quick_drop_low;
2010 t[1] = eep->modal_header_5g.quick_drop;
2012 t[2] = eep->base_ext1.quick_drop_high;
2014 value = interpolate(channel, f, t, 3);
2020 static HAL_BOOL ar9300_quick_drop_apply(struct ath_hal *ah, u_int16_t channel)
2022 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
2025 // Test value. if 0 then quickDrop is unused. Don't load anything.
2027 if (eep->base_eep_header.misc_configuration & 0x10)
2029 if (AR_SREV_OSPREY(ah) || AR_SREV_AR9580(ah) || AR_SREV_WASP(ah))
2031 value = ar9300_quick_drop_get(ah, 0, channel);
2032 OS_REG_RMW_FIELD(ah, AR_PHY_AGC, AR_PHY_AGC_QUICK_DROP, value);
2038 static u_int16_t ar9300_tx_end_to_xpa_off_get(struct ath_hal *ah, u_int16_t channel)
2040 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
2042 if (channel < 4000) {
2043 return eep->modal_header_2g.tx_end_to_xpa_off;
2045 return eep->modal_header_5g.tx_end_to_xpa_off;
2049 static HAL_BOOL ar9300_tx_end_to_xpab_off_apply(struct ath_hal *ah, u_int16_t channel)
2053 value = ar9300_tx_end_to_xpa_off_get(ah, channel);
2054 /* Apply to both xpaa and xpab */
2055 if (AR_SREV_OSPREY(ah) || AR_SREV_AR9580(ah) || AR_SREV_WASP(ah))
2057 OS_REG_RMW_FIELD(ah, AR_PHY_XPA_TIMING_CTL,
2058 AR_PHY_XPA_TIMING_CTL_TX_END_XPAB_OFF, value);
2059 OS_REG_RMW_FIELD(ah, AR_PHY_XPA_TIMING_CTL,
2060 AR_PHY_XPA_TIMING_CTL_TX_END_XPAA_OFF, value);
2066 ar9300_eeprom_cal_pier_get(struct ath_hal *ah, int mode, int ipier, int ichain,
2067 int *pfrequency, int *pcorrection, int *ptemperature, int *pvoltage)
2069 u_int8_t *p_cal_pier;
2070 OSP_CAL_DATA_PER_FREQ_OP_LOOP *p_cal_pier_struct;
2072 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
2074 if (ichain >= OSPREY_MAX_CHAINS) {
2075 HALDEBUG(ah, HAL_DEBUG_EEPROM,
2076 "%s: Invalid chain index, must be less than %d\n",
2077 __func__, OSPREY_MAX_CHAINS);
2081 if (mode) {/* 5GHz */
2082 if (ipier >= OSPREY_NUM_5G_CAL_PIERS){
2083 HALDEBUG(ah, HAL_DEBUG_EEPROM,
2084 "%s: Invalid 5GHz cal pier index, must be less than %d\n",
2085 __func__, OSPREY_NUM_5G_CAL_PIERS);
2088 p_cal_pier = &(eep->cal_freq_pier_5g[ipier]);
2089 p_cal_pier_struct = &(eep->cal_pier_data_5g[ichain][ipier]);
2092 if (ipier >= OSPREY_NUM_2G_CAL_PIERS){
2093 HALDEBUG(ah, HAL_DEBUG_EEPROM,
2094 "%s: Invalid 2GHz cal pier index, must be less than %d\n",
2095 __func__, OSPREY_NUM_2G_CAL_PIERS);
2099 p_cal_pier = &(eep->cal_freq_pier_2g[ipier]);
2100 p_cal_pier_struct = &(eep->cal_pier_data_2g[ichain][ipier]);
2103 *pfrequency = FBIN2FREQ(*p_cal_pier, is_2ghz);
2104 *pcorrection = p_cal_pier_struct->ref_power;
2105 *ptemperature = p_cal_pier_struct->temp_meas;
2106 *pvoltage = p_cal_pier_struct->volt_meas;
2111 * Apply the recorded correction values.
2114 ar9300_calibration_apply(struct ath_hal *ah, int frequency)
2116 struct ath_hal_9300 *ahp = AH9300(ah);
2118 int ichain, ipier, npier;
2121 int pfrequency, pcorrection, ptemperature, pvoltage;
2122 int bf, factor, plus;
2124 int lfrequency[AR9300_MAX_CHAINS];
2125 int hfrequency[AR9300_MAX_CHAINS];
2127 int lcorrection[AR9300_MAX_CHAINS];
2128 int hcorrection[AR9300_MAX_CHAINS];
2129 int correction[AR9300_MAX_CHAINS];
2131 int ltemperature[AR9300_MAX_CHAINS];
2132 int htemperature[AR9300_MAX_CHAINS];
2133 int temperature[AR9300_MAX_CHAINS];
2135 int lvoltage[AR9300_MAX_CHAINS];
2136 int hvoltage[AR9300_MAX_CHAINS];
2137 int voltage[AR9300_MAX_CHAINS];
2139 mode = (frequency >= 4000);
2140 npier = (mode) ? OSPREY_NUM_5G_CAL_PIERS : OSPREY_NUM_2G_CAL_PIERS;
2142 for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {
2143 lfrequency[ichain] = 0;
2144 hfrequency[ichain] = 100000;
2147 * identify best lower and higher frequency calibration measurement
2149 for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {
2150 for (ipier = 0; ipier < npier; ipier++) {
2151 if (ar9300_eeprom_cal_pier_get(
2152 ah, mode, ipier, ichain,
2153 &pfrequency, &pcorrection, &ptemperature, &pvoltage) == 0)
2155 fdiff = frequency - pfrequency;
2157 * this measurement is higher than our desired frequency
2160 if (hfrequency[ichain] <= 0 ||
2161 hfrequency[ichain] >= 100000 ||
2162 fdiff > (frequency - hfrequency[ichain]))
2165 * new best higher frequency measurement
2167 hfrequency[ichain] = pfrequency;
2168 hcorrection[ichain] = pcorrection;
2169 htemperature[ichain] = ptemperature;
2170 hvoltage[ichain] = pvoltage;
2174 if (lfrequency[ichain] <= 0 ||
2175 fdiff < (frequency - lfrequency[ichain]))
2178 * new best lower frequency measurement
2180 lfrequency[ichain] = pfrequency;
2181 lcorrection[ichain] = pcorrection;
2182 ltemperature[ichain] = ptemperature;
2183 lvoltage[ichain] = pvoltage;
2190 for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {
2191 HALDEBUG(ah, HAL_DEBUG_EEPROM,
2192 "%s: ch=%d f=%d low=%d %d h=%d %d\n",
2193 __func__, ichain, frequency,
2194 lfrequency[ichain], lcorrection[ichain],
2195 hfrequency[ichain], hcorrection[ichain]);
2197 * they're the same, so just pick one
2199 if (hfrequency[ichain] == lfrequency[ichain]) {
2200 correction[ichain] = lcorrection[ichain];
2201 voltage[ichain] = lvoltage[ichain];
2202 temperature[ichain] = ltemperature[ichain];
2203 } else if (frequency - lfrequency[ichain] < 1000) {
2204 /* the low frequency is good */
2205 if (hfrequency[ichain] - frequency < 1000) {
2207 * The high frequency is good too -
2208 * interpolate with round off.
2210 int mult, div, diff;
2211 mult = frequency - lfrequency[ichain];
2212 div = hfrequency[ichain] - lfrequency[ichain];
2214 diff = hcorrection[ichain] - lcorrection[ichain];
2215 bf = 2 * diff * mult / div;
2218 correction[ichain] = lcorrection[ichain] + factor + plus;
2220 diff = htemperature[ichain] - ltemperature[ichain];
2221 bf = 2 * diff * mult / div;
2224 temperature[ichain] = ltemperature[ichain] + factor + plus;
2226 diff = hvoltage[ichain] - lvoltage[ichain];
2227 bf = 2 * diff * mult / div;
2230 voltage[ichain] = lvoltage[ichain] + factor + plus;
2232 /* only low is good, use it */
2233 correction[ichain] = lcorrection[ichain];
2234 temperature[ichain] = ltemperature[ichain];
2235 voltage[ichain] = lvoltage[ichain];
2237 } else if (hfrequency[ichain] - frequency < 1000) {
2238 /* only high is good, use it */
2239 correction[ichain] = hcorrection[ichain];
2240 temperature[ichain] = htemperature[ichain];
2241 voltage[ichain] = hvoltage[ichain];
2243 /* nothing is good, presume 0???? */
2244 correction[ichain] = 0;
2245 temperature[ichain] = 0;
2246 voltage[ichain] = 0;
2250 /* GreenTx isn't currently supported */
2252 if (ah->ah_config.ath_hal_sta_update_tx_pwr_enable) {
2253 if (AR_SREV_POSEIDON(ah)) {
2254 /* Get calibrated OLPC gain delta value for GreenTx */
2255 ahp->ah_db2[POSEIDON_STORED_REG_G2_OLPC_OFFSET] =
2256 (u_int32_t) correction[0];
2260 ar9300_power_control_override(
2261 ah, frequency, correction, voltage, temperature);
2262 HALDEBUG(ah, HAL_DEBUG_EEPROM,
2263 "%s: for frequency=%d, calibration correction = %d %d %d\n",
2264 __func__, frequency, correction[0], correction[1], correction[2]);
2270 ar9300_power_control_override(struct ath_hal *ah, int frequency,
2271 int *correction, int *voltage, int *temperature)
2274 int temp_slope_1 = 0;
2275 int temp_slope_2 = 0;
2276 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
2277 int32_t f[8], t[8],t1[3], t2[3];
2280 OS_REG_RMW(ah, AR_PHY_TPC_11_B0,
2281 (correction[0] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),
2282 AR_PHY_TPC_OLPC_GAIN_DELTA);
2283 if (!AR_SREV_POSEIDON(ah)) {
2284 OS_REG_RMW(ah, AR_PHY_TPC_11_B1,
2285 (correction[1] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),
2286 AR_PHY_TPC_OLPC_GAIN_DELTA);
2287 if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {
2288 OS_REG_RMW(ah, AR_PHY_TPC_11_B2,
2289 (correction[2] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),
2290 AR_PHY_TPC_OLPC_GAIN_DELTA);
2294 * enable open loop power control on chip
2296 OS_REG_RMW(ah, AR_PHY_TPC_6_B0,
2297 (3 << AR_PHY_TPC_6_ERROR_EST_MODE_S), AR_PHY_TPC_6_ERROR_EST_MODE);
2298 if (!AR_SREV_POSEIDON(ah)) {
2299 OS_REG_RMW(ah, AR_PHY_TPC_6_B1,
2300 (3 << AR_PHY_TPC_6_ERROR_EST_MODE_S), AR_PHY_TPC_6_ERROR_EST_MODE);
2301 if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {
2302 OS_REG_RMW(ah, AR_PHY_TPC_6_B2,
2303 (3 << AR_PHY_TPC_6_ERROR_EST_MODE_S),
2304 AR_PHY_TPC_6_ERROR_EST_MODE);
2309 * Enable temperature compensation
2310 * Need to use register names
2312 if (frequency < 4000) {
2313 temp_slope = eep->modal_header_2g.temp_slope;
2315 if ((eep->base_eep_header.misc_configuration & 0x20) != 0)
2319 t[i]=eep->base_ext1.tempslopextension[i];
2320 f[i]=FBIN2FREQ(eep->cal_freq_pier_5g[i], 0);
2322 temp_slope=interpolate(frequency,f,t,8);
2326 if(!AR_SREV_SCORPION(ah)) {
2327 if (eep->base_ext2.temp_slope_low != 0) {
2328 t[0] = eep->base_ext2.temp_slope_low;
2330 t[1] = eep->modal_header_5g.temp_slope;
2332 t[2] = eep->base_ext2.temp_slope_high;
2334 temp_slope = interpolate(frequency, f, t, 3);
2336 temp_slope = eep->modal_header_5g.temp_slope;
2340 * Scorpion has individual chain tempslope values
2342 t[0] = eep->base_ext1.tempslopextension[2];
2343 t1[0]= eep->base_ext1.tempslopextension[3];
2344 t2[0]= eep->base_ext1.tempslopextension[4];
2346 t[1] = eep->modal_header_5g.temp_slope;
2347 t1[1]= eep->base_ext1.tempslopextension[0];
2348 t2[1]= eep->base_ext1.tempslopextension[1];
2350 t[2] = eep->base_ext1.tempslopextension[5];
2351 t1[2]= eep->base_ext1.tempslopextension[6];
2352 t2[2]= eep->base_ext1.tempslopextension[7];
2354 temp_slope = interpolate(frequency, f, t, 3);
2355 temp_slope_1=interpolate(frequency, f, t1,3);
2356 temp_slope_2=interpolate(frequency, f, t2,3);
2361 if (!AR_SREV_SCORPION(ah) && !AR_SREV_HONEYBEE(ah)) {
2362 OS_REG_RMW_FIELD(ah,
2363 AR_PHY_TPC_19, AR_PHY_TPC_19_ALPHA_THERM, temp_slope);
2365 /*Scorpion and Honeybee has tempSlope register for each chain*/
2366 /*Check whether temp_compensation feature is enabled or not*/
2367 if (eep->base_eep_header.feature_enable & 0x1){
2368 if(frequency < 4000) {
2369 if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x1) {
2370 OS_REG_RMW_FIELD(ah,
2371 AR_PHY_TPC_19, AR_PHY_TPC_19_ALPHA_THERM,
2372 eep->base_ext2.temp_slope_low);
2374 if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x2) {
2375 OS_REG_RMW_FIELD(ah,
2376 AR_SCORPION_PHY_TPC_19_B1, AR_PHY_TPC_19_ALPHA_THERM,
2379 if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x4) {
2380 OS_REG_RMW_FIELD(ah,
2381 AR_SCORPION_PHY_TPC_19_B2, AR_PHY_TPC_19_ALPHA_THERM,
2382 eep->base_ext2.temp_slope_high);
2385 if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x1) {
2386 OS_REG_RMW_FIELD(ah,
2387 AR_PHY_TPC_19, AR_PHY_TPC_19_ALPHA_THERM,
2390 if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x2) {
2391 OS_REG_RMW_FIELD(ah,
2392 AR_SCORPION_PHY_TPC_19_B1, AR_PHY_TPC_19_ALPHA_THERM,
2395 if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x4) {
2396 OS_REG_RMW_FIELD(ah,
2397 AR_SCORPION_PHY_TPC_19_B2, AR_PHY_TPC_19_ALPHA_THERM,
2402 /* If temp compensation is not enabled, set all registers to 0*/
2403 if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x1) {
2404 OS_REG_RMW_FIELD(ah,
2405 AR_PHY_TPC_19, AR_PHY_TPC_19_ALPHA_THERM, 0);
2407 if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x2) {
2408 OS_REG_RMW_FIELD(ah,
2409 AR_SCORPION_PHY_TPC_19_B1, AR_PHY_TPC_19_ALPHA_THERM, 0);
2411 if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x4) {
2412 OS_REG_RMW_FIELD(ah,
2413 AR_SCORPION_PHY_TPC_19_B2, AR_PHY_TPC_19_ALPHA_THERM, 0);
2417 OS_REG_RMW_FIELD(ah,
2418 AR_PHY_TPC_18, AR_PHY_TPC_18_THERM_CAL_VALUE, temperature[0]);
2423 /**************************************************************
2424 * ar9300_eep_def_get_max_edge_power
2426 * Find the maximum conformance test limit for the given channel and CTL info
2428 static inline u_int16_t
2429 ar9300_eep_def_get_max_edge_power(ar9300_eeprom_t *p_eep_data, u_int16_t freq,
2430 int idx, HAL_BOOL is_2ghz)
2432 u_int16_t twice_max_edge_power = AR9300_MAX_RATE_POWER;
2433 u_int8_t *ctl_freqbin = is_2ghz ?
2434 &p_eep_data->ctl_freqbin_2G[idx][0] :
2435 &p_eep_data->ctl_freqbin_5G[idx][0];
2436 u_int16_t num_edges = is_2ghz ?
2437 OSPREY_NUM_BAND_EDGES_2G : OSPREY_NUM_BAND_EDGES_5G;
2440 /* Get the edge power */
2441 for (i = 0; (i < num_edges) && (ctl_freqbin[i] != AR9300_BCHAN_UNUSED); i++)
2444 * If there's an exact channel match or an inband flag set
2445 * on the lower channel use the given rd_edge_power
2447 if (freq == fbin2freq(ctl_freqbin[i], is_2ghz)) {
2449 twice_max_edge_power =
2450 p_eep_data->ctl_power_data_2g[idx].ctl_edges[i].t_power;
2452 twice_max_edge_power =
2453 p_eep_data->ctl_power_data_5g[idx].ctl_edges[i].t_power;
2456 } else if ((i > 0) && (freq < fbin2freq(ctl_freqbin[i], is_2ghz))) {
2458 if (fbin2freq(ctl_freqbin[i - 1], 1) < freq &&
2459 p_eep_data->ctl_power_data_2g[idx].ctl_edges[i - 1].flag)
2461 twice_max_edge_power =
2462 p_eep_data->ctl_power_data_2g[idx].
2463 ctl_edges[i - 1].t_power;
2466 if (fbin2freq(ctl_freqbin[i - 1], 0) < freq &&
2467 p_eep_data->ctl_power_data_5g[idx].ctl_edges[i - 1].flag)
2469 twice_max_edge_power =
2470 p_eep_data->ctl_power_data_5g[idx].
2471 ctl_edges[i - 1].t_power;
2475 * Leave loop - no more affecting edges possible
2476 * in this monotonic increasing list
2482 * EV89475: EEPROM might contain 0 txpower in CTL table for certain
2483 * 2.4GHz channels. We workaround it by overwriting 60 (30 dBm) here.
2485 if (is_2ghz && (twice_max_edge_power == 0)) {
2486 twice_max_edge_power = 60;
2489 HALASSERT(twice_max_edge_power > 0);
2490 return twice_max_edge_power;
2494 ar9300_eeprom_set_power_per_rate_table(
2496 ar9300_eeprom_t *p_eep_data,
2497 const struct ieee80211_channel *chan,
2498 u_int8_t *p_pwr_array,
2500 u_int16_t antenna_reduction,
2501 u_int16_t twice_max_regulatory_power,
2502 u_int16_t power_limit,
2505 /* Local defines to distinguish between extension and control CTL's */
2506 #define EXT_ADDITIVE (0x8000)
2507 #define CTL_11A_EXT (CTL_11A | EXT_ADDITIVE)
2508 #define CTL_11G_EXT (CTL_11G | EXT_ADDITIVE)
2509 #define CTL_11B_EXT (CTL_11B | EXT_ADDITIVE)
2510 #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
2511 #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */
2512 #define PWRINCR_3_TO_1_CHAIN 9 /* 10*log(3)*2 */
2513 #define PWRINCR_3_TO_2_CHAIN 3 /* floor(10*log(3/2)*2) */
2514 #define PWRINCR_2_TO_1_CHAIN 6 /* 10*log(2)*2 */
2516 static const u_int16_t tp_scale_reduction_table[5] =
2517 { 0, 3, 6, 9, AR9300_MAX_RATE_POWER };
2519 int16_t twice_largest_antenna;
2520 u_int16_t twice_antenna_reduction = 2*antenna_reduction ;
2521 int16_t scaled_power = 0, min_ctl_power, max_reg_allowed_power;
2522 #define SUB_NUM_CTL_MODES_AT_5G_40 2 /* excluding HT40, EXT-OFDM */
2523 #define SUB_NUM_CTL_MODES_AT_2G_40 3 /* excluding HT40, EXT-OFDM, EXT-CCK */
2524 u_int16_t ctl_modes_for11a[] =
2525 {CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40};
2526 u_int16_t ctl_modes_for11g[] =
2527 {CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40};
2528 u_int16_t num_ctl_modes, *p_ctl_mode, ctl_mode, freq;
2529 CHAN_CENTERS centers;
2531 struct ath_hal_9300 *ahp = AH9300(ah);
2532 u_int8_t *ctl_index;
2534 u_int16_t twice_min_edge_power;
2535 u_int16_t twice_max_edge_power = AR9300_MAX_RATE_POWER;
2537 HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, chan);
2541 tx_chainmask = chainmask;
2543 tx_chainmask = ahp->ah_tx_chainmaskopt ?
2544 ahp->ah_tx_chainmaskopt :ahp->ah_tx_chainmask;
2546 ar9300_get_channel_centers(ah, chan, ¢ers);
2549 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
2550 ahp->twice_antenna_gain = p_eep_data->modal_header_2g.antenna_gain;
2552 ahp->twice_antenna_gain = p_eep_data->modal_header_5g.antenna_gain;
2556 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
2557 ahp->twice_antenna_gain = AH_MAX(p_eep_data->modal_header_2g.antenna_gain,
2558 AH_PRIVATE(ah)->ah_antenna_gain_2g);
2560 ahp->twice_antenna_gain = AH_MAX(p_eep_data->modal_header_5g.antenna_gain,
2561 AH_PRIVATE(ah)->ah_antenna_gain_5g);
2565 /* Save max allowed antenna gain to ease future lookups */
2566 ahp->twice_antenna_reduction = twice_antenna_reduction;
2568 /* Deduct antenna gain from EIRP to get the upper limit */
2569 twice_largest_antenna = (int16_t)AH_MIN((twice_antenna_reduction -
2570 ahp->twice_antenna_gain), 0);
2571 max_reg_allowed_power = twice_max_regulatory_power + twice_largest_antenna;
2573 /* Use ah_tp_scale - see bug 30070. */
2574 if (AH_PRIVATE(ah)->ah_tpScale != HAL_TP_SCALE_MAX) {
2575 max_reg_allowed_power -=
2576 (tp_scale_reduction_table[(AH_PRIVATE(ah)->ah_tpScale)] * 2);
2579 scaled_power = AH_MIN(power_limit, max_reg_allowed_power);
2582 * Reduce scaled Power by number of chains active to get to
2583 * per chain tx power level
2585 /* TODO: better value than these? */
2586 switch (ar9300_get_ntxchains(tx_chainmask)) {
2588 ahp->upper_limit[0] = AH_MAX(0, scaled_power);
2591 scaled_power -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
2592 ahp->upper_limit[1] = AH_MAX(0, scaled_power);
2595 scaled_power -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
2596 ahp->upper_limit[2] = AH_MAX(0, scaled_power);
2599 HALASSERT(0); /* Unsupported number of chains */
2602 scaled_power = AH_MAX(0, scaled_power);
2604 /* Get target powers from EEPROM - our baseline for TX Power */
2605 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
2606 /* Setup for CTL modes */
2607 /* CTL_11B, CTL_11G, CTL_2GHT20 */
2609 ARRAY_LENGTH(ctl_modes_for11g) - SUB_NUM_CTL_MODES_AT_2G_40;
2610 p_ctl_mode = ctl_modes_for11g;
2612 if (IEEE80211_IS_CHAN_HT40(chan)) {
2613 num_ctl_modes = ARRAY_LENGTH(ctl_modes_for11g); /* All 2G CTL's */
2616 /* Setup for CTL modes */
2617 /* CTL_11A, CTL_5GHT20 */
2619 ARRAY_LENGTH(ctl_modes_for11a) - SUB_NUM_CTL_MODES_AT_5G_40;
2620 p_ctl_mode = ctl_modes_for11a;
2622 if (IEEE80211_IS_CHAN_HT40(chan)) {
2623 num_ctl_modes = ARRAY_LENGTH(ctl_modes_for11a); /* All 5G CTL's */
2628 * For MIMO, need to apply regulatory caps individually across dynamically
2629 * running modes: CCK, OFDM, HT20, HT40
2631 * The outer loop walks through each possible applicable runtime mode.
2632 * The inner loop walks through each ctl_index entry in EEPROM.
2633 * The ctl value is encoded as [7:4] == test group, [3:0] == test mode.
2636 for (ctl_mode = 0; ctl_mode < num_ctl_modes; ctl_mode++) {
2637 HAL_BOOL is_ht40_ctl_mode =
2638 (p_ctl_mode[ctl_mode] == CTL_5GHT40) ||
2639 (p_ctl_mode[ctl_mode] == CTL_2GHT40);
2640 if (is_ht40_ctl_mode) {
2641 freq = centers.synth_center;
2642 } else if (p_ctl_mode[ctl_mode] & EXT_ADDITIVE) {
2643 freq = centers.ext_center;
2645 freq = centers.ctl_center;
2648 HALDEBUG(ah, HAL_DEBUG_POWER_MGMT,
2649 "LOOP-Mode ctl_mode %d < %d, "
2650 "is_ht40_ctl_mode %d, EXT_ADDITIVE %d\n",
2651 ctl_mode, num_ctl_modes, is_ht40_ctl_mode,
2652 (p_ctl_mode[ctl_mode] & EXT_ADDITIVE));
2653 /* walk through each CTL index stored in EEPROM */
2654 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
2655 ctl_index = p_eep_data->ctl_index_2g;
2656 ctl_num = OSPREY_NUM_CTLS_2G;
2658 ctl_index = p_eep_data->ctl_index_5g;
2659 ctl_num = OSPREY_NUM_CTLS_5G;
2662 for (i = 0; (i < ctl_num) && ctl_index[i]; i++) {
2663 HALDEBUG(ah, HAL_DEBUG_POWER_MGMT,
2664 " LOOP-Ctlidx %d: cfg_ctl 0x%2.2x p_ctl_mode 0x%2.2x "
2665 "ctl_index 0x%2.2x chan %d chanctl 0x%x\n",
2666 i, cfg_ctl, p_ctl_mode[ctl_mode], ctl_index[i],
2667 ichan->channel, ath_hal_getctl(ah, chan));
2671 * compare test group from regulatory channel list
2672 * with test mode from p_ctl_mode list
2674 if ((((cfg_ctl & ~CTL_MODE_M) |
2675 (p_ctl_mode[ctl_mode] & CTL_MODE_M)) == ctl_index[i]) ||
2676 (((cfg_ctl & ~CTL_MODE_M) |
2677 (p_ctl_mode[ctl_mode] & CTL_MODE_M)) ==
2678 ((ctl_index[i] & CTL_MODE_M) | SD_NO_CTL)))
2680 twice_min_edge_power =
2681 ar9300_eep_def_get_max_edge_power(
2682 p_eep_data, freq, i, IEEE80211_IS_CHAN_2GHZ(chan));
2684 HALDEBUG(ah, HAL_DEBUG_POWER_MGMT,
2685 " MATCH-EE_IDX %d: ch %d is2 %d "
2686 "2xMinEdge %d chainmask %d chains %d\n",
2687 i, freq, IEEE80211_IS_CHAN_2GHZ(chan),
2688 twice_min_edge_power, tx_chainmask,
2689 ar9300_get_ntxchains(tx_chainmask));
2691 if ((cfg_ctl & ~CTL_MODE_M) == SD_NO_CTL) {
2693 * Find the minimum of all CTL edge powers
2694 * that apply to this channel
2696 twice_max_edge_power =
2697 AH_MIN(twice_max_edge_power, twice_min_edge_power);
2700 twice_max_edge_power = twice_min_edge_power;
2706 min_ctl_power = (u_int8_t)AH_MIN(twice_max_edge_power, scaled_power);
2708 HALDEBUG(ah, HAL_DEBUG_POWER_MGMT,
2709 " SEL-Min ctl_mode %d p_ctl_mode %d "
2710 "2xMaxEdge %d sP %d min_ctl_pwr %d\n",
2711 ctl_mode, p_ctl_mode[ctl_mode],
2712 twice_max_edge_power, scaled_power, min_ctl_power);
2714 /* Apply ctl mode to correct target power set */
2715 switch (p_ctl_mode[ctl_mode]) {
2717 for (i = ALL_TARGET_LEGACY_1L_5L; i <= ALL_TARGET_LEGACY_11S; i++) {
2719 (u_int8_t)AH_MIN(p_pwr_array[i], min_ctl_power);
2724 for (i = ALL_TARGET_LEGACY_6_24; i <= ALL_TARGET_LEGACY_54; i++) {
2726 (u_int8_t)AH_MIN(p_pwr_array[i], min_ctl_power);
2728 if ((ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_3WIRE) ||
2729 (ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_MCI))
2731 if ((ahp->ah_bt_coex_flag & HAL_BT_COEX_FLAG_LOWER_TX_PWR)
2732 && (ahp->ah_bt_wlan_isolation
2733 < HAL_BT_COEX_ISOLATION_FOR_NO_COEX))
2736 u_int8_t reduce_pow;
2738 reduce_pow = (HAL_BT_COEX_ISOLATION_FOR_NO_COEX
2739 - ahp->ah_bt_wlan_isolation) << 1;
2741 if (reduce_pow <= p_pwr_array[i]) {
2742 p_pwr_array[i] -= reduce_pow;
2745 if ((ahp->ah_bt_coex_flag &
2746 HAL_BT_COEX_FLAG_LOW_ACK_PWR) &&
2747 (i != ALL_TARGET_LEGACY_36) &&
2748 (i != ALL_TARGET_LEGACY_48) &&
2749 (i != ALL_TARGET_LEGACY_54) &&
2750 (p_ctl_mode[ctl_mode] == CTL_11G))
2760 for (i = ALL_TARGET_HT20_0_8_16; i <= ALL_TARGET_HT20_23; i++) {
2762 (u_int8_t)AH_MIN(p_pwr_array[i], min_ctl_power);
2764 if (((ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_3WIRE) ||
2765 (ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_MCI)) &&
2766 (ahp->ah_bt_coex_flag & HAL_BT_COEX_FLAG_LOWER_TX_PWR) &&
2767 (ahp->ah_bt_wlan_isolation
2768 < HAL_BT_COEX_ISOLATION_FOR_NO_COEX)) {
2770 u_int8_t reduce_pow = (HAL_BT_COEX_ISOLATION_FOR_NO_COEX
2771 - ahp->ah_bt_wlan_isolation) << 1;
2773 if (reduce_pow <= p_pwr_array[i]) {
2774 p_pwr_array[i] -= reduce_pow;
2778 else if ((ahp->ah_bt_coex_flag &
2779 HAL_BT_COEX_FLAG_MCI_MAX_TX_PWR) &&
2780 (p_ctl_mode[ctl_mode] == CTL_2GHT20) &&
2781 (ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_MCI))
2785 max_pwr = MS(mci_concur_tx_max_pwr[2][1],
2786 ATH_MCI_CONCUR_TX_LOWEST_PWR_MASK);
2787 if (p_pwr_array[i] > max_pwr) {
2788 p_pwr_array[i] = max_pwr;
2797 target_power_cck_ext.t_pow2x[0] = (u_int8_t)
2798 AH_MIN(target_power_cck_ext.t_pow2x[0], min_ctl_power);
2799 #endif /* NOT_YET */
2804 target_power_ofdm_ext.t_pow2x[0] = (u_int8_t)
2805 AH_MIN(target_power_ofdm_ext.t_pow2x[0], min_ctl_power);
2806 #endif /* NOT_YET */
2810 for (i = ALL_TARGET_HT40_0_8_16; i <= ALL_TARGET_HT40_23; i++) {
2811 p_pwr_array[i] = (u_int8_t)
2812 AH_MIN(p_pwr_array[i], min_ctl_power);
2814 if (((ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_3WIRE) ||
2815 (ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_MCI)) &&
2816 (ahp->ah_bt_coex_flag & HAL_BT_COEX_FLAG_LOWER_TX_PWR) &&
2817 (ahp->ah_bt_wlan_isolation
2818 < HAL_BT_COEX_ISOLATION_FOR_NO_COEX)) {
2820 u_int8_t reduce_pow = (HAL_BT_COEX_ISOLATION_FOR_NO_COEX
2821 - ahp->ah_bt_wlan_isolation) << 1;
2823 if (reduce_pow <= p_pwr_array[i]) {
2824 p_pwr_array[i] -= reduce_pow;
2828 else if ((ahp->ah_bt_coex_flag &
2829 HAL_BT_COEX_FLAG_MCI_MAX_TX_PWR) &&
2830 (p_ctl_mode[ctl_mode] == CTL_2GHT40) &&
2831 (ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_MCI))
2835 max_pwr = MS(mci_concur_tx_max_pwr[3][1],
2836 ATH_MCI_CONCUR_TX_LOWEST_PWR_MASK);
2837 if (p_pwr_array[i] > max_pwr) {
2838 p_pwr_array[i] = max_pwr;
2849 } /* end ctl mode checking */
2856 #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
2857 #undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
2860 /**************************************************************
2861 * ar9300_eeprom_set_transmit_power
2863 * Set the transmit power in the baseband for the given
2864 * operating channel and mode.
2867 ar9300_eeprom_set_transmit_power(struct ath_hal *ah,
2868 ar9300_eeprom_t *p_eep_data, const struct ieee80211_channel *chan, u_int16_t cfg_ctl,
2869 u_int16_t antenna_reduction, u_int16_t twice_max_regulatory_power,
2870 u_int16_t power_limit)
2872 #define ABS(_x, _y) ((int)_x > (int)_y ? (int)_x - (int)_y : (int)_y - (int)_x)
2873 #define INCREASE_MAXPOW_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
2874 #define INCREASE_MAXPOW_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */
2875 u_int8_t target_power_val_t2[ar9300_rate_size];
2876 u_int8_t target_power_val_t2_eep[ar9300_rate_size];
2877 int16_t twice_array_gain = 0, max_power_level = 0;
2878 struct ath_hal_9300 *ahp = AH9300(ah);
2880 u_int32_t tmp_paprd_rate_mask = 0, *tmp_ptr = NULL;
2881 int paprd_scale_factor = 5;
2882 HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, chan);
2884 u_int8_t *ptr_mcs_rate2power_table_index;
2885 u_int8_t mcs_rate2power_table_index_ht20[24] =
2887 ALL_TARGET_HT20_0_8_16,
2888 ALL_TARGET_HT20_1_3_9_11_17_19,
2889 ALL_TARGET_HT20_1_3_9_11_17_19,
2890 ALL_TARGET_HT20_1_3_9_11_17_19,
2895 ALL_TARGET_HT20_0_8_16,
2896 ALL_TARGET_HT20_1_3_9_11_17_19,
2897 ALL_TARGET_HT20_1_3_9_11_17_19,
2898 ALL_TARGET_HT20_1_3_9_11_17_19,
2903 ALL_TARGET_HT20_0_8_16,
2904 ALL_TARGET_HT20_1_3_9_11_17_19,
2905 ALL_TARGET_HT20_1_3_9_11_17_19,
2906 ALL_TARGET_HT20_1_3_9_11_17_19,
2913 u_int8_t mcs_rate2power_table_index_ht40[24] =
2915 ALL_TARGET_HT40_0_8_16,
2916 ALL_TARGET_HT40_1_3_9_11_17_19,
2917 ALL_TARGET_HT40_1_3_9_11_17_19,
2918 ALL_TARGET_HT40_1_3_9_11_17_19,
2923 ALL_TARGET_HT40_0_8_16,
2924 ALL_TARGET_HT40_1_3_9_11_17_19,
2925 ALL_TARGET_HT40_1_3_9_11_17_19,
2926 ALL_TARGET_HT40_1_3_9_11_17_19,
2931 ALL_TARGET_HT40_0_8_16,
2932 ALL_TARGET_HT40_1_3_9_11_17_19,
2933 ALL_TARGET_HT40_1_3_9_11_17_19,
2934 ALL_TARGET_HT40_1_3_9_11_17_19,
2941 HALDEBUG(ah, HAL_DEBUG_CALIBRATE,
2942 "%s[%d] +++chan %d,cfgctl 0x%04x "
2943 "antenna_reduction 0x%04x, twice_max_regulatory_power 0x%04x "
2944 "power_limit 0x%04x\n",
2945 __func__, __LINE__, ichan->channel, cfg_ctl,
2946 antenna_reduction, twice_max_regulatory_power, power_limit);
2947 ar9300_set_target_power_from_eeprom(ah, ichan->channel, target_power_val_t2);
2949 if (ar9300_eeprom_get(ahp, EEP_PAPRD_ENABLED)) {
2950 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
2951 if (IEEE80211_IS_CHAN_HT40(chan)) {
2952 tmp_paprd_rate_mask =
2953 p_eep_data->modal_header_2g.paprd_rate_mask_ht40;
2954 tmp_ptr = &AH9300(ah)->ah_2g_paprd_rate_mask_ht40;
2956 tmp_paprd_rate_mask =
2957 p_eep_data->modal_header_2g.paprd_rate_mask_ht20;
2958 tmp_ptr = &AH9300(ah)->ah_2g_paprd_rate_mask_ht20;
2961 if (IEEE80211_IS_CHAN_HT40(chan)) {
2962 tmp_paprd_rate_mask =
2963 p_eep_data->modal_header_5g.paprd_rate_mask_ht40;
2964 tmp_ptr = &AH9300(ah)->ah_5g_paprd_rate_mask_ht40;
2966 tmp_paprd_rate_mask =
2967 p_eep_data->modal_header_5g.paprd_rate_mask_ht20;
2968 tmp_ptr = &AH9300(ah)->ah_5g_paprd_rate_mask_ht20;
2971 AH_PAPRD_GET_SCALE_FACTOR(
2972 paprd_scale_factor, p_eep_data, IEEE80211_IS_CHAN_2GHZ(chan), ichan->channel);
2973 HALDEBUG(ah, HAL_DEBUG_CALIBRATE, "%s[%d] paprd_scale_factor %d\n",
2974 __func__, __LINE__, paprd_scale_factor);
2975 /* PAPRD is not done yet, Scale down the EEP power */
2976 if (IEEE80211_IS_CHAN_HT40(chan)) {
2977 ptr_mcs_rate2power_table_index =
2978 &mcs_rate2power_table_index_ht40[0];
2980 ptr_mcs_rate2power_table_index =
2981 &mcs_rate2power_table_index_ht20[0];
2983 if (! ichan->paprd_table_write_done) {
2984 for (i = 0; i < 24; i++) {
2985 /* PAPRD is done yet, so Scale down Power for PAPRD Rates*/
2986 if (tmp_paprd_rate_mask & (1 << i)) {
2987 target_power_val_t2[ptr_mcs_rate2power_table_index[i]] -=
2989 HALDEBUG(ah, HAL_DEBUG_CALIBRATE,
2991 "Scale down target_power_val_t2[%d] = 0x%04x\n",
2993 ichan->channel, i, target_power_val_t2[i]);
2997 HALDEBUG(ah, HAL_DEBUG_CALIBRATE,
2998 "%s[%d]: PAPRD Done No TGT PWR Scaling\n", __func__, __LINE__);
3002 /* Save the Target power for future use */
3003 OS_MEMCPY(target_power_val_t2_eep, target_power_val_t2,
3004 sizeof(target_power_val_t2));
3005 ar9300_eeprom_set_power_per_rate_table(ah, p_eep_data, chan,
3006 target_power_val_t2, cfg_ctl,
3008 twice_max_regulatory_power,
3011 /* Save this for quick lookup */
3012 ahp->reg_dmn = ath_hal_getctl(ah, chan);
3015 * Always use CDD/direct per rate power table for register based approach.
3016 * For FCC, CDD calculations should factor in the array gain, hence
3017 * this adjust call. ETSI and MKK does not have this requirement.
3019 if (is_reg_dmn_fcc(ahp->reg_dmn)) {
3020 HALDEBUG(ah, HAL_DEBUG_CALIBRATE,
3021 "%s: FCC regdomain, calling reg_txpower_cdd\n",
3023 ar9300_adjust_reg_txpower_cdd(ah, target_power_val_t2);
3026 if (ar9300_eeprom_get(ahp, EEP_PAPRD_ENABLED)) {
3027 for (i = 0; i < ar9300_rate_size; i++) {
3029 * EEPROM TGT PWR is not same as current TGT PWR,
3030 * so Disable PAPRD for this rate.
3031 * Some of APs might ask to reduce Target Power,
3032 * if target power drops significantly,
3033 * disable PAPRD for that rate.
3035 if (tmp_paprd_rate_mask & (1 << i)) {
3036 if (ABS(target_power_val_t2_eep[i], target_power_val_t2[i]) >
3039 tmp_paprd_rate_mask &= ~(1 << i);
3040 HALDEBUG(ah, HAL_DEBUG_CALIBRATE,
3041 "%s: EEP TPC[%02d] 0x%08x "
3042 "Curr TPC[%02d] 0x%08x mask = 0x%08x\n",
3043 __func__, i, target_power_val_t2_eep[i], i,
3044 target_power_val_t2[i], tmp_paprd_rate_mask);
3049 HALDEBUG(ah, HAL_DEBUG_CALIBRATE,
3050 "%s: Chan %d After tmp_paprd_rate_mask = 0x%08x\n",
3051 __func__, ichan->channel, tmp_paprd_rate_mask);
3053 *tmp_ptr = tmp_paprd_rate_mask;
3057 /* Write target power array to registers */
3058 ar9300_transmit_power_reg_write(ah, target_power_val_t2);
3060 /* Write target power for self generated frames to the TPC register */
3061 ar9300_selfgen_tpc_reg_write(ah, chan, target_power_val_t2);
3063 /* GreenTx or Paprd */
3064 if (ah->ah_config.ath_hal_sta_update_tx_pwr_enable ||
3065 AH_PRIVATE(ah)->ah_caps.halPaprdEnabled)
3067 if (AR_SREV_POSEIDON(ah)) {
3068 /*For HAL_RSSI_TX_POWER_NONE array*/
3069 OS_MEMCPY(ahp->ah_default_tx_power,
3070 target_power_val_t2,
3071 sizeof(target_power_val_t2));
3072 /* Get defautl tx related register setting for GreenTx */
3074 ahp->ah_ob_db1[POSEIDON_STORED_REG_OBDB] =
3075 OS_REG_READ(ah, AR_PHY_65NM_CH0_TXRF2);
3076 /* Record TPC settting */
3077 ahp->ah_ob_db1[POSEIDON_STORED_REG_TPC] =
3078 OS_REG_READ(ah, AR_TPC);
3079 /* Record BB_powertx_rate9 setting */
3080 ahp->ah_ob_db1[POSEIDON_STORED_REG_BB_PWRTX_RATE9] =
3081 OS_REG_READ(ah, AR_PHY_BB_POWERTX_RATE9);
3086 * Return tx power used to iwconfig.
3087 * Since power is rate dependent, use one of the indices from the
3088 * AR9300_Rates enum to select an entry from target_power_val_t2[]
3090 * Currently returns the power for HT40 MCS 0, HT20 MCS 0, or OFDM 6 Mbps
3091 * as CCK power is less interesting (?).
3093 i = ALL_TARGET_LEGACY_6_24; /* legacy */
3094 if (IEEE80211_IS_CHAN_HT40(chan)) {
3095 i = ALL_TARGET_HT40_0_8_16; /* ht40 */
3096 } else if (IEEE80211_IS_CHAN_HT20(chan)) {
3097 i = ALL_TARGET_HT20_0_8_16; /* ht20 */
3099 max_power_level = target_power_val_t2[i];
3100 /* Adjusting the ah_max_power_level based on chains and antennaGain*/
3101 switch (ar9300_get_ntxchains(((ahp->ah_tx_chainmaskopt > 0) ?
3102 ahp->ah_tx_chainmaskopt : ahp->ah_tx_chainmask)))
3107 twice_array_gain = (ahp->twice_antenna_gain >= ahp->twice_antenna_reduction)? 0:
3108 ((int16_t)AH_MIN((ahp->twice_antenna_reduction -
3109 (ahp->twice_antenna_gain + INCREASE_MAXPOW_BY_TWO_CHAIN)), 0));
3110 /* Adjusting maxpower with antennaGain */
3111 max_power_level -= twice_array_gain;
3112 /* Adjusting maxpower based on chain */
3113 max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
3116 twice_array_gain = (ahp->twice_antenna_gain >= ahp->twice_antenna_reduction)? 0:
3117 ((int16_t)AH_MIN((ahp->twice_antenna_reduction -
3118 (ahp->twice_antenna_gain + INCREASE_MAXPOW_BY_THREE_CHAIN)), 0));
3120 /* Adjusting maxpower with antennaGain */
3121 max_power_level -= twice_array_gain;
3122 /* Adjusting maxpower based on chain */
3123 max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
3126 HALASSERT(0); /* Unsupported number of chains */
3128 AH_PRIVATE(ah)->ah_maxPowerLevel = (int8_t)max_power_level;
3130 ar9300_calibration_apply(ah, ichan->channel);
3133 /* Handle per packet TPC initializations */
3134 if (ah->ah_config.ath_hal_desc_tpc) {
3135 /* Transmit Power per-rate per-chain are computed here. A separate
3136 * power table is maintained for different MIMO modes (i.e. TXBF ON,
3137 * STBC) to enable easy lookup during packet transmit.
3138 * The reason for maintaing each of these tables per chain is that
3139 * the transmit power used for different number of chains is different
3140 * depending on whether the power has been limited by the target power,
3141 * the regulatory domain or the CTL limits.
3143 u_int mode = ath_hal_get_curmode(ah, chan);
3145 u_int8_t chainmasks[AR9300_MAX_CHAINS] =
3146 {OSPREY_1_CHAINMASK, OSPREY_2LOHI_CHAINMASK, OSPREY_3_CHAINMASK};
3147 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
3148 OS_MEMCPY(target_power_val_t2, target_power_val_t2_eep,
3149 sizeof(target_power_val_t2_eep));
3150 ar9300_eeprom_set_power_per_rate_table(ah, p_eep_data, chan,
3151 target_power_val_t2, cfg_ctl,
3153 twice_max_regulatory_power,
3154 power_limit, chainmasks[i]);
3155 HALDEBUG(ah, HAL_DEBUG_POWER_MGMT,
3156 " Channel = %d Chainmask = %d, Upper Limit = [%2d.%1d dBm]\n",
3157 ichan->channel, i, ahp->upper_limit[i]/2,
3158 ahp->upper_limit[i]%2 * 5);
3159 ar9300_init_rate_txpower(ah, mode, chan, target_power_val_t2,
3165 OS_REG_WRITE(ah, AR_PHY_PWRTX_MAX, AR_PHY_PWRTX_MAX_TPC_ENABLE);
3167 * Disable per chain power reduction since we are already
3168 * accounting for this in our calculations
3170 val = OS_REG_READ(ah, AR_PHY_POWER_TX_SUB);
3171 if (AR_SREV_WASP(ah)) {
3172 OS_REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
3173 val & AR_PHY_POWER_TX_SUB_2_DISABLE);
3175 OS_REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
3176 val & AR_PHY_POWER_TX_SUB_3_DISABLE);
3183 /**************************************************************
3184 * ar9300_eeprom_set_addac
3186 * Set the ADDAC from eeprom.
3189 ar9300_eeprom_set_addac(struct ath_hal *ah, struct ieee80211_channel *chan)
3192 HALDEBUG(AH_NULL, HAL_DEBUG_UNMASKABLE,
3193 "FIXME: ar9300_eeprom_def_set_addac called\n");
3195 MODAL_EEPDEF_HEADER *p_modal;
3196 struct ath_hal_9300 *ahp = AH9300(ah);
3197 ar9300_eeprom_t *eep = &ahp->ah_eeprom.def;
3200 if (AH_PRIVATE(ah)->ah_macVersion != AR_SREV_VERSION_SOWL) {
3204 HALASSERT(owl_get_eepdef_ver(ahp) == AR9300_EEP_VER);
3206 /* Xpa bias levels in eeprom are valid from rev 14.7 */
3207 if (owl_get_eepdef_rev(ahp) < AR9300_EEP_MINOR_VER_7) {
3211 if (ahp->ah_emu_eeprom) {
3215 p_modal = &(eep->modal_header[IEEE80211_IS_CHAN_2GHZ(chan)]);
3217 if (p_modal->xpa_bias_lvl != 0xff) {
3218 biaslevel = p_modal->xpa_bias_lvl;
3220 /* Use freqeuncy specific xpa bias level */
3221 u_int16_t reset_freq_bin, freq_bin, freq_count = 0;
3222 CHAN_CENTERS centers;
3224 ar9300_get_channel_centers(ah, chan, ¢ers);
3226 reset_freq_bin = FREQ2FBIN(centers.synth_center, IEEE80211_IS_CHAN_2GHZ(chan));
3227 freq_bin = p_modal->xpa_bias_lvl_freq[0] & 0xff;
3228 biaslevel = (u_int8_t)(p_modal->xpa_bias_lvl_freq[0] >> 14);
3232 while (freq_count < 3) {
3233 if (p_modal->xpa_bias_lvl_freq[freq_count] == 0x0) {
3237 freq_bin = p_modal->xpa_bias_lvl_freq[freq_count] & 0xff;
3238 if (reset_freq_bin >= freq_bin) {
3240 (u_int8_t)(p_modal->xpa_bias_lvl_freq[freq_count] >> 14);
3248 /* Apply bias level to the ADDAC values in the INI array */
3249 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
3250 INI_RA(&ahp->ah_ini_addac, 7, 1) =
3251 (INI_RA(&ahp->ah_ini_addac, 7, 1) & (~0x18)) | biaslevel << 3;
3253 INI_RA(&ahp->ah_ini_addac, 6, 1) =
3254 (INI_RA(&ahp->ah_ini_addac, 6, 1) & (~0xc0)) | biaslevel << 6;
3260 ar9300_eeprom_dump_support(struct ath_hal *ah, void **pp_e)
3262 *pp_e = &(AH9300(ah)->ah_eeprom);
3263 return sizeof(ar9300_eeprom_t);
3267 ar9300_eeprom_get_num_ant_config(struct ath_hal_9300 *ahp,
3268 HAL_FREQ_BAND freq_band)
3271 ar9300_eeprom_t *eep = &ahp->ah_eeprom.def;
3272 MODAL_EEPDEF_HEADER *p_modal =
3273 &(eep->modal_header[HAL_FREQ_BAND_2GHZ == freq_band]);
3274 BASE_EEPDEF_HEADER *p_base = &eep->base_eep_header;
3275 u_int8_t num_ant_config;
3277 num_ant_config = 1; /* default antenna configuration */
3279 if (p_base->version >= 0x0E0D) {
3280 if (p_modal->use_ant1) {
3281 num_ant_config += 1;
3285 return num_ant_config;
3292 ar9300_eeprom_get_ant_cfg(struct ath_hal_9300 *ahp,
3293 const struct ieee80211_channel *chan,
3294 u_int8_t index, u_int16_t *config)
3297 ar9300_eeprom_t *eep = &ahp->ah_eeprom.def;
3298 MODAL_EEPDEF_HEADER *p_modal = &(eep->modal_header[IEEE80211_IS_CHAN_2GHZ(chan)]);
3299 BASE_EEPDEF_HEADER *p_base = &eep->base_eep_header;
3303 *config = p_modal->ant_ctrl_common & 0xFFFF;
3306 if (p_base->version >= 0x0E0D) {
3307 if (p_modal->use_ant1) {
3308 *config = ((p_modal->ant_ctrl_common & 0xFFFF0000) >> 16);
3321 ar9300_eeprom_get_cust_data(struct ath_hal_9300 *ahp)
3323 return (u_int8_t *)ahp;
3327 static inline HAL_STATUS
3328 ar9300_check_eeprom(struct ath_hal *ah)
3331 u_int32_t sum = 0, el;
3334 struct ath_hal_9300 *ahp = AH9300(ah);
3335 HAL_BOOL need_swap = AH_FALSE;
3336 ar9300_eeprom_t *eep = (ar9300_eeprom_t *)&ahp->ah_eeprom.def;
3337 u_int16_t magic, magic2;
3342 ** We need to check the EEPROM data regardless of if it's in flash or
3346 if (!ahp->ah_priv.priv.ah_eeprom_read(
3347 ah, AR9300_EEPROM_MAGIC_OFFSET, &magic))
3349 HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: Reading Magic # failed\n", __func__);
3353 HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: Read Magic = 0x%04X\n", __func__, magic);
3355 if (!ar9300_eep_data_in_flash(ah)) {
3357 if (magic != AR9300_EEPROM_MAGIC) {
3358 magic2 = SWAP16(magic);
3360 if (magic2 == AR9300_EEPROM_MAGIC) {
3361 need_swap = AH_TRUE;
3362 eepdata = (u_int16_t *)(&ahp->ah_eeprom);
3365 addr < sizeof(ar9300_eeprom_t) / sizeof(u_int16_t);
3368 temp = SWAP16(*eepdata);
3372 HALDEBUG(ah, HAL_DEBUG_EEPROM_DUMP, "0x%04X ", *eepdata);
3373 if (((addr + 1) % 6) == 0) {
3374 HALDEBUG(ah, HAL_DEBUG_EEPROM_DUMP, "\n");
3378 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3379 "Invalid EEPROM Magic. endianness missmatch.\n");
3380 return HAL_EEBADSUM;
3384 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3385 "EEPROM being read from flash @0x%p\n", AH_PRIVATE(ah)->ah_st);
3388 HALDEBUG(ah, HAL_DEBUG_EEPROM, "need_swap = %s.\n", need_swap?"True":"False");
3391 el = SWAP16(ahp->ah_eeprom.def.base_eep_header.length);
3393 el = ahp->ah_eeprom.def.base_eep_header.length;
3396 eepdata = (u_int16_t *)(&ahp->ah_eeprom.def);
3398 i < AH_MIN(el, sizeof(ar9300_eeprom_t)) / sizeof(u_int16_t);
3405 * preddy: EEPROM endianness does not match. So change it
3406 * 8bit values in eeprom data structure does not need to be swapped
3407 * Only >8bits (16 & 32) values need to be swapped
3408 * If a new 16 or 32 bit field is added to the EEPROM contents,
3409 * please make sure to swap the field here
3411 u_int32_t integer, j;
3414 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3415 "EEPROM Endianness is not native.. Changing \n");
3417 /* convert Base Eep header */
3418 word = SWAP16(eep->base_eep_header.length);
3419 eep->base_eep_header.length = word;
3421 word = SWAP16(eep->base_eep_header.checksum);
3422 eep->base_eep_header.checksum = word;
3424 word = SWAP16(eep->base_eep_header.version);
3425 eep->base_eep_header.version = word;
3427 word = SWAP16(eep->base_eep_header.reg_dmn[0]);
3428 eep->base_eep_header.reg_dmn[0] = word;
3430 word = SWAP16(eep->base_eep_header.reg_dmn[1]);
3431 eep->base_eep_header.reg_dmn[1] = word;
3433 word = SWAP16(eep->base_eep_header.rf_silent);
3434 eep->base_eep_header.rf_silent = word;
3436 word = SWAP16(eep->base_eep_header.blue_tooth_options);
3437 eep->base_eep_header.blue_tooth_options = word;
3439 word = SWAP16(eep->base_eep_header.device_cap);
3440 eep->base_eep_header.device_cap = word;
3442 /* convert Modal Eep header */
3443 for (j = 0; j < ARRAY_LENGTH(eep->modal_header); j++) {
3444 MODAL_EEPDEF_HEADER *p_modal = &eep->modal_header[j];
3445 integer = SWAP32(p_modal->ant_ctrl_common);
3446 p_modal->ant_ctrl_common = integer;
3448 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
3449 integer = SWAP32(p_modal->ant_ctrl_chain[i]);
3450 p_modal->ant_ctrl_chain[i] = integer;
3453 for (i = 0; i < AR9300_EEPROM_MODAL_SPURS; i++) {
3454 word = SWAP16(p_modal->spur_chans[i].spur_chan);
3455 p_modal->spur_chans[i].spur_chan = word;
3460 /* Check CRC - Attach should fail on a bad checksum */
3461 if (sum != 0xffff || owl_get_eepdef_ver(ahp) != AR9300_EEP_VER ||
3462 owl_get_eepdef_rev(ahp) < AR9300_EEP_NO_BACK_VER) {
3463 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3464 "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
3465 sum, owl_get_eepdef_ver(ahp));
3466 return HAL_EEBADSUM;
3469 ar9300_eeprom_def_dump(ah, eep);
3473 #ifdef AH_AR9300_OVRD_TGT_PWR
3476 * 14.4 EEPROM contains low target powers.
3477 * Hardcode until EEPROM > 14.4
3479 if (owl_get_eepdef_ver(ahp) == 14 && owl_get_eepdef_rev(ahp) <= 4) {
3480 MODAL_EEPDEF_HEADER *p_modal;
3483 HALDEBUG(ah, HAL_DEBUG_POWER_OVERRIDE, "Original Target Powers\n");
3484 ar9300_eep_def_dump_tgt_power(ah, eep);
3486 HALDEBUG(ah, HAL_DEBUG_POWER_OVERRIDE,
3487 "Override Target Powers. EEPROM Version is %d.%d, "
3489 owl_get_eepdef_ver(ahp),
3490 owl_get_eepdef_rev(ahp),
3491 eep->base_eep_header.device_type);
3494 ar9300_eep_def_override_tgt_power(ah, eep);
3496 if (eep->base_eep_header.device_type == 5) {
3497 /* for xb72 only: improve transmit EVM for interop */
3498 p_modal = &eep->modal_header[1];
3499 p_modal->tx_frame_to_data_start = 0x23;
3500 p_modal->tx_frame_to_xpa_on = 0x23;
3501 p_modal->tx_frame_to_pa_on = 0x23;
3505 HALDEBUG(ah, HAL_DEBUG_POWER_OVERRIDE, "Modified Target Powers\n");
3506 ar9300_eep_def_dump_tgt_power(ah, eep);
3509 #endif /* AH_AR9300_OVRD_TGT_PWR */
3517 ar9300_eeprom_get_spur_chan(struct ath_hal *ah, int i, HAL_BOOL is_2ghz)
3519 u_int16_t spur_val = AR_NO_SPUR;
3521 struct ath_hal_9300 *ahp = AH9300(ah);
3522 ar9300_eeprom_t *eep = (ar9300_eeprom_t *)&ahp->ah_eeprom;
3524 HALASSERT(i < AR_EEPROM_MODAL_SPURS );
3526 HALDEBUG(ah, HAL_DEBUG_ANI,
3527 "Getting spur idx %d is2Ghz. %d val %x\n",
3529 AH_PRIVATE(ah)->ah_config.ath_hal_spur_chans[i][is_2ghz]);
3531 switch (AH_PRIVATE(ah)->ah_config.ath_hal_spur_mode) {
3533 /* returns AR_NO_SPUR */
3535 case SPUR_ENABLE_IOCTL:
3536 spur_val = AH_PRIVATE(ah)->ah_config.ath_hal_spur_chans[i][is_2ghz];
3537 HALDEBUG(ah, HAL_DEBUG_ANI,
3538 "Getting spur val from new loc. %d\n", spur_val);
3540 case SPUR_ENABLE_EEPROM:
3541 spur_val = eep->modal_header[is_2ghz].spur_chans[i].spur_chan;
3550 static inline HAL_BOOL
3551 ar9300_fill_eeprom(struct ath_hal *ah)
3553 return ar9300_eeprom_restore(ah);
3558 ar9300_eeprom_struct_size(void)
3560 return sizeof(ar9300_eeprom_t);
3563 int ar9300_eeprom_struct_default_many(void)
3565 return ARRAY_LENGTH(default9300);
3570 ar9300_eeprom_struct_default(int default_index)
3572 if (default_index >= 0 &&
3573 default_index < ARRAY_LENGTH(default9300))
3575 return default9300[default_index];
3582 ar9300_eeprom_struct_default_find_by_id(int id)
3586 for (it = 0; it < ARRAY_LENGTH(default9300); it++) {
3587 if (default9300[it] != 0 && default9300[it]->template_version == id) {
3588 return default9300[it];
3596 ar9300_calibration_data_read_flash(struct ath_hal *ah, long address,
3597 u_int8_t *buffer, int many)
3600 if (((address) < 0) || ((address + many) > AR9300_EEPROM_SIZE - 1)) {
3607 ar9300_calibration_data_read_eeprom(struct ath_hal *ah, long address,
3608 u_int8_t *buffer, int many)
3612 unsigned long eep_addr;
3613 unsigned long byte_addr;
3616 if (((address) < 0) || ((address + many) > AR9300_EEPROM_SIZE)) {
3620 for (i = 0; i < many; i++) {
3621 eep_addr = (u_int16_t) (address + i) / 2;
3622 byte_addr = (u_int16_t) (address + i) % 2;
3623 svalue = (u_int16_t *) value;
3624 if (! ath_hal_eepromRead(ah, eep_addr, svalue)) {
3625 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3626 "%s: Unable to read eeprom region \n", __func__);
3629 buffer[i] = (*svalue >> (8 * byte_addr)) & 0xff;
3635 ar9300_calibration_data_read_otp(struct ath_hal *ah, long address,
3636 u_int8_t *buffer, int many, HAL_BOOL is_wifi)
3639 unsigned long eep_addr;
3640 unsigned long byte_addr;
3643 if (((address) < 0) || ((address + many) > 0x400)) {
3647 for (i = 0; i < many; i++) {
3648 eep_addr = (u_int16_t) (address + i) / 4; /* otp is 4 bytes long???? */
3649 byte_addr = (u_int16_t) (address + i) % 4;
3650 if (!ar9300_otp_read(ah, eep_addr, &svalue, is_wifi)) {
3651 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3652 "%s: Unable to read otp region \n", __func__);
3655 buffer[i] = (svalue >> (8 * byte_addr)) & 0xff;
3660 #ifdef ATH_CAL_NAND_FLASH
3662 ar9300_calibration_data_read_nand(struct ath_hal *ah, long address,
3663 u_int8_t *buffer, int many)
3668 /* Calling OS based API to read NAND */
3669 ret_val = OS_NAND_FLASH_READ(ATH_CAL_NAND_PARTITION, address, many, &ret_len, buffer);
3671 return (ret_val ? AH_FALSE: AH_TRUE);
3676 ar9300_calibration_data_read(struct ath_hal *ah, long address,
3677 u_int8_t *buffer, int many)
3679 switch (AH9300(ah)->calibration_data_source) {
3680 case calibration_data_flash:
3681 return ar9300_calibration_data_read_flash(ah, address, buffer, many);
3682 case calibration_data_eeprom:
3683 return ar9300_calibration_data_read_eeprom(ah, address, buffer, many);
3684 case calibration_data_otp:
3685 return ar9300_calibration_data_read_otp(ah, address, buffer, many, 1);
3686 #ifdef ATH_CAL_NAND_FLASH
3687 case calibration_data_nand:
3688 return ar9300_calibration_data_read_nand(ah,address,buffer,many);
3697 ar9300_calibration_data_read_array(struct ath_hal *ah, int address,
3698 u_int8_t *buffer, int many)
3702 for (it = 0; it < many; it++) {
3703 (void)ar9300_calibration_data_read(ah, address - it, buffer + it, 1);
3710 * the address where the first configuration block is written
3712 static const int base_address = 0x3ff; /* 1KB */
3713 static const int base_address_512 = 0x1ff; /* 512Bytes */
3716 * the address where the NAND first configuration block is written
3718 #ifdef ATH_CAL_NAND_FLASH
3719 static const int base_address_nand = AR9300_FLASH_CAL_START_OFFSET;
3724 * the lower limit on configuration data
3726 static const int low_limit = 0x040;
3729 * returns size of the physical eeprom in bytes.
3730 * 1024 and 2048 are normal sizes.
3731 * 0 means there is no eeprom.
3734 ar9300_eeprom_size(struct ath_hal *ah)
3738 * first we'll try for 4096 bytes eeprom
3740 if (ar9300_eeprom_read_word(ah, 2047, &data)) {
3746 * then we'll try for 2048 bytes eeprom
3748 if (ar9300_eeprom_read_word(ah, 1023, &data)) {
3754 * then we'll try for 1024 bytes eeprom
3756 if (ar9300_eeprom_read_word(ah, 511, &data)) {
3765 * returns size of the physical otp in bytes.
3766 * 1024 and 2048 are normal sizes.
3767 * 0 means there is no eeprom.
3770 ar9300_otp_size(struct ath_hal *ah)
3772 if (AR_SREV_POSEIDON(ah) || AR_SREV_HORNET(ah)) {
3773 return base_address_512+1;
3775 return base_address+1;
3781 * find top of memory
3784 ar9300_eeprom_base_address(struct ath_hal *ah)
3788 if (AH9300(ah)->calibration_data_source == calibration_data_otp) {
3789 return ar9300_otp_size(ah)-1;
3793 size = ar9300_eeprom_size(ah);
3797 return ar9300_otp_size(ah)-1;
3803 ar9300_eeprom_volatile(struct ath_hal *ah)
3805 if (AH9300(ah)->calibration_data_source == calibration_data_otp) {
3806 return 0; /* no eeprom, use otp */
3808 return 1; /* board has eeprom or flash */
3813 * need to change this to look for the pcie data in the low parts of memory
3814 * cal data needs to stop a few locations above
3817 ar9300_eeprom_low_limit(struct ath_hal *ah)
3823 ar9300_compression_checksum(u_int8_t *data, int dsize)
3828 for (it = 0; it < dsize; it++) {
3829 checksum += data[it];
3837 ar9300_compression_header_unpack(u_int8_t *best, int *code, int *reference,
3838 int *length, int *major, int *minor)
3840 unsigned long value[4];
3846 *code = ((value[0] >> 5) & 0x0007);
3847 *reference = (value[0] & 0x001f) | ((value[1] >> 2) & 0x0020);
3848 *length = ((value[1] << 4) & 0x07f0) | ((value[2] >> 4) & 0x000f);
3849 *major = (value[2] & 0x000f);
3850 *minor = (value[3] & 0x00ff);
3857 ar9300_uncompress_block(struct ath_hal *ah, u_int8_t *mptr, int mdata_size,
3858 u_int8_t *block, int size)
3866 for (it = 0; it < size; it += (length + 2)) {
3870 length = block[it + 1];
3872 if (length > 0 && spot >= 0 && spot + length <= mdata_size) {
3873 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3874 "%s: Restore at %d: spot=%d offset=%d length=%d\n",
3875 __func__, it, spot, offset, length);
3876 OS_MEMCPY(&mptr[spot], &block[it + 2], length);
3878 } else if (length > 0) {
3879 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3880 "%s: Bad restore at %d: spot=%d offset=%d length=%d\n",
3881 __func__, it, spot, offset, length);
3889 ar9300_eeprom_restore_internal_address(struct ath_hal *ah,
3890 ar9300_eeprom_t *mptr, int mdata_size, int cptr, u_int8_t blank)
3892 u_int8_t word[MOUTPUT];
3893 ar9300_eeprom_t *dptr; /* was uint8 */
3895 int reference, length, major, minor;
3899 u_int16_t checksum, mchecksum;
3902 for (it = 0; it < MSTATE; it++) {
3903 (void) ar9300_calibration_data_read_array(
3904 ah, cptr, word, compression_header_length);
3905 if (word[0] == blank && word[1] == blank && word[2] == blank && word[3] == blank)
3909 ar9300_compression_header_unpack(
3910 word, &code, &reference, &length, &major, &minor);
3911 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3912 "%s: Found block at %x: "
3913 "code=%d ref=%d length=%d major=%d minor=%d\n",
3914 __func__, cptr, code, reference, length, major, minor);
3916 if (length >= 1024) {
3917 HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: Skipping bad header\n", __func__);
3918 cptr -= compression_header_length;
3923 (void) ar9300_calibration_data_read_array(
3925 compression_header_length + osize + compression_checksum_length);
3926 checksum = ar9300_compression_checksum(
3927 &word[compression_header_length], length);
3929 word[compression_header_length + osize] |
3930 (word[compression_header_length + osize + 1] << 8);
3931 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3932 "%s: checksum %x %x\n", __func__, checksum, mchecksum);
3933 if (checksum == mchecksum) {
3935 case _compress_none:
3936 if (length != mdata_size) {
3937 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3938 "%s: EEPROM structure size mismatch "
3939 "memory=%d eeprom=%d\n", __func__, mdata_size, length);
3942 OS_MEMCPY((u_int8_t *)mptr,
3943 (u_int8_t *)(word + compression_header_length), length);
3944 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3945 "%s: restored eeprom %d: uncompressed, length %d\n",
3946 __func__, it, length);
3950 case _compress_lzma:
3951 if (reference == reference_current) {
3954 dptr = (u_int8_t *)ar9300_eeprom_struct_default_find_by_id(
3957 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3958 "%s: Can't find reference eeprom struct %d\n",
3959 __func__, reference);
3964 if (usize != mdata_size) {
3965 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3966 "%s: uncompressed data is wrong size %d %d\n",
3967 __func__, usize, mdata_size);
3971 for (ib = 0; ib < mdata_size; ib++) {
3972 mptr[ib] = dptr[ib] ^ word[ib + overhead];
3974 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3975 "%s: restored eeprom %d: compressed, "
3976 "reference %d, length %d\n",
3977 __func__, it, reference, length);
3979 case _compress_pairs:
3980 if (reference == reference_current) {
3983 dptr = (u_int8_t *)ar9300_eeprom_struct_default_find_by_id(
3986 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3987 "%s: Can't find the reference "
3988 "eeprom structure %d\n",
3989 __func__, reference);
3993 HALDEBUG(ah, HAL_DEBUG_EEPROM,
3994 "%s: restored eeprom %d: "
3995 "pairs, reference %d, length %d,\n",
3996 __func__, it, reference, length);
3999 case _compress_block:
4000 if (reference == reference_current) {
4003 dptr = ar9300_eeprom_struct_default_find_by_id(reference);
4005 HALDEBUG(ah, HAL_DEBUG_EEPROM,
4006 "%s: cant find reference eeprom struct %d\n",
4007 __func__, reference);
4010 OS_MEMCPY(mptr, dptr, mdata_size);
4013 HALDEBUG(ah, HAL_DEBUG_EEPROM,
4014 "%s: restore eeprom %d: block, reference %d, length %d\n",
4015 __func__, it, reference, length);
4016 (void) ar9300_uncompress_block(ah,
4017 (u_int8_t *) mptr, mdata_size,
4018 (u_int8_t *) (word + compression_header_length), length);
4022 HALDEBUG(ah, HAL_DEBUG_EEPROM,
4023 "%s: unknown compression code %d\n", __func__, code);
4027 HALDEBUG(ah, HAL_DEBUG_EEPROM,
4028 "%s: skipping block with bad checksum\n", __func__);
4030 cptr -= compression_header_length + osize + compression_checksum_length;
4040 ar9300_eeprom_restore_from_dram(struct ath_hal *ah, ar9300_eeprom_t *mptr,
4043 struct ath_hal_9300 *ahp = AH9300(ah);
4044 #if !defined(USE_PLATFORM_FRAMEWORK)
4048 HALASSERT(mdata_size > 0);
4050 /* if cal_in_flash is AH_TRUE, the address sent by LMAC to HAL
4051 (i.e. ah->ah_st) is corresponding to Flash. so return from
4052 here if ar9300_eep_data_in_flash(ah) returns AH_TRUE */
4053 if(ar9300_eep_data_in_flash(ah))
4057 /* check if LMAC sent DRAM address is valid */
4058 if (!(uintptr_t)(AH_PRIVATE(ah)->ah_st)) {
4063 /* When calibration data is from host, Host will copy the
4064 compressed data to the predefined DRAM location saved at ah->ah_st */
4066 ath_hal_printf(ah, "Restoring Cal data from DRAM\n");
4067 ahp->ah_cal_mem = OS_REMAP((uintptr_t)(AH_PRIVATE(ah)->ah_st),
4070 if (!ahp->ah_cal_mem)
4072 HALDEBUG(ah, HAL_DEBUG_EEPROM,"%s: can't remap dram region\n", __func__);
4075 #if !defined(USE_PLATFORM_FRAMEWORK)
4076 cal_ptr = &((char *)(ahp->ah_cal_mem))[AR9300_FLASH_CAL_START_OFFSET];
4077 OS_MEMCPY(mptr, cal_ptr, mdata_size);
4079 OS_MEMCPY(mptr, ahp->ah_cal_mem, mdata_size);
4082 if (mptr->eeprom_version == 0xff ||
4083 mptr->template_version == 0xff ||
4084 mptr->eeprom_version == 0 ||
4085 mptr->template_version == 0)
4087 /* The board is uncalibrated */
4090 if (mptr->eeprom_version != 0x2)
4100 ar9300_eeprom_restore_from_flash(struct ath_hal *ah, ar9300_eeprom_t *mptr,
4103 struct ath_hal_9300 *ahp = AH9300(ah);
4106 HALASSERT(mdata_size > 0);
4108 if (!ahp->ah_cal_mem) {
4112 ath_hal_printf(ah, "Restoring Cal data from Flash\n");
4114 * When calibration data is saved in flash, read
4115 * uncompressed eeprom structure from flash and return
4117 cal_ptr = &((char *)(ahp->ah_cal_mem))[AR9300_FLASH_CAL_START_OFFSET];
4118 OS_MEMCPY(mptr, cal_ptr, mdata_size);
4120 ar9300_swap_eeprom((ar9300_eeprom_t *)mptr); DONE IN ar9300_restore()
4122 if (mptr->eeprom_version == 0xff ||
4123 mptr->template_version == 0xff ||
4124 mptr->eeprom_version == 0 ||
4125 mptr->template_version == 0)
4127 /* The board is uncalibrated */
4130 if (mptr->eeprom_version != 0x2)
4138 * Read the configuration data from the storage. We try the order with:
4139 * EEPROM, Flash, OTP. If all of above failed, use the default template.
4140 * The data can be put in any specified memory buffer.
4142 * Returns -1 on error.
4143 * Returns address of next memory location on success.
4146 ar9300_eeprom_restore_internal(struct ath_hal *ah, ar9300_eeprom_t *mptr,
4153 if ((AH9300(ah)->calibration_data_try == calibration_data_none ||
4154 AH9300(ah)->calibration_data_try == calibration_data_dram) &&
4155 AH9300(ah)->try_dram && nptr < 0)
4157 ath_hal_printf(ah, "Restoring Cal data from DRAM\n");
4158 AH9300(ah)->calibration_data_source = calibration_data_dram;
4159 AH9300(ah)->calibration_data_source_address = 0;
4160 nptr = ar9300_eeprom_restore_from_dram(ah, mptr, mdata_size);
4162 AH9300(ah)->calibration_data_source = calibration_data_none;
4163 AH9300(ah)->calibration_data_source_address = 0;
4167 if ((AH9300(ah)->calibration_data_try == calibration_data_none ||
4168 AH9300(ah)->calibration_data_try == calibration_data_eeprom) &&
4169 AH9300(ah)->try_eeprom && nptr < 0)
4172 * need to look at highest eeprom address as well as at
4173 * base_address=0x3ff where we used to write the data
4175 ath_hal_printf(ah, "Restoring Cal data from EEPROM\n");
4176 AH9300(ah)->calibration_data_source = calibration_data_eeprom;
4177 if (AH9300(ah)->calibration_data_try_address != 0) {
4178 AH9300(ah)->calibration_data_source_address =
4179 AH9300(ah)->calibration_data_try_address;
4180 nptr = ar9300_eeprom_restore_internal_address(
4181 ah, mptr, mdata_size,
4182 AH9300(ah)->calibration_data_source_address, 0xff);
4184 AH9300(ah)->calibration_data_source_address =
4185 ar9300_eeprom_base_address(ah);
4186 nptr = ar9300_eeprom_restore_internal_address(
4187 ah, mptr, mdata_size,
4188 AH9300(ah)->calibration_data_source_address, 0xff);
4190 AH9300(ah)->calibration_data_source_address != base_address)
4192 AH9300(ah)->calibration_data_source_address = base_address;
4193 nptr = ar9300_eeprom_restore_internal_address(
4194 ah, mptr, mdata_size,
4195 AH9300(ah)->calibration_data_source_address, 0xff);
4199 AH9300(ah)->calibration_data_source = calibration_data_none;
4200 AH9300(ah)->calibration_data_source_address = 0;
4205 * ##### should be an ifdef test for any AP usage,
4206 * either in driver or in nart
4208 if ((AH9300(ah)->calibration_data_try == calibration_data_none ||
4209 AH9300(ah)->calibration_data_try == calibration_data_flash) &&
4210 AH9300(ah)->try_flash && nptr < 0)
4212 ath_hal_printf(ah, "Restoring Cal data from Flash\n");
4213 AH9300(ah)->calibration_data_source = calibration_data_flash;
4214 /* how are we supposed to set this for flash? */
4215 AH9300(ah)->calibration_data_source_address = 0;
4216 nptr = ar9300_eeprom_restore_from_flash(ah, mptr, mdata_size);
4218 AH9300(ah)->calibration_data_source = calibration_data_none;
4219 AH9300(ah)->calibration_data_source_address = 0;
4223 if ((AH9300(ah)->calibration_data_try == calibration_data_none ||
4224 AH9300(ah)->calibration_data_try == calibration_data_otp) &&
4225 AH9300(ah)->try_otp && nptr < 0)
4227 ath_hal_printf(ah, "Restoring Cal data from OTP\n");
4228 AH9300(ah)->calibration_data_source = calibration_data_otp;
4229 if (AH9300(ah)->calibration_data_try_address != 0) {
4230 AH9300(ah)->calibration_data_source_address =
4231 AH9300(ah)->calibration_data_try_address;
4233 AH9300(ah)->calibration_data_source_address =
4234 ar9300_eeprom_base_address(ah);
4236 nptr = ar9300_eeprom_restore_internal_address(
4237 ah, mptr, mdata_size, AH9300(ah)->calibration_data_source_address, 0);
4239 AH9300(ah)->calibration_data_source = calibration_data_none;
4240 AH9300(ah)->calibration_data_source_address = 0;
4244 #ifdef ATH_CAL_NAND_FLASH
4245 if ((AH9300(ah)->calibration_data_try == calibration_data_none ||
4246 AH9300(ah)->calibration_data_try == calibration_data_nand) &&
4247 AH9300(ah)->try_nand && nptr < 0)
4249 AH9300(ah)->calibration_data_source = calibration_data_nand;
4250 AH9300(ah)->calibration_data_source_address = ((unsigned int)(AH_PRIVATE(ah)->ah_st)) + base_address_nand;
4251 if(ar9300_calibration_data_read(
4252 ah, AH9300(ah)->calibration_data_source_address,
4253 (u_int8_t *)mptr, mdata_size) == AH_TRUE)
4257 /*nptr=ar9300EepromRestoreInternalAddress(ah, mptr, mdataSize, CalibrationDataSourceAddress);*/
4260 AH9300(ah)->calibration_data_source = calibration_data_none;
4261 AH9300(ah)->calibration_data_source_address = 0;
4266 ath_hal_printf(ah, "%s[%d] No vaid CAL, calling default template\n",
4267 __func__, __LINE__);
4268 nptr = ar9300_eeprom_restore_something(ah, mptr, mdata_size);
4274 /******************************************************************************/
4276 ** \brief Eeprom Swapping Function
4278 ** This function will swap the contents of the "longer" EEPROM data items
4279 ** to ensure they are consistent with the endian requirements for the platform
4280 ** they are being compiled for
4282 ** \param eh Pointer to the EEPROM data structure
4285 #if AH_BYTE_ORDER == AH_BIG_ENDIAN
4287 ar9300_swap_eeprom(ar9300_eeprom_t *eep)
4293 word = __bswap16(eep->base_eep_header.reg_dmn[0]);
4294 eep->base_eep_header.reg_dmn[0] = word;
4296 word = __bswap16(eep->base_eep_header.reg_dmn[1]);
4297 eep->base_eep_header.reg_dmn[1] = word;
4299 dword = __bswap32(eep->base_eep_header.swreg);
4300 eep->base_eep_header.swreg = dword;
4302 dword = __bswap32(eep->modal_header_2g.ant_ctrl_common);
4303 eep->modal_header_2g.ant_ctrl_common = dword;
4305 dword = __bswap32(eep->modal_header_2g.ant_ctrl_common2);
4306 eep->modal_header_2g.ant_ctrl_common2 = dword;
4308 dword = __bswap32(eep->modal_header_2g.paprd_rate_mask_ht20);
4309 eep->modal_header_2g.paprd_rate_mask_ht20 = dword;
4311 dword = __bswap32(eep->modal_header_2g.paprd_rate_mask_ht40);
4312 eep->modal_header_2g.paprd_rate_mask_ht40 = dword;
4314 dword = __bswap32(eep->modal_header_5g.ant_ctrl_common);
4315 eep->modal_header_5g.ant_ctrl_common = dword;
4317 dword = __bswap32(eep->modal_header_5g.ant_ctrl_common2);
4318 eep->modal_header_5g.ant_ctrl_common2 = dword;
4320 dword = __bswap32(eep->modal_header_5g.paprd_rate_mask_ht20);
4321 eep->modal_header_5g.paprd_rate_mask_ht20 = dword;
4323 dword = __bswap32(eep->modal_header_5g.paprd_rate_mask_ht40);
4324 eep->modal_header_5g.paprd_rate_mask_ht40 = dword;
4326 for (i = 0; i < OSPREY_MAX_CHAINS; i++) {
4327 word = __bswap16(eep->modal_header_2g.ant_ctrl_chain[i]);
4328 eep->modal_header_2g.ant_ctrl_chain[i] = word;
4330 word = __bswap16(eep->modal_header_5g.ant_ctrl_chain[i]);
4331 eep->modal_header_5g.ant_ctrl_chain[i] = word;
4335 void ar9300_eeprom_template_swap(void)
4338 ar9300_eeprom_t *dptr;
4340 for (it = 0; it < ARRAY_LENGTH(default9300); it++) {
4341 dptr = ar9300_eeprom_struct_default(it);
4343 ar9300_swap_eeprom(dptr);
4351 * Restore the configuration structure by reading the eeprom.
4352 * This function destroys any existing in-memory structure content.
4355 ar9300_eeprom_restore(struct ath_hal *ah)
4357 struct ath_hal_9300 *ahp = AH9300(ah);
4358 ar9300_eeprom_t *mptr;
4360 HAL_BOOL status = AH_FALSE;
4362 mptr = &ahp->ah_eeprom;
4363 mdata_size = ar9300_eeprom_struct_size();
4365 if (mptr != 0 && mdata_size > 0) {
4366 #if AH_BYTE_ORDER == AH_BIG_ENDIAN
4367 ar9300_eeprom_template_swap();
4368 ar9300_swap_eeprom(mptr);
4371 * At this point, mptr points to the eeprom data structure
4372 * in it's "default" state. If this is big endian, swap the
4373 * data structures back to "little endian" form.
4375 if (ar9300_eeprom_restore_internal(ah, mptr, mdata_size) >= 0) {
4379 #if AH_BYTE_ORDER == AH_BIG_ENDIAN
4380 /* Second Swap, back to Big Endian */
4381 ar9300_eeprom_template_swap();
4382 ar9300_swap_eeprom(mptr);
4386 ahp->ah_2g_paprd_rate_mask_ht40 =
4387 mptr->modal_header_2g.paprd_rate_mask_ht40;
4388 ahp->ah_2g_paprd_rate_mask_ht20 =
4389 mptr->modal_header_2g.paprd_rate_mask_ht20;
4390 ahp->ah_5g_paprd_rate_mask_ht40 =
4391 mptr->modal_header_5g.paprd_rate_mask_ht40;
4392 ahp->ah_5g_paprd_rate_mask_ht20 =
4393 mptr->modal_header_5g.paprd_rate_mask_ht20;
4397 int32_t ar9300_thermometer_get(struct ath_hal *ah)
4399 struct ath_hal_9300 *ahp = AH9300(ah);
4402 (ahp->ah_eeprom.base_eep_header.misc_configuration >> 1) & 0x3;
4407 HAL_BOOL ar9300_thermometer_apply(struct ath_hal *ah)
4409 int thermometer = ar9300_thermometer_get(ah);
4412 /*#define AR_PHY_65NM_CH0_RXTX4 AR_PHY_65NM(ch0_RXTX4)*/
4413 #define AR_PHY_65NM_CH1_RXTX4 AR_PHY_65NM(ch1_RXTX4)
4414 #define AR_PHY_65NM_CH2_RXTX4 AR_PHY_65NM(ch2_RXTX4)
4415 /*#define AR_PHY_65NM_CH0_RXTX4_THERM_ON 0x10000000*/
4416 /*#define AR_PHY_65NM_CH0_RXTX4_THERM_ON_S 28*/
4417 #define AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR_S 29
4418 #define AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR \
4419 (0x1<<AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR_S)
4421 if (thermometer < 0) {
4422 OS_REG_RMW_FIELD(ah,
4423 AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 0);
4424 if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {
4425 OS_REG_RMW_FIELD(ah,
4426 AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 0);
4427 if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {
4428 OS_REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,
4429 AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 0);
4432 OS_REG_RMW_FIELD(ah,
4433 AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);
4434 if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {
4435 OS_REG_RMW_FIELD(ah,
4436 AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);
4437 if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {
4438 OS_REG_RMW_FIELD(ah,
4439 AR_PHY_65NM_CH2_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);
4443 OS_REG_RMW_FIELD(ah,
4444 AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 1);
4445 if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {
4446 OS_REG_RMW_FIELD(ah,
4447 AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 1);
4448 if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {
4449 OS_REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,
4450 AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 1);
4453 if (thermometer == 0) {
4454 OS_REG_RMW_FIELD(ah,
4455 AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 1);
4456 if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {
4457 OS_REG_RMW_FIELD(ah,
4458 AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);
4459 if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {
4460 OS_REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,
4461 AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);
4464 } else if (thermometer == 1) {
4465 OS_REG_RMW_FIELD(ah,
4466 AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);
4467 if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {
4468 OS_REG_RMW_FIELD(ah,
4469 AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 1);
4470 if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {
4471 OS_REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,
4472 AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);
4475 } else if (thermometer == 2) {
4476 OS_REG_RMW_FIELD(ah,
4477 AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);
4478 if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {
4479 OS_REG_RMW_FIELD(ah,
4480 AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);
4481 if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {
4482 OS_REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,
4483 AR_PHY_65NM_CH0_RXTX4_THERM_ON, 1);
4491 static int32_t ar9300_tuning_caps_params_get(struct ath_hal *ah)
4493 int tuning_caps_params;
4494 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
4495 tuning_caps_params = eep->base_eep_header.params_for_tuning_caps[0];
4496 return tuning_caps_params;
4500 * Read the tuning caps params from eeprom and set to correct register.
4501 * To regulation the frequency accuracy.
4503 HAL_BOOL ar9300_tuning_caps_apply(struct ath_hal *ah)
4505 int tuning_caps_params;
4506 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
4507 tuning_caps_params = ar9300_tuning_caps_params_get(ah);
4508 if ((eep->base_eep_header.feature_enable & 0x40) >> 6) {
4509 tuning_caps_params &= 0x7f;
4511 if (AR_SREV_POSEIDON(ah) || AR_SREV_WASP(ah) || AR_SREV_HONEYBEE(ah)) {
4513 } else if (AR_SREV_HORNET(ah)) {
4514 OS_REG_RMW_FIELD(ah,
4515 AR_HORNET_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPINDAC,
4516 tuning_caps_params);
4517 OS_REG_RMW_FIELD(ah,
4518 AR_HORNET_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPOUTDAC,
4519 tuning_caps_params);
4520 } else if (AR_SREV_SCORPION(ah)) {
4521 OS_REG_RMW_FIELD(ah,
4522 AR_SCORPION_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPINDAC,
4523 tuning_caps_params);
4524 OS_REG_RMW_FIELD(ah,
4525 AR_SCORPION_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPOUTDAC,
4526 tuning_caps_params);
4528 OS_REG_RMW_FIELD(ah,
4529 AR_OSPREY_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPINDAC,
4530 tuning_caps_params);
4531 OS_REG_RMW_FIELD(ah,
4532 AR_OSPREY_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPOUTDAC,
4533 tuning_caps_params);
4541 * Read the tx_frame_to_xpa_on param from eeprom and apply the value to
4544 HAL_BOOL ar9300_xpa_timing_control_apply(struct ath_hal *ah, HAL_BOOL is_2ghz)
4546 u_int8_t xpa_timing_control;
4547 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
4548 if ((eep->base_eep_header.feature_enable & 0x80) >> 7) {
4549 if (AR_SREV_OSPREY(ah) || AR_SREV_AR9580(ah) || AR_SREV_WASP(ah) || AR_SREV_HONEYBEE(ah)) {
4551 xpa_timing_control = eep->modal_header_2g.tx_frame_to_xpa_on;
4552 OS_REG_RMW_FIELD(ah,
4553 AR_PHY_XPA_TIMING_CTL, AR_PHY_XPA_TIMING_CTL_FRAME_XPAB_ON,
4554 xpa_timing_control);
4556 xpa_timing_control = eep->modal_header_5g.tx_frame_to_xpa_on;
4557 OS_REG_RMW_FIELD(ah,
4558 AR_PHY_XPA_TIMING_CTL, AR_PHY_XPA_TIMING_CTL_FRAME_XPAA_ON,
4559 xpa_timing_control);
4568 * Read the xLNA_bias_strength param from eeprom and apply the value to
4571 HAL_BOOL ar9300_x_lNA_bias_strength_apply(struct ath_hal *ah, HAL_BOOL is_2ghz)
4574 u_int32_t value = 0;
4575 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
4577 if ((eep->base_eep_header.misc_configuration & 0x40) >> 6) {
4578 if (AR_SREV_OSPREY(ah)) {
4580 x_lNABias = eep->modal_header_2g.xLNA_bias_strength;
4582 x_lNABias = eep->modal_header_5g.xLNA_bias_strength;
4584 value = x_lNABias & ( 0x03 ); // bit0,1 for chain0
4585 OS_REG_RMW_FIELD(ah,
4586 AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_RXTX4_XLNA_BIAS, value);
4587 value = (x_lNABias >> 2) & ( 0x03 ); // bit2,3 for chain1
4588 OS_REG_RMW_FIELD(ah,
4589 AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_RXTX4_XLNA_BIAS, value);
4590 value = (x_lNABias >> 4) & ( 0x03 ); // bit4,5 for chain2
4591 OS_REG_RMW_FIELD(ah,
4592 AR_PHY_65NM_CH2_RXTX4, AR_PHY_65NM_RXTX4_XLNA_BIAS, value);
4600 * Read EEPROM header info and program the device for correct operation
4601 * given the channel value.
4604 ar9300_eeprom_set_board_values(struct ath_hal *ah, const struct ieee80211_channel *chan)
4606 HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, chan);
4608 ar9300_xpa_bias_level_apply(ah, IEEE80211_IS_CHAN_2GHZ(chan));
4610 ar9300_xpa_timing_control_apply(ah, IEEE80211_IS_CHAN_2GHZ(chan));
4612 ar9300_ant_ctrl_apply(ah, IEEE80211_IS_CHAN_2GHZ(chan));
4613 ar9300_drive_strength_apply(ah);
4615 ar9300_x_lNA_bias_strength_apply(ah, IEEE80211_IS_CHAN_2GHZ(chan));
4617 /* wait for Poseidon internal regular turnning */
4618 /* for Hornet we move it before initPLL to avoid an access issue */
4619 /* Function not used when EMULATION. */
4620 if (!AR_SREV_HORNET(ah) && !AR_SREV_WASP(ah) && !AR_SREV_HONEYBEE(ah)) {
4621 ar9300_internal_regulator_apply(ah);
4624 ar9300_attenuation_apply(ah, ichan->channel);
4625 ar9300_quick_drop_apply(ah, ichan->channel);
4626 ar9300_thermometer_apply(ah);
4627 if(!AR_SREV_WASP(ah))
4629 ar9300_tuning_caps_apply(ah);
4632 ar9300_tx_end_to_xpab_off_apply(ah, ichan->channel);
4638 ar9300_eeprom_get_spur_chans_ptr(struct ath_hal *ah, HAL_BOOL is_2ghz)
4640 ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
4643 return &(eep->modal_header_2g.spur_chans[0]);
4645 return &(eep->modal_header_5g.spur_chans[0]);
4649 static u_int8_t ar9300_eeprom_get_tx_gain_table_number_max(struct ath_hal *ah)
4651 unsigned long tx_gain_table_max;
4652 tx_gain_table_max = OS_REG_READ_FIELD(ah,
4653 AR_PHY_TPC_7, AR_PHY_TPC_7_TX_GAIN_TABLE_MAX);
4654 return tx_gain_table_max;
4657 u_int8_t ar9300_eeprom_tx_gain_table_index_max_apply(struct ath_hal *ah, u_int16_t channel)
4660 ar9300_eeprom_t *ahp_Eeprom;
4661 struct ath_hal_9300 *ahp = AH9300(ah);
4663 ahp_Eeprom = &ahp->ah_eeprom;
4665 if (ahp_Eeprom->base_ext1.misc_enable == 0)
4670 index = ahp_Eeprom->modal_header_2g.tx_gain_cap;
4674 index = ahp_Eeprom->modal_header_5g.tx_gain_cap;
4677 OS_REG_RMW_FIELD(ah,
4678 AR_PHY_TPC_7, AR_PHY_TPC_7_TX_GAIN_TABLE_MAX, index);
4682 static u_int8_t ar9300_eeprom_get_pcdac_tx_gain_table_i(struct ath_hal *ah,
4683 int i, u_int8_t *pcdac)
4685 unsigned long tx_gain;
4686 u_int8_t tx_gain_table_max;
4687 tx_gain_table_max = ar9300_eeprom_get_tx_gain_table_number_max(ah);
4688 if (i <= 0 || i > tx_gain_table_max) {
4693 tx_gain = OS_REG_READ(ah, AR_PHY_TXGAIN_TAB(1) + i * 4);
4694 *pcdac = ((tx_gain >> 24) & 0xff);
4698 u_int8_t ar9300_eeprom_set_tx_gain_cap(struct ath_hal *ah,
4700 // pcdac read back from reg, read back value depends on reset 2GHz/5GHz ini
4701 // tx_gain_table, this function will be called twice after each
4702 // band's calibration.
4703 // after 2GHz cal, tx_gain_max[0] has 2GHz, calibration max txgain,
4704 // tx_gain_max[1]=-100
4705 // after 5GHz cal, tx_gain_max[0],tx_gain_max[1] have calibration
4706 // value for both band
4707 // reset is on 5GHz, reg reading from tx_gain_table is for 5GHz,
4708 // so program can't recalculate 2g.tx_gain_cap at this point.
4710 int i = 0, ig, im = 0;
4712 u_int8_t tx_gain_table_max;
4713 ar9300_eeprom_t *ahp_Eeprom;
4714 struct ath_hal_9300 *ahp = AH9300(ah);
4716 ahp_Eeprom = &ahp->ah_eeprom;
4718 if (ahp_Eeprom->base_ext1.misc_enable == 0)
4721 tx_gain_table_max = ar9300_eeprom_get_tx_gain_table_number_max(ah);
4723 for (i = 0; i < 2; i++) {
4724 if (tx_gain_max[i]>-100) { // -100 didn't cal that band.
4726 if (tx_gain_max[1]>-100) {
4728 // both band are calibrated, skip 2GHz 2g.tx_gain_cap reset
4731 for (ig = 1; ig <= tx_gain_table_max; ig++) {
4732 if (ah != 0 && ah->ah_reset != 0)
4734 ar9300_eeprom_get_pcdac_tx_gain_table_i(ah, ig, &pcdac);
4735 if (pcdac >= tx_gain_max[i])
4739 if (ig+1 <= tx_gain_table_max) {
4740 if (pcdac == tx_gain_max[i])
4745 ahp_Eeprom->modal_header_2g.tx_gain_cap = im;
4747 ahp_Eeprom->modal_header_5g.tx_gain_cap = im;
4751 ahp_Eeprom->modal_header_2g.tx_gain_cap = ig;
4753 ahp_Eeprom->modal_header_5g.tx_gain_cap = ig;