aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath/ath9k/eeprom_9287.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-10-08 14:06:20 -0400
committerJohn W. Linville <linville@tuxdriver.com>2011-10-11 16:41:26 -0400
commitca2c68cc7bc80fc4504fb420df04cce99c9ee6ec (patch)
tree999cd166f17b1d47226961267c1dd93ae9c8a4fd /drivers/net/wireless/ath/ath9k/eeprom_9287.c
parent72d874c67c3cdf21ca95045baabac6a5843222d8 (diff)
ath9k_hw: clean up tx power handling
The code for handling various restrictions concerning regulatory limits, antenna gain, etc. is very convoluted and duplicated across various EEPROM parsing implementations, making it hard to review. This patch partially cleans up the mess by unifying regulatory limit handling in one function and simplifying handling of antenna gain. It also removes unused transmit power scaling arrays from the EEPROM code, which belonged to an unimplemented API that isn't supposed to be in the driver anyway. Signed-off-by: Felix Fietkau <nbd@openwrt.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/ath/ath9k/eeprom_9287.c')
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_9287.c33
1 files changed, 6 insertions, 27 deletions
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_9287.c b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
index 6698b722b604..90d771fa2dea 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
@@ -336,6 +336,9 @@ static u32 ath9k_hw_ar9287_get_eeprom(struct ath_hw *ah,
336 return pBase->tempSensSlopePalOn; 336 return pBase->tempSensSlopePalOn;
337 else 337 else
338 return 0; 338 return 0;
339 case EEP_ANTENNA_GAIN_2G:
340 return max_t(u8, pModal->antennaGainCh[0],
341 pModal->antennaGainCh[1]);
339 default: 342 default:
340 return 0; 343 return 0;
341 } 344 }
@@ -554,8 +557,7 @@ static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
554 struct ath9k_channel *chan, 557 struct ath9k_channel *chan,
555 int16_t *ratesArray, 558 int16_t *ratesArray,
556 u16 cfgCtl, 559 u16 cfgCtl,
557 u16 AntennaReduction, 560 u16 antenna_reduction,
558 u16 twiceMaxRegulatoryPower,
559 u16 powerLimit) 561 u16 powerLimit)
560{ 562{
561#define CMP_CTL \ 563#define CMP_CTL \
@@ -569,12 +571,8 @@ static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
569#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 571#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
570#define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 572#define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
571 573
572 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
573 u16 twiceMaxEdgePower = MAX_RATE_POWER; 574 u16 twiceMaxEdgePower = MAX_RATE_POWER;
574 static const u16 tpScaleReductionTable[5] =
575 { 0, 3, 6, 9, MAX_RATE_POWER };
576 int i; 575 int i;
577 int16_t twiceLargestAntenna;
578 struct cal_ctl_data_ar9287 *rep; 576 struct cal_ctl_data_ar9287 *rep;
579 struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} }, 577 struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
580 targetPowerCck = {0, {0, 0, 0, 0} }; 578 targetPowerCck = {0, {0, 0, 0, 0} };
@@ -582,7 +580,7 @@ static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
582 targetPowerCckExt = {0, {0, 0, 0, 0} }; 580 targetPowerCckExt = {0, {0, 0, 0, 0} };
583 struct cal_target_power_ht targetPowerHt20, 581 struct cal_target_power_ht targetPowerHt20,
584 targetPowerHt40 = {0, {0, 0, 0, 0} }; 582 targetPowerHt40 = {0, {0, 0, 0, 0} };
585 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower; 583 u16 scaledPower = 0, minCtlPower;
586 static const u16 ctlModesFor11g[] = { 584 static const u16 ctlModesFor11g[] = {
587 CTL_11B, CTL_11G, CTL_2GHT20, 585 CTL_11B, CTL_11G, CTL_2GHT20,
588 CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40 586 CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
@@ -597,24 +595,7 @@ static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
597 tx_chainmask = ah->txchainmask; 595 tx_chainmask = ah->txchainmask;
598 596
599 ath9k_hw_get_channel_centers(ah, chan, &centers); 597 ath9k_hw_get_channel_centers(ah, chan, &centers);
600 598 scaledPower = powerLimit - antenna_reduction;
601 /* Compute TxPower reduction due to Antenna Gain */
602 twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
603 pEepData->modalHeader.antennaGainCh[1]);
604 twiceLargestAntenna = (int16_t)min((AntennaReduction) -
605 twiceLargestAntenna, 0);
606
607 /*
608 * scaledPower is the minimum of the user input power level
609 * and the regulatory allowed power level.
610 */
611 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
612
613 if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
614 maxRegAllowedPower -=
615 (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
616
617 scaledPower = min(powerLimit, maxRegAllowedPower);
618 599
619 /* 600 /*
620 * Reduce scaled Power by number of chains active 601 * Reduce scaled Power by number of chains active
@@ -815,7 +796,6 @@ static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
815static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah, 796static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
816 struct ath9k_channel *chan, u16 cfgCtl, 797 struct ath9k_channel *chan, u16 cfgCtl,
817 u8 twiceAntennaReduction, 798 u8 twiceAntennaReduction,
818 u8 twiceMaxRegulatoryPower,
819 u8 powerLimit, bool test) 799 u8 powerLimit, bool test)
820{ 800{
821 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); 801 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
@@ -834,7 +814,6 @@ static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
834 ath9k_hw_set_ar9287_power_per_rate_table(ah, chan, 814 ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
835 &ratesArray[0], cfgCtl, 815 &ratesArray[0], cfgCtl,
836 twiceAntennaReduction, 816 twiceAntennaReduction,
837 twiceMaxRegulatoryPower,
838 powerLimit); 817 powerLimit);
839 818
840 ath9k_hw_set_ar9287_power_cal_table(ah, chan); 819 ath9k_hw_set_ar9287_power_cal_table(ah, chan);