Path: blob/main/sys/dev/ath/ath_hal/ar5212/ar5111.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2009 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2008 Atheros Communications, Inc.5*6* Permission to use, copy, modify, and/or distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*/18#include "opt_ah.h"1920#include "ah.h"21#include "ah_internal.h"2223#include "ah_eeprom_v3.h"2425#include "ar5212/ar5212.h"26#include "ar5212/ar5212reg.h"27#include "ar5212/ar5212phy.h"2829#define AH_5212_511130#include "ar5212/ar5212.ini"3132#define N(a) (sizeof(a)/sizeof(a[0]))3334struct ar5111State {35RF_HAL_FUNCS base; /* public state, must be first */36uint16_t pcdacTable[PWR_TABLE_SIZE];3738uint32_t Bank0Data[N(ar5212Bank0_5111)];39uint32_t Bank1Data[N(ar5212Bank1_5111)];40uint32_t Bank2Data[N(ar5212Bank2_5111)];41uint32_t Bank3Data[N(ar5212Bank3_5111)];42uint32_t Bank6Data[N(ar5212Bank6_5111)];43uint32_t Bank7Data[N(ar5212Bank7_5111)];44};45#define AR5111(ah) ((struct ar5111State *) AH5212(ah)->ah_rfHal)4647static uint16_t ar5212GetScaledPower(uint16_t channel, uint16_t pcdacValue,48const PCDACS_EEPROM *pSrcStruct);49static HAL_BOOL ar5212FindValueInList(uint16_t channel, uint16_t pcdacValue,50const PCDACS_EEPROM *pSrcStruct, uint16_t *powerValue);51static void ar5212GetLowerUpperPcdacs(uint16_t pcdac, uint16_t channel,52const PCDACS_EEPROM *pSrcStruct,53uint16_t *pLowerPcdac, uint16_t *pUpperPcdac);5455extern void ar5212GetLowerUpperValues(uint16_t value,56const uint16_t *pList, uint16_t listSize,57uint16_t *pLowerValue, uint16_t *pUpperValue);58extern void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32,59uint32_t numBits, uint32_t firstBit, uint32_t column);6061static void62ar5111WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex,63int writes)64{65HAL_INI_WRITE_ARRAY(ah, ar5212Modes_5111, modesIndex, writes);66HAL_INI_WRITE_ARRAY(ah, ar5212Common_5111, 1, writes);67HAL_INI_WRITE_ARRAY(ah, ar5212BB_RfGain_5111, freqIndex, writes);68}6970/*71* Take the MHz channel value and set the Channel value72*73* ASSUMES: Writes enabled to analog bus74*/75static HAL_BOOL76ar5111SetChannel(struct ath_hal *ah, const struct ieee80211_channel *chan)77{78#define CI_2GHZ_INDEX_CORRECTION 1979uint16_t freq = ath_hal_gethwchannel(ah, chan);80uint32_t refClk, reg32, data2111;81int16_t chan5111, chanIEEE;8283/*84* Structure to hold 11b tuning information for 5111/211185* 16 MHz mode, divider ratio = 198 = NP+S. N=16, S=4 or 6, P=1286*/87typedef struct {88uint32_t refClkSel; /* reference clock, 1 for 16 MHz */89uint32_t channelSelect; /* P[7:4]S[3:0] bits */90uint16_t channel5111; /* 11a channel for 5111 */91} CHAN_INFO_2GHZ;9293static const CHAN_INFO_2GHZ chan2GHzData[] = {94{ 1, 0x46, 96 }, /* 2312 -19 */95{ 1, 0x46, 97 }, /* 2317 -18 */96{ 1, 0x46, 98 }, /* 2322 -17 */97{ 1, 0x46, 99 }, /* 2327 -16 */98{ 1, 0x46, 100 }, /* 2332 -15 */99{ 1, 0x46, 101 }, /* 2337 -14 */100{ 1, 0x46, 102 }, /* 2342 -13 */101{ 1, 0x46, 103 }, /* 2347 -12 */102{ 1, 0x46, 104 }, /* 2352 -11 */103{ 1, 0x46, 105 }, /* 2357 -10 */104{ 1, 0x46, 106 }, /* 2362 -9 */105{ 1, 0x46, 107 }, /* 2367 -8 */106{ 1, 0x46, 108 }, /* 2372 -7 */107/* index -6 to 0 are pad to make this a nolookup table */108{ 1, 0x46, 116 }, /* -6 */109{ 1, 0x46, 116 }, /* -5 */110{ 1, 0x46, 116 }, /* -4 */111{ 1, 0x46, 116 }, /* -3 */112{ 1, 0x46, 116 }, /* -2 */113{ 1, 0x46, 116 }, /* -1 */114{ 1, 0x46, 116 }, /* 0 */115{ 1, 0x46, 116 }, /* 2412 1 */116{ 1, 0x46, 117 }, /* 2417 2 */117{ 1, 0x46, 118 }, /* 2422 3 */118{ 1, 0x46, 119 }, /* 2427 4 */119{ 1, 0x46, 120 }, /* 2432 5 */120{ 1, 0x46, 121 }, /* 2437 6 */121{ 1, 0x46, 122 }, /* 2442 7 */122{ 1, 0x46, 123 }, /* 2447 8 */123{ 1, 0x46, 124 }, /* 2452 9 */124{ 1, 0x46, 125 }, /* 2457 10 */125{ 1, 0x46, 126 }, /* 2462 11 */126{ 1, 0x46, 127 }, /* 2467 12 */127{ 1, 0x46, 128 }, /* 2472 13 */128{ 1, 0x44, 124 }, /* 2484 14 */129{ 1, 0x46, 136 }, /* 2512 15 */130{ 1, 0x46, 140 }, /* 2532 16 */131{ 1, 0x46, 144 }, /* 2552 17 */132{ 1, 0x46, 148 }, /* 2572 18 */133{ 1, 0x46, 152 }, /* 2592 19 */134{ 1, 0x46, 156 }, /* 2612 20 */135{ 1, 0x46, 160 }, /* 2632 21 */136{ 1, 0x46, 164 }, /* 2652 22 */137{ 1, 0x46, 168 }, /* 2672 23 */138{ 1, 0x46, 172 }, /* 2692 24 */139{ 1, 0x46, 176 }, /* 2712 25 */140{ 1, 0x46, 180 } /* 2732 26 */141};142143OS_MARK(ah, AH_MARK_SETCHANNEL, freq);144145chanIEEE = chan->ic_ieee;146if (IEEE80211_IS_CHAN_2GHZ(chan)) {147const CHAN_INFO_2GHZ* ci =148&chan2GHzData[chanIEEE + CI_2GHZ_INDEX_CORRECTION];149uint32_t txctl;150151data2111 = ((ath_hal_reverseBits(ci->channelSelect, 8) & 0xff)152<< 5)153| (ci->refClkSel << 4);154chan5111 = ci->channel5111;155txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL);156if (freq == 2484) {157/* Enable channel spreading for channel 14 */158OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,159txctl | AR_PHY_CCK_TX_CTRL_JAPAN);160} else {161OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,162txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);163}164} else {165chan5111 = chanIEEE; /* no conversion needed */166data2111 = 0;167}168169/* Rest of the code is common for 5 GHz and 2.4 GHz. */170if (chan5111 >= 145 || (chan5111 & 0x1)) {171reg32 = ath_hal_reverseBits(chan5111 - 24, 8) & 0xff;172refClk = 1;173} else {174reg32 = ath_hal_reverseBits(((chan5111 - 24)/2), 8) & 0xff;175refClk = 0;176}177178reg32 = (reg32 << 2) | (refClk << 1) | (1 << 10) | 0x1;179OS_REG_WRITE(ah, AR_PHY(0x27), ((data2111 & 0xff) << 8) | (reg32 & 0xff));180reg32 >>= 8;181OS_REG_WRITE(ah, AR_PHY(0x34), (data2111 & 0xff00) | (reg32 & 0xff));182183AH_PRIVATE(ah)->ah_curchan = chan;184return AH_TRUE;185#undef CI_2GHZ_INDEX_CORRECTION186}187188/*189* Return a reference to the requested RF Bank.190*/191static uint32_t *192ar5111GetRfBank(struct ath_hal *ah, int bank)193{194struct ar5111State *priv = AR5111(ah);195196HALASSERT(priv != AH_NULL);197switch (bank) {198case 0: return priv->Bank0Data;199case 1: return priv->Bank1Data;200case 2: return priv->Bank2Data;201case 3: return priv->Bank3Data;202case 6: return priv->Bank6Data;203case 7: return priv->Bank7Data;204}205HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown RF Bank %d requested\n",206__func__, bank);207return AH_NULL;208}209210/*211* Reads EEPROM header info from device structure and programs212* all rf registers213*214* REQUIRES: Access to the analog rf device215*/216static HAL_BOOL217ar5111SetRfRegs(struct ath_hal *ah, const struct ieee80211_channel *chan,218uint16_t modesIndex, uint16_t *rfXpdGain)219{220uint16_t freq = ath_hal_gethwchannel(ah, chan);221struct ath_hal_5212 *ahp = AH5212(ah);222const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;223uint16_t rfXpdGainFixed, rfPloSel, rfPwdXpd, gainI;224uint16_t tempOB, tempDB;225uint32_t ob2GHz, db2GHz, rfReg[N(ar5212Bank6_5111)];226int i, regWrites = 0;227228HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan %u/0x%x modesIndex %u\n",229__func__, chan->ic_freq, chan->ic_flags, modesIndex);230231/* Setup rf parameters */232switch (chan->ic_flags & IEEE80211_CHAN_ALLFULL) {233case IEEE80211_CHAN_A:234if (4000 < freq && freq < 5260) {235tempOB = ee->ee_ob1;236tempDB = ee->ee_db1;237} else if (5260 <= freq && freq < 5500) {238tempOB = ee->ee_ob2;239tempDB = ee->ee_db2;240} else if (5500 <= freq && freq < 5725) {241tempOB = ee->ee_ob3;242tempDB = ee->ee_db3;243} else if (freq >= 5725) {244tempOB = ee->ee_ob4;245tempDB = ee->ee_db4;246} else {247/* XXX when does this happen??? */248tempOB = tempDB = 0;249}250ob2GHz = db2GHz = 0;251252rfXpdGainFixed = ee->ee_xgain[headerInfo11A];253rfPloSel = ee->ee_xpd[headerInfo11A];254rfPwdXpd = !ee->ee_xpd[headerInfo11A];255gainI = ee->ee_gainI[headerInfo11A];256break;257case IEEE80211_CHAN_B:258tempOB = ee->ee_obFor24;259tempDB = ee->ee_dbFor24;260ob2GHz = ee->ee_ob2GHz[0];261db2GHz = ee->ee_db2GHz[0];262263rfXpdGainFixed = ee->ee_xgain[headerInfo11B];264rfPloSel = ee->ee_xpd[headerInfo11B];265rfPwdXpd = !ee->ee_xpd[headerInfo11B];266gainI = ee->ee_gainI[headerInfo11B];267break;268case IEEE80211_CHAN_G:269case IEEE80211_CHAN_PUREG: /* NB: really 108G */270tempOB = ee->ee_obFor24g;271tempDB = ee->ee_dbFor24g;272ob2GHz = ee->ee_ob2GHz[1];273db2GHz = ee->ee_db2GHz[1];274275rfXpdGainFixed = ee->ee_xgain[headerInfo11G];276rfPloSel = ee->ee_xpd[headerInfo11G];277rfPwdXpd = !ee->ee_xpd[headerInfo11G];278gainI = ee->ee_gainI[headerInfo11G];279break;280default:281HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n",282__func__, chan->ic_flags);283return AH_FALSE;284}285286HALASSERT(1 <= tempOB && tempOB <= 5);287HALASSERT(1 <= tempDB && tempDB <= 5);288289/* Bank 0 Write */290for (i = 0; i < N(ar5212Bank0_5111); i++)291rfReg[i] = ar5212Bank0_5111[i][modesIndex];292if (IEEE80211_IS_CHAN_2GHZ(chan)) {293ar5212ModifyRfBuffer(rfReg, ob2GHz, 3, 119, 0);294ar5212ModifyRfBuffer(rfReg, db2GHz, 3, 122, 0);295}296HAL_INI_WRITE_BANK(ah, ar5212Bank0_5111, rfReg, regWrites);297298/* Bank 1 Write */299HAL_INI_WRITE_ARRAY(ah, ar5212Bank1_5111, 1, regWrites);300301/* Bank 2 Write */302HAL_INI_WRITE_ARRAY(ah, ar5212Bank2_5111, modesIndex, regWrites);303304/* Bank 3 Write */305HAL_INI_WRITE_ARRAY(ah, ar5212Bank3_5111, modesIndex, regWrites);306307/* Bank 6 Write */308for (i = 0; i < N(ar5212Bank6_5111); i++)309rfReg[i] = ar5212Bank6_5111[i][modesIndex];310if (IEEE80211_IS_CHAN_A(chan)) { /* NB: CHANNEL_A | CHANNEL_T */311ar5212ModifyRfBuffer(rfReg, ee->ee_cornerCal.pd84, 1, 51, 3);312ar5212ModifyRfBuffer(rfReg, ee->ee_cornerCal.pd90, 1, 45, 3);313}314ar5212ModifyRfBuffer(rfReg, rfPwdXpd, 1, 95, 0);315ar5212ModifyRfBuffer(rfReg, rfXpdGainFixed, 4, 96, 0);316/* Set 5212 OB & DB */317ar5212ModifyRfBuffer(rfReg, tempOB, 3, 104, 0);318ar5212ModifyRfBuffer(rfReg, tempDB, 3, 107, 0);319HAL_INI_WRITE_BANK(ah, ar5212Bank6_5111, rfReg, regWrites);320321/* Bank 7 Write */322for (i = 0; i < N(ar5212Bank7_5111); i++)323rfReg[i] = ar5212Bank7_5111[i][modesIndex];324ar5212ModifyRfBuffer(rfReg, gainI, 6, 29, 0);325ar5212ModifyRfBuffer(rfReg, rfPloSel, 1, 4, 0);326327if (IEEE80211_IS_CHAN_QUARTER(chan) || IEEE80211_IS_CHAN_HALF(chan)) {328uint32_t rfWaitI, rfWaitS, rfMaxTime;329330rfWaitS = 0x1f;331rfWaitI = (IEEE80211_IS_CHAN_HALF(chan)) ? 0x10 : 0x1f;332rfMaxTime = 3;333ar5212ModifyRfBuffer(rfReg, rfWaitS, 5, 19, 0);334ar5212ModifyRfBuffer(rfReg, rfWaitI, 5, 24, 0);335ar5212ModifyRfBuffer(rfReg, rfMaxTime, 2, 49, 0);336}337338HAL_INI_WRITE_BANK(ah, ar5212Bank7_5111, rfReg, regWrites);339340/* Now that we have reprogrammed rfgain value, clear the flag. */341ahp->ah_rfgainState = HAL_RFGAIN_INACTIVE;342343return AH_TRUE;344}345346/*347* Returns interpolated or the scaled up interpolated value348*/349static uint16_t350interpolate(uint16_t target, uint16_t srcLeft, uint16_t srcRight,351uint16_t targetLeft, uint16_t targetRight)352{353uint16_t rv;354int16_t lRatio;355356/* to get an accurate ratio, always scale, if want to scale, then don't scale back down */357if ((targetLeft * targetRight) == 0)358return 0;359360if (srcRight != srcLeft) {361/*362* Note the ratio always need to be scaled,363* since it will be a fraction.364*/365lRatio = (target - srcLeft) * EEP_SCALE / (srcRight - srcLeft);366if (lRatio < 0) {367/* Return as Left target if value would be negative */368rv = targetLeft;369} else if (lRatio > EEP_SCALE) {370/* Return as Right target if Ratio is greater than 100% (SCALE) */371rv = targetRight;372} else {373rv = (lRatio * targetRight + (EEP_SCALE - lRatio) *374targetLeft) / EEP_SCALE;375}376} else {377rv = targetLeft;378}379return rv;380}381382/*383* Read the transmit power levels from the structures taken from EEPROM384* Interpolate read transmit power values for this channel385* Organize the transmit power values into a table for writing into the hardware386*/387static HAL_BOOL388ar5111SetPowerTable(struct ath_hal *ah,389int16_t *pMinPower, int16_t *pMaxPower,390const struct ieee80211_channel *chan,391uint16_t *rfXpdGain)392{393uint16_t freq = ath_hal_gethwchannel(ah, chan);394struct ath_hal_5212 *ahp = AH5212(ah);395const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;396FULL_PCDAC_STRUCT pcdacStruct;397int i, j;398399uint16_t *pPcdacValues;400int16_t *pScaledUpDbm;401int16_t minScaledPwr;402int16_t maxScaledPwr;403int16_t pwr;404uint16_t pcdacMin = 0;405uint16_t pcdacMax = PCDAC_STOP;406uint16_t pcdacTableIndex;407uint16_t scaledPcdac;408PCDACS_EEPROM *pSrcStruct;409PCDACS_EEPROM eepromPcdacs;410411/* setup the pcdac struct to point to the correct info, based on mode */412switch (chan->ic_flags & IEEE80211_CHAN_ALLTURBOFULL) {413case IEEE80211_CHAN_A:414case IEEE80211_CHAN_ST:415eepromPcdacs.numChannels = ee->ee_numChannels11a;416eepromPcdacs.pChannelList = ee->ee_channels11a;417eepromPcdacs.pDataPerChannel = ee->ee_dataPerChannel11a;418break;419case IEEE80211_CHAN_B:420eepromPcdacs.numChannels = ee->ee_numChannels2_4;421eepromPcdacs.pChannelList = ee->ee_channels11b;422eepromPcdacs.pDataPerChannel = ee->ee_dataPerChannel11b;423break;424case IEEE80211_CHAN_G:425case IEEE80211_CHAN_108G:426eepromPcdacs.numChannels = ee->ee_numChannels2_4;427eepromPcdacs.pChannelList = ee->ee_channels11g;428eepromPcdacs.pDataPerChannel = ee->ee_dataPerChannel11g;429break;430default:431HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n",432__func__, chan->ic_flags);433return AH_FALSE;434}435436pSrcStruct = &eepromPcdacs;437438OS_MEMZERO(&pcdacStruct, sizeof(pcdacStruct));439pPcdacValues = pcdacStruct.PcdacValues;440pScaledUpDbm = pcdacStruct.PwrValues;441442/* Initialize the pcdacs to dBM structs pcdacs to be 1 to 63 */443for (i = PCDAC_START, j = 0; i <= PCDAC_STOP; i+= PCDAC_STEP, j++)444pPcdacValues[j] = i;445446pcdacStruct.numPcdacValues = j;447pcdacStruct.pcdacMin = PCDAC_START;448pcdacStruct.pcdacMax = PCDAC_STOP;449450/* Fill out the power values for this channel */451for (j = 0; j < pcdacStruct.numPcdacValues; j++ )452pScaledUpDbm[j] = ar5212GetScaledPower(freq,453pPcdacValues[j], pSrcStruct);454455/* Now scale the pcdac values to fit in the 64 entry power table */456minScaledPwr = pScaledUpDbm[0];457maxScaledPwr = pScaledUpDbm[pcdacStruct.numPcdacValues - 1];458459/* find minimum and make monotonic */460for (j = 0; j < pcdacStruct.numPcdacValues; j++) {461if (minScaledPwr >= pScaledUpDbm[j]) {462minScaledPwr = pScaledUpDbm[j];463pcdacMin = j;464}465/*466* Make the full_hsh monotonically increasing otherwise467* interpolation algorithm will get fooled gotta start468* working from the top, hence i = 63 - j.469*/470i = (uint16_t)(pcdacStruct.numPcdacValues - 1 - j);471if (i == 0)472break;473if (pScaledUpDbm[i-1] > pScaledUpDbm[i]) {474/*475* It could be a glitch, so make the power for476* this pcdac the same as the power from the477* next highest pcdac.478*/479pScaledUpDbm[i - 1] = pScaledUpDbm[i];480}481}482483for (j = 0; j < pcdacStruct.numPcdacValues; j++)484if (maxScaledPwr < pScaledUpDbm[j]) {485maxScaledPwr = pScaledUpDbm[j];486pcdacMax = j;487}488489/* Find the first power level with a pcdac */490pwr = (uint16_t)(PWR_STEP *491((minScaledPwr - PWR_MIN + PWR_STEP / 2) / PWR_STEP) + PWR_MIN);492493/* Write all the first pcdac entries based off the pcdacMin */494pcdacTableIndex = 0;495for (i = 0; i < (2 * (pwr - PWR_MIN) / EEP_SCALE + 1); i++) {496HALASSERT(pcdacTableIndex < PWR_TABLE_SIZE);497ahp->ah_pcdacTable[pcdacTableIndex++] = pcdacMin;498}499500i = 0;501while (pwr < pScaledUpDbm[pcdacStruct.numPcdacValues - 1] &&502pcdacTableIndex < PWR_TABLE_SIZE) {503pwr += PWR_STEP;504/* stop if dbM > max_power_possible */505while (pwr < pScaledUpDbm[pcdacStruct.numPcdacValues - 1] &&506(pwr - pScaledUpDbm[i])*(pwr - pScaledUpDbm[i+1]) > 0)507i++;508/* scale by 2 and add 1 to enable round up or down as needed */509scaledPcdac = (uint16_t)(interpolate(pwr,510pScaledUpDbm[i], pScaledUpDbm[i + 1],511(uint16_t)(pPcdacValues[i] * 2),512(uint16_t)(pPcdacValues[i + 1] * 2)) + 1);513514HALASSERT(pcdacTableIndex < PWR_TABLE_SIZE);515ahp->ah_pcdacTable[pcdacTableIndex] = scaledPcdac / 2;516if (ahp->ah_pcdacTable[pcdacTableIndex] > pcdacMax)517ahp->ah_pcdacTable[pcdacTableIndex] = pcdacMax;518pcdacTableIndex++;519}520521/* Write all the last pcdac entries based off the last valid pcdac */522while (pcdacTableIndex < PWR_TABLE_SIZE) {523ahp->ah_pcdacTable[pcdacTableIndex] =524ahp->ah_pcdacTable[pcdacTableIndex - 1];525pcdacTableIndex++;526}527528/* No power table adjustment for 5111 */529ahp->ah_txPowerIndexOffset = 0;530531return AH_TRUE;532}533534/*535* Get or interpolate the pcdac value from the calibrated data.536*/537static uint16_t538ar5212GetScaledPower(uint16_t channel, uint16_t pcdacValue,539const PCDACS_EEPROM *pSrcStruct)540{541uint16_t powerValue;542uint16_t lFreq, rFreq; /* left and right frequency values */543uint16_t llPcdac, ulPcdac; /* lower and upper left pcdac values */544uint16_t lrPcdac, urPcdac; /* lower and upper right pcdac values */545uint16_t lPwr, uPwr; /* lower and upper temp pwr values */546uint16_t lScaledPwr, rScaledPwr; /* left and right scaled power */547548if (ar5212FindValueInList(channel, pcdacValue, pSrcStruct, &powerValue)) {549/* value was copied from srcStruct */550return powerValue;551}552553ar5212GetLowerUpperValues(channel,554pSrcStruct->pChannelList, pSrcStruct->numChannels,555&lFreq, &rFreq);556ar5212GetLowerUpperPcdacs(pcdacValue,557lFreq, pSrcStruct, &llPcdac, &ulPcdac);558ar5212GetLowerUpperPcdacs(pcdacValue,559rFreq, pSrcStruct, &lrPcdac, &urPcdac);560561/* get the power index for the pcdac value */562ar5212FindValueInList(lFreq, llPcdac, pSrcStruct, &lPwr);563ar5212FindValueInList(lFreq, ulPcdac, pSrcStruct, &uPwr);564lScaledPwr = interpolate(pcdacValue, llPcdac, ulPcdac, lPwr, uPwr);565566ar5212FindValueInList(rFreq, lrPcdac, pSrcStruct, &lPwr);567ar5212FindValueInList(rFreq, urPcdac, pSrcStruct, &uPwr);568rScaledPwr = interpolate(pcdacValue, lrPcdac, urPcdac, lPwr, uPwr);569570return interpolate(channel, lFreq, rFreq, lScaledPwr, rScaledPwr);571}572573/*574* Find the value from the calibrated source data struct575*/576static HAL_BOOL577ar5212FindValueInList(uint16_t channel, uint16_t pcdacValue,578const PCDACS_EEPROM *pSrcStruct, uint16_t *powerValue)579{580const DATA_PER_CHANNEL *pChannelData = pSrcStruct->pDataPerChannel;581int i;582583for (i = 0; i < pSrcStruct->numChannels; i++ ) {584if (pChannelData->channelValue == channel) {585const uint16_t* pPcdac = pChannelData->PcdacValues;586int j;587588for (j = 0; j < pChannelData->numPcdacValues; j++ ) {589if (*pPcdac == pcdacValue) {590*powerValue = pChannelData->PwrValues[j];591return AH_TRUE;592}593pPcdac++;594}595}596pChannelData++;597}598return AH_FALSE;599}600601/*602* Get the upper and lower pcdac given the channel and the pcdac603* used in the search604*/605static void606ar5212GetLowerUpperPcdacs(uint16_t pcdac, uint16_t channel,607const PCDACS_EEPROM *pSrcStruct,608uint16_t *pLowerPcdac, uint16_t *pUpperPcdac)609{610const DATA_PER_CHANNEL *pChannelData = pSrcStruct->pDataPerChannel;611int i;612613/* Find the channel information */614for (i = 0; i < pSrcStruct->numChannels; i++) {615if (pChannelData->channelValue == channel)616break;617pChannelData++;618}619ar5212GetLowerUpperValues(pcdac, pChannelData->PcdacValues,620pChannelData->numPcdacValues,621pLowerPcdac, pUpperPcdac);622}623624static HAL_BOOL625ar5111GetChannelMaxMinPower(struct ath_hal *ah,626const struct ieee80211_channel *chan,627int16_t *maxPow, int16_t *minPow)628{629/* XXX - Get 5111 power limits! */630/* NB: caller will cope */631return AH_FALSE;632}633634/*635* Adjust NF based on statistical values for 5GHz frequencies.636*/637static int16_t638ar5111GetNfAdjust(struct ath_hal *ah, const HAL_CHANNEL_INTERNAL *c)639{640static const struct {641uint16_t freqLow;642int16_t adjust;643} adjust5111[] = {644{ 5790, 6 }, /* NB: ordered high -> low */645{ 5730, 4 },646{ 5690, 3 },647{ 5660, 2 },648{ 5610, 1 },649{ 5530, 0 },650{ 5450, 0 },651{ 5379, 1 },652{ 5209, 3 },653{ 3000, 5 },654{ 0, 0 },655};656int i;657658for (i = 0; c->channel <= adjust5111[i].freqLow; i++)659;660return adjust5111[i].adjust;661}662663/*664* Free memory for analog bank scratch buffers665*/666static void667ar5111RfDetach(struct ath_hal *ah)668{669struct ath_hal_5212 *ahp = AH5212(ah);670671HALASSERT(ahp->ah_rfHal != AH_NULL);672ath_hal_free(ahp->ah_rfHal);673ahp->ah_rfHal = AH_NULL;674}675676/*677* Allocate memory for analog bank scratch buffers678* Scratch Buffer will be reinitialized every reset so no need to zero now679*/680static HAL_BOOL681ar5111RfAttach(struct ath_hal *ah, HAL_STATUS *status)682{683struct ath_hal_5212 *ahp = AH5212(ah);684struct ar5111State *priv;685686HALASSERT(ah->ah_magic == AR5212_MAGIC);687688HALASSERT(ahp->ah_rfHal == AH_NULL);689priv = ath_hal_malloc(sizeof(struct ar5111State));690if (priv == AH_NULL) {691HALDEBUG(ah, HAL_DEBUG_ANY,692"%s: cannot allocate private state\n", __func__);693*status = HAL_ENOMEM; /* XXX */694return AH_FALSE;695}696priv->base.rfDetach = ar5111RfDetach;697priv->base.writeRegs = ar5111WriteRegs;698priv->base.getRfBank = ar5111GetRfBank;699priv->base.setChannel = ar5111SetChannel;700priv->base.setRfRegs = ar5111SetRfRegs;701priv->base.setPowerTable = ar5111SetPowerTable;702priv->base.getChannelMaxMinPower = ar5111GetChannelMaxMinPower;703priv->base.getNfAdjust = ar5111GetNfAdjust;704705ahp->ah_pcdacTable = priv->pcdacTable;706ahp->ah_pcdacTableSize = sizeof(priv->pcdacTable);707ahp->ah_rfHal = &priv->base;708709return AH_TRUE;710}711712static HAL_BOOL713ar5111Probe(struct ath_hal *ah)714{715return IS_RAD5111(ah);716}717AH_RF(RF5111, ar5111Probe, ar5111RfAttach);718719720