574
591
#undef XPA_LVL_FREQ
577
static void ath9k_hw_get_def_gain_boundaries_pdadcs(struct ath_hw *ah,
578
struct ath9k_channel *chan,
579
struct cal_data_per_freq *pRawDataSet,
580
u8 *bChans, u16 availPiers,
581
u16 tPdGainOverlap, int16_t *pMinCalPower,
582
u16 *pPdGainBoundaries, u8 *pPDADCValues,
587
u16 idxL = 0, idxR = 0, numPiers;
588
static u8 vpdTableL[AR5416_NUM_PD_GAINS]
589
[AR5416_MAX_PWR_RANGE_IN_HALF_DB];
590
static u8 vpdTableR[AR5416_NUM_PD_GAINS]
591
[AR5416_MAX_PWR_RANGE_IN_HALF_DB];
592
static u8 vpdTableI[AR5416_NUM_PD_GAINS]
593
[AR5416_MAX_PWR_RANGE_IN_HALF_DB];
595
u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
596
u8 minPwrT4[AR5416_NUM_PD_GAINS];
597
u8 maxPwrT4[AR5416_NUM_PD_GAINS];
600
u16 sizeCurrVpdTable, maxIndex, tgtIndex;
602
int16_t minDelta = 0;
603
struct chan_centers centers;
605
ath9k_hw_get_channel_centers(ah, chan, ¢ers);
607
for (numPiers = 0; numPiers < availPiers; numPiers++) {
608
if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
612
match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
614
bChans, numPiers, &idxL, &idxR);
617
for (i = 0; i < numXpdGains; i++) {
618
minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
619
maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
620
ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
621
pRawDataSet[idxL].pwrPdg[i],
622
pRawDataSet[idxL].vpdPdg[i],
623
AR5416_PD_GAIN_ICEPTS,
627
for (i = 0; i < numXpdGains; i++) {
628
pVpdL = pRawDataSet[idxL].vpdPdg[i];
629
pPwrL = pRawDataSet[idxL].pwrPdg[i];
630
pVpdR = pRawDataSet[idxR].vpdPdg[i];
631
pPwrR = pRawDataSet[idxR].pwrPdg[i];
633
minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
636
min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1],
637
pPwrR[AR5416_PD_GAIN_ICEPTS - 1]);
640
ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
642
AR5416_PD_GAIN_ICEPTS,
644
ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
646
AR5416_PD_GAIN_ICEPTS,
649
for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
651
(u8)(ath9k_hw_interpolate((u16)
656
bChans[idxL], bChans[idxR],
657
vpdTableL[i][j], vpdTableR[i][j]));
662
*pMinCalPower = (int16_t)(minPwrT4[0] / 2);
666
for (i = 0; i < numXpdGains; i++) {
667
if (i == (numXpdGains - 1))
668
pPdGainBoundaries[i] =
669
(u16)(maxPwrT4[i] / 2);
671
pPdGainBoundaries[i] =
672
(u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
674
pPdGainBoundaries[i] =
675
min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
677
if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
678
minDelta = pPdGainBoundaries[0] - 23;
679
pPdGainBoundaries[0] = 23;
685
if (AR_SREV_9280_10_OR_LATER(ah))
686
ss = (int16_t)(0 - (minPwrT4[i] / 2));
690
ss = (int16_t)((pPdGainBoundaries[i - 1] -
692
tPdGainOverlap + 1 + minDelta);
694
vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
695
vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
697
while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
698
tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
699
pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
703
sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
704
tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
706
maxIndex = (tgtIndex < sizeCurrVpdTable) ?
707
tgtIndex : sizeCurrVpdTable;
709
while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
710
pPDADCValues[k++] = vpdTableI[i][ss++];
713
vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
714
vpdTableI[i][sizeCurrVpdTable - 2]);
715
vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
717
if (tgtIndex > maxIndex) {
718
while ((ss <= tgtIndex) &&
719
(k < (AR5416_NUM_PDADC_VALUES - 1))) {
720
tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
721
(ss - maxIndex + 1) * vpdStep));
722
pPDADCValues[k++] = (u8)((tmpVal > 255) ?
729
while (i < AR5416_PD_GAINS_IN_MASK) {
730
pPdGainBoundaries[i] = pPdGainBoundaries[i - 1];
734
while (k < AR5416_NUM_PDADC_VALUES) {
735
pPDADCValues[k] = pPDADCValues[k - 1];
594
static int16_t ath9k_change_gain_boundary_setting(struct ath_hw *ah,
597
u16 pdGainOverlap_t2,
598
int8_t pwr_table_offset,
604
/* Prior to writing the boundaries or the pdadc vs. power table
605
* into the chip registers the default starting point on the pdadc
606
* vs. power table needs to be checked and the curve boundaries
607
* adjusted accordingly
609
if (AR_SREV_9280_20_OR_LATER(ah)) {
612
if (AR5416_PWR_TABLE_OFFSET_DB != pwr_table_offset) {
613
/* get the difference in dB */
614
*diff = (u16)(pwr_table_offset - AR5416_PWR_TABLE_OFFSET_DB);
615
/* get the number of half dB steps */
617
/* change the original gain boundary settings
618
* by the number of half dB steps
620
for (k = 0; k < numXpdGain; k++)
621
gb[k] = (u16)(gb[k] - *diff);
623
/* Because of a hardware limitation, ensure the gain boundary
624
* is not larger than (63 - overlap)
626
gb_limit = (u16)(MAX_RATE_POWER - pdGainOverlap_t2);
628
for (k = 0; k < numXpdGain; k++)
629
gb[k] = (u16)min(gb_limit, gb[k]);
635
static void ath9k_adjust_pdadc_values(struct ath_hw *ah,
636
int8_t pwr_table_offset,
640
#define NUM_PDADC(diff) (AR5416_NUM_PDADC_VALUES - diff)
643
/* If this is a board that has a pwrTableOffset that differs from
644
* the default AR5416_PWR_TABLE_OFFSET_DB then the start of the
645
* pdadc vs pwr table needs to be adjusted prior to writing to the
648
if (AR_SREV_9280_20_OR_LATER(ah)) {
649
if (AR5416_PWR_TABLE_OFFSET_DB != pwr_table_offset) {
650
/* shift the table to start at the new offset */
651
for (k = 0; k < (u16)NUM_PDADC(diff); k++ ) {
652
pdadcValues[k] = pdadcValues[k + diff];
655
/* fill the back of the table */
656
for (k = (u16)NUM_PDADC(diff); k < NUM_PDADC(0); k++) {
657
pdadcValues[k] = pdadcValues[NUM_PDADC(diff)];
742
664
static void ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
1191
1132
ath9k_hw_set_def_power_cal_table(ah, chan, &txPowerIndexOffset);
1134
regulatory->max_power_level = 0;
1193
1135
for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
1194
1136
ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
1195
if (ratesArray[i] > AR5416_MAX_RATE_POWER)
1196
ratesArray[i] = AR5416_MAX_RATE_POWER;
1199
if (AR_SREV_9280_10_OR_LATER(ah)) {
1200
for (i = 0; i < Ar5416RateSize; i++)
1201
ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
1137
if (ratesArray[i] > MAX_RATE_POWER)
1138
ratesArray[i] = MAX_RATE_POWER;
1139
if (ratesArray[i] > regulatory->max_power_level)
1140
regulatory->max_power_level = ratesArray[i];
1146
if (IS_CHAN_HT40(chan))
1148
else if (IS_CHAN_HT20(chan))
1151
regulatory->max_power_level = ratesArray[i];
1154
switch(ar5416_get_ntxchains(ah->txchainmask)) {
1158
regulatory->max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
1161
regulatory->max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
1164
ath_dbg(ath9k_hw_common(ah), ATH_DBG_EEPROM,
1165
"Invalid chainmask configuration\n");
1172
if (AR_SREV_9280_20_OR_LATER(ah)) {
1173
for (i = 0; i < Ar5416RateSize; i++) {
1174
int8_t pwr_table_offset;
1176
pwr_table_offset = ah->eep_ops->get_eeprom(ah,
1177
EEP_PWR_TABLE_OFFSET);
1178
ratesArray[i] -= pwr_table_offset * 2;
1204
1182
REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
1287
1265
REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
1288
1266
ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
1289
1267
| ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
1293
if (IS_CHAN_HT40(chan))
1295
else if (IS_CHAN_HT20(chan))
1298
if (AR_SREV_9280_10_OR_LATER(ah))
1299
regulatory->max_power_level =
1300
ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
1302
regulatory->max_power_level = ratesArray[i];
1304
switch(ar5416_get_ntxchains(ah->txchainmask)) {
1308
regulatory->max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
1311
regulatory->max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
1314
DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1315
"Invalid chainmask configuration\n");
1320
static u8 ath9k_hw_def_get_num_ant_config(struct ath_hw *ah,
1321
enum ieee80211_band freq_band)
1323
struct ar5416_eeprom_def *eep = &ah->eeprom.def;
1324
struct modal_eep_header *pModal =
1325
&(eep->modalHeader[ATH9K_HAL_FREQ_BAND_2GHZ == freq_band]);
1326
struct base_eep_header *pBase = &eep->baseEepHeader;
1331
if (pBase->version >= 0x0E0D)
1332
if (pModal->useAnt1)
1333
num_ant_config += 1;
1335
return num_ant_config;
1338
static u16 ath9k_hw_def_get_eeprom_antenna_cfg(struct ath_hw *ah,
1339
struct ath9k_channel *chan)
1341
struct ar5416_eeprom_def *eep = &ah->eeprom.def;
1342
struct modal_eep_header *pModal =
1343
&(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
1345
return pModal->antCtrlCommon & 0xFFFF;
1348
1270
static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
1350
1272
#define EEP_DEF_SPURCHAN \
1351
1273
(ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
1274
struct ath_common *common = ath9k_hw_common(ah);
1353
1276
u16 spur_val = AR_NO_SPUR;
1355
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
1356
"Getting spur idx %d is2Ghz. %d val %x\n",
1278
ath_dbg(common, ATH_DBG_ANI,
1279
"Getting spur idx:%d is2Ghz:%d val:%x\n",
1357
1280
i, is2GHz, ah->config.spurchans[i][is2GHz]);
1359
1282
switch (ah->config.spurmode) {