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.
17 * $FreeBSD: head/sys/dev/ath/ath_hal/ar5212/ar2316.c 187831 2009-01-28 18:00:22Z sam $
23 #include "ah_internal.h"
25 #include "ar5212/ar5212.h"
26 #include "ar5212/ar5212reg.h"
27 #include "ar5212/ar5212phy.h"
29 #include "ah_eeprom_v3.h"
32 #include "ar5212/ar5212.ini"
34 #define N(a) (sizeof(a)/sizeof(a[0]))
36 typedef RAW_DATA_STRUCT_2413 RAW_DATA_STRUCT_2316;
37 typedef RAW_DATA_PER_CHANNEL_2413 RAW_DATA_PER_CHANNEL_2316;
38 #define PWR_TABLE_SIZE_2316 PWR_TABLE_SIZE_2413
41 RF_HAL_FUNCS base; /* public state, must be first */
42 uint16_t pcdacTable[PWR_TABLE_SIZE_2316];
44 uint32_t Bank1Data[N(ar5212Bank1_2316)];
45 uint32_t Bank2Data[N(ar5212Bank2_2316)];
46 uint32_t Bank3Data[N(ar5212Bank3_2316)];
47 uint32_t Bank6Data[N(ar5212Bank6_2316)];
48 uint32_t Bank7Data[N(ar5212Bank7_2316)];
51 * Private state for reduced stack usage.
53 /* filled out Vpd table for all pdGains (chanL) */
54 uint16_t vpdTable_L[MAX_NUM_PDGAINS_PER_CHANNEL]
55 [MAX_PWR_RANGE_IN_HALF_DB];
56 /* filled out Vpd table for all pdGains (chanR) */
57 uint16_t vpdTable_R[MAX_NUM_PDGAINS_PER_CHANNEL]
58 [MAX_PWR_RANGE_IN_HALF_DB];
59 /* filled out Vpd table for all pdGains (interpolated) */
60 uint16_t vpdTable_I[MAX_NUM_PDGAINS_PER_CHANNEL]
61 [MAX_PWR_RANGE_IN_HALF_DB];
63 #define AR2316(ah) ((struct ar2316State *) AH5212(ah)->ah_rfHal)
65 extern void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32,
66 uint32_t numBits, uint32_t firstBit, uint32_t column);
69 ar2316WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex,
72 struct ath_hal_5212 *ahp = AH5212(ah);
74 HAL_INI_WRITE_ARRAY(ah, ar5212Modes_2316, modesIndex, regWrites);
75 HAL_INI_WRITE_ARRAY(ah, ar5212Common_2316, 1, regWrites);
76 HAL_INI_WRITE_ARRAY(ah, ar5212BB_RfGain_2316, freqIndex, regWrites);
79 if (!ahp->ah_cwCalRequire) {
80 OS_REG_WRITE(ah, 0xa358, (OS_REG_READ(ah, 0xa358) & ~0x2));
82 ahp->ah_cwCalRequire = AH_FALSE;
87 * Take the MHz channel value and set the Channel value
89 * ASSUMES: Writes enabled to analog bus
92 ar2316SetChannel(struct ath_hal *ah, struct ieee80211_channel *chan)
94 uint16_t freq = ath_hal_gethwchannel(ah, chan);
95 uint32_t channelSel = 0;
96 uint32_t bModeSynth = 0;
97 uint32_t aModeRefSel = 0;
100 OS_MARK(ah, AH_MARK_SETCHANNEL, freq);
105 if (((freq - 2192) % 5) == 0) {
106 channelSel = ((freq - 672) * 2 - 3040)/10;
108 } else if (((freq - 2224) % 5) == 0) {
109 channelSel = ((freq - 704) * 2 - 3040) / 10;
112 HALDEBUG(ah, HAL_DEBUG_ANY,
113 "%s: invalid channel %u MHz\n",
118 channelSel = (channelSel << 2) & 0xff;
119 channelSel = ath_hal_reverseBits(channelSel, 8);
121 txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL);
123 /* Enable channel spreading for channel 14 */
124 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
125 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
127 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
128 txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
130 } else if ((freq % 20) == 0 && freq >= 5120) {
131 channelSel = ath_hal_reverseBits(
132 ((freq - 4800) / 20 << 2), 8);
133 aModeRefSel = ath_hal_reverseBits(3, 2);
134 } else if ((freq % 10) == 0) {
135 channelSel = ath_hal_reverseBits(
136 ((freq - 4800) / 10 << 1), 8);
137 aModeRefSel = ath_hal_reverseBits(2, 2);
138 } else if ((freq % 5) == 0) {
139 channelSel = ath_hal_reverseBits(
140 (freq - 4800) / 5, 8);
141 aModeRefSel = ath_hal_reverseBits(1, 2);
143 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel %u MHz\n",
148 reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) |
150 OS_REG_WRITE(ah, AR_PHY(0x27), reg32 & 0xff);
153 OS_REG_WRITE(ah, AR_PHY(0x36), reg32 & 0x7f);
155 AH_PRIVATE(ah)->ah_curchan = chan;
160 * Reads EEPROM header info from device structure and programs
163 * REQUIRES: Access to the analog rf device
166 ar2316SetRfRegs(struct ath_hal *ah, const struct ieee80211_channel *chan,
167 uint16_t modesIndex, uint16_t *rfXpdGain)
169 #define RF_BANK_SETUP(_priv, _ix, _col) do { \
171 for (i = 0; i < N(ar5212Bank##_ix##_2316); i++) \
172 (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_2316[i][_col];\
174 struct ath_hal_5212 *ahp = AH5212(ah);
175 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
176 uint16_t ob2GHz = 0, db2GHz = 0;
177 struct ar2316State *priv = AR2316(ah);
180 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan %u/0x%x modesIndex %u\n",
181 __func__, chan->ic_freq, chan->ic_flags, modesIndex);
183 HALASSERT(priv != AH_NULL);
185 /* Setup rf parameters */
186 if (IEEE80211_IS_CHAN_B(chan)) {
187 ob2GHz = ee->ee_obFor24;
188 db2GHz = ee->ee_dbFor24;
190 ob2GHz = ee->ee_obFor24g;
191 db2GHz = ee->ee_dbFor24g;
195 RF_BANK_SETUP(priv, 1, 1);
198 RF_BANK_SETUP(priv, 2, modesIndex);
201 RF_BANK_SETUP(priv, 3, modesIndex);
204 RF_BANK_SETUP(priv, 6, modesIndex);
206 ar5212ModifyRfBuffer(priv->Bank6Data, ob2GHz, 3, 178, 0);
207 ar5212ModifyRfBuffer(priv->Bank6Data, db2GHz, 3, 175, 0);
210 RF_BANK_SETUP(priv, 7, modesIndex);
212 /* Write Analog registers */
213 HAL_INI_WRITE_BANK(ah, ar5212Bank1_2316, priv->Bank1Data, regWrites);
214 HAL_INI_WRITE_BANK(ah, ar5212Bank2_2316, priv->Bank2Data, regWrites);
215 HAL_INI_WRITE_BANK(ah, ar5212Bank3_2316, priv->Bank3Data, regWrites);
216 HAL_INI_WRITE_BANK(ah, ar5212Bank6_2316, priv->Bank6Data, regWrites);
217 HAL_INI_WRITE_BANK(ah, ar5212Bank7_2316, priv->Bank7Data, regWrites);
219 /* Now that we have reprogrammed rfgain value, clear the flag. */
220 ahp->ah_rfgainState = HAL_RFGAIN_INACTIVE;
227 * Return a reference to the requested RF Bank.
230 ar2316GetRfBank(struct ath_hal *ah, int bank)
232 struct ar2316State *priv = AR2316(ah);
234 HALASSERT(priv != AH_NULL);
236 case 1: return priv->Bank1Data;
237 case 2: return priv->Bank2Data;
238 case 3: return priv->Bank3Data;
239 case 6: return priv->Bank6Data;
240 case 7: return priv->Bank7Data;
242 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown RF Bank %d requested\n",
248 * Return indices surrounding the value in sorted integer lists.
250 * NB: the input list is assumed to be sorted in ascending order
253 GetLowerUpperIndex(int16_t v, const uint16_t *lp, uint16_t listSize,
254 uint32_t *vlo, uint32_t *vhi)
257 const int16_t *ep = lp+listSize;
261 * Check first and last elements for out-of-bounds conditions.
263 if (target < lp[0]) {
267 if (target >= ep[-1]) {
268 *vlo = *vhi = listSize - 1;
272 /* look for value being near or between 2 values in list */
273 for (tp = lp; tp < ep; tp++) {
275 * If value is close to the current value of the list
276 * then target is not between values, it is one of the values
279 *vlo = *vhi = tp - (const int16_t *) lp;
283 * Look for value being between current value and next value
284 * if so return these 2 values
286 if (target < tp[1]) {
287 *vlo = tp - (const int16_t *) lp;
295 * Fill the Vpdlist for indices Pmax-Pmin
298 ar2316FillVpdTable(uint32_t pdGainIdx, int16_t Pmin, int16_t Pmax,
299 const int16_t *pwrList, const int16_t *VpdList,
300 uint16_t numIntercepts, uint16_t retVpdList[][64])
303 int16_t currPwr = (int16_t)(2*Pmin);
304 /* since Pmin is pwr*2 and pwrList is 4*pwr */
310 if (numIntercepts < 2)
313 while (ii <= (uint16_t)(Pmax - Pmin)) {
314 GetLowerUpperIndex(currPwr, pwrList, numIntercepts,
317 idxR = 1; /* extrapolate below */
318 if (idxL == (uint32_t)(numIntercepts - 1))
319 idxL = numIntercepts - 2; /* extrapolate above */
320 if (pwrList[idxL] == pwrList[idxR])
324 (((currPwr - pwrList[idxL])*VpdList[idxR]+
325 (pwrList[idxR] - currPwr)*VpdList[idxL])/
326 (pwrList[idxR] - pwrList[idxL]));
327 retVpdList[pdGainIdx][ii] = kk;
329 currPwr += 2; /* half dB steps */
336 * Returns interpolated or the scaled up interpolated value
339 interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight,
340 int16_t targetLeft, int16_t targetRight)
344 if (srcRight != srcLeft) {
345 rv = ((target - srcLeft)*targetRight +
346 (srcRight - target)*targetLeft) / (srcRight - srcLeft);
354 * Uses the data points read from EEPROM to reconstruct the pdadc power table
355 * Called by ar2316SetPowerTable()
358 ar2316getGainBoundariesAndPdadcsForPowers(struct ath_hal *ah, uint16_t channel,
359 const RAW_DATA_STRUCT_2316 *pRawDataset,
360 uint16_t pdGainOverlap_t2,
361 int16_t *pMinCalPower, uint16_t pPdGainBoundaries[],
362 uint16_t pPdGainValues[], uint16_t pPDADCValues[])
364 struct ar2316State *priv = AR2316(ah);
365 #define VpdTable_L priv->vpdTable_L
366 #define VpdTable_R priv->vpdTable_R
367 #define VpdTable_I priv->vpdTable_I
369 int32_t ss;/* potentially -ve index for taking care of pdGainOverlap */
371 uint32_t numPdGainsUsed = 0;
373 * If desired to support -ve power levels in future, just
374 * change pwr_I_0 to signed 5-bits.
376 int16_t Pmin_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
377 /* to accomodate -ve power levels later on. */
378 int16_t Pmax_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
379 /* to accomodate -ve power levels later on */
383 uint32_t sizeCurrVpdTable, maxIndex, tgtIndex;
385 /* Get upper lower index */
386 GetLowerUpperIndex(channel, pRawDataset->pChannels,
387 pRawDataset->numChannels, &(idxL), &(idxR));
389 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
390 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
391 /* work backwards 'cause highest pdGain for lowest power */
392 numVpd = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].numVpd;
394 pPdGainValues[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pd_gain;
395 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0];
396 if (Pmin_t2[numPdGainsUsed] >pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]) {
397 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0];
399 Pmin_t2[numPdGainsUsed] = (int16_t)
400 (Pmin_t2[numPdGainsUsed] / 2);
401 Pmax_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[numVpd-1];
402 if (Pmax_t2[numPdGainsUsed] > pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1])
403 Pmax_t2[numPdGainsUsed] =
404 pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1];
405 Pmax_t2[numPdGainsUsed] = (int16_t)(Pmax_t2[numPdGainsUsed] / 2);
407 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
408 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0]),
409 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_L
412 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
413 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]),
414 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_R
416 for (kk = 0; kk < (uint16_t)(Pmax_t2[numPdGainsUsed] - Pmin_t2[numPdGainsUsed]); kk++) {
417 VpdTable_I[numPdGainsUsed][kk] =
419 channel, pRawDataset->pChannels[idxL], pRawDataset->pChannels[idxR],
420 (int16_t)VpdTable_L[numPdGainsUsed][kk], (int16_t)VpdTable_R[numPdGainsUsed][kk]);
422 /* fill VpdTable_I for this pdGain */
425 /* if this pdGain is used */
428 *pMinCalPower = Pmin_t2[0];
429 kk = 0; /* index for the final table */
430 for (ii = 0; ii < numPdGainsUsed; ii++) {
431 if (ii == (numPdGainsUsed - 1))
432 pPdGainBoundaries[ii] = Pmax_t2[ii] +
433 PD_GAIN_BOUNDARY_STRETCH_IN_HALF_DB;
435 pPdGainBoundaries[ii] = (uint16_t)
436 ((Pmax_t2[ii] + Pmin_t2[ii+1]) / 2 );
437 if (pPdGainBoundaries[ii] > 63) {
438 HALDEBUG(ah, HAL_DEBUG_ANY,
439 "%s: clamp pPdGainBoundaries[%d] %d\n",
440 __func__, ii, pPdGainBoundaries[ii]);/*XXX*/
441 pPdGainBoundaries[ii] = 63;
444 /* Find starting index for this pdGain */
446 ss = 0; /* for the first pdGain, start from index 0 */
448 ss = (pPdGainBoundaries[ii-1] - Pmin_t2[ii]) -
450 Vpd_step = (uint16_t)(VpdTable_I[ii][1] - VpdTable_I[ii][0]);
451 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
453 *-ve ss indicates need to extrapolate data below for this pdGain
456 tmpVal = (int16_t)(VpdTable_I[ii][0] + ss*Vpd_step);
457 pPDADCValues[kk++] = (uint16_t)((tmpVal < 0) ? 0 : tmpVal);
461 sizeCurrVpdTable = Pmax_t2[ii] - Pmin_t2[ii];
462 tgtIndex = pPdGainBoundaries[ii] + pdGainOverlap_t2 - Pmin_t2[ii];
463 maxIndex = (tgtIndex < sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;
465 while (ss < (int16_t)maxIndex)
466 pPDADCValues[kk++] = VpdTable_I[ii][ss++];
468 Vpd_step = (uint16_t)(VpdTable_I[ii][sizeCurrVpdTable-1] -
469 VpdTable_I[ii][sizeCurrVpdTable-2]);
470 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
472 * for last gain, pdGainBoundary == Pmax_t2, so will
473 * have to extrapolate
475 if (tgtIndex > maxIndex) { /* need to extrapolate above */
476 while(ss < (int16_t)tgtIndex) {
478 (VpdTable_I[ii][sizeCurrVpdTable-1] +
479 (ss-maxIndex)*Vpd_step);
480 pPDADCValues[kk++] = (tmpVal > 127) ?
484 } /* extrapolated above */
485 } /* for all pdGainUsed */
487 while (ii < MAX_NUM_PDGAINS_PER_CHANNEL) {
488 pPdGainBoundaries[ii] = pPdGainBoundaries[ii-1];
492 pPDADCValues[kk] = pPDADCValues[kk-1];
496 return numPdGainsUsed;
503 ar2316SetPowerTable(struct ath_hal *ah,
504 int16_t *minPower, int16_t *maxPower,
505 const struct ieee80211_channel *chan,
508 struct ath_hal_5212 *ahp = AH5212(ah);
509 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
510 const RAW_DATA_STRUCT_2316 *pRawDataset = AH_NULL;
511 uint16_t pdGainOverlap_t2;
512 int16_t minCalPower2316_t2;
513 uint16_t *pdadcValues = ahp->ah_pcdacTable;
514 uint16_t gainBoundaries[4];
515 uint32_t reg32, regoffset;
516 int i, numPdGainsUsed;
517 #ifndef AH_USE_INIPDGAIN
521 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan 0x%x flag 0x%x\n",
522 __func__, chan->ic_freq, chan->ic_flags);
524 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
525 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
526 else if (IEEE80211_IS_CHAN_B(chan))
527 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
529 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: illegal mode\n", __func__);
533 pdGainOverlap_t2 = (uint16_t) SM(OS_REG_READ(ah, AR_PHY_TPCRG5),
534 AR_PHY_TPCRG5_PD_GAIN_OVERLAP);
536 numPdGainsUsed = ar2316getGainBoundariesAndPdadcsForPowers(ah,
537 chan->channel, pRawDataset, pdGainOverlap_t2,
538 &minCalPower2316_t2,gainBoundaries, rfXpdGain, pdadcValues);
539 HALASSERT(1 <= numPdGainsUsed && numPdGainsUsed <= 3);
541 #ifdef AH_USE_INIPDGAIN
543 * Use pd_gains curve from eeprom; Atheros always uses
544 * the default curve from the ini file but some vendors
545 * (e.g. Zcomax) want to override this curve and not
546 * honoring their settings results in tx power 5dBm low.
548 OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
549 (pRawDataset->pDataPerChannel[0].numPdGains - 1));
551 tpcrg1 = OS_REG_READ(ah, AR_PHY_TPCRG1);
552 tpcrg1 = (tpcrg1 &~ AR_PHY_TPCRG1_NUM_PD_GAIN)
553 | SM(numPdGainsUsed-1, AR_PHY_TPCRG1_NUM_PD_GAIN);
554 switch (numPdGainsUsed) {
556 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING3;
557 tpcrg1 |= SM(rfXpdGain[2], AR_PHY_TPCRG1_PDGAIN_SETTING3);
560 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING2;
561 tpcrg1 |= SM(rfXpdGain[1], AR_PHY_TPCRG1_PDGAIN_SETTING2);
564 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING1;
565 tpcrg1 |= SM(rfXpdGain[0], AR_PHY_TPCRG1_PDGAIN_SETTING1);
569 if (tpcrg1 != OS_REG_READ(ah, AR_PHY_TPCRG1))
570 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: using non-default "
571 "pd_gains (default 0x%x, calculated 0x%x)\n",
572 __func__, OS_REG_READ(ah, AR_PHY_TPCRG1), tpcrg1);
574 OS_REG_WRITE(ah, AR_PHY_TPCRG1, tpcrg1);
578 * Note the pdadc table may not start at 0 dBm power, could be
579 * negative or greater than 0. Need to offset the power
580 * values by the amount of minPower for griffin
582 if (minCalPower2316_t2 != 0)
583 ahp->ah_txPowerIndexOffset = (int16_t)(0 - minCalPower2316_t2);
585 ahp->ah_txPowerIndexOffset = 0;
587 /* Finally, write the power values into the baseband power table */
588 regoffset = 0x9800 + (672 <<2); /* beginning of pdadc table in griffin */
589 for (i = 0; i < 32; i++) {
590 reg32 = ((pdadcValues[4*i + 0] & 0xFF) << 0) |
591 ((pdadcValues[4*i + 1] & 0xFF) << 8) |
592 ((pdadcValues[4*i + 2] & 0xFF) << 16) |
593 ((pdadcValues[4*i + 3] & 0xFF) << 24) ;
594 OS_REG_WRITE(ah, regoffset, reg32);
598 OS_REG_WRITE(ah, AR_PHY_TPCRG5,
599 SM(pdGainOverlap_t2, AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
600 SM(gainBoundaries[0], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
601 SM(gainBoundaries[1], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
602 SM(gainBoundaries[2], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
603 SM(gainBoundaries[3], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
609 ar2316GetMinPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2316 *data)
612 uint16_t Pmin=0,numVpd;
614 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
615 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
616 /* work backwards 'cause highest pdGain for lowest power */
617 numVpd = data->pDataPerPDGain[jj].numVpd;
619 Pmin = data->pDataPerPDGain[jj].pwr_t4[0];
627 ar2316GetMaxPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2316 *data)
630 uint16_t Pmax=0,numVpd;
632 for (ii=0; ii< MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
633 /* work forwards cuase lowest pdGain for highest power */
634 numVpd = data->pDataPerPDGain[ii].numVpd;
636 Pmax = data->pDataPerPDGain[ii].pwr_t4[numVpd-1];
644 ar2316GetChannelMaxMinPower(struct ath_hal *ah,
645 const struct ieee80211_channel *chan,
646 int16_t *maxPow, int16_t *minPow)
648 uint16_t freq = chan->ic_freq; /* NB: never mapped */
649 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
650 const RAW_DATA_STRUCT_2316 *pRawDataset = AH_NULL;
651 const RAW_DATA_PER_CHANNEL_2316 *data=AH_NULL;
652 uint16_t numChannels;
653 int totalD,totalF, totalMin,last, i;
657 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
658 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
659 else if (IEEE80211_IS_CHAN_B(chan))
660 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
664 numChannels = pRawDataset->numChannels;
665 data = pRawDataset->pDataPerChannel;
667 /* Make sure the channel is in the range of the TP values
673 if ((freq < data[0].channelValue) ||
674 (freq > data[numChannels-1].channelValue)) {
675 if (freq < data[0].channelValue) {
676 *maxPow = ar2316GetMaxPower(ah, &data[0]);
677 *minPow = ar2316GetMinPower(ah, &data[0]);
680 *maxPow = ar2316GetMaxPower(ah, &data[numChannels - 1]);
681 *minPow = ar2316GetMinPower(ah, &data[numChannels - 1]);
686 /* Linearly interpolate the power value now */
687 for (last=0,i=0; (i<numChannels) && (freq > data[i].channelValue);
689 totalD = data[i].channelValue - data[last].channelValue;
691 totalF = ar2316GetMaxPower(ah, &data[i]) - ar2316GetMaxPower(ah, &data[last]);
692 *maxPow = (int8_t) ((totalF*(freq-data[last].channelValue) +
693 ar2316GetMaxPower(ah, &data[last])*totalD)/totalD);
694 totalMin = ar2316GetMinPower(ah, &data[i]) - ar2316GetMinPower(ah, &data[last]);
695 *minPow = (int8_t) ((totalMin*(freq-data[last].channelValue) +
696 ar2316GetMinPower(ah, &data[last])*totalD)/totalD);
699 if (freq == data[i].channelValue) {
700 *maxPow = ar2316GetMaxPower(ah, &data[i]);
701 *minPow = ar2316GetMinPower(ah, &data[i]);
709 * Free memory for analog bank scratch buffers
712 ar2316RfDetach(struct ath_hal *ah)
714 struct ath_hal_5212 *ahp = AH5212(ah);
716 HALASSERT(ahp->ah_rfHal != AH_NULL);
717 ath_hal_free(ahp->ah_rfHal);
718 ahp->ah_rfHal = AH_NULL;
722 * Allocate memory for private state.
723 * Scratch Buffer will be reinitialized every reset so no need to zero now
726 ar2316RfAttach(struct ath_hal *ah, HAL_STATUS *status)
728 struct ath_hal_5212 *ahp = AH5212(ah);
729 struct ar2316State *priv;
731 HALASSERT(ah->ah_magic == AR5212_MAGIC);
733 HALASSERT(ahp->ah_rfHal == AH_NULL);
734 priv = ath_hal_malloc(sizeof(struct ar2316State));
735 if (priv == AH_NULL) {
736 HALDEBUG(ah, HAL_DEBUG_ANY,
737 "%s: cannot allocate private state\n", __func__);
738 *status = HAL_ENOMEM; /* XXX */
741 priv->base.rfDetach = ar2316RfDetach;
742 priv->base.writeRegs = ar2316WriteRegs;
743 priv->base.getRfBank = ar2316GetRfBank;
744 priv->base.setChannel = ar2316SetChannel;
745 priv->base.setRfRegs = ar2316SetRfRegs;
746 priv->base.setPowerTable = ar2316SetPowerTable;
747 priv->base.getChannelMaxMinPower = ar2316GetChannelMaxMinPower;
748 priv->base.getNfAdjust = ar5212GetNfAdjust;
750 ahp->ah_pcdacTable = priv->pcdacTable;
751 ahp->ah_pcdacTableSize = sizeof(priv->pcdacTable);
752 ahp->ah_rfHal = &priv->base;
754 ahp->ah_cwCalRequire = AH_TRUE; /* force initial cal */
760 ar2316Probe(struct ath_hal *ah)
764 AH_RF(RF2316, ar2316Probe, ar2316RfAttach);