aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2010-07-01 18:09:51 -0400
committerJohn W. Linville <linville@tuxdriver.com>2010-07-02 13:44:37 -0400
commit54bd5006b03ee980f6067b4d61c3605b5a5e1d4a (patch)
tree9542e10c03a130c46a34173bebd2cd3e202034f9 /drivers
parentf2552e28375cb34073a2f940ee9a8439c37d9ec2 (diff)
ath9k_hw: clean up the noise floor calibration code to reduce code duplication
Signed-off-by: Felix Fietkau <nbd@openwrt.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/ath/ath9k/ar5008_phy.c37
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9002_phy.c43
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.c37
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h6
5 files changed, 31 insertions, 96 deletions
diff --git a/drivers/net/wireless/ath/ath9k/ar5008_phy.c b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
index c6751826ce70..48c5a5f38caf 100644
--- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
@@ -1495,50 +1495,25 @@ static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
1495static void ar5008_hw_do_getnf(struct ath_hw *ah, 1495static void ar5008_hw_do_getnf(struct ath_hw *ah,
1496 int16_t nfarray[NUM_NF_READINGS]) 1496 int16_t nfarray[NUM_NF_READINGS])
1497{ 1497{
1498 struct ath_common *common = ath9k_hw_common(ah);
1499 int16_t nf; 1498 int16_t nf;
1500 1499
1501 nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR); 1500 nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
1502 if (nf & 0x100) 1501 nfarray[0] = sign_extend(nf, 9);
1503 nf = 0 - ((nf ^ 0x1ff) + 1);
1504 ath_print(common, ATH_DBG_CALIBRATE,
1505 "NF calibrated [ctl] [chain 0] is %d\n", nf);
1506 nfarray[0] = nf;
1507 1502
1508 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR); 1503 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR);
1509 if (nf & 0x100) 1504 nfarray[1] = sign_extend(nf, 9);
1510 nf = 0 - ((nf ^ 0x1ff) + 1);
1511 ath_print(common, ATH_DBG_CALIBRATE,
1512 "NF calibrated [ctl] [chain 1] is %d\n", nf);
1513 nfarray[1] = nf;
1514 1505
1515 nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR); 1506 nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR);
1516 if (nf & 0x100) 1507 nfarray[2] = sign_extend(nf, 9);
1517 nf = 0 - ((nf ^ 0x1ff) + 1);
1518 ath_print(common, ATH_DBG_CALIBRATE,
1519 "NF calibrated [ctl] [chain 2] is %d\n", nf);
1520 nfarray[2] = nf;
1521 1508
1522 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR); 1509 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
1523 if (nf & 0x100) 1510 nfarray[3] = sign_extend(nf, 9);
1524 nf = 0 - ((nf ^ 0x1ff) + 1);
1525 ath_print(common, ATH_DBG_CALIBRATE,
1526 "NF calibrated [ext] [chain 0] is %d\n", nf);
1527 nfarray[3] = nf;
1528 1511
1529 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR); 1512 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR);
1530 if (nf & 0x100) 1513 nfarray[4] = sign_extend(nf, 9);
1531 nf = 0 - ((nf ^ 0x1ff) + 1);
1532 ath_print(common, ATH_DBG_CALIBRATE,
1533 "NF calibrated [ext] [chain 1] is %d\n", nf);
1534 nfarray[4] = nf;
1535 1514
1536 nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR); 1515 nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR);
1537 if (nf & 0x100) 1516 nfarray[5] = sign_extend(nf, 9);
1538 nf = 0 - ((nf ^ 0x1ff) + 1);
1539 ath_print(common, ATH_DBG_CALIBRATE,
1540 "NF calibrated [ext] [chain 2] is %d\n", nf);
1541 nfarray[5] = nf;
1542} 1517}
1543 1518
1544static void ar5008_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan) 1519static void ar5008_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_phy.c b/drivers/net/wireless/ath/ath9k/ar9002_phy.c
index 240e8a402c9f..4922b8d4a938 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_phy.c
@@ -471,47 +471,22 @@ static u32 ar9002_hw_compute_pll_control(struct ath_hw *ah,
471static void ar9002_hw_do_getnf(struct ath_hw *ah, 471static void ar9002_hw_do_getnf(struct ath_hw *ah,
472 int16_t nfarray[NUM_NF_READINGS]) 472 int16_t nfarray[NUM_NF_READINGS])
473{ 473{
474 struct ath_common *common = ath9k_hw_common(ah);
475 int16_t nf; 474 int16_t nf;
476 475
477 nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR); 476 nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
477 nfarray[0] = sign_extend(nf, 9);
478 478
479 if (nf & 0x100) 479 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR9280_PHY_EXT_MINCCA_PWR);
480 nf = 0 - ((nf ^ 0x1ff) + 1); 480 nfarray[3] = sign_extend(nf, 9);
481 ath_print(common, ATH_DBG_CALIBRATE,
482 "NF calibrated [ctl] [chain 0] is %d\n", nf);
483
484 nfarray[0] = nf;
485 481
486 if (!AR_SREV_9285(ah) && !AR_SREV_9271(ah)) { 482 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
487 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), 483 return;
488 AR9280_PHY_CH1_MINCCA_PWR);
489 484
490 if (nf & 0x100) 485 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR9280_PHY_CH1_MINCCA_PWR);
491 nf = 0 - ((nf ^ 0x1ff) + 1); 486 nfarray[1] = sign_extend(nf, 9);
492 ath_print(common, ATH_DBG_CALIBRATE,
493 "NF calibrated [ctl] [chain 1] is %d\n", nf);
494 nfarray[1] = nf;
495 }
496 487
497 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR9280_PHY_EXT_MINCCA_PWR); 488 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR9280_PHY_CH1_EXT_MINCCA_PWR);
498 if (nf & 0x100) 489 nfarray[4] = sign_extend(nf, 9);
499 nf = 0 - ((nf ^ 0x1ff) + 1);
500 ath_print(common, ATH_DBG_CALIBRATE,
501 "NF calibrated [ext] [chain 0] is %d\n", nf);
502
503 nfarray[3] = nf;
504
505 if (!AR_SREV_9285(ah) && !AR_SREV_9271(ah)) {
506 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
507 AR9280_PHY_CH1_EXT_MINCCA_PWR);
508
509 if (nf & 0x100)
510 nf = 0 - ((nf ^ 0x1ff) + 1);
511 ath_print(common, ATH_DBG_CALIBRATE,
512 "NF calibrated [ext] [chain 1] is %d\n", nf);
513 nfarray[4] = nf;
514 }
515} 490}
516 491
517static void ar9002_hw_set_nf_limits(struct ath_hw *ah) 492static void ar9002_hw_set_nf_limits(struct ath_hw *ah)
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
index a0bc1b77cd1d..868b24ab347a 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
@@ -1018,50 +1018,25 @@ static bool ar9003_hw_ani_control(struct ath_hw *ah,
1018static void ar9003_hw_do_getnf(struct ath_hw *ah, 1018static void ar9003_hw_do_getnf(struct ath_hw *ah,
1019 int16_t nfarray[NUM_NF_READINGS]) 1019 int16_t nfarray[NUM_NF_READINGS])
1020{ 1020{
1021 struct ath_common *common = ath9k_hw_common(ah);
1022 int16_t nf; 1021 int16_t nf;
1023 1022
1024 nf = MS(REG_READ(ah, AR_PHY_CCA_0), AR_PHY_MINCCA_PWR); 1023 nf = MS(REG_READ(ah, AR_PHY_CCA_0), AR_PHY_MINCCA_PWR);
1025 if (nf & 0x100) 1024 nfarray[0] = sign_extend(nf, 9);
1026 nf = 0 - ((nf ^ 0x1ff) + 1);
1027 ath_print(common, ATH_DBG_CALIBRATE,
1028 "NF calibrated [ctl] [chain 0] is %d\n", nf);
1029 nfarray[0] = nf;
1030 1025
1031 nf = MS(REG_READ(ah, AR_PHY_CCA_1), AR_PHY_CH1_MINCCA_PWR); 1026 nf = MS(REG_READ(ah, AR_PHY_CCA_1), AR_PHY_CH1_MINCCA_PWR);
1032 if (nf & 0x100) 1027 nfarray[1] = sign_extend(nf, 9);
1033 nf = 0 - ((nf ^ 0x1ff) + 1);
1034 ath_print(common, ATH_DBG_CALIBRATE,
1035 "NF calibrated [ctl] [chain 1] is %d\n", nf);
1036 nfarray[1] = nf;
1037 1028
1038 nf = MS(REG_READ(ah, AR_PHY_CCA_2), AR_PHY_CH2_MINCCA_PWR); 1029 nf = MS(REG_READ(ah, AR_PHY_CCA_2), AR_PHY_CH2_MINCCA_PWR);
1039 if (nf & 0x100) 1030 nfarray[2] = sign_extend(nf, 9);
1040 nf = 0 - ((nf ^ 0x1ff) + 1);
1041 ath_print(common, ATH_DBG_CALIBRATE,
1042 "NF calibrated [ctl] [chain 2] is %d\n", nf);
1043 nfarray[2] = nf;
1044 1031
1045 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR); 1032 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
1046 if (nf & 0x100) 1033 nfarray[3] = sign_extend(nf, 9);
1047 nf = 0 - ((nf ^ 0x1ff) + 1);
1048 ath_print(common, ATH_DBG_CALIBRATE,
1049 "NF calibrated [ext] [chain 0] is %d\n", nf);
1050 nfarray[3] = nf;
1051 1034
1052 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_1), AR_PHY_CH1_EXT_MINCCA_PWR); 1035 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_1), AR_PHY_CH1_EXT_MINCCA_PWR);
1053 if (nf & 0x100) 1036 nfarray[4] = sign_extend(nf, 9);
1054 nf = 0 - ((nf ^ 0x1ff) + 1);
1055 ath_print(common, ATH_DBG_CALIBRATE,
1056 "NF calibrated [ext] [chain 1] is %d\n", nf);
1057 nfarray[4] = nf;
1058 1037
1059 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_2), AR_PHY_CH2_EXT_MINCCA_PWR); 1038 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_2), AR_PHY_CH2_EXT_MINCCA_PWR);
1060 if (nf & 0x100) 1039 nfarray[5] = sign_extend(nf, 9);
1061 nf = 0 - ((nf ^ 0x1ff) + 1);
1062 ath_print(common, ATH_DBG_CALIBRATE,
1063 "NF calibrated [ext] [chain 2] is %d\n", nf);
1064 nfarray[5] = nf;
1065} 1040}
1066 1041
1067static void ar9003_hw_set_nf_limits(struct ath_hw *ah) 1042static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index 7f49b7511bfd..cc29ef78d1bf 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -182,6 +182,10 @@ static void ath9k_hw_nf_sanitize(struct ath_hw *ah, s16 *nf)
182 if (!nf[i]) 182 if (!nf[i])
183 continue; 183 continue;
184 184
185 ath_print(common, ATH_DBG_CALIBRATE,
186 "NF calibrated [%s] [chain %d] is %d\n",
187 (i > 3 ? "ext" : "ctl"), i % 3, nf[i]);
188
185 if (nf[i] > limit->max) { 189 if (nf[i] > limit->max) {
186 ath_print(common, ATH_DBG_CALIBRATE, 190 ath_print(common, ATH_DBG_CALIBRATE,
187 "NF[%d] (%d) > MAX (%d), correcting to MAX", 191 "NF[%d] (%d) > MAX (%d), correcting to MAX",
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 6a4b69257100..92e2502caafa 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -853,6 +853,12 @@ static inline struct ath_hw_ops *ath9k_hw_ops(struct ath_hw *ah)
853 return &ah->ops; 853 return &ah->ops;
854} 854}
855 855
856static inline int sign_extend(int val, const int nbits)
857{
858 int order = BIT(nbits-1);
859 return (val ^ order) - order;
860}
861
856/* Initialization, Detach, Reset */ 862/* Initialization, Detach, Reset */
857const char *ath9k_hw_probe(u16 vendorid, u16 devid); 863const char *ath9k_hw_probe(u16 vendorid, u16 devid);
858void ath9k_hw_deinit(struct ath_hw *ah); 864void ath9k_hw_deinit(struct ath_hw *ah);