2 * Copyright (c) 2002-2008 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 * $Id: ar2425.c,v 1.8 2008/11/16 21:33:05 sam Exp $
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"
32 #include "ar5212/ar5212.ini"
34 #define N(a) (sizeof(a)/sizeof(a[0]))
37 RF_HAL_FUNCS base; /* public state, must be first */
38 uint16_t pcdacTable[PWR_TABLE_SIZE_2413];
40 uint32_t Bank1Data[N(ar5212Bank1_2425)];
41 uint32_t Bank2Data[N(ar5212Bank2_2425)];
42 uint32_t Bank3Data[N(ar5212Bank3_2425)];
43 uint32_t Bank6Data[N(ar5212Bank6_2425)]; /* 2417 is same size */
44 uint32_t Bank7Data[N(ar5212Bank7_2425)];
46 #define AR2425(ah) ((struct ar2425State *) AH5212(ah)->ah_rfHal)
48 extern void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32,
49 uint32_t numBits, uint32_t firstBit, uint32_t column);
52 ar2425WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex,
55 HAL_INI_WRITE_ARRAY(ah, ar5212Modes_2425, modesIndex, writes);
56 HAL_INI_WRITE_ARRAY(ah, ar5212Common_2425, 1, writes);
57 HAL_INI_WRITE_ARRAY(ah, ar5212BB_RfGain_2425, freqIndex, writes);
60 * for SWAN similar to Condor
61 * Bit 0 enables link to go to L1 when MAC goes to sleep.
62 * Bit 3 enables the loop back the link down to reset.
64 if (IS_PCIE(ah) && ath_hal_pcieL1SKPEnable) {
65 OS_REG_WRITE(ah, AR_PCIE_PMC,
66 AR_PCIE_PMC_ENA_L1 | AR_PCIE_PMC_ENA_RESET);
69 * for Standby issue in Swan/Condor.
70 * Bit 9 (MAC_WOW_PWR_STATE_MASK_D2)to be set to avoid skips
71 * before last Training Sequence 2 (TS2)
72 * Bit 8 (MAC_WOW_PWR_STATE_MASK_D1)to be unset to assert
73 * Power Reset along with PCI Reset
75 OS_REG_SET_BIT(ah, AR_PCIE_PMC, MAC_WOW_PWR_STATE_MASK_D2);
80 * Take the MHz channel value and set the Channel value
82 * ASSUMES: Writes enabled to analog bus
85 ar2425SetChannel(struct ath_hal *ah, HAL_CHANNEL_INTERNAL *chan)
87 uint32_t channelSel = 0;
88 uint32_t bModeSynth = 0;
89 uint32_t aModeRefSel = 0;
93 OS_MARK(ah, AH_MARK_SETCHANNEL, chan->channel);
95 if (chan->channel < 4800) {
98 channelSel = chan->channel - 2272;
99 channelSel = ath_hal_reverseBits(channelSel, 8);
101 txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL);
102 if (chan->channel == 2484) {
103 // Enable channel spreading for channel 14
104 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
105 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
107 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
108 txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
111 } else if (((chan->channel % 5) == 2) && (chan->channel <= 5435)) {
112 freq = chan->channel - 2; /* Align to even 5MHz raster */
113 channelSel = ath_hal_reverseBits(
114 (uint32_t)(((freq - 4800)*10)/25 + 1), 8);
115 aModeRefSel = ath_hal_reverseBits(0, 2);
116 } else if ((chan->channel % 20) == 0 && chan->channel >= 5120) {
117 channelSel = ath_hal_reverseBits(
118 ((chan->channel - 4800) / 20 << 2), 8);
119 aModeRefSel = ath_hal_reverseBits(1, 2);
120 } else if ((chan->channel % 10) == 0) {
121 channelSel = ath_hal_reverseBits(
122 ((chan->channel - 4800) / 10 << 1), 8);
123 aModeRefSel = ath_hal_reverseBits(1, 2);
124 } else if ((chan->channel % 5) == 0) {
125 channelSel = ath_hal_reverseBits(
126 (chan->channel - 4800) / 5, 8);
127 aModeRefSel = ath_hal_reverseBits(1, 2);
129 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel %u MHz\n",
130 __func__, chan->channel);
134 reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) |
136 OS_REG_WRITE(ah, AR_PHY(0x27), reg32 & 0xff);
139 OS_REG_WRITE(ah, AR_PHY(0x36), reg32 & 0x7f);
141 AH_PRIVATE(ah)->ah_curchan = chan;
146 * Reads EEPROM header info from device structure and programs
149 * REQUIRES: Access to the analog rf device
152 ar2425SetRfRegs(struct ath_hal *ah, HAL_CHANNEL_INTERNAL *chan, uint16_t modesIndex, uint16_t *rfXpdGain)
154 #define RF_BANK_SETUP(_priv, _ix, _col) do { \
156 for (i = 0; i < N(ar5212Bank##_ix##_2425); i++) \
157 (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_2425[i][_col];\
159 struct ath_hal_5212 *ahp = AH5212(ah);
160 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
161 struct ar2425State *priv = AR2425(ah);
162 uint16_t ob2GHz = 0, db2GHz = 0;
165 HALDEBUG(ah, HAL_DEBUG_RFPARAM,
166 "==>%s:chan 0x%x flag 0x%x modesIndex 0x%x\n",
167 __func__, chan->channel, chan->channelFlags, modesIndex);
171 /* Setup rf parameters */
172 switch (chan->channelFlags & CHANNEL_ALL) {
174 ob2GHz = ee->ee_obFor24;
175 db2GHz = ee->ee_dbFor24;
179 ob2GHz = ee->ee_obFor24g;
180 db2GHz = ee->ee_dbFor24g;
183 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n",
184 __func__, chan->channelFlags);
189 RF_BANK_SETUP(priv, 1, 1);
192 RF_BANK_SETUP(priv, 2, modesIndex);
195 RF_BANK_SETUP(priv, 3, modesIndex);
198 RF_BANK_SETUP(priv, 6, modesIndex);
200 ar5212ModifyRfBuffer(priv->Bank6Data, ob2GHz, 3, 193, 0);
201 ar5212ModifyRfBuffer(priv->Bank6Data, db2GHz, 3, 190, 0);
204 RF_BANK_SETUP(priv, 7, modesIndex);
206 /* Write Analog registers */
207 HAL_INI_WRITE_BANK(ah, ar5212Bank1_2425, priv->Bank1Data, regWrites);
208 HAL_INI_WRITE_BANK(ah, ar5212Bank2_2425, priv->Bank2Data, regWrites);
209 HAL_INI_WRITE_BANK(ah, ar5212Bank3_2425, priv->Bank3Data, regWrites);
211 HALASSERT(N(ar5212Bank6_2425) == N(ar5212Bank6_2417));
212 HAL_INI_WRITE_BANK(ah, ar5212Bank6_2417, priv->Bank6Data,
215 HAL_INI_WRITE_BANK(ah, ar5212Bank6_2425, priv->Bank6Data,
217 HAL_INI_WRITE_BANK(ah, ar5212Bank7_2425, priv->Bank7Data, regWrites);
219 /* Now that we have reprogrammed rfgain value, clear the flag. */
220 ahp->ah_rfgainState = HAL_RFGAIN_INACTIVE;
222 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "<==%s\n", __func__);
228 * Return a reference to the requested RF Bank.
231 ar2425GetRfBank(struct ath_hal *ah, int bank)
233 struct ar2425State *priv = AR2425(ah);
235 HALASSERT(priv != AH_NULL);
237 case 1: return priv->Bank1Data;
238 case 2: return priv->Bank2Data;
239 case 3: return priv->Bank3Data;
240 case 6: return priv->Bank6Data;
241 case 7: return priv->Bank7Data;
243 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown RF Bank %d requested\n",
249 * Return indices surrounding the value in sorted integer lists.
251 * NB: the input list is assumed to be sorted in ascending order
254 GetLowerUpperIndex(int16_t v, const uint16_t *lp, uint16_t listSize,
255 uint32_t *vlo, uint32_t *vhi)
258 const uint16_t *ep = lp+listSize;
262 * Check first and last elements for out-of-bounds conditions.
264 if (target < lp[0]) {
268 if (target >= ep[-1]) {
269 *vlo = *vhi = listSize - 1;
273 /* look for value being near or between 2 values in list */
274 for (tp = lp; tp < ep; tp++) {
276 * If value is close to the current value of the list
277 * then target is not between values, it is one of the values
280 *vlo = *vhi = tp - (const uint16_t *) lp;
284 * Look for value being between current value and next value
285 * if so return these 2 values
287 if (target < tp[1]) {
288 *vlo = tp - (const uint16_t *) lp;
296 * Fill the Vpdlist for indices Pmax-Pmin
299 ar2425FillVpdTable(uint32_t pdGainIdx, int16_t Pmin, int16_t Pmax,
300 const int16_t *pwrList, const uint16_t *VpdList,
301 uint16_t numIntercepts,
302 uint16_t retVpdList[][64])
305 int16_t currPwr = (int16_t)(2*Pmin);
306 /* since Pmin is pwr*2 and pwrList is 4*pwr */
312 if (numIntercepts < 2)
315 while (ii <= (uint16_t)(Pmax - Pmin)) {
316 GetLowerUpperIndex(currPwr, (const uint16_t *) pwrList,
317 numIntercepts, &(idxL), &(idxR));
319 idxR = 1; /* extrapolate below */
320 if (idxL == (uint32_t)(numIntercepts - 1))
321 idxL = numIntercepts - 2; /* extrapolate above */
322 if (pwrList[idxL] == pwrList[idxR])
326 (((currPwr - pwrList[idxL])*VpdList[idxR]+
327 (pwrList[idxR] - currPwr)*VpdList[idxL])/
328 (pwrList[idxR] - pwrList[idxL]));
329 retVpdList[pdGainIdx][ii] = kk;
331 currPwr += 2; /* half dB steps */
338 * Returns interpolated or the scaled up interpolated value
341 interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight,
342 int16_t targetLeft, int16_t targetRight)
346 if (srcRight != srcLeft) {
347 rv = ((target - srcLeft)*targetRight +
348 (srcRight - target)*targetLeft) / (srcRight - srcLeft);
356 * Uses the data points read from EEPROM to reconstruct the pdadc power table
357 * Called by ar2425SetPowerTable()
360 ar2425getGainBoundariesAndPdadcsForPowers(struct ath_hal *ah, uint16_t channel,
361 const RAW_DATA_STRUCT_2413 *pRawDataset,
362 uint16_t pdGainOverlap_t2,
363 int16_t *pMinCalPower, uint16_t pPdGainBoundaries[],
364 uint16_t pPdGainValues[], uint16_t pPDADCValues[])
366 /* Note the items statically allocated below are to reduce stack usage */
368 int32_t ss;/* potentially -ve index for taking care of pdGainOverlap */
370 uint32_t numPdGainsUsed = 0;
371 static uint16_t VpdTable_L[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB];
372 /* filled out Vpd table for all pdGains (chanL) */
373 static uint16_t VpdTable_R[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB];
374 /* filled out Vpd table for all pdGains (chanR) */
375 static uint16_t VpdTable_I[MAX_NUM_PDGAINS_PER_CHANNEL][MAX_PWR_RANGE_IN_HALF_DB];
376 /* filled out Vpd table for all pdGains (interpolated) */
378 * If desired to support -ve power levels in future, just
379 * change pwr_I_0 to signed 5-bits.
381 static int16_t Pmin_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
382 /* to accomodate -ve power levels later on. */
383 static int16_t Pmax_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
384 /* to accomodate -ve power levels later on */
388 uint32_t sizeCurrVpdTable, maxIndex, tgtIndex;
390 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "==>%s:\n", __func__);
392 /* Get upper lower index */
393 GetLowerUpperIndex(channel, pRawDataset->pChannels,
394 pRawDataset->numChannels, &(idxL), &(idxR));
396 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
397 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
398 /* work backwards 'cause highest pdGain for lowest power */
399 numVpd = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].numVpd;
401 pPdGainValues[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pd_gain;
402 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0];
403 if (Pmin_t2[numPdGainsUsed] >pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]) {
404 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0];
406 Pmin_t2[numPdGainsUsed] = (int16_t)
407 (Pmin_t2[numPdGainsUsed] / 2);
408 Pmax_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[numVpd-1];
409 if (Pmax_t2[numPdGainsUsed] > pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1])
410 Pmax_t2[numPdGainsUsed] =
411 pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1];
412 Pmax_t2[numPdGainsUsed] = (int16_t)(Pmax_t2[numPdGainsUsed] / 2);
414 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
415 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0]),
416 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_L
419 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
420 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]),
421 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_R
423 for (kk = 0; kk < (uint16_t)(Pmax_t2[numPdGainsUsed] - Pmin_t2[numPdGainsUsed]); kk++) {
424 VpdTable_I[numPdGainsUsed][kk] =
426 channel, pRawDataset->pChannels[idxL], pRawDataset->pChannels[idxR],
427 (int16_t)VpdTable_L[numPdGainsUsed][kk], (int16_t)VpdTable_R[numPdGainsUsed][kk]);
429 /* fill VpdTable_I for this pdGain */
432 /* if this pdGain is used */
435 *pMinCalPower = Pmin_t2[0];
436 kk = 0; /* index for the final table */
437 for (ii = 0; ii < numPdGainsUsed; ii++) {
438 if (ii == (numPdGainsUsed - 1))
439 pPdGainBoundaries[ii] = Pmax_t2[ii] +
440 PD_GAIN_BOUNDARY_STRETCH_IN_HALF_DB;
442 pPdGainBoundaries[ii] = (uint16_t)
443 ((Pmax_t2[ii] + Pmin_t2[ii+1]) / 2 );
445 /* Find starting index for this pdGain */
447 ss = 0; /* for the first pdGain, start from index 0 */
449 ss = (pPdGainBoundaries[ii-1] - Pmin_t2[ii]) -
451 Vpd_step = (uint16_t)(VpdTable_I[ii][1] - VpdTable_I[ii][0]);
452 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
454 *-ve ss indicates need to extrapolate data below for this pdGain
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)
467 pPDADCValues[kk++] = VpdTable_I[ii][ss++];
469 Vpd_step = (uint16_t)(VpdTable_I[ii][sizeCurrVpdTable-1] -
470 VpdTable_I[ii][sizeCurrVpdTable-2]);
471 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
473 * for last gain, pdGainBoundary == Pmax_t2, so will
474 * have to extrapolate
476 if (tgtIndex > maxIndex) { /* need to extrapolate above */
477 while(ss < (int16_t)tgtIndex) {
479 (VpdTable_I[ii][sizeCurrVpdTable-1] +
480 (ss-maxIndex)*Vpd_step);
481 pPDADCValues[kk++] = (tmpVal > 127) ?
485 } /* extrapolated above */
486 } /* for all pdGainUsed */
488 while (ii < MAX_NUM_PDGAINS_PER_CHANNEL) {
489 pPdGainBoundaries[ii] = pPdGainBoundaries[ii-1];
493 pPDADCValues[kk] = pPDADCValues[kk-1];
497 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "<==%s\n", __func__);
501 /* Same as 2413 set power table */
503 ar2425SetPowerTable(struct ath_hal *ah,
504 int16_t *minPower, int16_t *maxPower, HAL_CHANNEL_INTERNAL *chan,
507 struct ath_hal_5212 *ahp = AH5212(ah);
508 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
509 const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL;
510 uint16_t pdGainOverlap_t2;
511 int16_t minCalPower2413_t2;
512 uint16_t *pdadcValues = ahp->ah_pcdacTable;
513 uint16_t gainBoundaries[4];
514 uint32_t i, reg32, regoffset;
516 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s:chan 0x%x flag 0x%x\n",
517 __func__, chan->channel,chan->channelFlags);
519 if (IS_CHAN_G(chan) || IS_CHAN_108G(chan))
520 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
521 else if (IS_CHAN_B(chan))
522 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
524 HALDEBUG(ah, HAL_DEBUG_ANY, "%s:illegal mode\n", __func__);
528 pdGainOverlap_t2 = (uint16_t) SM(OS_REG_READ(ah, AR_PHY_TPCRG5),
529 AR_PHY_TPCRG5_PD_GAIN_OVERLAP);
531 ar2425getGainBoundariesAndPdadcsForPowers(ah, chan->channel,
532 pRawDataset, pdGainOverlap_t2,&minCalPower2413_t2,gainBoundaries,
533 rfXpdGain, pdadcValues);
535 OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
536 (pRawDataset->pDataPerChannel[0].numPdGains - 1));
539 * Note the pdadc table may not start at 0 dBm power, could be
540 * negative or greater than 0. Need to offset the power
541 * values by the amount of minPower for griffin
543 if (minCalPower2413_t2 != 0)
544 ahp->ah_txPowerIndexOffset = (int16_t)(0 - minCalPower2413_t2);
546 ahp->ah_txPowerIndexOffset = 0;
548 /* Finally, write the power values into the baseband power table */
549 regoffset = 0x9800 + (672 <<2); /* beginning of pdadc table in griffin */
550 for (i = 0; i < 32; i++) {
551 reg32 = ((pdadcValues[4*i + 0] & 0xFF) << 0) |
552 ((pdadcValues[4*i + 1] & 0xFF) << 8) |
553 ((pdadcValues[4*i + 2] & 0xFF) << 16) |
554 ((pdadcValues[4*i + 3] & 0xFF) << 24) ;
555 OS_REG_WRITE(ah, regoffset, reg32);
559 OS_REG_WRITE(ah, AR_PHY_TPCRG5,
560 SM(pdGainOverlap_t2, AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
561 SM(gainBoundaries[0], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
562 SM(gainBoundaries[1], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
563 SM(gainBoundaries[2], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
564 SM(gainBoundaries[3], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
570 ar2425GetMinPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)
573 uint16_t Pmin=0,numVpd;
575 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
576 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
577 /* work backwards 'cause highest pdGain for lowest power */
578 numVpd = data->pDataPerPDGain[jj].numVpd;
580 Pmin = data->pDataPerPDGain[jj].pwr_t4[0];
588 ar2425GetMaxPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)
591 uint16_t Pmax=0,numVpd;
593 for (ii=0; ii< MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
594 /* work forwards cuase lowest pdGain for highest power */
595 numVpd = data->pDataPerPDGain[ii].numVpd;
597 Pmax = data->pDataPerPDGain[ii].pwr_t4[numVpd-1];
606 ar2425GetChannelMaxMinPower(struct ath_hal *ah, HAL_CHANNEL *chan,
607 int16_t *maxPow, int16_t *minPow)
609 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
610 const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL;
611 const RAW_DATA_PER_CHANNEL_2413 *data = AH_NULL;
612 uint16_t numChannels;
613 int totalD,totalF, totalMin,last, i;
617 if (IS_CHAN_G(chan) || IS_CHAN_108G(chan))
618 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
619 else if (IS_CHAN_B(chan))
620 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
624 numChannels = pRawDataset->numChannels;
625 data = pRawDataset->pDataPerChannel;
627 /* Make sure the channel is in the range of the TP values
633 if ((chan->channel < data[0].channelValue) ||
634 (chan->channel > data[numChannels-1].channelValue)) {
635 if (chan->channel < data[0].channelValue) {
636 *maxPow = ar2425GetMaxPower(ah, &data[0]);
637 *minPow = ar2425GetMinPower(ah, &data[0]);
640 *maxPow = ar2425GetMaxPower(ah, &data[numChannels - 1]);
641 *minPow = ar2425GetMinPower(ah, &data[numChannels - 1]);
646 /* Linearly interpolate the power value now */
647 for (last=0,i=0; (i<numChannels) && (chan->channel > data[i].channelValue);
649 totalD = data[i].channelValue - data[last].channelValue;
651 totalF = ar2425GetMaxPower(ah, &data[i]) - ar2425GetMaxPower(ah, &data[last]);
652 *maxPow = (int8_t) ((totalF*(chan->channel-data[last].channelValue) +
653 ar2425GetMaxPower(ah, &data[last])*totalD)/totalD);
654 totalMin = ar2425GetMinPower(ah, &data[i]) - ar2425GetMinPower(ah, &data[last]);
655 *minPow = (int8_t) ((totalMin*(chan->channel-data[last].channelValue) +
656 ar2425GetMinPower(ah, &data[last])*totalD)/totalD);
659 if (chan->channel == data[i].channelValue) {
660 *maxPow = ar2425GetMaxPower(ah, &data[i]);
661 *minPow = ar2425GetMinPower(ah, &data[i]);
669 * Free memory for analog bank scratch buffers
672 ar2425RfDetach(struct ath_hal *ah)
674 struct ath_hal_5212 *ahp = AH5212(ah);
676 HALASSERT(ahp->ah_rfHal != AH_NULL);
677 ath_hal_free(ahp->ah_rfHal);
678 ahp->ah_rfHal = AH_NULL;
682 * Allocate memory for analog bank scratch buffers
683 * Scratch Buffer will be reinitialized every reset so no need to zero now
686 ar2425RfAttach(struct ath_hal *ah, HAL_STATUS *status)
688 struct ath_hal_5212 *ahp = AH5212(ah);
689 struct ar2425State *priv;
691 HALASSERT(ah->ah_magic == AR5212_MAGIC);
693 HALASSERT(ahp->ah_rfHal == AH_NULL);
694 priv = ath_hal_malloc(sizeof(struct ar2425State));
695 if (priv == AH_NULL) {
696 HALDEBUG(ah, HAL_DEBUG_ANY,
697 "%s: cannot allocate private state\n", __func__);
698 *status = HAL_ENOMEM; /* XXX */
701 priv->base.rfDetach = ar2425RfDetach;
702 priv->base.writeRegs = ar2425WriteRegs;
703 priv->base.getRfBank = ar2425GetRfBank;
704 priv->base.setChannel = ar2425SetChannel;
705 priv->base.setRfRegs = ar2425SetRfRegs;
706 priv->base.setPowerTable = ar2425SetPowerTable;
707 priv->base.getChannelMaxMinPower = ar2425GetChannelMaxMinPower;
708 priv->base.getNfAdjust = ar5212GetNfAdjust;
710 ahp->ah_pcdacTable = priv->pcdacTable;
711 ahp->ah_pcdacTableSize = sizeof(priv->pcdacTable);
712 ahp->ah_rfHal = &priv->base;
718 ar2425Probe(struct ath_hal *ah)
720 return IS_2425(ah) || IS_2417(ah);
722 AH_RF(RF2425, ar2425Probe, ar2425RfAttach);