029ce3d7af76da97a1e9da93beb79c30add859f4
[openwrt-10.03/.git] / package / mac80211 / patches / 581-ath9k_cleanup_txpower_handling.patch
1 --- a/drivers/net/wireless/ath/ath.h
2 +++ b/drivers/net/wireless/ath/ath.h
3 @@ -71,7 +71,6 @@ struct ath_regulatory {
4         char alpha2[2];
5         u16 country_code;
6         u16 max_power_level;
7 -       u32 tp_scale;
8         u16 current_rd;
9         u16 current_rd_ext;
10         int16_t power_limit;
11 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
12 +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
13 @@ -3040,6 +3040,10 @@ static u32 ath9k_hw_ar9300_get_eeprom(st
14                 return (pBase->miscConfiguration >> 0x3) & 0x1;
15         case EEP_ANT_DIV_CTL1:
16                 return eep->base_ext1.ant_div_control;
17 +       case EEP_ANTENNA_GAIN_5G:
18 +               return eep->modalHeader5G.antennaGain;
19 +       case EEP_ANTENNA_GAIN_2G:
20 +               return eep->modalHeader2G.antennaGain;
21         default:
22                 return 0;
23         }
24 @@ -4727,20 +4731,14 @@ static u16 ar9003_hw_get_max_edge_power(
25  static void ar9003_hw_set_power_per_rate_table(struct ath_hw *ah,
26                                                struct ath9k_channel *chan,
27                                                u8 *pPwrArray, u16 cfgCtl,
28 -                                              u8 twiceAntennaReduction,
29 -                                              u8 twiceMaxRegulatoryPower,
30 +                                              u8 antenna_reduction,
31                                                u16 powerLimit)
32  {
33 -       struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
34         struct ath_common *common = ath9k_hw_common(ah);
35         struct ar9300_eeprom *pEepData = &ah->eeprom.ar9300_eep;
36         u16 twiceMaxEdgePower = MAX_RATE_POWER;
37 -       static const u16 tpScaleReductionTable[5] = {
38 -               0, 3, 6, 9, MAX_RATE_POWER
39 -       };
40         int i;
41 -       int16_t  twiceLargestAntenna;
42 -       u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
43 +       u16 scaledPower = 0, minCtlPower;
44         static const u16 ctlModesFor11a[] = {
45                 CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40
46         };
47 @@ -4758,28 +4756,7 @@ static void ar9003_hw_set_power_per_rate
48         bool is2ghz = IS_CHAN_2GHZ(chan);
49  
50         ath9k_hw_get_channel_centers(ah, chan, &centers);
51 -
52 -       /* Compute TxPower reduction due to Antenna Gain */
53 -       if (is2ghz)
54 -               twiceLargestAntenna = pEepData->modalHeader2G.antennaGain;
55 -       else
56 -               twiceLargestAntenna = pEepData->modalHeader5G.antennaGain;
57 -
58 -       twiceLargestAntenna = (int16_t)min((twiceAntennaReduction) -
59 -                               twiceLargestAntenna, 0);
60 -
61 -       /*
62 -        * scaledPower is the minimum of the user input power level
63 -        * and the regulatory allowed power level
64 -        */
65 -       maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
66 -
67 -       if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) {
68 -               maxRegAllowedPower -=
69 -                       (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
70 -       }
71 -
72 -       scaledPower = min(powerLimit, maxRegAllowedPower);
73 +       scaledPower = powerLimit - antenna_reduction;
74  
75         /*
76          * Reduce scaled Power by number of chains active to get
77 @@ -4966,7 +4943,6 @@ static inline u8 mcsidx_to_tgtpwridx(uns
78  static void ath9k_hw_ar9300_set_txpower(struct ath_hw *ah,
79                                         struct ath9k_channel *chan, u16 cfgCtl,
80                                         u8 twiceAntennaReduction,
81 -                                       u8 twiceMaxRegulatoryPower,
82                                         u8 powerLimit, bool test)
83  {
84         struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
85 @@ -5019,7 +4995,6 @@ static void ath9k_hw_ar9300_set_txpower(
86         ar9003_hw_set_power_per_rate_table(ah, chan,
87                                            targetPowerValT2, cfgCtl,
88                                            twiceAntennaReduction,
89 -                                          twiceMaxRegulatoryPower,
90                                            powerLimit);
91  
92         if (ah->eep_ops->get_eeprom(ah, EEP_PAPRD)) {
93 --- a/drivers/net/wireless/ath/ath9k/hw.c
94 +++ b/drivers/net/wireless/ath/ath9k/hw.c
95 @@ -429,7 +429,6 @@ static void ath9k_hw_init_defaults(struc
96  
97         regulatory->country_code = CTRY_DEFAULT;
98         regulatory->power_limit = MAX_RATE_POWER;
99 -       regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
100  
101         ah->hw_version.magic = AR5416_MAGIC;
102         ah->hw_version.subvendorid = 0;
103 @@ -1396,9 +1395,7 @@ static bool ath9k_hw_chip_reset(struct a
104  static bool ath9k_hw_channel_change(struct ath_hw *ah,
105                                     struct ath9k_channel *chan)
106  {
107 -       struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
108         struct ath_common *common = ath9k_hw_common(ah);
109 -       struct ieee80211_channel *channel = chan->chan;
110         u32 qnum;
111         int r;
112  
113 @@ -1423,14 +1420,7 @@ static bool ath9k_hw_channel_change(stru
114                 return false;
115         }
116         ath9k_hw_set_clockrate(ah);
117 -
118 -       ah->eep_ops->set_txpower(ah, chan,
119 -                            ath9k_regd_get_ctl(regulatory, chan),
120 -                            channel->max_antenna_gain * 2,
121 -                            channel->max_power * 2,
122 -                            min((u32) MAX_RATE_POWER,
123 -                            (u32) regulatory->power_limit), false);
124 -
125 +       ath9k_hw_apply_txpower(ah, chan);
126         ath9k_hw_rfbus_done(ah);
127  
128         if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
129 @@ -2466,23 +2456,56 @@ bool ath9k_hw_disable(struct ath_hw *ah)
130  }
131  EXPORT_SYMBOL(ath9k_hw_disable);
132  
133 +static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
134 +{
135 +       enum eeprom_param gain_param;
136 +
137 +       if (IS_CHAN_2GHZ(chan))
138 +               gain_param = EEP_ANTENNA_GAIN_2G;
139 +       else
140 +               gain_param = EEP_ANTENNA_GAIN_5G;
141 +
142 +       return ah->eep_ops->get_eeprom(ah, gain_param);
143 +}
144 +
145 +void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan)
146 +{
147 +       struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
148 +       struct ieee80211_channel *channel;
149 +       int chan_pwr, new_pwr, max_gain;
150 +       int ant_gain, ant_reduction = 0;
151 +
152 +       if (!chan)
153 +               return;
154 +
155 +       channel = chan->chan;
156 +       chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
157 +       new_pwr = min_t(int, chan_pwr, reg->power_limit);
158 +       max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
159 +
160 +       ant_gain = get_antenna_gain(ah, chan);
161 +       if (ant_gain > max_gain)
162 +               ant_reduction = ant_gain - max_gain;
163 +
164 +       ah->eep_ops->set_txpower(ah, chan,
165 +                                ath9k_regd_get_ctl(reg, chan),
166 +                                ant_reduction, new_pwr, false);
167 +}
168 +
169  void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
170  {
171 -       struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
172 +       struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
173         struct ath9k_channel *chan = ah->curchan;
174         struct ieee80211_channel *channel = chan->chan;
175 -       int reg_pwr = min_t(int, MAX_RATE_POWER, limit);
176 -       int chan_pwr = channel->max_power * 2;
177  
178 +       reg->power_limit = min_t(int, limit, MAX_RATE_POWER);
179         if (test)
180 -               reg_pwr = chan_pwr = MAX_RATE_POWER;
181 +               channel->max_power = MAX_RATE_POWER / 2;
182  
183 -       regulatory->power_limit = reg_pwr;
184 +       ath9k_hw_apply_txpower(ah, chan);
185  
186 -       ah->eep_ops->set_txpower(ah, chan,
187 -                                ath9k_regd_get_ctl(regulatory, chan),
188 -                                channel->max_antenna_gain * 2,
189 -                                chan_pwr, reg_pwr, test);
190 +       if (test)
191 +               channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
192  }
193  EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
194  
195 --- a/drivers/net/wireless/ath/ath9k/hw.h
196 +++ b/drivers/net/wireless/ath/ath9k/hw.h
197 @@ -389,14 +389,6 @@ enum ath9k_power_mode {
198         ATH9K_PM_UNDEFINED
199  };
200  
201 -enum ath9k_tp_scale {
202 -       ATH9K_TP_SCALE_MAX = 0,
203 -       ATH9K_TP_SCALE_50,
204 -       ATH9K_TP_SCALE_25,
205 -       ATH9K_TP_SCALE_12,
206 -       ATH9K_TP_SCALE_MIN
207 -};
208 -
209  enum ser_reg_mode {
210         SER_REG_MODE_OFF = 0,
211         SER_REG_MODE_ON = 1,
212 @@ -964,6 +956,7 @@ void ath9k_hw_htc_resetinit(struct ath_h
213  /* PHY */
214  void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
215                                    u32 *coef_mantissa, u32 *coef_exponent);
216 +void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan);
217  
218  /*
219   * Code Specific to AR5008, AR9001 or AR9002,
220 --- a/drivers/net/wireless/ath/ath9k/eeprom_4k.c
221 +++ b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
222 @@ -350,6 +350,8 @@ static u32 ath9k_hw_4k_get_eeprom(struct
223                 return pModal->antdiv_ctl1;
224         case EEP_TXGAIN_TYPE:
225                 return pBase->txGainType;
226 +       case EEP_ANTENNA_GAIN_2G:
227 +               return pModal->antennaGainCh[0];
228         default:
229                 return 0;
230         }
231 @@ -462,8 +464,7 @@ static void ath9k_hw_set_4k_power_per_ra
232                                                  struct ath9k_channel *chan,
233                                                  int16_t *ratesArray,
234                                                  u16 cfgCtl,
235 -                                                u16 AntennaReduction,
236 -                                                u16 twiceMaxRegulatoryPower,
237 +                                                u16 antenna_reduction,
238                                                  u16 powerLimit)
239  {
240  #define CMP_TEST_GRP \
241 @@ -472,20 +473,16 @@ static void ath9k_hw_set_4k_power_per_ra
242         || (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
243             ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
244  
245 -       struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
246         int i;
247 -       int16_t twiceLargestAntenna;
248         u16 twiceMinEdgePower;
249         u16 twiceMaxEdgePower = MAX_RATE_POWER;
250 -       u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
251 +       u16 scaledPower = 0, minCtlPower;
252         u16 numCtlModes;
253         const u16 *pCtlMode;
254         u16 ctlMode, freq;
255         struct chan_centers centers;
256         struct cal_ctl_data_4k *rep;
257         struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
258 -       static const u16 tpScaleReductionTable[5] =
259 -               { 0, 3, 6, 9, MAX_RATE_POWER };
260         struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
261                 0, { 0, 0, 0, 0}
262         };
263 @@ -503,19 +500,7 @@ static void ath9k_hw_set_4k_power_per_ra
264  
265         ath9k_hw_get_channel_centers(ah, chan, &centers);
266  
267 -       twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0];
268 -       twiceLargestAntenna = (int16_t)min(AntennaReduction -
269 -                                          twiceLargestAntenna, 0);
270 -
271 -       maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
272 -       if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) {
273 -               maxRegAllowedPower -=
274 -                       (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
275 -       }
276 -
277 -       scaledPower = min(powerLimit, maxRegAllowedPower);
278 -       scaledPower = max((u16)0, scaledPower);
279 -
280 +       scaledPower = powerLimit - antenna_reduction;
281         numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
282         pCtlMode = ctlModesFor11g;
283  
284 @@ -671,7 +656,6 @@ static void ath9k_hw_4k_set_txpower(stru
285                                     struct ath9k_channel *chan,
286                                     u16 cfgCtl,
287                                     u8 twiceAntennaReduction,
288 -                                   u8 twiceMaxRegulatoryPower,
289                                     u8 powerLimit, bool test)
290  {
291         struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
292 @@ -691,7 +675,6 @@ static void ath9k_hw_4k_set_txpower(stru
293         ath9k_hw_set_4k_power_per_rate_table(ah, chan,
294                                              &ratesArray[0], cfgCtl,
295                                              twiceAntennaReduction,
296 -                                            twiceMaxRegulatoryPower,
297                                              powerLimit);
298  
299         ath9k_hw_set_4k_power_cal_table(ah, chan);
300 --- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
301 +++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
302 @@ -336,6 +336,9 @@ static u32 ath9k_hw_ar9287_get_eeprom(st
303                         return pBase->tempSensSlopePalOn;
304                 else
305                         return 0;
306 +       case EEP_ANTENNA_GAIN_2G:
307 +               return max_t(u8, pModal->antennaGainCh[0],
308 +                                pModal->antennaGainCh[1]);
309         default:
310                 return 0;
311         }
312 @@ -554,8 +557,7 @@ static void ath9k_hw_set_ar9287_power_pe
313                                                      struct ath9k_channel *chan,
314                                                      int16_t *ratesArray,
315                                                      u16 cfgCtl,
316 -                                                    u16 AntennaReduction,
317 -                                                    u16 twiceMaxRegulatoryPower,
318 +                                                    u16 antenna_reduction,
319                                                      u16 powerLimit)
320  {
321  #define CMP_CTL \
322 @@ -569,12 +571,8 @@ static void ath9k_hw_set_ar9287_power_pe
323  #define REDUCE_SCALED_POWER_BY_TWO_CHAIN     6
324  #define REDUCE_SCALED_POWER_BY_THREE_CHAIN   10
325  
326 -       struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
327         u16 twiceMaxEdgePower = MAX_RATE_POWER;
328 -       static const u16 tpScaleReductionTable[5] =
329 -               { 0, 3, 6, 9, MAX_RATE_POWER };
330         int i;
331 -       int16_t twiceLargestAntenna;
332         struct cal_ctl_data_ar9287 *rep;
333         struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
334                                     targetPowerCck = {0, {0, 0, 0, 0} };
335 @@ -582,7 +580,7 @@ static void ath9k_hw_set_ar9287_power_pe
336                                     targetPowerCckExt = {0, {0, 0, 0, 0} };
337         struct cal_target_power_ht targetPowerHt20,
338                                     targetPowerHt40 = {0, {0, 0, 0, 0} };
339 -       u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
340 +       u16 scaledPower = 0, minCtlPower;
341         static const u16 ctlModesFor11g[] = {
342                 CTL_11B, CTL_11G, CTL_2GHT20,
343                 CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
344 @@ -597,24 +595,7 @@ static void ath9k_hw_set_ar9287_power_pe
345         tx_chainmask = ah->txchainmask;
346  
347         ath9k_hw_get_channel_centers(ah, chan, &centers);
348 -
349 -       /* Compute TxPower reduction due to Antenna Gain */
350 -       twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
351 -                                 pEepData->modalHeader.antennaGainCh[1]);
352 -       twiceLargestAntenna = (int16_t)min((AntennaReduction) -
353 -                                          twiceLargestAntenna, 0);
354 -
355 -       /*
356 -        * scaledPower is the minimum of the user input power level
357 -        * and the regulatory allowed power level.
358 -        */
359 -       maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
360 -
361 -       if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
362 -               maxRegAllowedPower -=
363 -                       (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
364 -
365 -       scaledPower = min(powerLimit, maxRegAllowedPower);
366 +       scaledPower = powerLimit - antenna_reduction;
367  
368         /*
369          * Reduce scaled Power by number of chains active
370 @@ -815,7 +796,6 @@ static void ath9k_hw_set_ar9287_power_pe
371  static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
372                                         struct ath9k_channel *chan, u16 cfgCtl,
373                                         u8 twiceAntennaReduction,
374 -                                       u8 twiceMaxRegulatoryPower,
375                                         u8 powerLimit, bool test)
376  {
377         struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
378 @@ -834,7 +814,6 @@ static void ath9k_hw_ar9287_set_txpower(
379         ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
380                                                  &ratesArray[0], cfgCtl,
381                                                  twiceAntennaReduction,
382 -                                                twiceMaxRegulatoryPower,
383                                                  powerLimit);
384  
385         ath9k_hw_set_ar9287_power_cal_table(ah, chan);
386 --- a/drivers/net/wireless/ath/ath9k/eeprom_def.c
387 +++ b/drivers/net/wireless/ath/ath9k/eeprom_def.c
388 @@ -400,6 +400,7 @@ static u32 ath9k_hw_def_get_eeprom(struc
389         struct ar5416_eeprom_def *eep = &ah->eeprom.def;
390         struct modal_eep_header *pModal = eep->modalHeader;
391         struct base_eep_header *pBase = &eep->baseEepHeader;
392 +       int band = 0;
393  
394         switch (param) {
395         case EEP_NFTHRESH_5:
396 @@ -467,6 +468,14 @@ static u32 ath9k_hw_def_get_eeprom(struc
397                         return pBase->pwr_table_offset;
398                 else
399                         return AR5416_PWR_TABLE_OFFSET_DB;
400 +       case EEP_ANTENNA_GAIN_2G:
401 +               band = 1;
402 +               /* fall through */
403 +       case EEP_ANTENNA_GAIN_5G:
404 +               return max_t(u8, max_t(u8,
405 +                       pModal[band].antennaGainCh[0],
406 +                       pModal[band].antennaGainCh[1]),
407 +                       pModal[band].antennaGainCh[2]);
408         default:
409                 return 0;
410         }
411 @@ -986,21 +995,15 @@ static void ath9k_hw_set_def_power_per_r
412                                                   struct ath9k_channel *chan,
413                                                   int16_t *ratesArray,
414                                                   u16 cfgCtl,
415 -                                                 u16 AntennaReduction,
416 -                                                 u16 twiceMaxRegulatoryPower,
417 +                                                 u16 antenna_reduction,
418                                                   u16 powerLimit)
419  {
420  #define REDUCE_SCALED_POWER_BY_TWO_CHAIN     6  /* 10*log10(2)*2 */
421  #define REDUCE_SCALED_POWER_BY_THREE_CHAIN   9 /* 10*log10(3)*2 */
422  
423 -       struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
424         struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
425         u16 twiceMaxEdgePower = MAX_RATE_POWER;
426 -       static const u16 tpScaleReductionTable[5] =
427 -               { 0, 3, 6, 9, MAX_RATE_POWER };
428 -
429         int i;
430 -       int16_t twiceLargestAntenna;
431         struct cal_ctl_data *rep;
432         struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
433                 0, { 0, 0, 0, 0}
434 @@ -1012,7 +1015,7 @@ static void ath9k_hw_set_def_power_per_r
435         struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
436                 0, {0, 0, 0, 0}
437         };
438 -       u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
439 +       u16 scaledPower = 0, minCtlPower;
440         static const u16 ctlModesFor11a[] = {
441                 CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40
442         };
443 @@ -1031,27 +1034,7 @@ static void ath9k_hw_set_def_power_per_r
444  
445         ath9k_hw_get_channel_centers(ah, chan, &centers);
446  
447 -       twiceLargestAntenna = max(
448 -               pEepData->modalHeader
449 -                       [IS_CHAN_2GHZ(chan)].antennaGainCh[0],
450 -               pEepData->modalHeader
451 -                       [IS_CHAN_2GHZ(chan)].antennaGainCh[1]);
452 -
453 -       twiceLargestAntenna = max((u8)twiceLargestAntenna,
454 -                                 pEepData->modalHeader
455 -                                 [IS_CHAN_2GHZ(chan)].antennaGainCh[2]);
456 -
457 -       twiceLargestAntenna = (int16_t)min(AntennaReduction -
458 -                                          twiceLargestAntenna, 0);
459 -
460 -       maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
461 -
462 -       if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) {
463 -               maxRegAllowedPower -=
464 -                       (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
465 -       }
466 -
467 -       scaledPower = min(powerLimit, maxRegAllowedPower);
468 +       scaledPower = powerLimit - antenna_reduction;
469  
470         switch (ar5416_get_ntxchains(tx_chainmask)) {
471         case 1:
472 @@ -1256,7 +1239,6 @@ static void ath9k_hw_def_set_txpower(str
473                                     struct ath9k_channel *chan,
474                                     u16 cfgCtl,
475                                     u8 twiceAntennaReduction,
476 -                                   u8 twiceMaxRegulatoryPower,
477                                     u8 powerLimit, bool test)
478  {
479  #define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
480 @@ -1278,7 +1260,6 @@ static void ath9k_hw_def_set_txpower(str
481         ath9k_hw_set_def_power_per_rate_table(ah, chan,
482                                                &ratesArray[0], cfgCtl,
483                                                twiceAntennaReduction,
484 -                                              twiceMaxRegulatoryPower,
485                                                powerLimit);
486  
487         ath9k_hw_set_def_power_cal_table(ah, chan);
488 --- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
489 +++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
490 @@ -763,10 +763,8 @@ static void ar5008_hw_set_channel_regs(s
491  static int ar5008_hw_process_ini(struct ath_hw *ah,
492                                  struct ath9k_channel *chan)
493  {
494 -       struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
495         struct ath_common *common = ath9k_hw_common(ah);
496         int i, regWrites = 0;
497 -       struct ieee80211_channel *channel = chan->chan;
498         u32 modesIndex, freqIndex;
499  
500         switch (chan->chanmode) {
501 @@ -903,14 +901,7 @@ static int ar5008_hw_process_ini(struct 
502         ar5008_hw_set_channel_regs(ah, chan);
503         ar5008_hw_init_chain_masks(ah);
504         ath9k_olc_init(ah);
505 -
506 -       /* Set TX power */
507 -       ah->eep_ops->set_txpower(ah, chan,
508 -                                ath9k_regd_get_ctl(regulatory, chan),
509 -                                channel->max_antenna_gain * 2,
510 -                                channel->max_power * 2,
511 -                                min((u32) MAX_RATE_POWER,
512 -                                (u32) regulatory->power_limit), false);
513 +       ath9k_hw_apply_txpower(ah, chan);
514  
515         /* Write analog registers */
516         if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
517 --- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
518 +++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
519 @@ -19,7 +19,6 @@
520  
521  void ar9003_paprd_enable(struct ath_hw *ah, bool val)
522  {
523 -       struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
524         struct ath9k_channel *chan = ah->curchan;
525         struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
526  
527 @@ -54,13 +53,7 @@ void ar9003_paprd_enable(struct ath_hw *
528  
529         if (val) {
530                 ah->paprd_table_write_done = true;
531 -
532 -               ah->eep_ops->set_txpower(ah, chan,
533 -                               ath9k_regd_get_ctl(regulatory, chan),
534 -                               chan->chan->max_antenna_gain * 2,
535 -                               chan->chan->max_power * 2,
536 -                               min((u32) MAX_RATE_POWER,
537 -                               (u32) regulatory->power_limit), false);
538 +               ath9k_hw_apply_txpower(ah, chan);
539         }
540  
541         REG_RMW_FIELD(ah, AR_PHY_PAPRD_CTRL0_B0,
542 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
543 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
544 @@ -628,9 +628,7 @@ static void ar9003_hw_prog_ini(struct at
545  static int ar9003_hw_process_ini(struct ath_hw *ah,
546                                  struct ath9k_channel *chan)
547  {
548 -       struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
549         unsigned int regWrites = 0, i;
550 -       struct ieee80211_channel *channel = chan->chan;
551         u32 modesIndex;
552  
553         switch (chan->chanmode) {
554 @@ -683,14 +681,7 @@ static int ar9003_hw_process_ini(struct 
555         ar9003_hw_override_ini(ah);
556         ar9003_hw_set_channel_regs(ah, chan);
557         ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
558 -
559 -       /* Set TX power */
560 -       ah->eep_ops->set_txpower(ah, chan,
561 -                                ath9k_regd_get_ctl(regulatory, chan),
562 -                                channel->max_antenna_gain * 2,
563 -                                channel->max_power * 2,
564 -                                min((u32) MAX_RATE_POWER,
565 -                                (u32) regulatory->power_limit), false);
566 +       ath9k_hw_apply_txpower(ah, chan);
567  
568         return 0;
569  }
570 --- a/drivers/net/wireless/ath/ath9k/common.c
571 +++ b/drivers/net/wireless/ath/ath9k/common.c
572 @@ -161,10 +161,12 @@ EXPORT_SYMBOL(ath9k_cmn_count_streams);
573  void ath9k_cmn_update_txpow(struct ath_hw *ah, u16 cur_txpow,
574                             u16 new_txpow, u16 *txpower)
575  {
576 -       if (cur_txpow != new_txpow) {
577 +       struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
578 +
579 +       if (reg->power_limit != new_txpow) {
580                 ath9k_hw_set_txpowerlimit(ah, new_txpow, false);
581                 /* read back in case value is clamped */
582 -               *txpower = ath9k_hw_regulatory(ah)->power_limit;
583 +               *txpower = reg->max_power_level;
584         }
585  }
586  EXPORT_SYMBOL(ath9k_cmn_update_txpow);
587 --- a/drivers/net/wireless/ath/ath9k/eeprom.h
588 +++ b/drivers/net/wireless/ath/ath9k/eeprom.h
589 @@ -253,7 +253,9 @@ enum eeprom_param {
590         EEP_PAPRD,
591         EEP_MODAL_VER,
592         EEP_ANT_DIV_CTL1,
593 -       EEP_CHAIN_MASK_REDUCE
594 +       EEP_CHAIN_MASK_REDUCE,
595 +       EEP_ANTENNA_GAIN_2G,
596 +       EEP_ANTENNA_GAIN_5G