blob: 04b060af5087af230f261d4950c7b55a3b771591 [file] [log] [blame]
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2010-2011 Atheros Communications Inc.
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "hw.h"
Felix Fietkauda6f1d72010-04-15 17:38:31 -040018#include "ar9003_phy.h"
Luis R. Rodriguez8525f282010-04-15 17:38:19 -040019
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -040020static const int firstep_table[] =
21/* level: 0 1 2 3 4 5 6 7 8 */
22 { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
23
24static const int cycpwrThr1_table[] =
25/* level: 0 1 2 3 4 5 6 7 8 */
26 { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
27
28/*
29 * register values to turn OFDM weak signal detection OFF
30 */
31static const int m1ThreshLow_off = 127;
32static const int m2ThreshLow_off = 127;
33static const int m1Thresh_off = 127;
34static const int m2Thresh_off = 127;
35static const int m2CountThr_off = 31;
36static const int m2CountThrLow_off = 63;
37static const int m1ThreshLowExt_off = 127;
38static const int m2ThreshLowExt_off = 127;
39static const int m1ThreshExt_off = 127;
40static const int m2ThreshExt_off = 127;
41
Luis R. Rodriguez8525f282010-04-15 17:38:19 -040042/**
43 * ar9003_hw_set_channel - set channel on single-chip device
44 * @ah: atheros hardware structure
45 * @chan:
46 *
47 * This is the function to change channel on single-chip devices, that is
48 * all devices after ar9280.
49 *
50 * This function takes the channel value in MHz and sets
51 * hardware channel value. Assumes writes have been enabled to analog bus.
52 *
53 * Actual Expression,
54 *
55 * For 2GHz channel,
56 * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
57 * (freq_ref = 40MHz)
58 *
59 * For 5GHz channel,
60 * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
61 * (freq_ref = 40MHz/(24>>amodeRefSel))
62 *
63 * For 5GHz channels which are 5MHz spaced,
64 * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
65 * (freq_ref = 40MHz)
66 */
67static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
68{
Felix Fietkauf7abf0c2010-04-15 17:38:33 -040069 u16 bMode, fracMode = 0, aModeRefSel = 0;
70 u32 freq, channelSel = 0, reg32 = 0;
71 struct chan_centers centers;
72 int loadSynthChannel;
73
74 ath9k_hw_get_channel_centers(ah, chan, &centers);
75 freq = centers.synth_center;
76
77 if (freq < 4800) { /* 2 GHz, fractional mode */
Gabor Juhos5acb4b92011-06-21 11:23:34 +020078 if (AR_SREV_9330(ah)) {
79 u32 chan_frac;
80 u32 div;
81
82 if (ah->is_clk_25mhz)
83 div = 75;
84 else
85 div = 120;
86
87 channelSel = (freq * 4) / div;
88 chan_frac = (((freq * 4) % div) * 0x20000) / div;
89 channelSel = (channelSel << 17) | chan_frac;
90 } else if (AR_SREV_9485(ah)) {
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +053091 u32 chan_frac;
92
93 /*
94 * freq_ref = 40 / (refdiva >> amoderefsel); where refdiva=1 and amoderefsel=0
95 * ndiv = ((chan_mhz * 4) / 3) / freq_ref;
96 * chansel = int(ndiv), chanfrac = (ndiv - chansel) * 0x20000
97 */
98 channelSel = (freq * 4) / 120;
99 chan_frac = (((freq * 4) % 120) * 0x20000) / 120;
100 channelSel = (channelSel << 17) | chan_frac;
Vasanthakumar Thiagarajan17869f42011-04-19 19:29:08 +0530101 } else if (AR_SREV_9340(ah)) {
102 if (ah->is_clk_25mhz) {
103 u32 chan_frac;
104
105 channelSel = (freq * 2) / 75;
106 chan_frac = (((freq * 2) % 75) * 0x20000) / 75;
107 channelSel = (channelSel << 17) | chan_frac;
108 } else
109 channelSel = CHANSEL_2G(freq) >> 1;
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530110 } else
Vasanthakumar Thiagarajan85dd0922010-12-06 04:27:45 -0800111 channelSel = CHANSEL_2G(freq);
Felix Fietkauf7abf0c2010-04-15 17:38:33 -0400112 /* Set to 2G mode */
113 bMode = 1;
114 } else {
Vasanthakumar Thiagarajan17869f42011-04-19 19:29:08 +0530115 if (AR_SREV_9340(ah) && ah->is_clk_25mhz) {
116 u32 chan_frac;
117
118 channelSel = (freq * 2) / 75;
Gabor Juhosdbb204e2011-06-21 11:23:33 +0200119 chan_frac = (((freq * 2) % 75) * 0x20000) / 75;
Vasanthakumar Thiagarajan17869f42011-04-19 19:29:08 +0530120 channelSel = (channelSel << 17) | chan_frac;
121 } else {
122 channelSel = CHANSEL_5G(freq);
123 /* Doubler is ON, so, divide channelSel by 2. */
124 channelSel >>= 1;
125 }
Felix Fietkauf7abf0c2010-04-15 17:38:33 -0400126 /* Set to 5G mode */
127 bMode = 0;
128 }
129
130 /* Enable fractional mode for all channels */
131 fracMode = 1;
132 aModeRefSel = 0;
133 loadSynthChannel = 0;
134
135 reg32 = (bMode << 29);
136 REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
137
138 /* Enable Long shift Select for Synthesizer */
139 REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
140 AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
141
142 /* Program Synth. setting */
143 reg32 = (channelSel << 2) | (fracMode << 30) |
144 (aModeRefSel << 28) | (loadSynthChannel << 31);
145 REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
146
147 /* Toggle Load Synth channel bit */
148 loadSynthChannel = 1;
149 reg32 = (channelSel << 2) | (fracMode << 30) |
150 (aModeRefSel << 28) | (loadSynthChannel << 31);
151 REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
152
153 ah->curchan = chan;
154 ah->curchan_rad_index = -1;
155
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400156 return 0;
157}
158
159/**
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400160 * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400161 * @ah: atheros hardware structure
162 * @chan:
163 *
164 * For single-chip solutions. Converts to baseband spur frequency given the
165 * input channel frequency and compute register settings below.
166 *
167 * Spur mitigation for MRC CCK
168 */
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400169static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
170 struct ath9k_channel *chan)
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400171{
Joe Perches07b2fa52010-11-20 18:38:53 -0800172 static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
Felix Fietkauca375552010-04-15 17:38:35 -0400173 int cur_bb_spur, negative = 0, cck_spur_freq;
174 int i;
Vasanthakumar Thiagarajand9a25452010-12-06 04:27:47 -0800175 int range, max_spur_cnts, synth_freq;
176 u8 *spur_fbin_ptr = NULL;
Felix Fietkauca375552010-04-15 17:38:35 -0400177
178 /*
179 * Need to verify range +/- 10 MHz in control channel, otherwise spur
180 * is out-of-band and can be ignored.
181 */
182
Gabor Juhosc1acfbe2011-06-21 11:23:32 +0200183 if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah)) {
Vasanthakumar Thiagarajand9a25452010-12-06 04:27:47 -0800184 spur_fbin_ptr = ar9003_get_spur_chan_ptr(ah,
185 IS_CHAN_2GHZ(chan));
186 if (spur_fbin_ptr[0] == 0) /* No spur */
187 return;
188 max_spur_cnts = 5;
189 if (IS_CHAN_HT40(chan)) {
190 range = 19;
191 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
192 AR_PHY_GC_DYN2040_PRI_CH) == 0)
193 synth_freq = chan->channel + 10;
194 else
195 synth_freq = chan->channel - 10;
196 } else {
197 range = 10;
198 synth_freq = chan->channel;
199 }
200 } else {
Rajkumar Manoharan38df2f02011-10-24 18:14:39 +0530201 range = AR_SREV_9462(ah) ? 5 : 10;
Vasanthakumar Thiagarajand9a25452010-12-06 04:27:47 -0800202 max_spur_cnts = 4;
203 synth_freq = chan->channel;
204 }
205
206 for (i = 0; i < max_spur_cnts; i++) {
Rajkumar Manoharan38df2f02011-10-24 18:14:39 +0530207 if (AR_SREV_9462(ah) && (i == 0 || i == 3))
208 continue;
Felix Fietkauca375552010-04-15 17:38:35 -0400209 negative = 0;
Gabor Juhosc1acfbe2011-06-21 11:23:32 +0200210 if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah))
Vasanthakumar Thiagarajand9a25452010-12-06 04:27:47 -0800211 cur_bb_spur = FBIN2FREQ(spur_fbin_ptr[i],
212 IS_CHAN_2GHZ(chan)) - synth_freq;
213 else
214 cur_bb_spur = spur_freq[i] - synth_freq;
Felix Fietkauca375552010-04-15 17:38:35 -0400215
216 if (cur_bb_spur < 0) {
217 negative = 1;
218 cur_bb_spur = -cur_bb_spur;
219 }
Vasanthakumar Thiagarajand9a25452010-12-06 04:27:47 -0800220 if (cur_bb_spur < range) {
Felix Fietkauca375552010-04-15 17:38:35 -0400221 cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
222
223 if (negative == 1)
224 cck_spur_freq = -cck_spur_freq;
225
226 cck_spur_freq = cck_spur_freq & 0xfffff;
227
228 REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
229 AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
230 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
231 AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
232 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
233 AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
234 0x2);
235 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
236 AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
237 0x1);
238 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
239 AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
240 cck_spur_freq);
241
242 return;
243 }
244 }
245
246 REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
247 AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
248 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
249 AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
250 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
251 AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400252}
253
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400254/* Clean all spur register fields */
255static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
256{
257 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
258 AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
259 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
260 AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
261 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
262 AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
263 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
264 AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
265 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
266 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
267 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
268 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
269 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
270 AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
271 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
272 AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
273 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
274 AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
275
276 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
277 AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
278 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
279 AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
280 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
281 AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
282 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
283 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
284 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
285 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
286 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
287 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
288 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
289 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
290 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
291 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
292 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
293 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
294 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
295 AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
296}
297
298static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
299 int freq_offset,
300 int spur_freq_sd,
301 int spur_delta_phase,
302 int spur_subchannel_sd)
303{
304 int mask_index = 0;
305
306 /* OFDM Spur mitigation */
307 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
308 AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
309 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
310 AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
311 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
312 AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
313 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
314 AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
315 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
316 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
317 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
318 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
319 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
320 AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
321 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
322 AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
323 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
324 AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
325
326 if (REG_READ_FIELD(ah, AR_PHY_MODE,
327 AR_PHY_MODE_DYNAMIC) == 0x1)
328 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
329 AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
330
331 mask_index = (freq_offset << 4) / 5;
332 if (mask_index < 0)
333 mask_index = mask_index - 1;
334
335 mask_index = mask_index & 0x7f;
336
337 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
338 AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
339 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
340 AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
341 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
342 AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
343 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
344 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
345 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
346 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
347 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
348 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
349 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
350 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
351 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
352 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
353 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
354 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
355 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
356 AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
357}
358
359static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
360 struct ath9k_channel *chan,
361 int freq_offset)
362{
363 int spur_freq_sd = 0;
364 int spur_subchannel_sd = 0;
365 int spur_delta_phase = 0;
366
367 if (IS_CHAN_HT40(chan)) {
368 if (freq_offset < 0) {
369 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
370 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
371 spur_subchannel_sd = 1;
372 else
373 spur_subchannel_sd = 0;
374
Rajkumar Manoharana844adf2011-08-05 18:59:42 +0530375 spur_freq_sd = (freq_offset << 9) / 11;
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400376
377 } else {
378 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
379 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
380 spur_subchannel_sd = 0;
381 else
382 spur_subchannel_sd = 1;
383
Rajkumar Manoharana844adf2011-08-05 18:59:42 +0530384 spur_freq_sd = (freq_offset << 9) / 11;
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400385
386 }
387
388 spur_delta_phase = (freq_offset << 17) / 5;
389
390 } else {
391 spur_subchannel_sd = 0;
392 spur_freq_sd = (freq_offset << 9) /11;
393 spur_delta_phase = (freq_offset << 18) / 5;
394 }
395
396 spur_freq_sd = spur_freq_sd & 0x3ff;
397 spur_delta_phase = spur_delta_phase & 0xfffff;
398
399 ar9003_hw_spur_ofdm(ah,
400 freq_offset,
401 spur_freq_sd,
402 spur_delta_phase,
403 spur_subchannel_sd);
404}
405
406/* Spur mitigation for OFDM */
407static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
408 struct ath9k_channel *chan)
409{
410 int synth_freq;
411 int range = 10;
412 int freq_offset = 0;
413 int mode;
414 u8* spurChansPtr;
415 unsigned int i;
416 struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
417
418 if (IS_CHAN_5GHZ(chan)) {
419 spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
420 mode = 0;
421 }
422 else {
423 spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
424 mode = 1;
425 }
426
427 if (spurChansPtr[0] == 0)
428 return; /* No spur in the mode */
429
430 if (IS_CHAN_HT40(chan)) {
431 range = 19;
432 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
433 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
434 synth_freq = chan->channel - 10;
435 else
436 synth_freq = chan->channel + 10;
437 } else {
438 range = 10;
439 synth_freq = chan->channel;
440 }
441
442 ar9003_hw_spur_ofdm_clear(ah);
443
roel0f8e94d2011-04-10 21:09:50 +0200444 for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) {
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400445 freq_offset = FBIN2FREQ(spurChansPtr[i], mode) - synth_freq;
446 if (abs(freq_offset) < range) {
447 ar9003_hw_spur_ofdm_work(ah, chan, freq_offset);
448 break;
449 }
450 }
451}
452
453static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
454 struct ath9k_channel *chan)
455{
456 ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
457 ar9003_hw_spur_mitigate_ofdm(ah, chan);
458}
459
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400460static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
461 struct ath9k_channel *chan)
462{
Felix Fietkau317d3322010-04-15 17:38:34 -0400463 u32 pll;
464
465 pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
466
467 if (chan && IS_CHAN_HALF_RATE(chan))
468 pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
469 else if (chan && IS_CHAN_QUARTER_RATE(chan))
470 pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
471
Felix Fietkau14bc1102010-04-26 15:04:30 -0400472 pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
Felix Fietkau317d3322010-04-15 17:38:34 -0400473
474 return pll;
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400475}
476
477static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
478 struct ath9k_channel *chan)
479{
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400480 u32 phymode;
481 u32 enableDacFifo = 0;
482
483 enableDacFifo =
484 (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
485
486 /* Enable 11n HT, 20 MHz */
Rajkumar Manoharan8ad38d22011-08-20 17:34:19 +0530487 phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 |
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400488 AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
489
490 /* Configure baseband for dynamic 20/40 operation */
491 if (IS_CHAN_HT40(chan)) {
492 phymode |= AR_PHY_GC_DYN2040_EN;
493 /* Configure control (primary) channel at +-10MHz */
494 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
495 (chan->chanmode == CHANNEL_G_HT40PLUS))
496 phymode |= AR_PHY_GC_DYN2040_PRI_CH;
497
498 }
499
500 /* make sure we preserve INI settings */
501 phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
502 /* turn off Green Field detection for STA for now */
503 phymode &= ~AR_PHY_GC_GF_DETECT_EN;
504
505 REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
506
507 /* Configure MAC for 20/40 operation */
508 ath9k_hw_set11nmac2040(ah);
509
510 /* global transmit timeout (25 TUs default)*/
511 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
512 /* carrier sense timeout */
513 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400514}
515
516static void ar9003_hw_init_bb(struct ath_hw *ah,
517 struct ath9k_channel *chan)
518{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400519 u32 synthDelay;
520
521 /*
522 * Wait for the frequency synth to settle (synth goes on
523 * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
524 * Value is in 100ns increments.
525 */
526 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
527 if (IS_CHAN_B(chan))
528 synthDelay = (4 * synthDelay) / 22;
529 else
530 synthDelay /= 10;
531
532 /* Activate the PHY (includes baseband activate + synthesizer on) */
533 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
534
535 /*
536 * There is an issue if the AP starts the calibration before
537 * the base band timeout completes. This could result in the
538 * rx_clear false triggering. As a workaround we add delay an
539 * extra BASE_ACTIVATE_DELAY usecs to ensure this condition
540 * does not happen.
541 */
542 udelay(synthDelay + BASE_ACTIVATE_DELAY);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400543}
544
Rajkumar Manoharan56266bf2011-08-13 10:28:13 +0530545static void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400546{
547 switch (rx) {
548 case 0x5:
549 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
550 AR_PHY_SWAP_ALT_CHAIN);
551 case 0x3:
552 case 0x1:
553 case 0x2:
554 case 0x7:
555 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
556 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
557 break;
558 default:
559 break;
560 }
561
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +0530562 if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7))
563 REG_WRITE(ah, AR_SELFGEN_MASK, 0x3);
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530564 else if (AR_SREV_9462(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +0530565 /* xxx only when MCI support is enabled */
566 REG_WRITE(ah, AR_SELFGEN_MASK, 0x3);
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +0530567 else
568 REG_WRITE(ah, AR_SELFGEN_MASK, tx);
569
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400570 if (tx == 0x5) {
571 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
572 AR_PHY_SWAP_ALT_CHAIN);
573 }
574}
575
576/*
577 * Override INI values with chip specific configuration.
578 */
579static void ar9003_hw_override_ini(struct ath_hw *ah)
580{
581 u32 val;
582
583 /*
584 * Set the RX_ABORT and RX_DIS and clear it only after
585 * RXE is set for MAC. This prevents frames with
586 * corrupted descriptor status.
587 */
588 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
589
590 /*
591 * For AR9280 and above, there is a new feature that allows
592 * Multicast search based on both MAC Address and Key ID. By default,
593 * this feature is enabled. But since the driver is not using this
594 * feature, we switch it off; otherwise multicast search based on
595 * MAC addr only will fail.
596 */
597 val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
598 REG_WRITE(ah, AR_PCU_MISC_MODE2,
599 val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
Felix Fietkaubf3f2042011-09-15 14:25:37 +0200600
601 REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
602 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400603}
604
605static void ar9003_hw_prog_ini(struct ath_hw *ah,
606 struct ar5416IniArray *iniArr,
607 int column)
608{
609 unsigned int i, regWrites = 0;
610
611 /* New INI format: Array may be undefined (pre, core, post arrays) */
612 if (!iniArr->ia_array)
613 return;
614
615 /*
616 * New INI format: Pre, core, and post arrays for a given subsystem
617 * may be modal (> 2 columns) or non-modal (2 columns). Determine if
618 * the array is non-modal and force the column to 1.
619 */
620 if (column >= iniArr->ia_columns)
621 column = 1;
622
623 for (i = 0; i < iniArr->ia_rows; i++) {
624 u32 reg = INI_RA(iniArr, i, 0);
625 u32 val = INI_RA(iniArr, i, column);
626
Vasanthakumar Thiagarajan7e68b742010-12-15 07:30:47 -0800627 REG_WRITE(ah, reg, val);
Felix Fietkaub2ccc502010-07-30 21:02:12 +0200628
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400629 DO_DELAY(regWrites);
630 }
631}
632
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400633static int ar9003_hw_process_ini(struct ath_hw *ah,
634 struct ath9k_channel *chan)
635{
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400636 unsigned int regWrites = 0, i;
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +0530637 u32 modesIndex;
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400638
639 switch (chan->chanmode) {
640 case CHANNEL_A:
641 case CHANNEL_A_HT20:
642 modesIndex = 1;
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400643 break;
644 case CHANNEL_A_HT40PLUS:
645 case CHANNEL_A_HT40MINUS:
646 modesIndex = 2;
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400647 break;
648 case CHANNEL_G:
649 case CHANNEL_G_HT20:
650 case CHANNEL_B:
651 modesIndex = 4;
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400652 break;
653 case CHANNEL_G_HT40PLUS:
654 case CHANNEL_G_HT40MINUS:
655 modesIndex = 3;
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400656 break;
657
658 default:
659 return -EINVAL;
660 }
661
662 for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
663 ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
664 ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
665 ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
666 ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530667 if (i == ATH_INI_POST && AR_SREV_9462_20(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +0530668 ar9003_hw_prog_ini(ah,
669 &ah->ini_radio_post_sys2ant,
670 modesIndex);
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400671 }
672
673 REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
674 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
675
676 /*
677 * For 5GHz channels requiring Fast Clock, apply
678 * different modal values.
679 */
Felix Fietkau6b42e8d2010-04-26 15:04:35 -0400680 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400681 REG_WRITE_ARRAY(&ah->iniModesAdditional,
682 modesIndex, regWrites);
683
Rajkumar Manoharan1c1bdd32011-08-26 12:42:11 +0530684 if (AR_SREV_9330(ah))
Gabor Juhos172805a2011-06-21 11:23:26 +0200685 REG_WRITE_ARRAY(&ah->iniModesAdditional, 1, regWrites);
686
Vasanthakumar Thiagarajand89baac2011-04-19 19:29:04 +0530687 if (AR_SREV_9340(ah) && !ah->is_clk_25mhz)
688 REG_WRITE_ARRAY(&ah->iniModesAdditional_40M, 1, regWrites);
689
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530690 if (AR_SREV_9462(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +0530691 ar9003_hw_prog_ini(ah, &ah->ini_BTCOEX_MAX_TXPWR, 1);
692
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +0530693 ah->modes_index = modesIndex;
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400694 ar9003_hw_override_ini(ah);
695 ar9003_hw_set_channel_regs(ah, chan);
696 ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
Felix Fietkauca2c68c2011-10-08 20:06:20 +0200697 ath9k_hw_apply_txpower(ah, chan);
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400698
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530699 if (AR_SREV_9462(ah)) {
Rajkumar Manoharan8ad74c42011-10-13 11:00:38 +0530700 if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
701 AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL))
702 ah->enabled_cals |= TX_IQ_CAL;
703 else
704 ah->enabled_cals &= ~TX_IQ_CAL;
705
706 if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
707 ah->enabled_cals |= TX_CL_CAL;
708 else
709 ah->enabled_cals &= ~TX_CL_CAL;
710 }
711
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400712 return 0;
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400713}
714
715static void ar9003_hw_set_rfmode(struct ath_hw *ah,
716 struct ath9k_channel *chan)
717{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400718 u32 rfMode = 0;
719
720 if (chan == NULL)
721 return;
722
723 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
724 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
725
Felix Fietkau6b42e8d2010-04-26 15:04:35 -0400726 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400727 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
728
729 REG_WRITE(ah, AR_PHY_MODE, rfMode);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400730}
731
732static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
733{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400734 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400735}
736
737static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
738 struct ath9k_channel *chan)
739{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400740 u32 coef_scaled, ds_coef_exp, ds_coef_man;
741 u32 clockMhzScaled = 0x64000000;
742 struct chan_centers centers;
743
744 /*
745 * half and quarter rate can divide the scaled clock by 2 or 4
746 * scale for selected channel bandwidth
747 */
748 if (IS_CHAN_HALF_RATE(chan))
749 clockMhzScaled = clockMhzScaled >> 1;
750 else if (IS_CHAN_QUARTER_RATE(chan))
751 clockMhzScaled = clockMhzScaled >> 2;
752
753 /*
754 * ALGO -> coef = 1e8/fcarrier*fclock/40;
755 * scaled coef to provide precision for this floating calculation
756 */
757 ath9k_hw_get_channel_centers(ah, chan, &centers);
758 coef_scaled = clockMhzScaled / centers.synth_center;
759
760 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
761 &ds_coef_exp);
762
763 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
764 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
765 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
766 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
767
768 /*
769 * For Short GI,
770 * scaled coeff is 9/10 that of normal coeff
771 */
772 coef_scaled = (9 * coef_scaled) / 10;
773
774 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
775 &ds_coef_exp);
776
777 /* for short gi */
778 REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
779 AR_PHY_SGI_DSC_MAN, ds_coef_man);
780 REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
781 AR_PHY_SGI_DSC_EXP, ds_coef_exp);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400782}
783
784static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
785{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400786 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
787 return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
788 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400789}
790
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400791/*
792 * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
793 * Read the phy active delay register. Value is in 100ns increments.
794 */
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400795static void ar9003_hw_rfbus_done(struct ath_hw *ah)
796{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400797 u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
798 if (IS_CHAN_B(ah->curchan))
799 synthDelay = (4 * synthDelay) / 22;
800 else
801 synthDelay /= 10;
802
803 udelay(synthDelay + BASE_ACTIVATE_DELAY);
804
805 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400806}
807
Felix Fietkauc16fcb42010-04-15 17:38:39 -0400808static bool ar9003_hw_ani_control(struct ath_hw *ah,
809 enum ath9k_ani_cmd cmd, int param)
810{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400811 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400812 struct ath9k_channel *chan = ah->curchan;
Felix Fietkau093115b2010-10-04 20:09:47 +0200813 struct ar5416AniState *aniState = &chan->ani;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400814 s32 value, value2;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400815
816 switch (cmd & ah->ani_function) {
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400817 case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400818 /*
819 * on == 1 means ofdm weak signal detection is ON
820 * on == 1 is the default, for less noise immunity
821 *
822 * on == 0 means ofdm weak signal detection is OFF
823 * on == 0 means more noise imm
824 */
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400825 u32 on = param ? 1 : 0;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400826 /*
827 * make register setting for default
828 * (weak sig detect ON) come from INI file
829 */
830 int m1ThreshLow = on ?
831 aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
832 int m2ThreshLow = on ?
833 aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
834 int m1Thresh = on ?
835 aniState->iniDef.m1Thresh : m1Thresh_off;
836 int m2Thresh = on ?
837 aniState->iniDef.m2Thresh : m2Thresh_off;
838 int m2CountThr = on ?
839 aniState->iniDef.m2CountThr : m2CountThr_off;
840 int m2CountThrLow = on ?
841 aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
842 int m1ThreshLowExt = on ?
843 aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
844 int m2ThreshLowExt = on ?
845 aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
846 int m1ThreshExt = on ?
847 aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
848 int m2ThreshExt = on ?
849 aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400850
851 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
852 AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400853 m1ThreshLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400854 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
855 AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400856 m2ThreshLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400857 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400858 AR_PHY_SFCORR_M1_THRESH, m1Thresh);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400859 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400860 AR_PHY_SFCORR_M2_THRESH, m2Thresh);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400861 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400862 AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400863 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
864 AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400865 m2CountThrLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400866
867 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400868 AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400869 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400870 AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400871 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400872 AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400873 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400874 AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400875
876 if (on)
877 REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
878 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
879 else
880 REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
881 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
882
883 if (!on != aniState->ofdmWeakSigDetectOff) {
Joe Perches226afe62010-12-02 19:12:37 -0800884 ath_dbg(common, ATH_DBG_ANI,
885 "** ch %d: ofdm weak signal: %s=>%s\n",
886 chan->channel,
887 !aniState->ofdmWeakSigDetectOff ?
888 "on" : "off",
889 on ? "on" : "off");
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400890 if (on)
891 ah->stats.ast_ani_ofdmon++;
892 else
893 ah->stats.ast_ani_ofdmoff++;
894 aniState->ofdmWeakSigDetectOff = !on;
895 }
896 break;
897 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400898 case ATH9K_ANI_FIRSTEP_LEVEL:{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400899 u32 level = param;
900
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400901 if (level >= ARRAY_SIZE(firstep_table)) {
Joe Perches226afe62010-12-02 19:12:37 -0800902 ath_dbg(common, ATH_DBG_ANI,
903 "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
904 level, ARRAY_SIZE(firstep_table));
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400905 return false;
906 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400907
908 /*
909 * make register setting relative to default
910 * from INI file & cap value
911 */
912 value = firstep_table[level] -
913 firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
914 aniState->iniDef.firstep;
915 if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
916 value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
917 if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
918 value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400919 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
920 AR_PHY_FIND_SIG_FIRSTEP,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400921 value);
922 /*
923 * we need to set first step low register too
924 * make register setting relative to default
925 * from INI file & cap value
926 */
927 value2 = firstep_table[level] -
928 firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
929 aniState->iniDef.firstepLow;
930 if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
931 value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
932 if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
933 value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
934
935 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
936 AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
937
938 if (level != aniState->firstepLevel) {
Joe Perches226afe62010-12-02 19:12:37 -0800939 ath_dbg(common, ATH_DBG_ANI,
940 "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
941 chan->channel,
942 aniState->firstepLevel,
943 level,
944 ATH9K_ANI_FIRSTEP_LVL_NEW,
945 value,
946 aniState->iniDef.firstep);
947 ath_dbg(common, ATH_DBG_ANI,
948 "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
949 chan->channel,
950 aniState->firstepLevel,
951 level,
952 ATH9K_ANI_FIRSTEP_LVL_NEW,
953 value2,
954 aniState->iniDef.firstepLow);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400955 if (level > aniState->firstepLevel)
956 ah->stats.ast_ani_stepup++;
957 else if (level < aniState->firstepLevel)
958 ah->stats.ast_ani_stepdown++;
959 aniState->firstepLevel = level;
960 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400961 break;
962 }
963 case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400964 u32 level = param;
965
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400966 if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
Joe Perches226afe62010-12-02 19:12:37 -0800967 ath_dbg(common, ATH_DBG_ANI,
968 "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
969 level, ARRAY_SIZE(cycpwrThr1_table));
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400970 return false;
971 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400972 /*
973 * make register setting relative to default
974 * from INI file & cap value
975 */
976 value = cycpwrThr1_table[level] -
977 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
978 aniState->iniDef.cycpwrThr1;
979 if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
980 value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
981 if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
982 value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400983 REG_RMW_FIELD(ah, AR_PHY_TIMING5,
984 AR_PHY_TIMING5_CYCPWR_THR1,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400985 value);
986
987 /*
988 * set AR_PHY_EXT_CCA for extension channel
989 * make register setting relative to default
990 * from INI file & cap value
991 */
992 value2 = cycpwrThr1_table[level] -
993 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
994 aniState->iniDef.cycpwrThr1Ext;
995 if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
996 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
997 if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
998 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
999 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
1000 AR_PHY_EXT_CYCPWR_THR1, value2);
1001
1002 if (level != aniState->spurImmunityLevel) {
Joe Perches226afe62010-12-02 19:12:37 -08001003 ath_dbg(common, ATH_DBG_ANI,
1004 "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
1005 chan->channel,
1006 aniState->spurImmunityLevel,
1007 level,
1008 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
1009 value,
1010 aniState->iniDef.cycpwrThr1);
1011 ath_dbg(common, ATH_DBG_ANI,
1012 "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
1013 chan->channel,
1014 aniState->spurImmunityLevel,
1015 level,
1016 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
1017 value2,
1018 aniState->iniDef.cycpwrThr1Ext);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001019 if (level > aniState->spurImmunityLevel)
1020 ah->stats.ast_ani_spurup++;
1021 else if (level < aniState->spurImmunityLevel)
1022 ah->stats.ast_ani_spurdown++;
1023 aniState->spurImmunityLevel = level;
1024 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001025 break;
1026 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001027 case ATH9K_ANI_MRC_CCK:{
1028 /*
1029 * is_on == 1 means MRC CCK ON (default, less noise imm)
1030 * is_on == 0 means MRC CCK is OFF (more noise imm)
1031 */
1032 bool is_on = param ? 1 : 0;
1033 REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
1034 AR_PHY_MRC_CCK_ENABLE, is_on);
1035 REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
1036 AR_PHY_MRC_CCK_MUX_REG, is_on);
1037 if (!is_on != aniState->mrcCCKOff) {
Joe Perches226afe62010-12-02 19:12:37 -08001038 ath_dbg(common, ATH_DBG_ANI,
1039 "** ch %d: MRC CCK: %s=>%s\n",
1040 chan->channel,
1041 !aniState->mrcCCKOff ? "on" : "off",
1042 is_on ? "on" : "off");
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001043 if (is_on)
1044 ah->stats.ast_ani_ccklow++;
1045 else
1046 ah->stats.ast_ani_cckhigh++;
1047 aniState->mrcCCKOff = !is_on;
1048 }
1049 break;
1050 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001051 case ATH9K_ANI_PRESENT:
1052 break;
1053 default:
Joe Perches226afe62010-12-02 19:12:37 -08001054 ath_dbg(common, ATH_DBG_ANI, "invalid cmd %u\n", cmd);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001055 return false;
1056 }
1057
Joe Perches226afe62010-12-02 19:12:37 -08001058 ath_dbg(common, ATH_DBG_ANI,
1059 "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
1060 aniState->spurImmunityLevel,
1061 !aniState->ofdmWeakSigDetectOff ? "on" : "off",
1062 aniState->firstepLevel,
1063 !aniState->mrcCCKOff ? "on" : "off",
1064 aniState->listenTime,
1065 aniState->ofdmPhyErrCount,
1066 aniState->cckPhyErrCount);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001067 return true;
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001068}
1069
Felix Fietkau641d9922010-04-15 17:38:49 -04001070static void ar9003_hw_do_getnf(struct ath_hw *ah,
1071 int16_t nfarray[NUM_NF_READINGS])
1072{
Vasanthakumar Thiagarajanb06af7a2011-03-01 08:59:36 -08001073#define AR_PHY_CH_MINCCA_PWR 0x1FF00000
1074#define AR_PHY_CH_MINCCA_PWR_S 20
1075#define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
1076#define AR_PHY_CH_EXT_MINCCA_PWR_S 16
1077
Felix Fietkau641d9922010-04-15 17:38:49 -04001078 int16_t nf;
Vasanthakumar Thiagarajanb06af7a2011-03-01 08:59:36 -08001079 int i;
Felix Fietkau641d9922010-04-15 17:38:49 -04001080
Vasanthakumar Thiagarajanb06af7a2011-03-01 08:59:36 -08001081 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
1082 if (ah->rxchainmask & BIT(i)) {
1083 nf = MS(REG_READ(ah, ah->nf_regs[i]),
1084 AR_PHY_CH_MINCCA_PWR);
1085 nfarray[i] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001086
Vasanthakumar Thiagarajanb06af7a2011-03-01 08:59:36 -08001087 if (IS_CHAN_HT40(ah->curchan)) {
1088 u8 ext_idx = AR9300_MAX_CHAINS + i;
Felix Fietkau641d9922010-04-15 17:38:49 -04001089
Vasanthakumar Thiagarajanb06af7a2011-03-01 08:59:36 -08001090 nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
1091 AR_PHY_CH_EXT_MINCCA_PWR);
1092 nfarray[ext_idx] = sign_extend32(nf, 8);
1093 }
1094 }
1095 }
Felix Fietkau641d9922010-04-15 17:38:49 -04001096}
1097
Felix Fietkauf2552e22010-07-02 00:09:50 +02001098static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
Felix Fietkau641d9922010-04-15 17:38:49 -04001099{
Felix Fietkauf2552e22010-07-02 00:09:50 +02001100 ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
1101 ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
Gabor Juhos0c453732011-06-21 11:23:40 +02001102 if (AR_SREV_9330(ah))
1103 ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9330_2GHZ;
1104 else
1105 ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
Felix Fietkauf2552e22010-07-02 00:09:50 +02001106 ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
1107 ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
1108 ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
Felix Fietkau641d9922010-04-15 17:38:49 -04001109}
1110
Luis R. Rodriguezdf23aca2010-04-15 17:39:11 -04001111/*
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001112 * Initialize the ANI register values with default (ini) values.
1113 * This routine is called during a (full) hardware reset after
1114 * all the registers are initialised from the INI.
1115 */
1116static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
1117{
1118 struct ar5416AniState *aniState;
1119 struct ath_common *common = ath9k_hw_common(ah);
1120 struct ath9k_channel *chan = ah->curchan;
1121 struct ath9k_ani_default *iniDef;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001122 u32 val;
1123
Felix Fietkau093115b2010-10-04 20:09:47 +02001124 aniState = &ah->curchan->ani;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001125 iniDef = &aniState->iniDef;
1126
Joe Perches226afe62010-12-02 19:12:37 -08001127 ath_dbg(common, ATH_DBG_ANI,
1128 "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
1129 ah->hw_version.macVersion,
1130 ah->hw_version.macRev,
1131 ah->opmode,
1132 chan->channel,
1133 chan->channelFlags);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001134
1135 val = REG_READ(ah, AR_PHY_SFCORR);
1136 iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
1137 iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
1138 iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
1139
1140 val = REG_READ(ah, AR_PHY_SFCORR_LOW);
1141 iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
1142 iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
1143 iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
1144
1145 val = REG_READ(ah, AR_PHY_SFCORR_EXT);
1146 iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
1147 iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
1148 iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
1149 iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
1150 iniDef->firstep = REG_READ_FIELD(ah,
1151 AR_PHY_FIND_SIG,
1152 AR_PHY_FIND_SIG_FIRSTEP);
1153 iniDef->firstepLow = REG_READ_FIELD(ah,
1154 AR_PHY_FIND_SIG_LOW,
1155 AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
1156 iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
1157 AR_PHY_TIMING5,
1158 AR_PHY_TIMING5_CYCPWR_THR1);
1159 iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
1160 AR_PHY_EXT_CCA,
1161 AR_PHY_EXT_CYCPWR_THR1);
1162
1163 /* these levels just got reset to defaults by the INI */
1164 aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
1165 aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
1166 aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
1167 aniState->mrcCCKOff = !ATH9K_ANI_ENABLE_MRC_CCK;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001168}
1169
Felix Fietkau4e8c14e2010-11-11 03:18:38 +01001170static void ar9003_hw_set_radar_params(struct ath_hw *ah,
1171 struct ath_hw_radar_conf *conf)
1172{
1173 u32 radar_0 = 0, radar_1 = 0;
1174
1175 if (!conf) {
1176 REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
1177 return;
1178 }
1179
1180 radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
1181 radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
1182 radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
1183 radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
1184 radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
1185 radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
1186
1187 radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
1188 radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
1189 radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
1190 radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
1191 radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
1192
1193 REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
1194 REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
1195 if (conf->ext_channel)
1196 REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
1197 else
1198 REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
1199}
1200
Felix Fietkauc5d08552010-11-13 20:22:41 +01001201static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
1202{
1203 struct ath_hw_radar_conf *conf = &ah->radar_conf;
1204
1205 conf->fir_power = -28;
1206 conf->radar_rssi = 0;
1207 conf->pulse_height = 10;
1208 conf->pulse_rssi = 24;
1209 conf->pulse_inband = 8;
1210 conf->pulse_maxlen = 255;
1211 conf->pulse_inband_step = 12;
1212 conf->radar_inband = 8;
1213}
1214
Mohammed Shafi Shajakhan6bcbc062011-05-13 20:30:41 +05301215static void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah,
1216 struct ath_hw_antcomb_conf *antconf)
1217{
1218 u32 regval;
1219
1220 regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
1221 antconf->main_lna_conf = (regval & AR_PHY_9485_ANT_DIV_MAIN_LNACONF) >>
1222 AR_PHY_9485_ANT_DIV_MAIN_LNACONF_S;
1223 antconf->alt_lna_conf = (regval & AR_PHY_9485_ANT_DIV_ALT_LNACONF) >>
1224 AR_PHY_9485_ANT_DIV_ALT_LNACONF_S;
1225 antconf->fast_div_bias = (regval & AR_PHY_9485_ANT_FAST_DIV_BIAS) >>
1226 AR_PHY_9485_ANT_FAST_DIV_BIAS_S;
Gabor Juhoscd0ed1b2011-06-21 11:23:44 +02001227
Gabor Juhosc4cf2c52011-06-21 11:23:47 +02001228 if (AR_SREV_9330_11(ah)) {
1229 antconf->lna1_lna2_delta = -9;
1230 antconf->div_group = 1;
1231 } else if (AR_SREV_9485(ah)) {
Gabor Juhoscd0ed1b2011-06-21 11:23:44 +02001232 antconf->lna1_lna2_delta = -9;
1233 antconf->div_group = 2;
1234 } else {
1235 antconf->lna1_lna2_delta = -3;
1236 antconf->div_group = 0;
1237 }
Mohammed Shafi Shajakhan6bcbc062011-05-13 20:30:41 +05301238}
1239
1240static void ar9003_hw_antdiv_comb_conf_set(struct ath_hw *ah,
1241 struct ath_hw_antcomb_conf *antconf)
1242{
1243 u32 regval;
1244
1245 regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
1246 regval &= ~(AR_PHY_9485_ANT_DIV_MAIN_LNACONF |
1247 AR_PHY_9485_ANT_DIV_ALT_LNACONF |
1248 AR_PHY_9485_ANT_FAST_DIV_BIAS |
1249 AR_PHY_9485_ANT_DIV_MAIN_GAINTB |
1250 AR_PHY_9485_ANT_DIV_ALT_GAINTB);
1251 regval |= ((antconf->main_lna_conf <<
1252 AR_PHY_9485_ANT_DIV_MAIN_LNACONF_S)
1253 & AR_PHY_9485_ANT_DIV_MAIN_LNACONF);
1254 regval |= ((antconf->alt_lna_conf << AR_PHY_9485_ANT_DIV_ALT_LNACONF_S)
1255 & AR_PHY_9485_ANT_DIV_ALT_LNACONF);
1256 regval |= ((antconf->fast_div_bias << AR_PHY_9485_ANT_FAST_DIV_BIAS_S)
1257 & AR_PHY_9485_ANT_FAST_DIV_BIAS);
1258 regval |= ((antconf->main_gaintb << AR_PHY_9485_ANT_DIV_MAIN_GAINTB_S)
1259 & AR_PHY_9485_ANT_DIV_MAIN_GAINTB);
1260 regval |= ((antconf->alt_gaintb << AR_PHY_9485_ANT_DIV_ALT_GAINTB_S)
1261 & AR_PHY_9485_ANT_DIV_ALT_GAINTB);
1262
1263 REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
1264}
1265
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301266static int ar9003_hw_fast_chan_change(struct ath_hw *ah,
1267 struct ath9k_channel *chan,
1268 u8 *ini_reloaded)
1269{
1270 unsigned int regWrites = 0;
1271 u32 modesIndex;
1272
1273 switch (chan->chanmode) {
1274 case CHANNEL_A:
1275 case CHANNEL_A_HT20:
1276 modesIndex = 1;
1277 break;
1278 case CHANNEL_A_HT40PLUS:
1279 case CHANNEL_A_HT40MINUS:
1280 modesIndex = 2;
1281 break;
1282 case CHANNEL_G:
1283 case CHANNEL_G_HT20:
1284 case CHANNEL_B:
1285 modesIndex = 4;
1286 break;
1287 case CHANNEL_G_HT40PLUS:
1288 case CHANNEL_G_HT40MINUS:
1289 modesIndex = 3;
1290 break;
1291
1292 default:
1293 return -EINVAL;
1294 }
1295
1296 if (modesIndex == ah->modes_index) {
1297 *ini_reloaded = false;
1298 goto set_rfmode;
1299 }
1300
1301 ar9003_hw_prog_ini(ah, &ah->iniSOC[ATH_INI_POST], modesIndex);
1302 ar9003_hw_prog_ini(ah, &ah->iniMac[ATH_INI_POST], modesIndex);
1303 ar9003_hw_prog_ini(ah, &ah->iniBB[ATH_INI_POST], modesIndex);
1304 ar9003_hw_prog_ini(ah, &ah->iniRadio[ATH_INI_POST], modesIndex);
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05301305 if (AR_SREV_9462_20(ah))
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301306 ar9003_hw_prog_ini(ah,
1307 &ah->ini_radio_post_sys2ant,
1308 modesIndex);
1309
1310 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
1311
1312 /*
1313 * For 5GHz channels requiring Fast Clock, apply
1314 * different modal values.
1315 */
1316 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1317 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex, regWrites);
1318
1319 if (AR_SREV_9330(ah))
1320 REG_WRITE_ARRAY(&ah->iniModesAdditional, 1, regWrites);
1321
1322 if (AR_SREV_9340(ah) && !ah->is_clk_25mhz)
1323 REG_WRITE_ARRAY(&ah->iniModesAdditional_40M, 1, regWrites);
1324
1325 ah->modes_index = modesIndex;
1326 *ini_reloaded = true;
1327
1328set_rfmode:
1329 ar9003_hw_set_rfmode(ah, chan);
1330 return 0;
1331}
1332
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001333void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
1334{
1335 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
Mohammed Shafi Shajakhan6bcbc062011-05-13 20:30:41 +05301336 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
Joe Perches07b2fa52010-11-20 18:38:53 -08001337 static const u32 ar9300_cca_regs[6] = {
Felix Fietkaubbacee12010-07-11 15:44:42 +02001338 AR_PHY_CCA_0,
1339 AR_PHY_CCA_1,
1340 AR_PHY_CCA_2,
1341 AR_PHY_EXT_CCA,
1342 AR_PHY_EXT_CCA_1,
1343 AR_PHY_EXT_CCA_2,
1344 };
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001345
1346 priv_ops->rf_set_freq = ar9003_hw_set_channel;
1347 priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
1348 priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
1349 priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
1350 priv_ops->init_bb = ar9003_hw_init_bb;
1351 priv_ops->process_ini = ar9003_hw_process_ini;
1352 priv_ops->set_rfmode = ar9003_hw_set_rfmode;
1353 priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
1354 priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
1355 priv_ops->rfbus_req = ar9003_hw_rfbus_req;
1356 priv_ops->rfbus_done = ar9003_hw_rfbus_done;
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001357 priv_ops->ani_control = ar9003_hw_ani_control;
Felix Fietkau641d9922010-04-15 17:38:49 -04001358 priv_ops->do_getnf = ar9003_hw_do_getnf;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001359 priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
Felix Fietkau4e8c14e2010-11-11 03:18:38 +01001360 priv_ops->set_radar_params = ar9003_hw_set_radar_params;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301361 priv_ops->fast_chan_change = ar9003_hw_fast_chan_change;
Felix Fietkauf2552e22010-07-02 00:09:50 +02001362
Mohammed Shafi Shajakhan6bcbc062011-05-13 20:30:41 +05301363 ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get;
1364 ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set;
1365
Felix Fietkauf2552e22010-07-02 00:09:50 +02001366 ar9003_hw_set_nf_limits(ah);
Felix Fietkauc5d08552010-11-13 20:22:41 +01001367 ar9003_hw_set_radar_conf(ah);
Felix Fietkaubbacee12010-07-11 15:44:42 +02001368 memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001369}
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001370
1371void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
1372{
1373 struct ath_common *common = ath9k_hw_common(ah);
1374 u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
1375 u32 val, idle_count;
1376
1377 if (!idle_tmo_ms) {
1378 /* disable IRQ, disable chip-reset for BB panic */
1379 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
1380 REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
1381 ~(AR_PHY_WATCHDOG_RST_ENABLE |
1382 AR_PHY_WATCHDOG_IRQ_ENABLE));
1383
1384 /* disable watchdog in non-IDLE mode, disable in IDLE mode */
1385 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
1386 REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
1387 ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
1388 AR_PHY_WATCHDOG_IDLE_ENABLE));
1389
Joe Perches226afe62010-12-02 19:12:37 -08001390 ath_dbg(common, ATH_DBG_RESET, "Disabled BB Watchdog\n");
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001391 return;
1392 }
1393
1394 /* enable IRQ, disable chip-reset for BB watchdog */
1395 val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
1396 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
1397 (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
1398 ~AR_PHY_WATCHDOG_RST_ENABLE);
1399
1400 /* bound limit to 10 secs */
1401 if (idle_tmo_ms > 10000)
1402 idle_tmo_ms = 10000;
1403
1404 /*
1405 * The time unit for watchdog event is 2^15 44/88MHz cycles.
1406 *
1407 * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
1408 * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
1409 *
1410 * Given we use fast clock now in 5 GHz, these time units should
1411 * be common for both 2 GHz and 5 GHz.
1412 */
1413 idle_count = (100 * idle_tmo_ms) / 74;
1414 if (ah->curchan && IS_CHAN_HT40(ah->curchan))
1415 idle_count = (100 * idle_tmo_ms) / 37;
1416
1417 /*
1418 * enable watchdog in non-IDLE mode, disable in IDLE mode,
1419 * set idle time-out.
1420 */
1421 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
1422 AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
1423 AR_PHY_WATCHDOG_IDLE_MASK |
1424 (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
1425
Joe Perches226afe62010-12-02 19:12:37 -08001426 ath_dbg(common, ATH_DBG_RESET,
1427 "Enabled BB Watchdog timeout (%u ms)\n",
1428 idle_tmo_ms);
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001429}
1430
1431void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
1432{
1433 /*
1434 * we want to avoid printing in ISR context so we save the
1435 * watchdog status to be printed later in bottom half context.
1436 */
1437 ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
1438
1439 /*
1440 * the watchdog timer should reset on status read but to be sure
1441 * sure we write 0 to the watchdog status bit.
1442 */
1443 REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
1444 ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
1445}
1446
1447void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
1448{
1449 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau9dbebc72010-10-03 19:07:17 +02001450 u32 status;
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001451
1452 if (likely(!(common->debug_mask & ATH_DBG_RESET)))
1453 return;
1454
1455 status = ah->bb_watchdog_last_status;
Joe Perches226afe62010-12-02 19:12:37 -08001456 ath_dbg(common, ATH_DBG_RESET,
1457 "\n==== BB update: BB status=0x%08x ====\n", status);
1458 ath_dbg(common, ATH_DBG_RESET,
1459 "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
1460 MS(status, AR_PHY_WATCHDOG_INFO),
1461 MS(status, AR_PHY_WATCHDOG_DET_HANG),
1462 MS(status, AR_PHY_WATCHDOG_RADAR_SM),
1463 MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
1464 MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
1465 MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
1466 MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
1467 MS(status, AR_PHY_WATCHDOG_AGC_SM),
1468 MS(status, AR_PHY_WATCHDOG_SRCH_SM));
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001469
Joe Perches226afe62010-12-02 19:12:37 -08001470 ath_dbg(common, ATH_DBG_RESET,
1471 "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
1472 REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
1473 REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
1474 ath_dbg(common, ATH_DBG_RESET,
1475 "** BB mode: BB_gen_controls=0x%08x **\n",
1476 REG_READ(ah, AR_PHY_GEN_CTRL));
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001477
Felix Fietkaub5bfc562010-10-08 22:13:53 +02001478#define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
1479 if (common->cc_survey.cycles)
Joe Perches226afe62010-12-02 19:12:37 -08001480 ath_dbg(common, ATH_DBG_RESET,
1481 "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
1482 PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001483
Joe Perches226afe62010-12-02 19:12:37 -08001484 ath_dbg(common, ATH_DBG_RESET,
1485 "==== BB update: done ====\n\n");
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001486}
1487EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05301488
1489void ar9003_hw_disable_phy_restart(struct ath_hw *ah)
1490{
1491 u32 val;
1492
1493 /* While receiving unsupported rate frame rx state machine
1494 * gets into a state 0xb and if phy_restart happens in that
1495 * state, BB would go hang. If RXSM is in 0xb state after
1496 * first bb panic, ensure to disable the phy_restart.
1497 */
1498 if (!((MS(ah->bb_watchdog_last_status,
1499 AR_PHY_WATCHDOG_RX_OFDM_SM) == 0xb) ||
1500 ah->bb_hang_rx_ofdm))
1501 return;
1502
1503 ah->bb_hang_rx_ofdm = true;
1504 val = REG_READ(ah, AR_PHY_RESTART);
1505 val &= ~AR_PHY_RESTART_ENA;
1506
1507 REG_WRITE(ah, AR_PHY_RESTART, val);
1508}
1509EXPORT_SYMBOL(ar9003_hw_disable_phy_restart);