- struct ath5k_rate_pcal_info rate_info;
- struct ieee80211_channel *curr_channel = ah->ah_current_channel;
-@@ -3600,11 +3598,6 @@ ath5k_hw_txpower(struct ath5k_hw *ah, st
- u8 type;
- int ret;
-
-- if (txpower > AR5K_TUNE_MAX_TXPOWER) {
-- ATH5K_ERR(ah, "invalid tx power: %u\n", txpower);
-- return -EINVAL;
-- }
--
- ee_mode = ath5k_eeprom_mode_from_channel(channel);
- if (ee_mode < 0) {
- ATH5K_ERR(ah,
-@@ -3669,7 +3662,7 @@ ath5k_hw_txpower(struct ath5k_hw *ah, st
- ath5k_get_rate_pcal_data(ah, channel, &rate_info);
-
- /* Setup rate power table */
-- ath5k_setup_rate_powertable(ah, txpower, &rate_info, ee_mode);
-+ ath5k_setup_rate_powertable(ah, ah->ah_txpower.txp_user_pwr, &rate_info, ee_mode);
-
- /* Write rate power table on hw */
- ath5k_hw_reg_write(ah, AR5K_TXPOWER_OFDM(3, 24) |
-@@ -3719,8 +3712,16 @@ ath5k_hw_set_txpower_limit(struct ath5k_
- {
- ATH5K_DBG(ah, ATH5K_DEBUG_TXPOWER,
- "changing txpower to %d\n", txpower);
-+ if (txpower) {
-+ ah->ah_txpower.txp_user_pwr = txpower;
-
-- return ath5k_hw_txpower(ah, ah->ah_current_channel, txpower);
-+ if (ah->ah_txpower.txp_user_pwr > AR5K_TUNE_MAX_TXPOWER) {
-+ ATH5K_ERR(ah, "invalid tx power: %u\n", ah->ah_txpower.txp_user_pwr);
-+ return -EINVAL;
-+ }
-+ }
+ unsigned int i;
+ u16 *rates;
++ s16 rate_idx_scaled = 0;
+
+ /* max_pwr is power level we got from driver/user in 0.5dB
+ * units, switch to 0.25dB units so we can compare */
+@@ -3564,20 +3565,32 @@ ath5k_setup_rate_powertable(struct ath5k
+ for (i = 8; i <= 15; i++)
+ rates[i] -= ah->ah_txpower.txp_cck_ofdm_gainf_delta;
+
++ /* Save min/max and current tx power for this channel
++ * in 0.25dB units.
++ *
++ * Note: We use rates[0] for current tx power because
++ * it covers most of the rates, in most cases. It's our
++ * tx power limit and what the user expects to see. */
++ ah->ah_txpower.txp_min_pwr = 2 * rates[7];
++ ah->ah_txpower.txp_cur_pwr = 2 * rates[0];
++
++ /* Set max txpower for correct OFDM operation on all rates
++ * -that is the txpower for 54Mbit-, it's used for the PAPD
++ * gain probe and it's in 0.5dB units */
++ ah->ah_txpower.txp_ofdm = rates[7];