ath9k: fix tx power display
[openwrt/svn-archive/archive.git] / package / mac80211 / patches / 521-ath9k_hw_tx_power.patch
1 --- a/drivers/net/wireless/ath/ath9k/eeprom.h
2 +++ b/drivers/net/wireless/ath/ath9k/eeprom.h
3 @@ -680,7 +680,8 @@ struct eeprom_ops {
4 void (*set_addac)(struct ath_hw *hw, struct ath9k_channel *chan);
5 void (*set_txpower)(struct ath_hw *hw, struct ath9k_channel *chan,
6 u16 cfgCtl, u8 twiceAntennaReduction,
7 - u8 twiceMaxRegulatoryPower, u8 powerLimit);
8 + u8 twiceMaxRegulatoryPower, u8 powerLimit,
9 + bool test);
10 u16 (*get_spur_channel)(struct ath_hw *ah, u16 i, bool is2GHz);
11 };
12
13 --- a/drivers/net/wireless/ath/ath9k/eeprom_4k.c
14 +++ b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
15 @@ -726,7 +726,7 @@ static void ath9k_hw_4k_set_txpower(stru
16 u16 cfgCtl,
17 u8 twiceAntennaReduction,
18 u8 twiceMaxRegulatoryPower,
19 - u8 powerLimit)
20 + u8 powerLimit, bool test)
21 {
22 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
23 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
24 @@ -768,6 +768,9 @@ static void ath9k_hw_4k_set_txpower(stru
25
26 regulatory->max_power_level = ratesArray[i];
27
28 + if (test)
29 + return;
30 +
31 if (AR_SREV_9280_20_OR_LATER(ah)) {
32 for (i = 0; i < Ar5416RateSize; i++)
33 ratesArray[i] -= AR5416_PWR_TABLE_OFFSET_DB * 2;
34 --- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
35 +++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
36 @@ -853,7 +853,7 @@ static void ath9k_hw_ar9287_set_txpower(
37 struct ath9k_channel *chan, u16 cfgCtl,
38 u8 twiceAntennaReduction,
39 u8 twiceMaxRegulatoryPower,
40 - u8 powerLimit)
41 + u8 powerLimit, bool test)
42 {
43 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
44 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
45 @@ -883,6 +883,16 @@ static void ath9k_hw_ar9287_set_txpower(
46 ratesArray[i] = AR9287_MAX_RATE_POWER;
47 }
48
49 + if (IS_CHAN_2GHZ(chan))
50 + i = rate1l;
51 + else
52 + i = rate6mb;
53 +
54 + regulatory->max_power_level = ratesArray[i];
55 +
56 + if (test)
57 + return;
58 +
59 if (AR_SREV_9280_20_OR_LATER(ah)) {
60 for (i = 0; i < Ar5416RateSize; i++)
61 ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
62 @@ -971,17 +981,6 @@ static void ath9k_hw_ar9287_set_txpower(
63 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
64 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
65 }
66 -
67 - if (IS_CHAN_2GHZ(chan))
68 - i = rate1l;
69 - else
70 - i = rate6mb;
71 -
72 - if (AR_SREV_9280_20_OR_LATER(ah))
73 - regulatory->max_power_level =
74 - ratesArray[i] + AR9287_PWR_TABLE_OFFSET_DB * 2;
75 - else
76 - regulatory->max_power_level = ratesArray[i];
77 }
78
79 static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah,
80 --- a/drivers/net/wireless/ath/ath9k/eeprom_def.c
81 +++ b/drivers/net/wireless/ath/ath9k/eeprom_def.c
82 @@ -1258,7 +1258,7 @@ static void ath9k_hw_def_set_txpower(str
83 u16 cfgCtl,
84 u8 twiceAntennaReduction,
85 u8 twiceMaxRegulatoryPower,
86 - u8 powerLimit)
87 + u8 powerLimit, bool test)
88 {
89 #define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
90 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
91 @@ -1291,6 +1291,33 @@ static void ath9k_hw_def_set_txpower(str
92 ratesArray[i] = AR5416_MAX_RATE_POWER;
93 }
94
95 + i = rate6mb;
96 +
97 + if (IS_CHAN_HT40(chan))
98 + i = rateHt40_0;
99 + else if (IS_CHAN_HT20(chan))
100 + i = rateHt20_0;
101 +
102 + regulatory->max_power_level = ratesArray[i];
103 +
104 + switch(ar5416_get_ntxchains(ah->txchainmask)) {
105 + case 1:
106 + break;
107 + case 2:
108 + regulatory->max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
109 + break;
110 + case 3:
111 + regulatory->max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
112 + break;
113 + default:
114 + ath_print(ath9k_hw_common(ah), ATH_DBG_EEPROM,
115 + "Invalid chainmask configuration\n");
116 + break;
117 + }
118 +
119 + if (test)
120 + return;
121 +
122 if (AR_SREV_9280_20_OR_LATER(ah)) {
123 for (i = 0; i < Ar5416RateSize; i++) {
124 int8_t pwr_table_offset;
125 @@ -1387,34 +1414,6 @@ static void ath9k_hw_def_set_txpower(str
126 REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
127 ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
128 | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
129 -
130 - i = rate6mb;
131 -
132 - if (IS_CHAN_HT40(chan))
133 - i = rateHt40_0;
134 - else if (IS_CHAN_HT20(chan))
135 - i = rateHt20_0;
136 -
137 - if (AR_SREV_9280_20_OR_LATER(ah))
138 - regulatory->max_power_level =
139 - ratesArray[i] + AR5416_PWR_TABLE_OFFSET_DB * 2;
140 - else
141 - regulatory->max_power_level = ratesArray[i];
142 -
143 - switch(ar5416_get_ntxchains(ah->txchainmask)) {
144 - case 1:
145 - break;
146 - case 2:
147 - regulatory->max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
148 - break;
149 - case 3:
150 - regulatory->max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
151 - break;
152 - default:
153 - ath_print(ath9k_hw_common(ah), ATH_DBG_EEPROM,
154 - "Invalid chainmask configuration\n");
155 - break;
156 - }
157 }
158
159 static u8 ath9k_hw_def_get_num_ant_config(struct ath_hw *ah,
160 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
161 +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
162 @@ -2131,7 +2131,7 @@ static void ath9k_hw_ar9300_set_txpower(
163 struct ath9k_channel *chan, u16 cfgCtl,
164 u8 twiceAntennaReduction,
165 u8 twiceMaxRegulatoryPower,
166 - u8 powerLimit)
167 + u8 powerLimit, bool test)
168 {
169 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
170 struct ath_common *common = ath9k_hw_common(ah);
171 @@ -2160,9 +2160,6 @@ static void ath9k_hw_ar9300_set_txpower(
172 i++;
173 }
174
175 - /* Write target power array to registers */
176 - ar9003_hw_tx_power_regwrite(ah, targetPowerValT2);
177 -
178 /*
179 * This is the TX power we send back to driver core,
180 * and it can use to pass to userspace to display our
181 @@ -2181,8 +2178,13 @@ static void ath9k_hw_ar9300_set_txpower(
182 i = ALL_TARGET_HT20_0_8_16; /* ht20 */
183
184 ah->txpower_limit = targetPowerValT2[i];
185 - regulatory->max_power_level = ratesArray[i];
186 + regulatory->max_power_level = targetPowerValT2[i];
187
188 + if (test)
189 + return;
190 +
191 + /* Write target power array to registers */
192 + ar9003_hw_tx_power_regwrite(ah, targetPowerValT2);
193 ar9003_hw_calibration_apply(ah, chan->channel);
194 }
195
196 --- a/drivers/net/wireless/ath/ath9k/hw.c
197 +++ b/drivers/net/wireless/ath/ath9k/hw.c
198 @@ -1178,7 +1178,7 @@ static bool ath9k_hw_channel_change(stru
199 channel->max_antenna_gain * 2,
200 channel->max_power * 2,
201 min((u32) MAX_RATE_POWER,
202 - (u32) regulatory->power_limit));
203 + (u32) regulatory->power_limit), false);
204
205 ath9k_hw_rfbus_done(ah);
206
207 @@ -2177,7 +2177,7 @@ bool ath9k_hw_disable(struct ath_hw *ah)
208 }
209 EXPORT_SYMBOL(ath9k_hw_disable);
210
211 -void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
212 +void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
213 {
214 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
215 struct ath9k_channel *chan = ah->curchan;
216 @@ -2190,7 +2190,7 @@ void ath9k_hw_set_txpowerlimit(struct at
217 channel->max_antenna_gain * 2,
218 channel->max_power * 2,
219 min((u32) MAX_RATE_POWER,
220 - (u32) regulatory->power_limit));
221 + (u32) regulatory->power_limit), test);
222 }
223 EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
224
225 --- a/drivers/net/wireless/ath/ath9k/hw.h
226 +++ b/drivers/net/wireless/ath/ath9k/hw.h
227 @@ -860,7 +860,7 @@ u32 ath9k_hw_getrxfilter(struct ath_hw *
228 void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits);
229 bool ath9k_hw_phy_disable(struct ath_hw *ah);
230 bool ath9k_hw_disable(struct ath_hw *ah);
231 -void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit);
232 +void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test);
233 void ath9k_hw_setopmode(struct ath_hw *ah);
234 void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1);
235 void ath9k_hw_setbssidmask(struct ath_hw *ah);
236 --- a/drivers/net/wireless/ath/ath9k/main.c
237 +++ b/drivers/net/wireless/ath/ath9k/main.c
238 @@ -24,7 +24,7 @@ static void ath_update_txpow(struct ath_
239 struct ath_hw *ah = sc->sc_ah;
240
241 if (sc->curtxpow != sc->config.txpowlimit) {
242 - ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
243 + ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit, false);
244 /* read back in case value is clamped */
245 sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
246 }
247 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
248 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
249 @@ -614,7 +614,7 @@ static int ar9003_hw_process_ini(struct
250 channel->max_antenna_gain * 2,
251 channel->max_power * 2,
252 min((u32) MAX_RATE_POWER,
253 - (u32) regulatory->power_limit));
254 + (u32) regulatory->power_limit), false);
255
256 return 0;
257 }
258 --- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
259 +++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
260 @@ -875,7 +875,7 @@ static int ar5008_hw_process_ini(struct
261 channel->max_antenna_gain * 2,
262 channel->max_power * 2,
263 min((u32) MAX_RATE_POWER,
264 - (u32) regulatory->power_limit));
265 + (u32) regulatory->power_limit), false);
266
267 /* Write analog registers */
268 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
269 --- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c
270 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
271 @@ -29,7 +29,7 @@ static void ath_update_txpow(struct ath9
272 struct ath_hw *ah = priv->ah;
273
274 if (priv->curtxpow != priv->txpowlimit) {
275 - ath9k_hw_set_txpowerlimit(ah, priv->txpowlimit);
276 + ath9k_hw_set_txpowerlimit(ah, priv->txpowlimit, false);
277 /* read back in case value is clamped */
278 priv->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
279 }