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/ar2317.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 typedef RAW_DATA_STRUCT_2413 RAW_DATA_STRUCT_2317;
35 typedef RAW_DATA_PER_CHANNEL_2413 RAW_DATA_PER_CHANNEL_2317;
36 #define PWR_TABLE_SIZE_2317 PWR_TABLE_SIZE_2413
39 RF_HAL_FUNCS base; /* public state, must be first */
40 uint16_t pcdacTable[PWR_TABLE_SIZE_2317];
42 uint32_t Bank1Data[NELEM(ar5212Bank1_2317)];
43 uint32_t Bank2Data[NELEM(ar5212Bank2_2317)];
44 uint32_t Bank3Data[NELEM(ar5212Bank3_2317)];
45 uint32_t Bank6Data[NELEM(ar5212Bank6_2317)];
46 uint32_t Bank7Data[NELEM(ar5212Bank7_2317)];
49 * Private state for reduced stack usage.
51 /* filled out Vpd table for all pdGains (chanL) */
52 uint16_t vpdTable_L[MAX_NUM_PDGAINS_PER_CHANNEL]
53 [MAX_PWR_RANGE_IN_HALF_DB];
54 /* filled out Vpd table for all pdGains (chanR) */
55 uint16_t vpdTable_R[MAX_NUM_PDGAINS_PER_CHANNEL]
56 [MAX_PWR_RANGE_IN_HALF_DB];
57 /* filled out Vpd table for all pdGains (interpolated) */
58 uint16_t vpdTable_I[MAX_NUM_PDGAINS_PER_CHANNEL]
59 [MAX_PWR_RANGE_IN_HALF_DB];
61 #define AR2317(ah) ((struct ar2317State *) AH5212(ah)->ah_rfHal)
63 extern void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32,
64 uint32_t numBits, uint32_t firstBit, uint32_t column);
67 ar2317WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex,
70 HAL_INI_WRITE_ARRAY(ah, ar5212Modes_2317, modesIndex, writes);
71 HAL_INI_WRITE_ARRAY(ah, ar5212Common_2317, 1, writes);
72 HAL_INI_WRITE_ARRAY(ah, ar5212BB_RfGain_2317, freqIndex, writes);
76 * Take the MHz channel value and set the Channel value
78 * ASSUMES: Writes enabled to analog bus
81 ar2317SetChannel(struct ath_hal *ah, const struct ieee80211_channel *chan)
83 uint16_t freq = ath_hal_gethwchannel(ah, chan);
84 uint32_t channelSel = 0;
85 uint32_t bModeSynth = 0;
86 uint32_t aModeRefSel = 0;
89 OS_MARK(ah, AH_MARK_SETCHANNEL, freq);
93 channelSel = freq - 2272 ;
94 channelSel = ath_hal_reverseBits(channelSel, 8);
96 txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL);
98 /* Enable channel spreading for channel 14 */
99 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
100 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
102 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
103 txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
105 } else if ((freq % 20) == 0 && freq >= 5120) {
106 channelSel = ath_hal_reverseBits(
107 ((freq - 4800) / 20 << 2), 8);
108 aModeRefSel = ath_hal_reverseBits(3, 2);
109 } else if ((freq % 10) == 0) {
110 channelSel = ath_hal_reverseBits(
111 ((freq - 4800) / 10 << 1), 8);
112 aModeRefSel = ath_hal_reverseBits(2, 2);
113 } else if ((freq % 5) == 0) {
114 channelSel = ath_hal_reverseBits(
115 (freq - 4800) / 5, 8);
116 aModeRefSel = ath_hal_reverseBits(1, 2);
118 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel %u MHz\n",
123 reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) |
125 OS_REG_WRITE(ah, AR_PHY(0x27), reg32 & 0xff);
128 OS_REG_WRITE(ah, AR_PHY(0x36), reg32 & 0x7f);
130 AH_PRIVATE(ah)->ah_curchan = chan;
135 * Reads EEPROM header info from device structure and programs
138 * REQUIRES: Access to the analog rf device
141 ar2317SetRfRegs(struct ath_hal *ah,
142 const struct ieee80211_channel *chan,
143 uint16_t modesIndex, uint16_t *rfXpdGain)
145 #define RF_BANK_SETUP(_priv, _ix, _col) do { \
147 for (i = 0; i < NELEM(ar5212Bank##_ix##_2317); i++) \
148 (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_2317[i][_col];\
150 struct ath_hal_5212 *ahp = AH5212(ah);
151 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
152 uint16_t ob2GHz = 0, db2GHz = 0;
153 struct ar2317State *priv = AR2317(ah);
156 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan %u/0x%x modesIndex %u\n",
157 __func__, chan->ic_freq, chan->ic_flags, modesIndex);
161 /* Setup rf parameters */
162 if (IEEE80211_IS_CHAN_B(chan)) {
163 ob2GHz = ee->ee_obFor24;
164 db2GHz = ee->ee_dbFor24;
166 ob2GHz = ee->ee_obFor24g;
167 db2GHz = ee->ee_dbFor24g;
171 RF_BANK_SETUP(priv, 1, 1);
174 RF_BANK_SETUP(priv, 2, modesIndex);
177 RF_BANK_SETUP(priv, 3, modesIndex);
180 RF_BANK_SETUP(priv, 6, modesIndex);
182 ar5212ModifyRfBuffer(priv->Bank6Data, ob2GHz, 3, 193, 0);
183 ar5212ModifyRfBuffer(priv->Bank6Data, db2GHz, 3, 190, 0);
186 RF_BANK_SETUP(priv, 7, modesIndex);
188 /* Write Analog registers */
189 HAL_INI_WRITE_BANK(ah, ar5212Bank1_2317, priv->Bank1Data, regWrites);
190 HAL_INI_WRITE_BANK(ah, ar5212Bank2_2317, priv->Bank2Data, regWrites);
191 HAL_INI_WRITE_BANK(ah, ar5212Bank3_2317, priv->Bank3Data, regWrites);
192 HAL_INI_WRITE_BANK(ah, ar5212Bank6_2317, priv->Bank6Data, regWrites);
193 HAL_INI_WRITE_BANK(ah, ar5212Bank7_2317, priv->Bank7Data, regWrites);
194 /* Now that we have reprogrammed rfgain value, clear the flag. */
195 ahp->ah_rfgainState = HAL_RFGAIN_INACTIVE;
202 * Return a reference to the requested RF Bank.
205 ar2317GetRfBank(struct ath_hal *ah, int bank)
207 struct ar2317State *priv = AR2317(ah);
209 HALASSERT(priv != AH_NULL);
211 case 1: return priv->Bank1Data;
212 case 2: return priv->Bank2Data;
213 case 3: return priv->Bank3Data;
214 case 6: return priv->Bank6Data;
215 case 7: return priv->Bank7Data;
217 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown RF Bank %d requested\n",
223 * Return indices surrounding the value in sorted integer lists.
225 * NB: the input list is assumed to be sorted in ascending order
228 GetLowerUpperIndex(int16_t v, const uint16_t *lp, uint16_t listSize,
229 uint32_t *vlo, uint32_t *vhi)
232 const int16_t *ep = lp+listSize;
236 * Check first and last elements for out-of-bounds conditions.
238 if (target < lp[0]) {
242 if (target >= ep[-1]) {
243 *vlo = *vhi = listSize - 1;
247 /* look for value being near or between 2 values in list */
248 for (tp = lp; tp < ep; tp++) {
250 * If value is close to the current value of the list
251 * then target is not between values, it is one of the values
254 *vlo = *vhi = tp - (const int16_t *) lp;
258 * Look for value being between current value and next value
259 * if so return these 2 values
261 if (target < tp[1]) {
262 *vlo = tp - (const int16_t *) lp;
270 * Fill the Vpdlist for indices Pmax-Pmin
273 ar2317FillVpdTable(uint32_t pdGainIdx, int16_t Pmin, int16_t Pmax,
274 const int16_t *pwrList, const int16_t *VpdList,
275 uint16_t numIntercepts, uint16_t retVpdList[][64])
278 int16_t currPwr = (int16_t)(2*Pmin);
279 /* since Pmin is pwr*2 and pwrList is 4*pwr */
285 if (numIntercepts < 2)
288 while (ii <= (uint16_t)(Pmax - Pmin)) {
289 GetLowerUpperIndex(currPwr, pwrList, numIntercepts,
292 idxR = 1; /* extrapolate below */
293 if (idxL == (uint32_t)(numIntercepts - 1))
294 idxL = numIntercepts - 2; /* extrapolate above */
295 if (pwrList[idxL] == pwrList[idxR])
299 (((currPwr - pwrList[idxL])*VpdList[idxR]+
300 (pwrList[idxR] - currPwr)*VpdList[idxL])/
301 (pwrList[idxR] - pwrList[idxL]));
302 retVpdList[pdGainIdx][ii] = kk;
304 currPwr += 2; /* half dB steps */
311 * Returns interpolated or the scaled up interpolated value
314 interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight,
315 int16_t targetLeft, int16_t targetRight)
319 if (srcRight != srcLeft) {
320 rv = ((target - srcLeft)*targetRight +
321 (srcRight - target)*targetLeft) / (srcRight - srcLeft);
329 * Uses the data points read from EEPROM to reconstruct the pdadc power table
330 * Called by ar2317SetPowerTable()
333 ar2317getGainBoundariesAndPdadcsForPowers(struct ath_hal *ah, uint16_t channel,
334 const RAW_DATA_STRUCT_2317 *pRawDataset,
335 uint16_t pdGainOverlap_t2,
336 int16_t *pMinCalPower, uint16_t pPdGainBoundaries[],
337 uint16_t pPdGainValues[], uint16_t pPDADCValues[])
339 struct ar2317State *priv = AR2317(ah);
340 #define VpdTable_L priv->vpdTable_L
341 #define VpdTable_R priv->vpdTable_R
342 #define VpdTable_I priv->vpdTable_I
343 /* XXX excessive stack usage? */
345 int32_t ss;/* potentially -ve index for taking care of pdGainOverlap */
347 uint32_t numPdGainsUsed = 0;
349 * If desired to support -ve power levels in future, just
350 * change pwr_I_0 to signed 5-bits.
352 int16_t Pmin_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
353 /* to accomodate -ve power levels later on. */
354 int16_t Pmax_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
355 /* to accomodate -ve power levels later on */
359 uint32_t sizeCurrVpdTable, maxIndex, tgtIndex;
361 /* Get upper lower index */
362 GetLowerUpperIndex(channel, pRawDataset->pChannels,
363 pRawDataset->numChannels, &(idxL), &(idxR));
365 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
366 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
367 /* work backwards 'cause highest pdGain for lowest power */
368 numVpd = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].numVpd;
370 pPdGainValues[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pd_gain;
371 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0];
372 if (Pmin_t2[numPdGainsUsed] >pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]) {
373 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0];
375 Pmin_t2[numPdGainsUsed] = (int16_t)
376 (Pmin_t2[numPdGainsUsed] / 2);
377 Pmax_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[numVpd-1];
378 if (Pmax_t2[numPdGainsUsed] > pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1])
379 Pmax_t2[numPdGainsUsed] =
380 pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1];
381 Pmax_t2[numPdGainsUsed] = (int16_t)(Pmax_t2[numPdGainsUsed] / 2);
383 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
384 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0]),
385 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_L
388 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
389 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]),
390 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_R
392 for (kk = 0; kk < (uint16_t)(Pmax_t2[numPdGainsUsed] - Pmin_t2[numPdGainsUsed]); kk++) {
393 VpdTable_I[numPdGainsUsed][kk] =
395 channel, pRawDataset->pChannels[idxL], pRawDataset->pChannels[idxR],
396 (int16_t)VpdTable_L[numPdGainsUsed][kk], (int16_t)VpdTable_R[numPdGainsUsed][kk]);
398 /* fill VpdTable_I for this pdGain */
401 /* if this pdGain is used */
404 *pMinCalPower = Pmin_t2[0];
405 kk = 0; /* index for the final table */
406 for (ii = 0; ii < numPdGainsUsed; ii++) {
407 if (ii == (numPdGainsUsed - 1))
408 pPdGainBoundaries[ii] = Pmax_t2[ii] +
409 PD_GAIN_BOUNDARY_STRETCH_IN_HALF_DB;
411 pPdGainBoundaries[ii] = (uint16_t)
412 ((Pmax_t2[ii] + Pmin_t2[ii+1]) / 2 );
413 if (pPdGainBoundaries[ii] > 63) {
414 HALDEBUG(ah, HAL_DEBUG_ANY,
415 "%s: clamp pPdGainBoundaries[%d] %d\n",
416 __func__, ii, pPdGainBoundaries[ii]);/*XXX*/
417 pPdGainBoundaries[ii] = 63;
420 /* Find starting index for this pdGain */
422 ss = 0; /* for the first pdGain, start from index 0 */
424 ss = (pPdGainBoundaries[ii-1] - Pmin_t2[ii]) -
426 Vpd_step = (uint16_t)(VpdTable_I[ii][1] - VpdTable_I[ii][0]);
427 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
429 *-ve ss indicates need to extrapolate data below for this pdGain
432 tmpVal = (int16_t)(VpdTable_I[ii][0] + ss*Vpd_step);
433 pPDADCValues[kk++] = (uint16_t)((tmpVal < 0) ? 0 : tmpVal);
437 sizeCurrVpdTable = Pmax_t2[ii] - Pmin_t2[ii];
438 tgtIndex = pPdGainBoundaries[ii] + pdGainOverlap_t2 - Pmin_t2[ii];
439 maxIndex = (tgtIndex < sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;
441 while (ss < (int16_t)maxIndex)
442 pPDADCValues[kk++] = VpdTable_I[ii][ss++];
444 Vpd_step = (uint16_t)(VpdTable_I[ii][sizeCurrVpdTable-1] -
445 VpdTable_I[ii][sizeCurrVpdTable-2]);
446 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
448 * for last gain, pdGainBoundary == Pmax_t2, so will
449 * have to extrapolate
451 if (tgtIndex > maxIndex) { /* need to extrapolate above */
452 while(ss < (int16_t)tgtIndex) {
454 (VpdTable_I[ii][sizeCurrVpdTable-1] +
455 (ss-maxIndex)*Vpd_step);
456 pPDADCValues[kk++] = (tmpVal > 127) ?
460 } /* extrapolated above */
461 } /* for all pdGainUsed */
463 while (ii < MAX_NUM_PDGAINS_PER_CHANNEL) {
464 pPdGainBoundaries[ii] = pPdGainBoundaries[ii-1];
468 pPDADCValues[kk] = pPDADCValues[kk-1];
472 return numPdGainsUsed;
479 ar2317SetPowerTable(struct ath_hal *ah,
480 int16_t *minPower, int16_t *maxPower,
481 const struct ieee80211_channel *chan,
484 struct ath_hal_5212 *ahp = AH5212(ah);
485 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
486 const RAW_DATA_STRUCT_2317 *pRawDataset = AH_NULL;
487 uint16_t pdGainOverlap_t2;
488 int16_t minCalPower2317_t2;
489 uint16_t *pdadcValues = ahp->ah_pcdacTable;
490 uint16_t gainBoundaries[4];
491 uint32_t reg32, regoffset;
492 int i, numPdGainsUsed;
493 #ifndef AH_USE_INIPDGAIN
497 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan 0x%x flag 0x%x\n",
498 __func__, chan->ic_freq, chan->ic_flags);
500 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
501 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
502 else if (IEEE80211_IS_CHAN_B(chan))
503 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
505 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: illegal mode\n", __func__);
509 pdGainOverlap_t2 = (uint16_t) SM(OS_REG_READ(ah, AR_PHY_TPCRG5),
510 AR_PHY_TPCRG5_PD_GAIN_OVERLAP);
512 numPdGainsUsed = ar2317getGainBoundariesAndPdadcsForPowers(ah,
513 chan->channel, pRawDataset, pdGainOverlap_t2,
514 &minCalPower2317_t2,gainBoundaries, rfXpdGain, pdadcValues);
515 HALASSERT(1 <= numPdGainsUsed && numPdGainsUsed <= 3);
517 #ifdef AH_USE_INIPDGAIN
519 * Use pd_gains curve from eeprom; Atheros always uses
520 * the default curve from the ini file but some vendors
521 * (e.g. Zcomax) want to override this curve and not
522 * honoring their settings results in tx power 5dBm low.
524 OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
525 (pRawDataset->pDataPerChannel[0].numPdGains - 1));
527 tpcrg1 = OS_REG_READ(ah, AR_PHY_TPCRG1);
528 tpcrg1 = (tpcrg1 &~ AR_PHY_TPCRG1_NUM_PD_GAIN)
529 | SM(numPdGainsUsed-1, AR_PHY_TPCRG1_NUM_PD_GAIN);
530 switch (numPdGainsUsed) {
532 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING3;
533 tpcrg1 |= SM(rfXpdGain[2], AR_PHY_TPCRG1_PDGAIN_SETTING3);
536 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING2;
537 tpcrg1 |= SM(rfXpdGain[1], AR_PHY_TPCRG1_PDGAIN_SETTING2);
540 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING1;
541 tpcrg1 |= SM(rfXpdGain[0], AR_PHY_TPCRG1_PDGAIN_SETTING1);
545 if (tpcrg1 != OS_REG_READ(ah, AR_PHY_TPCRG1))
546 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: using non-default "
547 "pd_gains (default 0x%x, calculated 0x%x)\n",
548 __func__, OS_REG_READ(ah, AR_PHY_TPCRG1), tpcrg1);
550 OS_REG_WRITE(ah, AR_PHY_TPCRG1, tpcrg1);
554 * Note the pdadc table may not start at 0 dBm power, could be
555 * negative or greater than 0. Need to offset the power
556 * values by the amount of minPower for griffin
558 if (minCalPower2317_t2 != 0)
559 ahp->ah_txPowerIndexOffset = (int16_t)(0 - minCalPower2317_t2);
561 ahp->ah_txPowerIndexOffset = 0;
563 /* Finally, write the power values into the baseband power table */
564 regoffset = 0x9800 + (672 <<2); /* beginning of pdadc table in griffin */
565 for (i = 0; i < 32; i++) {
566 reg32 = ((pdadcValues[4*i + 0] & 0xFF) << 0) |
567 ((pdadcValues[4*i + 1] & 0xFF) << 8) |
568 ((pdadcValues[4*i + 2] & 0xFF) << 16) |
569 ((pdadcValues[4*i + 3] & 0xFF) << 24) ;
570 OS_REG_WRITE(ah, regoffset, reg32);
574 OS_REG_WRITE(ah, AR_PHY_TPCRG5,
575 SM(pdGainOverlap_t2, AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
576 SM(gainBoundaries[0], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
577 SM(gainBoundaries[1], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
578 SM(gainBoundaries[2], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
579 SM(gainBoundaries[3], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
585 ar2317GetMinPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2317 *data)
588 uint16_t Pmin=0,numVpd;
590 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
591 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
592 /* work backwards 'cause highest pdGain for lowest power */
593 numVpd = data->pDataPerPDGain[jj].numVpd;
595 Pmin = data->pDataPerPDGain[jj].pwr_t4[0];
603 ar2317GetMaxPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2317 *data)
606 uint16_t Pmax=0,numVpd;
609 for (ii=0; ii< MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
610 /* work forwards cuase lowest pdGain for highest power */
611 numVpd = data->pDataPerPDGain[ii].numVpd;
613 Pmax = data->pDataPerPDGain[ii].pwr_t4[numVpd-1];
614 vpdmax = data->pDataPerPDGain[ii].Vpd[numVpd-1];
622 ar2317GetChannelMaxMinPower(struct ath_hal *ah,
623 const struct ieee80211_channel *chan,
624 int16_t *maxPow, int16_t *minPow)
626 uint16_t freq = chan->ic_freq; /* NB: never mapped */
627 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
628 const RAW_DATA_STRUCT_2317 *pRawDataset = AH_NULL;
629 const RAW_DATA_PER_CHANNEL_2317 *data=AH_NULL;
630 uint16_t numChannels;
631 int totalD,totalF, totalMin,last, i;
635 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
636 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
637 else if (IEEE80211_IS_CHAN_B(chan))
638 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
642 numChannels = pRawDataset->numChannels;
643 data = pRawDataset->pDataPerChannel;
645 /* Make sure the channel is in the range of the TP values
651 if ((freq < data[0].channelValue) ||
652 (freq > data[numChannels-1].channelValue)) {
653 if (freq < data[0].channelValue) {
654 *maxPow = ar2317GetMaxPower(ah, &data[0]);
655 *minPow = ar2317GetMinPower(ah, &data[0]);
658 *maxPow = ar2317GetMaxPower(ah, &data[numChannels - 1]);
659 *minPow = ar2317GetMinPower(ah, &data[numChannels - 1]);
664 /* Linearly interpolate the power value now */
665 for (last=0,i=0; (i<numChannels) && (freq > data[i].channelValue);
667 totalD = data[i].channelValue - data[last].channelValue;
669 totalF = ar2317GetMaxPower(ah, &data[i]) - ar2317GetMaxPower(ah, &data[last]);
670 *maxPow = (int8_t) ((totalF*(freq-data[last].channelValue) +
671 ar2317GetMaxPower(ah, &data[last])*totalD)/totalD);
672 totalMin = ar2317GetMinPower(ah, &data[i]) - ar2317GetMinPower(ah, &data[last]);
673 *minPow = (int8_t) ((totalMin*(freq-data[last].channelValue) +
674 ar2317GetMinPower(ah, &data[last])*totalD)/totalD);
677 if (freq == data[i].channelValue) {
678 *maxPow = ar2317GetMaxPower(ah, &data[i]);
679 *minPow = ar2317GetMinPower(ah, &data[i]);
687 * Free memory for analog bank scratch buffers
690 ar2317RfDetach(struct ath_hal *ah)
692 struct ath_hal_5212 *ahp = AH5212(ah);
694 HALASSERT(ahp->ah_rfHal != AH_NULL);
695 ath_hal_free(ahp->ah_rfHal);
696 ahp->ah_rfHal = AH_NULL;
700 * Allocate memory for analog bank scratch buffers
701 * Scratch Buffer will be reinitialized every reset so no need to zero now
704 ar2317RfAttach(struct ath_hal *ah, HAL_STATUS *status)
706 struct ath_hal_5212 *ahp = AH5212(ah);
707 struct ar2317State *priv;
709 HALASSERT(ah->ah_magic == AR5212_MAGIC);
711 HALASSERT(ahp->ah_rfHal == AH_NULL);
712 priv = ath_hal_malloc(sizeof(struct ar2317State));
713 if (priv == AH_NULL) {
714 HALDEBUG(ah, HAL_DEBUG_ANY,
715 "%s: cannot allocate private state\n", __func__);
716 *status = HAL_ENOMEM; /* XXX */
719 priv->base.rfDetach = ar2317RfDetach;
720 priv->base.writeRegs = ar2317WriteRegs;
721 priv->base.getRfBank = ar2317GetRfBank;
722 priv->base.setChannel = ar2317SetChannel;
723 priv->base.setRfRegs = ar2317SetRfRegs;
724 priv->base.setPowerTable = ar2317SetPowerTable;
725 priv->base.getChannelMaxMinPower = ar2317GetChannelMaxMinPower;
726 priv->base.getNfAdjust = ar5212GetNfAdjust;
728 ahp->ah_pcdacTable = priv->pcdacTable;
729 ahp->ah_pcdacTableSize = sizeof(priv->pcdacTable);
730 ahp->ah_rfHal = &priv->base;
736 ar2317Probe(struct ath_hal *ah)
740 AH_RF(RF2317, ar2317Probe, ar2317RfAttach);