aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis R. Rodriguez <lrodriguez@atheros.com>2010-04-15 17:39:09 -0400
committerJohn W. Linville <linville@tuxdriver.com>2010-04-16 15:43:34 -0400
commit77d6d39a77939e5ed7e2ec72a1c1dce828ee582e (patch)
tree1bd2e36bdabb13ecf97109d8df198aed06d95715
parent400b738678bf6f0b65a76a4ec2925473ba3e06ff (diff)
ath9k_hw: abstract loading noisefloor
This is the last call on calib.c which acceses PHY stuff, with this change we calib.c is now generic between both all supported hardware families. Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> Signed-off-by: Felix Fietkau <nbd@openwrt.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/ath/ath9k/ar5008_phy.c67
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_calib.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.c67
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.h1
-rw-r--r--drivers/net/wireless/ath/ath9k/hw-ops.h6
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h2
6 files changed, 81 insertions, 68 deletions
diff --git a/drivers/net/wireless/ath/ath9k/ar5008_phy.c b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
index bd3792c78af1..94eb069b5ae3 100644
--- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
@@ -1247,6 +1247,72 @@ static void ar5008_hw_do_getnf(struct ath_hw *ah,
1247 nfarray[5] = nf; 1247 nfarray[5] = nf;
1248} 1248}
1249 1249
1250static void ar5008_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
1251{
1252 struct ath9k_nfcal_hist *h;
1253 int i, j;
1254 int32_t val;
1255 const u32 ar5416_cca_regs[6] = {
1256 AR_PHY_CCA,
1257 AR_PHY_CH1_CCA,
1258 AR_PHY_CH2_CCA,
1259 AR_PHY_EXT_CCA,
1260 AR_PHY_CH1_EXT_CCA,
1261 AR_PHY_CH2_EXT_CCA
1262 };
1263 u8 chainmask, rx_chain_status;
1264
1265 rx_chain_status = REG_READ(ah, AR_PHY_RX_CHAINMASK);
1266 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
1267 chainmask = 0x9;
1268 else if (AR_SREV_9280(ah) || AR_SREV_9287(ah)) {
1269 if ((rx_chain_status & 0x2) || (rx_chain_status & 0x4))
1270 chainmask = 0x1B;
1271 else
1272 chainmask = 0x09;
1273 } else {
1274 if (rx_chain_status & 0x4)
1275 chainmask = 0x3F;
1276 else if (rx_chain_status & 0x2)
1277 chainmask = 0x1B;
1278 else
1279 chainmask = 0x09;
1280 }
1281
1282 h = ah->nfCalHist;
1283
1284 for (i = 0; i < NUM_NF_READINGS; i++) {
1285 if (chainmask & (1 << i)) {
1286 val = REG_READ(ah, ar5416_cca_regs[i]);
1287 val &= 0xFFFFFE00;
1288 val |= (((u32) (h[i].privNF) << 1) & 0x1ff);
1289 REG_WRITE(ah, ar5416_cca_regs[i], val);
1290 }
1291 }
1292
1293 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
1294 AR_PHY_AGC_CONTROL_ENABLE_NF);
1295 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
1296 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
1297 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
1298
1299 for (j = 0; j < 5; j++) {
1300 if ((REG_READ(ah, AR_PHY_AGC_CONTROL) &
1301 AR_PHY_AGC_CONTROL_NF) == 0)
1302 break;
1303 udelay(50);
1304 }
1305
1306 for (i = 0; i < NUM_NF_READINGS; i++) {
1307 if (chainmask & (1 << i)) {
1308 val = REG_READ(ah, ar5416_cca_regs[i]);
1309 val &= 0xFFFFFE00;
1310 val |= (((u32) (-50) << 1) & 0x1ff);
1311 REG_WRITE(ah, ar5416_cca_regs[i], val);
1312 }
1313 }
1314}
1315
1250void ar5008_hw_attach_phy_ops(struct ath_hw *ah) 1316void ar5008_hw_attach_phy_ops(struct ath_hw *ah)
1251{ 1317{
1252 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); 1318 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
@@ -1270,6 +1336,7 @@ void ar5008_hw_attach_phy_ops(struct ath_hw *ah)
1270 priv_ops->set_diversity = ar5008_set_diversity; 1336 priv_ops->set_diversity = ar5008_set_diversity;
1271 priv_ops->ani_control = ar5008_hw_ani_control; 1337 priv_ops->ani_control = ar5008_hw_ani_control;
1272 priv_ops->do_getnf = ar5008_hw_do_getnf; 1338 priv_ops->do_getnf = ar5008_hw_do_getnf;
1339 priv_ops->loadnf = ar5008_hw_loadnf;
1273 1340
1274 if (AR_SREV_9100(ah)) 1341 if (AR_SREV_9100(ah))
1275 priv_ops->compute_pll_control = ar9100_hw_compute_pll_control; 1342 priv_ops->compute_pll_control = ar9100_hw_compute_pll_control;
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
index 00e4cb8d5f04..cd80a43ffcff 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
@@ -195,6 +195,11 @@ static bool ar9003_hw_iscal_supported(struct ath_hw *ah,
195 return false; 195 return false;
196} 196}
197 197
198static void ar9003_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
199{
200 /* TODO */
201}
202
198void ar9003_hw_attach_calib_ops(struct ath_hw *ah) 203void ar9003_hw_attach_calib_ops(struct ath_hw *ah)
199{ 204{
200 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); 205 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
@@ -204,6 +209,7 @@ void ar9003_hw_attach_calib_ops(struct ath_hw *ah)
204 priv_ops->init_cal = ar9003_hw_init_cal; 209 priv_ops->init_cal = ar9003_hw_init_cal;
205 priv_ops->setup_calibration = ar9003_hw_setup_calibration; 210 priv_ops->setup_calibration = ar9003_hw_setup_calibration;
206 priv_ops->iscal_supported = ar9003_hw_iscal_supported; 211 priv_ops->iscal_supported = ar9003_hw_iscal_supported;
212 priv_ops->loadnf = ar9003_hw_loadnf;
207 213
208 ops->calibrate = ar9003_hw_calibrate; 214 ops->calibrate = ar9003_hw_calibrate;
209} 215}
diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index 085e1264fbe0..6982577043b8 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -16,7 +16,6 @@
16 16
17#include "hw.h" 17#include "hw.h"
18#include "hw-ops.h" 18#include "hw-ops.h"
19#include "ar9002_phy.h"
20 19
21/* Common calibration code */ 20/* Common calibration code */
22 21
@@ -174,72 +173,6 @@ void ath9k_hw_start_nfcal(struct ath_hw *ah)
174 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF); 173 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
175} 174}
176 175
177void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
178{
179 struct ath9k_nfcal_hist *h;
180 int i, j;
181 int32_t val;
182 const u32 ar5416_cca_regs[6] = {
183 AR_PHY_CCA,
184 AR_PHY_CH1_CCA,
185 AR_PHY_CH2_CCA,
186 AR_PHY_EXT_CCA,
187 AR_PHY_CH1_EXT_CCA,
188 AR_PHY_CH2_EXT_CCA
189 };
190 u8 chainmask, rx_chain_status;
191
192 rx_chain_status = REG_READ(ah, AR_PHY_RX_CHAINMASK);
193 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
194 chainmask = 0x9;
195 else if (AR_SREV_9280(ah) || AR_SREV_9287(ah)) {
196 if ((rx_chain_status & 0x2) || (rx_chain_status & 0x4))
197 chainmask = 0x1B;
198 else
199 chainmask = 0x09;
200 } else {
201 if (rx_chain_status & 0x4)
202 chainmask = 0x3F;
203 else if (rx_chain_status & 0x2)
204 chainmask = 0x1B;
205 else
206 chainmask = 0x09;
207 }
208
209 h = ah->nfCalHist;
210
211 for (i = 0; i < NUM_NF_READINGS; i++) {
212 if (chainmask & (1 << i)) {
213 val = REG_READ(ah, ar5416_cca_regs[i]);
214 val &= 0xFFFFFE00;
215 val |= (((u32) (h[i].privNF) << 1) & 0x1ff);
216 REG_WRITE(ah, ar5416_cca_regs[i], val);
217 }
218 }
219
220 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
221 AR_PHY_AGC_CONTROL_ENABLE_NF);
222 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
223 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
224 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
225
226 for (j = 0; j < 5; j++) {
227 if ((REG_READ(ah, AR_PHY_AGC_CONTROL) &
228 AR_PHY_AGC_CONTROL_NF) == 0)
229 break;
230 udelay(50);
231 }
232
233 for (i = 0; i < NUM_NF_READINGS; i++) {
234 if (chainmask & (1 << i)) {
235 val = REG_READ(ah, ar5416_cca_regs[i]);
236 val &= 0xFFFFFE00;
237 val |= (((u32) (-50) << 1) & 0x1ff);
238 REG_WRITE(ah, ar5416_cca_regs[i], val);
239 }
240 }
241}
242
243int16_t ath9k_hw_getnf(struct ath_hw *ah, 176int16_t ath9k_hw_getnf(struct ath_hw *ah,
244 struct ath9k_channel *chan) 177 struct ath9k_channel *chan)
245{ 178{
diff --git a/drivers/net/wireless/ath/ath9k/calib.h b/drivers/net/wireless/ath/ath9k/calib.h
index 9f6c21d50f17..25828e89e7c7 100644
--- a/drivers/net/wireless/ath/ath9k/calib.h
+++ b/drivers/net/wireless/ath/ath9k/calib.h
@@ -114,7 +114,6 @@ struct ath9k_pacal_info{
114 114
115bool ath9k_hw_reset_calvalid(struct ath_hw *ah); 115bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
116void ath9k_hw_start_nfcal(struct ath_hw *ah); 116void ath9k_hw_start_nfcal(struct ath_hw *ah);
117void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
118int16_t ath9k_hw_getnf(struct ath_hw *ah, 117int16_t ath9k_hw_getnf(struct ath_hw *ah,
119 struct ath9k_channel *chan); 118 struct ath9k_channel *chan);
120void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah); 119void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah);
diff --git a/drivers/net/wireless/ath/ath9k/hw-ops.h b/drivers/net/wireless/ath/ath9k/hw-ops.h
index b777fd1894f0..b444ce5f09f8 100644
--- a/drivers/net/wireless/ath/ath9k/hw-ops.h
+++ b/drivers/net/wireless/ath/ath9k/hw-ops.h
@@ -182,6 +182,12 @@ static inline void ath9k_hw_do_getnf(struct ath_hw *ah,
182 ath9k_hw_private_ops(ah)->do_getnf(ah, nfarray); 182 ath9k_hw_private_ops(ah)->do_getnf(ah, nfarray);
183} 183}
184 184
185static inline void ath9k_hw_loadnf(struct ath_hw *ah,
186 struct ath9k_channel *chan)
187{
188 ath9k_hw_private_ops(ah)->loadnf(ah, chan);
189}
190
185static inline bool ath9k_hw_init_cal(struct ath_hw *ah, 191static inline bool ath9k_hw_init_cal(struct ath_hw *ah,
186 struct ath9k_channel *chan) 192 struct ath9k_channel *chan)
187{ 193{
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 7a32733108a2..d28a904606b8 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -486,6 +486,7 @@ struct ath_gen_timer_table {
486 * AR_RTC_PLL_CONTROL for a given channel 486 * AR_RTC_PLL_CONTROL for a given channel
487 * @setup_calibration: set up calibration 487 * @setup_calibration: set up calibration
488 * @iscal_supported: used to query if a type of calibration is supported 488 * @iscal_supported: used to query if a type of calibration is supported
489 * @loadnf: load noise floor read from each chain on the CCA registers
489 */ 490 */
490struct ath_hw_private_ops { 491struct ath_hw_private_ops {
491 /* Calibration ops */ 492 /* Calibration ops */
@@ -528,6 +529,7 @@ struct ath_hw_private_ops {
528 bool (*ani_control)(struct ath_hw *ah, enum ath9k_ani_cmd cmd, 529 bool (*ani_control)(struct ath_hw *ah, enum ath9k_ani_cmd cmd,
529 int param); 530 int param);
530 void (*do_getnf)(struct ath_hw *ah, int16_t nfarray[NUM_NF_READINGS]); 531 void (*do_getnf)(struct ath_hw *ah, int16_t nfarray[NUM_NF_READINGS]);
532 void (*loadnf)(struct ath_hw *ah, struct ath9k_channel *chan);
531}; 533};
532 534
533/** 535/**