blob: bce1fdb1660a4ee9ad5b10aa70988957116f372f [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 Thiagarajan85dd0922010-12-06 04:27:45 -080078 if (AR_SREV_9485(ah))
79 channelSel = CHANSEL_2G_9485(freq);
80 else
81 channelSel = CHANSEL_2G(freq);
Felix Fietkauf7abf0c2010-04-15 17:38:33 -040082 /* Set to 2G mode */
83 bMode = 1;
84 } else {
85 channelSel = CHANSEL_5G(freq);
86 /* Doubler is ON, so, divide channelSel by 2. */
87 channelSel >>= 1;
88 /* Set to 5G mode */
89 bMode = 0;
90 }
91
92 /* Enable fractional mode for all channels */
93 fracMode = 1;
94 aModeRefSel = 0;
95 loadSynthChannel = 0;
96
97 reg32 = (bMode << 29);
98 REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
99
100 /* Enable Long shift Select for Synthesizer */
101 REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
102 AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
103
104 /* Program Synth. setting */
105 reg32 = (channelSel << 2) | (fracMode << 30) |
106 (aModeRefSel << 28) | (loadSynthChannel << 31);
107 REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
108
109 /* Toggle Load Synth channel bit */
110 loadSynthChannel = 1;
111 reg32 = (channelSel << 2) | (fracMode << 30) |
112 (aModeRefSel << 28) | (loadSynthChannel << 31);
113 REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
114
115 ah->curchan = chan;
116 ah->curchan_rad_index = -1;
117
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400118 return 0;
119}
120
121/**
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400122 * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400123 * @ah: atheros hardware structure
124 * @chan:
125 *
126 * For single-chip solutions. Converts to baseband spur frequency given the
127 * input channel frequency and compute register settings below.
128 *
129 * Spur mitigation for MRC CCK
130 */
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400131static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
132 struct ath9k_channel *chan)
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400133{
Joe Perches07b2fa52010-11-20 18:38:53 -0800134 static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
Felix Fietkauca375552010-04-15 17:38:35 -0400135 int cur_bb_spur, negative = 0, cck_spur_freq;
136 int i;
137
138 /*
139 * Need to verify range +/- 10 MHz in control channel, otherwise spur
140 * is out-of-band and can be ignored.
141 */
142
143 for (i = 0; i < 4; i++) {
144 negative = 0;
145 cur_bb_spur = spur_freq[i] - chan->channel;
146
147 if (cur_bb_spur < 0) {
148 negative = 1;
149 cur_bb_spur = -cur_bb_spur;
150 }
151 if (cur_bb_spur < 10) {
152 cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
153
154 if (negative == 1)
155 cck_spur_freq = -cck_spur_freq;
156
157 cck_spur_freq = cck_spur_freq & 0xfffff;
158
159 REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
160 AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
161 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
162 AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
163 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
164 AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
165 0x2);
166 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
167 AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
168 0x1);
169 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
170 AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
171 cck_spur_freq);
172
173 return;
174 }
175 }
176
177 REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
178 AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
179 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
180 AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
181 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
182 AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400183}
184
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400185/* Clean all spur register fields */
186static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
187{
188 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
189 AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
190 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
191 AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
192 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
193 AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
194 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
195 AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
196 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
197 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
198 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
199 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
200 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
201 AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
202 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
203 AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
204 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
205 AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
206
207 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
208 AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
209 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
210 AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
211 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
212 AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
213 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
214 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
215 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
216 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
217 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
218 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
219 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
220 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
221 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
222 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
223 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
224 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
225 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
226 AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
227}
228
229static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
230 int freq_offset,
231 int spur_freq_sd,
232 int spur_delta_phase,
233 int spur_subchannel_sd)
234{
235 int mask_index = 0;
236
237 /* OFDM Spur mitigation */
238 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
239 AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
240 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
241 AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
242 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
243 AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
244 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
245 AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
246 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
247 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
248 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
249 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
250 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
251 AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
252 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
253 AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
254 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
255 AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
256
257 if (REG_READ_FIELD(ah, AR_PHY_MODE,
258 AR_PHY_MODE_DYNAMIC) == 0x1)
259 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
260 AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
261
262 mask_index = (freq_offset << 4) / 5;
263 if (mask_index < 0)
264 mask_index = mask_index - 1;
265
266 mask_index = mask_index & 0x7f;
267
268 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
269 AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
270 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
271 AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
272 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
273 AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
274 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
275 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
276 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
277 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
278 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
279 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
280 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
281 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
282 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
283 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
284 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
285 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
286 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
287 AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
288}
289
290static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
291 struct ath9k_channel *chan,
292 int freq_offset)
293{
294 int spur_freq_sd = 0;
295 int spur_subchannel_sd = 0;
296 int spur_delta_phase = 0;
297
298 if (IS_CHAN_HT40(chan)) {
299 if (freq_offset < 0) {
300 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
301 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
302 spur_subchannel_sd = 1;
303 else
304 spur_subchannel_sd = 0;
305
306 spur_freq_sd = ((freq_offset + 10) << 9) / 11;
307
308 } else {
309 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
310 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
311 spur_subchannel_sd = 0;
312 else
313 spur_subchannel_sd = 1;
314
315 spur_freq_sd = ((freq_offset - 10) << 9) / 11;
316
317 }
318
319 spur_delta_phase = (freq_offset << 17) / 5;
320
321 } else {
322 spur_subchannel_sd = 0;
323 spur_freq_sd = (freq_offset << 9) /11;
324 spur_delta_phase = (freq_offset << 18) / 5;
325 }
326
327 spur_freq_sd = spur_freq_sd & 0x3ff;
328 spur_delta_phase = spur_delta_phase & 0xfffff;
329
330 ar9003_hw_spur_ofdm(ah,
331 freq_offset,
332 spur_freq_sd,
333 spur_delta_phase,
334 spur_subchannel_sd);
335}
336
337/* Spur mitigation for OFDM */
338static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
339 struct ath9k_channel *chan)
340{
341 int synth_freq;
342 int range = 10;
343 int freq_offset = 0;
344 int mode;
345 u8* spurChansPtr;
346 unsigned int i;
347 struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
348
349 if (IS_CHAN_5GHZ(chan)) {
350 spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
351 mode = 0;
352 }
353 else {
354 spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
355 mode = 1;
356 }
357
358 if (spurChansPtr[0] == 0)
359 return; /* No spur in the mode */
360
361 if (IS_CHAN_HT40(chan)) {
362 range = 19;
363 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
364 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
365 synth_freq = chan->channel - 10;
366 else
367 synth_freq = chan->channel + 10;
368 } else {
369 range = 10;
370 synth_freq = chan->channel;
371 }
372
373 ar9003_hw_spur_ofdm_clear(ah);
374
375 for (i = 0; spurChansPtr[i] && i < 5; i++) {
376 freq_offset = FBIN2FREQ(spurChansPtr[i], mode) - synth_freq;
377 if (abs(freq_offset) < range) {
378 ar9003_hw_spur_ofdm_work(ah, chan, freq_offset);
379 break;
380 }
381 }
382}
383
384static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
385 struct ath9k_channel *chan)
386{
387 ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
388 ar9003_hw_spur_mitigate_ofdm(ah, chan);
389}
390
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400391static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
392 struct ath9k_channel *chan)
393{
Felix Fietkau317d3322010-04-15 17:38:34 -0400394 u32 pll;
395
396 pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
397
398 if (chan && IS_CHAN_HALF_RATE(chan))
399 pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
400 else if (chan && IS_CHAN_QUARTER_RATE(chan))
401 pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
402
Felix Fietkau14bc1102010-04-26 15:04:30 -0400403 pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
Felix Fietkau317d3322010-04-15 17:38:34 -0400404
405 return pll;
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400406}
407
408static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
409 struct ath9k_channel *chan)
410{
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400411 u32 phymode;
412 u32 enableDacFifo = 0;
413
414 enableDacFifo =
415 (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
416
417 /* Enable 11n HT, 20 MHz */
418 phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 | AR_PHY_GC_WALSH |
419 AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
420
421 /* Configure baseband for dynamic 20/40 operation */
422 if (IS_CHAN_HT40(chan)) {
423 phymode |= AR_PHY_GC_DYN2040_EN;
424 /* Configure control (primary) channel at +-10MHz */
425 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
426 (chan->chanmode == CHANNEL_G_HT40PLUS))
427 phymode |= AR_PHY_GC_DYN2040_PRI_CH;
428
429 }
430
431 /* make sure we preserve INI settings */
432 phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
433 /* turn off Green Field detection for STA for now */
434 phymode &= ~AR_PHY_GC_GF_DETECT_EN;
435
436 REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
437
438 /* Configure MAC for 20/40 operation */
439 ath9k_hw_set11nmac2040(ah);
440
441 /* global transmit timeout (25 TUs default)*/
442 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
443 /* carrier sense timeout */
444 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400445}
446
447static void ar9003_hw_init_bb(struct ath_hw *ah,
448 struct ath9k_channel *chan)
449{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400450 u32 synthDelay;
451
452 /*
453 * Wait for the frequency synth to settle (synth goes on
454 * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
455 * Value is in 100ns increments.
456 */
457 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
458 if (IS_CHAN_B(chan))
459 synthDelay = (4 * synthDelay) / 22;
460 else
461 synthDelay /= 10;
462
463 /* Activate the PHY (includes baseband activate + synthesizer on) */
464 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
465
466 /*
467 * There is an issue if the AP starts the calibration before
468 * the base band timeout completes. This could result in the
469 * rx_clear false triggering. As a workaround we add delay an
470 * extra BASE_ACTIVATE_DELAY usecs to ensure this condition
471 * does not happen.
472 */
473 udelay(synthDelay + BASE_ACTIVATE_DELAY);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400474}
475
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400476void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
477{
478 switch (rx) {
479 case 0x5:
480 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
481 AR_PHY_SWAP_ALT_CHAIN);
482 case 0x3:
483 case 0x1:
484 case 0x2:
485 case 0x7:
486 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
487 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
488 break;
489 default:
490 break;
491 }
492
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +0530493 if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7))
494 REG_WRITE(ah, AR_SELFGEN_MASK, 0x3);
495 else
496 REG_WRITE(ah, AR_SELFGEN_MASK, tx);
497
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400498 if (tx == 0x5) {
499 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
500 AR_PHY_SWAP_ALT_CHAIN);
501 }
502}
503
504/*
505 * Override INI values with chip specific configuration.
506 */
507static void ar9003_hw_override_ini(struct ath_hw *ah)
508{
509 u32 val;
510
511 /*
512 * Set the RX_ABORT and RX_DIS and clear it only after
513 * RXE is set for MAC. This prevents frames with
514 * corrupted descriptor status.
515 */
516 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
517
518 /*
519 * For AR9280 and above, there is a new feature that allows
520 * Multicast search based on both MAC Address and Key ID. By default,
521 * this feature is enabled. But since the driver is not using this
522 * feature, we switch it off; otherwise multicast search based on
523 * MAC addr only will fail.
524 */
525 val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
526 REG_WRITE(ah, AR_PCU_MISC_MODE2,
527 val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
528}
529
530static void ar9003_hw_prog_ini(struct ath_hw *ah,
531 struct ar5416IniArray *iniArr,
532 int column)
533{
534 unsigned int i, regWrites = 0;
535
536 /* New INI format: Array may be undefined (pre, core, post arrays) */
537 if (!iniArr->ia_array)
538 return;
539
540 /*
541 * New INI format: Pre, core, and post arrays for a given subsystem
542 * may be modal (> 2 columns) or non-modal (2 columns). Determine if
543 * the array is non-modal and force the column to 1.
544 */
545 if (column >= iniArr->ia_columns)
546 column = 1;
547
548 for (i = 0; i < iniArr->ia_rows; i++) {
549 u32 reg = INI_RA(iniArr, i, 0);
550 u32 val = INI_RA(iniArr, i, column);
551
Felix Fietkaub2ccc502010-07-30 21:02:12 +0200552 if (reg >= 0x16000 && reg < 0x17000)
553 ath9k_hw_analog_shift_regwrite(ah, reg, val);
554 else
555 REG_WRITE(ah, reg, val);
556
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400557 DO_DELAY(regWrites);
558 }
559}
560
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400561static int ar9003_hw_process_ini(struct ath_hw *ah,
562 struct ath9k_channel *chan)
563{
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400564 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
565 unsigned int regWrites = 0, i;
566 struct ieee80211_channel *channel = chan->chan;
567 u32 modesIndex, freqIndex;
568
569 switch (chan->chanmode) {
570 case CHANNEL_A:
571 case CHANNEL_A_HT20:
572 modesIndex = 1;
573 freqIndex = 1;
574 break;
575 case CHANNEL_A_HT40PLUS:
576 case CHANNEL_A_HT40MINUS:
577 modesIndex = 2;
578 freqIndex = 1;
579 break;
580 case CHANNEL_G:
581 case CHANNEL_G_HT20:
582 case CHANNEL_B:
583 modesIndex = 4;
584 freqIndex = 2;
585 break;
586 case CHANNEL_G_HT40PLUS:
587 case CHANNEL_G_HT40MINUS:
588 modesIndex = 3;
589 freqIndex = 2;
590 break;
591
592 default:
593 return -EINVAL;
594 }
595
596 for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
597 ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
598 ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
599 ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
600 ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
601 }
602
603 REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
604 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
605
606 /*
607 * For 5GHz channels requiring Fast Clock, apply
608 * different modal values.
609 */
Felix Fietkau6b42e8d2010-04-26 15:04:35 -0400610 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400611 REG_WRITE_ARRAY(&ah->iniModesAdditional,
612 modesIndex, regWrites);
613
614 ar9003_hw_override_ini(ah);
615 ar9003_hw_set_channel_regs(ah, chan);
616 ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
617
618 /* Set TX power */
619 ah->eep_ops->set_txpower(ah, chan,
620 ath9k_regd_get_ctl(regulatory, chan),
621 channel->max_antenna_gain * 2,
622 channel->max_power * 2,
623 min((u32) MAX_RATE_POWER,
Felix Fietkaude40f312010-10-20 03:08:53 +0200624 (u32) regulatory->power_limit), false);
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400625
626 return 0;
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400627}
628
629static void ar9003_hw_set_rfmode(struct ath_hw *ah,
630 struct ath9k_channel *chan)
631{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400632 u32 rfMode = 0;
633
634 if (chan == NULL)
635 return;
636
637 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
638 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
639
Felix Fietkau6b42e8d2010-04-26 15:04:35 -0400640 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400641 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
642
643 REG_WRITE(ah, AR_PHY_MODE, rfMode);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400644}
645
646static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
647{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400648 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400649}
650
651static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
652 struct ath9k_channel *chan)
653{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400654 u32 coef_scaled, ds_coef_exp, ds_coef_man;
655 u32 clockMhzScaled = 0x64000000;
656 struct chan_centers centers;
657
658 /*
659 * half and quarter rate can divide the scaled clock by 2 or 4
660 * scale for selected channel bandwidth
661 */
662 if (IS_CHAN_HALF_RATE(chan))
663 clockMhzScaled = clockMhzScaled >> 1;
664 else if (IS_CHAN_QUARTER_RATE(chan))
665 clockMhzScaled = clockMhzScaled >> 2;
666
667 /*
668 * ALGO -> coef = 1e8/fcarrier*fclock/40;
669 * scaled coef to provide precision for this floating calculation
670 */
671 ath9k_hw_get_channel_centers(ah, chan, &centers);
672 coef_scaled = clockMhzScaled / centers.synth_center;
673
674 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
675 &ds_coef_exp);
676
677 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
678 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
679 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
680 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
681
682 /*
683 * For Short GI,
684 * scaled coeff is 9/10 that of normal coeff
685 */
686 coef_scaled = (9 * coef_scaled) / 10;
687
688 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
689 &ds_coef_exp);
690
691 /* for short gi */
692 REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
693 AR_PHY_SGI_DSC_MAN, ds_coef_man);
694 REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
695 AR_PHY_SGI_DSC_EXP, ds_coef_exp);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400696}
697
698static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
699{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400700 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
701 return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
702 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400703}
704
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400705/*
706 * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
707 * Read the phy active delay register. Value is in 100ns increments.
708 */
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400709static void ar9003_hw_rfbus_done(struct ath_hw *ah)
710{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400711 u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
712 if (IS_CHAN_B(ah->curchan))
713 synthDelay = (4 * synthDelay) / 22;
714 else
715 synthDelay /= 10;
716
717 udelay(synthDelay + BASE_ACTIVATE_DELAY);
718
719 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400720}
721
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400722/*
723 * Set the interrupt and GPIO values so the ISR can disable RF
724 * on a switch signal. Assumes GPIO port and interrupt polarity
725 * are set prior to call.
726 */
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400727static void ar9003_hw_enable_rfkill(struct ath_hw *ah)
728{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400729 /* Connect rfsilent_bb_l to baseband */
730 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
731 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
732 /* Set input mux for rfsilent_bb_l to GPIO #0 */
733 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
734 AR_GPIO_INPUT_MUX2_RFSILENT);
735
736 /*
737 * Configure the desired GPIO port for input and
738 * enable baseband rf silence.
739 */
740 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
741 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400742}
743
744static void ar9003_hw_set_diversity(struct ath_hw *ah, bool value)
745{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400746 u32 v = REG_READ(ah, AR_PHY_CCK_DETECT);
747 if (value)
748 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
749 else
750 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
751 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400752}
753
Felix Fietkauc16fcb42010-04-15 17:38:39 -0400754static bool ar9003_hw_ani_control(struct ath_hw *ah,
755 enum ath9k_ani_cmd cmd, int param)
756{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400757 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400758 struct ath9k_channel *chan = ah->curchan;
Felix Fietkau093115b2010-10-04 20:09:47 +0200759 struct ar5416AniState *aniState = &chan->ani;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400760 s32 value, value2;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400761
762 switch (cmd & ah->ani_function) {
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400763 case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400764 /*
765 * on == 1 means ofdm weak signal detection is ON
766 * on == 1 is the default, for less noise immunity
767 *
768 * on == 0 means ofdm weak signal detection is OFF
769 * on == 0 means more noise imm
770 */
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400771 u32 on = param ? 1 : 0;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400772 /*
773 * make register setting for default
774 * (weak sig detect ON) come from INI file
775 */
776 int m1ThreshLow = on ?
777 aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
778 int m2ThreshLow = on ?
779 aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
780 int m1Thresh = on ?
781 aniState->iniDef.m1Thresh : m1Thresh_off;
782 int m2Thresh = on ?
783 aniState->iniDef.m2Thresh : m2Thresh_off;
784 int m2CountThr = on ?
785 aniState->iniDef.m2CountThr : m2CountThr_off;
786 int m2CountThrLow = on ?
787 aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
788 int m1ThreshLowExt = on ?
789 aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
790 int m2ThreshLowExt = on ?
791 aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
792 int m1ThreshExt = on ?
793 aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
794 int m2ThreshExt = on ?
795 aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400796
797 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
798 AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400799 m1ThreshLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400800 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
801 AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400802 m2ThreshLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400803 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400804 AR_PHY_SFCORR_M1_THRESH, m1Thresh);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400805 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400806 AR_PHY_SFCORR_M2_THRESH, m2Thresh);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400807 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400808 AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400809 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
810 AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400811 m2CountThrLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400812
813 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400814 AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400815 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400816 AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400817 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400818 AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400819 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400820 AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400821
822 if (on)
823 REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
824 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
825 else
826 REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
827 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
828
829 if (!on != aniState->ofdmWeakSigDetectOff) {
Joe Perches226afe62010-12-02 19:12:37 -0800830 ath_dbg(common, ATH_DBG_ANI,
831 "** ch %d: ofdm weak signal: %s=>%s\n",
832 chan->channel,
833 !aniState->ofdmWeakSigDetectOff ?
834 "on" : "off",
835 on ? "on" : "off");
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400836 if (on)
837 ah->stats.ast_ani_ofdmon++;
838 else
839 ah->stats.ast_ani_ofdmoff++;
840 aniState->ofdmWeakSigDetectOff = !on;
841 }
842 break;
843 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400844 case ATH9K_ANI_FIRSTEP_LEVEL:{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400845 u32 level = param;
846
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400847 if (level >= ARRAY_SIZE(firstep_table)) {
Joe Perches226afe62010-12-02 19:12:37 -0800848 ath_dbg(common, ATH_DBG_ANI,
849 "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
850 level, ARRAY_SIZE(firstep_table));
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400851 return false;
852 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400853
854 /*
855 * make register setting relative to default
856 * from INI file & cap value
857 */
858 value = firstep_table[level] -
859 firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
860 aniState->iniDef.firstep;
861 if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
862 value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
863 if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
864 value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400865 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
866 AR_PHY_FIND_SIG_FIRSTEP,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400867 value);
868 /*
869 * we need to set first step low register too
870 * make register setting relative to default
871 * from INI file & cap value
872 */
873 value2 = firstep_table[level] -
874 firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
875 aniState->iniDef.firstepLow;
876 if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
877 value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
878 if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
879 value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
880
881 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
882 AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
883
884 if (level != aniState->firstepLevel) {
Joe Perches226afe62010-12-02 19:12:37 -0800885 ath_dbg(common, ATH_DBG_ANI,
886 "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
887 chan->channel,
888 aniState->firstepLevel,
889 level,
890 ATH9K_ANI_FIRSTEP_LVL_NEW,
891 value,
892 aniState->iniDef.firstep);
893 ath_dbg(common, ATH_DBG_ANI,
894 "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
895 chan->channel,
896 aniState->firstepLevel,
897 level,
898 ATH9K_ANI_FIRSTEP_LVL_NEW,
899 value2,
900 aniState->iniDef.firstepLow);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400901 if (level > aniState->firstepLevel)
902 ah->stats.ast_ani_stepup++;
903 else if (level < aniState->firstepLevel)
904 ah->stats.ast_ani_stepdown++;
905 aniState->firstepLevel = level;
906 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400907 break;
908 }
909 case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400910 u32 level = param;
911
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400912 if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
Joe Perches226afe62010-12-02 19:12:37 -0800913 ath_dbg(common, ATH_DBG_ANI,
914 "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
915 level, ARRAY_SIZE(cycpwrThr1_table));
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400916 return false;
917 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400918 /*
919 * make register setting relative to default
920 * from INI file & cap value
921 */
922 value = cycpwrThr1_table[level] -
923 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
924 aniState->iniDef.cycpwrThr1;
925 if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
926 value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
927 if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
928 value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400929 REG_RMW_FIELD(ah, AR_PHY_TIMING5,
930 AR_PHY_TIMING5_CYCPWR_THR1,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400931 value);
932
933 /*
934 * set AR_PHY_EXT_CCA for extension channel
935 * make register setting relative to default
936 * from INI file & cap value
937 */
938 value2 = cycpwrThr1_table[level] -
939 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
940 aniState->iniDef.cycpwrThr1Ext;
941 if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
942 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
943 if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
944 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
945 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
946 AR_PHY_EXT_CYCPWR_THR1, value2);
947
948 if (level != aniState->spurImmunityLevel) {
Joe Perches226afe62010-12-02 19:12:37 -0800949 ath_dbg(common, ATH_DBG_ANI,
950 "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
951 chan->channel,
952 aniState->spurImmunityLevel,
953 level,
954 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
955 value,
956 aniState->iniDef.cycpwrThr1);
957 ath_dbg(common, ATH_DBG_ANI,
958 "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
959 chan->channel,
960 aniState->spurImmunityLevel,
961 level,
962 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
963 value2,
964 aniState->iniDef.cycpwrThr1Ext);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400965 if (level > aniState->spurImmunityLevel)
966 ah->stats.ast_ani_spurup++;
967 else if (level < aniState->spurImmunityLevel)
968 ah->stats.ast_ani_spurdown++;
969 aniState->spurImmunityLevel = level;
970 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400971 break;
972 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400973 case ATH9K_ANI_MRC_CCK:{
974 /*
975 * is_on == 1 means MRC CCK ON (default, less noise imm)
976 * is_on == 0 means MRC CCK is OFF (more noise imm)
977 */
978 bool is_on = param ? 1 : 0;
979 REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
980 AR_PHY_MRC_CCK_ENABLE, is_on);
981 REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
982 AR_PHY_MRC_CCK_MUX_REG, is_on);
983 if (!is_on != aniState->mrcCCKOff) {
Joe Perches226afe62010-12-02 19:12:37 -0800984 ath_dbg(common, ATH_DBG_ANI,
985 "** ch %d: MRC CCK: %s=>%s\n",
986 chan->channel,
987 !aniState->mrcCCKOff ? "on" : "off",
988 is_on ? "on" : "off");
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400989 if (is_on)
990 ah->stats.ast_ani_ccklow++;
991 else
992 ah->stats.ast_ani_cckhigh++;
993 aniState->mrcCCKOff = !is_on;
994 }
995 break;
996 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400997 case ATH9K_ANI_PRESENT:
998 break;
999 default:
Joe Perches226afe62010-12-02 19:12:37 -08001000 ath_dbg(common, ATH_DBG_ANI, "invalid cmd %u\n", cmd);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001001 return false;
1002 }
1003
Joe Perches226afe62010-12-02 19:12:37 -08001004 ath_dbg(common, ATH_DBG_ANI,
1005 "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
1006 aniState->spurImmunityLevel,
1007 !aniState->ofdmWeakSigDetectOff ? "on" : "off",
1008 aniState->firstepLevel,
1009 !aniState->mrcCCKOff ? "on" : "off",
1010 aniState->listenTime,
1011 aniState->ofdmPhyErrCount,
1012 aniState->cckPhyErrCount);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001013 return true;
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001014}
1015
Felix Fietkau641d9922010-04-15 17:38:49 -04001016static void ar9003_hw_do_getnf(struct ath_hw *ah,
1017 int16_t nfarray[NUM_NF_READINGS])
1018{
Felix Fietkau641d9922010-04-15 17:38:49 -04001019 int16_t nf;
1020
1021 nf = MS(REG_READ(ah, AR_PHY_CCA_0), AR_PHY_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001022 nfarray[0] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001023
1024 nf = MS(REG_READ(ah, AR_PHY_CCA_1), AR_PHY_CH1_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001025 nfarray[1] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001026
1027 nf = MS(REG_READ(ah, AR_PHY_CCA_2), AR_PHY_CH2_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001028 nfarray[2] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001029
Felix Fietkau866b7782010-07-23 04:07:48 +02001030 if (!IS_CHAN_HT40(ah->curchan))
1031 return;
1032
Felix Fietkau641d9922010-04-15 17:38:49 -04001033 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001034 nfarray[3] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001035
1036 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_1), AR_PHY_CH1_EXT_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001037 nfarray[4] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001038
1039 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_2), AR_PHY_CH2_EXT_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001040 nfarray[5] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001041}
1042
Felix Fietkauf2552e22010-07-02 00:09:50 +02001043static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
Felix Fietkau641d9922010-04-15 17:38:49 -04001044{
Felix Fietkauf2552e22010-07-02 00:09:50 +02001045 ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
1046 ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
1047 ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
1048 ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
1049 ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
1050 ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
Felix Fietkau641d9922010-04-15 17:38:49 -04001051}
1052
Luis R. Rodriguezdf23aca2010-04-15 17:39:11 -04001053/*
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001054 * Initialize the ANI register values with default (ini) values.
1055 * This routine is called during a (full) hardware reset after
1056 * all the registers are initialised from the INI.
1057 */
1058static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
1059{
1060 struct ar5416AniState *aniState;
1061 struct ath_common *common = ath9k_hw_common(ah);
1062 struct ath9k_channel *chan = ah->curchan;
1063 struct ath9k_ani_default *iniDef;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001064 u32 val;
1065
Felix Fietkau093115b2010-10-04 20:09:47 +02001066 aniState = &ah->curchan->ani;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001067 iniDef = &aniState->iniDef;
1068
Joe Perches226afe62010-12-02 19:12:37 -08001069 ath_dbg(common, ATH_DBG_ANI,
1070 "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
1071 ah->hw_version.macVersion,
1072 ah->hw_version.macRev,
1073 ah->opmode,
1074 chan->channel,
1075 chan->channelFlags);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001076
1077 val = REG_READ(ah, AR_PHY_SFCORR);
1078 iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
1079 iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
1080 iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
1081
1082 val = REG_READ(ah, AR_PHY_SFCORR_LOW);
1083 iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
1084 iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
1085 iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
1086
1087 val = REG_READ(ah, AR_PHY_SFCORR_EXT);
1088 iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
1089 iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
1090 iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
1091 iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
1092 iniDef->firstep = REG_READ_FIELD(ah,
1093 AR_PHY_FIND_SIG,
1094 AR_PHY_FIND_SIG_FIRSTEP);
1095 iniDef->firstepLow = REG_READ_FIELD(ah,
1096 AR_PHY_FIND_SIG_LOW,
1097 AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
1098 iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
1099 AR_PHY_TIMING5,
1100 AR_PHY_TIMING5_CYCPWR_THR1);
1101 iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
1102 AR_PHY_EXT_CCA,
1103 AR_PHY_EXT_CYCPWR_THR1);
1104
1105 /* these levels just got reset to defaults by the INI */
1106 aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
1107 aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
1108 aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
1109 aniState->mrcCCKOff = !ATH9K_ANI_ENABLE_MRC_CCK;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001110}
1111
Felix Fietkau4e8c14e2010-11-11 03:18:38 +01001112static void ar9003_hw_set_radar_params(struct ath_hw *ah,
1113 struct ath_hw_radar_conf *conf)
1114{
1115 u32 radar_0 = 0, radar_1 = 0;
1116
1117 if (!conf) {
1118 REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
1119 return;
1120 }
1121
1122 radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
1123 radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
1124 radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
1125 radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
1126 radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
1127 radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
1128
1129 radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
1130 radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
1131 radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
1132 radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
1133 radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
1134
1135 REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
1136 REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
1137 if (conf->ext_channel)
1138 REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
1139 else
1140 REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
1141}
1142
Felix Fietkauc5d08552010-11-13 20:22:41 +01001143static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
1144{
1145 struct ath_hw_radar_conf *conf = &ah->radar_conf;
1146
1147 conf->fir_power = -28;
1148 conf->radar_rssi = 0;
1149 conf->pulse_height = 10;
1150 conf->pulse_rssi = 24;
1151 conf->pulse_inband = 8;
1152 conf->pulse_maxlen = 255;
1153 conf->pulse_inband_step = 12;
1154 conf->radar_inband = 8;
1155}
1156
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001157void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
1158{
1159 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
Joe Perches07b2fa52010-11-20 18:38:53 -08001160 static const u32 ar9300_cca_regs[6] = {
Felix Fietkaubbacee12010-07-11 15:44:42 +02001161 AR_PHY_CCA_0,
1162 AR_PHY_CCA_1,
1163 AR_PHY_CCA_2,
1164 AR_PHY_EXT_CCA,
1165 AR_PHY_EXT_CCA_1,
1166 AR_PHY_EXT_CCA_2,
1167 };
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001168
1169 priv_ops->rf_set_freq = ar9003_hw_set_channel;
1170 priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
1171 priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
1172 priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
1173 priv_ops->init_bb = ar9003_hw_init_bb;
1174 priv_ops->process_ini = ar9003_hw_process_ini;
1175 priv_ops->set_rfmode = ar9003_hw_set_rfmode;
1176 priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
1177 priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
1178 priv_ops->rfbus_req = ar9003_hw_rfbus_req;
1179 priv_ops->rfbus_done = ar9003_hw_rfbus_done;
1180 priv_ops->enable_rfkill = ar9003_hw_enable_rfkill;
1181 priv_ops->set_diversity = ar9003_hw_set_diversity;
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001182 priv_ops->ani_control = ar9003_hw_ani_control;
Felix Fietkau641d9922010-04-15 17:38:49 -04001183 priv_ops->do_getnf = ar9003_hw_do_getnf;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001184 priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
Felix Fietkau4e8c14e2010-11-11 03:18:38 +01001185 priv_ops->set_radar_params = ar9003_hw_set_radar_params;
Felix Fietkauf2552e22010-07-02 00:09:50 +02001186
1187 ar9003_hw_set_nf_limits(ah);
Felix Fietkauc5d08552010-11-13 20:22:41 +01001188 ar9003_hw_set_radar_conf(ah);
Felix Fietkaubbacee12010-07-11 15:44:42 +02001189 memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001190}
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001191
1192void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
1193{
1194 struct ath_common *common = ath9k_hw_common(ah);
1195 u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
1196 u32 val, idle_count;
1197
1198 if (!idle_tmo_ms) {
1199 /* disable IRQ, disable chip-reset for BB panic */
1200 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
1201 REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
1202 ~(AR_PHY_WATCHDOG_RST_ENABLE |
1203 AR_PHY_WATCHDOG_IRQ_ENABLE));
1204
1205 /* disable watchdog in non-IDLE mode, disable in IDLE mode */
1206 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
1207 REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
1208 ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
1209 AR_PHY_WATCHDOG_IDLE_ENABLE));
1210
Joe Perches226afe62010-12-02 19:12:37 -08001211 ath_dbg(common, ATH_DBG_RESET, "Disabled BB Watchdog\n");
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001212 return;
1213 }
1214
1215 /* enable IRQ, disable chip-reset for BB watchdog */
1216 val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
1217 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
1218 (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
1219 ~AR_PHY_WATCHDOG_RST_ENABLE);
1220
1221 /* bound limit to 10 secs */
1222 if (idle_tmo_ms > 10000)
1223 idle_tmo_ms = 10000;
1224
1225 /*
1226 * The time unit for watchdog event is 2^15 44/88MHz cycles.
1227 *
1228 * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
1229 * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
1230 *
1231 * Given we use fast clock now in 5 GHz, these time units should
1232 * be common for both 2 GHz and 5 GHz.
1233 */
1234 idle_count = (100 * idle_tmo_ms) / 74;
1235 if (ah->curchan && IS_CHAN_HT40(ah->curchan))
1236 idle_count = (100 * idle_tmo_ms) / 37;
1237
1238 /*
1239 * enable watchdog in non-IDLE mode, disable in IDLE mode,
1240 * set idle time-out.
1241 */
1242 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
1243 AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
1244 AR_PHY_WATCHDOG_IDLE_MASK |
1245 (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
1246
Joe Perches226afe62010-12-02 19:12:37 -08001247 ath_dbg(common, ATH_DBG_RESET,
1248 "Enabled BB Watchdog timeout (%u ms)\n",
1249 idle_tmo_ms);
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001250}
1251
1252void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
1253{
1254 /*
1255 * we want to avoid printing in ISR context so we save the
1256 * watchdog status to be printed later in bottom half context.
1257 */
1258 ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
1259
1260 /*
1261 * the watchdog timer should reset on status read but to be sure
1262 * sure we write 0 to the watchdog status bit.
1263 */
1264 REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
1265 ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
1266}
1267
1268void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
1269{
1270 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau9dbebc72010-10-03 19:07:17 +02001271 u32 status;
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001272
1273 if (likely(!(common->debug_mask & ATH_DBG_RESET)))
1274 return;
1275
1276 status = ah->bb_watchdog_last_status;
Joe Perches226afe62010-12-02 19:12:37 -08001277 ath_dbg(common, ATH_DBG_RESET,
1278 "\n==== BB update: BB status=0x%08x ====\n", status);
1279 ath_dbg(common, ATH_DBG_RESET,
1280 "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
1281 MS(status, AR_PHY_WATCHDOG_INFO),
1282 MS(status, AR_PHY_WATCHDOG_DET_HANG),
1283 MS(status, AR_PHY_WATCHDOG_RADAR_SM),
1284 MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
1285 MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
1286 MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
1287 MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
1288 MS(status, AR_PHY_WATCHDOG_AGC_SM),
1289 MS(status, AR_PHY_WATCHDOG_SRCH_SM));
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001290
Joe Perches226afe62010-12-02 19:12:37 -08001291 ath_dbg(common, ATH_DBG_RESET,
1292 "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
1293 REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
1294 REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
1295 ath_dbg(common, ATH_DBG_RESET,
1296 "** BB mode: BB_gen_controls=0x%08x **\n",
1297 REG_READ(ah, AR_PHY_GEN_CTRL));
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001298
Felix Fietkaub5bfc562010-10-08 22:13:53 +02001299#define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
1300 if (common->cc_survey.cycles)
Joe Perches226afe62010-12-02 19:12:37 -08001301 ath_dbg(common, ATH_DBG_RESET,
1302 "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
1303 PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001304
Joe Perches226afe62010-12-02 19:12:37 -08001305 ath_dbg(common, ATH_DBG_RESET,
1306 "==== BB update: done ====\n\n");
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001307}
1308EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);