33#include "ar5212/ar5212.ini"
35#define N(a) (sizeof(a)/sizeof(a[0]))
39#define PWR_TABLE_SIZE_2316 PWR_TABLE_SIZE_2413
64#define AR2316(ah) ((struct ar2316State *) AH5212(ah)->ah_rfHal)
67 uint32_t numBits, uint32_t firstBit, uint32_t column);
96 uint32_t channelSel = 0;
97 uint32_t bModeSynth = 0;
98 uint32_t aModeRefSel = 0;
106 if (((freq - 2192) % 5) == 0) {
107 channelSel = ((freq - 672) * 2 - 3040)/10;
109 }
else if (((freq - 2224) % 5) == 0) {
110 channelSel = ((freq - 704) * 2 - 3040) / 10;
114 "%s: invalid channel %u MHz\n",
119 channelSel = (channelSel << 2) & 0xff;
131 }
else if ((freq % 20) == 0 && freq >= 5120) {
133 ((freq - 4800) / 20 << 2), 8);
135 }
else if ((freq % 10) == 0) {
137 ((freq - 4800) / 10 << 1), 8);
139 }
else if ((freq % 5) == 0) {
141 (freq - 4800) / 5, 8);
149 reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) |
168 uint16_t modesIndex, uint16_t *rfXpdGain)
170#define RF_BANK_SETUP(_priv, _ix, _col) do { \
172 for (i = 0; i < N(ar5212Bank##_ix##_2316); i++) \
173 (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_2316[i][_col];\
177 uint16_t ob2GHz = 0, db2GHz = 0;
182 __func__, chan->ic_freq, chan->ic_flags, modesIndex);
187 if (IEEE80211_IS_CHAN_B(chan)) {
255 uint32_t *vlo, uint32_t *vhi)
258 const int16_t *ep = lp+listSize;
264 if (target < lp[0]) {
268 if (target >= ep[-1]) {
269 *vlo = *vhi = listSize - 1;
274 for (tp = lp; tp < ep; tp++) {
280 *vlo = *vhi = tp - (
const int16_t *) lp;
287 if (target < tp[1]) {
288 *vlo = tp - (
const int16_t *) lp;
300 const int16_t *pwrList,
const int16_t *VpdList,
301 uint16_t numIntercepts, uint16_t retVpdList[][64])
304 int16_t currPwr = (int16_t)(2*Pmin);
311 if (numIntercepts < 2)
314 while (ii <= (uint16_t)(Pmax - Pmin)) {
319 if (idxL == (uint32_t)(numIntercepts - 1))
320 idxL = numIntercepts - 2;
321 if (pwrList[idxL] == pwrList[idxR])
325 (((currPwr - pwrList[idxL])*VpdList[idxR]+
326 (pwrList[idxR] - currPwr)*VpdList[idxL])/
327 (pwrList[idxR] - pwrList[idxL]));
328 retVpdList[pdGainIdx][ii] = kk;
341 int16_t targetLeft, int16_t targetRight)
345 if (srcRight != srcLeft) {
346 rv = ((target - srcLeft)*targetRight +
347 (srcRight - target)*targetLeft) / (srcRight - srcLeft);
361 uint16_t pdGainOverlap_t2,
362 int16_t *pMinCalPower, uint16_t pPdGainBoundaries[],
363 uint16_t pPdGainValues[], uint16_t pPDADCValues[])
366#define VpdTable_L priv->vpdTable_L
367#define VpdTable_R priv->vpdTable_R
368#define VpdTable_I priv->vpdTable_I
372 uint32_t numPdGainsUsed = 0;
384 uint32_t sizeCurrVpdTable, maxIndex, tgtIndex;
400 Pmin_t2[numPdGainsUsed] = (int16_t)
401 (Pmin_t2[numPdGainsUsed] / 2);
404 Pmax_t2[numPdGainsUsed] =
406 Pmax_t2[numPdGainsUsed] = (int16_t)(Pmax_t2[numPdGainsUsed] / 2);
408 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
413 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
417 for (kk = 0; kk < (uint16_t)(Pmax_t2[numPdGainsUsed] - Pmin_t2[numPdGainsUsed]); kk++) {
429 *pMinCalPower = Pmin_t2[0];
431 for (ii = 0; ii < numPdGainsUsed; ii++) {
432 if (ii == (numPdGainsUsed - 1))
433 pPdGainBoundaries[ii] = Pmax_t2[ii] +
436 pPdGainBoundaries[ii] = (uint16_t)
437 ((Pmax_t2[ii] + Pmin_t2[ii+1]) / 2 );
438 if (pPdGainBoundaries[ii] > 63) {
440 "%s: clamp pPdGainBoundaries[%d] %d\n",
441 __func__, ii, pPdGainBoundaries[ii]);
442 pPdGainBoundaries[ii] = 63;
449 ss = (pPdGainBoundaries[ii-1] - Pmin_t2[ii]) -
452 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
457 tmpVal = (int16_t)(
VpdTable_I[ii][0] + ss*Vpd_step);
458 pPDADCValues[kk++] = (uint16_t)((tmpVal < 0) ? 0 : tmpVal);
462 sizeCurrVpdTable = Pmax_t2[ii] - Pmin_t2[ii];
463 tgtIndex = pPdGainBoundaries[ii] + pdGainOverlap_t2 - Pmin_t2[ii];
464 maxIndex = (tgtIndex < sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;
466 while (ss < (int16_t)maxIndex)
469 Vpd_step = (uint16_t)(
VpdTable_I[ii][sizeCurrVpdTable-1] -
471 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
476 if (tgtIndex > maxIndex) {
477 while(ss < (int16_t)tgtIndex) {
480 (ss-maxIndex)*Vpd_step);
481 pPDADCValues[kk++] = (tmpVal > 127) ?
489 pPdGainBoundaries[ii] = pPdGainBoundaries[ii-1];
493 pPDADCValues[kk] = pPDADCValues[kk-1];
497 return numPdGainsUsed;
505 int16_t *minPower, int16_t *maxPower,
506 const struct ieee80211_channel *chan,
512 uint16_t pdGainOverlap_t2;
513 int16_t minCalPower2316_t2;
515 uint16_t gainBoundaries[4];
516 uint32_t reg32, regoffset;
517 int i, numPdGainsUsed;
518#ifndef AH_USE_INIPDGAIN
523 __func__, chan->ic_freq, chan->ic_flags);
525 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
527 else if (IEEE80211_IS_CHAN_B(chan))
538 chan->channel, pRawDataset, pdGainOverlap_t2,
539 &minCalPower2316_t2,gainBoundaries, rfXpdGain, pdadcValues);
540 HALASSERT(1 <= numPdGainsUsed && numPdGainsUsed <= 3);
542#ifdef AH_USE_INIPDGAIN
553 tpcrg1 = (tpcrg1 &~ AR_PHY_TPCRG1_NUM_PD_GAIN)
555 switch (numPdGainsUsed) {
557 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING3;
561 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING2;
565 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING1;
572 "pd_gains (default 0x%x, calculated 0x%x)\n",
583 if (minCalPower2316_t2 != 0)
589 regoffset = 0x9800 + (672 <<2);
590 for (i = 0; i < 32; i++) {
591 reg32 = ((pdadcValues[4*i + 0] & 0xFF) << 0) |
592 ((pdadcValues[4*i + 1] & 0xFF) << 8) |
593 ((pdadcValues[4*i + 2] & 0xFF) << 16) |
594 ((pdadcValues[4*i + 3] & 0xFF) << 24) ;
613 uint16_t Pmin=0,numVpd;
631 uint16_t Pmax=0,numVpd;
646 const struct ieee80211_channel *chan,
647 int16_t *maxPow, int16_t *minPow)
649 uint16_t freq = chan->ic_freq;
653 uint16_t numChannels;
654 int totalD,totalF, totalMin,last, i;
658 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
660 else if (IEEE80211_IS_CHAN_B(chan))
674 if ((freq < data[0].channelValue) ||
675 (freq > data[numChannels-1].channelValue)) {
676 if (freq < data[0].channelValue) {
688 for (last=0,i=0; (i<numChannels) && (freq > data[i].channelValue);
693 *maxPow = (int8_t) ((totalF*(freq-data[last].channelValue) +
696 *minPow = (int8_t) ((totalMin*(freq-data[last].channelValue) +
700 if (freq == data[i].channelValue) {
738 "%s: cannot allocate private state\n", __func__);
uint32_t ath_hal_reverseBits(uint32_t val, uint32_t n)
#define MAX_NUM_PDGAINS_PER_CHANNEL
#define PD_GAIN_BOUNDARY_STRETCH_IN_HALF_DB
#define MAX_PWR_RANGE_IN_HALF_DB
#define HAL_INI_WRITE_BANK(ah, regArray, bankData, regWr)
#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 OS_REG_RMW_FIELD(_a, _r, _f, _v)
#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_REG_READ(_ah, _reg)
static HAL_BOOL ar2316Probe(struct ath_hal *ah)
RAW_DATA_PER_CHANNEL_2413 RAW_DATA_PER_CHANNEL_2316
void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32, uint32_t numBits, uint32_t firstBit, uint32_t column)
static int16_t ar2316GetMinPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2316 *data)
#define PWR_TABLE_SIZE_2316
RAW_DATA_STRUCT_2413 RAW_DATA_STRUCT_2316
static HAL_BOOL ar2316GetChannelMaxMinPower(struct ath_hal *ah, const struct ieee80211_channel *chan, int16_t *maxPow, int16_t *minPow)
static HAL_BOOL ar2316SetChannel(struct ath_hal *ah, struct ieee80211_channel *chan)
static void ar2316RfDetach(struct ath_hal *ah)
static HAL_BOOL ar2316FillVpdTable(uint32_t pdGainIdx, int16_t Pmin, int16_t Pmax, const int16_t *pwrList, const int16_t *VpdList, uint16_t numIntercepts, uint16_t retVpdList[][64])
static HAL_BOOL ar2316SetPowerTable(struct ath_hal *ah, int16_t *minPower, int16_t *maxPower, const struct ieee80211_channel *chan, uint16_t *rfXpdGain)
static uint32_t * ar2316GetRfBank(struct ath_hal *ah, int bank)
static void ar2316WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex, int regWrites)
static void GetLowerUpperIndex(int16_t v, const uint16_t *lp, uint16_t listSize, uint32_t *vlo, uint32_t *vhi)
AH_RF(RF2316, ar2316Probe, ar2316RfAttach)
static HAL_BOOL ar2316RfAttach(struct ath_hal *ah, HAL_STATUS *status)
#define RF_BANK_SETUP(_priv, _ix, _col)
static HAL_BOOL ar2316SetRfRegs(struct ath_hal *ah, const struct ieee80211_channel *chan, uint16_t modesIndex, uint16_t *rfXpdGain)
static int16_t ar2316GetMaxPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2316 *data)
static int16_t interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight, int16_t targetLeft, int16_t targetRight)
static int ar2316getGainBoundariesAndPdadcsForPowers(struct ath_hal *ah, uint16_t channel, const RAW_DATA_STRUCT_2316 *pRawDataset, uint16_t pdGainOverlap_t2, int16_t *pMinCalPower, uint16_t pPdGainBoundaries[], uint16_t pPdGainValues[], uint16_t pPDADCValues[])
int16_t ar5212GetNfAdjust(struct ath_hal *, const HAL_CHANNEL_INTERNAL *)
#define AR_PHY_TPCRG1_PDGAIN_SETTING1
#define AR_PHY_CCK_TX_CTRL_JAPAN
#define AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4
#define AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2
#define AR_PHY_TPCRG1_PDGAIN_SETTING3
#define AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1
#define AR_PHY_TPCRG5_PD_GAIN_OVERLAP
#define AR_PHY_TPCRG1_PDGAIN_SETTING2
#define AR_PHY_TPCRG1_NUM_PD_GAIN
#define AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3
#define AR_PHY_CCK_TX_CTRL
RAW_DATA_PER_PDGAIN_2413 pDataPerPDGain[MAX_NUM_PDGAINS_PER_CHANNEL]
int16_t pwr_t4[NUM_POINTS_LAST_PDGAIN]
uint16_t Vpd[NUM_POINTS_LAST_PDGAIN]
uint16_t pChannels[NUM_11A_EEPROM_CHANNELS_2413]
RAW_DATA_PER_CHANNEL_2413 pDataPerChannel[NUM_11A_EEPROM_CHANNELS_2413]
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)
uint16_t pcdacTable[PWR_TABLE_SIZE_2316]
uint32_t Bank3Data[N(ar5212Bank3_2316)]
uint16_t vpdTable_I[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB]
uint32_t Bank6Data[N(ar5212Bank6_2316)]
uint16_t vpdTable_L[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB]
uint32_t Bank2Data[N(ar5212Bank2_2316)]
uint32_t Bank1Data[N(ar5212Bank1_2316)]
uint32_t Bank7Data[N(ar5212Bank7_2316)]
uint16_t vpdTable_R[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB]
int16_t ah_txPowerIndexOffset
HAL_RFGAIN ah_rfgainState