33#include "ar5212/ar5212.ini"
35#define N(a) (sizeof(a)/sizeof(a[0]))
47#define AR5112(ah) ((struct ar5112State *) AH5212(ah)->ah_rfHal)
50 uint16_t *lp, uint16_t listSize,
51 uint32_t *vlo, uint32_t *vhi);
53 int16_t *power, int16_t maxPower, int16_t *retVals);
57 int16_t *pwrTableHXpdT4, uint16_t retVals[], int16_t *pMid);
59 uint16_t srcLeft, uint16_t srcRight,
60 int16_t targetLeft, int16_t targetRight);
63 uint32_t numBits, uint32_t firstBit, uint32_t column);
83 uint32_t channelSel = 0;
84 uint32_t bModeSynth = 0;
85 uint32_t aModeRefSel = 0;
93 if (((freq - 2192) % 5) == 0) {
94 channelSel = ((freq - 672) * 2 - 3040)/10;
96 }
else if (((freq - 2224) % 5) == 0) {
97 channelSel = ((freq - 704) * 2 - 3040) / 10;
101 "%s: invalid channel %u MHz\n",
106 channelSel = (channelSel << 2) & 0xff;
118 }
else if (((freq % 5) == 2) && (freq <= 5435)) {
121 (uint32_t)(((freq - 4800)*10)/25 + 1), 8);
123 }
else if ((freq % 20) == 0 && freq >= 5120) {
125 ((freq - 4800) / 20 << 2), 8);
127 }
else if ((freq % 10) == 0) {
129 ((freq - 4800) / 10 << 1), 8);
131 }
else if ((freq % 5) == 0) {
133 (freq - 4800) / 5, 8);
141 reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) |
181 const struct ieee80211_channel *chan,
182 uint16_t modesIndex, uint16_t *rfXpdGain)
184#define RF_BANK_SETUP(_priv, _ix, _col) do { \
186 for (i = 0; i < N(ar5212Bank##_ix##_5112); i++) \
187 (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_5112[i][_col];\
192 uint16_t rfXpdSel, gainI;
193 uint16_t ob5GHz = 0, db5GHz = 0;
194 uint16_t ob2GHz = 0, db2GHz = 0;
202 __func__, chan->ic_freq, chan->ic_flags, modesIndex);
206 case IEEE80211_CHAN_A:
207 if (freq > 4000 && freq < 5260) {
210 }
else if (freq >= 5260 && freq < 5500) {
213 }
else if (freq >= 5500 && freq < 5725) {
216 }
else if (freq >= 5725) {
225 case IEEE80211_CHAN_B:
231 case IEEE80211_CHAN_G:
232 case IEEE80211_CHAN_PUREG:
240 __func__, chan->ic_flags);
261 if (IEEE80211_IS_CHAN_OFDM(chan)) {
277 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
305 if (IEEE80211_IS_CHAN_OFDM(chan))
312 if (IEEE80211_IS_CHAN_HALF(chan) || IEEE80211_IS_CHAN_QUARTER(chan)) {
313 uint32_t rfDelay, rfPeriod;
316 rfPeriod = (IEEE80211_IS_CHAN_HALF(chan)) ? 0x8 : 0xf;
323 if (ar5212IsEarEngaged(pDev, chan))
325 ar5212EarModify(pDev, EAR_LC_RF_WRITE, chan, &modifier);
347 int16_t *pPowerMin, int16_t *pPowerMax,
348 const struct ieee80211_channel *chan,
355 uint32_t xpdGainMask = 0;
356 int16_t powerMid, *pPowerMid = &powerMid;
362 int16_t minPwr_t4, maxPwr_t4, Pmin, Pmid;
364 uint32_t chan_idx_L = 0, chan_idx_R = 0;
365 uint16_t chan_L, chan_R;
367 int16_t pwr_table0[64];
368 int16_t pwr_table1[64];
372 int16_t powTableLXPD[2][64];
373 int16_t powTableHXPD[2][64];
374 int16_t tmpPowerTable[64];
375 uint16_t xgainList[2];
379 case IEEE80211_CHAN_A:
380 case IEEE80211_CHAN_ST:
384 case IEEE80211_CHAN_B:
388 case IEEE80211_CHAN_G:
389 case IEEE80211_CHAN_108G:
395 __func__, chan->ic_flags);
399 if ((xpdGainMask & pPowerExpn->
xpdMask) < 1) {
401 "%s: desired xpdGainMask 0x%x not supported by "
402 "calibrated xpdMask 0x%x\n", __func__,
403 xpdGainMask, pPowerExpn->
xpdMask);
407 maxPwr_t4 = (int16_t)(2*(*pPowerMax));
408 minPwr_t4 = (int16_t)(2*(*pPowerMin));
410 xgainList[0] = 0xDEAD;
411 xgainList[1] = 0xDEAD;
416 if (((xpdMask >> jj) & 1) > 0) {
419 "A maximum of 2 xpdGains supported"
420 "in pExpnPower data\n");
423 xgainList[kk++] = (uint16_t)jj;
428 pPowerExpn->
numChannels, &chan_idx_L, &chan_idx_R);
431 for (ii = chan_idx_L; ii <= chan_idx_R; ii++) {
433 if (xgainList[1] == 0xDEAD) {
437 numPcd *
sizeof(uint16_t));
439 numPcd *
sizeof(int16_t));
444 OS_MEMCPY(&powTableLXPD[kk][0], &tmpPowerTable[0],
450 numPcd*
sizeof(uint16_t));
453 numPcd*
sizeof(int16_t));
458 OS_MEMCPY(&powTableLXPD[kk][0], &tmpPowerTable[0],
459 64 *
sizeof(int16_t));
464 numPcd *
sizeof(uint16_t));
467 numPcd *
sizeof(int16_t));
472 OS_MEMCPY(&powTableHXPD[kk][0], &tmpPowerTable[0],
473 64 *
sizeof(int16_t));
478 chan_L = pPowerExpn->
pChannels[chan_idx_L];
479 chan_R = pPowerExpn->
pChannels[chan_idx_R];
480 kk = chan_idx_R - chan_idx_L;
482 if (xgainList[1] == 0xDEAD) {
483 for (jj = 0; jj < 64; jj++) {
485 freq, chan_L, chan_R,
486 powTableLXPD[0][jj], powTableLXPD[kk][jj]);
490 *pPowerMin = (int16_t) (Pmin / 2);
491 *pPowerMid = (int16_t) (pwr_table0[63] / 2);
492 *pPowerMax = (int16_t) (pwr_table0[63] / 2);
493 rfXpdGain[0] = xgainList[0];
494 rfXpdGain[1] = rfXpdGain[0];
496 for (jj = 0; jj < 64; jj++) {
498 freq, chan_L, chan_R,
499 powTableLXPD[0][jj], powTableLXPD[kk][jj]);
501 freq, chan_L, chan_R,
502 powTableHXPD[0][jj], powTableHXPD[kk][jj]);
504 if (numXpdGain == 2) {
506 &pwr_table0[0], &pwr_table1[0],
508 *pPowerMin = (int16_t) (Pmin / 2);
509 *pPowerMid = (int16_t) (Pmid / 2);
510 *pPowerMax = (int16_t) (pwr_table0[63] / 2);
511 rfXpdGain[0] = xgainList[0];
512 rfXpdGain[1] = xgainList[1];
513 }
else if (minPwr_t4 <= pwr_table1[63] &&
514 maxPwr_t4 <= pwr_table1[63]) {
517 rfXpdGain[0] = xgainList[1];
518 rfXpdGain[1] = rfXpdGain[0];
519 *pPowerMin = (int16_t) (Pmin / 2);
520 *pPowerMid = (int16_t) (pwr_table1[63] / 2);
521 *pPowerMax = (int16_t) (pwr_table1[63] / 2);
525 rfXpdGain[0] = xgainList[0];
526 rfXpdGain[1] = rfXpdGain[0];
527 *pPowerMin = (int16_t) (Pmin/2);
528 *pPowerMid = (int16_t) (pwr_table0[63] / 2);
529 *pPowerMax = (int16_t) (pwr_table0[63] / 2);
548 int16_t targetLeft, int16_t targetRight)
552 if (srcRight != srcLeft) {
553 rv = ((target - srcLeft)*targetRight +
554 (srcRight - target)*targetLeft) / (srcRight - srcLeft);
568 uint32_t *vlo, uint32_t *vhi)
571 uint16_t *ep = lp+listSize;
577 if (target < lp[0]) {
581 if (target >= ep[-1]) {
582 *vlo = *vhi = listSize - 1;
587 for (tp = lp; tp < ep; tp++) {
593 *vlo = *vhi = tp - lp;
600 if (target < tp[1]) {
609getFullPwrTable(uint16_t numPcdacs, uint16_t *pcdacs, int16_t *power, int16_t maxPower, int16_t *retVals)
617 "%s: at least 2 pcdac values needed [%d]\n",
618 __func__, numPcdacs);
621 for (ii = 0; ii < 64; ii++) {
622 if (ii>pcdacs[idxR] && idxR < numPcdacs-1) {
627 pcdacs[idxL], pcdacs[idxR], power[idxL], power[idxR]);
628 if (retVals[ii] >= maxPower) {
630 retVals[ii++] = maxPower;
646 int16_t ii, jj, jjMax;
647 int16_t pMin, currPower, pMax;
650 if ((pwrTableT4[63] - pwrTableT4[0]) > 126) {
651 pMin = pwrTableT4[63] - 126;
653 pMin = pwrTableT4[0];
656 pMax = pwrTableT4[63];
660 while ((pwrTableT4[jjMax] > (pMax - 1) ) && (jjMax >= 0)) {
666 for (ii = 63; ii >= 0; ii--) {
667 while ((jj < 64) && (jj > 0) && (pwrTableT4[jj] >= currPower)) {
672 retVals[ii] = retVals[ii + 1];
692 int16_t *pwrTableHXpdT4, uint16_t retVals[], int16_t *pMid)
694 int16_t ii, jj, jjMax;
695 int16_t pMin, pMax, currPower;
697 uint16_t msbFlag = 0x40;
700 if ((pwrTableLXpdT4[63] - pwrTableHXpdT4[0]) > 126) {
701 pMin = pwrTableLXpdT4[63] - 126;
703 pMin = pwrTableHXpdT4[0];
706 pMax = pwrTableLXpdT4[63];
709 while ((pwrTableLXpdT4[jjMax] > (pMax - 1) ) && (jjMax >= 0)){
713 *pMid = pwrTableHXpdT4[63];
717 pwrTableT4 = &(pwrTableLXpdT4[0]);
719 if ((currPower <= *pMid) || ( (jj == 0) && (msbFlag == 0x40))){
721 pwrTableT4 = &(pwrTableHXpdT4[0]);
724 while ((jj > 0) && (pwrTableT4[jj] >= currPower)) {
727 if ((jj == 0) && (msbFlag == 0x00)) {
729 retVals[ii] = retVals[ii+1];
734 retVals[ii] = jj | msbFlag;
745 int16_t minGain,minPwr,minPcdac,retVal;
763 retVal = minPwr - (minPcdac*2);
769 const struct ieee80211_channel *chan,
770 int16_t *maxPow, int16_t *minPow)
772 uint16_t freq = chan->ic_freq;
774 int numChannels=0,i,last;
775 int totalD, totalF,totalMin;
780 if (IEEE80211_IS_CHAN_A(chan)) {
781 powerArray = ee->ee_modePowerArray5112;
784 }
else if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan)) {
786 powerArray = ee->ee_modePowerArray5112;
789 }
else if (IEEE80211_IS_CHAN_B(chan)) {
790 powerArray = ee->ee_modePowerArray5112;
802 if ((freq < data[0].channelValue) ||
803 (freq > data[numChannels-1].channelValue)) {
804 if (freq < data[0].channelValue) {
817 (i<numChannels) && (freq > data[i].channelValue);
822 *maxPow = (int8_t) ((totalF*(freq-data[last].channelValue) + data[last].
maxPower_t4*totalD)/totalD);
825 *minPow = (int8_t) ((totalMin*(freq-data[last].channelValue) +
ar5112GetMinPower(ah, &data[last])*totalD)/totalD);
828 if (freq == data[i].channelValue) {
866 "%s: cannot allocate private state\n", __func__);
uint32_t ath_hal_reverseBits(uint32_t val, uint32_t n)
#define NUM_XPD_PER_CHANNEL
#define HAL_INI_WRITE_BANK(ah, regArray, bankData, regWr)
#define IEEE80211_CHAN_ALLTURBOFULL
#define HAL_INI_WRITE_ARRAY(ah, regArray, col, regWr)
void * ath_hal_malloc(size_t)
static OS_INLINE uint16_t ath_hal_gethwchannel(struct ath_hal *ah, const struct ieee80211_channel *c)
#define IEEE80211_CHAN_ALLFULL
#define HALDEBUG(_ah, __m,...)
void ath_hal_free(void *p)
#define OS_REG_WRITE(_ah, _reg, _val)
#define OS_MARK(_ah, _id, _v)
#define OS_MEMCPY(_d, _s, _n)
#define OS_REG_READ(_ah, _reg)
AH_RF(RF5112, ar5112Probe, ar5112RfAttach)
static HAL_BOOL ar5112RfAttach(struct ath_hal *ah, HAL_STATUS *status)
static HAL_BOOL ar5112Probe(struct ath_hal *ah)
void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32, uint32_t numBits, uint32_t firstBit, uint32_t column)
static HAL_BOOL ar5112SetPowerTable(struct ath_hal *ah, int16_t *pPowerMin, int16_t *pPowerMax, const struct ieee80211_channel *chan, uint16_t *rfXpdGain)
static HAL_BOOL ar5112GetChannelMaxMinPower(struct ath_hal *ah, const struct ieee80211_channel *chan, int16_t *maxPow, int16_t *minPow)
static int16_t ar5112GetMinPower(struct ath_hal *ah, const EXPN_DATA_PER_CHANNEL_5112 *data)
static int16_t getPminAndPcdacTableFromPowerTable(int16_t *pwrTableT4, uint16_t retVals[])
static void ar5112RfDetach(struct ath_hal *ah)
static void ar5112WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex, int writes)
static void ar5212GetLowerUpperIndex(uint16_t v, uint16_t *lp, uint16_t listSize, uint32_t *vlo, uint32_t *vhi)
#define RF_BANK_SETUP(_priv, _ix, _col)
static uint32_t * ar5112GetRfBank(struct ath_hal *ah, int bank)
static int16_t getPminAndPcdacTableFromTwoPowerTables(int16_t *pwrTableLXpdT4, int16_t *pwrTableHXpdT4, uint16_t retVals[], int16_t *pMid)
static HAL_BOOL ar5112SetChannel(struct ath_hal *ah, const struct ieee80211_channel *chan)
static HAL_BOOL getFullPwrTable(uint16_t numPcdacs, uint16_t *pcdacs, int16_t *power, int16_t maxPower, int16_t *retVals)
static int16_t interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight, int16_t targetLeft, int16_t targetRight)
static HAL_BOOL ar5112SetRfRegs(struct ath_hal *ah, const struct ieee80211_channel *chan, uint16_t modesIndex, uint16_t *rfXpdGain)
int16_t ar5212GetNfAdjust(struct ath_hal *, const HAL_CHANNEL_INTERNAL *)
#define IS_RADX112_REV2(ah)
#define AR_PHY_CCK_TX_CTRL_JAPAN
#define AR_PHY_CHIP_ID_REV_2
#define AR_PHY_CCK_TX_CTRL
EXPN_DATA_PER_CHANNEL_5112 * pDataPerChannel
EXPN_DATA_PER_XPD_5112 pDataPerXPD[NUM_XPD_PER_CHANNEL]
int16_t pwr_t4[NUM_POINTS_XPD0]
uint16_t pcdac[NUM_POINTS_XPD0]
const GAIN_OPTIMIZATION_STEP * currStep
HAL_BOOL(* getChannelMaxMinPower)(struct ath_hal *ah, const struct ieee80211_channel *, int16_t *maxPow, int16_t *minPow)
HAL_BOOL(* setRfRegs)(struct ath_hal *, const struct ieee80211_channel *, uint16_t modesIndex, uint16_t *rfXpdGain)
HAL_BOOL(* setPowerTable)(struct ath_hal *ah, int16_t *minPower, int16_t *maxPower, const struct ieee80211_channel *, uint16_t *rfXpdGain)
HAL_BOOL(* setChannel)(struct ath_hal *, const struct ieee80211_channel *)
uint32_t *(* getRfBank)(struct ath_hal *ah, int bank)
void(* writeRegs)(struct ath_hal *, u_int modeIndex, u_int freqIndex, int regWrites)
int16_t(* getNfAdjust)(struct ath_hal *, const HAL_CHANNEL_INTERNAL *)
void(* rfDetach)(struct ath_hal *ah)
uint32_t Bank7Data[N(ar5212Bank7_5112)]
uint32_t Bank6Data[N(ar5212Bank6_5112)]
uint16_t pcdacTable[PWR_TABLE_SIZE]
uint32_t Bank2Data[N(ar5212Bank2_5112)]
uint32_t Bank1Data[N(ar5212Bank1_5112)]
uint32_t Bank3Data[N(ar5212Bank3_5112)]
GAIN_VALUES ah_gainValues
int16_t ah_txPowerIndexOffset
HAL_RFGAIN ah_rfgainState