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 $
22 #include "ah_internal.h"
24 #include "ah_eeprom_v3.h"
26 #include "ar5212/ar5212.h"
27 #include "ar5212/ar5212reg.h"
28 #include "ar5212/ar5212phy.h"
31 #include "ar5212/ar5212.ini"
34 RF_HAL_FUNCS base; /* public state, must be first */
35 uint16_t pcdacTable[PWR_TABLE_SIZE_2413];
37 uint32_t Bank1Data[NELEM(ar5212Bank1_5413)];
38 uint32_t Bank2Data[NELEM(ar5212Bank2_5413)];
39 uint32_t Bank3Data[NELEM(ar5212Bank3_5413)];
40 uint32_t Bank6Data[NELEM(ar5212Bank6_5413)];
41 uint32_t Bank7Data[NELEM(ar5212Bank7_5413)];
44 * Private state for reduced stack usage.
46 /* filled out Vpd table for all pdGains (chanL) */
47 uint16_t vpdTable_L[MAX_NUM_PDGAINS_PER_CHANNEL]
48 [MAX_PWR_RANGE_IN_HALF_DB];
49 /* filled out Vpd table for all pdGains (chanR) */
50 uint16_t vpdTable_R[MAX_NUM_PDGAINS_PER_CHANNEL]
51 [MAX_PWR_RANGE_IN_HALF_DB];
52 /* filled out Vpd table for all pdGains (interpolated) */
53 uint16_t vpdTable_I[MAX_NUM_PDGAINS_PER_CHANNEL]
54 [MAX_PWR_RANGE_IN_HALF_DB];
56 #define AR5413(ah) ((struct ar5413State *) AH5212(ah)->ah_rfHal)
58 extern void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32,
59 uint32_t numBits, uint32_t firstBit, uint32_t column);
62 ar5413WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex,
65 HAL_INI_WRITE_ARRAY(ah, ar5212Modes_5413, modesIndex, writes);
66 HAL_INI_WRITE_ARRAY(ah, ar5212Common_5413, 1, writes);
67 HAL_INI_WRITE_ARRAY(ah, ar5212BB_RfGain_5413, freqIndex, writes);
71 * Take the MHz channel value and set the Channel value
73 * ASSUMES: Writes enabled to analog bus
76 ar5413SetChannel(struct ath_hal *ah, const struct ieee80211_channel *chan)
78 uint16_t freq = ath_hal_gethwchannel(ah, chan);
79 uint32_t channelSel = 0;
80 uint32_t bModeSynth = 0;
81 uint32_t aModeRefSel = 0;
84 OS_MARK(ah, AH_MARK_SETCHANNEL, freq);
89 if (((freq - 2192) % 5) == 0) {
90 channelSel = ((freq - 672) * 2 - 3040)/10;
92 } else if (((freq - 2224) % 5) == 0) {
93 channelSel = ((freq - 704) * 2 - 3040) / 10;
96 HALDEBUG(ah, HAL_DEBUG_ANY,
97 "%s: invalid channel %u MHz\n",
102 channelSel = (channelSel << 2) & 0xff;
103 channelSel = ath_hal_reverseBits(channelSel, 8);
105 txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL);
107 /* Enable channel spreading for channel 14 */
108 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
109 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
111 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
112 txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
114 } else if (((freq % 5) == 2) && (freq <= 5435)) {
115 freq = freq - 2; /* Align to even 5MHz raster */
116 channelSel = ath_hal_reverseBits(
117 (uint32_t)(((freq - 4800)*10)/25 + 1), 8);
118 aModeRefSel = ath_hal_reverseBits(0, 2);
119 } else if ((freq % 20) == 0 && freq >= 5120) {
120 channelSel = ath_hal_reverseBits(
121 ((freq - 4800) / 20 << 2), 8);
122 aModeRefSel = ath_hal_reverseBits(1, 2);
123 } else if ((freq % 10) == 0) {
124 channelSel = ath_hal_reverseBits(
125 ((freq - 4800) / 10 << 1), 8);
126 aModeRefSel = ath_hal_reverseBits(1, 2);
127 } else if ((freq % 5) == 0) {
128 channelSel = ath_hal_reverseBits(
129 (freq - 4800) / 5, 8);
130 aModeRefSel = ath_hal_reverseBits(1, 2);
132 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel %u MHz\n",
137 reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) |
139 OS_REG_WRITE(ah, AR_PHY(0x27), reg32 & 0xff);
142 OS_REG_WRITE(ah, AR_PHY(0x36), reg32 & 0x7f);
144 AH_PRIVATE(ah)->ah_curchan = chan;
149 * Reads EEPROM header info from device structure and programs
152 * REQUIRES: Access to the analog rf device
155 ar5413SetRfRegs(struct ath_hal *ah,
156 const struct ieee80211_channel *chan,
157 uint16_t modesIndex, uint16_t *rfXpdGain)
159 #define RF_BANK_SETUP(_priv, _ix, _col) do { \
161 for (i = 0; i < NELEM(ar5212Bank##_ix##_5413); i++) \
162 (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_5413[i][_col];\
164 struct ath_hal_5212 *ahp = AH5212(ah);
165 uint16_t freq = ath_hal_gethwchannel(ah, chan);
166 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
167 uint16_t ob5GHz = 0, db5GHz = 0;
168 uint16_t ob2GHz = 0, db2GHz = 0;
169 struct ar5413State *priv = AR5413(ah);
172 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan %u/0x%x modesIndex %u\n",
173 __func__, chan->ic_freq, chan->ic_flags, modesIndex);
175 HALASSERT(priv != AH_NULL);
177 /* Setup rf parameters */
178 switch (chan->ic_flags & IEEE80211_CHAN_ALLFULL) {
179 case IEEE80211_CHAN_A:
180 if (freq > 4000 && freq < 5260) {
183 } else if (freq >= 5260 && freq < 5500) {
186 } else if (freq >= 5500 && freq < 5725) {
189 } else if (freq >= 5725) {
196 case IEEE80211_CHAN_B:
197 ob2GHz = ee->ee_obFor24;
198 db2GHz = ee->ee_dbFor24;
200 case IEEE80211_CHAN_G:
201 case IEEE80211_CHAN_PUREG: /* NB: really 108G */
202 ob2GHz = ee->ee_obFor24g;
203 db2GHz = ee->ee_dbFor24g;
206 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n",
207 __func__, chan->ic_flags);
212 RF_BANK_SETUP(priv, 1, 1);
215 RF_BANK_SETUP(priv, 2, modesIndex);
218 RF_BANK_SETUP(priv, 3, modesIndex);
221 RF_BANK_SETUP(priv, 6, modesIndex);
223 /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
224 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
225 ar5212ModifyRfBuffer(priv->Bank6Data, ob2GHz, 3, 241, 0);
226 ar5212ModifyRfBuffer(priv->Bank6Data, db2GHz, 3, 238, 0);
228 /* TODO - only for Eagle 1.0 2GHz - remove for production */
229 /* XXX: but without this bit G doesn't work. */
230 ar5212ModifyRfBuffer(priv->Bank6Data, 1 , 1, 291, 2);
232 /* Optimum value for rf_pwd_iclobuf2G for PCIe chips only */
233 if (AH_PRIVATE(ah)->ah_ispcie) {
234 ar5212ModifyRfBuffer(priv->Bank6Data, ath_hal_reverseBits(6, 3),
238 ar5212ModifyRfBuffer(priv->Bank6Data, ob5GHz, 3, 247, 0);
239 ar5212ModifyRfBuffer(priv->Bank6Data, db5GHz, 3, 244, 0);
244 RF_BANK_SETUP(priv, 7, modesIndex);
246 /* Write Analog registers */
247 HAL_INI_WRITE_BANK(ah, ar5212Bank1_5413, priv->Bank1Data, regWrites);
248 HAL_INI_WRITE_BANK(ah, ar5212Bank2_5413, priv->Bank2Data, regWrites);
249 HAL_INI_WRITE_BANK(ah, ar5212Bank3_5413, priv->Bank3Data, regWrites);
250 HAL_INI_WRITE_BANK(ah, ar5212Bank6_5413, priv->Bank6Data, regWrites);
251 HAL_INI_WRITE_BANK(ah, ar5212Bank7_5413, priv->Bank7Data, regWrites);
253 /* Now that we have reprogrammed rfgain value, clear the flag. */
254 ahp->ah_rfgainState = HAL_RFGAIN_INACTIVE;
261 * Return a reference to the requested RF Bank.
264 ar5413GetRfBank(struct ath_hal *ah, int bank)
266 struct ar5413State *priv = AR5413(ah);
268 HALASSERT(priv != AH_NULL);
270 case 1: return priv->Bank1Data;
271 case 2: return priv->Bank2Data;
272 case 3: return priv->Bank3Data;
273 case 6: return priv->Bank6Data;
274 case 7: return priv->Bank7Data;
276 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown RF Bank %d requested\n",
282 * Return indices surrounding the value in sorted integer lists.
284 * NB: the input list is assumed to be sorted in ascending order
287 GetLowerUpperIndex(int16_t v, const uint16_t *lp, uint16_t listSize,
288 uint32_t *vlo, uint32_t *vhi)
291 const uint16_t *ep = lp+listSize;
295 * Check first and last elements for out-of-bounds conditions.
297 if (target < lp[0]) {
301 if (target >= ep[-1]) {
302 *vlo = *vhi = listSize - 1;
306 /* look for value being near or between 2 values in list */
307 for (tp = lp; tp < ep; tp++) {
309 * If value is close to the current value of the list
310 * then target is not between values, it is one of the values
313 *vlo = *vhi = tp - (const uint16_t *) lp;
317 * Look for value being between current value and next value
318 * if so return these 2 values
320 if (target < tp[1]) {
321 *vlo = tp - (const uint16_t *) lp;
329 * Fill the Vpdlist for indices Pmax-Pmin
332 ar5413FillVpdTable(uint32_t pdGainIdx, int16_t Pmin, int16_t Pmax,
333 const int16_t *pwrList, const uint16_t *VpdList,
334 uint16_t numIntercepts,
335 uint16_t retVpdList[][64])
338 int16_t currPwr = (int16_t)(2*Pmin);
339 /* since Pmin is pwr*2 and pwrList is 4*pwr */
344 if (numIntercepts < 2)
347 while (ii <= (uint16_t)(Pmax - Pmin)) {
348 GetLowerUpperIndex(currPwr, (const uint16_t *) pwrList,
349 numIntercepts, &(idxL), &(idxR));
351 idxR = 1; /* extrapolate below */
352 if (idxL == (uint32_t)(numIntercepts - 1))
353 idxL = numIntercepts - 2; /* extrapolate above */
354 if (pwrList[idxL] == pwrList[idxR])
358 (((currPwr - pwrList[idxL])*VpdList[idxR]+
359 (pwrList[idxR] - currPwr)*VpdList[idxL])/
360 (pwrList[idxR] - pwrList[idxL]));
361 retVpdList[pdGainIdx][ii] = kk;
363 currPwr += 2; /* half dB steps */
370 * Returns interpolated or the scaled up interpolated value
373 interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight,
374 int16_t targetLeft, int16_t targetRight)
378 if (srcRight != srcLeft) {
379 rv = ((target - srcLeft)*targetRight +
380 (srcRight - target)*targetLeft) / (srcRight - srcLeft);
388 * Uses the data points read from EEPROM to reconstruct the pdadc power table
389 * Called by ar5413SetPowerTable()
392 ar5413getGainBoundariesAndPdadcsForPowers(struct ath_hal *ah, uint16_t channel,
393 const RAW_DATA_STRUCT_2413 *pRawDataset,
394 uint16_t pdGainOverlap_t2,
395 int16_t *pMinCalPower, uint16_t pPdGainBoundaries[],
396 uint16_t pPdGainValues[], uint16_t pPDADCValues[])
398 struct ar5413State *priv = AR5413(ah);
399 #define VpdTable_L priv->vpdTable_L
400 #define VpdTable_R priv->vpdTable_R
401 #define VpdTable_I priv->vpdTable_I
403 int32_t ss;/* potentially -ve index for taking care of pdGainOverlap */
405 uint32_t numPdGainsUsed = 0;
407 * If desired to support -ve power levels in future, just
408 * change pwr_I_0 to signed 5-bits.
410 int16_t Pmin_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
411 /* to accomodate -ve power levels later on. */
412 int16_t Pmax_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
413 /* to accomodate -ve power levels later on */
417 uint32_t sizeCurrVpdTable, maxIndex, tgtIndex;
419 /* Get upper lower index */
420 GetLowerUpperIndex(channel, pRawDataset->pChannels,
421 pRawDataset->numChannels, &(idxL), &(idxR));
423 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
424 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
425 /* work backwards 'cause highest pdGain for lowest power */
426 numVpd = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].numVpd;
428 pPdGainValues[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pd_gain;
429 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0];
430 if (Pmin_t2[numPdGainsUsed] >pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]) {
431 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0];
433 Pmin_t2[numPdGainsUsed] = (int16_t)
434 (Pmin_t2[numPdGainsUsed] / 2);
435 Pmax_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[numVpd-1];
436 if (Pmax_t2[numPdGainsUsed] > pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1])
437 Pmax_t2[numPdGainsUsed] =
438 pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1];
439 Pmax_t2[numPdGainsUsed] = (int16_t)(Pmax_t2[numPdGainsUsed] / 2);
441 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
442 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0]),
443 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_L
446 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
447 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]),
448 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_R
450 for (kk = 0; kk < (uint16_t)(Pmax_t2[numPdGainsUsed] - Pmin_t2[numPdGainsUsed]); kk++) {
451 VpdTable_I[numPdGainsUsed][kk] =
453 channel, pRawDataset->pChannels[idxL], pRawDataset->pChannels[idxR],
454 (int16_t)VpdTable_L[numPdGainsUsed][kk], (int16_t)VpdTable_R[numPdGainsUsed][kk]);
456 /* fill VpdTable_I for this pdGain */
459 /* if this pdGain is used */
462 *pMinCalPower = Pmin_t2[0];
463 kk = 0; /* index for the final table */
464 for (ii = 0; ii < numPdGainsUsed; ii++) {
465 if (ii == (numPdGainsUsed - 1))
466 pPdGainBoundaries[ii] = Pmax_t2[ii] +
467 PD_GAIN_BOUNDARY_STRETCH_IN_HALF_DB;
469 pPdGainBoundaries[ii] = (uint16_t)
470 ((Pmax_t2[ii] + Pmin_t2[ii+1]) / 2 );
471 if (pPdGainBoundaries[ii] > 63) {
472 HALDEBUG(ah, HAL_DEBUG_ANY,
473 "%s: clamp pPdGainBoundaries[%d] %d\n",
474 __func__, ii, pPdGainBoundaries[ii]);/*XXX*/
475 pPdGainBoundaries[ii] = 63;
478 /* Find starting index for this pdGain */
480 ss = 0; /* for the first pdGain, start from index 0 */
482 ss = (pPdGainBoundaries[ii-1] - Pmin_t2[ii]) -
484 Vpd_step = (uint16_t)(VpdTable_I[ii][1] - VpdTable_I[ii][0]);
485 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
487 *-ve ss indicates need to extrapolate data below for this pdGain
490 tmpVal = (int16_t)(VpdTable_I[ii][0] + ss*Vpd_step);
491 pPDADCValues[kk++] = (uint16_t)((tmpVal < 0) ? 0 : tmpVal);
495 sizeCurrVpdTable = Pmax_t2[ii] - Pmin_t2[ii];
496 tgtIndex = pPdGainBoundaries[ii] + pdGainOverlap_t2 - Pmin_t2[ii];
497 maxIndex = (tgtIndex < sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;
499 while (ss < (int16_t)maxIndex)
500 pPDADCValues[kk++] = VpdTable_I[ii][ss++];
502 Vpd_step = (uint16_t)(VpdTable_I[ii][sizeCurrVpdTable-1] -
503 VpdTable_I[ii][sizeCurrVpdTable-2]);
504 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
506 * for last gain, pdGainBoundary == Pmax_t2, so will
507 * have to extrapolate
509 if (tgtIndex > maxIndex) { /* need to extrapolate above */
510 while(ss < (int16_t)tgtIndex) {
512 (VpdTable_I[ii][sizeCurrVpdTable-1] +
513 (ss-maxIndex)*Vpd_step);
514 pPDADCValues[kk++] = (tmpVal > 127) ?
518 } /* extrapolated above */
519 } /* for all pdGainUsed */
521 while (ii < MAX_NUM_PDGAINS_PER_CHANNEL) {
522 pPdGainBoundaries[ii] = pPdGainBoundaries[ii-1];
526 pPDADCValues[kk] = pPDADCValues[kk-1];
530 return numPdGainsUsed;
537 ar5413SetPowerTable(struct ath_hal *ah,
538 int16_t *minPower, int16_t *maxPower,
539 const struct ieee80211_channel *chan,
542 struct ath_hal_5212 *ahp = AH5212(ah);
543 uint16_t freq = ath_hal_gethwchannel(ah, chan);
544 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
545 const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL;
546 uint16_t pdGainOverlap_t2;
547 int16_t minCalPower5413_t2;
548 uint16_t *pdadcValues = ahp->ah_pcdacTable;
549 uint16_t gainBoundaries[4];
550 uint32_t reg32, regoffset;
551 int i, numPdGainsUsed;
552 #ifndef AH_USE_INIPDGAIN
556 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan 0x%x flag 0x%x\n",
557 __func__, chan->ic_freq, chan->ic_flags);
559 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
560 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
561 else if (IEEE80211_IS_CHAN_B(chan))
562 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
564 HALASSERT(IEEE80211_IS_CHAN_5GHZ(chan));
565 pRawDataset = &ee->ee_rawDataset2413[headerInfo11A];
568 pdGainOverlap_t2 = (uint16_t) SM(OS_REG_READ(ah, AR_PHY_TPCRG5),
569 AR_PHY_TPCRG5_PD_GAIN_OVERLAP);
571 numPdGainsUsed = ar5413getGainBoundariesAndPdadcsForPowers(ah,
572 freq, pRawDataset, pdGainOverlap_t2,
573 &minCalPower5413_t2,gainBoundaries, rfXpdGain, pdadcValues);
574 HALASSERT(1 <= numPdGainsUsed && numPdGainsUsed <= 3);
576 #ifdef AH_USE_INIPDGAIN
578 * Use pd_gains curve from eeprom; Atheros always uses
579 * the default curve from the ini file but some vendors
580 * (e.g. Zcomax) want to override this curve and not
581 * honoring their settings results in tx power 5dBm low.
583 OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
584 (pRawDataset->pDataPerChannel[0].numPdGains - 1));
586 tpcrg1 = OS_REG_READ(ah, AR_PHY_TPCRG1);
587 tpcrg1 = (tpcrg1 &~ AR_PHY_TPCRG1_NUM_PD_GAIN)
588 | SM(numPdGainsUsed-1, AR_PHY_TPCRG1_NUM_PD_GAIN);
589 switch (numPdGainsUsed) {
591 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING3;
592 tpcrg1 |= SM(rfXpdGain[2], AR_PHY_TPCRG1_PDGAIN_SETTING3);
595 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING2;
596 tpcrg1 |= SM(rfXpdGain[1], AR_PHY_TPCRG1_PDGAIN_SETTING2);
599 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING1;
600 tpcrg1 |= SM(rfXpdGain[0], AR_PHY_TPCRG1_PDGAIN_SETTING1);
604 if (tpcrg1 != OS_REG_READ(ah, AR_PHY_TPCRG1))
605 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: using non-default "
606 "pd_gains (default 0x%x, calculated 0x%x)\n",
607 __func__, OS_REG_READ(ah, AR_PHY_TPCRG1), tpcrg1);
609 OS_REG_WRITE(ah, AR_PHY_TPCRG1, tpcrg1);
613 * Note the pdadc table may not start at 0 dBm power, could be
614 * negative or greater than 0. Need to offset the power
615 * values by the amount of minPower for griffin
617 if (minCalPower5413_t2 != 0)
618 ahp->ah_txPowerIndexOffset = (int16_t)(0 - minCalPower5413_t2);
620 ahp->ah_txPowerIndexOffset = 0;
622 /* Finally, write the power values into the baseband power table */
623 regoffset = 0x9800 + (672 <<2); /* beginning of pdadc table in griffin */
624 for (i = 0; i < 32; i++) {
625 reg32 = ((pdadcValues[4*i + 0] & 0xFF) << 0) |
626 ((pdadcValues[4*i + 1] & 0xFF) << 8) |
627 ((pdadcValues[4*i + 2] & 0xFF) << 16) |
628 ((pdadcValues[4*i + 3] & 0xFF) << 24) ;
629 OS_REG_WRITE(ah, regoffset, reg32);
633 OS_REG_WRITE(ah, AR_PHY_TPCRG5,
634 SM(pdGainOverlap_t2, AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
635 SM(gainBoundaries[0], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
636 SM(gainBoundaries[1], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
637 SM(gainBoundaries[2], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
638 SM(gainBoundaries[3], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
644 ar5413GetMinPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)
647 uint16_t Pmin=0,numVpd;
649 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
650 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
651 /* work backwards 'cause highest pdGain for lowest power */
652 numVpd = data->pDataPerPDGain[jj].numVpd;
654 Pmin = data->pDataPerPDGain[jj].pwr_t4[0];
662 ar5413GetMaxPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)
665 uint16_t Pmax=0,numVpd;
667 for (ii=0; ii< MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
668 /* work forwards cuase lowest pdGain for highest power */
669 numVpd = data->pDataPerPDGain[ii].numVpd;
671 Pmax = data->pDataPerPDGain[ii].pwr_t4[numVpd-1];
679 ar5413GetChannelMaxMinPower(struct ath_hal *ah,
680 const struct ieee80211_channel *chan,
681 int16_t *maxPow, int16_t *minPow)
683 uint16_t freq = chan->ic_freq; /* NB: never mapped */
684 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
685 const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL;
686 const RAW_DATA_PER_CHANNEL_2413 *data=AH_NULL;
687 uint16_t numChannels;
688 int totalD,totalF, totalMin,last, i;
692 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
693 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
694 else if (IEEE80211_IS_CHAN_B(chan))
695 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
697 HALASSERT(IEEE80211_IS_CHAN_5GHZ(chan));
698 pRawDataset = &ee->ee_rawDataset2413[headerInfo11A];
701 numChannels = pRawDataset->numChannels;
702 data = pRawDataset->pDataPerChannel;
704 /* Make sure the channel is in the range of the TP values
710 if ((freq < data[0].channelValue) ||
711 (freq > data[numChannels-1].channelValue)) {
712 if (freq < data[0].channelValue) {
713 *maxPow = ar5413GetMaxPower(ah, &data[0]);
714 *minPow = ar5413GetMinPower(ah, &data[0]);
717 *maxPow = ar5413GetMaxPower(ah, &data[numChannels - 1]);
718 *minPow = ar5413GetMinPower(ah, &data[numChannels - 1]);
723 /* Linearly interpolate the power value now */
724 for (last=0,i=0; (i<numChannels) && (freq > data[i].channelValue);
726 totalD = data[i].channelValue - data[last].channelValue;
728 totalF = ar5413GetMaxPower(ah, &data[i]) - ar5413GetMaxPower(ah, &data[last]);
729 *maxPow = (int8_t) ((totalF*(freq-data[last].channelValue) +
730 ar5413GetMaxPower(ah, &data[last])*totalD)/totalD);
731 totalMin = ar5413GetMinPower(ah, &data[i]) - ar5413GetMinPower(ah, &data[last]);
732 *minPow = (int8_t) ((totalMin*(freq-data[last].channelValue) +
733 ar5413GetMinPower(ah, &data[last])*totalD)/totalD);
736 if (freq == data[i].channelValue) {
737 *maxPow = ar5413GetMaxPower(ah, &data[i]);
738 *minPow = ar5413GetMinPower(ah, &data[i]);
746 * Free memory for analog bank scratch buffers
749 ar5413RfDetach(struct ath_hal *ah)
751 struct ath_hal_5212 *ahp = AH5212(ah);
753 HALASSERT(ahp->ah_rfHal != AH_NULL);
754 ath_hal_free(ahp->ah_rfHal);
755 ahp->ah_rfHal = AH_NULL;
759 * Allocate memory for analog bank scratch buffers
760 * Scratch Buffer will be reinitialized every reset so no need to zero now
763 ar5413RfAttach(struct ath_hal *ah, HAL_STATUS *status)
765 struct ath_hal_5212 *ahp = AH5212(ah);
766 struct ar5413State *priv;
768 HALASSERT(ah->ah_magic == AR5212_MAGIC);
770 HALASSERT(ahp->ah_rfHal == AH_NULL);
771 priv = ath_hal_malloc(sizeof(struct ar5413State));
772 if (priv == AH_NULL) {
773 HALDEBUG(ah, HAL_DEBUG_ANY,
774 "%s: cannot allocate private state\n", __func__);
775 *status = HAL_ENOMEM; /* XXX */
778 priv->base.rfDetach = ar5413RfDetach;
779 priv->base.writeRegs = ar5413WriteRegs;
780 priv->base.getRfBank = ar5413GetRfBank;
781 priv->base.setChannel = ar5413SetChannel;
782 priv->base.setRfRegs = ar5413SetRfRegs;
783 priv->base.setPowerTable = ar5413SetPowerTable;
784 priv->base.getChannelMaxMinPower = ar5413GetChannelMaxMinPower;
785 priv->base.getNfAdjust = ar5212GetNfAdjust;
787 ahp->ah_pcdacTable = priv->pcdacTable;
788 ahp->ah_pcdacTableSize = sizeof(priv->pcdacTable);
789 ahp->ah_rfHal = &priv->base;
795 ar5413Probe(struct ath_hal *ah)
799 AH_RF(RF5413, ar5413Probe, ar5413RfAttach);