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/ar5413.c 188979 2009-02-24 01:07:06Z sam $
23 #include "ah_internal.h"
25 #include "ah_eeprom_v3.h"
27 #include "ar5212/ar5212.h"
28 #include "ar5212/ar5212reg.h"
29 #include "ar5212/ar5212phy.h"
32 #include "ar5212/ar5212.ini"
35 RF_HAL_FUNCS base; /* public state, must be first */
36 uint16_t pcdacTable[PWR_TABLE_SIZE_2413];
38 uint32_t Bank1Data[NELEM(ar5212Bank1_5413)];
39 uint32_t Bank2Data[NELEM(ar5212Bank2_5413)];
40 uint32_t Bank3Data[NELEM(ar5212Bank3_5413)];
41 uint32_t Bank6Data[NELEM(ar5212Bank6_5413)];
42 uint32_t Bank7Data[NELEM(ar5212Bank7_5413)];
45 * Private state for reduced stack usage.
47 /* filled out Vpd table for all pdGains (chanL) */
48 uint16_t vpdTable_L[MAX_NUM_PDGAINS_PER_CHANNEL]
49 [MAX_PWR_RANGE_IN_HALF_DB];
50 /* filled out Vpd table for all pdGains (chanR) */
51 uint16_t vpdTable_R[MAX_NUM_PDGAINS_PER_CHANNEL]
52 [MAX_PWR_RANGE_IN_HALF_DB];
53 /* filled out Vpd table for all pdGains (interpolated) */
54 uint16_t vpdTable_I[MAX_NUM_PDGAINS_PER_CHANNEL]
55 [MAX_PWR_RANGE_IN_HALF_DB];
57 #define AR5413(ah) ((struct ar5413State *) AH5212(ah)->ah_rfHal)
59 extern void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32,
60 uint32_t numBits, uint32_t firstBit, uint32_t column);
63 ar5413WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex,
66 HAL_INI_WRITE_ARRAY(ah, ar5212Modes_5413, modesIndex, writes);
67 HAL_INI_WRITE_ARRAY(ah, ar5212Common_5413, 1, writes);
68 HAL_INI_WRITE_ARRAY(ah, ar5212BB_RfGain_5413, freqIndex, writes);
72 * Take the MHz channel value and set the Channel value
74 * ASSUMES: Writes enabled to analog bus
77 ar5413SetChannel(struct ath_hal *ah, const struct ieee80211_channel *chan)
79 uint16_t freq = ath_hal_gethwchannel(ah, chan);
80 uint32_t channelSel = 0;
81 uint32_t bModeSynth = 0;
82 uint32_t aModeRefSel = 0;
85 OS_MARK(ah, AH_MARK_SETCHANNEL, freq);
90 if (((freq - 2192) % 5) == 0) {
91 channelSel = ((freq - 672) * 2 - 3040)/10;
93 } else if (((freq - 2224) % 5) == 0) {
94 channelSel = ((freq - 704) * 2 - 3040) / 10;
97 HALDEBUG(ah, HAL_DEBUG_ANY,
98 "%s: invalid channel %u MHz\n",
103 channelSel = (channelSel << 2) & 0xff;
104 channelSel = ath_hal_reverseBits(channelSel, 8);
106 txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL);
108 /* Enable channel spreading for channel 14 */
109 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
110 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
112 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
113 txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
115 } else if (((freq % 5) == 2) && (freq <= 5435)) {
116 freq = freq - 2; /* Align to even 5MHz raster */
117 channelSel = ath_hal_reverseBits(
118 (uint32_t)(((freq - 4800)*10)/25 + 1), 8);
119 aModeRefSel = ath_hal_reverseBits(0, 2);
120 } else if ((freq % 20) == 0 && freq >= 5120) {
121 channelSel = ath_hal_reverseBits(
122 ((freq - 4800) / 20 << 2), 8);
123 aModeRefSel = ath_hal_reverseBits(1, 2);
124 } else if ((freq % 10) == 0) {
125 channelSel = ath_hal_reverseBits(
126 ((freq - 4800) / 10 << 1), 8);
127 aModeRefSel = ath_hal_reverseBits(1, 2);
128 } else if ((freq % 5) == 0) {
129 channelSel = ath_hal_reverseBits(
130 (freq - 4800) / 5, 8);
131 aModeRefSel = ath_hal_reverseBits(1, 2);
133 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel %u MHz\n",
138 reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) |
140 OS_REG_WRITE(ah, AR_PHY(0x27), reg32 & 0xff);
143 OS_REG_WRITE(ah, AR_PHY(0x36), reg32 & 0x7f);
145 AH_PRIVATE(ah)->ah_curchan = chan;
150 * Reads EEPROM header info from device structure and programs
153 * REQUIRES: Access to the analog rf device
156 ar5413SetRfRegs(struct ath_hal *ah,
157 const struct ieee80211_channel *chan,
158 uint16_t modesIndex, uint16_t *rfXpdGain)
160 #define RF_BANK_SETUP(_priv, _ix, _col) do { \
162 for (i = 0; i < NELEM(ar5212Bank##_ix##_5413); i++) \
163 (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_5413[i][_col];\
165 struct ath_hal_5212 *ahp = AH5212(ah);
166 uint16_t freq = ath_hal_gethwchannel(ah, chan);
167 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
168 uint16_t ob5GHz = 0, db5GHz = 0;
169 uint16_t ob2GHz = 0, db2GHz = 0;
170 struct ar5413State *priv = AR5413(ah);
173 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan %u/0x%x modesIndex %u\n",
174 __func__, chan->ic_freq, chan->ic_flags, modesIndex);
176 HALASSERT(priv != AH_NULL);
178 /* Setup rf parameters */
179 switch (chan->ic_flags & IEEE80211_CHAN_ALLFULL) {
180 case IEEE80211_CHAN_A:
181 if (freq > 4000 && freq < 5260) {
184 } else if (freq >= 5260 && freq < 5500) {
187 } else if (freq >= 5500 && freq < 5725) {
190 } else if (freq >= 5725) {
197 case IEEE80211_CHAN_B:
198 ob2GHz = ee->ee_obFor24;
199 db2GHz = ee->ee_dbFor24;
201 case IEEE80211_CHAN_G:
202 case IEEE80211_CHAN_PUREG: /* NB: really 108G */
203 ob2GHz = ee->ee_obFor24g;
204 db2GHz = ee->ee_dbFor24g;
207 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n",
208 __func__, chan->ic_flags);
213 RF_BANK_SETUP(priv, 1, 1);
216 RF_BANK_SETUP(priv, 2, modesIndex);
219 RF_BANK_SETUP(priv, 3, modesIndex);
222 RF_BANK_SETUP(priv, 6, modesIndex);
224 /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
225 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
226 ar5212ModifyRfBuffer(priv->Bank6Data, ob2GHz, 3, 241, 0);
227 ar5212ModifyRfBuffer(priv->Bank6Data, db2GHz, 3, 238, 0);
229 /* TODO - only for Eagle 1.0 2GHz - remove for production */
230 /* XXX: but without this bit G doesn't work. */
231 ar5212ModifyRfBuffer(priv->Bank6Data, 1 , 1, 291, 2);
233 /* Optimum value for rf_pwd_iclobuf2G for PCIe chips only */
234 if (AH_PRIVATE(ah)->ah_ispcie) {
235 ar5212ModifyRfBuffer(priv->Bank6Data, ath_hal_reverseBits(6, 3),
239 ar5212ModifyRfBuffer(priv->Bank6Data, ob5GHz, 3, 247, 0);
240 ar5212ModifyRfBuffer(priv->Bank6Data, db5GHz, 3, 244, 0);
245 RF_BANK_SETUP(priv, 7, modesIndex);
247 /* Write Analog registers */
248 HAL_INI_WRITE_BANK(ah, ar5212Bank1_5413, priv->Bank1Data, regWrites);
249 HAL_INI_WRITE_BANK(ah, ar5212Bank2_5413, priv->Bank2Data, regWrites);
250 HAL_INI_WRITE_BANK(ah, ar5212Bank3_5413, priv->Bank3Data, regWrites);
251 HAL_INI_WRITE_BANK(ah, ar5212Bank6_5413, priv->Bank6Data, regWrites);
252 HAL_INI_WRITE_BANK(ah, ar5212Bank7_5413, priv->Bank7Data, regWrites);
254 /* Now that we have reprogrammed rfgain value, clear the flag. */
255 ahp->ah_rfgainState = HAL_RFGAIN_INACTIVE;
262 * Return a reference to the requested RF Bank.
265 ar5413GetRfBank(struct ath_hal *ah, int bank)
267 struct ar5413State *priv = AR5413(ah);
269 HALASSERT(priv != AH_NULL);
271 case 1: return priv->Bank1Data;
272 case 2: return priv->Bank2Data;
273 case 3: return priv->Bank3Data;
274 case 6: return priv->Bank6Data;
275 case 7: return priv->Bank7Data;
277 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown RF Bank %d requested\n",
283 * Return indices surrounding the value in sorted integer lists.
285 * NB: the input list is assumed to be sorted in ascending order
288 GetLowerUpperIndex(int16_t v, const uint16_t *lp, uint16_t listSize,
289 uint32_t *vlo, uint32_t *vhi)
292 const uint16_t *ep = lp+listSize;
296 * Check first and last elements for out-of-bounds conditions.
298 if (target < lp[0]) {
302 if (target >= ep[-1]) {
303 *vlo = *vhi = listSize - 1;
307 /* look for value being near or between 2 values in list */
308 for (tp = lp; tp < ep; tp++) {
310 * If value is close to the current value of the list
311 * then target is not between values, it is one of the values
314 *vlo = *vhi = tp - (const uint16_t *) lp;
318 * Look for value being between current value and next value
319 * if so return these 2 values
321 if (target < tp[1]) {
322 *vlo = tp - (const uint16_t *) lp;
330 * Fill the Vpdlist for indices Pmax-Pmin
333 ar5413FillVpdTable(uint32_t pdGainIdx, int16_t Pmin, int16_t Pmax,
334 const int16_t *pwrList, const uint16_t *VpdList,
335 uint16_t numIntercepts,
336 uint16_t retVpdList[][64])
339 int16_t currPwr = (int16_t)(2*Pmin);
340 /* since Pmin is pwr*2 and pwrList is 4*pwr */
346 if (numIntercepts < 2)
349 while (ii <= (uint16_t)(Pmax - Pmin)) {
350 GetLowerUpperIndex(currPwr, (const uint16_t *) pwrList,
351 numIntercepts, &(idxL), &(idxR));
353 idxR = 1; /* extrapolate below */
354 if (idxL == (uint32_t)(numIntercepts - 1))
355 idxL = numIntercepts - 2; /* extrapolate above */
356 if (pwrList[idxL] == pwrList[idxR])
360 (((currPwr - pwrList[idxL])*VpdList[idxR]+
361 (pwrList[idxR] - currPwr)*VpdList[idxL])/
362 (pwrList[idxR] - pwrList[idxL]));
363 retVpdList[pdGainIdx][ii] = kk;
365 currPwr += 2; /* half dB steps */
372 * Returns interpolated or the scaled up interpolated value
375 interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight,
376 int16_t targetLeft, int16_t targetRight)
380 if (srcRight != srcLeft) {
381 rv = ((target - srcLeft)*targetRight +
382 (srcRight - target)*targetLeft) / (srcRight - srcLeft);
390 * Uses the data points read from EEPROM to reconstruct the pdadc power table
391 * Called by ar5413SetPowerTable()
394 ar5413getGainBoundariesAndPdadcsForPowers(struct ath_hal *ah, uint16_t channel,
395 const RAW_DATA_STRUCT_2413 *pRawDataset,
396 uint16_t pdGainOverlap_t2,
397 int16_t *pMinCalPower, uint16_t pPdGainBoundaries[],
398 uint16_t pPdGainValues[], uint16_t pPDADCValues[])
400 struct ar5413State *priv = AR5413(ah);
401 #define VpdTable_L priv->vpdTable_L
402 #define VpdTable_R priv->vpdTable_R
403 #define VpdTable_I priv->vpdTable_I
405 int32_t ss;/* potentially -ve index for taking care of pdGainOverlap */
407 uint32_t numPdGainsUsed = 0;
409 * If desired to support -ve power levels in future, just
410 * change pwr_I_0 to signed 5-bits.
412 int16_t Pmin_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
413 /* to accomodate -ve power levels later on. */
414 int16_t Pmax_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
415 /* to accomodate -ve power levels later on */
419 uint32_t sizeCurrVpdTable, maxIndex, tgtIndex;
421 /* Get upper lower index */
422 GetLowerUpperIndex(channel, pRawDataset->pChannels,
423 pRawDataset->numChannels, &(idxL), &(idxR));
425 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
426 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
427 /* work backwards 'cause highest pdGain for lowest power */
428 numVpd = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].numVpd;
430 pPdGainValues[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pd_gain;
431 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0];
432 if (Pmin_t2[numPdGainsUsed] >pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]) {
433 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0];
435 Pmin_t2[numPdGainsUsed] = (int16_t)
436 (Pmin_t2[numPdGainsUsed] / 2);
437 Pmax_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[numVpd-1];
438 if (Pmax_t2[numPdGainsUsed] > pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1])
439 Pmax_t2[numPdGainsUsed] =
440 pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1];
441 Pmax_t2[numPdGainsUsed] = (int16_t)(Pmax_t2[numPdGainsUsed] / 2);
443 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
444 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0]),
445 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_L
448 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
449 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]),
450 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_R
452 for (kk = 0; kk < (uint16_t)(Pmax_t2[numPdGainsUsed] - Pmin_t2[numPdGainsUsed]); kk++) {
453 VpdTable_I[numPdGainsUsed][kk] =
455 channel, pRawDataset->pChannels[idxL], pRawDataset->pChannels[idxR],
456 (int16_t)VpdTable_L[numPdGainsUsed][kk], (int16_t)VpdTable_R[numPdGainsUsed][kk]);
458 /* fill VpdTable_I for this pdGain */
461 /* if this pdGain is used */
464 *pMinCalPower = Pmin_t2[0];
465 kk = 0; /* index for the final table */
466 for (ii = 0; ii < numPdGainsUsed; ii++) {
467 if (ii == (numPdGainsUsed - 1))
468 pPdGainBoundaries[ii] = Pmax_t2[ii] +
469 PD_GAIN_BOUNDARY_STRETCH_IN_HALF_DB;
471 pPdGainBoundaries[ii] = (uint16_t)
472 ((Pmax_t2[ii] + Pmin_t2[ii+1]) / 2 );
473 if (pPdGainBoundaries[ii] > 63) {
474 HALDEBUG(ah, HAL_DEBUG_ANY,
475 "%s: clamp pPdGainBoundaries[%d] %d\n",
476 __func__, ii, pPdGainBoundaries[ii]);/*XXX*/
477 pPdGainBoundaries[ii] = 63;
480 /* Find starting index for this pdGain */
482 ss = 0; /* for the first pdGain, start from index 0 */
484 ss = (pPdGainBoundaries[ii-1] - Pmin_t2[ii]) -
486 Vpd_step = (uint16_t)(VpdTable_I[ii][1] - VpdTable_I[ii][0]);
487 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
489 *-ve ss indicates need to extrapolate data below for this pdGain
492 tmpVal = (int16_t)(VpdTable_I[ii][0] + ss*Vpd_step);
493 pPDADCValues[kk++] = (uint16_t)((tmpVal < 0) ? 0 : tmpVal);
497 sizeCurrVpdTable = Pmax_t2[ii] - Pmin_t2[ii];
498 tgtIndex = pPdGainBoundaries[ii] + pdGainOverlap_t2 - Pmin_t2[ii];
499 maxIndex = (tgtIndex < sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;
501 while (ss < (int16_t)maxIndex)
502 pPDADCValues[kk++] = VpdTable_I[ii][ss++];
504 Vpd_step = (uint16_t)(VpdTable_I[ii][sizeCurrVpdTable-1] -
505 VpdTable_I[ii][sizeCurrVpdTable-2]);
506 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
508 * for last gain, pdGainBoundary == Pmax_t2, so will
509 * have to extrapolate
511 if (tgtIndex > maxIndex) { /* need to extrapolate above */
512 while(ss < (int16_t)tgtIndex) {
514 (VpdTable_I[ii][sizeCurrVpdTable-1] +
515 (ss-maxIndex)*Vpd_step);
516 pPDADCValues[kk++] = (tmpVal > 127) ?
520 } /* extrapolated above */
521 } /* for all pdGainUsed */
523 while (ii < MAX_NUM_PDGAINS_PER_CHANNEL) {
524 pPdGainBoundaries[ii] = pPdGainBoundaries[ii-1];
528 pPDADCValues[kk] = pPDADCValues[kk-1];
532 return numPdGainsUsed;
539 ar5413SetPowerTable(struct ath_hal *ah,
540 int16_t *minPower, int16_t *maxPower,
541 const struct ieee80211_channel *chan,
544 struct ath_hal_5212 *ahp = AH5212(ah);
545 uint16_t freq = ath_hal_gethwchannel(ah, chan);
546 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
547 const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL;
548 uint16_t pdGainOverlap_t2;
549 int16_t minCalPower5413_t2;
550 uint16_t *pdadcValues = ahp->ah_pcdacTable;
551 uint16_t gainBoundaries[4];
552 uint32_t reg32, regoffset;
553 int i, numPdGainsUsed;
554 #ifndef AH_USE_INIPDGAIN
558 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan 0x%x flag 0x%x\n",
559 __func__, chan->ic_freq, chan->ic_flags);
561 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
562 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
563 else if (IEEE80211_IS_CHAN_B(chan))
564 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
566 HALASSERT(IEEE80211_IS_CHAN_5GHZ(chan));
567 pRawDataset = &ee->ee_rawDataset2413[headerInfo11A];
570 pdGainOverlap_t2 = (uint16_t) SM(OS_REG_READ(ah, AR_PHY_TPCRG5),
571 AR_PHY_TPCRG5_PD_GAIN_OVERLAP);
573 numPdGainsUsed = ar5413getGainBoundariesAndPdadcsForPowers(ah,
574 freq, pRawDataset, pdGainOverlap_t2,
575 &minCalPower5413_t2,gainBoundaries, rfXpdGain, pdadcValues);
576 HALASSERT(1 <= numPdGainsUsed && numPdGainsUsed <= 3);
578 #ifdef AH_USE_INIPDGAIN
580 * Use pd_gains curve from eeprom; Atheros always uses
581 * the default curve from the ini file but some vendors
582 * (e.g. Zcomax) want to override this curve and not
583 * honoring their settings results in tx power 5dBm low.
585 OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
586 (pRawDataset->pDataPerChannel[0].numPdGains - 1));
588 tpcrg1 = OS_REG_READ(ah, AR_PHY_TPCRG1);
589 tpcrg1 = (tpcrg1 &~ AR_PHY_TPCRG1_NUM_PD_GAIN)
590 | SM(numPdGainsUsed-1, AR_PHY_TPCRG1_NUM_PD_GAIN);
591 switch (numPdGainsUsed) {
593 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING3;
594 tpcrg1 |= SM(rfXpdGain[2], AR_PHY_TPCRG1_PDGAIN_SETTING3);
597 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING2;
598 tpcrg1 |= SM(rfXpdGain[1], AR_PHY_TPCRG1_PDGAIN_SETTING2);
601 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING1;
602 tpcrg1 |= SM(rfXpdGain[0], AR_PHY_TPCRG1_PDGAIN_SETTING1);
606 if (tpcrg1 != OS_REG_READ(ah, AR_PHY_TPCRG1))
607 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: using non-default "
608 "pd_gains (default 0x%x, calculated 0x%x)\n",
609 __func__, OS_REG_READ(ah, AR_PHY_TPCRG1), tpcrg1);
611 OS_REG_WRITE(ah, AR_PHY_TPCRG1, tpcrg1);
615 * Note the pdadc table may not start at 0 dBm power, could be
616 * negative or greater than 0. Need to offset the power
617 * values by the amount of minPower for griffin
619 if (minCalPower5413_t2 != 0)
620 ahp->ah_txPowerIndexOffset = (int16_t)(0 - minCalPower5413_t2);
622 ahp->ah_txPowerIndexOffset = 0;
624 /* Finally, write the power values into the baseband power table */
625 regoffset = 0x9800 + (672 <<2); /* beginning of pdadc table in griffin */
626 for (i = 0; i < 32; i++) {
627 reg32 = ((pdadcValues[4*i + 0] & 0xFF) << 0) |
628 ((pdadcValues[4*i + 1] & 0xFF) << 8) |
629 ((pdadcValues[4*i + 2] & 0xFF) << 16) |
630 ((pdadcValues[4*i + 3] & 0xFF) << 24) ;
631 OS_REG_WRITE(ah, regoffset, reg32);
635 OS_REG_WRITE(ah, AR_PHY_TPCRG5,
636 SM(pdGainOverlap_t2, AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
637 SM(gainBoundaries[0], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
638 SM(gainBoundaries[1], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
639 SM(gainBoundaries[2], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
640 SM(gainBoundaries[3], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
646 ar5413GetMinPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)
649 uint16_t Pmin=0,numVpd;
651 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
652 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
653 /* work backwards 'cause highest pdGain for lowest power */
654 numVpd = data->pDataPerPDGain[jj].numVpd;
656 Pmin = data->pDataPerPDGain[jj].pwr_t4[0];
664 ar5413GetMaxPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)
667 uint16_t Pmax=0,numVpd;
669 for (ii=0; ii< MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
670 /* work forwards cuase lowest pdGain for highest power */
671 numVpd = data->pDataPerPDGain[ii].numVpd;
673 Pmax = data->pDataPerPDGain[ii].pwr_t4[numVpd-1];
681 ar5413GetChannelMaxMinPower(struct ath_hal *ah,
682 const struct ieee80211_channel *chan,
683 int16_t *maxPow, int16_t *minPow)
685 uint16_t freq = chan->ic_freq; /* NB: never mapped */
686 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
687 const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL;
688 const RAW_DATA_PER_CHANNEL_2413 *data=AH_NULL;
689 uint16_t numChannels;
690 int totalD,totalF, totalMin,last, i;
694 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
695 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
696 else if (IEEE80211_IS_CHAN_B(chan))
697 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
699 HALASSERT(IEEE80211_IS_CHAN_5GHZ(chan));
700 pRawDataset = &ee->ee_rawDataset2413[headerInfo11A];
703 numChannels = pRawDataset->numChannels;
704 data = pRawDataset->pDataPerChannel;
706 /* Make sure the channel is in the range of the TP values
712 if ((freq < data[0].channelValue) ||
713 (freq > data[numChannels-1].channelValue)) {
714 if (freq < data[0].channelValue) {
715 *maxPow = ar5413GetMaxPower(ah, &data[0]);
716 *minPow = ar5413GetMinPower(ah, &data[0]);
719 *maxPow = ar5413GetMaxPower(ah, &data[numChannels - 1]);
720 *minPow = ar5413GetMinPower(ah, &data[numChannels - 1]);
725 /* Linearly interpolate the power value now */
726 for (last=0,i=0; (i<numChannels) && (freq > data[i].channelValue);
728 totalD = data[i].channelValue - data[last].channelValue;
730 totalF = ar5413GetMaxPower(ah, &data[i]) - ar5413GetMaxPower(ah, &data[last]);
731 *maxPow = (int8_t) ((totalF*(freq-data[last].channelValue) +
732 ar5413GetMaxPower(ah, &data[last])*totalD)/totalD);
733 totalMin = ar5413GetMinPower(ah, &data[i]) - ar5413GetMinPower(ah, &data[last]);
734 *minPow = (int8_t) ((totalMin*(freq-data[last].channelValue) +
735 ar5413GetMinPower(ah, &data[last])*totalD)/totalD);
738 if (freq == data[i].channelValue) {
739 *maxPow = ar5413GetMaxPower(ah, &data[i]);
740 *minPow = ar5413GetMinPower(ah, &data[i]);
748 * Free memory for analog bank scratch buffers
751 ar5413RfDetach(struct ath_hal *ah)
753 struct ath_hal_5212 *ahp = AH5212(ah);
755 HALASSERT(ahp->ah_rfHal != AH_NULL);
756 ath_hal_free(ahp->ah_rfHal);
757 ahp->ah_rfHal = AH_NULL;
761 * Allocate memory for analog bank scratch buffers
762 * Scratch Buffer will be reinitialized every reset so no need to zero now
765 ar5413RfAttach(struct ath_hal *ah, HAL_STATUS *status)
767 struct ath_hal_5212 *ahp = AH5212(ah);
768 struct ar5413State *priv;
770 HALASSERT(ah->ah_magic == AR5212_MAGIC);
772 HALASSERT(ahp->ah_rfHal == AH_NULL);
773 priv = ath_hal_malloc(sizeof(struct ar5413State));
774 if (priv == AH_NULL) {
775 HALDEBUG(ah, HAL_DEBUG_ANY,
776 "%s: cannot allocate private state\n", __func__);
777 *status = HAL_ENOMEM; /* XXX */
780 priv->base.rfDetach = ar5413RfDetach;
781 priv->base.writeRegs = ar5413WriteRegs;
782 priv->base.getRfBank = ar5413GetRfBank;
783 priv->base.setChannel = ar5413SetChannel;
784 priv->base.setRfRegs = ar5413SetRfRegs;
785 priv->base.setPowerTable = ar5413SetPowerTable;
786 priv->base.getChannelMaxMinPower = ar5413GetChannelMaxMinPower;
787 priv->base.getNfAdjust = ar5212GetNfAdjust;
789 ahp->ah_pcdacTable = priv->pcdacTable;
790 ahp->ah_pcdacTableSize = sizeof(priv->pcdacTable);
791 ahp->ah_rfHal = &priv->base;
797 ar5413Probe(struct ath_hal *ah)
801 AH_RF(RF5413, ar5413Probe, ar5413RfAttach);