diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2012-04-14 16:01:58 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2012-04-16 14:38:53 -0400 |
commit | ea6f792b2b893249e0eeffdb3fe0ea191eaf80d7 (patch) | |
tree | 1e306360812654cd4988b09ea01ab8eb53c8cf37 | |
parent | 21bd6ea3116998e429dad796bce785e18df39daa (diff) |
ath9k: introduce ath9k_hw_get_scaled_power helper
The computation of the scaled power value in
various eeprom files uses identical code. Move
that code into a helper function and use that
instead of code duplication.
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | drivers/net/wireless/ath/ath9k/ar9003_eeprom.c | 28 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/eeprom.c | 33 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/eeprom.h | 5 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/eeprom_9287.c | 30 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/eeprom_def.c | 23 |
5 files changed, 44 insertions, 75 deletions
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c index 25a4a022f852..d254571ea4df 100644 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c | |||
@@ -30,8 +30,6 @@ | |||
30 | #define CTL_11A_EXT (CTL_11A | EXT_ADDITIVE) | 30 | #define CTL_11A_EXT (CTL_11A | EXT_ADDITIVE) |
31 | #define CTL_11G_EXT (CTL_11G | EXT_ADDITIVE) | 31 | #define CTL_11G_EXT (CTL_11G | EXT_ADDITIVE) |
32 | #define CTL_11B_EXT (CTL_11B | EXT_ADDITIVE) | 32 | #define CTL_11B_EXT (CTL_11B | EXT_ADDITIVE) |
33 | #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */ | ||
34 | #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */ | ||
35 | #define PWRINCR_3_TO_1_CHAIN 9 /* 10*log(3)*2 */ | 33 | #define PWRINCR_3_TO_1_CHAIN 9 /* 10*log(3)*2 */ |
36 | #define PWRINCR_3_TO_2_CHAIN 3 /* floor(10*log(3/2)*2) */ | 34 | #define PWRINCR_3_TO_2_CHAIN 3 /* floor(10*log(3/2)*2) */ |
37 | #define PWRINCR_2_TO_1_CHAIN 6 /* 10*log(2)*2 */ | 35 | #define PWRINCR_2_TO_1_CHAIN 6 /* 10*log(2)*2 */ |
@@ -4789,30 +4787,8 @@ static void ar9003_hw_set_power_per_rate_table(struct ath_hw *ah, | |||
4789 | bool is2ghz = IS_CHAN_2GHZ(chan); | 4787 | bool is2ghz = IS_CHAN_2GHZ(chan); |
4790 | 4788 | ||
4791 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); | 4789 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
4792 | scaledPower = powerLimit - antenna_reduction; | 4790 | scaledPower = ath9k_hw_get_scaled_power(ah, powerLimit, |
4793 | 4791 | antenna_reduction); | |
4794 | /* | ||
4795 | * Reduce scaled Power by number of chains active to get | ||
4796 | * to per chain tx power level | ||
4797 | */ | ||
4798 | switch (ar5416_get_ntxchains(ah->txchainmask)) { | ||
4799 | case 1: | ||
4800 | break; | ||
4801 | case 2: | ||
4802 | if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN) | ||
4803 | scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN; | ||
4804 | else | ||
4805 | scaledPower = 0; | ||
4806 | break; | ||
4807 | case 3: | ||
4808 | if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN) | ||
4809 | scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN; | ||
4810 | else | ||
4811 | scaledPower = 0; | ||
4812 | break; | ||
4813 | } | ||
4814 | |||
4815 | scaledPower = max((u16)0, scaledPower); | ||
4816 | 4792 | ||
4817 | /* | 4793 | /* |
4818 | * Get target powers from EEPROM - our baseline for TX Power | 4794 | * Get target powers from EEPROM - our baseline for TX Power |
diff --git a/drivers/net/wireless/ath/ath9k/eeprom.c b/drivers/net/wireless/ath/ath9k/eeprom.c index c43523233319..61bad99e76dd 100644 --- a/drivers/net/wireless/ath/ath9k/eeprom.c +++ b/drivers/net/wireless/ath/ath9k/eeprom.c | |||
@@ -290,6 +290,39 @@ u16 ath9k_hw_get_max_edge_power(u16 freq, struct cal_ctl_edges *pRdEdgesPower, | |||
290 | return twiceMaxEdgePower; | 290 | return twiceMaxEdgePower; |
291 | } | 291 | } |
292 | 292 | ||
293 | u16 ath9k_hw_get_scaled_power(struct ath_hw *ah, u16 power_limit, | ||
294 | u8 antenna_reduction) | ||
295 | { | ||
296 | u16 scaled_power; | ||
297 | |||
298 | scaled_power = power_limit - antenna_reduction; | ||
299 | |||
300 | /* | ||
301 | * Reduce scaled Power by number of chains active | ||
302 | * to get the per chain tx power level. | ||
303 | */ | ||
304 | switch (ar5416_get_ntxchains(ah->txchainmask)) { | ||
305 | case 1: | ||
306 | break; | ||
307 | case 2: | ||
308 | if (scaled_power > REDUCE_SCALED_POWER_BY_TWO_CHAIN) | ||
309 | scaled_power -= REDUCE_SCALED_POWER_BY_TWO_CHAIN; | ||
310 | else | ||
311 | scaled_power = 0; | ||
312 | break; | ||
313 | case 3: | ||
314 | if (scaled_power > REDUCE_SCALED_POWER_BY_THREE_CHAIN) | ||
315 | scaled_power -= REDUCE_SCALED_POWER_BY_THREE_CHAIN; | ||
316 | else | ||
317 | scaled_power = 0; | ||
318 | break; | ||
319 | } | ||
320 | |||
321 | scaled_power = max((u16)0, scaled_power); | ||
322 | |||
323 | return scaled_power; | ||
324 | } | ||
325 | |||
293 | void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah) | 326 | void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah) |
294 | { | 327 | { |
295 | struct ath_common *common = ath9k_hw_common(ah); | 328 | struct ath_common *common = ath9k_hw_common(ah); |
diff --git a/drivers/net/wireless/ath/ath9k/eeprom.h b/drivers/net/wireless/ath/ath9k/eeprom.h index 5ff7ab965120..8d779b44fe7c 100644 --- a/drivers/net/wireless/ath/ath9k/eeprom.h +++ b/drivers/net/wireless/ath/ath9k/eeprom.h | |||
@@ -82,6 +82,9 @@ | |||
82 | #define INCREASE_MAXPOW_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */ | 82 | #define INCREASE_MAXPOW_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */ |
83 | #define INCREASE_MAXPOW_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */ | 83 | #define INCREASE_MAXPOW_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */ |
84 | 84 | ||
85 | #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */ | ||
86 | #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */ | ||
87 | |||
85 | /* | 88 | /* |
86 | * For AR9285 and later chipsets, the following bits are not being programmed | 89 | * For AR9285 and later chipsets, the following bits are not being programmed |
87 | * in EEPROM and so need to be enabled always. | 90 | * in EEPROM and so need to be enabled always. |
@@ -686,6 +689,8 @@ void ath9k_hw_get_target_powers(struct ath_hw *ah, | |||
686 | u16 numRates, bool isHt40Target); | 689 | u16 numRates, bool isHt40Target); |
687 | u16 ath9k_hw_get_max_edge_power(u16 freq, struct cal_ctl_edges *pRdEdgesPower, | 690 | u16 ath9k_hw_get_max_edge_power(u16 freq, struct cal_ctl_edges *pRdEdgesPower, |
688 | bool is2GHz, int num_band_edges); | 691 | bool is2GHz, int num_band_edges); |
692 | u16 ath9k_hw_get_scaled_power(struct ath_hw *ah, u16 power_limit, | ||
693 | u8 antenna_reduction); | ||
689 | void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah); | 694 | void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah); |
690 | int ath9k_hw_eeprom_init(struct ath_hw *ah); | 695 | int ath9k_hw_eeprom_init(struct ath_hw *ah); |
691 | 696 | ||
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_9287.c b/drivers/net/wireless/ath/ath9k/eeprom_9287.c index 604eab858985..5ab0e6ed4655 100644 --- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c +++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c | |||
@@ -564,9 +564,6 @@ static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah, | |||
564 | (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \ | 564 | (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \ |
565 | ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL)) | 565 | ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL)) |
566 | 566 | ||
567 | #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */ | ||
568 | #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */ | ||
569 | |||
570 | u16 twiceMaxEdgePower; | 567 | u16 twiceMaxEdgePower; |
571 | int i; | 568 | int i; |
572 | struct cal_ctl_data_ar9287 *rep; | 569 | struct cal_ctl_data_ar9287 *rep; |
@@ -591,29 +588,8 @@ static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah, | |||
591 | tx_chainmask = ah->txchainmask; | 588 | tx_chainmask = ah->txchainmask; |
592 | 589 | ||
593 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); | 590 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
594 | scaledPower = powerLimit - antenna_reduction; | 591 | scaledPower = ath9k_hw_get_scaled_power(ah, powerLimit, |
595 | 592 | antenna_reduction); | |
596 | /* | ||
597 | * Reduce scaled Power by number of chains active | ||
598 | * to get the per chain tx power level. | ||
599 | */ | ||
600 | switch (ar5416_get_ntxchains(tx_chainmask)) { | ||
601 | case 1: | ||
602 | break; | ||
603 | case 2: | ||
604 | if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN) | ||
605 | scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN; | ||
606 | else | ||
607 | scaledPower = 0; | ||
608 | break; | ||
609 | case 3: | ||
610 | if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN) | ||
611 | scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN; | ||
612 | else | ||
613 | scaledPower = 0; | ||
614 | break; | ||
615 | } | ||
616 | scaledPower = max((u16)0, scaledPower); | ||
617 | 593 | ||
618 | /* | 594 | /* |
619 | * Get TX power from EEPROM. | 595 | * Get TX power from EEPROM. |
@@ -786,8 +762,6 @@ static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah, | |||
786 | 762 | ||
787 | #undef CMP_CTL | 763 | #undef CMP_CTL |
788 | #undef CMP_NO_CTL | 764 | #undef CMP_NO_CTL |
789 | #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN | ||
790 | #undef REDUCE_SCALED_POWER_BY_THREE_CHAIN | ||
791 | } | 765 | } |
792 | 766 | ||
793 | static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah, | 767 | static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah, |
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_def.c b/drivers/net/wireless/ath/ath9k/eeprom_def.c index 6a85796a342c..b5fba8b18b8b 100644 --- a/drivers/net/wireless/ath/ath9k/eeprom_def.c +++ b/drivers/net/wireless/ath/ath9k/eeprom_def.c | |||
@@ -991,9 +991,6 @@ static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah, | |||
991 | u16 antenna_reduction, | 991 | u16 antenna_reduction, |
992 | u16 powerLimit) | 992 | u16 powerLimit) |
993 | { | 993 | { |
994 | #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */ | ||
995 | #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */ | ||
996 | |||
997 | struct ar5416_eeprom_def *pEepData = &ah->eeprom.def; | 994 | struct ar5416_eeprom_def *pEepData = &ah->eeprom.def; |
998 | u16 twiceMaxEdgePower; | 995 | u16 twiceMaxEdgePower; |
999 | int i; | 996 | int i; |
@@ -1027,24 +1024,8 @@ static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah, | |||
1027 | 1024 | ||
1028 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); | 1025 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
1029 | 1026 | ||
1030 | scaledPower = powerLimit - antenna_reduction; | 1027 | scaledPower = ath9k_hw_get_scaled_power(ah, powerLimit, |
1031 | 1028 | antenna_reduction); | |
1032 | switch (ar5416_get_ntxchains(tx_chainmask)) { | ||
1033 | case 1: | ||
1034 | break; | ||
1035 | case 2: | ||
1036 | if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN) | ||
1037 | scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN; | ||
1038 | else | ||
1039 | scaledPower = 0; | ||
1040 | break; | ||
1041 | case 3: | ||
1042 | if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN) | ||
1043 | scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN; | ||
1044 | else | ||
1045 | scaledPower = 0; | ||
1046 | break; | ||
1047 | } | ||
1048 | 1029 | ||
1049 | if (IS_CHAN_2GHZ(chan)) { | 1030 | if (IS_CHAN_2GHZ(chan)) { |
1050 | numCtlModes = ARRAY_SIZE(ctlModesFor11g) - | 1031 | numCtlModes = ARRAY_SIZE(ctlModesFor11g) - |