Path: blob/main/sys/dev/ath/ath_hal/ar5212/ar2425.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 "ar5212/ar5212.h"24#include "ar5212/ar5212reg.h"25#include "ar5212/ar5212phy.h"2627#include "ah_eeprom_v3.h"2829#define AH_5212_242530#define AH_5212_241731#include "ar5212/ar5212.ini"3233#define N(a) (sizeof(a)/sizeof(a[0]))3435struct ar2425State {36RF_HAL_FUNCS base; /* public state, must be first */37uint16_t pcdacTable[PWR_TABLE_SIZE_2413];3839uint32_t Bank1Data[N(ar5212Bank1_2425)];40uint32_t Bank2Data[N(ar5212Bank2_2425)];41uint32_t Bank3Data[N(ar5212Bank3_2425)];42uint32_t Bank6Data[N(ar5212Bank6_2425)]; /* 2417 is same size */43uint32_t Bank7Data[N(ar5212Bank7_2425)];44};45#define AR2425(ah) ((struct ar2425State *) AH5212(ah)->ah_rfHal)4647extern void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32,48uint32_t numBits, uint32_t firstBit, uint32_t column);4950static void51ar2425WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex,52int writes)53{54HAL_INI_WRITE_ARRAY(ah, ar5212Modes_2425, modesIndex, writes);55HAL_INI_WRITE_ARRAY(ah, ar5212Common_2425, 1, writes);56HAL_INI_WRITE_ARRAY(ah, ar5212BB_RfGain_2425, freqIndex, writes);57#if 058/*59* for SWAN similar to Condor60* Bit 0 enables link to go to L1 when MAC goes to sleep.61* Bit 3 enables the loop back the link down to reset.62*/63if (AH_PRIVATE(ah)->ah_ispcie && && ath_hal_pcieL1SKPEnable) {64OS_REG_WRITE(ah, AR_PCIE_PMC,65AR_PCIE_PMC_ENA_L1 | AR_PCIE_PMC_ENA_RESET);66}67/*68* for Standby issue in Swan/Condor.69* Bit 9 (MAC_WOW_PWR_STATE_MASK_D2)to be set to avoid skips70* before last Training Sequence 2 (TS2)71* Bit 8 (MAC_WOW_PWR_STATE_MASK_D1)to be unset to assert72* Power Reset along with PCI Reset73*/74OS_REG_SET_BIT(ah, AR_PCIE_PMC, MAC_WOW_PWR_STATE_MASK_D2);75#endif76}7778/*79* Take the MHz channel value and set the Channel value80*81* ASSUMES: Writes enabled to analog bus82*/83static HAL_BOOL84ar2425SetChannel(struct ath_hal *ah, const struct ieee80211_channel *chan)85{86uint16_t freq = ath_hal_gethwchannel(ah, chan);87uint32_t channelSel = 0;88uint32_t bModeSynth = 0;89uint32_t aModeRefSel = 0;90uint32_t reg32 = 0;9192OS_MARK(ah, AH_MARK_SETCHANNEL, freq);9394if (freq < 4800) {95uint32_t txctl;9697channelSel = freq - 2272;98channelSel = ath_hal_reverseBits(channelSel, 8);99100txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL);101if (freq == 2484) {102// Enable channel spreading for channel 14103OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,104txctl | AR_PHY_CCK_TX_CTRL_JAPAN);105} else {106OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,107txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);108}109110} else if (((freq % 5) == 2) && (freq <= 5435)) {111freq = freq - 2; /* Align to even 5MHz raster */112channelSel = ath_hal_reverseBits(113(uint32_t)(((freq - 4800)*10)/25 + 1), 8);114aModeRefSel = ath_hal_reverseBits(0, 2);115} else if ((freq % 20) == 0 && freq >= 5120) {116channelSel = ath_hal_reverseBits(117((freq - 4800) / 20 << 2), 8);118aModeRefSel = ath_hal_reverseBits(1, 2);119} else if ((freq % 10) == 0) {120channelSel = ath_hal_reverseBits(121((freq - 4800) / 10 << 1), 8);122aModeRefSel = ath_hal_reverseBits(1, 2);123} else if ((freq % 5) == 0) {124channelSel = ath_hal_reverseBits(125(freq - 4800) / 5, 8);126aModeRefSel = ath_hal_reverseBits(1, 2);127} else {128HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel %u MHz\n",129__func__, freq);130return AH_FALSE;131}132133reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) |134(1 << 12) | 0x1;135OS_REG_WRITE(ah, AR_PHY(0x27), reg32 & 0xff);136137reg32 >>= 8;138OS_REG_WRITE(ah, AR_PHY(0x36), reg32 & 0x7f);139140AH_PRIVATE(ah)->ah_curchan = chan;141return AH_TRUE;142}143144/*145* Reads EEPROM header info from device structure and programs146* all rf registers147*148* REQUIRES: Access to the analog rf device149*/150static HAL_BOOL151ar2425SetRfRegs(struct ath_hal *ah,152const struct ieee80211_channel *chan,153uint16_t modesIndex, uint16_t *rfXpdGain)154{155#define RF_BANK_SETUP(_priv, _ix, _col) do { \156int i; \157for (i = 0; i < N(ar5212Bank##_ix##_2425); i++) \158(_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_2425[i][_col];\159} while (0)160struct ath_hal_5212 *ahp = AH5212(ah);161const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;162struct ar2425State *priv = AR2425(ah);163uint16_t ob2GHz = 0, db2GHz = 0;164int regWrites = 0;165166HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan %u/0x%x modesIndex %u\n",167__func__, chan->ic_freq, chan->ic_flags, modesIndex);168169HALASSERT(priv);170171/* Setup rf parameters */172if (IEEE80211_IS_CHAN_B(chan)) {173ob2GHz = ee->ee_obFor24;174db2GHz = ee->ee_dbFor24;175} else {176ob2GHz = ee->ee_obFor24g;177db2GHz = ee->ee_dbFor24g;178}179180/* Bank 1 Write */181RF_BANK_SETUP(priv, 1, 1);182183/* Bank 2 Write */184RF_BANK_SETUP(priv, 2, modesIndex);185186/* Bank 3 Write */187RF_BANK_SETUP(priv, 3, modesIndex);188189/* Bank 6 Write */190RF_BANK_SETUP(priv, 6, modesIndex);191192ar5212ModifyRfBuffer(priv->Bank6Data, ob2GHz, 3, 193, 0);193ar5212ModifyRfBuffer(priv->Bank6Data, db2GHz, 3, 190, 0);194195/* Bank 7 Setup */196RF_BANK_SETUP(priv, 7, modesIndex);197198/* Write Analog registers */199HAL_INI_WRITE_BANK(ah, ar5212Bank1_2425, priv->Bank1Data, regWrites);200HAL_INI_WRITE_BANK(ah, ar5212Bank2_2425, priv->Bank2Data, regWrites);201HAL_INI_WRITE_BANK(ah, ar5212Bank3_2425, priv->Bank3Data, regWrites);202if (IS_2417(ah)) {203HALASSERT(N(ar5212Bank6_2425) == N(ar5212Bank6_2417));204HAL_INI_WRITE_BANK(ah, ar5212Bank6_2417, priv->Bank6Data,205regWrites);206} else207HAL_INI_WRITE_BANK(ah, ar5212Bank6_2425, priv->Bank6Data,208regWrites);209HAL_INI_WRITE_BANK(ah, ar5212Bank7_2425, priv->Bank7Data, regWrites);210211/* Now that we have reprogrammed rfgain value, clear the flag. */212ahp->ah_rfgainState = HAL_RFGAIN_INACTIVE;213214HALDEBUG(ah, HAL_DEBUG_RFPARAM, "<==%s\n", __func__);215return AH_TRUE;216#undef RF_BANK_SETUP217}218219/*220* Return a reference to the requested RF Bank.221*/222static uint32_t *223ar2425GetRfBank(struct ath_hal *ah, int bank)224{225struct ar2425State *priv = AR2425(ah);226227HALASSERT(priv != AH_NULL);228switch (bank) {229case 1: return priv->Bank1Data;230case 2: return priv->Bank2Data;231case 3: return priv->Bank3Data;232case 6: return priv->Bank6Data;233case 7: return priv->Bank7Data;234}235HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown RF Bank %d requested\n",236__func__, bank);237return AH_NULL;238}239240/*241* Return indices surrounding the value in sorted integer lists.242*243* NB: the input list is assumed to be sorted in ascending order244*/245static void246GetLowerUpperIndex(int16_t v, const uint16_t *lp, uint16_t listSize,247uint32_t *vlo, uint32_t *vhi)248{249int16_t target = v;250const uint16_t *ep = lp+listSize;251const uint16_t *tp;252253/*254* Check first and last elements for out-of-bounds conditions.255*/256if (target < lp[0]) {257*vlo = *vhi = 0;258return;259}260if (target >= ep[-1]) {261*vlo = *vhi = listSize - 1;262return;263}264265/* look for value being near or between 2 values in list */266for (tp = lp; tp < ep; tp++) {267/*268* If value is close to the current value of the list269* then target is not between values, it is one of the values270*/271if (*tp == target) {272*vlo = *vhi = tp - (const uint16_t *) lp;273return;274}275/*276* Look for value being between current value and next value277* if so return these 2 values278*/279if (target < tp[1]) {280*vlo = tp - (const uint16_t *) lp;281*vhi = *vlo + 1;282return;283}284}285}286287/*288* Fill the Vpdlist for indices Pmax-Pmin289*/290static HAL_BOOL291ar2425FillVpdTable(uint32_t pdGainIdx, int16_t Pmin, int16_t Pmax,292const int16_t *pwrList, const uint16_t *VpdList,293uint16_t numIntercepts,294uint16_t retVpdList[][64])295{296uint16_t ii, jj, kk;297int16_t currPwr = (int16_t)(2*Pmin);298/* since Pmin is pwr*2 and pwrList is 4*pwr */299uint32_t idxL, idxR;300301ii = 0;302jj = 0;303304if (numIntercepts < 2)305return AH_FALSE;306307while (ii <= (uint16_t)(Pmax - Pmin)) {308GetLowerUpperIndex(currPwr, (const uint16_t *) pwrList,309numIntercepts, &(idxL), &(idxR));310if (idxR < 1)311idxR = 1; /* extrapolate below */312if (idxL == (uint32_t)(numIntercepts - 1))313idxL = numIntercepts - 2; /* extrapolate above */314if (pwrList[idxL] == pwrList[idxR])315kk = VpdList[idxL];316else317kk = (uint16_t)318(((currPwr - pwrList[idxL])*VpdList[idxR]+319(pwrList[idxR] - currPwr)*VpdList[idxL])/320(pwrList[idxR] - pwrList[idxL]));321retVpdList[pdGainIdx][ii] = kk;322ii++;323currPwr += 2; /* half dB steps */324}325326return AH_TRUE;327}328329/*330* Returns interpolated or the scaled up interpolated value331*/332static int16_t333interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight,334int16_t targetLeft, int16_t targetRight)335{336int16_t rv;337338if (srcRight != srcLeft) {339rv = ((target - srcLeft)*targetRight +340(srcRight - target)*targetLeft) / (srcRight - srcLeft);341} else {342rv = targetLeft;343}344return rv;345}346347/*348* Uses the data points read from EEPROM to reconstruct the pdadc power table349* Called by ar2425SetPowerTable()350*/351static void352ar2425getGainBoundariesAndPdadcsForPowers(struct ath_hal *ah, uint16_t channel,353const RAW_DATA_STRUCT_2413 *pRawDataset,354uint16_t pdGainOverlap_t2,355int16_t *pMinCalPower, uint16_t pPdGainBoundaries[],356uint16_t pPdGainValues[], uint16_t pPDADCValues[])357{358/* Note the items statically allocated below are to reduce stack usage */359uint32_t ii, jj, kk;360int32_t ss;/* potentially -ve index for taking care of pdGainOverlap */361uint32_t idxL, idxR;362uint32_t numPdGainsUsed = 0;363static uint16_t VpdTable_L[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB];364/* filled out Vpd table for all pdGains (chanL) */365static uint16_t VpdTable_R[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB];366/* filled out Vpd table for all pdGains (chanR) */367static uint16_t VpdTable_I[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB];368/* filled out Vpd table for all pdGains (interpolated) */369/*370* If desired to support -ve power levels in future, just371* change pwr_I_0 to signed 5-bits.372*/373static int16_t Pmin_t2[MAX_NUM_PDGAINS_PER_CHANNEL];374/* to accommodate -ve power levels later on. */375static int16_t Pmax_t2[MAX_NUM_PDGAINS_PER_CHANNEL];376/* to accommodate -ve power levels later on */377uint16_t numVpd = 0;378uint16_t Vpd_step;379int16_t tmpVal ;380uint32_t sizeCurrVpdTable, maxIndex, tgtIndex;381382HALDEBUG(ah, HAL_DEBUG_RFPARAM, "==>%s:\n", __func__);383384/* Get upper lower index */385GetLowerUpperIndex(channel, pRawDataset->pChannels,386pRawDataset->numChannels, &(idxL), &(idxR));387388for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {389jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;390/* work backwards 'cause highest pdGain for lowest power */391numVpd = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].numVpd;392if (numVpd > 0) {393pPdGainValues[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pd_gain;394Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0];395if (Pmin_t2[numPdGainsUsed] >pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]) {396Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0];397}398Pmin_t2[numPdGainsUsed] = (int16_t)399(Pmin_t2[numPdGainsUsed] / 2);400Pmax_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[numVpd-1];401if (Pmax_t2[numPdGainsUsed] > pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1])402Pmax_t2[numPdGainsUsed] =403pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1];404Pmax_t2[numPdGainsUsed] = (int16_t)(Pmax_t2[numPdGainsUsed] / 2);405ar2425FillVpdTable(406numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],407&(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0]),408&(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_L409);410ar2425FillVpdTable(411numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],412&(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]),413&(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_R414);415for (kk = 0; kk < (uint16_t)(Pmax_t2[numPdGainsUsed] - Pmin_t2[numPdGainsUsed]); kk++) {416VpdTable_I[numPdGainsUsed][kk] =417interpolate_signed(418channel, pRawDataset->pChannels[idxL], pRawDataset->pChannels[idxR],419(int16_t)VpdTable_L[numPdGainsUsed][kk], (int16_t)VpdTable_R[numPdGainsUsed][kk]);420}421/* fill VpdTable_I for this pdGain */422numPdGainsUsed++;423}424/* if this pdGain is used */425}426427*pMinCalPower = Pmin_t2[0];428kk = 0; /* index for the final table */429for (ii = 0; ii < numPdGainsUsed; ii++) {430if (ii == (numPdGainsUsed - 1))431pPdGainBoundaries[ii] = Pmax_t2[ii] +432PD_GAIN_BOUNDARY_STRETCH_IN_HALF_DB;433else434pPdGainBoundaries[ii] = (uint16_t)435((Pmax_t2[ii] + Pmin_t2[ii+1]) / 2 );436437/* Find starting index for this pdGain */438if (ii == 0)439ss = 0; /* for the first pdGain, start from index 0 */440else441ss = (pPdGainBoundaries[ii-1] - Pmin_t2[ii]) -442pdGainOverlap_t2;443Vpd_step = (uint16_t)(VpdTable_I[ii][1] - VpdTable_I[ii][0]);444Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);445/*446*-ve ss indicates need to extrapolate data below for this pdGain447*/448while (ss < 0) {449tmpVal = (int16_t)(VpdTable_I[ii][0] + ss*Vpd_step);450pPDADCValues[kk++] = (uint16_t)((tmpVal < 0) ? 0 : tmpVal);451ss++;452}453454sizeCurrVpdTable = Pmax_t2[ii] - Pmin_t2[ii];455tgtIndex = pPdGainBoundaries[ii] + pdGainOverlap_t2 - Pmin_t2[ii];456maxIndex = (tgtIndex < sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;457458while (ss < (int16_t)maxIndex)459pPDADCValues[kk++] = VpdTable_I[ii][ss++];460461Vpd_step = (uint16_t)(VpdTable_I[ii][sizeCurrVpdTable-1] -462VpdTable_I[ii][sizeCurrVpdTable-2]);463Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);464/*465* for last gain, pdGainBoundary == Pmax_t2, so will466* have to extrapolate467*/468if (tgtIndex > maxIndex) { /* need to extrapolate above */469while(ss < (int16_t)tgtIndex) {470tmpVal = (uint16_t)471(VpdTable_I[ii][sizeCurrVpdTable-1] +472(ss-maxIndex)*Vpd_step);473pPDADCValues[kk++] = (tmpVal > 127) ?474127 : tmpVal;475ss++;476}477} /* extrapolated above */478} /* for all pdGainUsed */479480while (ii < MAX_NUM_PDGAINS_PER_CHANNEL) {481pPdGainBoundaries[ii] = pPdGainBoundaries[ii-1];482ii++;483}484while (kk < 128) {485pPDADCValues[kk] = pPDADCValues[kk-1];486kk++;487}488489HALDEBUG(ah, HAL_DEBUG_RFPARAM, "<==%s\n", __func__);490}491492/* Same as 2413 set power table */493static HAL_BOOL494ar2425SetPowerTable(struct ath_hal *ah,495int16_t *minPower, int16_t *maxPower,496const struct ieee80211_channel *chan,497uint16_t *rfXpdGain)498{499uint16_t freq = ath_hal_gethwchannel(ah, chan);500struct ath_hal_5212 *ahp = AH5212(ah);501const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;502const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL;503uint16_t pdGainOverlap_t2;504int16_t minCalPower2413_t2;505uint16_t *pdadcValues = ahp->ah_pcdacTable;506uint16_t gainBoundaries[4];507uint32_t i, reg32, regoffset;508509HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s:chan 0x%x flag 0x%x\n",510__func__, freq, chan->ic_flags);511512if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))513pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];514else if (IEEE80211_IS_CHAN_B(chan))515pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];516else {517HALDEBUG(ah, HAL_DEBUG_ANY, "%s:illegal mode\n", __func__);518return AH_FALSE;519}520521pdGainOverlap_t2 = (uint16_t) SM(OS_REG_READ(ah, AR_PHY_TPCRG5),522AR_PHY_TPCRG5_PD_GAIN_OVERLAP);523524ar2425getGainBoundariesAndPdadcsForPowers(ah, freq,525pRawDataset, pdGainOverlap_t2,&minCalPower2413_t2,gainBoundaries,526rfXpdGain, pdadcValues);527528OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,529(pRawDataset->pDataPerChannel[0].numPdGains - 1));530531/*532* Note the pdadc table may not start at 0 dBm power, could be533* negative or greater than 0. Need to offset the power534* values by the amount of minPower for griffin535*/536if (minCalPower2413_t2 != 0)537ahp->ah_txPowerIndexOffset = (int16_t)(0 - minCalPower2413_t2);538else539ahp->ah_txPowerIndexOffset = 0;540541/* Finally, write the power values into the baseband power table */542regoffset = 0x9800 + (672 <<2); /* beginning of pdadc table in griffin */543for (i = 0; i < 32; i++) {544reg32 = ((pdadcValues[4*i + 0] & 0xFF) << 0) |545((pdadcValues[4*i + 1] & 0xFF) << 8) |546((pdadcValues[4*i + 2] & 0xFF) << 16) |547((pdadcValues[4*i + 3] & 0xFF) << 24) ;548OS_REG_WRITE(ah, regoffset, reg32);549regoffset += 4;550}551552OS_REG_WRITE(ah, AR_PHY_TPCRG5,553SM(pdGainOverlap_t2, AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |554SM(gainBoundaries[0], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |555SM(gainBoundaries[1], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |556SM(gainBoundaries[2], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |557SM(gainBoundaries[3], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));558559return AH_TRUE;560}561562static int16_t563ar2425GetMinPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)564{565uint32_t ii,jj;566uint16_t Pmin=0,numVpd;567568for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {569jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;570/* work backwards 'cause highest pdGain for lowest power */571numVpd = data->pDataPerPDGain[jj].numVpd;572if (numVpd > 0) {573Pmin = data->pDataPerPDGain[jj].pwr_t4[0];574return(Pmin);575}576}577return(Pmin);578}579580static int16_t581ar2425GetMaxPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)582{583uint32_t ii;584uint16_t Pmax=0,numVpd;585586for (ii=0; ii< MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {587/* work forwards cuase lowest pdGain for highest power */588numVpd = data->pDataPerPDGain[ii].numVpd;589if (numVpd > 0) {590Pmax = data->pDataPerPDGain[ii].pwr_t4[numVpd-1];591return(Pmax);592}593}594return(Pmax);595}596597static598HAL_BOOL599ar2425GetChannelMaxMinPower(struct ath_hal *ah,600const struct ieee80211_channel *chan,601int16_t *maxPow, int16_t *minPow)602{603uint16_t freq = chan->ic_freq; /* NB: never mapped */604const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;605const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL;606const RAW_DATA_PER_CHANNEL_2413 *data = AH_NULL;607uint16_t numChannels;608int totalD,totalF, totalMin,last, i;609610*maxPow = 0;611612if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))613pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];614else if (IEEE80211_IS_CHAN_B(chan))615pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];616else617return(AH_FALSE);618619numChannels = pRawDataset->numChannels;620data = pRawDataset->pDataPerChannel;621622/* Make sure the channel is in the range of the TP values623* (freq piers)624*/625if (numChannels < 1)626return(AH_FALSE);627628if ((freq < data[0].channelValue) ||629(freq > data[numChannels-1].channelValue)) {630if (freq < data[0].channelValue) {631*maxPow = ar2425GetMaxPower(ah, &data[0]);632*minPow = ar2425GetMinPower(ah, &data[0]);633return(AH_TRUE);634} else {635*maxPow = ar2425GetMaxPower(ah, &data[numChannels - 1]);636*minPow = ar2425GetMinPower(ah, &data[numChannels - 1]);637return(AH_TRUE);638}639}640641/* Linearly interpolate the power value now */642for (last=0,i=0; (i<numChannels) && (freq > data[i].channelValue);643last = i++);644totalD = data[i].channelValue - data[last].channelValue;645if (totalD > 0) {646totalF = ar2425GetMaxPower(ah, &data[i]) - ar2425GetMaxPower(ah, &data[last]);647*maxPow = (int8_t) ((totalF*(freq-data[last].channelValue) +648ar2425GetMaxPower(ah, &data[last])*totalD)/totalD);649totalMin = ar2425GetMinPower(ah, &data[i]) - ar2425GetMinPower(ah, &data[last]);650*minPow = (int8_t) ((totalMin*(freq-data[last].channelValue) +651ar2425GetMinPower(ah, &data[last])*totalD)/totalD);652return(AH_TRUE);653} else {654if (freq == data[i].channelValue) {655*maxPow = ar2425GetMaxPower(ah, &data[i]);656*minPow = ar2425GetMinPower(ah, &data[i]);657return(AH_TRUE);658} else659return(AH_FALSE);660}661}662663/*664* Free memory for analog bank scratch buffers665*/666static void667ar2425RfDetach(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_BOOL681ar2425RfAttach(struct ath_hal *ah, HAL_STATUS *status)682{683struct ath_hal_5212 *ahp = AH5212(ah);684struct ar2425State *priv;685686HALASSERT(ah->ah_magic == AR5212_MAGIC);687688HALASSERT(ahp->ah_rfHal == AH_NULL);689priv = ath_hal_malloc(sizeof(struct ar2425State));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 = ar2425RfDetach;697priv->base.writeRegs = ar2425WriteRegs;698priv->base.getRfBank = ar2425GetRfBank;699priv->base.setChannel = ar2425SetChannel;700priv->base.setRfRegs = ar2425SetRfRegs;701priv->base.setPowerTable = ar2425SetPowerTable;702priv->base.getChannelMaxMinPower = ar2425GetChannelMaxMinPower;703priv->base.getNfAdjust = ar5212GetNfAdjust;704705ahp->ah_pcdacTable = priv->pcdacTable;706ahp->ah_pcdacTableSize = sizeof(priv->pcdacTable);707ahp->ah_rfHal = &priv->base;708709return AH_TRUE;710}711712static HAL_BOOL713ar2425Probe(struct ath_hal *ah)714{715return IS_2425(ah) || IS_2417(ah);716}717AH_RF(RF2425, ar2425Probe, ar2425RfAttach);718719720