ath9k: clean up some code duplication related to noise floor handling
[openwrt/svn-archive/archive.git] / package / mac80211 / patches / 531-ath9k_nf_cleanup.patch
1 --- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
2 +++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
3 @@ -1497,50 +1497,25 @@ static bool ar5008_hw_ani_control_new(st
4 static void ar5008_hw_do_getnf(struct ath_hw *ah,
5 int16_t nfarray[NUM_NF_READINGS])
6 {
7 - struct ath_common *common = ath9k_hw_common(ah);
8 int16_t nf;
9
10 nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
11 - if (nf & 0x100)
12 - nf = 0 - ((nf ^ 0x1ff) + 1);
13 - ath_print(common, ATH_DBG_CALIBRATE,
14 - "NF calibrated [ctl] [chain 0] is %d\n", nf);
15 - nfarray[0] = nf;
16 + nfarray[0] = sign_extend(nf, 9);
17
18 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR);
19 - if (nf & 0x100)
20 - nf = 0 - ((nf ^ 0x1ff) + 1);
21 - ath_print(common, ATH_DBG_CALIBRATE,
22 - "NF calibrated [ctl] [chain 1] is %d\n", nf);
23 - nfarray[1] = nf;
24 + nfarray[1] = sign_extend(nf, 9);
25
26 nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR);
27 - if (nf & 0x100)
28 - nf = 0 - ((nf ^ 0x1ff) + 1);
29 - ath_print(common, ATH_DBG_CALIBRATE,
30 - "NF calibrated [ctl] [chain 2] is %d\n", nf);
31 - nfarray[2] = nf;
32 + nfarray[2] = sign_extend(nf, 9);
33
34 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
35 - if (nf & 0x100)
36 - nf = 0 - ((nf ^ 0x1ff) + 1);
37 - ath_print(common, ATH_DBG_CALIBRATE,
38 - "NF calibrated [ext] [chain 0] is %d\n", nf);
39 - nfarray[3] = nf;
40 + nfarray[3] = sign_extend(nf, 9);
41
42 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR);
43 - if (nf & 0x100)
44 - nf = 0 - ((nf ^ 0x1ff) + 1);
45 - ath_print(common, ATH_DBG_CALIBRATE,
46 - "NF calibrated [ext] [chain 1] is %d\n", nf);
47 - nfarray[4] = nf;
48 + nfarray[4] = sign_extend(nf, 9);
49
50 nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR);
51 - if (nf & 0x100)
52 - nf = 0 - ((nf ^ 0x1ff) + 1);
53 - ath_print(common, ATH_DBG_CALIBRATE,
54 - "NF calibrated [ext] [chain 2] is %d\n", nf);
55 - nfarray[5] = nf;
56 + nfarray[5] = sign_extend(nf, 9);
57 }
58
59 static void ar5008_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
60 --- a/drivers/net/wireless/ath/ath9k/ar9002_phy.c
61 +++ b/drivers/net/wireless/ath/ath9k/ar9002_phy.c
62 @@ -471,47 +471,22 @@ static u32 ar9002_hw_compute_pll_control
63 static void ar9002_hw_do_getnf(struct ath_hw *ah,
64 int16_t nfarray[NUM_NF_READINGS])
65 {
66 - struct ath_common *common = ath9k_hw_common(ah);
67 int16_t nf;
68
69 nf = MS(REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
70 -
71 - if (nf & 0x100)
72 - nf = 0 - ((nf ^ 0x1ff) + 1);
73 - ath_print(common, ATH_DBG_CALIBRATE,
74 - "NF calibrated [ctl] [chain 0] is %d\n", nf);
75 -
76 - nfarray[0] = nf;
77 -
78 - if (!AR_SREV_9285(ah) && !AR_SREV_9271(ah)) {
79 - nf = MS(REG_READ(ah, AR_PHY_CH1_CCA),
80 - AR9280_PHY_CH1_MINCCA_PWR);
81 -
82 - if (nf & 0x100)
83 - nf = 0 - ((nf ^ 0x1ff) + 1);
84 - ath_print(common, ATH_DBG_CALIBRATE,
85 - "NF calibrated [ctl] [chain 1] is %d\n", nf);
86 - nfarray[1] = nf;
87 - }
88 + nfarray[0] = sign_extend(nf, 9);
89
90 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR9280_PHY_EXT_MINCCA_PWR);
91 - if (nf & 0x100)
92 - nf = 0 - ((nf ^ 0x1ff) + 1);
93 - ath_print(common, ATH_DBG_CALIBRATE,
94 - "NF calibrated [ext] [chain 0] is %d\n", nf);
95 -
96 - nfarray[3] = nf;
97 -
98 - if (!AR_SREV_9285(ah) && !AR_SREV_9271(ah)) {
99 - nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA),
100 - AR9280_PHY_CH1_EXT_MINCCA_PWR);
101 -
102 - if (nf & 0x100)
103 - nf = 0 - ((nf ^ 0x1ff) + 1);
104 - ath_print(common, ATH_DBG_CALIBRATE,
105 - "NF calibrated [ext] [chain 1] is %d\n", nf);
106 - nfarray[4] = nf;
107 - }
108 + nfarray[3] = sign_extend(nf, 9);
109 +
110 + if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
111 + return;
112 +
113 + nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR9280_PHY_CH1_MINCCA_PWR);
114 + nfarray[1] = sign_extend(nf, 9);
115 +
116 + nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR9280_PHY_CH1_EXT_MINCCA_PWR);
117 + nfarray[4] = sign_extend(nf, 9);
118 }
119
120 static void ar9002_hw_set_nf_limits(struct ath_hw *ah)
121 --- a/drivers/net/wireless/ath/ath9k/calib.c
122 +++ b/drivers/net/wireless/ath/ath9k/calib.c
123 @@ -182,6 +182,10 @@ static void ath9k_hw_nf_sanitize(struct
124 if (!nf[i])
125 continue;
126
127 + ath_print(common, ATH_DBG_CALIBRATE,
128 + "NF calibrated [%s] [chain %d] is %d\n",
129 + (i > 3 ? "ext" : "ctl"), i % 3, nf[i]);
130 +
131 if (nf[i] > limit->max) {
132 ath_print(common, ATH_DBG_CALIBRATE,
133 "NF[%d] (%d) > MAX (%d), correcting to MAX",
134 --- a/drivers/net/wireless/ath/ath9k/hw.h
135 +++ b/drivers/net/wireless/ath/ath9k/hw.h
136 @@ -853,6 +853,12 @@ static inline struct ath_hw_ops *ath9k_h
137 return &ah->ops;
138 }
139
140 +static inline int sign_extend(int val, const int nbits)
141 +{
142 + int order = BIT(nbits-1);
143 + return (val ^ order) - order;
144 +}
145 +
146 /* Initialization, Detach, Reset */
147 const char *ath9k_hw_probe(u16 vendorid, u16 devid);
148 void ath9k_hw_deinit(struct ath_hw *ah);
149 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
150 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
151 @@ -1018,50 +1018,25 @@ static bool ar9003_hw_ani_control(struct
152 static void ar9003_hw_do_getnf(struct ath_hw *ah,
153 int16_t nfarray[NUM_NF_READINGS])
154 {
155 - struct ath_common *common = ath9k_hw_common(ah);
156 int16_t nf;
157
158 nf = MS(REG_READ(ah, AR_PHY_CCA_0), AR_PHY_MINCCA_PWR);
159 - if (nf & 0x100)
160 - nf = 0 - ((nf ^ 0x1ff) + 1);
161 - ath_print(common, ATH_DBG_CALIBRATE,
162 - "NF calibrated [ctl] [chain 0] is %d\n", nf);
163 - nfarray[0] = nf;
164 + nfarray[0] = sign_extend(nf, 9);
165
166 nf = MS(REG_READ(ah, AR_PHY_CCA_1), AR_PHY_CH1_MINCCA_PWR);
167 - if (nf & 0x100)
168 - nf = 0 - ((nf ^ 0x1ff) + 1);
169 - ath_print(common, ATH_DBG_CALIBRATE,
170 - "NF calibrated [ctl] [chain 1] is %d\n", nf);
171 - nfarray[1] = nf;
172 + nfarray[1] = sign_extend(nf, 9);
173
174 nf = MS(REG_READ(ah, AR_PHY_CCA_2), AR_PHY_CH2_MINCCA_PWR);
175 - if (nf & 0x100)
176 - nf = 0 - ((nf ^ 0x1ff) + 1);
177 - ath_print(common, ATH_DBG_CALIBRATE,
178 - "NF calibrated [ctl] [chain 2] is %d\n", nf);
179 - nfarray[2] = nf;
180 + nfarray[2] = sign_extend(nf, 9);
181
182 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
183 - if (nf & 0x100)
184 - nf = 0 - ((nf ^ 0x1ff) + 1);
185 - ath_print(common, ATH_DBG_CALIBRATE,
186 - "NF calibrated [ext] [chain 0] is %d\n", nf);
187 - nfarray[3] = nf;
188 + nfarray[3] = sign_extend(nf, 9);
189
190 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_1), AR_PHY_CH1_EXT_MINCCA_PWR);
191 - if (nf & 0x100)
192 - nf = 0 - ((nf ^ 0x1ff) + 1);
193 - ath_print(common, ATH_DBG_CALIBRATE,
194 - "NF calibrated [ext] [chain 1] is %d\n", nf);
195 - nfarray[4] = nf;
196 + nfarray[4] = sign_extend(nf, 9);
197
198 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_2), AR_PHY_CH2_EXT_MINCCA_PWR);
199 - if (nf & 0x100)
200 - nf = 0 - ((nf ^ 0x1ff) + 1);
201 - ath_print(common, ATH_DBG_CALIBRATE,
202 - "NF calibrated [ext] [chain 2] is %d\n", nf);
203 - nfarray[5] = nf;
204 + nfarray[5] = sign_extend(nf, 9);
205 }
206
207 static void ar9003_hw_set_nf_limits(struct ath_hw *ah)