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 typedef RAW_DATA_STRUCT_2413 RAW_DATA_STRUCT_2316;
35 typedef RAW_DATA_PER_CHANNEL_2413 RAW_DATA_PER_CHANNEL_2316;
36 #define PWR_TABLE_SIZE_2316 PWR_TABLE_SIZE_2413
39 RF_HAL_FUNCS base; /* public state, must be first */
40 uint16_t pcdacTable[PWR_TABLE_SIZE_2316];
42 uint32_t Bank1Data[NELEM(ar5212Bank1_2316)];
43 uint32_t Bank2Data[NELEM(ar5212Bank2_2316)];
44 uint32_t Bank3Data[NELEM(ar5212Bank3_2316)];
45 uint32_t Bank6Data[NELEM(ar5212Bank6_2316)];
46 uint32_t Bank7Data[NELEM(ar5212Bank7_2316)];
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 AR2316(ah) ((struct ar2316State *) 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 ar2316WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex,
70 struct ath_hal_5212 *ahp = AH5212(ah);
72 HAL_INI_WRITE_ARRAY(ah, ar5212Modes_2316, modesIndex, regWrites);
73 HAL_INI_WRITE_ARRAY(ah, ar5212Common_2316, 1, regWrites);
74 HAL_INI_WRITE_ARRAY(ah, ar5212BB_RfGain_2316, freqIndex, regWrites);
77 if (!ahp->ah_cwCalRequire) {
78 OS_REG_WRITE(ah, 0xa358, (OS_REG_READ(ah, 0xa358) & ~0x2));
80 ahp->ah_cwCalRequire = AH_FALSE;
85 * Take the MHz channel value and set the Channel value
87 * ASSUMES: Writes enabled to analog bus
90 ar2316SetChannel(struct ath_hal *ah, struct ieee80211_channel *chan)
92 uint16_t freq = ath_hal_gethwchannel(ah, chan);
93 uint32_t channelSel = 0;
94 uint32_t bModeSynth = 0;
95 uint32_t aModeRefSel = 0;
98 OS_MARK(ah, AH_MARK_SETCHANNEL, freq);
103 if (((freq - 2192) % 5) == 0) {
104 channelSel = ((freq - 672) * 2 - 3040)/10;
106 } else if (((freq - 2224) % 5) == 0) {
107 channelSel = ((freq - 704) * 2 - 3040) / 10;
110 HALDEBUG(ah, HAL_DEBUG_ANY,
111 "%s: invalid channel %u MHz\n",
116 channelSel = (channelSel << 2) & 0xff;
117 channelSel = ath_hal_reverseBits(channelSel, 8);
119 txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL);
121 /* Enable channel spreading for channel 14 */
122 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
123 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
125 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
126 txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
128 } else if ((freq % 20) == 0 && freq >= 5120) {
129 channelSel = ath_hal_reverseBits(
130 ((freq - 4800) / 20 << 2), 8);
131 aModeRefSel = ath_hal_reverseBits(3, 2);
132 } else if ((freq % 10) == 0) {
133 channelSel = ath_hal_reverseBits(
134 ((freq - 4800) / 10 << 1), 8);
135 aModeRefSel = ath_hal_reverseBits(2, 2);
136 } else if ((freq % 5) == 0) {
137 channelSel = ath_hal_reverseBits(
138 (freq - 4800) / 5, 8);
139 aModeRefSel = ath_hal_reverseBits(1, 2);
141 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel %u MHz\n",
146 reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) |
148 OS_REG_WRITE(ah, AR_PHY(0x27), reg32 & 0xff);
151 OS_REG_WRITE(ah, AR_PHY(0x36), reg32 & 0x7f);
153 AH_PRIVATE(ah)->ah_curchan = chan;
158 * Reads EEPROM header info from device structure and programs
161 * REQUIRES: Access to the analog rf device
164 ar2316SetRfRegs(struct ath_hal *ah, const struct ieee80211_channel *chan,
165 uint16_t modesIndex, uint16_t *rfXpdGain)
167 #define RF_BANK_SETUP(_priv, _ix, _col) do { \
169 for (i = 0; i < NELEM(ar5212Bank##_ix##_2316); i++) \
170 (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_2316[i][_col];\
172 struct ath_hal_5212 *ahp = AH5212(ah);
173 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
174 uint16_t ob2GHz = 0, db2GHz = 0;
175 struct ar2316State *priv = AR2316(ah);
178 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan %u/0x%x modesIndex %u\n",
179 __func__, chan->ic_freq, chan->ic_flags, modesIndex);
181 HALASSERT(priv != AH_NULL);
183 /* Setup rf parameters */
184 if (IEEE80211_IS_CHAN_B(chan)) {
185 ob2GHz = ee->ee_obFor24;
186 db2GHz = ee->ee_dbFor24;
188 ob2GHz = ee->ee_obFor24g;
189 db2GHz = ee->ee_dbFor24g;
193 RF_BANK_SETUP(priv, 1, 1);
196 RF_BANK_SETUP(priv, 2, modesIndex);
199 RF_BANK_SETUP(priv, 3, modesIndex);
202 RF_BANK_SETUP(priv, 6, modesIndex);
204 ar5212ModifyRfBuffer(priv->Bank6Data, ob2GHz, 3, 178, 0);
205 ar5212ModifyRfBuffer(priv->Bank6Data, db2GHz, 3, 175, 0);
208 RF_BANK_SETUP(priv, 7, modesIndex);
210 /* Write Analog registers */
211 HAL_INI_WRITE_BANK(ah, ar5212Bank1_2316, priv->Bank1Data, regWrites);
212 HAL_INI_WRITE_BANK(ah, ar5212Bank2_2316, priv->Bank2Data, regWrites);
213 HAL_INI_WRITE_BANK(ah, ar5212Bank3_2316, priv->Bank3Data, regWrites);
214 HAL_INI_WRITE_BANK(ah, ar5212Bank6_2316, priv->Bank6Data, regWrites);
215 HAL_INI_WRITE_BANK(ah, ar5212Bank7_2316, priv->Bank7Data, regWrites);
217 /* Now that we have reprogrammed rfgain value, clear the flag. */
218 ahp->ah_rfgainState = HAL_RFGAIN_INACTIVE;
225 * Return a reference to the requested RF Bank.
228 ar2316GetRfBank(struct ath_hal *ah, int bank)
230 struct ar2316State *priv = AR2316(ah);
232 HALASSERT(priv != AH_NULL);
234 case 1: return priv->Bank1Data;
235 case 2: return priv->Bank2Data;
236 case 3: return priv->Bank3Data;
237 case 6: return priv->Bank6Data;
238 case 7: return priv->Bank7Data;
240 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown RF Bank %d requested\n",
246 * Return indices surrounding the value in sorted integer lists.
248 * NB: the input list is assumed to be sorted in ascending order
251 GetLowerUpperIndex(int16_t v, const uint16_t *lp, uint16_t listSize,
252 uint32_t *vlo, uint32_t *vhi)
255 const int16_t *ep = lp+listSize;
259 * Check first and last elements for out-of-bounds conditions.
261 if (target < lp[0]) {
265 if (target >= ep[-1]) {
266 *vlo = *vhi = listSize - 1;
270 /* look for value being near or between 2 values in list */
271 for (tp = lp; tp < ep; tp++) {
273 * If value is close to the current value of the list
274 * then target is not between values, it is one of the values
277 *vlo = *vhi = tp - (const int16_t *) lp;
281 * Look for value being between current value and next value
282 * if so return these 2 values
284 if (target < tp[1]) {
285 *vlo = tp - (const int16_t *) lp;
293 * Fill the Vpdlist for indices Pmax-Pmin
296 ar2316FillVpdTable(uint32_t pdGainIdx, int16_t Pmin, int16_t Pmax,
297 const int16_t *pwrList, const int16_t *VpdList,
298 uint16_t numIntercepts, uint16_t retVpdList[][64])
301 int16_t currPwr = (int16_t)(2*Pmin);
302 /* since Pmin is pwr*2 and pwrList is 4*pwr */
308 if (numIntercepts < 2)
311 while (ii <= (uint16_t)(Pmax - Pmin)) {
312 GetLowerUpperIndex(currPwr, pwrList, numIntercepts,
315 idxR = 1; /* extrapolate below */
316 if (idxL == (uint32_t)(numIntercepts - 1))
317 idxL = numIntercepts - 2; /* extrapolate above */
318 if (pwrList[idxL] == pwrList[idxR])
322 (((currPwr - pwrList[idxL])*VpdList[idxR]+
323 (pwrList[idxR] - currPwr)*VpdList[idxL])/
324 (pwrList[idxR] - pwrList[idxL]));
325 retVpdList[pdGainIdx][ii] = kk;
327 currPwr += 2; /* half dB steps */
334 * Returns interpolated or the scaled up interpolated value
337 interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight,
338 int16_t targetLeft, int16_t targetRight)
342 if (srcRight != srcLeft) {
343 rv = ((target - srcLeft)*targetRight +
344 (srcRight - target)*targetLeft) / (srcRight - srcLeft);
352 * Uses the data points read from EEPROM to reconstruct the pdadc power table
353 * Called by ar2316SetPowerTable()
356 ar2316getGainBoundariesAndPdadcsForPowers(struct ath_hal *ah, uint16_t channel,
357 const RAW_DATA_STRUCT_2316 *pRawDataset,
358 uint16_t pdGainOverlap_t2,
359 int16_t *pMinCalPower, uint16_t pPdGainBoundaries[],
360 uint16_t pPdGainValues[], uint16_t pPDADCValues[])
362 struct ar2316State *priv = AR2316(ah);
363 #define VpdTable_L priv->vpdTable_L
364 #define VpdTable_R priv->vpdTable_R
365 #define VpdTable_I priv->vpdTable_I
367 int32_t ss;/* potentially -ve index for taking care of pdGainOverlap */
369 uint32_t numPdGainsUsed = 0;
371 * If desired to support -ve power levels in future, just
372 * change pwr_I_0 to signed 5-bits.
374 int16_t Pmin_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
375 /* to accomodate -ve power levels later on. */
376 int16_t Pmax_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
377 /* to accomodate -ve power levels later on */
381 uint32_t sizeCurrVpdTable, maxIndex, tgtIndex;
383 /* Get upper lower index */
384 GetLowerUpperIndex(channel, pRawDataset->pChannels,
385 pRawDataset->numChannels, &(idxL), &(idxR));
387 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
388 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
389 /* work backwards 'cause highest pdGain for lowest power */
390 numVpd = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].numVpd;
392 pPdGainValues[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pd_gain;
393 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0];
394 if (Pmin_t2[numPdGainsUsed] >pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]) {
395 Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0];
397 Pmin_t2[numPdGainsUsed] = (int16_t)
398 (Pmin_t2[numPdGainsUsed] / 2);
399 Pmax_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[numVpd-1];
400 if (Pmax_t2[numPdGainsUsed] > pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1])
401 Pmax_t2[numPdGainsUsed] =
402 pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1];
403 Pmax_t2[numPdGainsUsed] = (int16_t)(Pmax_t2[numPdGainsUsed] / 2);
405 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
406 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0]),
407 &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_L
410 numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
411 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]),
412 &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_R
414 for (kk = 0; kk < (uint16_t)(Pmax_t2[numPdGainsUsed] - Pmin_t2[numPdGainsUsed]); kk++) {
415 VpdTable_I[numPdGainsUsed][kk] =
417 channel, pRawDataset->pChannels[idxL], pRawDataset->pChannels[idxR],
418 (int16_t)VpdTable_L[numPdGainsUsed][kk], (int16_t)VpdTable_R[numPdGainsUsed][kk]);
420 /* fill VpdTable_I for this pdGain */
423 /* if this pdGain is used */
426 *pMinCalPower = Pmin_t2[0];
427 kk = 0; /* index for the final table */
428 for (ii = 0; ii < numPdGainsUsed; ii++) {
429 if (ii == (numPdGainsUsed - 1))
430 pPdGainBoundaries[ii] = Pmax_t2[ii] +
431 PD_GAIN_BOUNDARY_STRETCH_IN_HALF_DB;
433 pPdGainBoundaries[ii] = (uint16_t)
434 ((Pmax_t2[ii] + Pmin_t2[ii+1]) / 2 );
435 if (pPdGainBoundaries[ii] > 63) {
436 HALDEBUG(ah, HAL_DEBUG_ANY,
437 "%s: clamp pPdGainBoundaries[%d] %d\n",
438 __func__, ii, pPdGainBoundaries[ii]);/*XXX*/
439 pPdGainBoundaries[ii] = 63;
442 /* Find starting index for this pdGain */
444 ss = 0; /* for the first pdGain, start from index 0 */
446 ss = (pPdGainBoundaries[ii-1] - Pmin_t2[ii]) -
448 Vpd_step = (uint16_t)(VpdTable_I[ii][1] - VpdTable_I[ii][0]);
449 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
451 *-ve ss indicates need to extrapolate data below for this pdGain
454 tmpVal = (int16_t)(VpdTable_I[ii][0] + ss*Vpd_step);
455 pPDADCValues[kk++] = (uint16_t)((tmpVal < 0) ? 0 : tmpVal);
459 sizeCurrVpdTable = Pmax_t2[ii] - Pmin_t2[ii];
460 tgtIndex = pPdGainBoundaries[ii] + pdGainOverlap_t2 - Pmin_t2[ii];
461 maxIndex = (tgtIndex < sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;
463 while (ss < (int16_t)maxIndex)
464 pPDADCValues[kk++] = VpdTable_I[ii][ss++];
466 Vpd_step = (uint16_t)(VpdTable_I[ii][sizeCurrVpdTable-1] -
467 VpdTable_I[ii][sizeCurrVpdTable-2]);
468 Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
470 * for last gain, pdGainBoundary == Pmax_t2, so will
471 * have to extrapolate
473 if (tgtIndex > maxIndex) { /* need to extrapolate above */
474 while(ss < (int16_t)tgtIndex) {
476 (VpdTable_I[ii][sizeCurrVpdTable-1] +
477 (ss-maxIndex)*Vpd_step);
478 pPDADCValues[kk++] = (tmpVal > 127) ?
482 } /* extrapolated above */
483 } /* for all pdGainUsed */
485 while (ii < MAX_NUM_PDGAINS_PER_CHANNEL) {
486 pPdGainBoundaries[ii] = pPdGainBoundaries[ii-1];
490 pPDADCValues[kk] = pPDADCValues[kk-1];
494 return numPdGainsUsed;
501 ar2316SetPowerTable(struct ath_hal *ah,
502 int16_t *minPower, int16_t *maxPower,
503 const struct ieee80211_channel *chan,
506 struct ath_hal_5212 *ahp = AH5212(ah);
507 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
508 const RAW_DATA_STRUCT_2316 *pRawDataset = AH_NULL;
509 uint16_t pdGainOverlap_t2;
510 int16_t minCalPower2316_t2;
511 uint16_t *pdadcValues = ahp->ah_pcdacTable;
512 uint16_t gainBoundaries[4];
513 uint32_t reg32, regoffset;
514 int i, numPdGainsUsed;
515 #ifndef AH_USE_INIPDGAIN
519 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan 0x%x flag 0x%x\n",
520 __func__, chan->ic_freq, chan->ic_flags);
522 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
523 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
524 else if (IEEE80211_IS_CHAN_B(chan))
525 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
527 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: illegal mode\n", __func__);
531 pdGainOverlap_t2 = (uint16_t) SM(OS_REG_READ(ah, AR_PHY_TPCRG5),
532 AR_PHY_TPCRG5_PD_GAIN_OVERLAP);
534 numPdGainsUsed = ar2316getGainBoundariesAndPdadcsForPowers(ah,
535 chan->channel, pRawDataset, pdGainOverlap_t2,
536 &minCalPower2316_t2,gainBoundaries, rfXpdGain, pdadcValues);
537 HALASSERT(1 <= numPdGainsUsed && numPdGainsUsed <= 3);
539 #ifdef AH_USE_INIPDGAIN
541 * Use pd_gains curve from eeprom; Atheros always uses
542 * the default curve from the ini file but some vendors
543 * (e.g. Zcomax) want to override this curve and not
544 * honoring their settings results in tx power 5dBm low.
546 OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
547 (pRawDataset->pDataPerChannel[0].numPdGains - 1));
549 tpcrg1 = OS_REG_READ(ah, AR_PHY_TPCRG1);
550 tpcrg1 = (tpcrg1 &~ AR_PHY_TPCRG1_NUM_PD_GAIN)
551 | SM(numPdGainsUsed-1, AR_PHY_TPCRG1_NUM_PD_GAIN);
552 switch (numPdGainsUsed) {
554 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING3;
555 tpcrg1 |= SM(rfXpdGain[2], AR_PHY_TPCRG1_PDGAIN_SETTING3);
558 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING2;
559 tpcrg1 |= SM(rfXpdGain[1], AR_PHY_TPCRG1_PDGAIN_SETTING2);
562 tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING1;
563 tpcrg1 |= SM(rfXpdGain[0], AR_PHY_TPCRG1_PDGAIN_SETTING1);
567 if (tpcrg1 != OS_REG_READ(ah, AR_PHY_TPCRG1))
568 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: using non-default "
569 "pd_gains (default 0x%x, calculated 0x%x)\n",
570 __func__, OS_REG_READ(ah, AR_PHY_TPCRG1), tpcrg1);
572 OS_REG_WRITE(ah, AR_PHY_TPCRG1, tpcrg1);
576 * Note the pdadc table may not start at 0 dBm power, could be
577 * negative or greater than 0. Need to offset the power
578 * values by the amount of minPower for griffin
580 if (minCalPower2316_t2 != 0)
581 ahp->ah_txPowerIndexOffset = (int16_t)(0 - minCalPower2316_t2);
583 ahp->ah_txPowerIndexOffset = 0;
585 /* Finally, write the power values into the baseband power table */
586 regoffset = 0x9800 + (672 <<2); /* beginning of pdadc table in griffin */
587 for (i = 0; i < 32; i++) {
588 reg32 = ((pdadcValues[4*i + 0] & 0xFF) << 0) |
589 ((pdadcValues[4*i + 1] & 0xFF) << 8) |
590 ((pdadcValues[4*i + 2] & 0xFF) << 16) |
591 ((pdadcValues[4*i + 3] & 0xFF) << 24) ;
592 OS_REG_WRITE(ah, regoffset, reg32);
596 OS_REG_WRITE(ah, AR_PHY_TPCRG5,
597 SM(pdGainOverlap_t2, AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
598 SM(gainBoundaries[0], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
599 SM(gainBoundaries[1], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
600 SM(gainBoundaries[2], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
601 SM(gainBoundaries[3], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
607 ar2316GetMinPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2316 *data)
610 uint16_t Pmin=0,numVpd;
612 for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
613 jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
614 /* work backwards 'cause highest pdGain for lowest power */
615 numVpd = data->pDataPerPDGain[jj].numVpd;
617 Pmin = data->pDataPerPDGain[jj].pwr_t4[0];
625 ar2316GetMaxPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2316 *data)
628 uint16_t Pmax=0,numVpd;
630 for (ii=0; ii< MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
631 /* work forwards cuase lowest pdGain for highest power */
632 numVpd = data->pDataPerPDGain[ii].numVpd;
634 Pmax = data->pDataPerPDGain[ii].pwr_t4[numVpd-1];
642 ar2316GetChannelMaxMinPower(struct ath_hal *ah,
643 const struct ieee80211_channel *chan,
644 int16_t *maxPow, int16_t *minPow)
646 uint16_t freq = chan->ic_freq; /* NB: never mapped */
647 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
648 const RAW_DATA_STRUCT_2316 *pRawDataset = AH_NULL;
649 const RAW_DATA_PER_CHANNEL_2316 *data=AH_NULL;
650 uint16_t numChannels;
651 int totalD,totalF, totalMin,last, i;
655 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan))
656 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
657 else if (IEEE80211_IS_CHAN_B(chan))
658 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
662 numChannels = pRawDataset->numChannels;
663 data = pRawDataset->pDataPerChannel;
665 /* Make sure the channel is in the range of the TP values
671 if ((freq < data[0].channelValue) ||
672 (freq > data[numChannels-1].channelValue)) {
673 if (freq < data[0].channelValue) {
674 *maxPow = ar2316GetMaxPower(ah, &data[0]);
675 *minPow = ar2316GetMinPower(ah, &data[0]);
678 *maxPow = ar2316GetMaxPower(ah, &data[numChannels - 1]);
679 *minPow = ar2316GetMinPower(ah, &data[numChannels - 1]);
684 /* Linearly interpolate the power value now */
685 for (last=0,i=0; (i<numChannels) && (freq > data[i].channelValue);
687 totalD = data[i].channelValue - data[last].channelValue;
689 totalF = ar2316GetMaxPower(ah, &data[i]) - ar2316GetMaxPower(ah, &data[last]);
690 *maxPow = (int8_t) ((totalF*(freq-data[last].channelValue) +
691 ar2316GetMaxPower(ah, &data[last])*totalD)/totalD);
692 totalMin = ar2316GetMinPower(ah, &data[i]) - ar2316GetMinPower(ah, &data[last]);
693 *minPow = (int8_t) ((totalMin*(freq-data[last].channelValue) +
694 ar2316GetMinPower(ah, &data[last])*totalD)/totalD);
697 if (freq == data[i].channelValue) {
698 *maxPow = ar2316GetMaxPower(ah, &data[i]);
699 *minPow = ar2316GetMinPower(ah, &data[i]);
707 * Free memory for analog bank scratch buffers
710 ar2316RfDetach(struct ath_hal *ah)
712 struct ath_hal_5212 *ahp = AH5212(ah);
714 HALASSERT(ahp->ah_rfHal != AH_NULL);
715 ath_hal_free(ahp->ah_rfHal);
716 ahp->ah_rfHal = AH_NULL;
720 * Allocate memory for private state.
721 * Scratch Buffer will be reinitialized every reset so no need to zero now
724 ar2316RfAttach(struct ath_hal *ah, HAL_STATUS *status)
726 struct ath_hal_5212 *ahp = AH5212(ah);
727 struct ar2316State *priv;
729 HALASSERT(ah->ah_magic == AR5212_MAGIC);
731 HALASSERT(ahp->ah_rfHal == AH_NULL);
732 priv = ath_hal_malloc(sizeof(struct ar2316State));
733 if (priv == AH_NULL) {
734 HALDEBUG(ah, HAL_DEBUG_ANY,
735 "%s: cannot allocate private state\n", __func__);
736 *status = HAL_ENOMEM; /* XXX */
739 priv->base.rfDetach = ar2316RfDetach;
740 priv->base.writeRegs = ar2316WriteRegs;
741 priv->base.getRfBank = ar2316GetRfBank;
742 priv->base.setChannel = ar2316SetChannel;
743 priv->base.setRfRegs = ar2316SetRfRegs;
744 priv->base.setPowerTable = ar2316SetPowerTable;
745 priv->base.getChannelMaxMinPower = ar2316GetChannelMaxMinPower;
746 priv->base.getNfAdjust = ar5212GetNfAdjust;
748 ahp->ah_pcdacTable = priv->pcdacTable;
749 ahp->ah_pcdacTableSize = sizeof(priv->pcdacTable);
750 ahp->ah_rfHal = &priv->base;
752 ahp->ah_cwCalRequire = AH_TRUE; /* force initial cal */
758 ar2316Probe(struct ath_hal *ah)
762 AH_RF(RF2316, ar2316Probe, ar2316RfAttach);