blob: c4d08058d40bb523a4c3827bb40a4d95d79d2db0 [file] [log] [blame]
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001/*
2 * Copyright (c) 2010 Atheros Communications Inc.
3 *
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 */
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +053078 if (AR_SREV_9485(ah)) {
79 u32 chan_frac;
80
81 /*
82 * freq_ref = 40 / (refdiva >> amoderefsel); where refdiva=1 and amoderefsel=0
83 * ndiv = ((chan_mhz * 4) / 3) / freq_ref;
84 * chansel = int(ndiv), chanfrac = (ndiv - chansel) * 0x20000
85 */
86 channelSel = (freq * 4) / 120;
87 chan_frac = (((freq * 4) % 120) * 0x20000) / 120;
88 channelSel = (channelSel << 17) | chan_frac;
89 } else
Vasanthakumar Thiagarajan85dd0922010-12-06 04:27:45 -080090 channelSel = CHANSEL_2G(freq);
Felix Fietkauf7abf0c2010-04-15 17:38:33 -040091 /* Set to 2G mode */
92 bMode = 1;
93 } else {
94 channelSel = CHANSEL_5G(freq);
95 /* Doubler is ON, so, divide channelSel by 2. */
96 channelSel >>= 1;
97 /* Set to 5G mode */
98 bMode = 0;
99 }
100
101 /* Enable fractional mode for all channels */
102 fracMode = 1;
103 aModeRefSel = 0;
104 loadSynthChannel = 0;
105
106 reg32 = (bMode << 29);
107 REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
108
109 /* Enable Long shift Select for Synthesizer */
110 REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
111 AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
112
113 /* Program Synth. setting */
114 reg32 = (channelSel << 2) | (fracMode << 30) |
115 (aModeRefSel << 28) | (loadSynthChannel << 31);
116 REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
117
118 /* Toggle Load Synth channel bit */
119 loadSynthChannel = 1;
120 reg32 = (channelSel << 2) | (fracMode << 30) |
121 (aModeRefSel << 28) | (loadSynthChannel << 31);
122 REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
123
124 ah->curchan = chan;
125 ah->curchan_rad_index = -1;
126
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400127 return 0;
128}
129
130/**
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400131 * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400132 * @ah: atheros hardware structure
133 * @chan:
134 *
135 * For single-chip solutions. Converts to baseband spur frequency given the
136 * input channel frequency and compute register settings below.
137 *
138 * Spur mitigation for MRC CCK
139 */
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400140static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
141 struct ath9k_channel *chan)
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400142{
Joe Perches07b2fa52010-11-20 18:38:53 -0800143 static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
Felix Fietkauca375552010-04-15 17:38:35 -0400144 int cur_bb_spur, negative = 0, cck_spur_freq;
145 int i;
Vasanthakumar Thiagarajand9a25452010-12-06 04:27:47 -0800146 int range, max_spur_cnts, synth_freq;
147 u8 *spur_fbin_ptr = NULL;
Felix Fietkauca375552010-04-15 17:38:35 -0400148
149 /*
150 * Need to verify range +/- 10 MHz in control channel, otherwise spur
151 * is out-of-band and can be ignored.
152 */
153
Vasanthakumar Thiagarajand9a25452010-12-06 04:27:47 -0800154 if (AR_SREV_9485(ah)) {
155 spur_fbin_ptr = ar9003_get_spur_chan_ptr(ah,
156 IS_CHAN_2GHZ(chan));
157 if (spur_fbin_ptr[0] == 0) /* No spur */
158 return;
159 max_spur_cnts = 5;
160 if (IS_CHAN_HT40(chan)) {
161 range = 19;
162 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
163 AR_PHY_GC_DYN2040_PRI_CH) == 0)
164 synth_freq = chan->channel + 10;
165 else
166 synth_freq = chan->channel - 10;
167 } else {
168 range = 10;
169 synth_freq = chan->channel;
170 }
171 } else {
172 range = 10;
173 max_spur_cnts = 4;
174 synth_freq = chan->channel;
175 }
176
177 for (i = 0; i < max_spur_cnts; i++) {
Felix Fietkauca375552010-04-15 17:38:35 -0400178 negative = 0;
Vasanthakumar Thiagarajand9a25452010-12-06 04:27:47 -0800179 if (AR_SREV_9485(ah))
180 cur_bb_spur = FBIN2FREQ(spur_fbin_ptr[i],
181 IS_CHAN_2GHZ(chan)) - synth_freq;
182 else
183 cur_bb_spur = spur_freq[i] - synth_freq;
Felix Fietkauca375552010-04-15 17:38:35 -0400184
185 if (cur_bb_spur < 0) {
186 negative = 1;
187 cur_bb_spur = -cur_bb_spur;
188 }
Vasanthakumar Thiagarajand9a25452010-12-06 04:27:47 -0800189 if (cur_bb_spur < range) {
Felix Fietkauca375552010-04-15 17:38:35 -0400190 cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
191
192 if (negative == 1)
193 cck_spur_freq = -cck_spur_freq;
194
195 cck_spur_freq = cck_spur_freq & 0xfffff;
196
197 REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
198 AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
199 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
200 AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
201 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
202 AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
203 0x2);
204 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
205 AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
206 0x1);
207 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
208 AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
209 cck_spur_freq);
210
211 return;
212 }
213 }
214
215 REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
216 AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
217 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
218 AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
219 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
220 AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400221}
222
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400223/* Clean all spur register fields */
224static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
225{
226 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
227 AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
228 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
229 AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
230 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
231 AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
232 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
233 AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
234 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
235 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
236 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
237 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
238 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
239 AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
240 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
241 AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
242 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
243 AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
244
245 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
246 AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
247 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
248 AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
249 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
250 AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
251 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
252 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
253 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
254 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
255 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
256 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
257 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
258 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
259 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
260 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
261 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
262 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
263 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
264 AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
265}
266
267static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
268 int freq_offset,
269 int spur_freq_sd,
270 int spur_delta_phase,
271 int spur_subchannel_sd)
272{
273 int mask_index = 0;
274
275 /* OFDM Spur mitigation */
276 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
277 AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
278 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
279 AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
280 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
281 AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
282 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
283 AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
284 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
285 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
286 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
287 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
288 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
289 AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
290 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
291 AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
292 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
293 AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
294
295 if (REG_READ_FIELD(ah, AR_PHY_MODE,
296 AR_PHY_MODE_DYNAMIC) == 0x1)
297 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
298 AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
299
300 mask_index = (freq_offset << 4) / 5;
301 if (mask_index < 0)
302 mask_index = mask_index - 1;
303
304 mask_index = mask_index & 0x7f;
305
306 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
307 AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
308 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
309 AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
310 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
311 AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
312 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
313 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
314 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
315 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
316 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
317 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
318 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
319 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
320 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
321 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
322 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
323 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
324 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
325 AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
326}
327
328static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
329 struct ath9k_channel *chan,
330 int freq_offset)
331{
332 int spur_freq_sd = 0;
333 int spur_subchannel_sd = 0;
334 int spur_delta_phase = 0;
335
336 if (IS_CHAN_HT40(chan)) {
337 if (freq_offset < 0) {
338 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
339 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
340 spur_subchannel_sd = 1;
341 else
342 spur_subchannel_sd = 0;
343
344 spur_freq_sd = ((freq_offset + 10) << 9) / 11;
345
346 } else {
347 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
348 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
349 spur_subchannel_sd = 0;
350 else
351 spur_subchannel_sd = 1;
352
353 spur_freq_sd = ((freq_offset - 10) << 9) / 11;
354
355 }
356
357 spur_delta_phase = (freq_offset << 17) / 5;
358
359 } else {
360 spur_subchannel_sd = 0;
361 spur_freq_sd = (freq_offset << 9) /11;
362 spur_delta_phase = (freq_offset << 18) / 5;
363 }
364
365 spur_freq_sd = spur_freq_sd & 0x3ff;
366 spur_delta_phase = spur_delta_phase & 0xfffff;
367
368 ar9003_hw_spur_ofdm(ah,
369 freq_offset,
370 spur_freq_sd,
371 spur_delta_phase,
372 spur_subchannel_sd);
373}
374
375/* Spur mitigation for OFDM */
376static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
377 struct ath9k_channel *chan)
378{
379 int synth_freq;
380 int range = 10;
381 int freq_offset = 0;
382 int mode;
383 u8* spurChansPtr;
384 unsigned int i;
385 struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
386
387 if (IS_CHAN_5GHZ(chan)) {
388 spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
389 mode = 0;
390 }
391 else {
392 spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
393 mode = 1;
394 }
395
396 if (spurChansPtr[0] == 0)
397 return; /* No spur in the mode */
398
399 if (IS_CHAN_HT40(chan)) {
400 range = 19;
401 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
402 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
403 synth_freq = chan->channel - 10;
404 else
405 synth_freq = chan->channel + 10;
406 } else {
407 range = 10;
408 synth_freq = chan->channel;
409 }
410
411 ar9003_hw_spur_ofdm_clear(ah);
412
roel0f8e94d2011-04-10 21:09:50 +0200413 for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) {
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400414 freq_offset = FBIN2FREQ(spurChansPtr[i], mode) - synth_freq;
415 if (abs(freq_offset) < range) {
416 ar9003_hw_spur_ofdm_work(ah, chan, freq_offset);
417 break;
418 }
419 }
420}
421
422static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
423 struct ath9k_channel *chan)
424{
425 ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
426 ar9003_hw_spur_mitigate_ofdm(ah, chan);
427}
428
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400429static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
430 struct ath9k_channel *chan)
431{
Felix Fietkau317d3322010-04-15 17:38:34 -0400432 u32 pll;
433
434 pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
435
436 if (chan && IS_CHAN_HALF_RATE(chan))
437 pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
438 else if (chan && IS_CHAN_QUARTER_RATE(chan))
439 pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
440
Felix Fietkau14bc1102010-04-26 15:04:30 -0400441 pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
Felix Fietkau317d3322010-04-15 17:38:34 -0400442
443 return pll;
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400444}
445
446static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
447 struct ath9k_channel *chan)
448{
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400449 u32 phymode;
450 u32 enableDacFifo = 0;
451
452 enableDacFifo =
453 (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
454
455 /* Enable 11n HT, 20 MHz */
456 phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 | AR_PHY_GC_WALSH |
457 AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
458
459 /* Configure baseband for dynamic 20/40 operation */
460 if (IS_CHAN_HT40(chan)) {
461 phymode |= AR_PHY_GC_DYN2040_EN;
462 /* Configure control (primary) channel at +-10MHz */
463 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
464 (chan->chanmode == CHANNEL_G_HT40PLUS))
465 phymode |= AR_PHY_GC_DYN2040_PRI_CH;
466
467 }
468
469 /* make sure we preserve INI settings */
470 phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
471 /* turn off Green Field detection for STA for now */
472 phymode &= ~AR_PHY_GC_GF_DETECT_EN;
473
474 REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
475
476 /* Configure MAC for 20/40 operation */
477 ath9k_hw_set11nmac2040(ah);
478
479 /* global transmit timeout (25 TUs default)*/
480 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
481 /* carrier sense timeout */
482 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400483}
484
485static void ar9003_hw_init_bb(struct ath_hw *ah,
486 struct ath9k_channel *chan)
487{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400488 u32 synthDelay;
489
490 /*
491 * Wait for the frequency synth to settle (synth goes on
492 * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
493 * Value is in 100ns increments.
494 */
495 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
496 if (IS_CHAN_B(chan))
497 synthDelay = (4 * synthDelay) / 22;
498 else
499 synthDelay /= 10;
500
501 /* Activate the PHY (includes baseband activate + synthesizer on) */
502 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
503
504 /*
505 * There is an issue if the AP starts the calibration before
506 * the base band timeout completes. This could result in the
507 * rx_clear false triggering. As a workaround we add delay an
508 * extra BASE_ACTIVATE_DELAY usecs to ensure this condition
509 * does not happen.
510 */
511 udelay(synthDelay + BASE_ACTIVATE_DELAY);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400512}
513
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400514void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
515{
516 switch (rx) {
517 case 0x5:
518 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
519 AR_PHY_SWAP_ALT_CHAIN);
520 case 0x3:
521 case 0x1:
522 case 0x2:
523 case 0x7:
524 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
525 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
526 break;
527 default:
528 break;
529 }
530
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +0530531 if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7))
532 REG_WRITE(ah, AR_SELFGEN_MASK, 0x3);
533 else
534 REG_WRITE(ah, AR_SELFGEN_MASK, tx);
535
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400536 if (tx == 0x5) {
537 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
538 AR_PHY_SWAP_ALT_CHAIN);
539 }
540}
541
542/*
543 * Override INI values with chip specific configuration.
544 */
545static void ar9003_hw_override_ini(struct ath_hw *ah)
546{
547 u32 val;
548
549 /*
550 * Set the RX_ABORT and RX_DIS and clear it only after
551 * RXE is set for MAC. This prevents frames with
552 * corrupted descriptor status.
553 */
554 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
555
556 /*
557 * For AR9280 and above, there is a new feature that allows
558 * Multicast search based on both MAC Address and Key ID. By default,
559 * this feature is enabled. But since the driver is not using this
560 * feature, we switch it off; otherwise multicast search based on
561 * MAC addr only will fail.
562 */
563 val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
564 REG_WRITE(ah, AR_PCU_MISC_MODE2,
565 val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
566}
567
568static void ar9003_hw_prog_ini(struct ath_hw *ah,
569 struct ar5416IniArray *iniArr,
570 int column)
571{
572 unsigned int i, regWrites = 0;
573
574 /* New INI format: Array may be undefined (pre, core, post arrays) */
575 if (!iniArr->ia_array)
576 return;
577
578 /*
579 * New INI format: Pre, core, and post arrays for a given subsystem
580 * may be modal (> 2 columns) or non-modal (2 columns). Determine if
581 * the array is non-modal and force the column to 1.
582 */
583 if (column >= iniArr->ia_columns)
584 column = 1;
585
586 for (i = 0; i < iniArr->ia_rows; i++) {
587 u32 reg = INI_RA(iniArr, i, 0);
588 u32 val = INI_RA(iniArr, i, column);
589
Vasanthakumar Thiagarajan7e68b742010-12-15 07:30:47 -0800590 REG_WRITE(ah, reg, val);
Felix Fietkaub2ccc502010-07-30 21:02:12 +0200591
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400592 DO_DELAY(regWrites);
593 }
594}
595
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400596static int ar9003_hw_process_ini(struct ath_hw *ah,
597 struct ath9k_channel *chan)
598{
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400599 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
600 unsigned int regWrites = 0, i;
601 struct ieee80211_channel *channel = chan->chan;
602 u32 modesIndex, freqIndex;
603
604 switch (chan->chanmode) {
605 case CHANNEL_A:
606 case CHANNEL_A_HT20:
607 modesIndex = 1;
608 freqIndex = 1;
609 break;
610 case CHANNEL_A_HT40PLUS:
611 case CHANNEL_A_HT40MINUS:
612 modesIndex = 2;
613 freqIndex = 1;
614 break;
615 case CHANNEL_G:
616 case CHANNEL_G_HT20:
617 case CHANNEL_B:
618 modesIndex = 4;
619 freqIndex = 2;
620 break;
621 case CHANNEL_G_HT40PLUS:
622 case CHANNEL_G_HT40MINUS:
623 modesIndex = 3;
624 freqIndex = 2;
625 break;
626
627 default:
628 return -EINVAL;
629 }
630
631 for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
632 ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
633 ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
634 ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
635 ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
636 }
637
638 REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
639 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
640
641 /*
642 * For 5GHz channels requiring Fast Clock, apply
643 * different modal values.
644 */
Felix Fietkau6b42e8d2010-04-26 15:04:35 -0400645 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400646 REG_WRITE_ARRAY(&ah->iniModesAdditional,
647 modesIndex, regWrites);
648
Vasanthakumar Thiagarajand89baac2011-04-19 19:29:04 +0530649 if (AR_SREV_9340(ah) && !ah->is_clk_25mhz)
650 REG_WRITE_ARRAY(&ah->iniModesAdditional_40M, 1, regWrites);
651
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400652 ar9003_hw_override_ini(ah);
653 ar9003_hw_set_channel_regs(ah, chan);
654 ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
655
656 /* Set TX power */
657 ah->eep_ops->set_txpower(ah, chan,
658 ath9k_regd_get_ctl(regulatory, chan),
659 channel->max_antenna_gain * 2,
660 channel->max_power * 2,
661 min((u32) MAX_RATE_POWER,
Felix Fietkaude40f312010-10-20 03:08:53 +0200662 (u32) regulatory->power_limit), false);
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400663
664 return 0;
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400665}
666
667static void ar9003_hw_set_rfmode(struct ath_hw *ah,
668 struct ath9k_channel *chan)
669{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400670 u32 rfMode = 0;
671
672 if (chan == NULL)
673 return;
674
675 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
676 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
677
Felix Fietkau6b42e8d2010-04-26 15:04:35 -0400678 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400679 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
680
681 REG_WRITE(ah, AR_PHY_MODE, rfMode);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400682}
683
684static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
685{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400686 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400687}
688
689static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
690 struct ath9k_channel *chan)
691{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400692 u32 coef_scaled, ds_coef_exp, ds_coef_man;
693 u32 clockMhzScaled = 0x64000000;
694 struct chan_centers centers;
695
696 /*
697 * half and quarter rate can divide the scaled clock by 2 or 4
698 * scale for selected channel bandwidth
699 */
700 if (IS_CHAN_HALF_RATE(chan))
701 clockMhzScaled = clockMhzScaled >> 1;
702 else if (IS_CHAN_QUARTER_RATE(chan))
703 clockMhzScaled = clockMhzScaled >> 2;
704
705 /*
706 * ALGO -> coef = 1e8/fcarrier*fclock/40;
707 * scaled coef to provide precision for this floating calculation
708 */
709 ath9k_hw_get_channel_centers(ah, chan, &centers);
710 coef_scaled = clockMhzScaled / centers.synth_center;
711
712 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
713 &ds_coef_exp);
714
715 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
716 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
717 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
718 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
719
720 /*
721 * For Short GI,
722 * scaled coeff is 9/10 that of normal coeff
723 */
724 coef_scaled = (9 * coef_scaled) / 10;
725
726 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
727 &ds_coef_exp);
728
729 /* for short gi */
730 REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
731 AR_PHY_SGI_DSC_MAN, ds_coef_man);
732 REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
733 AR_PHY_SGI_DSC_EXP, ds_coef_exp);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400734}
735
736static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
737{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400738 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
739 return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
740 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400741}
742
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400743/*
744 * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
745 * Read the phy active delay register. Value is in 100ns increments.
746 */
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400747static void ar9003_hw_rfbus_done(struct ath_hw *ah)
748{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400749 u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
750 if (IS_CHAN_B(ah->curchan))
751 synthDelay = (4 * synthDelay) / 22;
752 else
753 synthDelay /= 10;
754
755 udelay(synthDelay + BASE_ACTIVATE_DELAY);
756
757 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400758}
759
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400760static void ar9003_hw_set_diversity(struct ath_hw *ah, bool value)
761{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400762 u32 v = REG_READ(ah, AR_PHY_CCK_DETECT);
763 if (value)
764 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
765 else
766 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
767 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400768}
769
Felix Fietkauc16fcb42010-04-15 17:38:39 -0400770static bool ar9003_hw_ani_control(struct ath_hw *ah,
771 enum ath9k_ani_cmd cmd, int param)
772{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400773 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400774 struct ath9k_channel *chan = ah->curchan;
Felix Fietkau093115b2010-10-04 20:09:47 +0200775 struct ar5416AniState *aniState = &chan->ani;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400776 s32 value, value2;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400777
778 switch (cmd & ah->ani_function) {
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400779 case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400780 /*
781 * on == 1 means ofdm weak signal detection is ON
782 * on == 1 is the default, for less noise immunity
783 *
784 * on == 0 means ofdm weak signal detection is OFF
785 * on == 0 means more noise imm
786 */
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400787 u32 on = param ? 1 : 0;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400788 /*
789 * make register setting for default
790 * (weak sig detect ON) come from INI file
791 */
792 int m1ThreshLow = on ?
793 aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
794 int m2ThreshLow = on ?
795 aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
796 int m1Thresh = on ?
797 aniState->iniDef.m1Thresh : m1Thresh_off;
798 int m2Thresh = on ?
799 aniState->iniDef.m2Thresh : m2Thresh_off;
800 int m2CountThr = on ?
801 aniState->iniDef.m2CountThr : m2CountThr_off;
802 int m2CountThrLow = on ?
803 aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
804 int m1ThreshLowExt = on ?
805 aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
806 int m2ThreshLowExt = on ?
807 aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
808 int m1ThreshExt = on ?
809 aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
810 int m2ThreshExt = on ?
811 aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400812
813 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
814 AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400815 m1ThreshLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400816 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
817 AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400818 m2ThreshLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400819 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400820 AR_PHY_SFCORR_M1_THRESH, m1Thresh);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400821 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400822 AR_PHY_SFCORR_M2_THRESH, m2Thresh);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400823 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400824 AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400825 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
826 AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400827 m2CountThrLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400828
829 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400830 AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400831 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400832 AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400833 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400834 AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400835 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400836 AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400837
838 if (on)
839 REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
840 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
841 else
842 REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
843 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
844
845 if (!on != aniState->ofdmWeakSigDetectOff) {
Joe Perches226afe62010-12-02 19:12:37 -0800846 ath_dbg(common, ATH_DBG_ANI,
847 "** ch %d: ofdm weak signal: %s=>%s\n",
848 chan->channel,
849 !aniState->ofdmWeakSigDetectOff ?
850 "on" : "off",
851 on ? "on" : "off");
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400852 if (on)
853 ah->stats.ast_ani_ofdmon++;
854 else
855 ah->stats.ast_ani_ofdmoff++;
856 aniState->ofdmWeakSigDetectOff = !on;
857 }
858 break;
859 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400860 case ATH9K_ANI_FIRSTEP_LEVEL:{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400861 u32 level = param;
862
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400863 if (level >= ARRAY_SIZE(firstep_table)) {
Joe Perches226afe62010-12-02 19:12:37 -0800864 ath_dbg(common, ATH_DBG_ANI,
865 "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
866 level, ARRAY_SIZE(firstep_table));
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400867 return false;
868 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400869
870 /*
871 * make register setting relative to default
872 * from INI file & cap value
873 */
874 value = firstep_table[level] -
875 firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
876 aniState->iniDef.firstep;
877 if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
878 value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
879 if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
880 value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400881 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
882 AR_PHY_FIND_SIG_FIRSTEP,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400883 value);
884 /*
885 * we need to set first step low register too
886 * make register setting relative to default
887 * from INI file & cap value
888 */
889 value2 = firstep_table[level] -
890 firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
891 aniState->iniDef.firstepLow;
892 if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
893 value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
894 if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
895 value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
896
897 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
898 AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
899
900 if (level != aniState->firstepLevel) {
Joe Perches226afe62010-12-02 19:12:37 -0800901 ath_dbg(common, ATH_DBG_ANI,
902 "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
903 chan->channel,
904 aniState->firstepLevel,
905 level,
906 ATH9K_ANI_FIRSTEP_LVL_NEW,
907 value,
908 aniState->iniDef.firstep);
909 ath_dbg(common, ATH_DBG_ANI,
910 "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
911 chan->channel,
912 aniState->firstepLevel,
913 level,
914 ATH9K_ANI_FIRSTEP_LVL_NEW,
915 value2,
916 aniState->iniDef.firstepLow);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400917 if (level > aniState->firstepLevel)
918 ah->stats.ast_ani_stepup++;
919 else if (level < aniState->firstepLevel)
920 ah->stats.ast_ani_stepdown++;
921 aniState->firstepLevel = level;
922 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400923 break;
924 }
925 case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400926 u32 level = param;
927
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400928 if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
Joe Perches226afe62010-12-02 19:12:37 -0800929 ath_dbg(common, ATH_DBG_ANI,
930 "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
931 level, ARRAY_SIZE(cycpwrThr1_table));
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400932 return false;
933 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400934 /*
935 * make register setting relative to default
936 * from INI file & cap value
937 */
938 value = cycpwrThr1_table[level] -
939 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
940 aniState->iniDef.cycpwrThr1;
941 if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
942 value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
943 if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
944 value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400945 REG_RMW_FIELD(ah, AR_PHY_TIMING5,
946 AR_PHY_TIMING5_CYCPWR_THR1,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400947 value);
948
949 /*
950 * set AR_PHY_EXT_CCA for extension channel
951 * make register setting relative to default
952 * from INI file & cap value
953 */
954 value2 = cycpwrThr1_table[level] -
955 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
956 aniState->iniDef.cycpwrThr1Ext;
957 if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
958 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
959 if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
960 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
961 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
962 AR_PHY_EXT_CYCPWR_THR1, value2);
963
964 if (level != aniState->spurImmunityLevel) {
Joe Perches226afe62010-12-02 19:12:37 -0800965 ath_dbg(common, ATH_DBG_ANI,
966 "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
967 chan->channel,
968 aniState->spurImmunityLevel,
969 level,
970 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
971 value,
972 aniState->iniDef.cycpwrThr1);
973 ath_dbg(common, ATH_DBG_ANI,
974 "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
975 chan->channel,
976 aniState->spurImmunityLevel,
977 level,
978 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
979 value2,
980 aniState->iniDef.cycpwrThr1Ext);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400981 if (level > aniState->spurImmunityLevel)
982 ah->stats.ast_ani_spurup++;
983 else if (level < aniState->spurImmunityLevel)
984 ah->stats.ast_ani_spurdown++;
985 aniState->spurImmunityLevel = level;
986 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400987 break;
988 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400989 case ATH9K_ANI_MRC_CCK:{
990 /*
991 * is_on == 1 means MRC CCK ON (default, less noise imm)
992 * is_on == 0 means MRC CCK is OFF (more noise imm)
993 */
994 bool is_on = param ? 1 : 0;
995 REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
996 AR_PHY_MRC_CCK_ENABLE, is_on);
997 REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
998 AR_PHY_MRC_CCK_MUX_REG, is_on);
999 if (!is_on != aniState->mrcCCKOff) {
Joe Perches226afe62010-12-02 19:12:37 -08001000 ath_dbg(common, ATH_DBG_ANI,
1001 "** ch %d: MRC CCK: %s=>%s\n",
1002 chan->channel,
1003 !aniState->mrcCCKOff ? "on" : "off",
1004 is_on ? "on" : "off");
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001005 if (is_on)
1006 ah->stats.ast_ani_ccklow++;
1007 else
1008 ah->stats.ast_ani_cckhigh++;
1009 aniState->mrcCCKOff = !is_on;
1010 }
1011 break;
1012 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001013 case ATH9K_ANI_PRESENT:
1014 break;
1015 default:
Joe Perches226afe62010-12-02 19:12:37 -08001016 ath_dbg(common, ATH_DBG_ANI, "invalid cmd %u\n", cmd);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001017 return false;
1018 }
1019
Joe Perches226afe62010-12-02 19:12:37 -08001020 ath_dbg(common, ATH_DBG_ANI,
1021 "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
1022 aniState->spurImmunityLevel,
1023 !aniState->ofdmWeakSigDetectOff ? "on" : "off",
1024 aniState->firstepLevel,
1025 !aniState->mrcCCKOff ? "on" : "off",
1026 aniState->listenTime,
1027 aniState->ofdmPhyErrCount,
1028 aniState->cckPhyErrCount);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001029 return true;
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001030}
1031
Felix Fietkau641d9922010-04-15 17:38:49 -04001032static void ar9003_hw_do_getnf(struct ath_hw *ah,
1033 int16_t nfarray[NUM_NF_READINGS])
1034{
Vasanthakumar Thiagarajanb06af7a2011-03-01 08:59:36 -08001035#define AR_PHY_CH_MINCCA_PWR 0x1FF00000
1036#define AR_PHY_CH_MINCCA_PWR_S 20
1037#define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
1038#define AR_PHY_CH_EXT_MINCCA_PWR_S 16
1039
Felix Fietkau641d9922010-04-15 17:38:49 -04001040 int16_t nf;
Vasanthakumar Thiagarajanb06af7a2011-03-01 08:59:36 -08001041 int i;
Felix Fietkau641d9922010-04-15 17:38:49 -04001042
Vasanthakumar Thiagarajanb06af7a2011-03-01 08:59:36 -08001043 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
1044 if (ah->rxchainmask & BIT(i)) {
1045 nf = MS(REG_READ(ah, ah->nf_regs[i]),
1046 AR_PHY_CH_MINCCA_PWR);
1047 nfarray[i] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001048
Vasanthakumar Thiagarajanb06af7a2011-03-01 08:59:36 -08001049 if (IS_CHAN_HT40(ah->curchan)) {
1050 u8 ext_idx = AR9300_MAX_CHAINS + i;
Felix Fietkau641d9922010-04-15 17:38:49 -04001051
Vasanthakumar Thiagarajanb06af7a2011-03-01 08:59:36 -08001052 nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
1053 AR_PHY_CH_EXT_MINCCA_PWR);
1054 nfarray[ext_idx] = sign_extend32(nf, 8);
1055 }
1056 }
1057 }
Felix Fietkau641d9922010-04-15 17:38:49 -04001058}
1059
Felix Fietkauf2552e22010-07-02 00:09:50 +02001060static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
Felix Fietkau641d9922010-04-15 17:38:49 -04001061{
Felix Fietkauf2552e22010-07-02 00:09:50 +02001062 ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
1063 ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
1064 ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
1065 ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
1066 ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
1067 ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
Felix Fietkau641d9922010-04-15 17:38:49 -04001068}
1069
Luis R. Rodriguezdf23aca2010-04-15 17:39:11 -04001070/*
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001071 * Initialize the ANI register values with default (ini) values.
1072 * This routine is called during a (full) hardware reset after
1073 * all the registers are initialised from the INI.
1074 */
1075static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
1076{
1077 struct ar5416AniState *aniState;
1078 struct ath_common *common = ath9k_hw_common(ah);
1079 struct ath9k_channel *chan = ah->curchan;
1080 struct ath9k_ani_default *iniDef;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001081 u32 val;
1082
Felix Fietkau093115b2010-10-04 20:09:47 +02001083 aniState = &ah->curchan->ani;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001084 iniDef = &aniState->iniDef;
1085
Joe Perches226afe62010-12-02 19:12:37 -08001086 ath_dbg(common, ATH_DBG_ANI,
1087 "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
1088 ah->hw_version.macVersion,
1089 ah->hw_version.macRev,
1090 ah->opmode,
1091 chan->channel,
1092 chan->channelFlags);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001093
1094 val = REG_READ(ah, AR_PHY_SFCORR);
1095 iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
1096 iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
1097 iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
1098
1099 val = REG_READ(ah, AR_PHY_SFCORR_LOW);
1100 iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
1101 iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
1102 iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
1103
1104 val = REG_READ(ah, AR_PHY_SFCORR_EXT);
1105 iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
1106 iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
1107 iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
1108 iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
1109 iniDef->firstep = REG_READ_FIELD(ah,
1110 AR_PHY_FIND_SIG,
1111 AR_PHY_FIND_SIG_FIRSTEP);
1112 iniDef->firstepLow = REG_READ_FIELD(ah,
1113 AR_PHY_FIND_SIG_LOW,
1114 AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
1115 iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
1116 AR_PHY_TIMING5,
1117 AR_PHY_TIMING5_CYCPWR_THR1);
1118 iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
1119 AR_PHY_EXT_CCA,
1120 AR_PHY_EXT_CYCPWR_THR1);
1121
1122 /* these levels just got reset to defaults by the INI */
1123 aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
1124 aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
1125 aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
1126 aniState->mrcCCKOff = !ATH9K_ANI_ENABLE_MRC_CCK;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001127}
1128
Felix Fietkau4e8c14e2010-11-11 03:18:38 +01001129static void ar9003_hw_set_radar_params(struct ath_hw *ah,
1130 struct ath_hw_radar_conf *conf)
1131{
1132 u32 radar_0 = 0, radar_1 = 0;
1133
1134 if (!conf) {
1135 REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
1136 return;
1137 }
1138
1139 radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
1140 radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
1141 radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
1142 radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
1143 radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
1144 radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
1145
1146 radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
1147 radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
1148 radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
1149 radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
1150 radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
1151
1152 REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
1153 REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
1154 if (conf->ext_channel)
1155 REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
1156 else
1157 REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
1158}
1159
Felix Fietkauc5d08552010-11-13 20:22:41 +01001160static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
1161{
1162 struct ath_hw_radar_conf *conf = &ah->radar_conf;
1163
1164 conf->fir_power = -28;
1165 conf->radar_rssi = 0;
1166 conf->pulse_height = 10;
1167 conf->pulse_rssi = 24;
1168 conf->pulse_inband = 8;
1169 conf->pulse_maxlen = 255;
1170 conf->pulse_inband_step = 12;
1171 conf->radar_inband = 8;
1172}
1173
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001174void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
1175{
1176 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
Joe Perches07b2fa52010-11-20 18:38:53 -08001177 static const u32 ar9300_cca_regs[6] = {
Felix Fietkaubbacee12010-07-11 15:44:42 +02001178 AR_PHY_CCA_0,
1179 AR_PHY_CCA_1,
1180 AR_PHY_CCA_2,
1181 AR_PHY_EXT_CCA,
1182 AR_PHY_EXT_CCA_1,
1183 AR_PHY_EXT_CCA_2,
1184 };
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001185
1186 priv_ops->rf_set_freq = ar9003_hw_set_channel;
1187 priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
1188 priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
1189 priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
1190 priv_ops->init_bb = ar9003_hw_init_bb;
1191 priv_ops->process_ini = ar9003_hw_process_ini;
1192 priv_ops->set_rfmode = ar9003_hw_set_rfmode;
1193 priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
1194 priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
1195 priv_ops->rfbus_req = ar9003_hw_rfbus_req;
1196 priv_ops->rfbus_done = ar9003_hw_rfbus_done;
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001197 priv_ops->set_diversity = ar9003_hw_set_diversity;
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001198 priv_ops->ani_control = ar9003_hw_ani_control;
Felix Fietkau641d9922010-04-15 17:38:49 -04001199 priv_ops->do_getnf = ar9003_hw_do_getnf;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001200 priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
Felix Fietkau4e8c14e2010-11-11 03:18:38 +01001201 priv_ops->set_radar_params = ar9003_hw_set_radar_params;
Felix Fietkauf2552e22010-07-02 00:09:50 +02001202
1203 ar9003_hw_set_nf_limits(ah);
Felix Fietkauc5d08552010-11-13 20:22:41 +01001204 ar9003_hw_set_radar_conf(ah);
Felix Fietkaubbacee12010-07-11 15:44:42 +02001205 memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001206}
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001207
1208void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
1209{
1210 struct ath_common *common = ath9k_hw_common(ah);
1211 u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
1212 u32 val, idle_count;
1213
1214 if (!idle_tmo_ms) {
1215 /* disable IRQ, disable chip-reset for BB panic */
1216 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
1217 REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
1218 ~(AR_PHY_WATCHDOG_RST_ENABLE |
1219 AR_PHY_WATCHDOG_IRQ_ENABLE));
1220
1221 /* disable watchdog in non-IDLE mode, disable in IDLE mode */
1222 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
1223 REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
1224 ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
1225 AR_PHY_WATCHDOG_IDLE_ENABLE));
1226
Joe Perches226afe62010-12-02 19:12:37 -08001227 ath_dbg(common, ATH_DBG_RESET, "Disabled BB Watchdog\n");
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001228 return;
1229 }
1230
1231 /* enable IRQ, disable chip-reset for BB watchdog */
1232 val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
1233 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
1234 (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
1235 ~AR_PHY_WATCHDOG_RST_ENABLE);
1236
1237 /* bound limit to 10 secs */
1238 if (idle_tmo_ms > 10000)
1239 idle_tmo_ms = 10000;
1240
1241 /*
1242 * The time unit for watchdog event is 2^15 44/88MHz cycles.
1243 *
1244 * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
1245 * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
1246 *
1247 * Given we use fast clock now in 5 GHz, these time units should
1248 * be common for both 2 GHz and 5 GHz.
1249 */
1250 idle_count = (100 * idle_tmo_ms) / 74;
1251 if (ah->curchan && IS_CHAN_HT40(ah->curchan))
1252 idle_count = (100 * idle_tmo_ms) / 37;
1253
1254 /*
1255 * enable watchdog in non-IDLE mode, disable in IDLE mode,
1256 * set idle time-out.
1257 */
1258 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
1259 AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
1260 AR_PHY_WATCHDOG_IDLE_MASK |
1261 (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
1262
Joe Perches226afe62010-12-02 19:12:37 -08001263 ath_dbg(common, ATH_DBG_RESET,
1264 "Enabled BB Watchdog timeout (%u ms)\n",
1265 idle_tmo_ms);
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001266}
1267
1268void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
1269{
1270 /*
1271 * we want to avoid printing in ISR context so we save the
1272 * watchdog status to be printed later in bottom half context.
1273 */
1274 ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
1275
1276 /*
1277 * the watchdog timer should reset on status read but to be sure
1278 * sure we write 0 to the watchdog status bit.
1279 */
1280 REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
1281 ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
1282}
1283
1284void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
1285{
1286 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau9dbebc72010-10-03 19:07:17 +02001287 u32 status;
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001288
1289 if (likely(!(common->debug_mask & ATH_DBG_RESET)))
1290 return;
1291
1292 status = ah->bb_watchdog_last_status;
Joe Perches226afe62010-12-02 19:12:37 -08001293 ath_dbg(common, ATH_DBG_RESET,
1294 "\n==== BB update: BB status=0x%08x ====\n", status);
1295 ath_dbg(common, ATH_DBG_RESET,
1296 "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
1297 MS(status, AR_PHY_WATCHDOG_INFO),
1298 MS(status, AR_PHY_WATCHDOG_DET_HANG),
1299 MS(status, AR_PHY_WATCHDOG_RADAR_SM),
1300 MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
1301 MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
1302 MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
1303 MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
1304 MS(status, AR_PHY_WATCHDOG_AGC_SM),
1305 MS(status, AR_PHY_WATCHDOG_SRCH_SM));
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001306
Joe Perches226afe62010-12-02 19:12:37 -08001307 ath_dbg(common, ATH_DBG_RESET,
1308 "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
1309 REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
1310 REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
1311 ath_dbg(common, ATH_DBG_RESET,
1312 "** BB mode: BB_gen_controls=0x%08x **\n",
1313 REG_READ(ah, AR_PHY_GEN_CTRL));
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001314
Felix Fietkaub5bfc562010-10-08 22:13:53 +02001315#define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
1316 if (common->cc_survey.cycles)
Joe Perches226afe62010-12-02 19:12:37 -08001317 ath_dbg(common, ATH_DBG_RESET,
1318 "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
1319 PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001320
Joe Perches226afe62010-12-02 19:12:37 -08001321 ath_dbg(common, ATH_DBG_RESET,
1322 "==== BB update: done ====\n\n");
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001323}
1324EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);