33#include "ar5212/ar5212.ini"
35#define N(a) (sizeof(a)/sizeof(a[0]))
60#define AR2413(ah) ((struct ar2413State *) AH5212(ah)->ah_rfHal)
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) |
161 const struct ieee80211_channel *chan,
162 uint16_t modesIndex, uint16_t *rfXpdGain)
164#define RF_BANK_SETUP(_priv, _ix, _col) do { \
166 for (i = 0; i < N(ar5212Bank##_ix##_2413); i++) \
167 (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_2413[i][_col];\
171 uint16_t ob2GHz = 0, db2GHz = 0;
176 __func__, chan->ic_freq, chan->ic_flags, modesIndex);
181 if (IEEE80211_IS_CHAN_B(chan)) {
249 uint32_t *vlo, uint32_t *vhi)
252 const uint16_t *ep = lp+listSize;
258 if (target < lp[0]) {
262 if (target >= ep[-1]) {
263 *vlo = *vhi = listSize - 1;
268 for (tp = lp; tp < ep; tp++) {
274 *vlo = *vhi = tp - (
const uint16_t *) lp;
281 if (target < tp[1]) {
282 *vlo = tp - (
const uint16_t *) lp;
294 const int16_t *pwrList,
const uint16_t *VpdList,
295 uint16_t numIntercepts, uint16_t retVpdList[][64])
298 int16_t currPwr = (int16_t)(2*Pmin);
305 if (numIntercepts < 2)
308 while (ii <= (uint16_t)(Pmax - Pmin)) {
310 numIntercepts, &(idxL), &(idxR));
313 if (idxL == (uint32_t)(numIntercepts - 1))
314 idxL = numIntercepts - 2;
315 if (pwrList[idxL] == pwrList[idxR])
319 (((currPwr - pwrList[idxL])*VpdList[idxR]+
320 (pwrList[idxR] - currPwr)*VpdList[idxL])/
321 (pwrList[idxR] - pwrList[idxL]));
322 retVpdList[pdGainIdx][ii] = kk;
335 int16_t targetLeft, int16_t targetRight)
339 if (srcRight != srcLeft) {
340 rv = ((target - srcLeft)*targetRight +
341 (srcRight - target)*targetLeft) / (srcRight - srcLeft);
355 uint16_t pdGainOverlap_t2,
356 int16_t *pMinCalPower, uint16_t pPdGainBoundaries[],
357 uint16_t pPdGainValues[], uint16_t pPDADCValues[])
360#define VpdTable_L priv->vpdTable_L
361#define VpdTable_R priv->vpdTable_R
362#define VpdTable_I priv->vpdTable_I
366 uint32_t numPdGainsUsed = 0;
378 uint32_t sizeCurrVpdTable, maxIndex, tgtIndex;
394 Pmin_t2[numPdGainsUsed] = (int16_t)
395 (Pmin_t2[numPdGainsUsed] / 2);
398 Pmax_t2[numPdGainsUsed] =
400 Pmax_t2[numPdGainsUsed] = (int16_t)(Pmax_t2[numPdGainsUsed] / 2);
402 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
407 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
411 for (kk = 0; kk < (uint16_t)(Pmax_t2[numPdGainsUsed] - Pmin_t2[numPdGainsUsed]); kk++) {
423 *pMinCalPower = Pmin_t2[0];
425 for (ii = 0; ii < numPdGainsUsed; ii++) {
426 if (ii == (numPdGainsUsed - 1))
427 pPdGainBoundaries[ii] = Pmax_t2[ii] +
430 pPdGainBoundaries[ii] = (uint16_t)
431 ((Pmax_t2[ii] + Pmin_t2[ii+1]) / 2 );
432 if (pPdGainBoundaries[ii] > 63) {
434 "%s: clamp pPdGainBoundaries[%d] %d\n",
435 __func__, ii, pPdGainBoundaries[ii]);
436 pPdGainBoundaries[ii] = 63;
443 ss = (pPdGainBoundaries[ii-1] - Pmin_t2[ii]) -
446 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
451 tmpVal = (int16_t)(
VpdTable_I[ii][0] + ss*Vpd_step);
452 pPDADCValues[kk++] = (uint16_t)((tmpVal < 0) ? 0 : tmpVal);
456 sizeCurrVpdTable = Pmax_t2[ii] - Pmin_t2[ii];
457 tgtIndex = pPdGainBoundaries[ii] + pdGainOverlap_t2 - Pmin_t2[ii];
458 maxIndex = (tgtIndex < sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;
460 while (ss < (int16_t)maxIndex)
463 Vpd_step = (uint16_t)(
VpdTable_I[ii][sizeCurrVpdTable-1] -
465 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
470 if (tgtIndex > maxIndex) {
471 while(ss < (int16_t)tgtIndex) {
474 (ss-maxIndex)*Vpd_step);
475 pPDADCValues[kk++] = (tmpVal > 127) ?
483 pPdGainBoundaries[ii] = pPdGainBoundaries[ii-1];
487 pPDADCValues[kk] = pPDADCValues[kk-1];
491 return numPdGainsUsed;
499 int16_t *minPower, int16_t *maxPower,
500 const struct ieee80211_channel *chan,
507 uint16_t pdGainOverlap_t2;
508 int16_t minCalPower2413_t2;
510 uint16_t gainBoundaries[4];
511 uint32_t reg32, regoffset;
512 int i, numPdGainsUsed;
513#ifndef AH_USE_INIPDGAIN
518 __func__, freq, chan->ic_flags);
520 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
522 else if (IEEE80211_IS_CHAN_B(chan))
533 freq, pRawDataset, pdGainOverlap_t2,
534 &minCalPower2413_t2,gainBoundaries, rfXpdGain, pdadcValues);
535 HALASSERT(1 <= numPdGainsUsed && numPdGainsUsed <= 3);
537#ifdef AH_USE_INIPDGAIN
548 tpcrg1 = (tpcrg1 &~ AR_PHY_TPCRG1_NUM_PD_GAIN)
550 switch (numPdGainsUsed) {
552 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING3;
556 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING2;
560 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING1;
567 "pd_gains (default 0x%x, calculated 0x%x)\n",
578 if (minCalPower2413_t2 != 0)
584 regoffset = 0x9800 + (672 <<2);
585 for (i = 0; i < 32; i++) {
586 reg32 = ((pdadcValues[4*i + 0] & 0xFF) << 0) |
587 ((pdadcValues[4*i + 1] & 0xFF) << 8) |
588 ((pdadcValues[4*i + 2] & 0xFF) << 16) |
589 ((pdadcValues[4*i + 3] & 0xFF) << 24) ;
608 uint16_t Pmin=0,numVpd;
626 uint16_t Pmax=0,numVpd;
641 const struct ieee80211_channel *chan,
642 int16_t *maxPow, int16_t *minPow)
644 uint16_t freq = chan->ic_freq;
648 uint16_t numChannels;
649 int totalD,totalF, totalMin,last, i;
653 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
655 else if (IEEE80211_IS_CHAN_B(chan))
669 if ((freq < data[0].channelValue) ||
670 (freq > data[numChannels-1].channelValue)) {
671 if (freq < data[0].channelValue) {
683 for (last=0,i=0; (i<numChannels) && (freq > data[i].channelValue);
688 *maxPow = (int8_t) ((totalF*(freq-data[last].channelValue) +
691 *minPow = (int8_t) ((totalMin*(freq-data[last].channelValue) +
695 if (freq == data[i].channelValue) {
733 "%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 PWR_TABLE_SIZE_2413
#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 ar2413SetPowerTable(struct ath_hal *ah, int16_t *minPower, int16_t *maxPower, const struct ieee80211_channel *chan, uint16_t *rfXpdGain)
static int16_t ar2413GetMaxPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)
static int ar2413getGainBoundariesAndPdadcsForPowers(struct ath_hal *ah, uint16_t channel, const RAW_DATA_STRUCT_2413 *pRawDataset, uint16_t pdGainOverlap_t2, int16_t *pMinCalPower, uint16_t pPdGainBoundaries[], uint16_t pPdGainValues[], uint16_t pPDADCValues[])
static uint32_t * ar2413GetRfBank(struct ath_hal *ah, int bank)
void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32, uint32_t numBits, uint32_t firstBit, uint32_t column)
static HAL_BOOL ar2413RfAttach(struct ath_hal *ah, HAL_STATUS *status)
static HAL_BOOL ar2413SetChannel(struct ath_hal *ah, const struct ieee80211_channel *chan)
static HAL_BOOL ar2413GetChannelMaxMinPower(struct ath_hal *ah, const struct ieee80211_channel *chan, int16_t *maxPow, int16_t *minPow)
static int16_t ar2413GetMinPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)
static HAL_BOOL ar2413Probe(struct ath_hal *ah)
static void GetLowerUpperIndex(int16_t v, const uint16_t *lp, uint16_t listSize, uint32_t *vlo, uint32_t *vhi)
static HAL_BOOL ar2413SetRfRegs(struct ath_hal *ah, const struct ieee80211_channel *chan, uint16_t modesIndex, uint16_t *rfXpdGain)
#define RF_BANK_SETUP(_priv, _ix, _col)
static void ar2413WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex, int writes)
AH_RF(RF2413, ar2413Probe, ar2413RfAttach)
static HAL_BOOL ar2413FillVpdTable(uint32_t pdGainIdx, int16_t Pmin, int16_t Pmax, const int16_t *pwrList, const uint16_t *VpdList, uint16_t numIntercepts, uint16_t retVpdList[][64])
static void ar2413RfDetach(struct ath_hal *ah)
static int16_t interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight, int16_t targetLeft, int16_t targetRight)
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 vpdTable_L[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB]
uint16_t pcdacTable[PWR_TABLE_SIZE_2413]
uint16_t vpdTable_R[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB]
uint32_t Bank6Data[N(ar5212Bank6_2413)]
uint32_t Bank7Data[N(ar5212Bank7_2413)]
uint32_t Bank1Data[N(ar5212Bank1_2413)]
uint32_t Bank2Data[N(ar5212Bank2_2413)]
uint32_t Bank3Data[N(ar5212Bank3_2413)]
uint16_t vpdTable_I[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB]
int16_t ah_txPowerIndexOffset
HAL_RFGAIN ah_rfgainState