2 * Copyright (c) 2008-2009 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 static void ath9k_hw_analog_shift_rmw(struct ath_hw *ah,
25 regVal = REG_READ(ah, reg) & ~mask;
26 regVal |= (val << shift) & mask;
28 REG_WRITE(ah, reg, regVal);
30 if (ah->config.analog_shiftreg)
36 static inline u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz)
39 if (fbin == AR5416_BCHAN_UNUSED)
42 return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
45 static inline int16_t ath9k_hw_interpolate(u16 target,
46 u16 srcLeft, u16 srcRight,
52 if (srcRight == srcLeft) {
55 rv = (int16_t) (((target - srcLeft) * targetRight +
56 (srcRight - target) * targetLeft) /
57 (srcRight - srcLeft));
62 static inline bool ath9k_hw_get_lower_upper_index(u8 target, u8 *pList,
63 u16 listSize, u16 *indexL,
68 if (target <= pList[0]) {
69 *indexL = *indexR = 0;
72 if (target >= pList[listSize - 1]) {
73 *indexL = *indexR = (u16) (listSize - 1);
77 for (i = 0; i < listSize - 1; i++) {
78 if (pList[i] == target) {
79 *indexL = *indexR = i;
82 if (target < pList[i + 1]) {
84 *indexR = (u16) (i + 1);
91 static inline bool ath9k_hw_nvram_read(struct ath_hw *ah, u32 off, u16 *data)
93 struct ath_softc *sc = ah->ah_sc;
95 return sc->bus_ops->eeprom_read(ah, off, data);
98 static inline bool ath9k_hw_fill_vpd_table(u8 pwrMin, u8 pwrMax, u8 *pPwrList,
99 u8 *pVpdList, u16 numIntercepts,
104 u16 idxL = 0, idxR = 0;
106 for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) {
107 ath9k_hw_get_lower_upper_index(currPwr, pPwrList,
108 numIntercepts, &(idxL),
112 if (idxL == numIntercepts - 1)
113 idxL = (u16) (numIntercepts - 2);
114 if (pPwrList[idxL] == pPwrList[idxR])
117 k = (u16)(((currPwr - pPwrList[idxL]) * pVpdList[idxR] +
118 (pPwrList[idxR] - currPwr) * pVpdList[idxL]) /
119 (pPwrList[idxR] - pPwrList[idxL]));
120 pRetVpdList[i] = (u8) k;
127 static void ath9k_hw_get_legacy_target_powers(struct ath_hw *ah,
128 struct ath9k_channel *chan,
129 struct cal_target_power_leg *powInfo,
131 struct cal_target_power_leg *pNewPower,
132 u16 numRates, bool isExtTarget)
134 struct chan_centers centers;
137 int matchIndex = -1, lowIndex = -1;
140 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
141 freq = (isExtTarget) ? centers.ext_center : centers.ctl_center;
143 if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel,
144 IS_CHAN_2GHZ(chan))) {
147 for (i = 0; (i < numChannels) &&
148 (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
149 if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
150 IS_CHAN_2GHZ(chan))) {
153 } else if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
154 IS_CHAN_2GHZ(chan))) &&
155 (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
156 IS_CHAN_2GHZ(chan)))) {
161 if ((matchIndex == -1) && (lowIndex == -1))
165 if (matchIndex != -1) {
166 *pNewPower = powInfo[matchIndex];
168 clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
170 chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
173 for (i = 0; i < numRates; i++) {
174 pNewPower->tPow2x[i] =
175 (u8)ath9k_hw_interpolate(freq, clo, chi,
176 powInfo[lowIndex].tPow2x[i],
177 powInfo[lowIndex + 1].tPow2x[i]);
182 static void ath9k_get_txgain_index(struct ath_hw *ah,
183 struct ath9k_channel *chan,
184 struct calDataPerFreqOpLoop *rawDatasetOpLoop,
185 u8 *calChans, u16 availPiers, u8 *pwr, u8 *pcdacIdx)
188 u16 idxL = 0, idxR = 0, numPiers;
190 struct chan_centers centers;
192 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
194 for (numPiers = 0; numPiers < availPiers; numPiers++)
195 if (calChans[numPiers] == AR5416_BCHAN_UNUSED)
198 match = ath9k_hw_get_lower_upper_index(
199 (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
200 calChans, numPiers, &idxL, &idxR);
202 pcdac = rawDatasetOpLoop[idxL].pcdac[0][0];
203 *pwr = rawDatasetOpLoop[idxL].pwrPdg[0][0];
205 pcdac = rawDatasetOpLoop[idxR].pcdac[0][0];
206 *pwr = (rawDatasetOpLoop[idxL].pwrPdg[0][0] +
207 rawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
210 while (pcdac > ah->originalGain[i] &&
211 i < (AR9280_TX_GAIN_TABLE_SIZE - 1))
218 static void ath9k_olc_get_pdadcs(struct ath_hw *ah,
226 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_0,
227 AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
228 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_1,
229 AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
231 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL7,
232 AR_PHY_TX_PWRCTRL_INIT_TX_GAIN, initTxGain);
235 for (i = 0; i < AR5416_NUM_PDADC_VALUES; i++)
237 pPDADCValues[i] = 0x0;
239 pPDADCValues[i] = 0xFF;
245 static void ath9k_hw_get_target_powers(struct ath_hw *ah,
246 struct ath9k_channel *chan,
247 struct cal_target_power_ht *powInfo,
249 struct cal_target_power_ht *pNewPower,
250 u16 numRates, bool isHt40Target)
252 struct chan_centers centers;
255 int matchIndex = -1, lowIndex = -1;
258 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
259 freq = isHt40Target ? centers.synth_center : centers.ctl_center;
261 if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) {
264 for (i = 0; (i < numChannels) &&
265 (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
266 if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
267 IS_CHAN_2GHZ(chan))) {
271 if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
272 IS_CHAN_2GHZ(chan))) &&
273 (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
274 IS_CHAN_2GHZ(chan)))) {
279 if ((matchIndex == -1) && (lowIndex == -1))
283 if (matchIndex != -1) {
284 *pNewPower = powInfo[matchIndex];
286 clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
288 chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
291 for (i = 0; i < numRates; i++) {
292 pNewPower->tPow2x[i] = (u8)ath9k_hw_interpolate(freq,
294 powInfo[lowIndex].tPow2x[i],
295 powInfo[lowIndex + 1].tPow2x[i]);
300 static u16 ath9k_hw_get_max_edge_power(u16 freq,
301 struct cal_ctl_edges *pRdEdgesPower,
302 bool is2GHz, int num_band_edges)
304 u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
307 for (i = 0; (i < num_band_edges) &&
308 (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
309 if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) {
310 twiceMaxEdgePower = pRdEdgesPower[i].tPower;
312 } else if ((i > 0) &&
313 (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
315 if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel,
317 pRdEdgesPower[i - 1].flag) {
319 pRdEdgesPower[i - 1].tPower;
325 return twiceMaxEdgePower;
328 /****************************************/
329 /* EEPROM Operations for 4K sized cards */
330 /****************************************/
332 static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
334 return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF);
337 static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
339 return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF);
342 static bool ath9k_hw_4k_fill_eeprom(struct ath_hw *ah)
344 #define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
345 u16 *eep_data = (u16 *)&ah->eeprom.map4k;
346 int addr, eep_start_loc = 0;
350 if (!ath9k_hw_use_flash(ah)) {
351 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
352 "Reading from EEPROM, not flash\n");
355 for (addr = 0; addr < SIZE_EEPROM_4K; addr++) {
356 if (!ath9k_hw_nvram_read(ah, addr + eep_start_loc, eep_data)) {
357 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
358 "Unable to read eeprom region \n");
365 #undef SIZE_EEPROM_4K
368 static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah)
370 #define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
371 struct ar5416_eeprom_4k *eep =
372 (struct ar5416_eeprom_4k *) &ah->eeprom.map4k;
373 u16 *eepdata, temp, magic, magic2;
375 bool need_swap = false;
379 if (!ath9k_hw_use_flash(ah)) {
380 if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET,
382 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
383 "Reading Magic # failed\n");
387 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
388 "Read Magic = 0x%04X\n", magic);
390 if (magic != AR5416_EEPROM_MAGIC) {
391 magic2 = swab16(magic);
393 if (magic2 == AR5416_EEPROM_MAGIC) {
395 eepdata = (u16 *) (&ah->eeprom);
397 for (addr = 0; addr < EEPROM_4K_SIZE; addr++) {
398 temp = swab16(*eepdata);
403 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
404 "Invalid EEPROM Magic. "
405 "endianness mismatch.\n");
411 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
412 need_swap ? "True" : "False");
415 el = swab16(ah->eeprom.map4k.baseEepHeader.length);
417 el = ah->eeprom.map4k.baseEepHeader.length;
419 if (el > sizeof(struct ar5416_eeprom_4k))
420 el = sizeof(struct ar5416_eeprom_4k) / sizeof(u16);
422 el = el / sizeof(u16);
424 eepdata = (u16 *)(&ah->eeprom);
426 for (i = 0; i < el; i++)
433 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
434 "EEPROM Endianness is not native.. Changing\n");
436 word = swab16(eep->baseEepHeader.length);
437 eep->baseEepHeader.length = word;
439 word = swab16(eep->baseEepHeader.checksum);
440 eep->baseEepHeader.checksum = word;
442 word = swab16(eep->baseEepHeader.version);
443 eep->baseEepHeader.version = word;
445 word = swab16(eep->baseEepHeader.regDmn[0]);
446 eep->baseEepHeader.regDmn[0] = word;
448 word = swab16(eep->baseEepHeader.regDmn[1]);
449 eep->baseEepHeader.regDmn[1] = word;
451 word = swab16(eep->baseEepHeader.rfSilent);
452 eep->baseEepHeader.rfSilent = word;
454 word = swab16(eep->baseEepHeader.blueToothOptions);
455 eep->baseEepHeader.blueToothOptions = word;
457 word = swab16(eep->baseEepHeader.deviceCap);
458 eep->baseEepHeader.deviceCap = word;
460 integer = swab32(eep->modalHeader.antCtrlCommon);
461 eep->modalHeader.antCtrlCommon = integer;
463 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
464 integer = swab32(eep->modalHeader.antCtrlChain[i]);
465 eep->modalHeader.antCtrlChain[i] = integer;
468 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
469 word = swab16(eep->modalHeader.spurChans[i].spurChan);
470 eep->modalHeader.spurChans[i].spurChan = word;
474 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
475 ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
476 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
477 "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
478 sum, ah->eep_ops->get_eeprom_ver(ah));
483 #undef EEPROM_4K_SIZE
486 static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah,
487 enum eeprom_param param)
489 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
490 struct modal_eep_4k_header *pModal = &eep->modalHeader;
491 struct base_eep_header_4k *pBase = &eep->baseEepHeader;
495 return pModal->noiseFloorThreshCh[0];
496 case AR_EEPROM_MAC(0):
497 return pBase->macAddr[0] << 8 | pBase->macAddr[1];
498 case AR_EEPROM_MAC(1):
499 return pBase->macAddr[2] << 8 | pBase->macAddr[3];
500 case AR_EEPROM_MAC(2):
501 return pBase->macAddr[4] << 8 | pBase->macAddr[5];
503 return pBase->regDmn[0];
505 return pBase->regDmn[1];
507 return pBase->deviceCap;
509 return pBase->opCapFlags;
511 return pBase->rfSilent;
513 return pModal->ob_01;
515 return pModal->db1_01;
517 return pBase->version & AR5416_EEP_VER_MINOR_MASK;
519 return pBase->txMask;
521 return pBase->rxMask;
529 static void ath9k_hw_get_4k_gain_boundaries_pdadcs(struct ath_hw *ah,
530 struct ath9k_channel *chan,
531 struct cal_data_per_freq_4k *pRawDataSet,
532 u8 *bChans, u16 availPiers,
533 u16 tPdGainOverlap, int16_t *pMinCalPower,
534 u16 *pPdGainBoundaries, u8 *pPDADCValues,
537 #define TMP_VAL_VPD_TABLE \
538 ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
541 u16 idxL = 0, idxR = 0, numPiers;
542 static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
543 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
544 static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
545 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
546 static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
547 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
549 u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
550 u8 minPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
551 u8 maxPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
554 u16 sizeCurrVpdTable, maxIndex, tgtIndex;
556 int16_t minDelta = 0;
557 struct chan_centers centers;
558 #define PD_GAIN_BOUNDARY_DEFAULT 58;
560 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
562 for (numPiers = 0; numPiers < availPiers; numPiers++) {
563 if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
567 match = ath9k_hw_get_lower_upper_index(
568 (u8)FREQ2FBIN(centers.synth_center,
569 IS_CHAN_2GHZ(chan)), bChans, numPiers,
573 for (i = 0; i < numXpdGains; i++) {
574 minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
575 maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
576 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
577 pRawDataSet[idxL].pwrPdg[i],
578 pRawDataSet[idxL].vpdPdg[i],
579 AR5416_EEP4K_PD_GAIN_ICEPTS,
583 for (i = 0; i < numXpdGains; i++) {
584 pVpdL = pRawDataSet[idxL].vpdPdg[i];
585 pPwrL = pRawDataSet[idxL].pwrPdg[i];
586 pVpdR = pRawDataSet[idxR].vpdPdg[i];
587 pPwrR = pRawDataSet[idxR].pwrPdg[i];
589 minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
592 min(pPwrL[AR5416_EEP4K_PD_GAIN_ICEPTS - 1],
593 pPwrR[AR5416_EEP4K_PD_GAIN_ICEPTS - 1]);
596 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
598 AR5416_EEP4K_PD_GAIN_ICEPTS,
600 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
602 AR5416_EEP4K_PD_GAIN_ICEPTS,
605 for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
607 (u8)(ath9k_hw_interpolate((u16)
612 bChans[idxL], bChans[idxR],
613 vpdTableL[i][j], vpdTableR[i][j]));
618 *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
622 for (i = 0; i < numXpdGains; i++) {
623 if (i == (numXpdGains - 1))
624 pPdGainBoundaries[i] =
625 (u16)(maxPwrT4[i] / 2);
627 pPdGainBoundaries[i] =
628 (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
630 pPdGainBoundaries[i] =
631 min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
633 if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
634 minDelta = pPdGainBoundaries[0] - 23;
635 pPdGainBoundaries[0] = 23;
641 if (AR_SREV_9280_10_OR_LATER(ah))
642 ss = (int16_t)(0 - (minPwrT4[i] / 2));
646 ss = (int16_t)((pPdGainBoundaries[i - 1] -
648 tPdGainOverlap + 1 + minDelta);
650 vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
651 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
653 while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
654 tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
655 pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
659 sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
660 tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
662 maxIndex = (tgtIndex < sizeCurrVpdTable) ?
663 tgtIndex : sizeCurrVpdTable;
665 while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1)))
666 pPDADCValues[k++] = vpdTableI[i][ss++];
668 vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
669 vpdTableI[i][sizeCurrVpdTable - 2]);
670 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
672 if (tgtIndex >= maxIndex) {
673 while ((ss <= tgtIndex) &&
674 (k < (AR5416_NUM_PDADC_VALUES - 1))) {
675 tmpVal = (int16_t) TMP_VAL_VPD_TABLE;
676 pPDADCValues[k++] = (u8)((tmpVal > 255) ?
683 while (i < AR5416_EEP4K_PD_GAINS_IN_MASK) {
684 pPdGainBoundaries[i] = PD_GAIN_BOUNDARY_DEFAULT;
688 while (k < AR5416_NUM_PDADC_VALUES) {
689 pPDADCValues[k] = pPDADCValues[k - 1];
694 #undef TMP_VAL_VPD_TABLE
697 static void ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah,
698 struct ath9k_channel *chan,
699 int16_t *pTxPowerIndexOffset)
701 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
702 struct cal_data_per_freq_4k *pRawDataset;
703 u8 *pCalBChans = NULL;
704 u16 pdGainOverlap_t2;
705 static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
706 u16 gainBoundaries[AR5416_EEP4K_PD_GAINS_IN_MASK];
708 int16_t tMinCalPower;
709 u16 numXpdGain, xpdMask;
710 u16 xpdGainValues[AR5416_EEP4K_NUM_PD_GAINS] = { 0, 0 };
711 u32 reg32, regOffset, regChainOffset;
713 xpdMask = pEepData->modalHeader.xpdGain;
715 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
716 AR5416_EEP_MINOR_VER_2) {
718 pEepData->modalHeader.pdGainOverlap;
720 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
721 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
724 pCalBChans = pEepData->calFreqPier2G;
725 numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS;
729 for (i = 1; i <= AR5416_EEP4K_PD_GAINS_IN_MASK; i++) {
730 if ((xpdMask >> (AR5416_EEP4K_PD_GAINS_IN_MASK - i)) & 1) {
731 if (numXpdGain >= AR5416_EEP4K_NUM_PD_GAINS)
733 xpdGainValues[numXpdGain] =
734 (u16)(AR5416_EEP4K_PD_GAINS_IN_MASK - i);
739 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
740 (numXpdGain - 1) & 0x3);
741 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
743 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
745 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, 0);
747 for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
748 if (AR_SREV_5416_20_OR_LATER(ah) &&
749 (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
751 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
753 regChainOffset = i * 0x1000;
755 if (pEepData->baseEepHeader.txMask & (1 << i)) {
756 pRawDataset = pEepData->calPierData2G[i];
758 ath9k_hw_get_4k_gain_boundaries_pdadcs(ah, chan,
759 pRawDataset, pCalBChans,
760 numPiers, pdGainOverlap_t2,
761 &tMinCalPower, gainBoundaries,
762 pdadcValues, numXpdGain);
764 if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
765 REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset,
767 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
768 | SM(gainBoundaries[0],
769 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
770 | SM(gainBoundaries[1],
771 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
772 | SM(gainBoundaries[2],
773 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
774 | SM(gainBoundaries[3],
775 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
778 regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
779 for (j = 0; j < 32; j++) {
780 reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
781 ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
782 ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
783 ((pdadcValues[4 * j + 3] & 0xFF) << 24);
784 REG_WRITE(ah, regOffset, reg32);
786 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
787 "PDADC (%d,%4x): %4.4x %8.8x\n",
788 i, regChainOffset, regOffset,
790 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
792 "PDADC %3d Value %3d | "
793 "PDADC %3d Value %3d | "
794 "PDADC %3d Value %3d | "
795 "PDADC %3d Value %3d |\n",
796 i, 4 * j, pdadcValues[4 * j],
797 4 * j + 1, pdadcValues[4 * j + 1],
798 4 * j + 2, pdadcValues[4 * j + 2],
800 pdadcValues[4 * j + 3]);
807 *pTxPowerIndexOffset = 0;
810 static void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
811 struct ath9k_channel *chan,
814 u16 AntennaReduction,
815 u16 twiceMaxRegulatoryPower,
818 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
819 u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
820 static const u16 tpScaleReductionTable[5] =
821 { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
824 int16_t twiceLargestAntenna;
825 struct cal_ctl_data_4k *rep;
826 struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
829 struct cal_target_power_leg targetPowerOfdmExt = {
830 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
833 struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
836 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
837 u16 ctlModesFor11g[] =
838 { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
841 u16 numCtlModes, *pCtlMode, ctlMode, freq;
842 struct chan_centers centers;
844 u16 twiceMinEdgePower;
846 tx_chainmask = ah->txchainmask;
848 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
850 twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0];
852 twiceLargestAntenna = (int16_t)min(AntennaReduction -
853 twiceLargestAntenna, 0);
855 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
857 if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) {
858 maxRegAllowedPower -=
859 (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
862 scaledPower = min(powerLimit, maxRegAllowedPower);
863 scaledPower = max((u16)0, scaledPower);
865 numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
866 pCtlMode = ctlModesFor11g;
868 ath9k_hw_get_legacy_target_powers(ah, chan,
869 pEepData->calTargetPowerCck,
870 AR5416_NUM_2G_CCK_TARGET_POWERS,
871 &targetPowerCck, 4, false);
872 ath9k_hw_get_legacy_target_powers(ah, chan,
873 pEepData->calTargetPower2G,
874 AR5416_NUM_2G_20_TARGET_POWERS,
875 &targetPowerOfdm, 4, false);
876 ath9k_hw_get_target_powers(ah, chan,
877 pEepData->calTargetPower2GHT20,
878 AR5416_NUM_2G_20_TARGET_POWERS,
879 &targetPowerHt20, 8, false);
881 if (IS_CHAN_HT40(chan)) {
882 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
883 ath9k_hw_get_target_powers(ah, chan,
884 pEepData->calTargetPower2GHT40,
885 AR5416_NUM_2G_40_TARGET_POWERS,
886 &targetPowerHt40, 8, true);
887 ath9k_hw_get_legacy_target_powers(ah, chan,
888 pEepData->calTargetPowerCck,
889 AR5416_NUM_2G_CCK_TARGET_POWERS,
890 &targetPowerCckExt, 4, true);
891 ath9k_hw_get_legacy_target_powers(ah, chan,
892 pEepData->calTargetPower2G,
893 AR5416_NUM_2G_20_TARGET_POWERS,
894 &targetPowerOfdmExt, 4, true);
897 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
898 bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
899 (pCtlMode[ctlMode] == CTL_2GHT40);
901 freq = centers.synth_center;
902 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
903 freq = centers.ext_center;
905 freq = centers.ctl_center;
907 if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
908 ah->eep_ops->get_eeprom_rev(ah) <= 2)
909 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
911 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
912 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
914 ctlMode, numCtlModes, isHt40CtlMode,
915 (pCtlMode[ctlMode] & EXT_ADDITIVE));
917 for (i = 0; (i < AR5416_NUM_CTLS) &&
918 pEepData->ctlIndex[i]; i++) {
919 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
920 " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
921 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
923 i, cfgCtl, pCtlMode[ctlMode],
924 pEepData->ctlIndex[i], chan->channel);
926 if ((((cfgCtl & ~CTL_MODE_M) |
927 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
928 pEepData->ctlIndex[i]) ||
929 (((cfgCtl & ~CTL_MODE_M) |
930 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
931 ((pEepData->ctlIndex[i] & CTL_MODE_M) |
933 rep = &(pEepData->ctlData[i]);
936 ath9k_hw_get_max_edge_power(freq,
937 rep->ctlEdges[ar5416_get_ntxchains
940 AR5416_EEP4K_NUM_BAND_EDGES);
942 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
943 " MATCH-EE_IDX %d: ch %d is2 %d "
944 "2xMinEdge %d chainmask %d chains %d\n",
945 i, freq, IS_CHAN_2GHZ(chan),
946 twiceMinEdgePower, tx_chainmask,
949 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
951 min(twiceMaxEdgePower,
954 twiceMaxEdgePower = twiceMinEdgePower;
960 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
962 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
963 " SEL-Min ctlMode %d pCtlMode %d "
964 "2xMaxEdge %d sP %d minCtlPwr %d\n",
965 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
966 scaledPower, minCtlPower);
968 switch (pCtlMode[ctlMode]) {
970 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x);
972 targetPowerCck.tPow2x[i] =
973 min((u16)targetPowerCck.tPow2x[i],
978 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x);
980 targetPowerOfdm.tPow2x[i] =
981 min((u16)targetPowerOfdm.tPow2x[i],
986 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x);
988 targetPowerHt20.tPow2x[i] =
989 min((u16)targetPowerHt20.tPow2x[i],
994 targetPowerCckExt.tPow2x[0] = min((u16)
995 targetPowerCckExt.tPow2x[0],
999 targetPowerOfdmExt.tPow2x[0] = min((u16)
1000 targetPowerOfdmExt.tPow2x[0],
1004 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x);
1006 targetPowerHt40.tPow2x[i] =
1007 min((u16)targetPowerHt40.tPow2x[i],
1016 ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
1017 ratesArray[rate18mb] = ratesArray[rate24mb] =
1018 targetPowerOfdm.tPow2x[0];
1019 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
1020 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
1021 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
1022 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
1024 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
1025 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
1027 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
1028 ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1];
1029 ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
1030 ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3];
1032 if (IS_CHAN_HT40(chan)) {
1033 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
1034 ratesArray[rateHt40_0 + i] =
1035 targetPowerHt40.tPow2x[i];
1037 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
1038 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
1039 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
1040 ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
1044 static void ath9k_hw_4k_set_txpower(struct ath_hw *ah,
1045 struct ath9k_channel *chan,
1047 u8 twiceAntennaReduction,
1048 u8 twiceMaxRegulatoryPower,
1051 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
1052 struct modal_eep_4k_header *pModal = &pEepData->modalHeader;
1053 int16_t ratesArray[Ar5416RateSize];
1054 int16_t txPowerIndexOffset = 0;
1055 u8 ht40PowerIncForPdadc = 2;
1058 memset(ratesArray, 0, sizeof(ratesArray));
1060 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1061 AR5416_EEP_MINOR_VER_2) {
1062 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
1065 ath9k_hw_set_4k_power_per_rate_table(ah, chan,
1066 &ratesArray[0], cfgCtl,
1067 twiceAntennaReduction,
1068 twiceMaxRegulatoryPower,
1071 ath9k_hw_set_4k_power_cal_table(ah, chan, &txPowerIndexOffset);
1073 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
1074 ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
1075 if (ratesArray[i] > AR5416_MAX_RATE_POWER)
1076 ratesArray[i] = AR5416_MAX_RATE_POWER;
1079 if (AR_SREV_9280_10_OR_LATER(ah)) {
1080 for (i = 0; i < Ar5416RateSize; i++)
1081 ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
1084 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
1085 ATH9K_POW_SM(ratesArray[rate18mb], 24)
1086 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
1087 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
1088 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
1089 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
1090 ATH9K_POW_SM(ratesArray[rate54mb], 24)
1091 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
1092 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
1093 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
1095 if (IS_CHAN_2GHZ(chan)) {
1096 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
1097 ATH9K_POW_SM(ratesArray[rate2s], 24)
1098 | ATH9K_POW_SM(ratesArray[rate2l], 16)
1099 | ATH9K_POW_SM(ratesArray[rateXr], 8)
1100 | ATH9K_POW_SM(ratesArray[rate1l], 0));
1101 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
1102 ATH9K_POW_SM(ratesArray[rate11s], 24)
1103 | ATH9K_POW_SM(ratesArray[rate11l], 16)
1104 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
1105 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
1108 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
1109 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
1110 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
1111 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
1112 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
1113 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
1114 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
1115 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
1116 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
1117 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
1119 if (IS_CHAN_HT40(chan)) {
1120 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
1121 ATH9K_POW_SM(ratesArray[rateHt40_3] +
1122 ht40PowerIncForPdadc, 24)
1123 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
1124 ht40PowerIncForPdadc, 16)
1125 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
1126 ht40PowerIncForPdadc, 8)
1127 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
1128 ht40PowerIncForPdadc, 0));
1129 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
1130 ATH9K_POW_SM(ratesArray[rateHt40_7] +
1131 ht40PowerIncForPdadc, 24)
1132 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
1133 ht40PowerIncForPdadc, 16)
1134 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
1135 ht40PowerIncForPdadc, 8)
1136 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
1137 ht40PowerIncForPdadc, 0));
1139 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
1140 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
1141 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
1142 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
1143 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
1148 if (IS_CHAN_HT40(chan))
1150 else if (IS_CHAN_HT20(chan))
1153 if (AR_SREV_9280_10_OR_LATER(ah))
1154 ah->regulatory.max_power_level =
1155 ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
1157 ah->regulatory.max_power_level = ratesArray[i];
1161 static void ath9k_hw_4k_set_addac(struct ath_hw *ah,
1162 struct ath9k_channel *chan)
1164 struct modal_eep_4k_header *pModal;
1165 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
1168 if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
1171 if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
1174 pModal = &eep->modalHeader;
1176 if (pModal->xpaBiasLvl != 0xff) {
1177 biaslevel = pModal->xpaBiasLvl;
1178 INI_RA(&ah->iniAddac, 7, 1) =
1179 (INI_RA(&ah->iniAddac, 7, 1) & (~0x18)) | biaslevel << 3;
1183 static void ath9k_hw_4k_set_gain(struct ath_hw *ah,
1184 struct modal_eep_4k_header *pModal,
1185 struct ar5416_eeprom_4k *eep,
1186 u8 txRxAttenLocal, int regChainOffset)
1188 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
1189 pModal->antCtrlChain[0]);
1191 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
1192 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
1193 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
1194 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
1195 SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
1196 SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
1198 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1199 AR5416_EEP_MINOR_VER_3) {
1200 txRxAttenLocal = pModal->txRxAttenCh[0];
1202 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1203 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]);
1204 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1205 AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
1206 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1207 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
1208 pModal->xatten2Margin[0]);
1209 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1210 AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]);
1213 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
1214 AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
1215 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
1216 AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
1218 if (AR_SREV_9285_11(ah))
1219 REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14));
1222 static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
1223 struct ath9k_channel *chan)
1225 struct modal_eep_4k_header *pModal;
1226 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
1228 u8 ob[5], db1[5], db2[5];
1229 u8 ant_div_control1, ant_div_control2;
1232 pModal = &eep->modalHeader;
1233 txRxAttenLocal = 23;
1235 REG_WRITE(ah, AR_PHY_SWITCH_COM,
1236 ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
1238 /* Single chain for 4K EEPROM*/
1239 ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal, 0);
1241 /* Initialize Ant Diversity settings from EEPROM */
1242 if (pModal->version == 3) {
1243 ant_div_control1 = ((pModal->ob_234 >> 12) & 0xf);
1244 ant_div_control2 = ((pModal->db1_234 >> 12) & 0xf);
1245 regVal = REG_READ(ah, 0x99ac);
1246 regVal &= (~(0x7f000000));
1247 regVal |= ((ant_div_control1 & 0x1) << 24);
1248 regVal |= (((ant_div_control1 >> 1) & 0x1) << 29);
1249 regVal |= (((ant_div_control1 >> 2) & 0x1) << 30);
1250 regVal |= ((ant_div_control2 & 0x3) << 25);
1251 regVal |= (((ant_div_control2 >> 2) & 0x3) << 27);
1252 REG_WRITE(ah, 0x99ac, regVal);
1253 regVal = REG_READ(ah, 0x99ac);
1254 regVal = REG_READ(ah, 0xa208);
1255 regVal &= (~(0x1 << 13));
1256 regVal |= (((ant_div_control1 >> 3) & 0x1) << 13);
1257 REG_WRITE(ah, 0xa208, regVal);
1258 regVal = REG_READ(ah, 0xa208);
1261 if (pModal->version >= 2) {
1262 ob[0] = (pModal->ob_01 & 0xf);
1263 ob[1] = (pModal->ob_01 >> 4) & 0xf;
1264 ob[2] = (pModal->ob_234 & 0xf);
1265 ob[3] = ((pModal->ob_234 >> 4) & 0xf);
1266 ob[4] = ((pModal->ob_234 >> 8) & 0xf);
1268 db1[0] = (pModal->db1_01 & 0xf);
1269 db1[1] = ((pModal->db1_01 >> 4) & 0xf);
1270 db1[2] = (pModal->db1_234 & 0xf);
1271 db1[3] = ((pModal->db1_234 >> 4) & 0xf);
1272 db1[4] = ((pModal->db1_234 >> 8) & 0xf);
1274 db2[0] = (pModal->db2_01 & 0xf);
1275 db2[1] = ((pModal->db2_01 >> 4) & 0xf);
1276 db2[2] = (pModal->db2_234 & 0xf);
1277 db2[3] = ((pModal->db2_234 >> 4) & 0xf);
1278 db2[4] = ((pModal->db2_234 >> 8) & 0xf);
1280 } else if (pModal->version == 1) {
1281 ob[0] = (pModal->ob_01 & 0xf);
1282 ob[1] = ob[2] = ob[3] = ob[4] = (pModal->ob_01 >> 4) & 0xf;
1283 db1[0] = (pModal->db1_01 & 0xf);
1284 db1[1] = db1[2] = db1[3] =
1285 db1[4] = ((pModal->db1_01 >> 4) & 0xf);
1286 db2[0] = (pModal->db2_01 & 0xf);
1287 db2[1] = db2[2] = db2[3] =
1288 db2[4] = ((pModal->db2_01 >> 4) & 0xf);
1291 for (i = 0; i < 5; i++) {
1292 ob[i] = pModal->ob_01;
1293 db1[i] = pModal->db1_01;
1294 db2[i] = pModal->db1_01;
1298 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1299 AR9285_AN_RF2G3_OB_0, AR9285_AN_RF2G3_OB_0_S, ob[0]);
1300 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1301 AR9285_AN_RF2G3_OB_1, AR9285_AN_RF2G3_OB_1_S, ob[1]);
1302 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1303 AR9285_AN_RF2G3_OB_2, AR9285_AN_RF2G3_OB_2_S, ob[2]);
1304 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1305 AR9285_AN_RF2G3_OB_3, AR9285_AN_RF2G3_OB_3_S, ob[3]);
1306 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1307 AR9285_AN_RF2G3_OB_4, AR9285_AN_RF2G3_OB_4_S, ob[4]);
1309 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1310 AR9285_AN_RF2G3_DB1_0, AR9285_AN_RF2G3_DB1_0_S, db1[0]);
1311 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1312 AR9285_AN_RF2G3_DB1_1, AR9285_AN_RF2G3_DB1_1_S, db1[1]);
1313 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1314 AR9285_AN_RF2G3_DB1_2, AR9285_AN_RF2G3_DB1_2_S, db1[2]);
1315 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1316 AR9285_AN_RF2G4_DB1_3, AR9285_AN_RF2G4_DB1_3_S, db1[3]);
1317 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1318 AR9285_AN_RF2G4_DB1_4, AR9285_AN_RF2G4_DB1_4_S, db1[4]);
1320 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1321 AR9285_AN_RF2G4_DB2_0, AR9285_AN_RF2G4_DB2_0_S, db2[0]);
1322 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1323 AR9285_AN_RF2G4_DB2_1, AR9285_AN_RF2G4_DB2_1_S, db2[1]);
1324 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1325 AR9285_AN_RF2G4_DB2_2, AR9285_AN_RF2G4_DB2_2_S, db2[2]);
1326 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1327 AR9285_AN_RF2G4_DB2_3, AR9285_AN_RF2G4_DB2_3_S, db2[3]);
1328 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1329 AR9285_AN_RF2G4_DB2_4, AR9285_AN_RF2G4_DB2_4_S, db2[4]);
1332 if (AR_SREV_9285_11(ah))
1333 REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
1335 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
1336 pModal->switchSettling);
1337 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
1338 pModal->adcDesiredSize);
1340 REG_WRITE(ah, AR_PHY_RF_CTL4,
1341 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
1342 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
1343 SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
1344 SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
1346 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
1347 pModal->txEndToRxOn);
1348 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
1350 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
1353 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1354 AR5416_EEP_MINOR_VER_2) {
1355 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
1356 pModal->txFrameToDataStart);
1357 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
1358 pModal->txFrameToPaOn);
1361 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1362 AR5416_EEP_MINOR_VER_3) {
1363 if (IS_CHAN_HT40(chan))
1364 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1365 AR_PHY_SETTLING_SWITCH,
1366 pModal->swSettleHt40);
1370 static u16 ath9k_hw_4k_get_eeprom_antenna_cfg(struct ath_hw *ah,
1371 struct ath9k_channel *chan)
1373 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
1374 struct modal_eep_4k_header *pModal = &eep->modalHeader;
1376 return pModal->antCtrlCommon & 0xFFFF;
1379 static u8 ath9k_hw_4k_get_num_ant_config(struct ath_hw *ah,
1380 enum ieee80211_band freq_band)
1385 static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
1387 #define EEP_MAP4K_SPURCHAN \
1388 (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan)
1390 u16 spur_val = AR_NO_SPUR;
1392 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
1393 "Getting spur idx %d is2Ghz. %d val %x\n",
1394 i, is2GHz, ah->config.spurchans[i][is2GHz]);
1396 switch (ah->config.spurmode) {
1399 case SPUR_ENABLE_IOCTL:
1400 spur_val = ah->config.spurchans[i][is2GHz];
1401 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
1402 "Getting spur val from new loc. %d\n", spur_val);
1404 case SPUR_ENABLE_EEPROM:
1405 spur_val = EEP_MAP4K_SPURCHAN;
1411 #undef EEP_MAP4K_SPURCHAN
1414 static struct eeprom_ops eep_4k_ops = {
1415 .check_eeprom = ath9k_hw_4k_check_eeprom,
1416 .get_eeprom = ath9k_hw_4k_get_eeprom,
1417 .fill_eeprom = ath9k_hw_4k_fill_eeprom,
1418 .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver,
1419 .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev,
1420 .get_num_ant_config = ath9k_hw_4k_get_num_ant_config,
1421 .get_eeprom_antenna_cfg = ath9k_hw_4k_get_eeprom_antenna_cfg,
1422 .set_board_values = ath9k_hw_4k_set_board_values,
1423 .set_addac = ath9k_hw_4k_set_addac,
1424 .set_txpower = ath9k_hw_4k_set_txpower,
1425 .get_spur_channel = ath9k_hw_4k_get_spur_channel
1428 /************************************************/
1429 /* EEPROM Operations for non-4K (Default) cards */
1430 /************************************************/
1432 static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
1434 return ((ah->eeprom.def.baseEepHeader.version >> 12) & 0xF);
1437 static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
1439 return ((ah->eeprom.def.baseEepHeader.version) & 0xFFF);
1442 static bool ath9k_hw_def_fill_eeprom(struct ath_hw *ah)
1444 #define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(u16))
1445 u16 *eep_data = (u16 *)&ah->eeprom.def;
1446 int addr, ar5416_eep_start_loc = 0x100;
1448 for (addr = 0; addr < SIZE_EEPROM_DEF; addr++) {
1449 if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc,
1451 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
1452 "Unable to read eeprom region\n");
1458 #undef SIZE_EEPROM_DEF
1461 static int ath9k_hw_def_check_eeprom(struct ath_hw *ah)
1463 struct ar5416_eeprom_def *eep =
1464 (struct ar5416_eeprom_def *) &ah->eeprom.def;
1465 u16 *eepdata, temp, magic, magic2;
1467 bool need_swap = false;
1470 if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
1471 DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Reading Magic # failed\n");
1475 if (!ath9k_hw_use_flash(ah)) {
1476 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1477 "Read Magic = 0x%04X\n", magic);
1479 if (magic != AR5416_EEPROM_MAGIC) {
1480 magic2 = swab16(magic);
1482 if (magic2 == AR5416_EEPROM_MAGIC) {
1483 size = sizeof(struct ar5416_eeprom_def);
1485 eepdata = (u16 *) (&ah->eeprom);
1487 for (addr = 0; addr < size / sizeof(u16); addr++) {
1488 temp = swab16(*eepdata);
1493 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
1494 "Invalid EEPROM Magic. "
1495 "Endianness mismatch.\n");
1501 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
1502 need_swap ? "True" : "False");
1505 el = swab16(ah->eeprom.def.baseEepHeader.length);
1507 el = ah->eeprom.def.baseEepHeader.length;
1509 if (el > sizeof(struct ar5416_eeprom_def))
1510 el = sizeof(struct ar5416_eeprom_def) / sizeof(u16);
1512 el = el / sizeof(u16);
1514 eepdata = (u16 *)(&ah->eeprom);
1516 for (i = 0; i < el; i++)
1523 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1524 "EEPROM Endianness is not native.. Changing.\n");
1526 word = swab16(eep->baseEepHeader.length);
1527 eep->baseEepHeader.length = word;
1529 word = swab16(eep->baseEepHeader.checksum);
1530 eep->baseEepHeader.checksum = word;
1532 word = swab16(eep->baseEepHeader.version);
1533 eep->baseEepHeader.version = word;
1535 word = swab16(eep->baseEepHeader.regDmn[0]);
1536 eep->baseEepHeader.regDmn[0] = word;
1538 word = swab16(eep->baseEepHeader.regDmn[1]);
1539 eep->baseEepHeader.regDmn[1] = word;
1541 word = swab16(eep->baseEepHeader.rfSilent);
1542 eep->baseEepHeader.rfSilent = word;
1544 word = swab16(eep->baseEepHeader.blueToothOptions);
1545 eep->baseEepHeader.blueToothOptions = word;
1547 word = swab16(eep->baseEepHeader.deviceCap);
1548 eep->baseEepHeader.deviceCap = word;
1550 for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
1551 struct modal_eep_header *pModal =
1552 &eep->modalHeader[j];
1553 integer = swab32(pModal->antCtrlCommon);
1554 pModal->antCtrlCommon = integer;
1556 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
1557 integer = swab32(pModal->antCtrlChain[i]);
1558 pModal->antCtrlChain[i] = integer;
1561 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
1562 word = swab16(pModal->spurChans[i].spurChan);
1563 pModal->spurChans[i].spurChan = word;
1568 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
1569 ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
1570 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
1571 "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
1572 sum, ah->eep_ops->get_eeprom_ver(ah));
1579 static u32 ath9k_hw_def_get_eeprom(struct ath_hw *ah,
1580 enum eeprom_param param)
1582 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
1583 struct modal_eep_header *pModal = eep->modalHeader;
1584 struct base_eep_header *pBase = &eep->baseEepHeader;
1587 case EEP_NFTHRESH_5:
1588 return pModal[0].noiseFloorThreshCh[0];
1589 case EEP_NFTHRESH_2:
1590 return pModal[1].noiseFloorThreshCh[0];
1591 case AR_EEPROM_MAC(0):
1592 return pBase->macAddr[0] << 8 | pBase->macAddr[1];
1593 case AR_EEPROM_MAC(1):
1594 return pBase->macAddr[2] << 8 | pBase->macAddr[3];
1595 case AR_EEPROM_MAC(2):
1596 return pBase->macAddr[4] << 8 | pBase->macAddr[5];
1598 return pBase->regDmn[0];
1600 return pBase->regDmn[1];
1602 return pBase->deviceCap;
1604 return pBase->opCapFlags;
1606 return pBase->rfSilent;
1608 return pModal[0].ob;
1610 return pModal[0].db;
1612 return pModal[1].ob;
1614 return pModal[1].db;
1616 return AR5416_VER_MASK;
1618 return pBase->txMask;
1620 return pBase->rxMask;
1621 case EEP_RXGAIN_TYPE:
1622 return pBase->rxGainType;
1623 case EEP_TXGAIN_TYPE:
1624 return pBase->txGainType;
1625 case EEP_OL_PWRCTRL:
1626 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
1627 return pBase->openLoopPwrCntl ? true : false;
1630 case EEP_RC_CHAIN_MASK:
1631 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
1632 return pBase->rcChainMask;
1635 case EEP_DAC_HPWR_5G:
1636 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
1637 return pBase->dacHiPwrMode_5G;
1641 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
1642 return pBase->frac_n_5g;
1650 static void ath9k_hw_def_set_gain(struct ath_hw *ah,
1651 struct modal_eep_header *pModal,
1652 struct ar5416_eeprom_def *eep,
1653 u8 txRxAttenLocal, int regChainOffset, int i)
1655 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
1656 txRxAttenLocal = pModal->txRxAttenCh[i];
1658 if (AR_SREV_9280_10_OR_LATER(ah)) {
1659 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1660 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
1661 pModal->bswMargin[i]);
1662 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1663 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
1664 pModal->bswAtten[i]);
1665 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1666 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
1667 pModal->xatten2Margin[i]);
1668 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1669 AR_PHY_GAIN_2GHZ_XATTEN2_DB,
1670 pModal->xatten2Db[i]);
1672 REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1673 (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
1674 ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
1675 | SM(pModal-> bswMargin[i],
1676 AR_PHY_GAIN_2GHZ_BSW_MARGIN));
1677 REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1678 (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
1679 ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
1680 | SM(pModal->bswAtten[i],
1681 AR_PHY_GAIN_2GHZ_BSW_ATTEN));
1685 if (AR_SREV_9280_10_OR_LATER(ah)) {
1687 AR_PHY_RXGAIN + regChainOffset,
1688 AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
1690 AR_PHY_RXGAIN + regChainOffset,
1691 AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[i]);
1694 AR_PHY_RXGAIN + regChainOffset,
1695 (REG_READ(ah, AR_PHY_RXGAIN + regChainOffset) &
1696 ~AR_PHY_RXGAIN_TXRX_ATTEN)
1697 | SM(txRxAttenLocal, AR_PHY_RXGAIN_TXRX_ATTEN));
1699 AR_PHY_GAIN_2GHZ + regChainOffset,
1700 (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
1701 ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
1702 SM(pModal->rxTxMarginCh[i], AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
1706 static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
1707 struct ath9k_channel *chan)
1709 struct modal_eep_header *pModal;
1710 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
1711 int i, regChainOffset;
1714 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
1715 txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
1717 REG_WRITE(ah, AR_PHY_SWITCH_COM,
1718 ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
1720 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
1721 if (AR_SREV_9280(ah)) {
1726 if (AR_SREV_5416_20_OR_LATER(ah) &&
1727 (ah->rxchainmask == 5 || ah->txchainmask == 5) && (i != 0))
1728 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
1730 regChainOffset = i * 0x1000;
1732 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
1733 pModal->antCtrlChain[i]);
1735 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
1736 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
1737 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
1738 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
1739 SM(pModal->iqCalICh[i],
1740 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
1741 SM(pModal->iqCalQCh[i],
1742 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
1744 if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah))
1745 ath9k_hw_def_set_gain(ah, pModal, eep, txRxAttenLocal,
1749 if (AR_SREV_9280_10_OR_LATER(ah)) {
1750 if (IS_CHAN_2GHZ(chan)) {
1751 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
1753 AR_AN_RF2G1_CH0_OB_S,
1755 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
1757 AR_AN_RF2G1_CH0_DB_S,
1759 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
1761 AR_AN_RF2G1_CH1_OB_S,
1763 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
1765 AR_AN_RF2G1_CH1_DB_S,
1768 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
1769 AR_AN_RF5G1_CH0_OB5,
1770 AR_AN_RF5G1_CH0_OB5_S,
1772 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
1773 AR_AN_RF5G1_CH0_DB5,
1774 AR_AN_RF5G1_CH0_DB5_S,
1776 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
1777 AR_AN_RF5G1_CH1_OB5,
1778 AR_AN_RF5G1_CH1_OB5_S,
1780 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
1781 AR_AN_RF5G1_CH1_DB5,
1782 AR_AN_RF5G1_CH1_DB5_S,
1785 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
1786 AR_AN_TOP2_XPABIAS_LVL,
1787 AR_AN_TOP2_XPABIAS_LVL_S,
1788 pModal->xpaBiasLvl);
1789 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
1790 AR_AN_TOP2_LOCALBIAS,
1791 AR_AN_TOP2_LOCALBIAS_S,
1792 pModal->local_bias);
1793 REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
1794 pModal->force_xpaon);
1797 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
1798 pModal->switchSettling);
1799 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
1800 pModal->adcDesiredSize);
1802 if (!AR_SREV_9280_10_OR_LATER(ah))
1803 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
1804 AR_PHY_DESIRED_SZ_PGA,
1805 pModal->pgaDesiredSize);
1807 REG_WRITE(ah, AR_PHY_RF_CTL4,
1808 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
1809 | SM(pModal->txEndToXpaOff,
1810 AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
1811 | SM(pModal->txFrameToXpaOn,
1812 AR_PHY_RF_CTL4_FRAME_XPAA_ON)
1813 | SM(pModal->txFrameToXpaOn,
1814 AR_PHY_RF_CTL4_FRAME_XPAB_ON));
1816 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
1817 pModal->txEndToRxOn);
1819 if (AR_SREV_9280_10_OR_LATER(ah)) {
1820 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
1822 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
1823 AR_PHY_EXT_CCA0_THRESH62,
1826 REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
1828 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
1829 AR_PHY_EXT_CCA_THRESH62,
1833 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
1834 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
1835 AR_PHY_TX_END_DATA_START,
1836 pModal->txFrameToDataStart);
1837 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
1838 pModal->txFrameToPaOn);
1841 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
1842 if (IS_CHAN_HT40(chan))
1843 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1844 AR_PHY_SETTLING_SWITCH,
1845 pModal->swSettleHt40);
1848 if (AR_SREV_9280_20_OR_LATER(ah) &&
1849 AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
1850 REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
1851 AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
1855 if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
1856 if (IS_CHAN_2GHZ(chan))
1857 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
1858 eep->baseEepHeader.dacLpMode);
1859 else if (eep->baseEepHeader.dacHiPwrMode_5G)
1860 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, 0);
1862 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
1863 eep->baseEepHeader.dacLpMode);
1865 REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, AR_PHY_FRAME_CTL_TX_CLIP,
1866 pModal->miscBits >> 2);
1868 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL9,
1869 AR_PHY_TX_DESIRED_SCALE_CCK,
1870 eep->baseEepHeader.desiredScaleCCK);
1874 static void ath9k_hw_def_set_addac(struct ath_hw *ah,
1875 struct ath9k_channel *chan)
1877 #define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
1878 struct modal_eep_header *pModal;
1879 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
1882 if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
1885 if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
1888 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
1890 if (pModal->xpaBiasLvl != 0xff) {
1891 biaslevel = pModal->xpaBiasLvl;
1893 u16 resetFreqBin, freqBin, freqCount = 0;
1894 struct chan_centers centers;
1896 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
1898 resetFreqBin = FREQ2FBIN(centers.synth_center,
1899 IS_CHAN_2GHZ(chan));
1900 freqBin = XPA_LVL_FREQ(0) & 0xff;
1901 biaslevel = (u8) (XPA_LVL_FREQ(0) >> 14);
1905 while (freqCount < 3) {
1906 if (XPA_LVL_FREQ(freqCount) == 0x0)
1909 freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
1910 if (resetFreqBin >= freqBin)
1911 biaslevel = (u8)(XPA_LVL_FREQ(freqCount) >> 14);
1918 if (IS_CHAN_2GHZ(chan)) {
1919 INI_RA(&ah->iniAddac, 7, 1) = (INI_RA(&ah->iniAddac,
1920 7, 1) & (~0x18)) | biaslevel << 3;
1922 INI_RA(&ah->iniAddac, 6, 1) = (INI_RA(&ah->iniAddac,
1923 6, 1) & (~0xc0)) | biaslevel << 6;
1928 static void ath9k_hw_get_def_gain_boundaries_pdadcs(struct ath_hw *ah,
1929 struct ath9k_channel *chan,
1930 struct cal_data_per_freq *pRawDataSet,
1931 u8 *bChans, u16 availPiers,
1932 u16 tPdGainOverlap, int16_t *pMinCalPower,
1933 u16 *pPdGainBoundaries, u8 *pPDADCValues,
1938 u16 idxL = 0, idxR = 0, numPiers;
1939 static u8 vpdTableL[AR5416_NUM_PD_GAINS]
1940 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
1941 static u8 vpdTableR[AR5416_NUM_PD_GAINS]
1942 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
1943 static u8 vpdTableI[AR5416_NUM_PD_GAINS]
1944 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
1946 u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
1947 u8 minPwrT4[AR5416_NUM_PD_GAINS];
1948 u8 maxPwrT4[AR5416_NUM_PD_GAINS];
1951 u16 sizeCurrVpdTable, maxIndex, tgtIndex;
1953 int16_t minDelta = 0;
1954 struct chan_centers centers;
1956 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
1958 for (numPiers = 0; numPiers < availPiers; numPiers++) {
1959 if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
1963 match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
1964 IS_CHAN_2GHZ(chan)),
1965 bChans, numPiers, &idxL, &idxR);
1968 for (i = 0; i < numXpdGains; i++) {
1969 minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
1970 maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
1971 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
1972 pRawDataSet[idxL].pwrPdg[i],
1973 pRawDataSet[idxL].vpdPdg[i],
1974 AR5416_PD_GAIN_ICEPTS,
1978 for (i = 0; i < numXpdGains; i++) {
1979 pVpdL = pRawDataSet[idxL].vpdPdg[i];
1980 pPwrL = pRawDataSet[idxL].pwrPdg[i];
1981 pVpdR = pRawDataSet[idxR].vpdPdg[i];
1982 pPwrR = pRawDataSet[idxR].pwrPdg[i];
1984 minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
1987 min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1],
1988 pPwrR[AR5416_PD_GAIN_ICEPTS - 1]);
1991 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
1993 AR5416_PD_GAIN_ICEPTS,
1995 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
1997 AR5416_PD_GAIN_ICEPTS,
2000 for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
2002 (u8)(ath9k_hw_interpolate((u16)
2007 bChans[idxL], bChans[idxR],
2008 vpdTableL[i][j], vpdTableR[i][j]));
2013 *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
2017 for (i = 0; i < numXpdGains; i++) {
2018 if (i == (numXpdGains - 1))
2019 pPdGainBoundaries[i] =
2020 (u16)(maxPwrT4[i] / 2);
2022 pPdGainBoundaries[i] =
2023 (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
2025 pPdGainBoundaries[i] =
2026 min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
2028 if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
2029 minDelta = pPdGainBoundaries[0] - 23;
2030 pPdGainBoundaries[0] = 23;
2036 if (AR_SREV_9280_10_OR_LATER(ah))
2037 ss = (int16_t)(0 - (minPwrT4[i] / 2));
2041 ss = (int16_t)((pPdGainBoundaries[i - 1] -
2042 (minPwrT4[i] / 2)) -
2043 tPdGainOverlap + 1 + minDelta);
2045 vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
2046 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
2048 while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
2049 tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
2050 pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
2054 sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
2055 tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
2057 maxIndex = (tgtIndex < sizeCurrVpdTable) ?
2058 tgtIndex : sizeCurrVpdTable;
2060 while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
2061 pPDADCValues[k++] = vpdTableI[i][ss++];
2064 vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
2065 vpdTableI[i][sizeCurrVpdTable - 2]);
2066 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
2068 if (tgtIndex > maxIndex) {
2069 while ((ss <= tgtIndex) &&
2070 (k < (AR5416_NUM_PDADC_VALUES - 1))) {
2071 tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
2072 (ss - maxIndex + 1) * vpdStep));
2073 pPDADCValues[k++] = (u8)((tmpVal > 255) ?
2080 while (i < AR5416_PD_GAINS_IN_MASK) {
2081 pPdGainBoundaries[i] = pPdGainBoundaries[i - 1];
2085 while (k < AR5416_NUM_PDADC_VALUES) {
2086 pPDADCValues[k] = pPDADCValues[k - 1];
2093 static void ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
2094 struct ath9k_channel *chan,
2095 int16_t *pTxPowerIndexOffset)
2097 #define SM_PD_GAIN(x) SM(0x38, AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##x)
2098 #define SM_PDGAIN_B(x, y) \
2099 SM((gainBoundaries[x]), AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##y)
2101 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
2102 struct cal_data_per_freq *pRawDataset;
2103 u8 *pCalBChans = NULL;
2104 u16 pdGainOverlap_t2;
2105 static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
2106 u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
2108 int16_t tMinCalPower;
2109 u16 numXpdGain, xpdMask;
2110 u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
2111 u32 reg32, regOffset, regChainOffset;
2114 modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
2115 xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
2117 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
2118 AR5416_EEP_MINOR_VER_2) {
2120 pEepData->modalHeader[modalIdx].pdGainOverlap;
2122 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
2123 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
2126 if (IS_CHAN_2GHZ(chan)) {
2127 pCalBChans = pEepData->calFreqPier2G;
2128 numPiers = AR5416_NUM_2G_CAL_PIERS;
2130 pCalBChans = pEepData->calFreqPier5G;
2131 numPiers = AR5416_NUM_5G_CAL_PIERS;
2134 if (OLC_FOR_AR9280_20_LATER && IS_CHAN_2GHZ(chan)) {
2135 pRawDataset = pEepData->calPierData2G[0];
2136 ah->initPDADC = ((struct calDataPerFreqOpLoop *)
2137 pRawDataset)->vpdPdg[0][0];
2142 for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
2143 if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
2144 if (numXpdGain >= AR5416_NUM_PD_GAINS)
2146 xpdGainValues[numXpdGain] =
2147 (u16)(AR5416_PD_GAINS_IN_MASK - i);
2152 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
2153 (numXpdGain - 1) & 0x3);
2154 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
2156 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
2158 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
2161 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
2162 if (AR_SREV_5416_20_OR_LATER(ah) &&
2163 (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
2165 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
2167 regChainOffset = i * 0x1000;
2169 if (pEepData->baseEepHeader.txMask & (1 << i)) {
2170 if (IS_CHAN_2GHZ(chan))
2171 pRawDataset = pEepData->calPierData2G[i];
2173 pRawDataset = pEepData->calPierData5G[i];
2176 if (OLC_FOR_AR9280_20_LATER) {
2180 ath9k_get_txgain_index(ah, chan,
2181 (struct calDataPerFreqOpLoop *)pRawDataset,
2182 pCalBChans, numPiers, &txPower, &pcdacIdx);
2183 ath9k_olc_get_pdadcs(ah, pcdacIdx,
2184 txPower/2, pdadcValues);
2186 ath9k_hw_get_def_gain_boundaries_pdadcs(ah,
2188 pCalBChans, numPiers,
2196 if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
2197 if (OLC_FOR_AR9280_20_LATER) {
2199 AR_PHY_TPCRG5 + regChainOffset,
2201 AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
2202 SM_PD_GAIN(1) | SM_PD_GAIN(2) |
2203 SM_PD_GAIN(3) | SM_PD_GAIN(4));
2206 AR_PHY_TPCRG5 + regChainOffset,
2207 SM(pdGainOverlap_t2,
2208 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)|
2216 regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
2217 for (j = 0; j < 32; j++) {
2218 reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
2219 ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
2220 ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
2221 ((pdadcValues[4 * j + 3] & 0xFF) << 24);
2222 REG_WRITE(ah, regOffset, reg32);
2224 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2225 "PDADC (%d,%4x): %4.4x %8.8x\n",
2226 i, regChainOffset, regOffset,
2228 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2229 "PDADC: Chain %d | PDADC %3d "
2230 "Value %3d | PDADC %3d Value %3d | "
2231 "PDADC %3d Value %3d | PDADC %3d "
2233 i, 4 * j, pdadcValues[4 * j],
2234 4 * j + 1, pdadcValues[4 * j + 1],
2235 4 * j + 2, pdadcValues[4 * j + 2],
2237 pdadcValues[4 * j + 3]);
2244 *pTxPowerIndexOffset = 0;
2249 static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
2250 struct ath9k_channel *chan,
2251 int16_t *ratesArray,
2253 u16 AntennaReduction,
2254 u16 twiceMaxRegulatoryPower,
2257 #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
2258 #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */
2260 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
2261 u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
2262 static const u16 tpScaleReductionTable[5] =
2263 { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
2266 int16_t twiceLargestAntenna;
2267 struct cal_ctl_data *rep;
2268 struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
2271 struct cal_target_power_leg targetPowerOfdmExt = {
2272 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
2275 struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
2278 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
2279 u16 ctlModesFor11a[] =
2280 { CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40 };
2281 u16 ctlModesFor11g[] =
2282 { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
2285 u16 numCtlModes, *pCtlMode, ctlMode, freq;
2286 struct chan_centers centers;
2288 u16 twiceMinEdgePower;
2290 tx_chainmask = ah->txchainmask;
2292 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
2294 twiceLargestAntenna = max(
2295 pEepData->modalHeader
2296 [IS_CHAN_2GHZ(chan)].antennaGainCh[0],
2297 pEepData->modalHeader
2298 [IS_CHAN_2GHZ(chan)].antennaGainCh[1]);
2300 twiceLargestAntenna = max((u8)twiceLargestAntenna,
2301 pEepData->modalHeader
2302 [IS_CHAN_2GHZ(chan)].antennaGainCh[2]);
2304 twiceLargestAntenna = (int16_t)min(AntennaReduction -
2305 twiceLargestAntenna, 0);
2307 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
2309 if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) {
2310 maxRegAllowedPower -=
2311 (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
2314 scaledPower = min(powerLimit, maxRegAllowedPower);
2316 switch (ar5416_get_ntxchains(tx_chainmask)) {
2320 scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
2323 scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
2327 scaledPower = max((u16)0, scaledPower);
2329 if (IS_CHAN_2GHZ(chan)) {
2330 numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
2331 SUB_NUM_CTL_MODES_AT_2G_40;
2332 pCtlMode = ctlModesFor11g;
2334 ath9k_hw_get_legacy_target_powers(ah, chan,
2335 pEepData->calTargetPowerCck,
2336 AR5416_NUM_2G_CCK_TARGET_POWERS,
2337 &targetPowerCck, 4, false);
2338 ath9k_hw_get_legacy_target_powers(ah, chan,
2339 pEepData->calTargetPower2G,
2340 AR5416_NUM_2G_20_TARGET_POWERS,
2341 &targetPowerOfdm, 4, false);
2342 ath9k_hw_get_target_powers(ah, chan,
2343 pEepData->calTargetPower2GHT20,
2344 AR5416_NUM_2G_20_TARGET_POWERS,
2345 &targetPowerHt20, 8, false);
2347 if (IS_CHAN_HT40(chan)) {
2348 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
2349 ath9k_hw_get_target_powers(ah, chan,
2350 pEepData->calTargetPower2GHT40,
2351 AR5416_NUM_2G_40_TARGET_POWERS,
2352 &targetPowerHt40, 8, true);
2353 ath9k_hw_get_legacy_target_powers(ah, chan,
2354 pEepData->calTargetPowerCck,
2355 AR5416_NUM_2G_CCK_TARGET_POWERS,
2356 &targetPowerCckExt, 4, true);
2357 ath9k_hw_get_legacy_target_powers(ah, chan,
2358 pEepData->calTargetPower2G,
2359 AR5416_NUM_2G_20_TARGET_POWERS,
2360 &targetPowerOfdmExt, 4, true);
2363 numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
2364 SUB_NUM_CTL_MODES_AT_5G_40;
2365 pCtlMode = ctlModesFor11a;
2367 ath9k_hw_get_legacy_target_powers(ah, chan,
2368 pEepData->calTargetPower5G,
2369 AR5416_NUM_5G_20_TARGET_POWERS,
2370 &targetPowerOfdm, 4, false);
2371 ath9k_hw_get_target_powers(ah, chan,
2372 pEepData->calTargetPower5GHT20,
2373 AR5416_NUM_5G_20_TARGET_POWERS,
2374 &targetPowerHt20, 8, false);
2376 if (IS_CHAN_HT40(chan)) {
2377 numCtlModes = ARRAY_SIZE(ctlModesFor11a);
2378 ath9k_hw_get_target_powers(ah, chan,
2379 pEepData->calTargetPower5GHT40,
2380 AR5416_NUM_5G_40_TARGET_POWERS,
2381 &targetPowerHt40, 8, true);
2382 ath9k_hw_get_legacy_target_powers(ah, chan,
2383 pEepData->calTargetPower5G,
2384 AR5416_NUM_5G_20_TARGET_POWERS,
2385 &targetPowerOfdmExt, 4, true);
2389 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
2390 bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
2391 (pCtlMode[ctlMode] == CTL_2GHT40);
2393 freq = centers.synth_center;
2394 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
2395 freq = centers.ext_center;
2397 freq = centers.ctl_center;
2399 if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
2400 ah->eep_ops->get_eeprom_rev(ah) <= 2)
2401 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
2403 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2404 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
2405 "EXT_ADDITIVE %d\n",
2406 ctlMode, numCtlModes, isHt40CtlMode,
2407 (pCtlMode[ctlMode] & EXT_ADDITIVE));
2409 for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
2410 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2411 " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
2412 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
2414 i, cfgCtl, pCtlMode[ctlMode],
2415 pEepData->ctlIndex[i], chan->channel);
2417 if ((((cfgCtl & ~CTL_MODE_M) |
2418 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
2419 pEepData->ctlIndex[i]) ||
2420 (((cfgCtl & ~CTL_MODE_M) |
2421 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
2422 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
2423 rep = &(pEepData->ctlData[i]);
2425 twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
2426 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
2427 IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
2429 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2430 " MATCH-EE_IDX %d: ch %d is2 %d "
2431 "2xMinEdge %d chainmask %d chains %d\n",
2432 i, freq, IS_CHAN_2GHZ(chan),
2433 twiceMinEdgePower, tx_chainmask,
2434 ar5416_get_ntxchains
2436 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
2437 twiceMaxEdgePower = min(twiceMaxEdgePower,
2440 twiceMaxEdgePower = twiceMinEdgePower;
2446 minCtlPower = min(twiceMaxEdgePower, scaledPower);
2448 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2449 " SEL-Min ctlMode %d pCtlMode %d "
2450 "2xMaxEdge %d sP %d minCtlPwr %d\n",
2451 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
2452 scaledPower, minCtlPower);
2454 switch (pCtlMode[ctlMode]) {
2456 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
2457 targetPowerCck.tPow2x[i] =
2458 min((u16)targetPowerCck.tPow2x[i],
2464 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
2465 targetPowerOfdm.tPow2x[i] =
2466 min((u16)targetPowerOfdm.tPow2x[i],
2472 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
2473 targetPowerHt20.tPow2x[i] =
2474 min((u16)targetPowerHt20.tPow2x[i],
2479 targetPowerCckExt.tPow2x[0] = min((u16)
2480 targetPowerCckExt.tPow2x[0],
2485 targetPowerOfdmExt.tPow2x[0] = min((u16)
2486 targetPowerOfdmExt.tPow2x[0],
2491 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
2492 targetPowerHt40.tPow2x[i] =
2493 min((u16)targetPowerHt40.tPow2x[i],
2502 ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
2503 ratesArray[rate18mb] = ratesArray[rate24mb] =
2504 targetPowerOfdm.tPow2x[0];
2505 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
2506 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
2507 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
2508 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
2510 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
2511 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
2513 if (IS_CHAN_2GHZ(chan)) {
2514 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
2515 ratesArray[rate2s] = ratesArray[rate2l] =
2516 targetPowerCck.tPow2x[1];
2517 ratesArray[rate5_5s] = ratesArray[rate5_5l] =
2518 targetPowerCck.tPow2x[2];
2519 ratesArray[rate11s] = ratesArray[rate11l] =
2520 targetPowerCck.tPow2x[3];
2522 if (IS_CHAN_HT40(chan)) {
2523 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
2524 ratesArray[rateHt40_0 + i] =
2525 targetPowerHt40.tPow2x[i];
2527 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
2528 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
2529 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
2530 if (IS_CHAN_2GHZ(chan)) {
2531 ratesArray[rateExtCck] =
2532 targetPowerCckExt.tPow2x[0];
2537 static void ath9k_hw_def_set_txpower(struct ath_hw *ah,
2538 struct ath9k_channel *chan,
2540 u8 twiceAntennaReduction,
2541 u8 twiceMaxRegulatoryPower,
2544 #define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
2545 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
2546 struct modal_eep_header *pModal =
2547 &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
2548 int16_t ratesArray[Ar5416RateSize];
2549 int16_t txPowerIndexOffset = 0;
2550 u8 ht40PowerIncForPdadc = 2;
2551 int i, cck_ofdm_delta = 0;
2553 memset(ratesArray, 0, sizeof(ratesArray));
2555 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
2556 AR5416_EEP_MINOR_VER_2) {
2557 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
2560 ath9k_hw_set_def_power_per_rate_table(ah, chan,
2561 &ratesArray[0], cfgCtl,
2562 twiceAntennaReduction,
2563 twiceMaxRegulatoryPower,
2566 ath9k_hw_set_def_power_cal_table(ah, chan, &txPowerIndexOffset);
2568 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
2569 ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
2570 if (ratesArray[i] > AR5416_MAX_RATE_POWER)
2571 ratesArray[i] = AR5416_MAX_RATE_POWER;
2574 if (AR_SREV_9280_10_OR_LATER(ah)) {
2575 for (i = 0; i < Ar5416RateSize; i++)
2576 ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
2579 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
2580 ATH9K_POW_SM(ratesArray[rate18mb], 24)
2581 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
2582 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
2583 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
2584 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
2585 ATH9K_POW_SM(ratesArray[rate54mb], 24)
2586 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
2587 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
2588 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
2590 if (IS_CHAN_2GHZ(chan)) {
2591 if (OLC_FOR_AR9280_20_LATER) {
2593 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
2594 ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24)
2595 | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16)
2596 | ATH9K_POW_SM(ratesArray[rateXr], 8)
2597 | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0));
2598 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
2599 ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24)
2600 | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16)
2601 | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8)
2602 | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0));
2604 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
2605 ATH9K_POW_SM(ratesArray[rate2s], 24)
2606 | ATH9K_POW_SM(ratesArray[rate2l], 16)
2607 | ATH9K_POW_SM(ratesArray[rateXr], 8)
2608 | ATH9K_POW_SM(ratesArray[rate1l], 0));
2609 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
2610 ATH9K_POW_SM(ratesArray[rate11s], 24)
2611 | ATH9K_POW_SM(ratesArray[rate11l], 16)
2612 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
2613 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
2617 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
2618 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
2619 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
2620 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
2621 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
2622 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
2623 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
2624 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
2625 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
2626 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
2628 if (IS_CHAN_HT40(chan)) {
2629 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
2630 ATH9K_POW_SM(ratesArray[rateHt40_3] +
2631 ht40PowerIncForPdadc, 24)
2632 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
2633 ht40PowerIncForPdadc, 16)
2634 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
2635 ht40PowerIncForPdadc, 8)
2636 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
2637 ht40PowerIncForPdadc, 0));
2638 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
2639 ATH9K_POW_SM(ratesArray[rateHt40_7] +
2640 ht40PowerIncForPdadc, 24)
2641 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
2642 ht40PowerIncForPdadc, 16)
2643 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
2644 ht40PowerIncForPdadc, 8)
2645 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
2646 ht40PowerIncForPdadc, 0));
2647 if (OLC_FOR_AR9280_20_LATER) {
2648 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
2649 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
2650 | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16)
2651 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
2652 | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0));
2654 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
2655 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
2656 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
2657 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
2658 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
2662 REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
2663 ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
2664 | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
2668 if (IS_CHAN_HT40(chan))
2670 else if (IS_CHAN_HT20(chan))
2673 if (AR_SREV_9280_10_OR_LATER(ah))
2674 ah->regulatory.max_power_level =
2675 ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
2677 ah->regulatory.max_power_level = ratesArray[i];
2679 switch(ar5416_get_ntxchains(ah->txchainmask)) {
2683 ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
2686 ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
2689 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2690 "Invalid chainmask configuration\n");
2695 static u8 ath9k_hw_def_get_num_ant_config(struct ath_hw *ah,
2696 enum ieee80211_band freq_band)
2698 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
2699 struct modal_eep_header *pModal =
2700 &(eep->modalHeader[ATH9K_HAL_FREQ_BAND_2GHZ == freq_band]);
2701 struct base_eep_header *pBase = &eep->baseEepHeader;
2706 if (pBase->version >= 0x0E0D)
2707 if (pModal->useAnt1)
2708 num_ant_config += 1;
2710 return num_ant_config;
2713 static u16 ath9k_hw_def_get_eeprom_antenna_cfg(struct ath_hw *ah,
2714 struct ath9k_channel *chan)
2716 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
2717 struct modal_eep_header *pModal =
2718 &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
2720 return pModal->antCtrlCommon & 0xFFFF;
2723 static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
2725 #define EEP_DEF_SPURCHAN \
2726 (ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
2728 u16 spur_val = AR_NO_SPUR;
2730 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2731 "Getting spur idx %d is2Ghz. %d val %x\n",
2732 i, is2GHz, ah->config.spurchans[i][is2GHz]);
2734 switch (ah->config.spurmode) {
2737 case SPUR_ENABLE_IOCTL:
2738 spur_val = ah->config.spurchans[i][is2GHz];
2739 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2740 "Getting spur val from new loc. %d\n", spur_val);
2742 case SPUR_ENABLE_EEPROM:
2743 spur_val = EEP_DEF_SPURCHAN;
2749 #undef EEP_DEF_SPURCHAN
2752 static struct eeprom_ops eep_def_ops = {
2753 .check_eeprom = ath9k_hw_def_check_eeprom,
2754 .get_eeprom = ath9k_hw_def_get_eeprom,
2755 .fill_eeprom = ath9k_hw_def_fill_eeprom,
2756 .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver,
2757 .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev,
2758 .get_num_ant_config = ath9k_hw_def_get_num_ant_config,
2759 .get_eeprom_antenna_cfg = ath9k_hw_def_get_eeprom_antenna_cfg,
2760 .set_board_values = ath9k_hw_def_set_board_values,
2761 .set_addac = ath9k_hw_def_set_addac,
2762 .set_txpower = ath9k_hw_def_set_txpower,
2763 .get_spur_channel = ath9k_hw_def_get_spur_channel
2766 int ath9k_hw_eeprom_attach(struct ath_hw *ah)
2770 if (AR_SREV_9285(ah)) {
2771 ah->eep_map = EEP_MAP_4KBITS;
2772 ah->eep_ops = &eep_4k_ops;
2774 ah->eep_map = EEP_MAP_DEFAULT;
2775 ah->eep_ops = &eep_def_ops;
2778 if (!ah->eep_ops->fill_eeprom(ah))
2781 status = ah->eep_ops->check_eeprom(ah);