Path: blob/main/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_eeprom.c
48526 views
/*1* Copyright (c) 2013 Qualcomm Atheros, Inc.2*3* Permission to use, copy, modify, and/or distribute this software for any4* purpose with or without fee is hereby granted, provided that the above5* copyright notice and this permission notice appear in all copies.6*7* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH8* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY9* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,10* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM11* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR12* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR13* PERFORMANCE OF THIS SOFTWARE.14*/1516#include "opt_ah.h"1718#include "ah.h"19#include "ah_internal.h"20#include "ah_devid.h"21#ifdef AH_DEBUG22#include "ah_desc.h" /* NB: for HAL_PHYERR* */23#endif24#include "ar9300/ar9300.h"25#include "ar9300/ar9300eep.h"26#include "ar9300/ar9300template_generic.h"27#include "ar9300/ar9300template_xb112.h"28#include "ar9300/ar9300template_hb116.h"29#include "ar9300/ar9300template_xb113.h"30#include "ar9300/ar9300template_hb112.h"31#include "ar9300/ar9300template_ap121.h"32#include "ar9300/ar9300template_osprey_k31.h"33#include "ar9300/ar9300template_wasp_2.h"34#include "ar9300/ar9300template_wasp_k31.h"35#include "ar9300/ar9300template_aphrodite.h"36#include "ar9300/ar9300reg.h"37#include "ar9300/ar9300phy.h"38394041#if AH_BYTE_ORDER == AH_BIG_ENDIAN42void ar9300_swap_eeprom(ar9300_eeprom_t *eep);43void ar9300_eeprom_template_swap(void);44#endif4546static u_int16_t ar9300_eeprom_get_spur_chan(struct ath_hal *ah,47int spur_chan, HAL_BOOL is_2ghz);48#ifdef UNUSED49static inline HAL_BOOL ar9300_fill_eeprom(struct ath_hal *ah);50static inline HAL_STATUS ar9300_check_eeprom(struct ath_hal *ah);51#endif5253static ar9300_eeprom_t *default9300[] =54{55&ar9300_template_generic,56&ar9300_template_xb112,57&ar9300_template_hb116,58&ar9300_template_hb112,59&ar9300_template_xb113,60&ar9300_template_ap121,61&ar9300_template_wasp_2,62&ar9300_template_wasp_k31,63&ar9300_template_osprey_k31,64&ar9300_template_aphrodite,65};6667/*68* Different types of memory where the calibration data might be stored.69* All types are searched in ar9300_eeprom_restore()70* in the order flash, eeprom, otp.71* To disable searching a type, set its parameter to 0.72*/7374/*75* This is where we look for the calibration data.76* must be set before ath_attach() is called77*/78static int calibration_data_try = calibration_data_none;79static int calibration_data_try_address = 0;8081/*82* Set the type of memory used to store calibration data.83* Used by nart to force reading/writing of a specific type.84* The driver can normally allow autodetection85* by setting source to calibration_data_none=0.86*/87void ar9300_calibration_data_set(struct ath_hal *ah, int32_t source)88{89if (ah != 0) {90AH9300(ah)->calibration_data_source = source;91} else {92calibration_data_try = source;93}94}9596int32_t ar9300_calibration_data_get(struct ath_hal *ah)97{98if (ah != 0) {99return AH9300(ah)->calibration_data_source;100} else {101return calibration_data_try;102}103}104105/*106* Set the address of first byte used to store calibration data.107* Used by nart to force reading/writing at a specific address.108* The driver can normally allow autodetection by setting size=0.109*/110void ar9300_calibration_data_address_set(struct ath_hal *ah, int32_t size)111{112if (ah != 0) {113AH9300(ah)->calibration_data_source_address = size;114} else {115calibration_data_try_address = size;116}117}118119int32_t ar9300_calibration_data_address_get(struct ath_hal *ah)120{121if (ah != 0) {122return AH9300(ah)->calibration_data_source_address;123} else {124return calibration_data_try_address;125}126}127128/*129* This is the template that is loaded if ar9300_eeprom_restore()130* can't find valid data in the memory.131*/132static int Ar9300_eeprom_template_preference = ar9300_eeprom_template_generic;133134void ar9300_eeprom_template_preference(int32_t value)135{136Ar9300_eeprom_template_preference = value;137}138139/*140* Install the specified default template.141* Overwrites any existing calibration and configuration information in memory.142*/143int32_t ar9300_eeprom_template_install(struct ath_hal *ah, int32_t value)144{145struct ath_hal_9300 *ahp = AH9300(ah);146ar9300_eeprom_t *mptr, *dptr;147int mdata_size;148149mptr = &ahp->ah_eeprom;150mdata_size = ar9300_eeprom_struct_size();151if (mptr != 0) {152#if 0153calibration_data_source = calibration_data_none;154calibration_data_source_address = 0;155#endif156dptr = ar9300_eeprom_struct_default_find_by_id(value);157if (dptr != 0) {158OS_MEMCPY(mptr, dptr, mdata_size);159return 0;160}161}162return -1;163}164165static int166ar9300_eeprom_restore_something(struct ath_hal *ah, ar9300_eeprom_t *mptr,167int mdata_size)168{169int it;170ar9300_eeprom_t *dptr;171int nptr;172173nptr = -1;174/*175* if we didn't find any blocks in the memory,176* put the prefered template in place177*/178if (nptr < 0) {179AH9300(ah)->calibration_data_source = calibration_data_none;180AH9300(ah)->calibration_data_source_address = 0;181dptr = ar9300_eeprom_struct_default_find_by_id(182Ar9300_eeprom_template_preference);183if (dptr != 0) {184OS_MEMCPY(mptr, dptr, mdata_size);185nptr = 0;186}187}188/*189* if we didn't find the prefered one,190* put the normal default template in place191*/192if (nptr < 0) {193AH9300(ah)->calibration_data_source = calibration_data_none;194AH9300(ah)->calibration_data_source_address = 0;195dptr = ar9300_eeprom_struct_default_find_by_id(196ar9300_eeprom_template_default);197if (dptr != 0) {198OS_MEMCPY(mptr, dptr, mdata_size);199nptr = 0;200}201}202/*203* if we can't find the best template, put any old template in place204* presume that newer ones are better, so search backwards205*/206if (nptr < 0) {207AH9300(ah)->calibration_data_source = calibration_data_none;208AH9300(ah)->calibration_data_source_address = 0;209for (it = ar9300_eeprom_struct_default_many() - 1; it >= 0; it--) {210dptr = ar9300_eeprom_struct_default(it);211if (dptr != 0) {212OS_MEMCPY(mptr, dptr, mdata_size);213nptr = 0;214break;215}216}217}218return nptr;219}220221/*222* Read 16 bits of data from offset into *data223*/224HAL_BOOL225ar9300_eeprom_read_word(struct ath_hal *ah, u_int off, u_int16_t *data)226{227if (AR_SREV_OSPREY(ah) || AR_SREV_POSEIDON(ah) || AR_SREV_JUPITER(ah))228{229(void) OS_REG_READ(ah, AR9300_EEPROM_OFFSET + (off << AR9300_EEPROM_S));230if (!ath_hal_wait(ah,231AR_HOSTIF_REG(ah, AR_EEPROM_STATUS_DATA),232AR_EEPROM_STATUS_DATA_BUSY | AR_EEPROM_STATUS_DATA_PROT_ACCESS,2330))234{235return AH_FALSE;236}237*data = MS(OS_REG_READ(ah,238AR_HOSTIF_REG(ah, AR_EEPROM_STATUS_DATA)), AR_EEPROM_STATUS_DATA_VAL);239return AH_TRUE;240}241else242{243*data = 0;244return AH_FALSE;245}246}247248249HAL_BOOL250ar9300_otp_read(struct ath_hal *ah, u_int off, u_int32_t *data, HAL_BOOL is_wifi)251{252int time_out = 1000;253int status = 0;254u_int32_t addr;255256if (AR_SREV_HONEYBEE(ah)){ /* no OTP for Honeybee */257return false;258}259addr = (AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah))?260OTP_MEM_START_ADDRESS_WASP : OTP_MEM_START_ADDRESS;261if (!is_wifi) {262addr = BTOTP_MEM_START_ADDRESS;263}264addr += off * 4; /* OTP is 32 bit addressable */265(void) OS_REG_READ(ah, addr);266267addr = (AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah)) ?268OTP_STATUS0_OTP_SM_BUSY_WASP : OTP_STATUS0_OTP_SM_BUSY;269if (!is_wifi) {270addr = BTOTP_STATUS0_OTP_SM_BUSY;271}272while ((time_out > 0) && (!status)) { /* wait for access complete */273/* Read data valid, access not busy, sm not busy */274status = ((OS_REG_READ(ah, addr) & 0x7) == 0x4) ? 1 : 0;275time_out--;276}277if (time_out == 0) {278HALDEBUG(ah, HAL_DEBUG_EEPROM,279"%s: Timed out during OTP Status0 validation\n", __func__);280return AH_FALSE;281}282283addr = (AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah)) ?284OTP_STATUS1_EFUSE_READ_DATA_WASP : OTP_STATUS1_EFUSE_READ_DATA;285if (!is_wifi) {286addr = BTOTP_STATUS1_EFUSE_READ_DATA;287}288*data = OS_REG_READ(ah, addr);289return AH_TRUE;290}291292293294295static HAL_STATUS296ar9300_flash_map(struct ath_hal *ah)297{298/* XXX disable flash remapping for now (ie, SoC support) */299ath_hal_printf(ah, "%s: unimplemented for now\n", __func__);300#if 0301struct ath_hal_9300 *ahp = AH9300(ah);302#if defined(AR9100) || defined(__NetBSD__)303ahp->ah_cal_mem = OS_REMAP(ah, AR9300_EEPROM_START_ADDR, AR9300_EEPROM_MAX);304#else305ahp->ah_cal_mem = OS_REMAP((uintptr_t)(AH_PRIVATE(ah)->ah_st),306(AR9300_EEPROM_MAX + AR9300_FLASH_CAL_START_OFFSET));307#endif308if (!ahp->ah_cal_mem) {309HALDEBUG(ah, HAL_DEBUG_EEPROM,310"%s: cannot remap eeprom region \n", __func__);311return HAL_EIO;312}313#endif314return HAL_OK;315}316317HAL_BOOL318ar9300_flash_read(struct ath_hal *ah, u_int off, u_int16_t *data)319{320struct ath_hal_9300 *ahp = AH9300(ah);321322*data = ((u_int16_t *)ahp->ah_cal_mem)[off];323return AH_TRUE;324}325326HAL_BOOL327ar9300_flash_write(struct ath_hal *ah, u_int off, u_int16_t data)328{329struct ath_hal_9300 *ahp = AH9300(ah);330331((u_int16_t *)ahp->ah_cal_mem)[off] = data;332return AH_TRUE;333}334335HAL_STATUS336ar9300_eeprom_attach(struct ath_hal *ah)337{338struct ath_hal_9300 *ahp = AH9300(ah);339ahp->try_dram = 1;340ahp->try_eeprom = 1;341ahp->try_otp = 1;342#ifdef ATH_CAL_NAND_FLASH343ahp->try_nand = 1;344#else345ahp->try_flash = 1;346#endif347ahp->calibration_data_source = calibration_data_none;348ahp->calibration_data_source_address = 0;349ahp->calibration_data_try = calibration_data_try;350ahp->calibration_data_try_address = 0;351352/*353* In case flash will be used for EEPROM. Otherwise ahp->ah_cal_mem354* must be set to NULL or the real EEPROM address.355*/356ar9300_flash_map(ah);357/*358* ###### This function always return NO SPUR.359* This is not true for many board designs.360* Does anyone use this?361*/362AH_PRIVATE(ah)->ah_getSpurChan = ar9300_eeprom_get_spur_chan;363364#ifdef OLDCODE365/* XXX Needs to be moved for dynamic selection */366ahp->ah_eeprom = *(default9300[ar9300_eeprom_template_default]);367368369if (AR_SREV_HORNET(ah)) {370/* Set default values for Hornet. */371ahp->ah_eeprom.base_eep_header.op_cap_flags.op_flags =372AR9300_OPFLAGS_11G;373ahp->ah_eeprom.base_eep_header.txrx_mask = 0x11;374} else if (AR_SREV_POSEIDON(ah)) {375/* Set default values for Poseidon. */376ahp->ah_eeprom.base_eep_header.op_cap_flags.op_flags =377AR9300_OPFLAGS_11G;378ahp->ah_eeprom.base_eep_header.txrx_mask = 0x11;379}380381if (AH_PRIVATE(ah)->ah_config.ath_hal_skip_eeprom_read) {382ahp->ah_emu_eeprom = 1;383return HAL_OK;384}385386ahp->ah_emu_eeprom = 1;387388#ifdef UNUSED389#endif390391if (!ar9300_fill_eeprom(ah)) {392return HAL_EIO;393}394395return HAL_OK;396/* return ar9300_check_eeprom(ah); */397#else398ahp->ah_emu_eeprom = 1;399400#if 0401/*#ifdef MDK_AP*/ /* MDK_AP is defined only in NART AP build */402u_int8_t buffer[10];403int caldata_check = 0;404405ar9300_calibration_data_read_flash(406ah, FLASH_BASE_CALDATA_OFFSET, buffer, 4);407printf("flash caldata:: %x\n", buffer[0]);408if (buffer[0] != 0xff) {409caldata_check = 1;410}411if (!caldata_check) {412ar9300_eeprom_t *mptr;413int mdata_size;414if (AR_SREV_HORNET(ah)) {415/* XXX: For initial testing */416mptr = &ahp->ah_eeprom;417mdata_size = ar9300_eeprom_struct_size();418ahp->ah_eeprom = ar9300_template_ap121;419ahp->ah_emu_eeprom = 1;420/* need it to let art save in to flash ????? */421calibration_data_source = calibration_data_flash;422} else if (AR_SREV_WASP(ah)) {423/* XXX: For initial testing */424ath_hal_printf(ah, " wasp eep attach\n");425mptr = &ahp->ah_eeprom;426mdata_size = ar9300_eeprom_struct_size();427ahp->ah_eeprom = ar9300_template_generic;428ahp->ah_eeprom.mac_addr[0] = 0x00;429ahp->ah_eeprom.mac_addr[1] = 0x03;430ahp->ah_eeprom.mac_addr[2] = 0x7F;431ahp->ah_eeprom.mac_addr[3] = 0xBA;432ahp->ah_eeprom.mac_addr[4] = 0xD0;433ahp->ah_eeprom.mac_addr[5] = 0x00;434ahp->ah_emu_eeprom = 1;435ahp->ah_eeprom.base_eep_header.txrx_mask = 0x33;436ahp->ah_eeprom.base_eep_header.txrxgain = 0x10;437/* need it to let art save in to flash ????? */438calibration_data_source = calibration_data_flash;439}440return HAL_OK;441}442#endif443if (AR_SREV_HORNET(ah) || AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah)444|| AR_SREV_HONEYBEE(ah)) {445ahp->try_eeprom = 0;446}447448if (AR_SREV_HONEYBEE(ah)) {449ahp->try_otp = 0;450}451452if (!ar9300_eeprom_restore(ah)) {453return HAL_EIO;454}455return HAL_OK;456#endif457}458459u_int32_t460ar9300_eeprom_get(struct ath_hal_9300 *ahp, EEPROM_PARAM param)461{462ar9300_eeprom_t *eep = &ahp->ah_eeprom;463OSPREY_BASE_EEP_HEADER *p_base = &eep->base_eep_header;464OSPREY_BASE_EXTENSION_1 *base_ext1 = &eep->base_ext1;465466switch (param) {467#ifdef NOTYET468case EEP_NFTHRESH_5:469return p_modal[0].noise_floor_thresh_ch[0];470case EEP_NFTHRESH_2:471return p_modal[1].noise_floor_thresh_ch[0];472#endif473case EEP_MAC_LSW:474return eep->mac_addr[0] << 8 | eep->mac_addr[1];475case EEP_MAC_MID:476return eep->mac_addr[2] << 8 | eep->mac_addr[3];477case EEP_MAC_MSW:478return eep->mac_addr[4] << 8 | eep->mac_addr[5];479case EEP_REG_0:480return p_base->reg_dmn[0];481case EEP_REG_1:482return p_base->reg_dmn[1];483case EEP_OP_CAP:484return p_base->device_cap;485case EEP_OP_MODE:486return p_base->op_cap_flags.op_flags;487case EEP_RF_SILENT:488return p_base->rf_silent;489#ifdef NOTYET490case EEP_OB_5:491return p_modal[0].ob;492case EEP_DB_5:493return p_modal[0].db;494case EEP_OB_2:495return p_modal[1].ob;496case EEP_DB_2:497return p_modal[1].db;498case EEP_MINOR_REV:499return p_base->eeprom_version & AR9300_EEP_VER_MINOR_MASK;500#endif501case EEP_TX_MASK:502return (p_base->txrx_mask >> 4) & 0xf;503case EEP_RX_MASK:504return p_base->txrx_mask & 0xf;505#ifdef NOTYET506case EEP_FSTCLK_5G:507return p_base->fast_clk5g;508case EEP_RXGAIN_TYPE:509return p_base->rx_gain_type;510#endif511case EEP_DRIVE_STRENGTH:512#define AR9300_EEP_BASE_DRIVE_STRENGTH 0x1513return p_base->misc_configuration & AR9300_EEP_BASE_DRIVE_STRENGTH;514case EEP_INTERNAL_REGULATOR:515/* Bit 4 is internal regulator flag */516return ((p_base->feature_enable & 0x10) >> 4);517case EEP_SWREG:518return (p_base->swreg);519case EEP_PAPRD_ENABLED:520/* Bit 5 is paprd flag */521return ((p_base->feature_enable & 0x20) >> 5);522case EEP_ANTDIV_control:523return (u_int32_t)(base_ext1->ant_div_control);524case EEP_CHAIN_MASK_REDUCE:525return ((p_base->misc_configuration >> 3) & 0x1);526case EEP_OL_PWRCTRL:527return 0;528case EEP_DEV_TYPE:529return p_base->device_type;530default:531HALASSERT(0);532return 0;533}534}535536537538/******************************************************************************/539/*!540** \brief EEPROM fixup code for INI values541**542** This routine provides a place to insert "fixup" code for specific devices543** that need to modify INI values based on EEPROM values, BEFORE the INI values544** are written.545** Certain registers in the INI file can only be written once without546** undesired side effects, and this provides a place for EEPROM overrides547** in these cases.548**549** This is called at attach time once. It should not affect run time550** performance at all551**552** \param ah Pointer to HAL object (this)553** \param p_eep_data Pointer to (filled in) eeprom data structure554** \param reg register being inspected on this call555** \param value value in INI file556**557** \return Updated value for INI file.558*/559u_int32_t560ar9300_ini_fixup(struct ath_hal *ah, ar9300_eeprom_t *p_eep_data,561u_int32_t reg, u_int32_t value)562{563HALDEBUG(AH_NULL, HAL_DEBUG_UNMASKABLE,564"ar9300_eeprom_def_ini_fixup: FIXME\n");565#if 0566BASE_EEPDEF_HEADER *p_base = &(p_eep_data->base_eep_header);567568switch (AH_PRIVATE(ah)->ah_devid)569{570case AR9300_DEVID_AR9300_PCI:571/*572** Need to set the external/internal regulator bit to the proper value.573** Can only write this ONCE.574*/575576if ( reg == 0x7894 )577{578/*579** Check for an EEPROM data structure of "0x0b" or better580*/581582HALDEBUG(ah, HAL_DEBUG_EEPROM, "ini VAL: %x EEPROM: %x\n",583value, (p_base->version & 0xff));584585if ( (p_base->version & 0xff) > 0x0a) {586HALDEBUG(ah, HAL_DEBUG_EEPROM,587"PWDCLKIND: %d\n", p_base->pwdclkind);588value &= ~AR_AN_TOP2_PWDCLKIND;589value |=590AR_AN_TOP2_PWDCLKIND &591(p_base->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);592} else {593HALDEBUG(ah, HAL_DEBUG_EEPROM, "PWDCLKIND Earlier Rev\n");594}595596HALDEBUG(ah, HAL_DEBUG_EEPROM, "final ini VAL: %x\n", value);597}598break;599600}601602return (value);603#else604return 0;605#endif606}607608/*609* Returns the interpolated y value corresponding to the specified x value610* from the np ordered pairs of data (px,py).611* The pairs do not have to be in any order.612* If the specified x value is less than any of the px,613* the returned y value is equal to the py for the lowest px.614* If the specified x value is greater than any of the px,615* the returned y value is equal to the py for the highest px.616*/617static int618interpolate(int32_t x, int32_t *px, int32_t *py, u_int16_t np)619{620int ip = 0;621int lx = 0, ly = 0, lhave = 0;622int hx = 0, hy = 0, hhave = 0;623int dx = 0;624int y = 0;625int bf, factor, plus;626627lhave = 0;628hhave = 0;629/*630* identify best lower and higher x calibration measurement631*/632for (ip = 0; ip < np; ip++) {633dx = x - px[ip];634/* this measurement is higher than our desired x */635if (dx <= 0) {636if (!hhave || dx > (x - hx)) {637/* new best higher x measurement */638hx = px[ip];639hy = py[ip];640hhave = 1;641}642}643/* this measurement is lower than our desired x */644if (dx >= 0) {645if (!lhave || dx < (x - lx)) {646/* new best lower x measurement */647lx = px[ip];648ly = py[ip];649lhave = 1;650}651}652}653/* the low x is good */654if (lhave) {655/* so is the high x */656if (hhave) {657/* they're the same, so just pick one */658if (hx == lx) {659y = ly;660} else {661/* interpolate with round off */662bf = (2 * (hy - ly) * (x - lx)) / (hx - lx);663plus = (bf % 2);664factor = bf / 2;665y = ly + factor + plus;666}667} else {668/* only low is good, use it */669y = ly;670}671} else if (hhave) {672/* only high is good, use it */673y = hy;674} else {675/* nothing is good,this should never happen unless np=0, ???? */676y = -(1 << 30);677}678679return y;680}681682u_int8_t683ar9300_eeprom_get_legacy_trgt_pwr(struct ath_hal *ah, u_int16_t rate_index,684u_int16_t freq, HAL_BOOL is_2ghz)685{686u_int16_t num_piers, i;687int32_t target_power_array[OSPREY_NUM_5G_20_TARGET_POWERS];688int32_t freq_array[OSPREY_NUM_5G_20_TARGET_POWERS];689u_int8_t *p_freq_bin;690ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;691CAL_TARGET_POWER_LEG *p_eeprom_target_pwr;692693if (is_2ghz) {694num_piers = OSPREY_NUM_2G_20_TARGET_POWERS;695p_eeprom_target_pwr = eep->cal_target_power_2g;696p_freq_bin = eep->cal_target_freqbin_2g;697} else {698num_piers = OSPREY_NUM_5G_20_TARGET_POWERS;699p_eeprom_target_pwr = eep->cal_target_power_5g;700p_freq_bin = eep->cal_target_freqbin_5g;701}702703/*704* create array of channels and targetpower from705* targetpower piers stored on eeprom706*/707for (i = 0; i < num_piers; i++) {708freq_array[i] = FBIN2FREQ(p_freq_bin[i], is_2ghz);709target_power_array[i] = p_eeprom_target_pwr[i].t_pow2x[rate_index];710}711712/* interpolate to get target power for given frequency */713return714((u_int8_t)interpolate(715(int32_t)freq, freq_array, target_power_array, num_piers));716}717718u_int8_t719ar9300_eeprom_get_ht20_trgt_pwr(struct ath_hal *ah, u_int16_t rate_index,720u_int16_t freq, HAL_BOOL is_2ghz)721{722u_int16_t num_piers, i;723int32_t target_power_array[OSPREY_NUM_5G_20_TARGET_POWERS];724int32_t freq_array[OSPREY_NUM_5G_20_TARGET_POWERS];725u_int8_t *p_freq_bin;726ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;727OSP_CAL_TARGET_POWER_HT *p_eeprom_target_pwr;728729if (is_2ghz) {730num_piers = OSPREY_NUM_2G_20_TARGET_POWERS;731p_eeprom_target_pwr = eep->cal_target_power_2g_ht20;732p_freq_bin = eep->cal_target_freqbin_2g_ht20;733} else {734num_piers = OSPREY_NUM_5G_20_TARGET_POWERS;735p_eeprom_target_pwr = eep->cal_target_power_5g_ht20;736p_freq_bin = eep->cal_target_freqbin_5g_ht20;737}738739/*740* create array of channels and targetpower from741* targetpower piers stored on eeprom742*/743for (i = 0; i < num_piers; i++) {744freq_array[i] = FBIN2FREQ(p_freq_bin[i], is_2ghz);745target_power_array[i] = p_eeprom_target_pwr[i].t_pow2x[rate_index];746}747748/* interpolate to get target power for given frequency */749return750((u_int8_t)interpolate(751(int32_t)freq, freq_array, target_power_array, num_piers));752}753754u_int8_t755ar9300_eeprom_get_ht40_trgt_pwr(struct ath_hal *ah, u_int16_t rate_index,756u_int16_t freq, HAL_BOOL is_2ghz)757{758u_int16_t num_piers, i;759int32_t target_power_array[OSPREY_NUM_5G_40_TARGET_POWERS];760int32_t freq_array[OSPREY_NUM_5G_40_TARGET_POWERS];761u_int8_t *p_freq_bin;762ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;763OSP_CAL_TARGET_POWER_HT *p_eeprom_target_pwr;764765if (is_2ghz) {766num_piers = OSPREY_NUM_2G_40_TARGET_POWERS;767p_eeprom_target_pwr = eep->cal_target_power_2g_ht40;768p_freq_bin = eep->cal_target_freqbin_2g_ht40;769} else {770num_piers = OSPREY_NUM_5G_40_TARGET_POWERS;771p_eeprom_target_pwr = eep->cal_target_power_5g_ht40;772p_freq_bin = eep->cal_target_freqbin_5g_ht40;773}774775/*776* create array of channels and targetpower from777* targetpower piers stored on eeprom778*/779for (i = 0; i < num_piers; i++) {780freq_array[i] = FBIN2FREQ(p_freq_bin[i], is_2ghz);781target_power_array[i] = p_eeprom_target_pwr[i].t_pow2x[rate_index];782}783784/* interpolate to get target power for given frequency */785return786((u_int8_t)interpolate(787(int32_t)freq, freq_array, target_power_array, num_piers));788}789790u_int8_t791ar9300_eeprom_get_cck_trgt_pwr(struct ath_hal *ah, u_int16_t rate_index,792u_int16_t freq)793{794u_int16_t num_piers = OSPREY_NUM_2G_CCK_TARGET_POWERS, i;795int32_t target_power_array[OSPREY_NUM_2G_CCK_TARGET_POWERS];796int32_t freq_array[OSPREY_NUM_2G_CCK_TARGET_POWERS];797ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;798u_int8_t *p_freq_bin = eep->cal_target_freqbin_cck;799CAL_TARGET_POWER_LEG *p_eeprom_target_pwr = eep->cal_target_power_cck;800801/*802* create array of channels and targetpower from803* targetpower piers stored on eeprom804*/805for (i = 0; i < num_piers; i++) {806freq_array[i] = FBIN2FREQ(p_freq_bin[i], 1);807target_power_array[i] = p_eeprom_target_pwr[i].t_pow2x[rate_index];808}809810/* interpolate to get target power for given frequency */811return812((u_int8_t)interpolate(813(int32_t)freq, freq_array, target_power_array, num_piers));814}815816/*817* Set tx power registers to array of values passed in818*/819int820ar9300_transmit_power_reg_write(struct ath_hal *ah, u_int8_t *p_pwr_array)821{822#define POW_SM(_r, _s) (((_r) & 0x3f) << (_s))823/* make sure forced gain is not set */824#if 0825field_write("force_dac_gain", 0);826OS_REG_WRITE(ah, 0xa3f8, 0);827field_write("force_tx_gain", 0);828#endif829830OS_REG_WRITE(ah, 0xa458, 0);831832/* Write the OFDM power per rate set */833/* 6 (LSB), 9, 12, 18 (MSB) */834OS_REG_WRITE(ah, 0xa3c0,835POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 24)836| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 16)837| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 8)838| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 0)839);840/* 24 (LSB), 36, 48, 54 (MSB) */841OS_REG_WRITE(ah, 0xa3c4,842POW_SM(p_pwr_array[ALL_TARGET_LEGACY_54], 24)843| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_48], 16)844| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_36], 8)845| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 0)846);847848/* Write the CCK power per rate set */849/* 1L (LSB), reserved, 2L, 2S (MSB) */850OS_REG_WRITE(ah, 0xa3c8,851POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 24)852| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 16)853/* | POW_SM(tx_power_times2, 8)*/ /* this is reserved for Osprey */854| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 0)855);856/* 5.5L (LSB), 5.5S, 11L, 11S (MSB) */857OS_REG_WRITE(ah, 0xa3cc,858POW_SM(p_pwr_array[ALL_TARGET_LEGACY_11S], 24)859| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_11L], 16)860| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_5S], 8)861| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 0)862);863864/* write the power for duplicated frames - HT40 */865/* dup40_cck (LSB), dup40_ofdm, ext20_cck, ext20_ofdm (MSB) */866OS_REG_WRITE(ah, 0xa3e0,867POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 24)868| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 16)869| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], 8)870| POW_SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], 0)871);872873/* Write the HT20 power per rate set */874/* 0/8/16 (LSB), 1-3/9-11/17-19, 4, 5 (MSB) */875OS_REG_WRITE(ah, 0xa3d0,876POW_SM(p_pwr_array[ALL_TARGET_HT20_5], 24)877| POW_SM(p_pwr_array[ALL_TARGET_HT20_4], 16)878| POW_SM(p_pwr_array[ALL_TARGET_HT20_1_3_9_11_17_19], 8)879| POW_SM(p_pwr_array[ALL_TARGET_HT20_0_8_16], 0)880);881882/* 6 (LSB), 7, 12, 13 (MSB) */883OS_REG_WRITE(ah, 0xa3d4,884POW_SM(p_pwr_array[ALL_TARGET_HT20_13], 24)885| POW_SM(p_pwr_array[ALL_TARGET_HT20_12], 16)886| POW_SM(p_pwr_array[ALL_TARGET_HT20_7], 8)887| POW_SM(p_pwr_array[ALL_TARGET_HT20_6], 0)888);889890/* 14 (LSB), 15, 20, 21 */891OS_REG_WRITE(ah, 0xa3e4,892POW_SM(p_pwr_array[ALL_TARGET_HT20_21], 24)893| POW_SM(p_pwr_array[ALL_TARGET_HT20_20], 16)894| POW_SM(p_pwr_array[ALL_TARGET_HT20_15], 8)895| POW_SM(p_pwr_array[ALL_TARGET_HT20_14], 0)896);897898/* Mixed HT20 and HT40 rates */899/* HT20 22 (LSB), HT20 23, HT40 22, HT40 23 (MSB) */900OS_REG_WRITE(ah, 0xa3e8,901POW_SM(p_pwr_array[ALL_TARGET_HT40_23], 24)902| POW_SM(p_pwr_array[ALL_TARGET_HT40_22], 16)903| POW_SM(p_pwr_array[ALL_TARGET_HT20_23], 8)904| POW_SM(p_pwr_array[ALL_TARGET_HT20_22], 0)905);906907/* Write the HT40 power per rate set */908/* correct PAR difference between HT40 and HT20/LEGACY */909/* 0/8/16 (LSB), 1-3/9-11/17-19, 4, 5 (MSB) */910OS_REG_WRITE(ah, 0xa3d8,911POW_SM(p_pwr_array[ALL_TARGET_HT40_5], 24)912| POW_SM(p_pwr_array[ALL_TARGET_HT40_4], 16)913| POW_SM(p_pwr_array[ALL_TARGET_HT40_1_3_9_11_17_19], 8)914| POW_SM(p_pwr_array[ALL_TARGET_HT40_0_8_16], 0)915);916917/* 6 (LSB), 7, 12, 13 (MSB) */918OS_REG_WRITE(ah, 0xa3dc,919POW_SM(p_pwr_array[ALL_TARGET_HT40_13], 24)920| POW_SM(p_pwr_array[ALL_TARGET_HT40_12], 16)921| POW_SM(p_pwr_array[ALL_TARGET_HT40_7], 8)922| POW_SM(p_pwr_array[ALL_TARGET_HT40_6], 0)923);924925/* 14 (LSB), 15, 20, 21 */926OS_REG_WRITE(ah, 0xa3ec,927POW_SM(p_pwr_array[ALL_TARGET_HT40_21], 24)928| POW_SM(p_pwr_array[ALL_TARGET_HT40_20], 16)929| POW_SM(p_pwr_array[ALL_TARGET_HT40_15], 8)930| POW_SM(p_pwr_array[ALL_TARGET_HT40_14], 0)931);932933return 0;934#undef POW_SM935}936937static void938ar9300_selfgen_tpc_reg_write(struct ath_hal *ah, const struct ieee80211_channel *chan,939u_int8_t *p_pwr_array)940{941u_int32_t tpc_reg_val;942943/* Set the target power values for self generated frames (ACK,RTS/CTS) to944* be within limits. This is just a safety measure.With per packet TPC mode945* enabled the target power value used with self generated frames will be946* MIN( TPC reg, BB_powertx_rate register)947*/948949if (IEEE80211_IS_CHAN_2GHZ(chan)) {950tpc_reg_val = (SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], AR_TPC_ACK) |951SM(p_pwr_array[ALL_TARGET_LEGACY_1L_5L], AR_TPC_CTS) |952SM(0x3f, AR_TPC_CHIRP) |953SM(0x3f, AR_TPC_RPT));954} else {955tpc_reg_val = (SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], AR_TPC_ACK) |956SM(p_pwr_array[ALL_TARGET_LEGACY_6_24], AR_TPC_CTS) |957SM(0x3f, AR_TPC_CHIRP) |958SM(0x3f, AR_TPC_RPT));959}960OS_REG_WRITE(ah, AR_TPC, tpc_reg_val);961}962963void964ar9300_set_target_power_from_eeprom(struct ath_hal *ah, u_int16_t freq,965u_int8_t *target_power_val_t2)966{967/* hard code for now, need to get from eeprom struct */968u_int8_t ht40_power_inc_for_pdadc = 0;969HAL_BOOL is_2ghz = 0;970971if (freq < 4000) {972is_2ghz = 1;973}974975target_power_val_t2[ALL_TARGET_LEGACY_6_24] =976ar9300_eeprom_get_legacy_trgt_pwr(977ah, LEGACY_TARGET_RATE_6_24, freq, is_2ghz);978target_power_val_t2[ALL_TARGET_LEGACY_36] =979ar9300_eeprom_get_legacy_trgt_pwr(980ah, LEGACY_TARGET_RATE_36, freq, is_2ghz);981target_power_val_t2[ALL_TARGET_LEGACY_48] =982ar9300_eeprom_get_legacy_trgt_pwr(983ah, LEGACY_TARGET_RATE_48, freq, is_2ghz);984target_power_val_t2[ALL_TARGET_LEGACY_54] =985ar9300_eeprom_get_legacy_trgt_pwr(986ah, LEGACY_TARGET_RATE_54, freq, is_2ghz);987target_power_val_t2[ALL_TARGET_LEGACY_1L_5L] =988ar9300_eeprom_get_cck_trgt_pwr(989ah, LEGACY_TARGET_RATE_1L_5L, freq);990target_power_val_t2[ALL_TARGET_LEGACY_5S] =991ar9300_eeprom_get_cck_trgt_pwr(992ah, LEGACY_TARGET_RATE_5S, freq);993target_power_val_t2[ALL_TARGET_LEGACY_11L] =994ar9300_eeprom_get_cck_trgt_pwr(995ah, LEGACY_TARGET_RATE_11L, freq);996target_power_val_t2[ALL_TARGET_LEGACY_11S] =997ar9300_eeprom_get_cck_trgt_pwr(998ah, LEGACY_TARGET_RATE_11S, freq);999target_power_val_t2[ALL_TARGET_HT20_0_8_16] =1000ar9300_eeprom_get_ht20_trgt_pwr(1001ah, HT_TARGET_RATE_0_8_16, freq, is_2ghz);1002target_power_val_t2[ALL_TARGET_HT20_1_3_9_11_17_19] =1003ar9300_eeprom_get_ht20_trgt_pwr(1004ah, HT_TARGET_RATE_1_3_9_11_17_19, freq, is_2ghz);1005target_power_val_t2[ALL_TARGET_HT20_4] =1006ar9300_eeprom_get_ht20_trgt_pwr(1007ah, HT_TARGET_RATE_4, freq, is_2ghz);1008target_power_val_t2[ALL_TARGET_HT20_5] =1009ar9300_eeprom_get_ht20_trgt_pwr(1010ah, HT_TARGET_RATE_5, freq, is_2ghz);1011target_power_val_t2[ALL_TARGET_HT20_6] =1012ar9300_eeprom_get_ht20_trgt_pwr(1013ah, HT_TARGET_RATE_6, freq, is_2ghz);1014target_power_val_t2[ALL_TARGET_HT20_7] =1015ar9300_eeprom_get_ht20_trgt_pwr(1016ah, HT_TARGET_RATE_7, freq, is_2ghz);1017target_power_val_t2[ALL_TARGET_HT20_12] =1018ar9300_eeprom_get_ht20_trgt_pwr(1019ah, HT_TARGET_RATE_12, freq, is_2ghz);1020target_power_val_t2[ALL_TARGET_HT20_13] =1021ar9300_eeprom_get_ht20_trgt_pwr(1022ah, HT_TARGET_RATE_13, freq, is_2ghz);1023target_power_val_t2[ALL_TARGET_HT20_14] =1024ar9300_eeprom_get_ht20_trgt_pwr(1025ah, HT_TARGET_RATE_14, freq, is_2ghz);1026target_power_val_t2[ALL_TARGET_HT20_15] =1027ar9300_eeprom_get_ht20_trgt_pwr(1028ah, HT_TARGET_RATE_15, freq, is_2ghz);1029target_power_val_t2[ALL_TARGET_HT20_20] =1030ar9300_eeprom_get_ht20_trgt_pwr(1031ah, HT_TARGET_RATE_20, freq, is_2ghz);1032target_power_val_t2[ALL_TARGET_HT20_21] =1033ar9300_eeprom_get_ht20_trgt_pwr(1034ah, HT_TARGET_RATE_21, freq, is_2ghz);1035target_power_val_t2[ALL_TARGET_HT20_22] =1036ar9300_eeprom_get_ht20_trgt_pwr(1037ah, HT_TARGET_RATE_22, freq, is_2ghz);1038target_power_val_t2[ALL_TARGET_HT20_23] =1039ar9300_eeprom_get_ht20_trgt_pwr(1040ah, HT_TARGET_RATE_23, freq, is_2ghz);1041target_power_val_t2[ALL_TARGET_HT40_0_8_16] =1042ar9300_eeprom_get_ht40_trgt_pwr(1043ah, HT_TARGET_RATE_0_8_16, freq, is_2ghz) +1044ht40_power_inc_for_pdadc;1045target_power_val_t2[ALL_TARGET_HT40_1_3_9_11_17_19] =1046ar9300_eeprom_get_ht40_trgt_pwr(1047ah, HT_TARGET_RATE_1_3_9_11_17_19, freq, is_2ghz) +1048ht40_power_inc_for_pdadc;1049target_power_val_t2[ALL_TARGET_HT40_4] =1050ar9300_eeprom_get_ht40_trgt_pwr(1051ah, HT_TARGET_RATE_4, freq, is_2ghz) + ht40_power_inc_for_pdadc;1052target_power_val_t2[ALL_TARGET_HT40_5] =1053ar9300_eeprom_get_ht40_trgt_pwr(1054ah, HT_TARGET_RATE_5, freq, is_2ghz) + ht40_power_inc_for_pdadc;1055target_power_val_t2[ALL_TARGET_HT40_6] =1056ar9300_eeprom_get_ht40_trgt_pwr(1057ah, HT_TARGET_RATE_6, freq, is_2ghz) + ht40_power_inc_for_pdadc;1058target_power_val_t2[ALL_TARGET_HT40_7] =1059ar9300_eeprom_get_ht40_trgt_pwr(1060ah, HT_TARGET_RATE_7, freq, is_2ghz) + ht40_power_inc_for_pdadc;1061target_power_val_t2[ALL_TARGET_HT40_12] =1062ar9300_eeprom_get_ht40_trgt_pwr(1063ah, HT_TARGET_RATE_12, freq, is_2ghz) + ht40_power_inc_for_pdadc;1064target_power_val_t2[ALL_TARGET_HT40_13] =1065ar9300_eeprom_get_ht40_trgt_pwr(1066ah, HT_TARGET_RATE_13, freq, is_2ghz) + ht40_power_inc_for_pdadc;1067target_power_val_t2[ALL_TARGET_HT40_14] =1068ar9300_eeprom_get_ht40_trgt_pwr(1069ah, HT_TARGET_RATE_14, freq, is_2ghz) + ht40_power_inc_for_pdadc;1070target_power_val_t2[ALL_TARGET_HT40_15] =1071ar9300_eeprom_get_ht40_trgt_pwr(1072ah, HT_TARGET_RATE_15, freq, is_2ghz) + ht40_power_inc_for_pdadc;1073target_power_val_t2[ALL_TARGET_HT40_20] =1074ar9300_eeprom_get_ht40_trgt_pwr(1075ah, HT_TARGET_RATE_20, freq, is_2ghz) + ht40_power_inc_for_pdadc;1076target_power_val_t2[ALL_TARGET_HT40_21] =1077ar9300_eeprom_get_ht40_trgt_pwr(1078ah, HT_TARGET_RATE_21, freq, is_2ghz) + ht40_power_inc_for_pdadc;1079target_power_val_t2[ALL_TARGET_HT40_22] =1080ar9300_eeprom_get_ht40_trgt_pwr(1081ah, HT_TARGET_RATE_22, freq, is_2ghz) + ht40_power_inc_for_pdadc;1082target_power_val_t2[ALL_TARGET_HT40_23] =1083ar9300_eeprom_get_ht40_trgt_pwr(1084ah, HT_TARGET_RATE_23, freq, is_2ghz) + ht40_power_inc_for_pdadc;10851086#ifdef AH_DEBUG1087{1088int i = 0;10891090HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: APPLYING TARGET POWERS\n", __func__);1091while (i < ar9300_rate_size) {1092HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: TPC[%02d] 0x%08x ",1093__func__, i, target_power_val_t2[i]);1094i++;1095if (i == ar9300_rate_size) {1096break;1097}1098HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: TPC[%02d] 0x%08x ",1099__func__, i, target_power_val_t2[i]);1100i++;1101if (i == ar9300_rate_size) {1102break;1103}1104HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: TPC[%02d] 0x%08x ",1105__func__, i, target_power_val_t2[i]);1106i++;1107if (i == ar9300_rate_size) {1108break;1109}1110HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: TPC[%02d] 0x%08x \n",1111__func__, i, target_power_val_t2[i]);1112i++;1113}1114}1115#endif1116}11171118u_int16_t *ar9300_regulatory_domain_get(struct ath_hal *ah)1119{1120ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1121return eep->base_eep_header.reg_dmn;1122}112311241125int32_t1126ar9300_eeprom_write_enable_gpio_get(struct ath_hal *ah)1127{1128ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1129return eep->base_eep_header.eeprom_write_enable_gpio;1130}11311132int32_t1133ar9300_wlan_disable_gpio_get(struct ath_hal *ah)1134{1135ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1136return eep->base_eep_header.wlan_disable_gpio;1137}11381139int32_t1140ar9300_wlan_led_gpio_get(struct ath_hal *ah)1141{1142ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1143return eep->base_eep_header.wlan_led_gpio;1144}11451146int32_t1147ar9300_rx_band_select_gpio_get(struct ath_hal *ah)1148{1149ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1150return eep->base_eep_header.rx_band_select_gpio;1151}11521153/*1154* since valid noise floor values are negative, returns 1 on error1155*/1156int32_t1157ar9300_noise_floor_cal_or_power_get(struct ath_hal *ah, int32_t frequency,1158int32_t ichain, HAL_BOOL use_cal)1159{1160int nf_use = 1; /* start with an error return value */1161int32_t fx[OSPREY_NUM_5G_CAL_PIERS + OSPREY_NUM_2G_CAL_PIERS];1162int32_t nf[OSPREY_NUM_5G_CAL_PIERS + OSPREY_NUM_2G_CAL_PIERS];1163int nnf;1164int is_2ghz;1165int ipier, npier;1166ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1167u_int8_t *p_cal_pier;1168OSP_CAL_DATA_PER_FREQ_OP_LOOP *p_cal_pier_struct;11691170/*1171* check chain value1172*/1173if (ichain < 0 || ichain >= OSPREY_MAX_CHAINS) {1174return 1;1175}11761177/* figure out which band we're using */1178is_2ghz = (frequency < 4000);1179if (is_2ghz) {1180npier = OSPREY_NUM_2G_CAL_PIERS;1181p_cal_pier = eep->cal_freq_pier_2g;1182p_cal_pier_struct = eep->cal_pier_data_2g[ichain];1183} else {1184npier = OSPREY_NUM_5G_CAL_PIERS;1185p_cal_pier = eep->cal_freq_pier_5g;1186p_cal_pier_struct = eep->cal_pier_data_5g[ichain];1187}1188/* look for valid noise floor values */1189nnf = 0;1190for (ipier = 0; ipier < npier; ipier++) {1191fx[nnf] = FBIN2FREQ(p_cal_pier[ipier], is_2ghz);1192nf[nnf] = use_cal ?1193p_cal_pier_struct[ipier].rx_noisefloor_cal :1194p_cal_pier_struct[ipier].rx_noisefloor_power;1195if (nf[nnf] < 0) {1196nnf++;1197}1198}1199/*1200* If we have some valid values, interpolate to find the value1201* at the desired frequency.1202*/1203if (nnf > 0) {1204nf_use = interpolate(frequency, fx, nf, nnf);1205}12061207return nf_use;1208}12091210/*1211* Return the Rx NF offset for specific channel.1212* The values saved in EEPROM/OTP/Flash is converted through the following way:1213* ((_p) - NOISE_PWR_DATA_OFFSET) << 21214* So we need to convert back to the original values.1215*/1216int ar9300_get_rx_nf_offset(struct ath_hal *ah, struct ieee80211_channel *chan, int8_t *nf_pwr, int8_t *nf_cal) {1217HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, chan);1218int8_t rx_nf_pwr, rx_nf_cal;1219int i;1220//HALASSERT(ichan);12211222/* Fill 0 if valid internal channel is not found */1223if (ichan == AH_NULL) {1224OS_MEMZERO(nf_pwr, sizeof(nf_pwr[0])*OSPREY_MAX_CHAINS);1225OS_MEMZERO(nf_cal, sizeof(nf_cal[0])*OSPREY_MAX_CHAINS);1226return -1;1227}12281229for (i = 0; i < OSPREY_MAX_CHAINS; i++) {1230if ((rx_nf_pwr = ar9300_noise_floor_cal_or_power_get(ah, ichan->channel, i, 0)) == 1) {1231nf_pwr[i] = 0;1232} else {1233//printk("%s: raw nf_pwr[%d] = %d\n", __func__, i, rx_nf_pwr);1234nf_pwr[i] = NOISE_PWR_DBM_2_INT(rx_nf_pwr);1235}12361237if ((rx_nf_cal = ar9300_noise_floor_cal_or_power_get(ah, ichan->channel, i, 1)) == 1) {1238nf_cal[i] = 0;1239} else {1240//printk("%s: raw nf_cal[%d] = %d\n", __func__, i, rx_nf_cal);1241nf_cal[i] = NOISE_PWR_DBM_2_INT(rx_nf_cal);1242}1243}12441245return 0;1246}12471248int32_t ar9300_rx_gain_index_get(struct ath_hal *ah)1249{1250ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;12511252return (eep->base_eep_header.txrxgain) & 0xf; /* bits 3:0 */1253}125412551256int32_t ar9300_tx_gain_index_get(struct ath_hal *ah)1257{1258ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;12591260return (eep->base_eep_header.txrxgain >> 4) & 0xf; /* bits 7:4 */1261}12621263HAL_BOOL ar9300_internal_regulator_apply(struct ath_hal *ah)1264{1265struct ath_hal_9300 *ahp = AH9300(ah);1266int internal_regulator = ar9300_eeprom_get(ahp, EEP_INTERNAL_REGULATOR);1267int reg_pmu1, reg_pmu2, reg_pmu1_set, reg_pmu2_set;1268u_int32_t reg_PMU1, reg_PMU2;1269unsigned long eep_addr;1270u_int32_t reg_val, reg_usb = 0, reg_pmu = 0;1271int usb_valid = 0, pmu_valid = 0;1272unsigned char pmu_refv;12731274if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {1275reg_PMU1 = AR_PHY_PMU1_JUPITER;1276reg_PMU2 = AR_PHY_PMU2_JUPITER;1277}1278else {1279reg_PMU1 = AR_PHY_PMU1;1280reg_PMU2 = AR_PHY_PMU2;1281}12821283if (internal_regulator) {1284if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah)) {1285if (AR_SREV_HORNET(ah)) {1286/* Read OTP first */1287for (eep_addr = 0x14; ; eep_addr -= 0x10) {12881289ar9300_otp_read(ah, eep_addr / 4, ®_val, 1);12901291if ((reg_val & 0x80) == 0x80){1292usb_valid = 1;1293reg_usb = reg_val & 0x000000ff;1294}12951296if ((reg_val & 0x80000000) == 0x80000000){1297pmu_valid = 1;1298reg_pmu = (reg_val & 0xff000000) >> 24;1299}13001301if (eep_addr == 0x4) {1302break;1303}1304}13051306if (pmu_valid) {1307pmu_refv = reg_pmu & 0xf;1308} else {1309pmu_refv = 0x8;1310}13111312/*1313* If (valid) {1314* Usb_phy_ctrl2_tx_cal_en -> 01315* Usb_phy_ctrl2_tx_cal_sel -> 01316* Usb_phy_ctrl2_tx_man_cal -> 0, 1, 3, 7 or 15 from OTP1317* }1318*/1319if (usb_valid) {1320OS_REG_RMW_FIELD(ah, 0x16c88, AR_PHY_CTRL2_TX_CAL_EN, 0x0);1321OS_REG_RMW_FIELD(ah, 0x16c88, AR_PHY_CTRL2_TX_CAL_SEL, 0x0);1322OS_REG_RMW_FIELD(ah, 0x16c88,1323AR_PHY_CTRL2_TX_MAN_CAL, (reg_usb & 0xf));1324}13251326} else {1327pmu_refv = 0x8;1328}1329/*#ifndef USE_HIF*/1330/* Follow the MDK settings for Hornet PMU.1331* my $pwd = 0x0;1332* my $Nfdiv = 0x3; # xtal_freq = 25MHz1333* my $Nfdiv = 0x4; # xtal_freq = 40MHz1334* my $Refv = 0x7; # 0x5:1.22V; 0x8:1.29V1335* my $Gm1 = 0x3; #Poseidon $Gm1=11336* my $classb = 0x0;1337* my $Cc = 0x1; #Poseidon $Cc=71338* my $Rc = 0x6;1339* my $ramp_slope = 0x1;1340* my $Segm = 0x3;1341* my $use_local_osc = 0x0;1342* my $force_xosc_stable = 0x0;1343* my $Selfb = 0x0; #Poseidon $Selfb=11344* my $Filterfb = 0x3; #Poseidon $Filterfb=01345* my $Filtervc = 0x0;1346* my $disc = 0x0;1347* my $discdel = 0x4;1348* my $spare = 0x0;1349* $reg_PMU1 =1350* $pwd | ($Nfdiv<<1) | ($Refv<<4) | ($Gm1<<8) |1351* ($classb<<11) | ($Cc<<14) | ($Rc<<17) | ($ramp_slope<<20) |1352* ($Segm<<24) | ($use_local_osc<<26) |1353* ($force_xosc_stable<<27) | ($Selfb<<28) | ($Filterfb<<29);1354* $reg_PMU2 = $handle->reg_rd("ch0_PMU2");1355* $reg_PMU2 = ($reg_PMU2 & 0xfe3fffff) | ($Filtervc<<22);1356* $reg_PMU2 = ($reg_PMU2 & 0xe3ffffff) | ($discdel<<26);1357* $reg_PMU2 = ($reg_PMU2 & 0x1fffffff) | ($spare<<29);1358*/1359if (ahp->clk_25mhz) {1360reg_pmu1_set = 0 |1361(3 << 1) | (pmu_refv << 4) | (3 << 8) | (0 << 11) |1362(1 << 14) | (6 << 17) | (1 << 20) | (3 << 24) |1363(0 << 26) | (0 << 27) | (0 << 28) | (0 << 29);1364} else {1365if (AR_SREV_POSEIDON(ah)) {1366reg_pmu1_set = 0 |1367(5 << 1) | (7 << 4) | (2 << 8) | (0 << 11) |1368(2 << 14) | (6 << 17) | (1 << 20) | (3 << 24) |1369(0 << 26) | (0 << 27) | (1 << 28) | (0 << 29) ;1370} else {1371reg_pmu1_set = 0 |1372(4 << 1) | (7 << 4) | (3 << 8) | (0 << 11) |1373(1 << 14) | (6 << 17) | (1 << 20) | (3 << 24) |1374(0 << 26) | (0 << 27) | (0 << 28) | (0 << 29) ;1375}1376}1377OS_REG_RMW_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM, 0x0);13781379OS_REG_WRITE(ah, reg_PMU1, reg_pmu1_set); /* 0x638c8376 */1380reg_pmu1 = OS_REG_READ(ah, reg_PMU1);1381while (reg_pmu1 != reg_pmu1_set) {1382OS_REG_WRITE(ah, reg_PMU1, reg_pmu1_set); /* 0x638c8376 */1383OS_DELAY(10);1384reg_pmu1 = OS_REG_READ(ah, reg_PMU1);1385}13861387reg_pmu2_set =1388(OS_REG_READ(ah, reg_PMU2) & (~0xFFC00000)) | (4 << 26);1389OS_REG_WRITE(ah, reg_PMU2, reg_pmu2_set);1390reg_pmu2 = OS_REG_READ(ah, reg_PMU2);1391while (reg_pmu2 != reg_pmu2_set) {1392OS_REG_WRITE(ah, reg_PMU2, reg_pmu2_set);1393OS_DELAY(10);1394reg_pmu2 = OS_REG_READ(ah, reg_PMU2);1395}1396reg_pmu2_set =1397(OS_REG_READ(ah, reg_PMU2) & (~0x00200000)) | (1 << 21);1398OS_REG_WRITE(ah, reg_PMU2, reg_pmu2_set);1399reg_pmu2 = OS_REG_READ(ah, reg_PMU2);1400while (reg_pmu2 != reg_pmu2_set) {1401OS_REG_WRITE(ah, reg_PMU2, reg_pmu2_set);1402OS_DELAY(10);1403reg_pmu2 = OS_REG_READ(ah, reg_PMU2);1404}1405/*#endif*/1406} else if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {1407/* Internal regulator is ON. Write swreg register. */1408int swreg = ar9300_eeprom_get(ahp, EEP_SWREG);1409OS_REG_WRITE(ah, reg_PMU1, swreg);1410} else {1411/* Internal regulator is ON. Write swreg register. */1412int swreg = ar9300_eeprom_get(ahp, EEP_SWREG);1413OS_REG_WRITE(ah, AR_RTC_REG_CONTROL1,1414OS_REG_READ(ah, AR_RTC_REG_CONTROL1) &1415(~AR_RTC_REG_CONTROL1_SWREG_PROGRAM));1416OS_REG_WRITE(ah, AR_RTC_REG_CONTROL0, swreg);1417/* Set REG_CONTROL1.SWREG_PROGRAM */1418OS_REG_WRITE(ah, AR_RTC_REG_CONTROL1,1419OS_REG_READ(ah, AR_RTC_REG_CONTROL1) |1420AR_RTC_REG_CONTROL1_SWREG_PROGRAM);1421}1422} else {1423if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah)) {1424OS_REG_RMW_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM, 0x0);1425reg_pmu2 = OS_REG_READ_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM);1426while (reg_pmu2) {1427OS_DELAY(10);1428reg_pmu2 = OS_REG_READ_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM);1429}1430OS_REG_RMW_FIELD(ah, reg_PMU1, AR_PHY_PMU1_PWD, 0x1);1431reg_pmu1 = OS_REG_READ_FIELD(ah, reg_PMU1, AR_PHY_PMU1_PWD);1432while (!reg_pmu1) {1433OS_DELAY(10);1434reg_pmu1 = OS_REG_READ_FIELD(ah, reg_PMU1, AR_PHY_PMU1_PWD);1435}1436OS_REG_RMW_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM, 0x1);1437reg_pmu2 = OS_REG_READ_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM);1438while (!reg_pmu2) {1439OS_DELAY(10);1440reg_pmu2 = OS_REG_READ_FIELD(ah, reg_PMU2, AR_PHY_PMU2_PGM);1441}1442} else if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {1443OS_REG_RMW_FIELD(ah, reg_PMU1, AR_PHY_PMU1_PWD, 0x1);1444} else {1445OS_REG_WRITE(ah, AR_RTC_SLEEP_CLK,1446(OS_REG_READ(ah, AR_RTC_SLEEP_CLK) |1447AR_RTC_FORCE_SWREG_PRD | AR_RTC_PCIE_RST_PWDN_EN));1448}1449}14501451return 0;1452}14531454HAL_BOOL ar9300_drive_strength_apply(struct ath_hal *ah)1455{1456struct ath_hal_9300 *ahp = AH9300(ah);1457int drive_strength;1458unsigned long reg;14591460drive_strength = ar9300_eeprom_get(ahp, EEP_DRIVE_STRENGTH);1461if (drive_strength) {1462reg = OS_REG_READ(ah, AR_PHY_65NM_CH0_BIAS1);1463reg &= ~0x00ffffc0;1464reg |= 0x5 << 21;1465reg |= 0x5 << 18;1466reg |= 0x5 << 15;1467reg |= 0x5 << 12;1468reg |= 0x5 << 9;1469reg |= 0x5 << 6;1470OS_REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS1, reg);14711472reg = OS_REG_READ(ah, AR_PHY_65NM_CH0_BIAS2);1473reg &= ~0xffffffe0;1474reg |= 0x5 << 29;1475reg |= 0x5 << 26;1476reg |= 0x5 << 23;1477reg |= 0x5 << 20;1478reg |= 0x5 << 17;1479reg |= 0x5 << 14;1480reg |= 0x5 << 11;1481reg |= 0x5 << 8;1482reg |= 0x5 << 5;1483OS_REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS2, reg);14841485reg = OS_REG_READ(ah, AR_PHY_65NM_CH0_BIAS4);1486reg &= ~0xff800000;1487reg |= 0x5 << 29;1488reg |= 0x5 << 26;1489reg |= 0x5 << 23;1490OS_REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS4, reg);1491}1492return 0;1493}14941495int32_t ar9300_xpa_bias_level_get(struct ath_hal *ah, HAL_BOOL is_2ghz)1496{1497ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1498if (is_2ghz) {1499return eep->modal_header_2g.xpa_bias_lvl;1500} else {1501return eep->modal_header_5g.xpa_bias_lvl;1502}1503}15041505HAL_BOOL ar9300_xpa_bias_level_apply(struct ath_hal *ah, HAL_BOOL is_2ghz)1506{1507/*1508* In ar9330 emu, we can't access radio registers,1509* merlin is used for radio part.1510*/1511int bias;1512bias = ar9300_xpa_bias_level_get(ah, is_2ghz);15131514if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah) || AR_SREV_WASP(ah)) {1515OS_REG_RMW_FIELD(ah,1516AR_HORNET_CH0_TOP2, AR_HORNET_CH0_TOP2_XPABIASLVL, bias);1517} else if (AR_SREV_SCORPION(ah)) {1518OS_REG_RMW_FIELD(ah,1519AR_SCORPION_CH0_TOP, AR_SCORPION_CH0_TOP_XPABIASLVL, bias);1520} else if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {1521OS_REG_RMW_FIELD(ah,1522AR_PHY_65NM_CH0_TOP_JUPITER, AR_PHY_65NM_CH0_TOP_XPABIASLVL, bias);1523} else {1524OS_REG_RMW_FIELD(ah,1525AR_PHY_65NM_CH0_TOP, AR_PHY_65NM_CH0_TOP_XPABIASLVL, bias);1526OS_REG_RMW_FIELD(ah,1527AR_PHY_65NM_CH0_THERM, AR_PHY_65NM_CH0_THERM_XPABIASLVL_MSB,1528bias >> 2);1529OS_REG_RMW_FIELD(ah,1530AR_PHY_65NM_CH0_THERM, AR_PHY_65NM_CH0_THERM_XPASHORT2GND, 1);1531}1532return 0;1533}15341535u_int32_t ar9300_ant_ctrl_common_get(struct ath_hal *ah, HAL_BOOL is_2ghz)1536{1537ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1538if (is_2ghz) {1539return eep->modal_header_2g.ant_ctrl_common;1540} else {1541return eep->modal_header_5g.ant_ctrl_common;1542}1543}1544static u_int16_t1545ar9300_switch_com_spdt_get(struct ath_hal *ah, HAL_BOOL is_2ghz)1546{1547ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1548if (is_2ghz) {1549return eep->modal_header_2g.switchcomspdt;1550} else {1551return eep->modal_header_5g.switchcomspdt;1552}1553}1554u_int32_t ar9300_ant_ctrl_common2_get(struct ath_hal *ah, HAL_BOOL is_2ghz)1555{1556ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1557if (is_2ghz) {1558return eep->modal_header_2g.ant_ctrl_common2;1559} else {1560return eep->modal_header_5g.ant_ctrl_common2;1561}1562}15631564u_int16_t ar9300_ant_ctrl_chain_get(struct ath_hal *ah, int chain,1565HAL_BOOL is_2ghz)1566{1567ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1568if (chain >= 0 && chain < OSPREY_MAX_CHAINS) {1569if (is_2ghz) {1570return eep->modal_header_2g.ant_ctrl_chain[chain];1571} else {1572return eep->modal_header_5g.ant_ctrl_chain[chain];1573}1574}1575return 0;1576}15771578/*1579* Select the usage of antenna via the RF switch.1580* Default values are loaded from eeprom.1581*/1582HAL_BOOL ar9300_ant_swcom_sel(struct ath_hal *ah, u_int8_t ops,1583u_int32_t *common_tbl1, u_int32_t *common_tbl2)1584{1585ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1586struct ath_hal_private *ap = AH_PRIVATE(ah);1587const struct ieee80211_channel *curchan = ap->ah_curchan;1588enum {1589ANT_SELECT_OPS_GET,1590ANT_SELECT_OPS_SET,1591};15921593if (AR_SREV_JUPITER(ah) || AR_SREV_SCORPION(ah))1594return AH_FALSE;15951596if (!curchan)1597return AH_FALSE;15981599#define AR_SWITCH_TABLE_COM_ALL (0xffff)1600#define AR_SWITCH_TABLE_COM_ALL_S (0)1601#define AR_SWITCH_TABLE_COM2_ALL (0xffffff)1602#define AR_SWITCH_TABLE_COM2_ALL_S (0)1603switch (ops) {1604case ANT_SELECT_OPS_GET:1605*common_tbl1 = OS_REG_READ_FIELD(ah, AR_PHY_SWITCH_COM,1606AR_SWITCH_TABLE_COM_ALL);1607*common_tbl2 = OS_REG_READ_FIELD(ah, AR_PHY_SWITCH_COM_2,1608AR_SWITCH_TABLE_COM2_ALL);1609break;1610case ANT_SELECT_OPS_SET:1611OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM,1612AR_SWITCH_TABLE_COM_ALL, *common_tbl1);1613OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2,1614AR_SWITCH_TABLE_COM2_ALL, *common_tbl2);16151616/* write back to eeprom */1617if (IEEE80211_IS_CHAN_2GHZ(curchan)) {1618eep->modal_header_2g.ant_ctrl_common = *common_tbl1;1619eep->modal_header_2g.ant_ctrl_common2 = *common_tbl2;1620} else {1621eep->modal_header_5g.ant_ctrl_common = *common_tbl1;1622eep->modal_header_5g.ant_ctrl_common2 = *common_tbl2;1623}16241625break;1626default:1627break;1628}16291630return AH_TRUE;1631}16321633HAL_BOOL ar9300_ant_ctrl_apply(struct ath_hal *ah, HAL_BOOL is_2ghz)1634{1635u_int32_t value;1636struct ath_hal_9300 *ahp = AH9300(ah);1637u_int32_t regval;1638struct ath_hal_private *ahpriv = AH_PRIVATE(ah);1639#if ATH_ANT_DIV_COMB1640HAL_CAPABILITIES *pcap = &ahpriv->ah_caps;1641#endif /* ATH_ANT_DIV_COMB */1642u_int32_t xlan_gpio_cfg;1643u_int8_t i;16441645HALDEBUG(ah, HAL_DEBUG_BT_COEX, "%s: use_bt_ant_enable=%d\n",1646__func__, ahp->ah_lna_div_use_bt_ant_enable);16471648/* XXX TODO: only if rx_gain_idx == 0 */1649if (AR_SREV_POSEIDON(ah)) {1650xlan_gpio_cfg = ah->ah_config.ath_hal_ext_lna_ctl_gpio;1651if (xlan_gpio_cfg) {1652for (i = 0; i < 32; i++) {1653if (xlan_gpio_cfg & (1 << i)) {1654ath_hal_gpioCfgOutput(ah, i,1655HAL_GPIO_OUTPUT_MUX_PCIE_ATTENTION_LED);1656}1657}1658}1659}1660#define AR_SWITCH_TABLE_COM_ALL (0xffff)1661#define AR_SWITCH_TABLE_COM_ALL_S (0)1662#define AR_SWITCH_TABLE_COM_JUPITER_ALL (0xffffff)1663#define AR_SWITCH_TABLE_COM_JUPITER_ALL_S (0)1664#define AR_SWITCH_TABLE_COM_SCORPION_ALL (0xffffff)1665#define AR_SWITCH_TABLE_COM_SCORPION_ALL_S (0)1666#define AR_SWITCH_TABLE_COM_HONEYBEE_ALL (0xffffff)1667#define AR_SWITCH_TABLE_COM_HONEYBEE_ALL_S (0)1668#define AR_SWITCH_TABLE_COM_SPDT (0x00f00000)1669value = ar9300_ant_ctrl_common_get(ah, is_2ghz);1670if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {1671if (AR_SREV_JUPITER_10(ah)) {1672/* Force SPDT setting for Jupiter 1.0 chips. */1673value &= ~AR_SWITCH_TABLE_COM_SPDT;1674value |= 0x00100000;1675}1676OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM,1677AR_SWITCH_TABLE_COM_JUPITER_ALL, value);1678}1679else if (AR_SREV_SCORPION(ah)) {1680OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM,1681AR_SWITCH_TABLE_COM_SCORPION_ALL, value);1682}1683else if (AR_SREV_HONEYBEE(ah)) {1684OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM,1685AR_SWITCH_TABLE_COM_HONEYBEE_ALL, value);1686}1687else {1688OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM,1689AR_SWITCH_TABLE_COM_ALL, value);1690}1691/*1692* Jupiter2.0 defines new switch table for BT/WLAN,1693* here's new field name in WB222.ref for both 2G and 5G.1694* Register: [GLB_CONTROL] GLB_CONTROL (@0x20044)1695* 15:12 R/W SWITCH_TABLE_COM_SPDT_WLAN_RX SWITCH_TABLE_COM_SPDT_WLAN_RX1696* 11:8 R/W SWITCH_TABLE_COM_SPDT_WLAN_TX SWITCH_TABLE_COM_SPDT_WLAN_TX1697* 7:4 R/W SWITCH_TABLE_COM_SPDT_WLAN_IDLE SWITCH_TABLE_COM_SPDT_WLAN_IDLE1698*/1699#define AR_SWITCH_TABLE_COM_SPDT_ALL (0x0000fff0)1700#define AR_SWITCH_TABLE_COM_SPDT_ALL_S (4)1701if (AR_SREV_JUPITER_20_OR_LATER(ah) || AR_SREV_APHRODITE(ah)) {1702value = ar9300_switch_com_spdt_get(ah, is_2ghz);1703OS_REG_RMW_FIELD(ah, AR_GLB_CONTROL,1704AR_SWITCH_TABLE_COM_SPDT_ALL, value);17051706OS_REG_SET_BIT(ah, AR_GLB_CONTROL,1707AR_BTCOEX_CTRL_SPDT_ENABLE);1708//OS_REG_SET_BIT(ah, AR_GLB_CONTROL,1709// AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);1710}17111712#define AR_SWITCH_TABLE_COM2_ALL (0xffffff)1713#define AR_SWITCH_TABLE_COM2_ALL_S (0)1714value = ar9300_ant_ctrl_common2_get(ah, is_2ghz);1715#if ATH_ANT_DIV_COMB1716if ( AR_SREV_POSEIDON(ah) && (ahp->ah_lna_div_use_bt_ant_enable == TRUE) ) {1717value &= ~AR_SWITCH_TABLE_COM2_ALL;1718value |= ah->ah_config.ath_hal_ant_ctrl_comm2g_switch_enable;1719HALDEBUG(ah, HAL_DEBUG_RESET, "%s: com2=0x%08x\n", __func__, value)1720}1721#endif /* ATH_ANT_DIV_COMB */1722OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2, AR_SWITCH_TABLE_COM2_ALL, value);17231724#define AR_SWITCH_TABLE_ALL (0xfff)1725#define AR_SWITCH_TABLE_ALL_S (0)1726value = ar9300_ant_ctrl_chain_get(ah, 0, is_2ghz);1727OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_CHAIN_0, AR_SWITCH_TABLE_ALL, value);17281729if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah) && !AR_SREV_APHRODITE(ah)) {1730value = ar9300_ant_ctrl_chain_get(ah, 1, is_2ghz);1731OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_CHAIN_1, AR_SWITCH_TABLE_ALL, value);17321733if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah)) {1734value = ar9300_ant_ctrl_chain_get(ah, 2, is_2ghz);1735OS_REG_RMW_FIELD(ah,1736AR_PHY_SWITCH_CHAIN_2, AR_SWITCH_TABLE_ALL, value);1737}1738}1739if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah) || AR_SREV_APHRODITE(ah)) {1740value = ar9300_eeprom_get(ahp, EEP_ANTDIV_control);1741/* main_lnaconf, alt_lnaconf, main_tb, alt_tb */1742regval = OS_REG_READ(ah, AR_PHY_MC_GAIN_CTRL);1743regval &= (~ANT_DIV_CONTROL_ALL); /* clear bit 25~30 */1744regval |= (value & 0x3f) << ANT_DIV_CONTROL_ALL_S;1745/* enable_lnadiv */1746regval &= (~MULTICHAIN_GAIN_CTRL__ENABLE_ANT_DIV_LNADIV__MASK);1747regval |= ((value >> 6) & 0x1) <<1748MULTICHAIN_GAIN_CTRL__ENABLE_ANT_DIV_LNADIV__SHIFT;1749#if ATH_ANT_DIV_COMB1750if ( AR_SREV_POSEIDON(ah) && (ahp->ah_lna_div_use_bt_ant_enable == TRUE) ) {1751regval |= ANT_DIV_ENABLE;1752}1753if (AR_SREV_APHRODITE(ah)) {1754if (ahp->ah_lna_div_use_bt_ant_enable) {1755regval |= (1 << MULTICHAIN_GAIN_CTRL__ENABLE_ANT_SW_RX_PROT__SHIFT);17561757OS_REG_SET_BIT(ah, AR_PHY_RESTART,1758RESTART__ENABLE_ANT_FAST_DIV_M2FLAG__MASK);17591760/* Force WLAN LNA diversity ON */1761OS_REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,1762AR_BTCOEX_WL_LNADIV_FORCE_ON);1763} else {1764regval &= ~(1 << MULTICHAIN_GAIN_CTRL__ENABLE_ANT_DIV_LNADIV__SHIFT);1765regval &= ~(1 << MULTICHAIN_GAIN_CTRL__ENABLE_ANT_SW_RX_PROT__SHIFT);17661767OS_REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,1768(1 << MULTICHAIN_GAIN_CTRL__ENABLE_ANT_SW_RX_PROT__SHIFT));17691770/* Force WLAN LNA diversity OFF */1771OS_REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV,1772AR_BTCOEX_WL_LNADIV_FORCE_ON);1773}1774}17751776#endif /* ATH_ANT_DIV_COMB */1777OS_REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);17781779/* enable fast_div */1780regval = OS_REG_READ(ah, AR_PHY_CCK_DETECT);1781regval &= (~BBB_SIG_DETECT__ENABLE_ANT_FAST_DIV__MASK);1782regval |= ((value >> 7) & 0x1) <<1783BBB_SIG_DETECT__ENABLE_ANT_FAST_DIV__SHIFT;1784#if ATH_ANT_DIV_COMB1785if ((AR_SREV_POSEIDON(ah) || AR_SREV_APHRODITE(ah))1786&& (ahp->ah_lna_div_use_bt_ant_enable == TRUE) ) {1787regval |= FAST_DIV_ENABLE;1788}1789#endif /* ATH_ANT_DIV_COMB */1790OS_REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);1791}17921793#if ATH_ANT_DIV_COMB1794if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON_11_OR_LATER(ah)) {1795if (pcap->halAntDivCombSupport) {1796/* If support DivComb, set MAIN to LNA1, ALT to LNA2 at beginning */1797regval = OS_REG_READ(ah, AR_PHY_MC_GAIN_CTRL);1798/* clear bit 25~30 main_lnaconf, alt_lnaconf, main_tb, alt_tb */1799regval &= (~(MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__MASK |1800MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__MASK |1801MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_GAINTB__MASK |1802MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_GAINTB__MASK));1803regval |= (HAL_ANT_DIV_COMB_LNA1 <<1804MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__SHIFT);1805regval |= (HAL_ANT_DIV_COMB_LNA2 <<1806MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__SHIFT);1807OS_REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);1808}18091810}1811#endif /* ATH_ANT_DIV_COMB */1812if (AR_SREV_POSEIDON(ah) && ( ahp->ah_diversity_control == HAL_ANT_FIXED_A1813|| ahp->ah_diversity_control == HAL_ANT_FIXED_B))1814{1815u_int32_t reg_val = OS_REG_READ(ah, AR_PHY_MC_GAIN_CTRL);1816reg_val &= ~(MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__MASK |1817MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__MASK |1818MULTICHAIN_GAIN_CTRL__ANT_FAST_DIV_BIAS__MASK |1819MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_GAINTB__MASK |1820MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_GAINTB__MASK );18211822switch (ahp->ah_diversity_control) {1823case HAL_ANT_FIXED_A:1824/* Enable first antenna only */1825reg_val |= (HAL_ANT_DIV_COMB_LNA1 <<1826MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__SHIFT);1827reg_val |= (HAL_ANT_DIV_COMB_LNA2 <<1828MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__SHIFT);1829/* main/alt gain table and Fast Div Bias all set to 0 */1830OS_REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, reg_val);1831regval = OS_REG_READ(ah, AR_PHY_CCK_DETECT);1832regval &= (~BBB_SIG_DETECT__ENABLE_ANT_FAST_DIV__MASK);1833OS_REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);1834break;1835case HAL_ANT_FIXED_B:1836/* Enable second antenna only, after checking capability */1837reg_val |= (HAL_ANT_DIV_COMB_LNA2 <<1838MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__SHIFT);1839reg_val |= (HAL_ANT_DIV_COMB_LNA1 <<1840MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__SHIFT);1841/* main/alt gain table and Fast Div all set to 0 */1842OS_REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, reg_val);1843regval = OS_REG_READ(ah, AR_PHY_CCK_DETECT);1844regval &= (~BBB_SIG_DETECT__ENABLE_ANT_FAST_DIV__MASK);1845OS_REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);1846/* For WB225, need to swith ANT2 from BT to Wifi1847* This will not affect HB125 LNA diversity feature.1848*/1849HALDEBUG(ah, HAL_DEBUG_RESET, "%s: com2=0x%08x\n", __func__,1850ah->ah_config.ath_hal_ant_ctrl_comm2g_switch_enable)1851OS_REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2, AR_SWITCH_TABLE_COM2_ALL,1852ah->ah_config.ath_hal_ant_ctrl_comm2g_switch_enable);1853break;1854default:1855break;1856}1857}1858return 0;1859}18601861static u_int16_t1862ar9300_attenuation_chain_get(struct ath_hal *ah, int chain, u_int16_t channel)1863{1864int32_t f[3], t[3];1865u_int16_t value;1866ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1867if (chain >= 0 && chain < OSPREY_MAX_CHAINS) {1868if (channel < 4000) {1869return eep->modal_header_2g.xatten1_db[chain];1870} else {1871if (eep->base_ext2.xatten1_db_low[chain] != 0) {1872t[0] = eep->base_ext2.xatten1_db_low[chain];1873f[0] = 5180;1874t[1] = eep->modal_header_5g.xatten1_db[chain];1875f[1] = 5500;1876t[2] = eep->base_ext2.xatten1_db_high[chain];1877f[2] = 5785;1878value = interpolate(channel, f, t, 3);1879return value;1880} else {1881return eep->modal_header_5g.xatten1_db[chain];1882}1883}1884}1885return 0;1886}18871888static u_int16_t1889ar9300_attenuation_margin_chain_get(struct ath_hal *ah, int chain,1890u_int16_t channel)1891{1892int32_t f[3], t[3];1893u_int16_t value;1894ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;1895if (chain >= 0 && chain < OSPREY_MAX_CHAINS) {1896if (channel < 4000) {1897return eep->modal_header_2g.xatten1_margin[chain];1898} else {1899if (eep->base_ext2.xatten1_margin_low[chain] != 0) {1900t[0] = eep->base_ext2.xatten1_margin_low[chain];1901f[0] = 5180;1902t[1] = eep->modal_header_5g.xatten1_margin[chain];1903f[1] = 5500;1904t[2] = eep->base_ext2.xatten1_margin_high[chain];1905f[2] = 5785;1906value = interpolate(channel, f, t, 3);1907return value;1908} else {1909return eep->modal_header_5g.xatten1_margin[chain];1910}1911}1912}1913return 0;1914}19151916#if 01917HAL_BOOL ar9300_attenuation_apply(struct ath_hal *ah, u_int16_t channel)1918{1919u_int32_t value;1920// struct ath_hal_private *ahpriv = AH_PRIVATE(ah);19211922/* Test value. if 0 then attenuation is unused. Don't load anything. */1923value = ar9300_attenuation_chain_get(ah, 0, channel);1924OS_REG_RMW_FIELD(ah,1925AR_PHY_EXT_ATTEN_CTL_0, AR_PHY_EXT_ATTEN_CTL_XATTEN1_DB, value);1926value = ar9300_attenuation_margin_chain_get(ah, 0, channel);1927if (ar9300_rx_gain_index_get(ah) == 01928&& ah->ah_config.ath_hal_ext_atten_margin_cfg)1929{1930value = 5;1931}1932OS_REG_RMW_FIELD(ah,1933AR_PHY_EXT_ATTEN_CTL_0, AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN, value);19341935if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {1936value = ar9300_attenuation_chain_get(ah, 1, channel);1937OS_REG_RMW_FIELD(ah,1938AR_PHY_EXT_ATTEN_CTL_1, AR_PHY_EXT_ATTEN_CTL_XATTEN1_DB, value);1939value = ar9300_attenuation_margin_chain_get(ah, 1, channel);1940OS_REG_RMW_FIELD(ah,1941AR_PHY_EXT_ATTEN_CTL_1, AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,1942value);1943if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah)&& !AR_SREV_HONEYBEE(ah) ) {1944value = ar9300_attenuation_chain_get(ah, 2, channel);1945OS_REG_RMW_FIELD(ah,1946AR_PHY_EXT_ATTEN_CTL_2, AR_PHY_EXT_ATTEN_CTL_XATTEN1_DB, value);1947value = ar9300_attenuation_margin_chain_get(ah, 2, channel);1948OS_REG_RMW_FIELD(ah,1949AR_PHY_EXT_ATTEN_CTL_2, AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,1950value);1951}1952}1953return 0;1954}1955#endif1956HAL_BOOL1957ar9300_attenuation_apply(struct ath_hal *ah, u_int16_t channel)1958{1959int i;1960uint32_t value;1961uint32_t ext_atten_reg[3] = {1962AR_PHY_EXT_ATTEN_CTL_0,1963AR_PHY_EXT_ATTEN_CTL_1,1964AR_PHY_EXT_ATTEN_CTL_21965};19661967/*1968* If it's an AR9462 and we're receiving on the second1969* chain only, set the chain 0 details from chain 11970* calibration.1971*1972* This is from ath9k.1973*/1974if (AR_SREV_JUPITER(ah) && (AH9300(ah)->ah_rx_chainmask == 0x2)) {1975value = ar9300_attenuation_chain_get(ah, 1, channel);1976OS_REG_RMW_FIELD(ah, ext_atten_reg[0],1977AR_PHY_EXT_ATTEN_CTL_XATTEN1_DB, value);1978value = ar9300_attenuation_margin_chain_get(ah, 1, channel);1979OS_REG_RMW_FIELD(ah, ext_atten_reg[0],1980AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN, value);1981}19821983/*1984* Now, loop over the configured transmit chains and1985* load in the attenuation/margin settings as appropriate.1986*/1987for (i = 0; i < 3; i++) {1988if ((AH9300(ah)->ah_tx_chainmask & (1 << i)) == 0)1989continue;19901991value = ar9300_attenuation_chain_get(ah, i, channel);1992OS_REG_RMW_FIELD(ah, ext_atten_reg[i],1993AR_PHY_EXT_ATTEN_CTL_XATTEN1_DB,1994value);19951996if (AR_SREV_POSEIDON(ah) &&1997(ar9300_rx_gain_index_get(ah) == 0) &&1998ah->ah_config.ath_hal_ext_atten_margin_cfg) {1999value = 5;2000} else {2001value = ar9300_attenuation_margin_chain_get(ah, 0,2002channel);2003}20042005/*2006* I'm not sure why it's loading in this setting into2007* the chain 0 margin regardless of the current chain.2008*/2009if (ah->ah_config.ath_hal_min_gainidx)2010OS_REG_RMW_FIELD(ah,2011AR_PHY_EXT_ATTEN_CTL_0,2012AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,2013value);20142015OS_REG_RMW_FIELD(ah,2016ext_atten_reg[i],2017AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,2018value);2019}20202021return (0);2022}202320242025static u_int16_t ar9300_quick_drop_get(struct ath_hal *ah,2026int chain, u_int16_t channel)2027{2028int32_t f[3], t[3];2029u_int16_t value;2030ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;20312032if (channel < 4000) {2033return eep->modal_header_2g.quick_drop;2034} else {2035t[0] = eep->base_ext1.quick_drop_low;2036f[0] = 5180;2037t[1] = eep->modal_header_5g.quick_drop;2038f[1] = 5500;2039t[2] = eep->base_ext1.quick_drop_high;2040f[2] = 5785;2041value = interpolate(channel, f, t, 3);2042return value;2043}2044}204520462047static HAL_BOOL ar9300_quick_drop_apply(struct ath_hal *ah, u_int16_t channel)2048{2049ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;2050u_int32_t value;2051//2052// Test value. if 0 then quickDrop is unused. Don't load anything.2053//2054if (eep->base_eep_header.misc_configuration & 0x10)2055{2056if (AR_SREV_OSPREY(ah) || AR_SREV_AR9580(ah) || AR_SREV_WASP(ah))2057{2058value = ar9300_quick_drop_get(ah, 0, channel);2059OS_REG_RMW_FIELD(ah, AR_PHY_AGC, AR_PHY_AGC_QUICK_DROP, value);2060}2061}2062return 0;2063}20642065static u_int16_t ar9300_tx_end_to_xpa_off_get(struct ath_hal *ah, u_int16_t channel)2066{2067ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;20682069if (channel < 4000) {2070return eep->modal_header_2g.tx_end_to_xpa_off;2071} else {2072return eep->modal_header_5g.tx_end_to_xpa_off;2073}2074}20752076static HAL_BOOL ar9300_tx_end_to_xpab_off_apply(struct ath_hal *ah, u_int16_t channel)2077{2078u_int32_t value;20792080value = ar9300_tx_end_to_xpa_off_get(ah, channel);2081/* Apply to both xpaa and xpab */2082if (AR_SREV_OSPREY(ah) || AR_SREV_AR9580(ah) || AR_SREV_WASP(ah))2083{2084OS_REG_RMW_FIELD(ah, AR_PHY_XPA_TIMING_CTL,2085AR_PHY_XPA_TIMING_CTL_TX_END_XPAB_OFF, value);2086OS_REG_RMW_FIELD(ah, AR_PHY_XPA_TIMING_CTL,2087AR_PHY_XPA_TIMING_CTL_TX_END_XPAA_OFF, value);2088}2089return 0;2090}20912092static int2093ar9300_eeprom_cal_pier_get(struct ath_hal *ah, int mode, int ipier, int ichain,2094int *pfrequency, int *pcorrection, int *ptemperature, int *pvoltage)2095{2096u_int8_t *p_cal_pier;2097OSP_CAL_DATA_PER_FREQ_OP_LOOP *p_cal_pier_struct;2098int is_2ghz;2099ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;21002101if (ichain >= OSPREY_MAX_CHAINS) {2102HALDEBUG(ah, HAL_DEBUG_EEPROM,2103"%s: Invalid chain index, must be less than %d\n",2104__func__, OSPREY_MAX_CHAINS);2105return -1;2106}21072108if (mode) {/* 5GHz */2109if (ipier >= OSPREY_NUM_5G_CAL_PIERS){2110HALDEBUG(ah, HAL_DEBUG_EEPROM,2111"%s: Invalid 5GHz cal pier index, must be less than %d\n",2112__func__, OSPREY_NUM_5G_CAL_PIERS);2113return -1;2114}2115p_cal_pier = &(eep->cal_freq_pier_5g[ipier]);2116p_cal_pier_struct = &(eep->cal_pier_data_5g[ichain][ipier]);2117is_2ghz = 0;2118} else {2119if (ipier >= OSPREY_NUM_2G_CAL_PIERS){2120HALDEBUG(ah, HAL_DEBUG_EEPROM,2121"%s: Invalid 2GHz cal pier index, must be less than %d\n",2122__func__, OSPREY_NUM_2G_CAL_PIERS);2123return -1;2124}21252126p_cal_pier = &(eep->cal_freq_pier_2g[ipier]);2127p_cal_pier_struct = &(eep->cal_pier_data_2g[ichain][ipier]);2128is_2ghz = 1;2129}2130*pfrequency = FBIN2FREQ(*p_cal_pier, is_2ghz);2131*pcorrection = p_cal_pier_struct->ref_power;2132*ptemperature = p_cal_pier_struct->temp_meas;2133*pvoltage = p_cal_pier_struct->volt_meas;2134return 0;2135}21362137/*2138* Apply the recorded correction values.2139*/2140static int2141ar9300_calibration_apply(struct ath_hal *ah, int frequency)2142{2143struct ath_hal_9300 *ahp = AH9300(ah);21442145int ichain, ipier, npier;2146int mode;2147int fdiff;2148int pfrequency, pcorrection, ptemperature, pvoltage;2149int bf, factor, plus;21502151int lfrequency[AR9300_MAX_CHAINS];2152int hfrequency[AR9300_MAX_CHAINS];21532154int lcorrection[AR9300_MAX_CHAINS];2155int hcorrection[AR9300_MAX_CHAINS];2156int correction[AR9300_MAX_CHAINS];21572158int ltemperature[AR9300_MAX_CHAINS];2159int htemperature[AR9300_MAX_CHAINS];2160int temperature[AR9300_MAX_CHAINS];21612162int lvoltage[AR9300_MAX_CHAINS];2163int hvoltage[AR9300_MAX_CHAINS];2164int voltage[AR9300_MAX_CHAINS];21652166mode = (frequency >= 4000);2167npier = (mode) ? OSPREY_NUM_5G_CAL_PIERS : OSPREY_NUM_2G_CAL_PIERS;21682169for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {2170lfrequency[ichain] = 0;2171hfrequency[ichain] = 100000;2172}2173/*2174* identify best lower and higher frequency calibration measurement2175*/2176for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {2177for (ipier = 0; ipier < npier; ipier++) {2178if (ar9300_eeprom_cal_pier_get(2179ah, mode, ipier, ichain,2180&pfrequency, &pcorrection, &ptemperature, &pvoltage) == 0)2181{2182fdiff = frequency - pfrequency;2183/*2184* this measurement is higher than our desired frequency2185*/2186if (fdiff <= 0) {2187if (hfrequency[ichain] <= 0 ||2188hfrequency[ichain] >= 100000 ||2189fdiff > (frequency - hfrequency[ichain]))2190{2191/*2192* new best higher frequency measurement2193*/2194hfrequency[ichain] = pfrequency;2195hcorrection[ichain] = pcorrection;2196htemperature[ichain] = ptemperature;2197hvoltage[ichain] = pvoltage;2198}2199}2200if (fdiff >= 0) {2201if (lfrequency[ichain] <= 0 ||2202fdiff < (frequency - lfrequency[ichain]))2203{2204/*2205* new best lower frequency measurement2206*/2207lfrequency[ichain] = pfrequency;2208lcorrection[ichain] = pcorrection;2209ltemperature[ichain] = ptemperature;2210lvoltage[ichain] = pvoltage;2211}2212}2213}2214}2215}2216/* interpolate */2217for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {2218HALDEBUG(ah, HAL_DEBUG_EEPROM,2219"%s: ch=%d f=%d low=%d %d h=%d %d\n",2220__func__, ichain, frequency,2221lfrequency[ichain], lcorrection[ichain],2222hfrequency[ichain], hcorrection[ichain]);2223/*2224* they're the same, so just pick one2225*/2226if (hfrequency[ichain] == lfrequency[ichain]) {2227correction[ichain] = lcorrection[ichain];2228voltage[ichain] = lvoltage[ichain];2229temperature[ichain] = ltemperature[ichain];2230} else if (frequency - lfrequency[ichain] < 1000) {2231/* the low frequency is good */2232if (hfrequency[ichain] - frequency < 1000) {2233/*2234* The high frequency is good too -2235* interpolate with round off.2236*/2237int mult, div, diff;2238mult = frequency - lfrequency[ichain];2239div = hfrequency[ichain] - lfrequency[ichain];22402241diff = hcorrection[ichain] - lcorrection[ichain];2242bf = 2 * diff * mult / div;2243plus = (bf % 2);2244factor = bf / 2;2245correction[ichain] = lcorrection[ichain] + factor + plus;22462247diff = htemperature[ichain] - ltemperature[ichain];2248bf = 2 * diff * mult / div;2249plus = (bf % 2);2250factor = bf / 2;2251temperature[ichain] = ltemperature[ichain] + factor + plus;22522253diff = hvoltage[ichain] - lvoltage[ichain];2254bf = 2 * diff * mult / div;2255plus = (bf % 2);2256factor = bf / 2;2257voltage[ichain] = lvoltage[ichain] + factor + plus;2258} else {2259/* only low is good, use it */2260correction[ichain] = lcorrection[ichain];2261temperature[ichain] = ltemperature[ichain];2262voltage[ichain] = lvoltage[ichain];2263}2264} else if (hfrequency[ichain] - frequency < 1000) {2265/* only high is good, use it */2266correction[ichain] = hcorrection[ichain];2267temperature[ichain] = htemperature[ichain];2268voltage[ichain] = hvoltage[ichain];2269} else {2270/* nothing is good, presume 0???? */2271correction[ichain] = 0;2272temperature[ichain] = 0;2273voltage[ichain] = 0;2274}2275}22762277/* GreenTx isn't currently supported */2278/* GreenTx */2279if (ah->ah_config.ath_hal_sta_update_tx_pwr_enable) {2280if (AR_SREV_POSEIDON(ah)) {2281/* Get calibrated OLPC gain delta value for GreenTx */2282ahp->ah_db2[POSEIDON_STORED_REG_G2_OLPC_OFFSET] =2283(u_int32_t) correction[0];2284}2285}22862287ar9300_power_control_override(2288ah, frequency, correction, voltage, temperature);2289HALDEBUG(ah, HAL_DEBUG_EEPROM,2290"%s: for frequency=%d, calibration correction = %d %d %d\n",2291__func__, frequency, correction[0], correction[1], correction[2]);22922293return 0;2294}22952296int2297ar9300_power_control_override(struct ath_hal *ah, int frequency,2298int *correction, int *voltage, int *temperature)2299{2300int temp_slope = 0;2301int temp_slope_1 = 0;2302int temp_slope_2 = 0;2303ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;2304int32_t f[8], t[8],t1[3], t2[3];2305int i;23062307OS_REG_RMW(ah, AR_PHY_TPC_11_B0,2308(correction[0] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),2309AR_PHY_TPC_OLPC_GAIN_DELTA);2310if (!AR_SREV_POSEIDON(ah)) {2311OS_REG_RMW(ah, AR_PHY_TPC_11_B1,2312(correction[1] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),2313AR_PHY_TPC_OLPC_GAIN_DELTA);2314if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {2315OS_REG_RMW(ah, AR_PHY_TPC_11_B2,2316(correction[2] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),2317AR_PHY_TPC_OLPC_GAIN_DELTA);2318}2319}2320/*2321* enable open loop power control on chip2322*/2323OS_REG_RMW(ah, AR_PHY_TPC_6_B0,2324(3 << AR_PHY_TPC_6_ERROR_EST_MODE_S), AR_PHY_TPC_6_ERROR_EST_MODE);2325if (!AR_SREV_POSEIDON(ah)) {2326OS_REG_RMW(ah, AR_PHY_TPC_6_B1,2327(3 << AR_PHY_TPC_6_ERROR_EST_MODE_S), AR_PHY_TPC_6_ERROR_EST_MODE);2328if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {2329OS_REG_RMW(ah, AR_PHY_TPC_6_B2,2330(3 << AR_PHY_TPC_6_ERROR_EST_MODE_S),2331AR_PHY_TPC_6_ERROR_EST_MODE);2332}2333}23342335/*2336* Enable temperature compensation2337* Need to use register names2338*/2339if (frequency < 4000) {2340temp_slope = eep->modal_header_2g.temp_slope;2341} else {2342if ((eep->base_eep_header.misc_configuration & 0x20) != 0)2343{2344for(i=0;i<8;i++)2345{2346t[i]=eep->base_ext1.tempslopextension[i];2347f[i]=FBIN2FREQ(eep->cal_freq_pier_5g[i], 0);2348}2349temp_slope=interpolate(frequency,f,t,8);2350}2351else2352{2353if(!AR_SREV_SCORPION(ah)) {2354if (eep->base_ext2.temp_slope_low != 0) {2355t[0] = eep->base_ext2.temp_slope_low;2356f[0] = 5180;2357t[1] = eep->modal_header_5g.temp_slope;2358f[1] = 5500;2359t[2] = eep->base_ext2.temp_slope_high;2360f[2] = 5785;2361temp_slope = interpolate(frequency, f, t, 3);2362} else {2363temp_slope = eep->modal_header_5g.temp_slope;2364}2365} else {2366/*2367* Scorpion has individual chain tempslope values2368*/2369t[0] = eep->base_ext1.tempslopextension[2];2370t1[0]= eep->base_ext1.tempslopextension[3];2371t2[0]= eep->base_ext1.tempslopextension[4];2372f[0] = 5180;2373t[1] = eep->modal_header_5g.temp_slope;2374t1[1]= eep->base_ext1.tempslopextension[0];2375t2[1]= eep->base_ext1.tempslopextension[1];2376f[1] = 5500;2377t[2] = eep->base_ext1.tempslopextension[5];2378t1[2]= eep->base_ext1.tempslopextension[6];2379t2[2]= eep->base_ext1.tempslopextension[7];2380f[2] = 5785;2381temp_slope = interpolate(frequency, f, t, 3);2382temp_slope_1=interpolate(frequency, f, t1,3);2383temp_slope_2=interpolate(frequency, f, t2,3);2384}2385}2386}23872388if (!AR_SREV_SCORPION(ah) && !AR_SREV_HONEYBEE(ah)) {2389OS_REG_RMW_FIELD(ah,2390AR_PHY_TPC_19, AR_PHY_TPC_19_ALPHA_THERM, temp_slope);2391} else {2392/*Scorpion and Honeybee has tempSlope register for each chain*/2393/*Check whether temp_compensation feature is enabled or not*/2394if (eep->base_eep_header.feature_enable & 0x1){2395if(frequency < 4000) {2396if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x1) {2397OS_REG_RMW_FIELD(ah,2398AR_PHY_TPC_19, AR_PHY_TPC_19_ALPHA_THERM,2399eep->base_ext2.temp_slope_low);2400}2401if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x2) {2402OS_REG_RMW_FIELD(ah,2403AR_SCORPION_PHY_TPC_19_B1, AR_PHY_TPC_19_ALPHA_THERM,2404temp_slope);2405}2406if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x4) {2407OS_REG_RMW_FIELD(ah,2408AR_SCORPION_PHY_TPC_19_B2, AR_PHY_TPC_19_ALPHA_THERM,2409eep->base_ext2.temp_slope_high);2410}2411} else {2412if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x1) {2413OS_REG_RMW_FIELD(ah,2414AR_PHY_TPC_19, AR_PHY_TPC_19_ALPHA_THERM,2415temp_slope);2416}2417if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x2) {2418OS_REG_RMW_FIELD(ah,2419AR_SCORPION_PHY_TPC_19_B1, AR_PHY_TPC_19_ALPHA_THERM,2420temp_slope_1);2421}2422if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x4) {2423OS_REG_RMW_FIELD(ah,2424AR_SCORPION_PHY_TPC_19_B2, AR_PHY_TPC_19_ALPHA_THERM,2425temp_slope_2);2426}2427}2428}else {2429/* If temp compensation is not enabled, set all registers to 0*/2430if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x1) {2431OS_REG_RMW_FIELD(ah,2432AR_PHY_TPC_19, AR_PHY_TPC_19_ALPHA_THERM, 0);2433}2434if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x2) {2435OS_REG_RMW_FIELD(ah,2436AR_SCORPION_PHY_TPC_19_B1, AR_PHY_TPC_19_ALPHA_THERM, 0);2437}2438if (((eep->base_eep_header.txrx_mask & 0xf0) >> 4) & 0x4) {2439OS_REG_RMW_FIELD(ah,2440AR_SCORPION_PHY_TPC_19_B2, AR_PHY_TPC_19_ALPHA_THERM, 0);2441}2442}2443}2444OS_REG_RMW_FIELD(ah,2445AR_PHY_TPC_18, AR_PHY_TPC_18_THERM_CAL_VALUE, temperature[0]);24462447return 0;2448}24492450/**************************************************************2451* ar9300_eep_def_get_max_edge_power2452*2453* Find the maximum conformance test limit for the given channel and CTL info2454*/2455static inline u_int16_t2456ar9300_eep_def_get_max_edge_power(ar9300_eeprom_t *p_eep_data, u_int16_t freq,2457int idx, HAL_BOOL is_2ghz)2458{2459u_int16_t twice_max_edge_power = AR9300_MAX_RATE_POWER;2460u_int8_t *ctl_freqbin = is_2ghz ?2461&p_eep_data->ctl_freqbin_2G[idx][0] :2462&p_eep_data->ctl_freqbin_5G[idx][0];2463u_int16_t num_edges = is_2ghz ?2464OSPREY_NUM_BAND_EDGES_2G : OSPREY_NUM_BAND_EDGES_5G;2465int i;24662467/* Get the edge power */2468for (i = 0; (i < num_edges) && (ctl_freqbin[i] != AR9300_BCHAN_UNUSED); i++)2469{2470/*2471* If there's an exact channel match or an inband flag set2472* on the lower channel use the given rd_edge_power2473*/2474if (freq == fbin2freq(ctl_freqbin[i], is_2ghz)) {2475if (is_2ghz) {2476twice_max_edge_power =2477p_eep_data->ctl_power_data_2g[idx].ctl_edges[i].t_power;2478} else {2479twice_max_edge_power =2480p_eep_data->ctl_power_data_5g[idx].ctl_edges[i].t_power;2481}2482break;2483} else if ((i > 0) && (freq < fbin2freq(ctl_freqbin[i], is_2ghz))) {2484if (is_2ghz) {2485if (fbin2freq(ctl_freqbin[i - 1], 1) < freq &&2486p_eep_data->ctl_power_data_2g[idx].ctl_edges[i - 1].flag)2487{2488twice_max_edge_power =2489p_eep_data->ctl_power_data_2g[idx].2490ctl_edges[i - 1].t_power;2491}2492} else {2493if (fbin2freq(ctl_freqbin[i - 1], 0) < freq &&2494p_eep_data->ctl_power_data_5g[idx].ctl_edges[i - 1].flag)2495{2496twice_max_edge_power =2497p_eep_data->ctl_power_data_5g[idx].2498ctl_edges[i - 1].t_power;2499}2500}2501/*2502* Leave loop - no more affecting edges possible2503* in this monotonic increasing list2504*/2505break;2506}2507}2508/*2509* EV89475: EEPROM might contain 0 txpower in CTL table for certain2510* 2.4GHz channels. We workaround it by overwriting 60 (30 dBm) here.2511*/2512if (is_2ghz && (twice_max_edge_power == 0)) {2513twice_max_edge_power = 60;2514}25152516HALASSERT(twice_max_edge_power > 0);2517return twice_max_edge_power;2518}25192520HAL_BOOL2521ar9300_eeprom_set_power_per_rate_table(2522struct ath_hal *ah,2523ar9300_eeprom_t *p_eep_data,2524const struct ieee80211_channel *chan,2525u_int8_t *p_pwr_array,2526u_int16_t cfg_ctl,2527u_int16_t antenna_reduction,2528u_int16_t twice_max_regulatory_power,2529u_int16_t power_limit,2530u_int8_t chainmask)2531{2532/* Local defines to distinguish between extension and control CTL's */2533#define EXT_ADDITIVE (0x8000)2534#define CTL_11A_EXT (CTL_11A | EXT_ADDITIVE)2535#define CTL_11G_EXT (CTL_11G | EXT_ADDITIVE)2536#define CTL_11B_EXT (CTL_11B | EXT_ADDITIVE)2537#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */2538#define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */2539#define PWRINCR_3_TO_1_CHAIN 9 /* 10*log(3)*2 */2540#define PWRINCR_3_TO_2_CHAIN 3 /* floor(10*log(3/2)*2) */2541#define PWRINCR_2_TO_1_CHAIN 6 /* 10*log(2)*2 */25422543static const u_int16_t tp_scale_reduction_table[5] =2544{ 0, 3, 6, 9, AR9300_MAX_RATE_POWER };2545int i;2546int16_t twice_largest_antenna;2547u_int16_t twice_antenna_reduction = 2*antenna_reduction ;2548int16_t scaled_power = 0, min_ctl_power, max_reg_allowed_power;2549#define SUB_NUM_CTL_MODES_AT_5G_40 2 /* excluding HT40, EXT-OFDM */2550#define SUB_NUM_CTL_MODES_AT_2G_40 3 /* excluding HT40, EXT-OFDM, EXT-CCK */2551u_int16_t ctl_modes_for11a[] =2552{CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40};2553u_int16_t ctl_modes_for11g[] =2554{CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40};2555u_int16_t num_ctl_modes, *p_ctl_mode, ctl_mode, freq;2556CHAN_CENTERS centers;2557int tx_chainmask;2558struct ath_hal_9300 *ahp = AH9300(ah);2559u_int8_t *ctl_index;2560u_int8_t ctl_num;2561u_int16_t twice_min_edge_power;2562u_int16_t twice_max_edge_power = AR9300_MAX_RATE_POWER;2563#ifdef AH_DEBUG2564HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, chan);2565#endif25662567if (chainmask)2568tx_chainmask = chainmask;2569else2570tx_chainmask = ahp->ah_tx_chainmaskopt ?2571ahp->ah_tx_chainmaskopt :ahp->ah_tx_chainmask;25722573ar9300_get_channel_centers(ah, chan, ¢ers);25742575#if 12576if (IEEE80211_IS_CHAN_2GHZ(chan)) {2577ahp->twice_antenna_gain = p_eep_data->modal_header_2g.antenna_gain;2578} else {2579ahp->twice_antenna_gain = p_eep_data->modal_header_5g.antenna_gain;2580}25812582#else2583if (IEEE80211_IS_CHAN_2GHZ(chan)) {2584ahp->twice_antenna_gain = AH_MAX(p_eep_data->modal_header_2g.antenna_gain,2585AH_PRIVATE(ah)->ah_antenna_gain_2g);2586} else {2587ahp->twice_antenna_gain = AH_MAX(p_eep_data->modal_header_5g.antenna_gain,2588AH_PRIVATE(ah)->ah_antenna_gain_5g);2589}2590#endif25912592/* Save max allowed antenna gain to ease future lookups */2593ahp->twice_antenna_reduction = twice_antenna_reduction;25942595/* Deduct antenna gain from EIRP to get the upper limit */2596twice_largest_antenna = (int16_t)AH_MIN((twice_antenna_reduction -2597ahp->twice_antenna_gain), 0);2598max_reg_allowed_power = twice_max_regulatory_power + twice_largest_antenna;25992600/* Use ah_tp_scale - see bug 30070. */2601if (AH_PRIVATE(ah)->ah_tpScale != HAL_TP_SCALE_MAX) {2602max_reg_allowed_power -=2603(tp_scale_reduction_table[(AH_PRIVATE(ah)->ah_tpScale)] * 2);2604}26052606scaled_power = AH_MIN(power_limit, max_reg_allowed_power);26072608/*2609* Reduce scaled Power by number of chains active to get to2610* per chain tx power level2611*/2612/* TODO: better value than these? */2613switch (ar9300_get_ntxchains(tx_chainmask)) {2614case 1:2615ahp->upper_limit[0] = AH_MAX(0, scaled_power);2616break;2617case 2:2618scaled_power -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;2619ahp->upper_limit[1] = AH_MAX(0, scaled_power);2620break;2621case 3:2622scaled_power -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;2623ahp->upper_limit[2] = AH_MAX(0, scaled_power);2624break;2625default:2626HALASSERT(0); /* Unsupported number of chains */2627}26282629scaled_power = AH_MAX(0, scaled_power);26302631/* Get target powers from EEPROM - our baseline for TX Power */2632if (IEEE80211_IS_CHAN_2GHZ(chan)) {2633/* Setup for CTL modes */2634/* CTL_11B, CTL_11G, CTL_2GHT20 */2635num_ctl_modes =2636ARRAY_LENGTH(ctl_modes_for11g) - SUB_NUM_CTL_MODES_AT_2G_40;2637p_ctl_mode = ctl_modes_for11g;26382639if (IEEE80211_IS_CHAN_HT40(chan)) {2640num_ctl_modes = ARRAY_LENGTH(ctl_modes_for11g); /* All 2G CTL's */2641}2642} else {2643/* Setup for CTL modes */2644/* CTL_11A, CTL_5GHT20 */2645num_ctl_modes =2646ARRAY_LENGTH(ctl_modes_for11a) - SUB_NUM_CTL_MODES_AT_5G_40;2647p_ctl_mode = ctl_modes_for11a;26482649if (IEEE80211_IS_CHAN_HT40(chan)) {2650num_ctl_modes = ARRAY_LENGTH(ctl_modes_for11a); /* All 5G CTL's */2651}2652}26532654/*2655* For MIMO, need to apply regulatory caps individually across dynamically2656* running modes: CCK, OFDM, HT20, HT402657*2658* The outer loop walks through each possible applicable runtime mode.2659* The inner loop walks through each ctl_index entry in EEPROM.2660* The ctl value is encoded as [7:4] == test group, [3:0] == test mode.2661*2662*/2663for (ctl_mode = 0; ctl_mode < num_ctl_modes; ctl_mode++) {2664HAL_BOOL is_ht40_ctl_mode =2665(p_ctl_mode[ctl_mode] == CTL_5GHT40) ||2666(p_ctl_mode[ctl_mode] == CTL_2GHT40);2667if (is_ht40_ctl_mode) {2668freq = centers.synth_center;2669} else if (p_ctl_mode[ctl_mode] & EXT_ADDITIVE) {2670freq = centers.ext_center;2671} else {2672freq = centers.ctl_center;2673}26742675HALDEBUG(ah, HAL_DEBUG_POWER_MGMT,2676"LOOP-Mode ctl_mode %d < %d, "2677"is_ht40_ctl_mode %d, EXT_ADDITIVE %d\n",2678ctl_mode, num_ctl_modes, is_ht40_ctl_mode,2679(p_ctl_mode[ctl_mode] & EXT_ADDITIVE));2680/* walk through each CTL index stored in EEPROM */2681if (IEEE80211_IS_CHAN_2GHZ(chan)) {2682ctl_index = p_eep_data->ctl_index_2g;2683ctl_num = OSPREY_NUM_CTLS_2G;2684} else {2685ctl_index = p_eep_data->ctl_index_5g;2686ctl_num = OSPREY_NUM_CTLS_5G;2687}26882689for (i = 0; (i < ctl_num) && ctl_index[i]; i++) {2690HALDEBUG(ah, HAL_DEBUG_POWER_MGMT,2691" LOOP-Ctlidx %d: cfg_ctl 0x%2.2x p_ctl_mode 0x%2.2x "2692"ctl_index 0x%2.2x chan %d chanctl 0x%x\n",2693i, cfg_ctl, p_ctl_mode[ctl_mode], ctl_index[i],2694ichan->channel, ath_hal_getctl(ah, chan));269526962697/*2698* compare test group from regulatory channel list2699* with test mode from p_ctl_mode list2700*/2701if ((((cfg_ctl & ~CTL_MODE_M) |2702(p_ctl_mode[ctl_mode] & CTL_MODE_M)) == ctl_index[i]) ||2703(((cfg_ctl & ~CTL_MODE_M) |2704(p_ctl_mode[ctl_mode] & CTL_MODE_M)) ==2705((ctl_index[i] & CTL_MODE_M) | SD_NO_CTL)))2706{2707twice_min_edge_power =2708ar9300_eep_def_get_max_edge_power(2709p_eep_data, freq, i, IEEE80211_IS_CHAN_2GHZ(chan));27102711HALDEBUG(ah, HAL_DEBUG_POWER_MGMT,2712" MATCH-EE_IDX %d: ch %d is2 %d "2713"2xMinEdge %d chainmask %d chains %d\n",2714i, freq, IEEE80211_IS_CHAN_2GHZ(chan),2715twice_min_edge_power, tx_chainmask,2716ar9300_get_ntxchains(tx_chainmask));27172718if ((cfg_ctl & ~CTL_MODE_M) == SD_NO_CTL) {2719/*2720* Find the minimum of all CTL edge powers2721* that apply to this channel2722*/2723twice_max_edge_power =2724AH_MIN(twice_max_edge_power, twice_min_edge_power);2725} else {2726/* specific */2727twice_max_edge_power = twice_min_edge_power;2728break;2729}2730}2731}27322733min_ctl_power = (u_int8_t)AH_MIN(twice_max_edge_power, scaled_power);27342735HALDEBUG(ah, HAL_DEBUG_POWER_MGMT,2736" SEL-Min ctl_mode %d p_ctl_mode %d "2737"2xMaxEdge %d sP %d min_ctl_pwr %d\n",2738ctl_mode, p_ctl_mode[ctl_mode],2739twice_max_edge_power, scaled_power, min_ctl_power);27402741/* Apply ctl mode to correct target power set */2742switch (p_ctl_mode[ctl_mode]) {2743case CTL_11B:2744for (i = ALL_TARGET_LEGACY_1L_5L; i <= ALL_TARGET_LEGACY_11S; i++) {2745p_pwr_array[i] =2746(u_int8_t)AH_MIN(p_pwr_array[i], min_ctl_power);2747}2748break;2749case CTL_11A:2750case CTL_11G:2751for (i = ALL_TARGET_LEGACY_6_24; i <= ALL_TARGET_LEGACY_54; i++) {2752p_pwr_array[i] =2753(u_int8_t)AH_MIN(p_pwr_array[i], min_ctl_power);2754#ifdef ATH_BT_COEX2755if ((ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_3WIRE) ||2756(ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_MCI))2757{2758if ((ahp->ah_bt_coex_flag & HAL_BT_COEX_FLAG_LOWER_TX_PWR)2759&& (ahp->ah_bt_wlan_isolation2760< HAL_BT_COEX_ISOLATION_FOR_NO_COEX))2761{27622763u_int8_t reduce_pow;27642765reduce_pow = (HAL_BT_COEX_ISOLATION_FOR_NO_COEX2766- ahp->ah_bt_wlan_isolation) << 1;27672768if (reduce_pow <= p_pwr_array[i]) {2769p_pwr_array[i] -= reduce_pow;2770}2771}2772if ((ahp->ah_bt_coex_flag &2773HAL_BT_COEX_FLAG_LOW_ACK_PWR) &&2774(i != ALL_TARGET_LEGACY_36) &&2775(i != ALL_TARGET_LEGACY_48) &&2776(i != ALL_TARGET_LEGACY_54) &&2777(p_ctl_mode[ctl_mode] == CTL_11G))2778{2779p_pwr_array[i] = 0;2780}2781}2782#endif2783}2784break;2785case CTL_5GHT20:2786case CTL_2GHT20:2787for (i = ALL_TARGET_HT20_0_8_16; i <= ALL_TARGET_HT20_23; i++) {2788p_pwr_array[i] =2789(u_int8_t)AH_MIN(p_pwr_array[i], min_ctl_power);2790#ifdef ATH_BT_COEX2791if (((ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_3WIRE) ||2792(ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_MCI)) &&2793(ahp->ah_bt_coex_flag & HAL_BT_COEX_FLAG_LOWER_TX_PWR) &&2794(ahp->ah_bt_wlan_isolation2795< HAL_BT_COEX_ISOLATION_FOR_NO_COEX)) {27962797u_int8_t reduce_pow = (HAL_BT_COEX_ISOLATION_FOR_NO_COEX2798- ahp->ah_bt_wlan_isolation) << 1;27992800if (reduce_pow <= p_pwr_array[i]) {2801p_pwr_array[i] -= reduce_pow;2802}2803}2804#if ATH_SUPPORT_MCI2805else if ((ahp->ah_bt_coex_flag &2806HAL_BT_COEX_FLAG_MCI_MAX_TX_PWR) &&2807(p_ctl_mode[ctl_mode] == CTL_2GHT20) &&2808(ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_MCI))2809{2810u_int8_t max_pwr;28112812max_pwr = MS(mci_concur_tx_max_pwr[2][1],2813ATH_MCI_CONCUR_TX_LOWEST_PWR_MASK);2814if (p_pwr_array[i] > max_pwr) {2815p_pwr_array[i] = max_pwr;2816}2817}2818#endif2819#endif2820}2821break;2822case CTL_11B_EXT:2823#ifdef NOT_YET2824target_power_cck_ext.t_pow2x[0] = (u_int8_t)2825AH_MIN(target_power_cck_ext.t_pow2x[0], min_ctl_power);2826#endif /* NOT_YET */2827break;2828case CTL_11A_EXT:2829case CTL_11G_EXT:2830#ifdef NOT_YET2831target_power_ofdm_ext.t_pow2x[0] = (u_int8_t)2832AH_MIN(target_power_ofdm_ext.t_pow2x[0], min_ctl_power);2833#endif /* NOT_YET */2834break;2835case CTL_5GHT40:2836case CTL_2GHT40:2837for (i = ALL_TARGET_HT40_0_8_16; i <= ALL_TARGET_HT40_23; i++) {2838p_pwr_array[i] = (u_int8_t)2839AH_MIN(p_pwr_array[i], min_ctl_power);2840#ifdef ATH_BT_COEX2841if (((ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_3WIRE) ||2842(ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_MCI)) &&2843(ahp->ah_bt_coex_flag & HAL_BT_COEX_FLAG_LOWER_TX_PWR) &&2844(ahp->ah_bt_wlan_isolation2845< HAL_BT_COEX_ISOLATION_FOR_NO_COEX)) {28462847u_int8_t reduce_pow = (HAL_BT_COEX_ISOLATION_FOR_NO_COEX2848- ahp->ah_bt_wlan_isolation) << 1;28492850if (reduce_pow <= p_pwr_array[i]) {2851p_pwr_array[i] -= reduce_pow;2852}2853}2854#if ATH_SUPPORT_MCI2855else if ((ahp->ah_bt_coex_flag &2856HAL_BT_COEX_FLAG_MCI_MAX_TX_PWR) &&2857(p_ctl_mode[ctl_mode] == CTL_2GHT40) &&2858(ahp->ah_bt_coex_config_type == HAL_BT_COEX_CFG_MCI))2859{2860u_int8_t max_pwr;28612862max_pwr = MS(mci_concur_tx_max_pwr[3][1],2863ATH_MCI_CONCUR_TX_LOWEST_PWR_MASK);2864if (p_pwr_array[i] > max_pwr) {2865p_pwr_array[i] = max_pwr;2866}2867}2868#endif2869#endif2870}2871break;2872default:2873HALASSERT(0);2874break;2875}2876} /* end ctl mode checking */28772878return AH_TRUE;2879#undef EXT_ADDITIVE2880#undef CTL_11A_EXT2881#undef CTL_11G_EXT2882#undef CTL_11B_EXT2883#undef REDUCE_SCALED_POWER_BY_TWO_CHAIN2884#undef REDUCE_SCALED_POWER_BY_THREE_CHAIN2885}28862887/**************************************************************2888* ar9300_eeprom_set_transmit_power2889*2890* Set the transmit power in the baseband for the given2891* operating channel and mode.2892*/2893HAL_STATUS2894ar9300_eeprom_set_transmit_power(struct ath_hal *ah,2895ar9300_eeprom_t *p_eep_data, const struct ieee80211_channel *chan, u_int16_t cfg_ctl,2896u_int16_t antenna_reduction, u_int16_t twice_max_regulatory_power,2897u_int16_t power_limit)2898{2899#define ABS(_x, _y) ((int)_x > (int)_y ? (int)_x - (int)_y : (int)_y - (int)_x)2900#define INCREASE_MAXPOW_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */2901#define INCREASE_MAXPOW_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */2902u_int8_t target_power_val_t2[ar9300_rate_size];2903u_int8_t target_power_val_t2_eep[ar9300_rate_size];2904int16_t twice_array_gain = 0, max_power_level = 0;2905struct ath_hal_9300 *ahp = AH9300(ah);2906int i = 0;2907u_int32_t tmp_paprd_rate_mask = 0, *tmp_ptr = NULL;2908int paprd_scale_factor = 5;2909HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, chan);29102911u_int8_t *ptr_mcs_rate2power_table_index;2912u_int8_t mcs_rate2power_table_index_ht20[24] =2913{2914ALL_TARGET_HT20_0_8_16,2915ALL_TARGET_HT20_1_3_9_11_17_19,2916ALL_TARGET_HT20_1_3_9_11_17_19,2917ALL_TARGET_HT20_1_3_9_11_17_19,2918ALL_TARGET_HT20_4,2919ALL_TARGET_HT20_5,2920ALL_TARGET_HT20_6,2921ALL_TARGET_HT20_7,2922ALL_TARGET_HT20_0_8_16,2923ALL_TARGET_HT20_1_3_9_11_17_19,2924ALL_TARGET_HT20_1_3_9_11_17_19,2925ALL_TARGET_HT20_1_3_9_11_17_19,2926ALL_TARGET_HT20_12,2927ALL_TARGET_HT20_13,2928ALL_TARGET_HT20_14,2929ALL_TARGET_HT20_15,2930ALL_TARGET_HT20_0_8_16,2931ALL_TARGET_HT20_1_3_9_11_17_19,2932ALL_TARGET_HT20_1_3_9_11_17_19,2933ALL_TARGET_HT20_1_3_9_11_17_19,2934ALL_TARGET_HT20_20,2935ALL_TARGET_HT20_21,2936ALL_TARGET_HT20_22,2937ALL_TARGET_HT20_232938};29392940u_int8_t mcs_rate2power_table_index_ht40[24] =2941{2942ALL_TARGET_HT40_0_8_16,2943ALL_TARGET_HT40_1_3_9_11_17_19,2944ALL_TARGET_HT40_1_3_9_11_17_19,2945ALL_TARGET_HT40_1_3_9_11_17_19,2946ALL_TARGET_HT40_4,2947ALL_TARGET_HT40_5,2948ALL_TARGET_HT40_6,2949ALL_TARGET_HT40_7,2950ALL_TARGET_HT40_0_8_16,2951ALL_TARGET_HT40_1_3_9_11_17_19,2952ALL_TARGET_HT40_1_3_9_11_17_19,2953ALL_TARGET_HT40_1_3_9_11_17_19,2954ALL_TARGET_HT40_12,2955ALL_TARGET_HT40_13,2956ALL_TARGET_HT40_14,2957ALL_TARGET_HT40_15,2958ALL_TARGET_HT40_0_8_16,2959ALL_TARGET_HT40_1_3_9_11_17_19,2960ALL_TARGET_HT40_1_3_9_11_17_19,2961ALL_TARGET_HT40_1_3_9_11_17_19,2962ALL_TARGET_HT40_20,2963ALL_TARGET_HT40_21,2964ALL_TARGET_HT40_22,2965ALL_TARGET_HT40_23,2966};29672968HALDEBUG(ah, HAL_DEBUG_CALIBRATE,2969"%s[%d] +++chan %d,cfgctl 0x%04x "2970"antenna_reduction 0x%04x, twice_max_regulatory_power 0x%04x "2971"power_limit 0x%04x\n",2972__func__, __LINE__, ichan->channel, cfg_ctl,2973antenna_reduction, twice_max_regulatory_power, power_limit);2974ar9300_set_target_power_from_eeprom(ah, ichan->channel, target_power_val_t2);29752976if (ar9300_eeprom_get(ahp, EEP_PAPRD_ENABLED)) {2977if (IEEE80211_IS_CHAN_2GHZ(chan)) {2978if (IEEE80211_IS_CHAN_HT40(chan)) {2979tmp_paprd_rate_mask =2980p_eep_data->modal_header_2g.paprd_rate_mask_ht40;2981tmp_ptr = &AH9300(ah)->ah_2g_paprd_rate_mask_ht40;2982} else {2983tmp_paprd_rate_mask =2984p_eep_data->modal_header_2g.paprd_rate_mask_ht20;2985tmp_ptr = &AH9300(ah)->ah_2g_paprd_rate_mask_ht20;2986}2987} else {2988if (IEEE80211_IS_CHAN_HT40(chan)) {2989tmp_paprd_rate_mask =2990p_eep_data->modal_header_5g.paprd_rate_mask_ht40;2991tmp_ptr = &AH9300(ah)->ah_5g_paprd_rate_mask_ht40;2992} else {2993tmp_paprd_rate_mask =2994p_eep_data->modal_header_5g.paprd_rate_mask_ht20;2995tmp_ptr = &AH9300(ah)->ah_5g_paprd_rate_mask_ht20;2996}2997}2998AH_PAPRD_GET_SCALE_FACTOR(2999paprd_scale_factor, p_eep_data, IEEE80211_IS_CHAN_2GHZ(chan), ichan->channel);3000HALDEBUG(ah, HAL_DEBUG_CALIBRATE, "%s[%d] paprd_scale_factor %d\n",3001__func__, __LINE__, paprd_scale_factor);3002/* PAPRD is not done yet, Scale down the EEP power */3003if (IEEE80211_IS_CHAN_HT40(chan)) {3004ptr_mcs_rate2power_table_index =3005&mcs_rate2power_table_index_ht40[0];3006} else {3007ptr_mcs_rate2power_table_index =3008&mcs_rate2power_table_index_ht20[0];3009}3010if (! ichan->paprd_table_write_done) {3011for (i = 0; i < 24; i++) {3012/* PAPRD is done yet, so Scale down Power for PAPRD Rates*/3013if (tmp_paprd_rate_mask & (1 << i)) {3014target_power_val_t2[ptr_mcs_rate2power_table_index[i]] -=3015paprd_scale_factor;3016HALDEBUG(ah, HAL_DEBUG_CALIBRATE,3017"%s[%d]: Chan %d "3018"Scale down target_power_val_t2[%d] = 0x%04x\n",3019__func__, __LINE__,3020ichan->channel, i, target_power_val_t2[i]);3021}3022}3023} else {3024HALDEBUG(ah, HAL_DEBUG_CALIBRATE,3025"%s[%d]: PAPRD Done No TGT PWR Scaling\n", __func__, __LINE__);3026}3027}30283029/* Save the Target power for future use */3030OS_MEMCPY(target_power_val_t2_eep, target_power_val_t2,3031sizeof(target_power_val_t2));3032ar9300_eeprom_set_power_per_rate_table(ah, p_eep_data, chan,3033target_power_val_t2, cfg_ctl,3034antenna_reduction,3035twice_max_regulatory_power,3036power_limit, 0);30373038/* Save this for quick lookup */3039ahp->reg_dmn = ath_hal_getctl(ah, chan);30403041/*3042* After reading FCC/OET 13TR1003 (Directional Gain of IEEE 802.113043* MIMO devices employing cyclic delay diversity) and looking at what3044* ath9k does, let's disable the CDD check until it's clearer exactly3045* how the maximum cap should be applied here.3046*3047* Right now the CDD check is simply unconditionally reducing the3048* gain of legacy and 1/2 stream rates depending upon the chainmask.3049* (CDD is used when transmitting rates that don't already use up the3050* full set of streams - eg OFDM or MCS0-7 on a 2 or 3 chain TX path.)3051*3052* It's dropping the 2-chain TX by 3dB and 3-chain by 5dB to "meet"3053* power spectral density requirements but it's not currently taking3054* into account how close to the regulatory limit the hardware/antenna3055* system is already at. It doesn't help that the conductive testing3056* limits have the array gain at 0dB for all AR9300/derivative3057* configurations.3058*3059* It also doesn't let us do single chain transmit at the full allowed3060* power for the regulatory/CTL limits as it subtracts it from what's3061* programmed into the hardware.3062*3063* ath9k doesn't factor any of the CDD stuff into account, so I'm going3064* to disable it here and in the TPC path until I get a better idea3065* of what to really do here.3066*/3067#if 03068/*3069* Always use CDD/direct per rate power table for register based approach.3070* For FCC, CDD calculations should factor in the array gain, hence3071* this adjust call. ETSI and MKK does not have this requirement.3072*/3073if (is_reg_dmn_fcc(ahp->reg_dmn)) {3074HALDEBUG(ah, HAL_DEBUG_CALIBRATE,3075"%s: FCC regdomain, calling reg_txpower_cdd\n",3076__func__);3077ar9300_adjust_reg_txpower_cdd(ah, target_power_val_t2);3078}3079#endif30803081if (ar9300_eeprom_get(ahp, EEP_PAPRD_ENABLED)) {3082for (i = 0; i < ar9300_rate_size; i++) {3083/*3084* EEPROM TGT PWR is not same as current TGT PWR,3085* so Disable PAPRD for this rate.3086* Some of APs might ask to reduce Target Power,3087* if target power drops significantly,3088* disable PAPRD for that rate.3089*/3090if (tmp_paprd_rate_mask & (1 << i)) {3091if (ABS(target_power_val_t2_eep[i], target_power_val_t2[i]) >3092paprd_scale_factor)3093{3094tmp_paprd_rate_mask &= ~(1 << i);3095HALDEBUG(ah, HAL_DEBUG_CALIBRATE,3096"%s: EEP TPC[%02d] 0x%08x "3097"Curr TPC[%02d] 0x%08x mask = 0x%08x\n",3098__func__, i, target_power_val_t2_eep[i], i,3099target_power_val_t2[i], tmp_paprd_rate_mask);3100}3101}31023103}3104HALDEBUG(ah, HAL_DEBUG_CALIBRATE,3105"%s: Chan %d After tmp_paprd_rate_mask = 0x%08x\n",3106__func__, ichan->channel, tmp_paprd_rate_mask);3107if (tmp_ptr) {3108*tmp_ptr = tmp_paprd_rate_mask;3109}3110}31113112/* Write target power array to registers */3113ar9300_transmit_power_reg_write(ah, target_power_val_t2);31143115/* Write target power for self generated frames to the TPC register */3116ar9300_selfgen_tpc_reg_write(ah, chan, target_power_val_t2);31173118/* GreenTx or Paprd */3119if (ah->ah_config.ath_hal_sta_update_tx_pwr_enable ||3120AH_PRIVATE(ah)->ah_caps.halPaprdEnabled)3121{3122if (AR_SREV_POSEIDON(ah)) {3123/*For HAL_RSSI_TX_POWER_NONE array*/3124OS_MEMCPY(ahp->ah_default_tx_power,3125target_power_val_t2,3126sizeof(target_power_val_t2));3127/* Get defautl tx related register setting for GreenTx */3128/* Record OB/DB */3129ahp->ah_ob_db1[POSEIDON_STORED_REG_OBDB] =3130OS_REG_READ(ah, AR_PHY_65NM_CH0_TXRF2);3131/* Record TPC settting */3132ahp->ah_ob_db1[POSEIDON_STORED_REG_TPC] =3133OS_REG_READ(ah, AR_TPC);3134/* Record BB_powertx_rate9 setting */3135ahp->ah_ob_db1[POSEIDON_STORED_REG_BB_PWRTX_RATE9] =3136OS_REG_READ(ah, AR_PHY_BB_POWERTX_RATE9);3137}3138}31393140/*3141* Return tx power used to iwconfig.3142* Since power is rate dependent, use one of the indices from the3143* AR9300_Rates enum to select an entry from target_power_val_t2[]3144* to report.3145* Currently returns the power for HT40 MCS 0, HT20 MCS 0, or OFDM 6 Mbps3146* as CCK power is less interesting (?).3147*/3148i = ALL_TARGET_LEGACY_6_24; /* legacy */3149if (IEEE80211_IS_CHAN_HT40(chan)) {3150i = ALL_TARGET_HT40_0_8_16; /* ht40 */3151} else if (IEEE80211_IS_CHAN_HT20(chan)) {3152i = ALL_TARGET_HT20_0_8_16; /* ht20 */3153}3154max_power_level = target_power_val_t2[i];3155/* Adjusting the ah_max_power_level based on chains and antennaGain*/3156switch (ar9300_get_ntxchains(((ahp->ah_tx_chainmaskopt > 0) ?3157ahp->ah_tx_chainmaskopt : ahp->ah_tx_chainmask)))3158{3159case 1:3160break;3161case 2:3162twice_array_gain = (ahp->twice_antenna_gain >= ahp->twice_antenna_reduction)? 0:3163((int16_t)AH_MIN((ahp->twice_antenna_reduction -3164(ahp->twice_antenna_gain + INCREASE_MAXPOW_BY_TWO_CHAIN)), 0));3165/* Adjusting maxpower with antennaGain */3166max_power_level -= twice_array_gain;3167/* Adjusting maxpower based on chain */3168max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;3169break;3170case 3:3171twice_array_gain = (ahp->twice_antenna_gain >= ahp->twice_antenna_reduction)? 0:3172((int16_t)AH_MIN((ahp->twice_antenna_reduction -3173(ahp->twice_antenna_gain + INCREASE_MAXPOW_BY_THREE_CHAIN)), 0));31743175/* Adjusting maxpower with antennaGain */3176max_power_level -= twice_array_gain;3177/* Adjusting maxpower based on chain */3178max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;3179break;3180default:3181HALASSERT(0); /* Unsupported number of chains */3182}3183AH_PRIVATE(ah)->ah_maxPowerLevel = (int8_t)max_power_level;31843185ar9300_calibration_apply(ah, ichan->channel);3186#undef ABS31873188/* Handle per packet TPC initializations */3189if (ah->ah_config.ath_hal_desc_tpc) {3190/* Transmit Power per-rate per-chain are computed here. A separate3191* power table is maintained for different MIMO modes (i.e. TXBF ON,3192* STBC) to enable easy lookup during packet transmit.3193* The reason for maintaing each of these tables per chain is that3194* the transmit power used for different number of chains is different3195* depending on whether the power has been limited by the target power,3196* the regulatory domain or the CTL limits.3197*/3198u_int mode = ath_hal_get_curmode(ah, chan);3199u_int32_t val = 0;3200u_int8_t chainmasks[AR9300_MAX_CHAINS] =3201{OSPREY_1_CHAINMASK, OSPREY_2LOHI_CHAINMASK, OSPREY_3_CHAINMASK};3202for (i = 0; i < AR9300_MAX_CHAINS; i++) {3203OS_MEMCPY(target_power_val_t2, target_power_val_t2_eep,3204sizeof(target_power_val_t2_eep));3205ar9300_eeprom_set_power_per_rate_table(ah, p_eep_data, chan,3206target_power_val_t2, cfg_ctl,3207antenna_reduction,3208twice_max_regulatory_power,3209power_limit, chainmasks[i]);3210HALDEBUG(ah, HAL_DEBUG_POWER_MGMT,3211" Channel = %d Chainmask = %d, Upper Limit = [%2d.%1d dBm]\n",3212ichan->channel, i, ahp->upper_limit[i]/2,3213ahp->upper_limit[i]%2 * 5);3214ar9300_init_rate_txpower(ah, mode, chan, target_power_val_t2,3215chainmasks[i]);32163217}32183219/* Enable TPC */3220OS_REG_WRITE(ah, AR_PHY_PWRTX_MAX, AR_PHY_PWRTX_MAX_TPC_ENABLE);3221/*3222* Disable per chain power reduction since we are already3223* accounting for this in our calculations3224*/3225val = OS_REG_READ(ah, AR_PHY_POWER_TX_SUB);3226if (AR_SREV_WASP(ah)) {3227OS_REG_WRITE(ah, AR_PHY_POWER_TX_SUB,3228val & AR_PHY_POWER_TX_SUB_2_DISABLE);3229} else {3230OS_REG_WRITE(ah, AR_PHY_POWER_TX_SUB,3231val & AR_PHY_POWER_TX_SUB_3_DISABLE);3232}3233}32343235return HAL_OK;3236}32373238/**************************************************************3239* ar9300_eeprom_set_addac3240*3241* Set the ADDAC from eeprom.3242*/3243void3244ar9300_eeprom_set_addac(struct ath_hal *ah, struct ieee80211_channel *chan)3245{32463247HALDEBUG(AH_NULL, HAL_DEBUG_UNMASKABLE,3248"FIXME: ar9300_eeprom_def_set_addac called\n");3249#if 03250MODAL_EEPDEF_HEADER *p_modal;3251struct ath_hal_9300 *ahp = AH9300(ah);3252ar9300_eeprom_t *eep = &ahp->ah_eeprom.def;3253u_int8_t biaslevel;32543255if (AH_PRIVATE(ah)->ah_macVersion != AR_SREV_VERSION_SOWL) {3256return;3257}32583259HALASSERT(owl_get_eepdef_ver(ahp) == AR9300_EEP_VER);32603261/* Xpa bias levels in eeprom are valid from rev 14.7 */3262if (owl_get_eepdef_rev(ahp) < AR9300_EEP_MINOR_VER_7) {3263return;3264}32653266if (ahp->ah_emu_eeprom) {3267return;3268}32693270p_modal = &(eep->modal_header[IEEE80211_IS_CHAN_2GHZ(chan)]);32713272if (p_modal->xpa_bias_lvl != 0xff) {3273biaslevel = p_modal->xpa_bias_lvl;3274} else {3275/* Use freqeuncy specific xpa bias level */3276u_int16_t reset_freq_bin, freq_bin, freq_count = 0;3277CHAN_CENTERS centers;32783279ar9300_get_channel_centers(ah, chan, ¢ers);32803281reset_freq_bin = FREQ2FBIN(centers.synth_center, IEEE80211_IS_CHAN_2GHZ(chan));3282freq_bin = p_modal->xpa_bias_lvl_freq[0] & 0xff;3283biaslevel = (u_int8_t)(p_modal->xpa_bias_lvl_freq[0] >> 14);32843285freq_count++;32863287while (freq_count < 3) {3288if (p_modal->xpa_bias_lvl_freq[freq_count] == 0x0) {3289break;3290}32913292freq_bin = p_modal->xpa_bias_lvl_freq[freq_count] & 0xff;3293if (reset_freq_bin >= freq_bin) {3294biaslevel =3295(u_int8_t)(p_modal->xpa_bias_lvl_freq[freq_count] >> 14);3296} else {3297break;3298}3299freq_count++;3300}3301}33023303/* Apply bias level to the ADDAC values in the INI array */3304if (IEEE80211_IS_CHAN_2GHZ(chan)) {3305INI_RA(&ahp->ah_ini_addac, 7, 1) =3306(INI_RA(&ahp->ah_ini_addac, 7, 1) & (~0x18)) | biaslevel << 3;3307} else {3308INI_RA(&ahp->ah_ini_addac, 6, 1) =3309(INI_RA(&ahp->ah_ini_addac, 6, 1) & (~0xc0)) | biaslevel << 6;3310}3311#endif3312}33133314u_int3315ar9300_eeprom_dump_support(struct ath_hal *ah, void **pp_e)3316{3317*pp_e = &(AH9300(ah)->ah_eeprom);3318return sizeof(ar9300_eeprom_t);3319}33203321u_int8_t3322ar9300_eeprom_get_num_ant_config(struct ath_hal_9300 *ahp,3323HAL_FREQ_BAND freq_band)3324{3325#if 03326ar9300_eeprom_t *eep = &ahp->ah_eeprom.def;3327MODAL_EEPDEF_HEADER *p_modal =3328&(eep->modal_header[HAL_FREQ_BAND_2GHZ == freq_band]);3329BASE_EEPDEF_HEADER *p_base = &eep->base_eep_header;3330u_int8_t num_ant_config;33313332num_ant_config = 1; /* default antenna configuration */33333334if (p_base->version >= 0x0E0D) {3335if (p_modal->use_ant1) {3336num_ant_config += 1;3337}3338}33393340return num_ant_config;3341#else3342return 1;3343#endif3344}33453346HAL_STATUS3347ar9300_eeprom_get_ant_cfg(struct ath_hal_9300 *ahp,3348const struct ieee80211_channel *chan,3349u_int8_t index, u_int16_t *config)3350{3351#if 03352ar9300_eeprom_t *eep = &ahp->ah_eeprom.def;3353MODAL_EEPDEF_HEADER *p_modal = &(eep->modal_header[IEEE80211_IS_CHAN_2GHZ(chan)]);3354BASE_EEPDEF_HEADER *p_base = &eep->base_eep_header;33553356switch (index) {3357case 0:3358*config = p_modal->ant_ctrl_common & 0xFFFF;3359return HAL_OK;3360case 1:3361if (p_base->version >= 0x0E0D) {3362if (p_modal->use_ant1) {3363*config = ((p_modal->ant_ctrl_common & 0xFFFF0000) >> 16);3364return HAL_OK;3365}3366}3367break;3368default:3369break;3370}3371#endif3372return HAL_EINVAL;3373}33743375u_int8_t*3376ar9300_eeprom_get_cust_data(struct ath_hal_9300 *ahp)3377{3378return (u_int8_t *)ahp;3379}33803381#ifdef UNUSED3382static inline HAL_STATUS3383ar9300_check_eeprom(struct ath_hal *ah)3384{3385#if 03386u_int32_t sum = 0, el;3387u_int16_t *eepdata;3388int i;3389struct ath_hal_9300 *ahp = AH9300(ah);3390HAL_BOOL need_swap = AH_FALSE;3391ar9300_eeprom_t *eep = (ar9300_eeprom_t *)&ahp->ah_eeprom.def;3392u_int16_t magic, magic2;3393int addr;3394u_int16_t temp;33953396/*3397** We need to check the EEPROM data regardless of if it's in flash or3398** in EEPROM.3399*/34003401if (!ahp->ah_priv.priv.ah_eeprom_read(3402ah, AR9300_EEPROM_MAGIC_OFFSET, &magic))3403{3404HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: Reading Magic # failed\n", __func__);3405return AH_FALSE;3406}34073408HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: Read Magic = 0x%04X\n", __func__, magic);34093410if (!ar9300_eep_data_in_flash(ah)) {34113412if (magic != AR9300_EEPROM_MAGIC) {3413magic2 = SWAP16(magic);34143415if (magic2 == AR9300_EEPROM_MAGIC) {3416need_swap = AH_TRUE;3417eepdata = (u_int16_t *)(&ahp->ah_eeprom);34183419for (addr = 0;3420addr < sizeof(ar9300_eeprom_t) / sizeof(u_int16_t);3421addr++)3422{3423temp = SWAP16(*eepdata);3424*eepdata = temp;3425eepdata++;34263427HALDEBUG(ah, HAL_DEBUG_EEPROM_DUMP, "0x%04X ", *eepdata);3428if (((addr + 1) % 6) == 0) {3429HALDEBUG(ah, HAL_DEBUG_EEPROM_DUMP, "\n");3430}3431}3432} else {3433HALDEBUG(ah, HAL_DEBUG_EEPROM,3434"Invalid EEPROM Magic. endianness missmatch.\n");3435return HAL_EEBADSUM;3436}3437}3438} else {3439HALDEBUG(ah, HAL_DEBUG_EEPROM,3440"EEPROM being read from flash @0x%p\n", AH_PRIVATE(ah)->ah_st);3441}34423443HALDEBUG(ah, HAL_DEBUG_EEPROM, "need_swap = %s.\n", need_swap?"True":"False");34443445if (need_swap) {3446el = SWAP16(ahp->ah_eeprom.def.base_eep_header.length);3447} else {3448el = ahp->ah_eeprom.def.base_eep_header.length;3449}34503451eepdata = (u_int16_t *)(&ahp->ah_eeprom.def);3452for (i = 0;3453i < AH_MIN(el, sizeof(ar9300_eeprom_t)) / sizeof(u_int16_t);3454i++) {3455sum ^= *eepdata++;3456}34573458if (need_swap) {3459/*3460* preddy: EEPROM endianness does not match. So change it3461* 8bit values in eeprom data structure does not need to be swapped3462* Only >8bits (16 & 32) values need to be swapped3463* If a new 16 or 32 bit field is added to the EEPROM contents,3464* please make sure to swap the field here3465*/3466u_int32_t integer, j;3467u_int16_t word;34683469HALDEBUG(ah, HAL_DEBUG_EEPROM,3470"EEPROM Endianness is not native.. Changing \n");34713472/* convert Base Eep header */3473word = SWAP16(eep->base_eep_header.length);3474eep->base_eep_header.length = word;34753476word = SWAP16(eep->base_eep_header.checksum);3477eep->base_eep_header.checksum = word;34783479word = SWAP16(eep->base_eep_header.version);3480eep->base_eep_header.version = word;34813482word = SWAP16(eep->base_eep_header.reg_dmn[0]);3483eep->base_eep_header.reg_dmn[0] = word;34843485word = SWAP16(eep->base_eep_header.reg_dmn[1]);3486eep->base_eep_header.reg_dmn[1] = word;34873488word = SWAP16(eep->base_eep_header.rf_silent);3489eep->base_eep_header.rf_silent = word;34903491word = SWAP16(eep->base_eep_header.blue_tooth_options);3492eep->base_eep_header.blue_tooth_options = word;34933494word = SWAP16(eep->base_eep_header.device_cap);3495eep->base_eep_header.device_cap = word;34963497/* convert Modal Eep header */3498for (j = 0; j < ARRAY_LENGTH(eep->modal_header); j++) {3499MODAL_EEPDEF_HEADER *p_modal = &eep->modal_header[j];3500integer = SWAP32(p_modal->ant_ctrl_common);3501p_modal->ant_ctrl_common = integer;35023503for (i = 0; i < AR9300_MAX_CHAINS; i++) {3504integer = SWAP32(p_modal->ant_ctrl_chain[i]);3505p_modal->ant_ctrl_chain[i] = integer;3506}35073508for (i = 0; i < AR9300_EEPROM_MODAL_SPURS; i++) {3509word = SWAP16(p_modal->spur_chans[i].spur_chan);3510p_modal->spur_chans[i].spur_chan = word;3511}3512}3513}35143515/* Check CRC - Attach should fail on a bad checksum */3516if (sum != 0xffff || owl_get_eepdef_ver(ahp) != AR9300_EEP_VER ||3517owl_get_eepdef_rev(ahp) < AR9300_EEP_NO_BACK_VER) {3518HALDEBUG(ah, HAL_DEBUG_EEPROM,3519"Bad EEPROM checksum 0x%x or revision 0x%04x\n",3520sum, owl_get_eepdef_ver(ahp));3521return HAL_EEBADSUM;3522}3523#ifdef EEPROM_DUMP3524ar9300_eeprom_def_dump(ah, eep);3525#endif35263527#if 03528#ifdef AH_AR9300_OVRD_TGT_PWR35293530/*3531* 14.4 EEPROM contains low target powers.3532* Hardcode until EEPROM > 14.43533*/3534if (owl_get_eepdef_ver(ahp) == 14 && owl_get_eepdef_rev(ahp) <= 4) {3535MODAL_EEPDEF_HEADER *p_modal;35363537#ifdef EEPROM_DUMP3538HALDEBUG(ah, HAL_DEBUG_POWER_OVERRIDE, "Original Target Powers\n");3539ar9300_eep_def_dump_tgt_power(ah, eep);3540#endif3541HALDEBUG(ah, HAL_DEBUG_POWER_OVERRIDE,3542"Override Target Powers. EEPROM Version is %d.%d, "3543"Device Type %d\n",3544owl_get_eepdef_ver(ahp),3545owl_get_eepdef_rev(ahp),3546eep->base_eep_header.device_type);354735483549ar9300_eep_def_override_tgt_power(ah, eep);35503551if (eep->base_eep_header.device_type == 5) {3552/* for xb72 only: improve transmit EVM for interop */3553p_modal = &eep->modal_header[1];3554p_modal->tx_frame_to_data_start = 0x23;3555p_modal->tx_frame_to_xpa_on = 0x23;3556p_modal->tx_frame_to_pa_on = 0x23;3557}35583559#ifdef EEPROM_DUMP3560HALDEBUG(ah, HAL_DEBUG_POWER_OVERRIDE, "Modified Target Powers\n");3561ar9300_eep_def_dump_tgt_power(ah, eep);3562#endif3563}3564#endif /* AH_AR9300_OVRD_TGT_PWR */3565#endif3566#endif3567return HAL_OK;3568}3569#endif35703571static u_int16_t3572ar9300_eeprom_get_spur_chan(struct ath_hal *ah, int i, HAL_BOOL is_2ghz)3573{3574u_int16_t spur_val = AR_NO_SPUR;3575#if 03576struct ath_hal_9300 *ahp = AH9300(ah);3577ar9300_eeprom_t *eep = (ar9300_eeprom_t *)&ahp->ah_eeprom;35783579HALASSERT(i < AR_EEPROM_MODAL_SPURS );35803581HALDEBUG(ah, HAL_DEBUG_ANI,3582"Getting spur idx %d is2Ghz. %d val %x\n",3583i, is_2ghz,3584AH_PRIVATE(ah)->ah_config.ath_hal_spur_chans[i][is_2ghz]);35853586switch (AH_PRIVATE(ah)->ah_config.ath_hal_spur_mode) {3587case SPUR_DISABLE:3588/* returns AR_NO_SPUR */3589break;3590case SPUR_ENABLE_IOCTL:3591spur_val = AH_PRIVATE(ah)->ah_config.ath_hal_spur_chans[i][is_2ghz];3592HALDEBUG(ah, HAL_DEBUG_ANI,3593"Getting spur val from new loc. %d\n", spur_val);3594break;3595case SPUR_ENABLE_EEPROM:3596spur_val = eep->modal_header[is_2ghz].spur_chans[i].spur_chan;3597break;35983599}3600#endif3601return spur_val;3602}36033604#ifdef UNUSED3605static inline HAL_BOOL3606ar9300_fill_eeprom(struct ath_hal *ah)3607{3608return ar9300_eeprom_restore(ah);3609}3610#endif36113612u_int16_t3613ar9300_eeprom_struct_size(void)3614{3615return sizeof(ar9300_eeprom_t);3616}36173618int ar9300_eeprom_struct_default_many(void)3619{3620return ARRAY_LENGTH(default9300);3621}362236233624ar9300_eeprom_t *3625ar9300_eeprom_struct_default(int default_index)3626{3627if (default_index >= 0 &&3628default_index < ARRAY_LENGTH(default9300))3629{3630return default9300[default_index];3631} else {3632return 0;3633}3634}36353636ar9300_eeprom_t *3637ar9300_eeprom_struct_default_find_by_id(int id)3638{3639int it;36403641for (it = 0; it < ARRAY_LENGTH(default9300); it++) {3642if (default9300[it] != 0 && default9300[it]->template_version == id) {3643return default9300[it];3644}3645}3646return 0;3647}364836493650HAL_BOOL3651ar9300_calibration_data_read_flash(struct ath_hal *ah, long address,3652u_int8_t *buffer, int many)3653{36543655if (((address) < 0) || ((address + many) > AR9300_EEPROM_SIZE - 1)) {3656return AH_FALSE;3657}3658return AH_FALSE;3659}36603661HAL_BOOL3662ar9300_calibration_data_read_eeprom(struct ath_hal *ah, long address,3663u_int8_t *buffer, int many)3664{3665int i;3666u_int8_t value[2];3667unsigned long eep_addr;3668unsigned long byte_addr;3669u_int16_t *svalue;36703671if (((address) < 0) || ((address + many) > AR9300_EEPROM_SIZE)) {3672return AH_FALSE;3673}36743675for (i = 0; i < many; i++) {3676eep_addr = (u_int16_t) (address + i) / 2;3677byte_addr = (u_int16_t) (address + i) % 2;3678svalue = (u_int16_t *) value;3679if (! ath_hal_eepromRead(ah, eep_addr, svalue)) {3680HALDEBUG(ah, HAL_DEBUG_EEPROM,3681"%s: Unable to read eeprom region \n", __func__);3682return AH_FALSE;3683}3684buffer[i] = (*svalue >> (8 * byte_addr)) & 0xff;3685}3686return AH_TRUE;3687}36883689HAL_BOOL3690ar9300_calibration_data_read_otp(struct ath_hal *ah, long address,3691u_int8_t *buffer, int many, HAL_BOOL is_wifi)3692{3693int i;3694unsigned long eep_addr;3695unsigned long byte_addr;3696u_int32_t svalue;36973698if (((address) < 0) || ((address + many) > 0x400)) {3699return AH_FALSE;3700}37013702for (i = 0; i < many; i++) {3703eep_addr = (u_int16_t) (address + i) / 4; /* otp is 4 bytes long???? */3704byte_addr = (u_int16_t) (address + i) % 4;3705if (!ar9300_otp_read(ah, eep_addr, &svalue, is_wifi)) {3706HALDEBUG(ah, HAL_DEBUG_EEPROM,3707"%s: Unable to read otp region \n", __func__);3708return AH_FALSE;3709}3710buffer[i] = (svalue >> (8 * byte_addr)) & 0xff;3711}3712return AH_TRUE;3713}37143715#ifdef ATH_CAL_NAND_FLASH3716HAL_BOOL3717ar9300_calibration_data_read_nand(struct ath_hal *ah, long address,3718u_int8_t *buffer, int many)3719{3720int ret_len;3721int ret_val = 1;37223723/* Calling OS based API to read NAND */3724ret_val = OS_NAND_FLASH_READ(ATH_CAL_NAND_PARTITION, address, many, &ret_len, buffer);37253726return (ret_val ? AH_FALSE: AH_TRUE);3727}3728#endif37293730HAL_BOOL3731ar9300_calibration_data_read(struct ath_hal *ah, long address,3732u_int8_t *buffer, int many)3733{3734switch (AH9300(ah)->calibration_data_source) {3735case calibration_data_flash:3736return ar9300_calibration_data_read_flash(ah, address, buffer, many);3737case calibration_data_eeprom:3738return ar9300_calibration_data_read_eeprom(ah, address, buffer, many);3739case calibration_data_otp:3740return ar9300_calibration_data_read_otp(ah, address, buffer, many, 1);3741#ifdef ATH_CAL_NAND_FLASH3742case calibration_data_nand:3743return ar9300_calibration_data_read_nand(ah,address,buffer,many);3744#endif37453746}3747return AH_FALSE;3748}374937503751HAL_BOOL3752ar9300_calibration_data_read_array(struct ath_hal *ah, int address,3753u_int8_t *buffer, int many)3754{3755int it;37563757for (it = 0; it < many; it++) {3758(void)ar9300_calibration_data_read(ah, address - it, buffer + it, 1);3759}3760return AH_TRUE;3761}376237633764/*3765* the address where the first configuration block is written3766*/3767static const int base_address = 0x3ff; /* 1KB */3768static const int base_address_512 = 0x1ff; /* 512Bytes */37693770/*3771* the address where the NAND first configuration block is written3772*/3773#ifdef ATH_CAL_NAND_FLASH3774static const int base_address_nand = AR9300_FLASH_CAL_START_OFFSET;3775#endif377637773778/*3779* the lower limit on configuration data3780*/3781static const int low_limit = 0x040;37823783/*3784* returns size of the physical eeprom in bytes.3785* 1024 and 2048 are normal sizes.3786* 0 means there is no eeprom.3787*/3788int32_t3789ar9300_eeprom_size(struct ath_hal *ah)3790{3791u_int16_t data;3792/*3793* first we'll try for 4096 bytes eeprom3794*/3795if (ar9300_eeprom_read_word(ah, 2047, &data)) {3796if (data != 0) {3797return 4096;3798}3799}3800/*3801* then we'll try for 2048 bytes eeprom3802*/3803if (ar9300_eeprom_read_word(ah, 1023, &data)) {3804if (data != 0) {3805return 2048;3806}3807}3808/*3809* then we'll try for 1024 bytes eeprom3810*/3811if (ar9300_eeprom_read_word(ah, 511, &data)) {3812if (data != 0) {3813return 1024;3814}3815}3816return 0;3817}38183819/*3820* returns size of the physical otp in bytes.3821* 1024 and 2048 are normal sizes.3822* 0 means there is no eeprom.3823*/3824int32_t3825ar9300_otp_size(struct ath_hal *ah)3826{3827if (AR_SREV_POSEIDON(ah) || AR_SREV_HORNET(ah)) {3828return base_address_512+1;3829} else {3830return base_address+1;3831}3832}383338343835/*3836* find top of memory3837*/3838int3839ar9300_eeprom_base_address(struct ath_hal *ah)3840{3841int size;38423843if (AH9300(ah)->calibration_data_source == calibration_data_otp) {3844return ar9300_otp_size(ah)-1;3845}3846else3847{3848size = ar9300_eeprom_size(ah);3849if (size > 0) {3850return size - 1;3851} else {3852return ar9300_otp_size(ah)-1;3853}3854}3855}38563857int3858ar9300_eeprom_volatile(struct ath_hal *ah)3859{3860if (AH9300(ah)->calibration_data_source == calibration_data_otp) {3861return 0; /* no eeprom, use otp */3862} else {3863return 1; /* board has eeprom or flash */3864}3865}38663867/*3868* need to change this to look for the pcie data in the low parts of memory3869* cal data needs to stop a few locations above3870*/3871int3872ar9300_eeprom_low_limit(struct ath_hal *ah)3873{3874return low_limit;3875}38763877u_int16_t3878ar9300_compression_checksum(u_int8_t *data, int dsize)3879{3880int it;3881int checksum = 0;38823883for (it = 0; it < dsize; it++) {3884checksum += data[it];3885checksum &= 0xffff;3886}38873888return checksum;3889}38903891int3892ar9300_compression_header_unpack(u_int8_t *best, int *code, int *reference,3893int *length, int *major, int *minor)3894{3895unsigned long value[4];38963897value[0] = best[0];3898value[1] = best[1];3899value[2] = best[2];3900value[3] = best[3];3901*code = ((value[0] >> 5) & 0x0007);3902*reference = (value[0] & 0x001f) | ((value[1] >> 2) & 0x0020);3903*length = ((value[1] << 4) & 0x07f0) | ((value[2] >> 4) & 0x000f);3904*major = (value[2] & 0x000f);3905*minor = (value[3] & 0x00ff);39063907return 4;3908}390939103911static HAL_BOOL3912ar9300_uncompress_block(struct ath_hal *ah, u_int8_t *mptr, int mdata_size,3913u_int8_t *block, int size)3914{3915int it;3916int spot;3917int offset;3918int length;39193920spot = 0;3921for (it = 0; it < size; it += (length + 2)) {3922offset = block[it];3923offset &= 0xff;3924spot += offset;3925length = block[it + 1];3926length &= 0xff;3927if (length > 0 && spot >= 0 && spot + length <= mdata_size) {3928HALDEBUG(ah, HAL_DEBUG_EEPROM,3929"%s: Restore at %d: spot=%d offset=%d length=%d\n",3930__func__, it, spot, offset, length);3931OS_MEMCPY(&mptr[spot], &block[it + 2], length);3932spot += length;3933} else if (length > 0) {3934HALDEBUG(ah, HAL_DEBUG_EEPROM,3935"%s: Bad restore at %d: spot=%d offset=%d length=%d\n",3936__func__, it, spot, offset, length);3937return AH_FALSE;3938}3939}3940return AH_TRUE;3941}39423943static int3944ar9300_eeprom_restore_internal_address(struct ath_hal *ah,3945ar9300_eeprom_t *mptr, int mdata_size, int cptr, u_int8_t blank)3946{3947u_int8_t word[MOUTPUT];3948ar9300_eeprom_t *dptr; /* was uint8 */3949int code;3950int reference, length, major, minor;3951int osize;3952int it;3953int restored;3954u_int16_t checksum, mchecksum;39553956restored = 0;3957for (it = 0; it < MSTATE; it++) {3958(void) ar9300_calibration_data_read_array(3959ah, cptr, word, compression_header_length);3960if (word[0] == blank && word[1] == blank && word[2] == blank && word[3] == blank)3961{3962break;3963}3964ar9300_compression_header_unpack(3965word, &code, &reference, &length, &major, &minor);3966HALDEBUG(ah, HAL_DEBUG_EEPROM,3967"%s: Found block at %x: "3968"code=%d ref=%d length=%d major=%d minor=%d\n",3969__func__, cptr, code, reference, length, major, minor);3970#ifdef DONTUSE3971if (length >= 1024) {3972HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: Skipping bad header\n", __func__);3973cptr -= compression_header_length;3974continue;3975}3976#endif3977osize = length;3978(void) ar9300_calibration_data_read_array(3979ah, cptr, word,3980compression_header_length + osize + compression_checksum_length);3981checksum = ar9300_compression_checksum(3982&word[compression_header_length], length);3983mchecksum =3984word[compression_header_length + osize] |3985(word[compression_header_length + osize + 1] << 8);3986HALDEBUG(ah, HAL_DEBUG_EEPROM,3987"%s: checksum %x %x\n", __func__, checksum, mchecksum);3988if (checksum == mchecksum) {3989switch (code) {3990case _compress_none:3991if (length != mdata_size) {3992HALDEBUG(ah, HAL_DEBUG_EEPROM,3993"%s: EEPROM structure size mismatch "3994"memory=%d eeprom=%d\n", __func__, mdata_size, length);3995return -1;3996}3997OS_MEMCPY((u_int8_t *)mptr,3998(u_int8_t *)(word + compression_header_length), length);3999HALDEBUG(ah, HAL_DEBUG_EEPROM,4000"%s: restored eeprom %d: uncompressed, length %d\n",4001__func__, it, length);4002restored = 1;4003break;4004#ifdef UNUSED4005case _compress_lzma:4006if (reference == reference_current) {4007dptr = mptr;4008} else {4009dptr = (u_int8_t *)ar9300_eeprom_struct_default_find_by_id(4010reference);4011if (dptr == 0) {4012HALDEBUG(ah, HAL_DEBUG_EEPROM,4013"%s: Can't find reference eeprom struct %d\n",4014__func__, reference);4015goto done;4016}4017}4018usize = -1;4019if (usize != mdata_size) {4020HALDEBUG(ah, HAL_DEBUG_EEPROM,4021"%s: uncompressed data is wrong size %d %d\n",4022__func__, usize, mdata_size);4023goto done;4024}40254026for (ib = 0; ib < mdata_size; ib++) {4027mptr[ib] = dptr[ib] ^ word[ib + overhead];4028}4029HALDEBUG(ah, HAL_DEBUG_EEPROM,4030"%s: restored eeprom %d: compressed, "4031"reference %d, length %d\n",4032__func__, it, reference, length);4033break;4034case _compress_pairs:4035if (reference == reference_current) {4036dptr = mptr;4037} else {4038dptr = (u_int8_t *)ar9300_eeprom_struct_default_find_by_id(4039reference);4040if (dptr == 0) {4041HALDEBUG(ah, HAL_DEBUG_EEPROM,4042"%s: Can't find the reference "4043"eeprom structure %d\n",4044__func__, reference);4045goto done;4046}4047}4048HALDEBUG(ah, HAL_DEBUG_EEPROM,4049"%s: restored eeprom %d: "4050"pairs, reference %d, length %d,\n",4051__func__, it, reference, length);4052break;4053#endif4054case _compress_block:4055if (reference == reference_current) {4056dptr = mptr;4057} else {4058dptr = ar9300_eeprom_struct_default_find_by_id(reference);4059if (dptr == 0) {4060HALDEBUG(ah, HAL_DEBUG_EEPROM,4061"%s: cant find reference eeprom struct %d\n",4062__func__, reference);4063break;4064}4065OS_MEMCPY(mptr, dptr, mdata_size);4066}40674068HALDEBUG(ah, HAL_DEBUG_EEPROM,4069"%s: restore eeprom %d: block, reference %d, length %d\n",4070__func__, it, reference, length);4071(void) ar9300_uncompress_block(ah,4072(u_int8_t *) mptr, mdata_size,4073(u_int8_t *) (word + compression_header_length), length);4074restored = 1;4075break;4076default:4077HALDEBUG(ah, HAL_DEBUG_EEPROM,4078"%s: unknown compression code %d\n", __func__, code);4079break;4080}4081} else {4082HALDEBUG(ah, HAL_DEBUG_EEPROM,4083"%s: skipping block with bad checksum\n", __func__);4084}4085cptr -= compression_header_length + osize + compression_checksum_length;4086}40874088if (!restored) {4089cptr = -1;4090}4091return cptr;4092}40934094static int4095ar9300_eeprom_restore_from_dram(struct ath_hal *ah, ar9300_eeprom_t *mptr,4096int mdata_size)4097{4098struct ath_hal_9300 *ahp = AH9300(ah);4099#if !defined(USE_PLATFORM_FRAMEWORK)4100char *cal_ptr;4101#endif41024103HALASSERT(mdata_size > 0);41044105/* if cal_in_flash is AH_TRUE, the address sent by LMAC to HAL4106(i.e. ah->ah_st) is corresponding to Flash. so return from4107here if ar9300_eep_data_in_flash(ah) returns AH_TRUE */4108if(ar9300_eep_data_in_flash(ah))4109return -1;41104111#if 04112/* check if LMAC sent DRAM address is valid */4113if (!(uintptr_t)(AH_PRIVATE(ah)->ah_st)) {4114return -1;4115}4116#endif41174118/* When calibration data is from host, Host will copy the4119compressed data to the predefined DRAM location saved at ah->ah_st */4120#if 04121ath_hal_printf(ah, "Restoring Cal data from DRAM\n");4122ahp->ah_cal_mem = OS_REMAP((uintptr_t)(AH_PRIVATE(ah)->ah_st),4123HOST_CALDATA_SIZE);4124#endif4125if (!ahp->ah_cal_mem)4126{4127HALDEBUG(ah, HAL_DEBUG_EEPROM,"%s: can't remap dram region\n", __func__);4128return -1;4129}4130#if !defined(USE_PLATFORM_FRAMEWORK)4131cal_ptr = &((char *)(ahp->ah_cal_mem))[AR9300_FLASH_CAL_START_OFFSET];4132OS_MEMCPY(mptr, cal_ptr, mdata_size);4133#else4134OS_MEMCPY(mptr, ahp->ah_cal_mem, mdata_size);4135#endif41364137if (mptr->eeprom_version == 0xff ||4138mptr->template_version == 0xff ||4139mptr->eeprom_version == 0 ||4140mptr->template_version == 0)4141{4142/* The board is uncalibrated */4143return -1;4144}4145if (mptr->eeprom_version != 0x2)4146{4147return -1;4148}41494150return mdata_size;41514152}41534154static int4155ar9300_eeprom_restore_from_flash(struct ath_hal *ah, ar9300_eeprom_t *mptr,4156int mdata_size)4157{4158struct ath_hal_9300 *ahp = AH9300(ah);4159char *cal_ptr;41604161HALASSERT(mdata_size > 0);41624163if (!ahp->ah_cal_mem) {4164return -1;4165}41664167ath_hal_printf(ah, "Restoring Cal data from Flash\n");4168/*4169* When calibration data is saved in flash, read4170* uncompressed eeprom structure from flash and return4171*/4172cal_ptr = &((char *)(ahp->ah_cal_mem))[AR9300_FLASH_CAL_START_OFFSET];4173OS_MEMCPY(mptr, cal_ptr, mdata_size);4174#if 04175ar9300_swap_eeprom((ar9300_eeprom_t *)mptr); DONE IN ar9300_restore()4176#endif4177if (mptr->eeprom_version == 0xff ||4178mptr->template_version == 0xff ||4179mptr->eeprom_version == 0 ||4180mptr->template_version == 0)4181{4182/* The board is uncalibrated */4183return -1;4184}4185if (mptr->eeprom_version != 0x2)4186{4187return -1;4188}4189return mdata_size;4190}41914192/*4193* Read the configuration data from the storage. We try the order with:4194* EEPROM, Flash, OTP. If all of above failed, use the default template.4195* The data can be put in any specified memory buffer.4196*4197* Returns -1 on error.4198* Returns address of next memory location on success.4199*/4200int4201ar9300_eeprom_restore_internal(struct ath_hal *ah, ar9300_eeprom_t *mptr,4202int mdata_size)4203{4204int nptr;42054206nptr = -1;42074208if ((AH9300(ah)->calibration_data_try == calibration_data_none ||4209AH9300(ah)->calibration_data_try == calibration_data_dram) &&4210AH9300(ah)->try_dram && nptr < 0)4211{4212ath_hal_printf(ah, "Restoring Cal data from DRAM\n");4213AH9300(ah)->calibration_data_source = calibration_data_dram;4214AH9300(ah)->calibration_data_source_address = 0;4215nptr = ar9300_eeprom_restore_from_dram(ah, mptr, mdata_size);4216if (nptr < 0) {4217AH9300(ah)->calibration_data_source = calibration_data_none;4218AH9300(ah)->calibration_data_source_address = 0;4219}4220}42214222if ((AH9300(ah)->calibration_data_try == calibration_data_none ||4223AH9300(ah)->calibration_data_try == calibration_data_eeprom) &&4224AH9300(ah)->try_eeprom && nptr < 0)4225{4226/*4227* need to look at highest eeprom address as well as at4228* base_address=0x3ff where we used to write the data4229*/4230ath_hal_printf(ah, "Restoring Cal data from EEPROM\n");4231AH9300(ah)->calibration_data_source = calibration_data_eeprom;4232if (AH9300(ah)->calibration_data_try_address != 0) {4233AH9300(ah)->calibration_data_source_address =4234AH9300(ah)->calibration_data_try_address;4235nptr = ar9300_eeprom_restore_internal_address(4236ah, mptr, mdata_size,4237AH9300(ah)->calibration_data_source_address, 0xff);4238} else {4239AH9300(ah)->calibration_data_source_address =4240ar9300_eeprom_base_address(ah);4241nptr = ar9300_eeprom_restore_internal_address(4242ah, mptr, mdata_size,4243AH9300(ah)->calibration_data_source_address, 0xff);4244if (nptr < 0 &&4245AH9300(ah)->calibration_data_source_address != base_address)4246{4247AH9300(ah)->calibration_data_source_address = base_address;4248nptr = ar9300_eeprom_restore_internal_address(4249ah, mptr, mdata_size,4250AH9300(ah)->calibration_data_source_address, 0xff);4251}4252}4253if (nptr < 0) {4254AH9300(ah)->calibration_data_source = calibration_data_none;4255AH9300(ah)->calibration_data_source_address = 0;4256}4257}42584259/*4260* ##### should be an ifdef test for any AP usage,4261* either in driver or in nart4262*/4263if ((AH9300(ah)->calibration_data_try == calibration_data_none ||4264AH9300(ah)->calibration_data_try == calibration_data_flash) &&4265AH9300(ah)->try_flash && nptr < 0)4266{4267ath_hal_printf(ah, "Restoring Cal data from Flash\n");4268AH9300(ah)->calibration_data_source = calibration_data_flash;4269/* how are we supposed to set this for flash? */4270AH9300(ah)->calibration_data_source_address = 0;4271nptr = ar9300_eeprom_restore_from_flash(ah, mptr, mdata_size);4272if (nptr < 0) {4273AH9300(ah)->calibration_data_source = calibration_data_none;4274AH9300(ah)->calibration_data_source_address = 0;4275}4276}42774278if ((AH9300(ah)->calibration_data_try == calibration_data_none ||4279AH9300(ah)->calibration_data_try == calibration_data_otp) &&4280AH9300(ah)->try_otp && nptr < 0)4281{4282ath_hal_printf(ah, "Restoring Cal data from OTP\n");4283AH9300(ah)->calibration_data_source = calibration_data_otp;4284if (AH9300(ah)->calibration_data_try_address != 0) {4285AH9300(ah)->calibration_data_source_address =4286AH9300(ah)->calibration_data_try_address;4287} else {4288AH9300(ah)->calibration_data_source_address =4289ar9300_eeprom_base_address(ah);4290}4291nptr = ar9300_eeprom_restore_internal_address(4292ah, mptr, mdata_size, AH9300(ah)->calibration_data_source_address, 0);4293if (nptr < 0) {4294AH9300(ah)->calibration_data_source = calibration_data_none;4295AH9300(ah)->calibration_data_source_address = 0;4296}4297}42984299#ifdef ATH_CAL_NAND_FLASH4300if ((AH9300(ah)->calibration_data_try == calibration_data_none ||4301AH9300(ah)->calibration_data_try == calibration_data_nand) &&4302AH9300(ah)->try_nand && nptr < 0)4303{4304AH9300(ah)->calibration_data_source = calibration_data_nand;4305AH9300(ah)->calibration_data_source_address = ((unsigned int)(AH_PRIVATE(ah)->ah_st)) + base_address_nand;4306if(ar9300_calibration_data_read(4307ah, AH9300(ah)->calibration_data_source_address,4308(u_int8_t *)mptr, mdata_size) == AH_TRUE)4309{4310nptr = mdata_size;4311}4312/*nptr=ar9300EepromRestoreInternalAddress(ah, mptr, mdataSize, CalibrationDataSourceAddress);*/4313if(nptr < 0)4314{4315AH9300(ah)->calibration_data_source = calibration_data_none;4316AH9300(ah)->calibration_data_source_address = 0;4317}4318}4319#endif4320if (nptr < 0) {4321ath_hal_printf(ah, "%s[%d] No valid CAL, calling default template\n",4322__func__, __LINE__);4323nptr = ar9300_eeprom_restore_something(ah, mptr, mdata_size);4324}43254326return nptr;4327}43284329/******************************************************************************/4330/*!4331** \brief Eeprom Swapping Function4332**4333** This function will swap the contents of the "longer" EEPROM data items4334** to ensure they are consistent with the endian requirements for the platform4335** they are being compiled for4336**4337** \param eh Pointer to the EEPROM data structure4338** \return N/A4339*/4340#if AH_BYTE_ORDER == AH_BIG_ENDIAN4341void4342ar9300_swap_eeprom(ar9300_eeprom_t *eep)4343{4344u_int32_t dword;4345u_int16_t word;4346int i;43474348word = __bswap16(eep->base_eep_header.reg_dmn[0]);4349eep->base_eep_header.reg_dmn[0] = word;43504351word = __bswap16(eep->base_eep_header.reg_dmn[1]);4352eep->base_eep_header.reg_dmn[1] = word;43534354dword = __bswap32(eep->base_eep_header.swreg);4355eep->base_eep_header.swreg = dword;43564357dword = __bswap32(eep->modal_header_2g.ant_ctrl_common);4358eep->modal_header_2g.ant_ctrl_common = dword;43594360dword = __bswap32(eep->modal_header_2g.ant_ctrl_common2);4361eep->modal_header_2g.ant_ctrl_common2 = dword;43624363dword = __bswap32(eep->modal_header_2g.paprd_rate_mask_ht20);4364eep->modal_header_2g.paprd_rate_mask_ht20 = dword;43654366dword = __bswap32(eep->modal_header_2g.paprd_rate_mask_ht40);4367eep->modal_header_2g.paprd_rate_mask_ht40 = dword;43684369dword = __bswap32(eep->modal_header_5g.ant_ctrl_common);4370eep->modal_header_5g.ant_ctrl_common = dword;43714372dword = __bswap32(eep->modal_header_5g.ant_ctrl_common2);4373eep->modal_header_5g.ant_ctrl_common2 = dword;43744375dword = __bswap32(eep->modal_header_5g.paprd_rate_mask_ht20);4376eep->modal_header_5g.paprd_rate_mask_ht20 = dword;43774378dword = __bswap32(eep->modal_header_5g.paprd_rate_mask_ht40);4379eep->modal_header_5g.paprd_rate_mask_ht40 = dword;43804381for (i = 0; i < OSPREY_MAX_CHAINS; i++) {4382word = __bswap16(eep->modal_header_2g.ant_ctrl_chain[i]);4383eep->modal_header_2g.ant_ctrl_chain[i] = word;43844385word = __bswap16(eep->modal_header_5g.ant_ctrl_chain[i]);4386eep->modal_header_5g.ant_ctrl_chain[i] = word;4387}4388}43894390void ar9300_eeprom_template_swap(void)4391{4392int it;4393ar9300_eeprom_t *dptr;43944395for (it = 0; it < ARRAY_LENGTH(default9300); it++) {4396dptr = ar9300_eeprom_struct_default(it);4397if (dptr != 0) {4398ar9300_swap_eeprom(dptr);4399}4400}4401}4402#endif440344044405/*4406* Restore the configuration structure by reading the eeprom.4407* This function destroys any existing in-memory structure content.4408*/4409HAL_BOOL4410ar9300_eeprom_restore(struct ath_hal *ah)4411{4412struct ath_hal_9300 *ahp = AH9300(ah);4413ar9300_eeprom_t *mptr;4414int mdata_size;4415HAL_BOOL status = AH_FALSE;44164417mptr = &ahp->ah_eeprom;4418mdata_size = ar9300_eeprom_struct_size();44194420if (mptr != 0 && mdata_size > 0) {4421#if AH_BYTE_ORDER == AH_BIG_ENDIAN4422ar9300_eeprom_template_swap();4423ar9300_swap_eeprom(mptr);4424#endif4425/*4426* At this point, mptr points to the eeprom data structure4427* in its "default" state. If this is big endian, swap the4428* data structures back to "little endian" form.4429*/4430if (ar9300_eeprom_restore_internal(ah, mptr, mdata_size) >= 0) {4431status = AH_TRUE;4432}44334434#if AH_BYTE_ORDER == AH_BIG_ENDIAN4435/* Second Swap, back to Big Endian */4436ar9300_eeprom_template_swap();4437ar9300_swap_eeprom(mptr);4438#endif44394440}4441ahp->ah_2g_paprd_rate_mask_ht40 =4442mptr->modal_header_2g.paprd_rate_mask_ht40;4443ahp->ah_2g_paprd_rate_mask_ht20 =4444mptr->modal_header_2g.paprd_rate_mask_ht20;4445ahp->ah_5g_paprd_rate_mask_ht40 =4446mptr->modal_header_5g.paprd_rate_mask_ht40;4447ahp->ah_5g_paprd_rate_mask_ht20 =4448mptr->modal_header_5g.paprd_rate_mask_ht20;4449return status;4450}44514452int32_t ar9300_thermometer_get(struct ath_hal *ah)4453{4454struct ath_hal_9300 *ahp = AH9300(ah);4455int thermometer;4456thermometer =4457(ahp->ah_eeprom.base_eep_header.misc_configuration >> 1) & 0x3;4458thermometer--;4459return thermometer;4460}44614462HAL_BOOL ar9300_thermometer_apply(struct ath_hal *ah)4463{4464int thermometer = ar9300_thermometer_get(ah);44654466/* ch0_RXTX4 */4467/*#define AR_PHY_65NM_CH0_RXTX4 AR_PHY_65NM(ch0_RXTX4)*/4468#define AR_PHY_65NM_CH1_RXTX4 AR_PHY_65NM(ch1_RXTX4)4469#define AR_PHY_65NM_CH2_RXTX4 AR_PHY_65NM(ch2_RXTX4)4470/*#define AR_PHY_65NM_CH0_RXTX4_THERM_ON 0x10000000*/4471/*#define AR_PHY_65NM_CH0_RXTX4_THERM_ON_S 28*/4472#define AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR_S 294473#define AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR \4474(0x1<<AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR_S)44754476if (thermometer < 0) {4477OS_REG_RMW_FIELD(ah,4478AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 0);4479if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {4480OS_REG_RMW_FIELD(ah,4481AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 0);4482if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {4483OS_REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,4484AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 0);4485}4486}4487OS_REG_RMW_FIELD(ah,4488AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);4489if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {4490OS_REG_RMW_FIELD(ah,4491AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);4492if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {4493OS_REG_RMW_FIELD(ah,4494AR_PHY_65NM_CH2_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);4495}4496}4497} else {4498OS_REG_RMW_FIELD(ah,4499AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 1);4500if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {4501OS_REG_RMW_FIELD(ah,4502AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 1);4503if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {4504OS_REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,4505AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, 1);4506}4507}4508if (thermometer == 0) {4509OS_REG_RMW_FIELD(ah,4510AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 1);4511if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {4512OS_REG_RMW_FIELD(ah,4513AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);4514if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {4515OS_REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,4516AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);4517}4518}4519} else if (thermometer == 1) {4520OS_REG_RMW_FIELD(ah,4521AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);4522if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {4523OS_REG_RMW_FIELD(ah,4524AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 1);4525if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {4526OS_REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,4527AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);4528}4529}4530} else if (thermometer == 2) {4531OS_REG_RMW_FIELD(ah,4532AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);4533if (!AR_SREV_HORNET(ah) && !AR_SREV_POSEIDON(ah)) {4534OS_REG_RMW_FIELD(ah,4535AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_CH0_RXTX4_THERM_ON, 0);4536if (!AR_SREV_WASP(ah) && !AR_SREV_JUPITER(ah) && !AR_SREV_HONEYBEE(ah) ) {4537OS_REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,4538AR_PHY_65NM_CH0_RXTX4_THERM_ON, 1);4539}4540}4541}4542}4543return AH_TRUE;4544}45454546static int32_t ar9300_tuning_caps_params_get(struct ath_hal *ah)4547{4548int tuning_caps_params;4549ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;4550tuning_caps_params = eep->base_eep_header.params_for_tuning_caps[0];4551return tuning_caps_params;4552}45534554/*4555* Read the tuning caps params from eeprom and set to correct register.4556* To regulation the frequency accuracy.4557*/4558HAL_BOOL ar9300_tuning_caps_apply(struct ath_hal *ah)4559{4560int tuning_caps_params;4561ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;4562tuning_caps_params = ar9300_tuning_caps_params_get(ah);4563if ((eep->base_eep_header.feature_enable & 0x40) >> 6) {4564tuning_caps_params &= 0x7f;45654566if (AR_SREV_POSEIDON(ah) || AR_SREV_WASP(ah) || AR_SREV_HONEYBEE(ah)) {4567return true;4568} else if (AR_SREV_HORNET(ah)) {4569OS_REG_RMW_FIELD(ah,4570AR_HORNET_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPINDAC,4571tuning_caps_params);4572OS_REG_RMW_FIELD(ah,4573AR_HORNET_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPOUTDAC,4574tuning_caps_params);4575} else if (AR_SREV_SCORPION(ah)) {4576OS_REG_RMW_FIELD(ah,4577AR_SCORPION_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPINDAC,4578tuning_caps_params);4579OS_REG_RMW_FIELD(ah,4580AR_SCORPION_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPOUTDAC,4581tuning_caps_params);4582} else {4583OS_REG_RMW_FIELD(ah,4584AR_OSPREY_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPINDAC,4585tuning_caps_params);4586OS_REG_RMW_FIELD(ah,4587AR_OSPREY_CH0_XTAL, AR_OSPREY_CHO_XTAL_CAPOUTDAC,4588tuning_caps_params);4589}45904591}4592return AH_TRUE;4593}45944595/*4596* Read the tx_frame_to_xpa_on param from eeprom and apply the value to4597* correct register.4598*/4599HAL_BOOL ar9300_xpa_timing_control_apply(struct ath_hal *ah, HAL_BOOL is_2ghz)4600{4601u_int8_t xpa_timing_control;4602ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;4603if ((eep->base_eep_header.feature_enable & 0x80) >> 7) {4604if (AR_SREV_OSPREY(ah) || AR_SREV_AR9580(ah) || AR_SREV_WASP(ah) || AR_SREV_HONEYBEE(ah)) {4605if (is_2ghz) {4606xpa_timing_control = eep->modal_header_2g.tx_frame_to_xpa_on;4607OS_REG_RMW_FIELD(ah,4608AR_PHY_XPA_TIMING_CTL, AR_PHY_XPA_TIMING_CTL_FRAME_XPAB_ON,4609xpa_timing_control);4610} else {4611xpa_timing_control = eep->modal_header_5g.tx_frame_to_xpa_on;4612OS_REG_RMW_FIELD(ah,4613AR_PHY_XPA_TIMING_CTL, AR_PHY_XPA_TIMING_CTL_FRAME_XPAA_ON,4614xpa_timing_control);4615}4616}4617}4618return AH_TRUE;4619}462046214622/*4623* Read the xLNA_bias_strength param from eeprom and apply the value to4624* correct register.4625*/4626HAL_BOOL ar9300_x_lNA_bias_strength_apply(struct ath_hal *ah, HAL_BOOL is_2ghz)4627{4628u_int8_t x_lNABias;4629u_int32_t value = 0;4630ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;46314632if ((eep->base_eep_header.misc_configuration & 0x40) >> 6) {4633if (AR_SREV_OSPREY(ah)) {4634if (is_2ghz) {4635x_lNABias = eep->modal_header_2g.xLNA_bias_strength;4636} else {4637x_lNABias = eep->modal_header_5g.xLNA_bias_strength;4638}4639value = x_lNABias & ( 0x03 ); // bit0,1 for chain04640OS_REG_RMW_FIELD(ah,4641AR_PHY_65NM_CH0_RXTX4, AR_PHY_65NM_RXTX4_XLNA_BIAS, value);4642value = (x_lNABias >> 2) & ( 0x03 ); // bit2,3 for chain14643OS_REG_RMW_FIELD(ah,4644AR_PHY_65NM_CH1_RXTX4, AR_PHY_65NM_RXTX4_XLNA_BIAS, value);4645value = (x_lNABias >> 4) & ( 0x03 ); // bit4,5 for chain24646OS_REG_RMW_FIELD(ah,4647AR_PHY_65NM_CH2_RXTX4, AR_PHY_65NM_RXTX4_XLNA_BIAS, value);4648}4649}4650return AH_TRUE;4651}465246534654/*4655* Read EEPROM header info and program the device for correct operation4656* given the channel value.4657*/4658HAL_BOOL4659ar9300_eeprom_set_board_values(struct ath_hal *ah, const struct ieee80211_channel *chan)4660{4661HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, chan);46624663ar9300_xpa_bias_level_apply(ah, IEEE80211_IS_CHAN_2GHZ(chan));46644665ar9300_xpa_timing_control_apply(ah, IEEE80211_IS_CHAN_2GHZ(chan));46664667ar9300_ant_ctrl_apply(ah, IEEE80211_IS_CHAN_2GHZ(chan));4668ar9300_drive_strength_apply(ah);46694670ar9300_x_lNA_bias_strength_apply(ah, IEEE80211_IS_CHAN_2GHZ(chan));46714672/* wait for Poseidon internal regular turnning */4673/* for Hornet we move it before initPLL to avoid an access issue */4674/* Function not used when EMULATION. */4675if (!AR_SREV_HORNET(ah) && !AR_SREV_WASP(ah) && !AR_SREV_HONEYBEE(ah)) {4676ar9300_internal_regulator_apply(ah);4677}46784679ar9300_attenuation_apply(ah, ichan->channel);4680ar9300_quick_drop_apply(ah, ichan->channel);4681ar9300_thermometer_apply(ah);4682if(!AR_SREV_WASP(ah))4683{4684ar9300_tuning_caps_apply(ah);4685}46864687ar9300_tx_end_to_xpab_off_apply(ah, ichan->channel);46884689return AH_TRUE;4690}46914692u_int8_t *4693ar9300_eeprom_get_spur_chans_ptr(struct ath_hal *ah, HAL_BOOL is_2ghz)4694{4695ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;46964697if (is_2ghz) {4698return &(eep->modal_header_2g.spur_chans[0]);4699} else {4700return &(eep->modal_header_5g.spur_chans[0]);4701}4702}47034704static u_int8_t ar9300_eeprom_get_tx_gain_table_number_max(struct ath_hal *ah)4705{4706unsigned long tx_gain_table_max;4707tx_gain_table_max = OS_REG_READ_FIELD(ah,4708AR_PHY_TPC_7, AR_PHY_TPC_7_TX_GAIN_TABLE_MAX);4709return tx_gain_table_max;4710}47114712u_int8_t ar9300_eeprom_tx_gain_table_index_max_apply(struct ath_hal *ah, u_int16_t channel)4713{4714unsigned int index;4715ar9300_eeprom_t *ahp_Eeprom;4716struct ath_hal_9300 *ahp = AH9300(ah);47174718ahp_Eeprom = &ahp->ah_eeprom;47194720if (ahp_Eeprom->base_ext1.misc_enable == 0)4721return AH_FALSE;47224723if (channel < 4000)4724{4725index = ahp_Eeprom->modal_header_2g.tx_gain_cap;4726}4727else4728{4729index = ahp_Eeprom->modal_header_5g.tx_gain_cap;4730}47314732OS_REG_RMW_FIELD(ah,4733AR_PHY_TPC_7, AR_PHY_TPC_7_TX_GAIN_TABLE_MAX, index);4734return AH_TRUE;4735}47364737static u_int8_t ar9300_eeprom_get_pcdac_tx_gain_table_i(struct ath_hal *ah,4738int i, u_int8_t *pcdac)4739{4740unsigned long tx_gain;4741u_int8_t tx_gain_table_max;4742tx_gain_table_max = ar9300_eeprom_get_tx_gain_table_number_max(ah);4743if (i <= 0 || i > tx_gain_table_max) {4744*pcdac = 0;4745return AH_FALSE;4746}47474748tx_gain = OS_REG_READ(ah, AR_PHY_TXGAIN_TAB(1) + i * 4);4749*pcdac = ((tx_gain >> 24) & 0xff);4750return AH_TRUE;4751}47524753u_int8_t ar9300_eeprom_set_tx_gain_cap(struct ath_hal *ah,4754int *tx_gain_max)4755// pcdac read back from reg, read back value depends on reset 2GHz/5GHz ini4756// tx_gain_table, this function will be called twice after each4757// band's calibration.4758// after 2GHz cal, tx_gain_max[0] has 2GHz, calibration max txgain,4759// tx_gain_max[1]=-1004760// after 5GHz cal, tx_gain_max[0],tx_gain_max[1] have calibration4761// value for both band4762// reset is on 5GHz, reg reading from tx_gain_table is for 5GHz,4763// so program can't recalculate 2g.tx_gain_cap at this point.4764{4765int i = 0, ig, im = 0;4766u_int8_t pcdac = 0;4767u_int8_t tx_gain_table_max;4768ar9300_eeprom_t *ahp_Eeprom;4769struct ath_hal_9300 *ahp = AH9300(ah);47704771ahp_Eeprom = &ahp->ah_eeprom;47724773if (ahp_Eeprom->base_ext1.misc_enable == 0)4774return AH_FALSE;47754776tx_gain_table_max = ar9300_eeprom_get_tx_gain_table_number_max(ah);47774778for (i = 0; i < 2; i++) {4779if (tx_gain_max[i]>-100) { // -100 didn't cal that band.4780if ( i== 0) {4781if (tx_gain_max[1]>-100) {4782continue;4783// both band are calibrated, skip 2GHz 2g.tx_gain_cap reset4784}4785}4786for (ig = 1; ig <= tx_gain_table_max; ig++) {4787if (ah != 0 && ah->ah_reset != 0)4788{4789ar9300_eeprom_get_pcdac_tx_gain_table_i(ah, ig, &pcdac);4790if (pcdac >= tx_gain_max[i])4791break;4792}4793}4794if (ig+1 <= tx_gain_table_max) {4795if (pcdac == tx_gain_max[i])4796im = ig;4797else4798im = ig + 1;4799if (i == 0) {4800ahp_Eeprom->modal_header_2g.tx_gain_cap = im;4801} else {4802ahp_Eeprom->modal_header_5g.tx_gain_cap = im;4803}4804} else {4805if (i == 0) {4806ahp_Eeprom->modal_header_2g.tx_gain_cap = ig;4807} else {4808ahp_Eeprom->modal_header_5g.tx_gain_cap = ig;4809}4810}4811}4812}4813return AH_TRUE;4814}481548164817