2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2008 Atheros Communications, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "ah_internal.h"
24 #include "ar5212/ar5212.h"
25 #include "ar5212/ar5212reg.h"
26 #include "ar5212/ar5212phy.h"
28 #include "ah_eeprom_v3.h"
31 #include "ar5212/ar5212.ini"
33 #define N(a) (sizeof(a)/sizeof(a[0]))
35 typedef RAW_DATA_STRUCT_2413 RAW_DATA_STRUCT_2316;
36 typedef RAW_DATA_PER_CHANNEL_2413 RAW_DATA_PER_CHANNEL_2316;
37 #define PWR_TABLE_SIZE_2316 PWR_TABLE_SIZE_2413
40 RF_HAL_FUNCS base; /* public state, must be first */
41 uint16_t pcdacTable[PWR_TABLE_SIZE_2316];
43 uint32_t Bank1Data[N(ar5212Bank1_2316)];
44 uint32_t Bank2Data[N(ar5212Bank2_2316)];
45 uint32_t Bank3Data[N(ar5212Bank3_2316)];
46 uint32_t Bank6Data[N(ar5212Bank6_2316)];
47 uint32_t Bank7Data[N(ar5212Bank7_2316)];
50 * Private state for reduced stack usage.
52 /* filled out Vpd table for all pdGains (chanL) */
53 uint16_t vpdTable_L[MAX_NUM_PDGAINS_PER_CHANNEL]
54 [MAX_PWR_RANGE_IN_HALF_DB];
55 /* filled out Vpd table for all pdGains (chanR) */
56 uint16_t vpdTable_R[MAX_NUM_PDGAINS_PER_CHANNEL]
57 [MAX_PWR_RANGE_IN_HALF_DB];
58 /* filled out Vpd table for all pdGains (interpolated) */
59 uint16_t vpdTable_I[MAX_NUM_PDGAINS_PER_CHANNEL]
60 [MAX_PWR_RANGE_IN_HALF_DB];
62 #define AR2316(ah) ((struct ar2316State *) AH5212(ah)->ah_rfHal)
64 extern void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32,
65 uint32_t numBits, uint32_t firstBit, uint32_t column);
68 ar2316WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex,
71 struct ath_hal_5212 *ahp = AH5212(ah);
73 HAL_INI_WRITE_ARRAY(ah, ar5212Modes_2316, modesIndex, regWrites);
74 HAL_INI_WRITE_ARRAY(ah, ar5212Common_2316, 1, regWrites);
75 HAL_INI_WRITE_ARRAY(ah, ar5212BB_RfGain_2316, freqIndex, regWrites);
78 if (!ahp->ah_cwCalRequire) {
79 OS_REG_WRITE(ah, 0xa358, (OS_REG_READ(ah, 0xa358) & ~0x2));
81 ahp->ah_cwCalRequire = AH_FALSE;
86 * Take the MHz channel value and set the Channel value
88 * ASSUMES: Writes enabled to analog bus
91 ar2316SetChannel(struct ath_hal *ah, struct ieee80211_channel *chan)
93 uint16_t freq = ath_hal_gethwchannel(ah, chan);
94 uint32_t channelSel = 0;
95 uint32_t bModeSynth = 0;
96 uint32_t aModeRefSel = 0;
99 OS_MARK(ah, AH_MARK_SETCHANNEL, freq);
104 if (((freq - 2192) % 5) == 0) {
105 channelSel = ((freq - 672) * 2 - 3040)/10;
107 } else if (((freq - 2224) % 5) == 0) {
108 channelSel = ((freq - 704) * 2 - 3040) / 10;
111 HALDEBUG(ah, HAL_DEBUG_ANY,
112 "%s: invalid channel %u MHz\n",
117 channelSel = (channelSel << 2) & 0xff;
118 channelSel = ath_hal_reverseBits(channelSel, 8);
120 txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL);
122 /* Enable channel spreading for channel 14 */
123 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
124 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
126 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
127 txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
129 } else if ((freq % 20) == 0 && freq >= 5120) {
130 channelSel = ath_hal_reverseBits(
131 ((freq - 4800) / 20 << 2), 8);
132 aModeRefSel = ath_hal_reverseBits(3, 2);
133 } else if ((freq % 10) == 0) {
134 channelSel = ath_hal_reverseBits(
135 ((freq - 4800) / 10 << 1), 8);
136 aModeRefSel = ath_hal_reverseBits(2, 2);
137 } else if ((freq % 5) == 0) {
138 channelSel = ath_hal_reverseBits(
139 (freq - 4800) / 5, 8);
140 aModeRefSel = ath_hal_reverseBits(1, 2);
142 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel %u MHz\n",
147 reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) |
149 OS_REG_WRITE(ah, AR_PHY(0x27), reg32 & 0xff);
152 OS_REG_WRITE(ah, AR_PHY(0x36), reg32 & 0x7f);
154 AH_PRIVATE(ah)->ah_curchan = chan;
159 * Reads EEPROM header info from device structure and programs
162 * REQUIRES: Access to the analog rf device
165 ar2316SetRfRegs(struct ath_hal *ah, const struct ieee80211_channel *chan,
166 uint16_t modesIndex, uint16_t *rfXpdGain)
168 #define RF_BANK_SETUP(_priv, _ix, _col) do { \
170 for (i = 0; i < N(ar5212Bank##_ix##_2316); i++) \
171 (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_2316[i][_col];\
173 struct ath_hal_5212 *ahp = AH5212(ah);
174 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
175 uint16_t ob2GHz = 0, db2GHz = 0;
176 struct ar2316State *priv = AR2316(ah);
179 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan %u/0x%x modesIndex %u\n",
180 __func__, chan->ic_freq, chan->ic_flags, modesIndex);
182 HALASSERT(priv != AH_NULL);
184 /* Setup rf parameters */
185 if (IEEE80211_IS_CHAN_B(chan)) {
186 ob2GHz = ee->ee_obFor24;
187 db2GHz = ee->ee_dbFor24;
189 ob2GHz = ee->ee_obFor24g;
190 db2GHz = ee->ee_dbFor24g;
194 RF_BANK_SETUP(priv, 1, 1);
197 RF_BANK_SETUP(priv, 2, modesIndex);
200 RF_BANK_SETUP(priv, 3, modesIndex);
203 RF_BANK_SETUP(priv, 6, modesIndex);
205 ar5212ModifyRfBuffer(priv->Bank6Data, ob2GHz, 3, 178, 0);
206 ar5212ModifyRfBuffer(priv->Bank6Data, db2GHz, 3, 175, 0);
209 RF_BANK_SETUP(priv, 7, modesIndex);
211 /* Write Analog registers */
212 HAL_INI_WRITE_BANK(ah, ar5212Bank1_2316, priv->Bank1Data, regWrites);
213 HAL_INI_WRITE_BANK(ah, ar5212Bank2_2316, priv->Bank2Data, regWrites);
214 HAL_INI_WRITE_BANK(ah, ar5212Bank3_2316, priv->Bank3Data, regWrites);
215 HAL_INI_WRITE_BANK(ah, ar5212Bank6_2316, priv->Bank6Data, regWrites);
216 HAL_INI_WRITE_BANK(ah, ar5212Bank7_2316, priv->Bank7Data, regWrites);
218 /* Now that we have reprogrammed rfgain value, clear the flag. */
219 ahp->ah_rfgainState = HAL_RFGAIN_INACTIVE;
226 * Return a reference to the requested RF Bank.
229 ar2316GetRfBank(struct ath_hal *ah, int bank)
231 struct ar2316State *priv = AR2316(ah);
233 HALASSERT(priv != AH_NULL);
235 case 1: return priv->Bank1Data;
236 case 2: return priv->Bank2Data;
237 case 3: return priv->Bank3Data;
238 case 6: return priv->Bank6Data;
239 case 7: return priv->Bank7Data;
241 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown RF Bank %d requested\n",
247 * Return indices surrounding the value in sorted integer lists.
249 * NB: the input list is assumed to be sorted in ascending order
252 GetLowerUpperIndex(int16_t v, const uint16_t *lp, uint16_t listSize,
253 uint32_t *vlo, uint32_t *vhi)
256 const int16_t *ep = lp+listSize;
260 * Check first and last elements for out-of-bounds conditions.
262 if (target < lp[0]) {
266 if (target >= ep[-1]) {
267 *vlo = *vhi = listSize - 1;
271 /* look for value being near or between 2 values in list */
272 for (tp = lp; tp < ep; tp++) {
274 * If value is close to the current value of the list
275 * then target is not between values, it is one of the values
278 *vlo = *vhi = tp - (const int16_t *) lp;
282 * Look for value being between current value and next value
283 * if so return these 2 values
285 if (target < tp[1]) {
286 *vlo = tp - (const int16_t *) lp;
294 * Fill the Vpdlist for indices Pmax-Pmin
297 ar2316FillVpdTable(uint32_t pdGainIdx, int16_t Pmin, int16_t Pmax,
298 const int16_t *pwrList, const int16_t *VpdList,
299 uint16_t numIntercepts, uint16_t retVpdList[][64])
302 int16_t currPwr = (int16_t)(2*Pmin);
303 /* since Pmin is pwr*2 and pwrList is 4*pwr */
309 if (numIntercepts < 2)
312 while (ii <= (uint16_t)(Pmax - Pmin)) {
313 GetLowerUpperIndex(currPwr, pwrList, numIntercepts,
316 idxR = 1; /* extrapolate below */
317 if (idxL == (uint32_t)(numIntercepts - 1))
318 idxL = numIntercepts - 2; /* extrapolate above */
319 if (pwrList[idxL] == pwrList[idxR])
323 (((currPwr - pwrList[idxL])*VpdList[idxR]+
324 (pwrList[idxR] - currPwr)*VpdList[idxL])/
325 (pwrList[idxR] - pwrList[idxL]));
326 retVpdList[pdGainIdx][ii] = kk;
328 currPwr += 2; /* half dB steps */
335 * Returns interpolated or the scaled up interpolated value
338 interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight,
339 int16_t targetLeft, int16_t targetRight)
343 if (srcRight != srcLeft) {
344 rv = ((target - srcLeft)*targetRight +
345 (srcRight - target)*targetLeft) / (srcRight - srcLeft);
353 * Uses the data points read from EEPROM to reconstruct the pdadc power table
354 * Called by ar2316SetPowerTable()
357 ar2316getGainBoundariesAndPdadcsForPowers(struct ath_hal *ah, uint16_t channel,
358 const RAW_DATA_STRUCT_2316 *pRawDataset,
359 uint16_t pdGainOverlap_t2,
360 int16_t *pMinCalPower, uint16_t pPdGainBoundaries[],
361 uint16_t pPdGainValues[], uint16_t pPDADCValues[])
363 struct ar2316State *priv = AR2316(ah);
364 #define VpdTable_L priv->vpdTable_L
365 #define VpdTable_R priv->vpdTable_R
366 #define VpdTable_I priv->vpdTable_I
368 int32_t ss;/* potentially -ve index for taking care of pdGainOverlap */
370 uint32_t numPdGainsUsed = 0;
372 * If desired to support -ve power levels in future, just
373 * change pwr_I_0 to signed 5-bits.
375 int16_t Pmin_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
376 /* to accomodate -ve power levels later on. */
377 int16_t Pmax_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
378 /* to accomodate -ve power levels later on */
382 uint32_t sizeCurrVpdTable, maxIndex, tgtIndex;
384 /* Get upper lower index */
385 GetLowerUpperIndex(channel, pRawDataset->pChannels,
386 pRawDataset->numChannels, &(idxL), &(idxR));
388 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
389 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
390 /* work backwards 'cause highest pdGain for lowest power */
391 numVpd = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].numVpd;
393 pPdGainValues[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pd_gain;
394 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0];
395 if (Pmin_t2[numPdGainsUsed] >pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]) {
396 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0];
398 Pmin_t2[numPdGainsUsed] = (int16_t)
399 (Pmin_t2[numPdGainsUsed] / 2);
400 Pmax_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[numVpd-1];
401 if (Pmax_t2[numPdGainsUsed] > pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1])
402 Pmax_t2[numPdGainsUsed] =
403 pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1];
404 Pmax_t2[numPdGainsUsed] = (int16_t)(Pmax_t2[numPdGainsUsed] / 2);
406 numPdGainsUsed, 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_L
411 numPdGainsUsed, 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_R
415 for (kk = 0; kk < (uint16_t)(Pmax_t2[numPdGainsUsed] - Pmin_t2[numPdGainsUsed]); kk++) {
416 VpdTable_I[numPdGainsUsed][kk] =
418 channel, pRawDataset->pChannels[idxL], pRawDataset->pChannels[idxR],
419 (int16_t)VpdTable_L[numPdGainsUsed][kk], (int16_t)VpdTable_R[numPdGainsUsed][kk]);
421 /* fill VpdTable_I for this pdGain */
424 /* if this pdGain is used */
427 *pMinCalPower = Pmin_t2[0];
428 kk = 0; /* index for the final table */
429 for (ii = 0; ii < numPdGainsUsed; ii++) {
430 if (ii == (numPdGainsUsed - 1))
431 pPdGainBoundaries[ii] = Pmax_t2[ii] +
432 PD_GAIN_BOUNDARY_STRETCH_IN_HALF_DB;
434 pPdGainBoundaries[ii] = (uint16_t)
435 ((Pmax_t2[ii] + Pmin_t2[ii+1]) / 2 );
436 if (pPdGainBoundaries[ii] > 63) {
437 HALDEBUG(ah, HAL_DEBUG_ANY,
438 "%s: clamp pPdGainBoundaries[%d] %d\n",
439 __func__, ii, pPdGainBoundaries[ii]);/*XXX*/
440 pPdGainBoundaries[ii] = 63;
443 /* Find starting index for this pdGain */
445 ss = 0; /* for the first pdGain, start from index 0 */
447 ss = (pPdGainBoundaries[ii-1] - Pmin_t2[ii]) -
449 Vpd_step = (uint16_t)(VpdTable_I[ii][1] - VpdTable_I[ii][0]);
450 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
452 *-ve ss indicates need to extrapolate data below for this pdGain
455 tmpVal = (int16_t)(VpdTable_I[ii][0] + ss*Vpd_step);
456 pPDADCValues[kk++] = (uint16_t)((tmpVal < 0) ? 0 : tmpVal);
460 sizeCurrVpdTable = Pmax_t2[ii] - Pmin_t2[ii];
461 tgtIndex = pPdGainBoundaries[ii] + pdGainOverlap_t2 - Pmin_t2[ii];
462 maxIndex = (tgtIndex < sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;
464 while (ss < (int16_t)maxIndex)
465 pPDADCValues[kk++] = VpdTable_I[ii][ss++];
467 Vpd_step = (uint16_t)(VpdTable_I[ii][sizeCurrVpdTable-1] -
468 VpdTable_I[ii][sizeCurrVpdTable-2]);
469 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
471 * for last gain, pdGainBoundary == Pmax_t2, so will
472 * have to extrapolate
474 if (tgtIndex > maxIndex) { /* need to extrapolate above */
475 while(ss < (int16_t)tgtIndex) {
477 (VpdTable_I[ii][sizeCurrVpdTable-1] +
478 (ss-maxIndex)*Vpd_step);
479 pPDADCValues[kk++] = (tmpVal > 127) ?
483 } /* extrapolated above */
484 } /* for all pdGainUsed */
486 while (ii < MAX_NUM_PDGAINS_PER_CHANNEL) {
487 pPdGainBoundaries[ii] = pPdGainBoundaries[ii-1];
491 pPDADCValues[kk] = pPDADCValues[kk-1];
495 return numPdGainsUsed;
502 ar2316SetPowerTable(struct ath_hal *ah,
503 int16_t *minPower, int16_t *maxPower,
504 const struct ieee80211_channel *chan,
507 struct ath_hal_5212 *ahp = AH5212(ah);
508 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
509 const RAW_DATA_STRUCT_2316 *pRawDataset = AH_NULL;
510 uint16_t pdGainOverlap_t2;
511 int16_t minCalPower2316_t2;
512 uint16_t *pdadcValues = ahp->ah_pcdacTable;
513 uint16_t gainBoundaries[4];
514 uint32_t reg32, regoffset;
515 int i, numPdGainsUsed;
516 #ifndef AH_USE_INIPDGAIN
520 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan 0x%x flag 0x%x\n",
521 __func__, chan->ic_freq, chan->ic_flags);
523 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
524 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
525 else if (IEEE80211_IS_CHAN_B(chan))
526 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
528 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: illegal mode\n", __func__);
532 pdGainOverlap_t2 = (uint16_t) SM(OS_REG_READ(ah, AR_PHY_TPCRG5),
533 AR_PHY_TPCRG5_PD_GAIN_OVERLAP);
535 numPdGainsUsed = ar2316getGainBoundariesAndPdadcsForPowers(ah,
536 chan->channel, pRawDataset, pdGainOverlap_t2,
537 &minCalPower2316_t2,gainBoundaries, rfXpdGain, pdadcValues);
538 HALASSERT(1 <= numPdGainsUsed && numPdGainsUsed <= 3);
540 #ifdef AH_USE_INIPDGAIN
542 * Use pd_gains curve from eeprom; Atheros always uses
543 * the default curve from the ini file but some vendors
544 * (e.g. Zcomax) want to override this curve and not
545 * honoring their settings results in tx power 5dBm low.
547 OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
548 (pRawDataset->pDataPerChannel[0].numPdGains - 1));
550 tpcrg1 = OS_REG_READ(ah, AR_PHY_TPCRG1);
551 tpcrg1 = (tpcrg1 &~ AR_PHY_TPCRG1_NUM_PD_GAIN)
552 | SM(numPdGainsUsed-1, AR_PHY_TPCRG1_NUM_PD_GAIN);
553 switch (numPdGainsUsed) {
555 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING3;
556 tpcrg1 |= SM(rfXpdGain[2], AR_PHY_TPCRG1_PDGAIN_SETTING3);
559 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING2;
560 tpcrg1 |= SM(rfXpdGain[1], AR_PHY_TPCRG1_PDGAIN_SETTING2);
563 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING1;
564 tpcrg1 |= SM(rfXpdGain[0], AR_PHY_TPCRG1_PDGAIN_SETTING1);
568 if (tpcrg1 != OS_REG_READ(ah, AR_PHY_TPCRG1))
569 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: using non-default "
570 "pd_gains (default 0x%x, calculated 0x%x)\n",
571 __func__, OS_REG_READ(ah, AR_PHY_TPCRG1), tpcrg1);
573 OS_REG_WRITE(ah, AR_PHY_TPCRG1, tpcrg1);
577 * Note the pdadc table may not start at 0 dBm power, could be
578 * negative or greater than 0. Need to offset the power
579 * values by the amount of minPower for griffin
581 if (minCalPower2316_t2 != 0)
582 ahp->ah_txPowerIndexOffset = (int16_t)(0 - minCalPower2316_t2);
584 ahp->ah_txPowerIndexOffset = 0;
586 /* Finally, write the power values into the baseband power table */
587 regoffset = 0x9800 + (672 <<2); /* beginning of pdadc table in griffin */
588 for (i = 0; i < 32; i++) {
589 reg32 = ((pdadcValues[4*i + 0] & 0xFF) << 0) |
590 ((pdadcValues[4*i + 1] & 0xFF) << 8) |
591 ((pdadcValues[4*i + 2] & 0xFF) << 16) |
592 ((pdadcValues[4*i + 3] & 0xFF) << 24) ;
593 OS_REG_WRITE(ah, regoffset, reg32);
597 OS_REG_WRITE(ah, AR_PHY_TPCRG5,
598 SM(pdGainOverlap_t2, AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
599 SM(gainBoundaries[0], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
600 SM(gainBoundaries[1], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
601 SM(gainBoundaries[2], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
602 SM(gainBoundaries[3], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
608 ar2316GetMinPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2316 *data)
611 uint16_t Pmin=0,numVpd;
613 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
614 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
615 /* work backwards 'cause highest pdGain for lowest power */
616 numVpd = data->pDataPerPDGain[jj].numVpd;
618 Pmin = data->pDataPerPDGain[jj].pwr_t4[0];
626 ar2316GetMaxPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2316 *data)
629 uint16_t Pmax=0,numVpd;
631 for (ii=0; ii< MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
632 /* work forwards cuase lowest pdGain for highest power */
633 numVpd = data->pDataPerPDGain[ii].numVpd;
635 Pmax = data->pDataPerPDGain[ii].pwr_t4[numVpd-1];
643 ar2316GetChannelMaxMinPower(struct ath_hal *ah,
644 const struct ieee80211_channel *chan,
645 int16_t *maxPow, int16_t *minPow)
647 uint16_t freq = chan->ic_freq; /* NB: never mapped */
648 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
649 const RAW_DATA_STRUCT_2316 *pRawDataset = AH_NULL;
650 const RAW_DATA_PER_CHANNEL_2316 *data=AH_NULL;
651 uint16_t numChannels;
652 int totalD,totalF, totalMin,last, i;
656 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
657 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
658 else if (IEEE80211_IS_CHAN_B(chan))
659 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
663 numChannels = pRawDataset->numChannels;
664 data = pRawDataset->pDataPerChannel;
666 /* Make sure the channel is in the range of the TP values
672 if ((freq < data[0].channelValue) ||
673 (freq > data[numChannels-1].channelValue)) {
674 if (freq < data[0].channelValue) {
675 *maxPow = ar2316GetMaxPower(ah, &data[0]);
676 *minPow = ar2316GetMinPower(ah, &data[0]);
679 *maxPow = ar2316GetMaxPower(ah, &data[numChannels - 1]);
680 *minPow = ar2316GetMinPower(ah, &data[numChannels - 1]);
685 /* Linearly interpolate the power value now */
686 for (last=0,i=0; (i<numChannels) && (freq > data[i].channelValue);
688 totalD = data[i].channelValue - data[last].channelValue;
690 totalF = ar2316GetMaxPower(ah, &data[i]) - ar2316GetMaxPower(ah, &data[last]);
691 *maxPow = (int8_t) ((totalF*(freq-data[last].channelValue) +
692 ar2316GetMaxPower(ah, &data[last])*totalD)/totalD);
693 totalMin = ar2316GetMinPower(ah, &data[i]) - ar2316GetMinPower(ah, &data[last]);
694 *minPow = (int8_t) ((totalMin*(freq-data[last].channelValue) +
695 ar2316GetMinPower(ah, &data[last])*totalD)/totalD);
698 if (freq == data[i].channelValue) {
699 *maxPow = ar2316GetMaxPower(ah, &data[i]);
700 *minPow = ar2316GetMinPower(ah, &data[i]);
708 * Free memory for analog bank scratch buffers
711 ar2316RfDetach(struct ath_hal *ah)
713 struct ath_hal_5212 *ahp = AH5212(ah);
715 HALASSERT(ahp->ah_rfHal != AH_NULL);
716 ath_hal_free(ahp->ah_rfHal);
717 ahp->ah_rfHal = AH_NULL;
721 * Allocate memory for private state.
722 * Scratch Buffer will be reinitialized every reset so no need to zero now
725 ar2316RfAttach(struct ath_hal *ah, HAL_STATUS *status)
727 struct ath_hal_5212 *ahp = AH5212(ah);
728 struct ar2316State *priv;
730 HALASSERT(ah->ah_magic == AR5212_MAGIC);
732 HALASSERT(ahp->ah_rfHal == AH_NULL);
733 priv = ath_hal_malloc(sizeof(struct ar2316State));
734 if (priv == AH_NULL) {
735 HALDEBUG(ah, HAL_DEBUG_ANY,
736 "%s: cannot allocate private state\n", __func__);
737 *status = HAL_ENOMEM; /* XXX */
740 priv->base.rfDetach = ar2316RfDetach;
741 priv->base.writeRegs = ar2316WriteRegs;
742 priv->base.getRfBank = ar2316GetRfBank;
743 priv->base.setChannel = ar2316SetChannel;
744 priv->base.setRfRegs = ar2316SetRfRegs;
745 priv->base.setPowerTable = ar2316SetPowerTable;
746 priv->base.getChannelMaxMinPower = ar2316GetChannelMaxMinPower;
747 priv->base.getNfAdjust = ar5212GetNfAdjust;
749 ahp->ah_pcdacTable = priv->pcdacTable;
750 ahp->ah_pcdacTableSize = sizeof(priv->pcdacTable);
751 ahp->ah_rfHal = &priv->base;
753 ahp->ah_cwCalRequire = AH_TRUE; /* force initial cal */
759 ar2316Probe(struct ath_hal *ah)
763 AH_RF(RF2316, ar2316Probe, ar2316RfAttach);