blob: b34a9e91edd80ff4616cb3f844f5c5341e09b1ef [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 */
78 channelSel = CHANSEL_2G(freq);
79 /* Set to 2G mode */
80 bMode = 1;
81 } else {
82 channelSel = CHANSEL_5G(freq);
83 /* Doubler is ON, so, divide channelSel by 2. */
84 channelSel >>= 1;
85 /* Set to 5G mode */
86 bMode = 0;
87 }
88
89 /* Enable fractional mode for all channels */
90 fracMode = 1;
91 aModeRefSel = 0;
92 loadSynthChannel = 0;
93
94 reg32 = (bMode << 29);
95 REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
96
97 /* Enable Long shift Select for Synthesizer */
98 REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
99 AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
100
101 /* Program Synth. setting */
102 reg32 = (channelSel << 2) | (fracMode << 30) |
103 (aModeRefSel << 28) | (loadSynthChannel << 31);
104 REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
105
106 /* Toggle Load Synth channel bit */
107 loadSynthChannel = 1;
108 reg32 = (channelSel << 2) | (fracMode << 30) |
109 (aModeRefSel << 28) | (loadSynthChannel << 31);
110 REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
111
112 ah->curchan = chan;
113 ah->curchan_rad_index = -1;
114
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400115 return 0;
116}
117
118/**
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400119 * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400120 * @ah: atheros hardware structure
121 * @chan:
122 *
123 * For single-chip solutions. Converts to baseband spur frequency given the
124 * input channel frequency and compute register settings below.
125 *
126 * Spur mitigation for MRC CCK
127 */
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400128static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
129 struct ath9k_channel *chan)
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400130{
Joe Perches07b2fa52010-11-20 18:38:53 -0800131 static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
Felix Fietkauca375552010-04-15 17:38:35 -0400132 int cur_bb_spur, negative = 0, cck_spur_freq;
133 int i;
134
135 /*
136 * Need to verify range +/- 10 MHz in control channel, otherwise spur
137 * is out-of-band and can be ignored.
138 */
139
140 for (i = 0; i < 4; i++) {
141 negative = 0;
142 cur_bb_spur = spur_freq[i] - chan->channel;
143
144 if (cur_bb_spur < 0) {
145 negative = 1;
146 cur_bb_spur = -cur_bb_spur;
147 }
148 if (cur_bb_spur < 10) {
149 cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
150
151 if (negative == 1)
152 cck_spur_freq = -cck_spur_freq;
153
154 cck_spur_freq = cck_spur_freq & 0xfffff;
155
156 REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
157 AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
158 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
159 AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
160 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
161 AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
162 0x2);
163 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
164 AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
165 0x1);
166 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
167 AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
168 cck_spur_freq);
169
170 return;
171 }
172 }
173
174 REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
175 AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
176 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
177 AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
178 REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
179 AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400180}
181
Luis R. Rodriguez1547da32010-04-15 17:39:15 -0400182/* Clean all spur register fields */
183static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
184{
185 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
186 AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
187 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
188 AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
189 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
190 AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
191 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
192 AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
193 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
194 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
195 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
196 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
197 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
198 AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
199 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
200 AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
201 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
202 AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
203
204 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
205 AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
206 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
207 AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
208 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
209 AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
210 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
211 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
212 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
213 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
214 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
215 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
216 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
217 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
218 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
219 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
220 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
221 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
222 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
223 AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
224}
225
226static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
227 int freq_offset,
228 int spur_freq_sd,
229 int spur_delta_phase,
230 int spur_subchannel_sd)
231{
232 int mask_index = 0;
233
234 /* OFDM Spur mitigation */
235 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
236 AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
237 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
238 AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
239 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
240 AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
241 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
242 AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
243 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
244 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
245 REG_RMW_FIELD(ah, AR_PHY_TIMING11,
246 AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
247 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
248 AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
249 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
250 AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
251 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
252 AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
253
254 if (REG_READ_FIELD(ah, AR_PHY_MODE,
255 AR_PHY_MODE_DYNAMIC) == 0x1)
256 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
257 AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
258
259 mask_index = (freq_offset << 4) / 5;
260 if (mask_index < 0)
261 mask_index = mask_index - 1;
262
263 mask_index = mask_index & 0x7f;
264
265 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
266 AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
267 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
268 AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
269 REG_RMW_FIELD(ah, AR_PHY_TIMING4,
270 AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
271 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
272 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
273 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
274 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
275 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
276 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
277 REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
278 AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
279 REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
280 AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
281 REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
282 AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
283 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
284 AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
285}
286
287static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
288 struct ath9k_channel *chan,
289 int freq_offset)
290{
291 int spur_freq_sd = 0;
292 int spur_subchannel_sd = 0;
293 int spur_delta_phase = 0;
294
295 if (IS_CHAN_HT40(chan)) {
296 if (freq_offset < 0) {
297 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
298 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
299 spur_subchannel_sd = 1;
300 else
301 spur_subchannel_sd = 0;
302
303 spur_freq_sd = ((freq_offset + 10) << 9) / 11;
304
305 } else {
306 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
307 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
308 spur_subchannel_sd = 0;
309 else
310 spur_subchannel_sd = 1;
311
312 spur_freq_sd = ((freq_offset - 10) << 9) / 11;
313
314 }
315
316 spur_delta_phase = (freq_offset << 17) / 5;
317
318 } else {
319 spur_subchannel_sd = 0;
320 spur_freq_sd = (freq_offset << 9) /11;
321 spur_delta_phase = (freq_offset << 18) / 5;
322 }
323
324 spur_freq_sd = spur_freq_sd & 0x3ff;
325 spur_delta_phase = spur_delta_phase & 0xfffff;
326
327 ar9003_hw_spur_ofdm(ah,
328 freq_offset,
329 spur_freq_sd,
330 spur_delta_phase,
331 spur_subchannel_sd);
332}
333
334/* Spur mitigation for OFDM */
335static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
336 struct ath9k_channel *chan)
337{
338 int synth_freq;
339 int range = 10;
340 int freq_offset = 0;
341 int mode;
342 u8* spurChansPtr;
343 unsigned int i;
344 struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
345
346 if (IS_CHAN_5GHZ(chan)) {
347 spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
348 mode = 0;
349 }
350 else {
351 spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
352 mode = 1;
353 }
354
355 if (spurChansPtr[0] == 0)
356 return; /* No spur in the mode */
357
358 if (IS_CHAN_HT40(chan)) {
359 range = 19;
360 if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
361 AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
362 synth_freq = chan->channel - 10;
363 else
364 synth_freq = chan->channel + 10;
365 } else {
366 range = 10;
367 synth_freq = chan->channel;
368 }
369
370 ar9003_hw_spur_ofdm_clear(ah);
371
372 for (i = 0; spurChansPtr[i] && i < 5; i++) {
373 freq_offset = FBIN2FREQ(spurChansPtr[i], mode) - synth_freq;
374 if (abs(freq_offset) < range) {
375 ar9003_hw_spur_ofdm_work(ah, chan, freq_offset);
376 break;
377 }
378 }
379}
380
381static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
382 struct ath9k_channel *chan)
383{
384 ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
385 ar9003_hw_spur_mitigate_ofdm(ah, chan);
386}
387
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400388static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
389 struct ath9k_channel *chan)
390{
Felix Fietkau317d3322010-04-15 17:38:34 -0400391 u32 pll;
392
393 pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
394
395 if (chan && IS_CHAN_HALF_RATE(chan))
396 pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
397 else if (chan && IS_CHAN_QUARTER_RATE(chan))
398 pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
399
Felix Fietkau14bc1102010-04-26 15:04:30 -0400400 pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
Felix Fietkau317d3322010-04-15 17:38:34 -0400401
402 return pll;
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400403}
404
405static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
406 struct ath9k_channel *chan)
407{
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400408 u32 phymode;
409 u32 enableDacFifo = 0;
410
411 enableDacFifo =
412 (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
413
414 /* Enable 11n HT, 20 MHz */
415 phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 | AR_PHY_GC_WALSH |
416 AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
417
418 /* Configure baseband for dynamic 20/40 operation */
419 if (IS_CHAN_HT40(chan)) {
420 phymode |= AR_PHY_GC_DYN2040_EN;
421 /* Configure control (primary) channel at +-10MHz */
422 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
423 (chan->chanmode == CHANNEL_G_HT40PLUS))
424 phymode |= AR_PHY_GC_DYN2040_PRI_CH;
425
426 }
427
428 /* make sure we preserve INI settings */
429 phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
430 /* turn off Green Field detection for STA for now */
431 phymode &= ~AR_PHY_GC_GF_DETECT_EN;
432
433 REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
434
435 /* Configure MAC for 20/40 operation */
436 ath9k_hw_set11nmac2040(ah);
437
438 /* global transmit timeout (25 TUs default)*/
439 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
440 /* carrier sense timeout */
441 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400442}
443
444static void ar9003_hw_init_bb(struct ath_hw *ah,
445 struct ath9k_channel *chan)
446{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400447 u32 synthDelay;
448
449 /*
450 * Wait for the frequency synth to settle (synth goes on
451 * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
452 * Value is in 100ns increments.
453 */
454 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
455 if (IS_CHAN_B(chan))
456 synthDelay = (4 * synthDelay) / 22;
457 else
458 synthDelay /= 10;
459
460 /* Activate the PHY (includes baseband activate + synthesizer on) */
461 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
462
463 /*
464 * There is an issue if the AP starts the calibration before
465 * the base band timeout completes. This could result in the
466 * rx_clear false triggering. As a workaround we add delay an
467 * extra BASE_ACTIVATE_DELAY usecs to ensure this condition
468 * does not happen.
469 */
470 udelay(synthDelay + BASE_ACTIVATE_DELAY);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400471}
472
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400473void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
474{
475 switch (rx) {
476 case 0x5:
477 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
478 AR_PHY_SWAP_ALT_CHAIN);
479 case 0x3:
480 case 0x1:
481 case 0x2:
482 case 0x7:
483 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
484 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
485 break;
486 default:
487 break;
488 }
489
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +0530490 if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7))
491 REG_WRITE(ah, AR_SELFGEN_MASK, 0x3);
492 else
493 REG_WRITE(ah, AR_SELFGEN_MASK, tx);
494
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400495 if (tx == 0x5) {
496 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
497 AR_PHY_SWAP_ALT_CHAIN);
498 }
499}
500
501/*
502 * Override INI values with chip specific configuration.
503 */
504static void ar9003_hw_override_ini(struct ath_hw *ah)
505{
506 u32 val;
507
508 /*
509 * Set the RX_ABORT and RX_DIS and clear it only after
510 * RXE is set for MAC. This prevents frames with
511 * corrupted descriptor status.
512 */
513 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
514
515 /*
516 * For AR9280 and above, there is a new feature that allows
517 * Multicast search based on both MAC Address and Key ID. By default,
518 * this feature is enabled. But since the driver is not using this
519 * feature, we switch it off; otherwise multicast search based on
520 * MAC addr only will fail.
521 */
522 val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
523 REG_WRITE(ah, AR_PCU_MISC_MODE2,
524 val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
525}
526
527static void ar9003_hw_prog_ini(struct ath_hw *ah,
528 struct ar5416IniArray *iniArr,
529 int column)
530{
531 unsigned int i, regWrites = 0;
532
533 /* New INI format: Array may be undefined (pre, core, post arrays) */
534 if (!iniArr->ia_array)
535 return;
536
537 /*
538 * New INI format: Pre, core, and post arrays for a given subsystem
539 * may be modal (> 2 columns) or non-modal (2 columns). Determine if
540 * the array is non-modal and force the column to 1.
541 */
542 if (column >= iniArr->ia_columns)
543 column = 1;
544
545 for (i = 0; i < iniArr->ia_rows; i++) {
546 u32 reg = INI_RA(iniArr, i, 0);
547 u32 val = INI_RA(iniArr, i, column);
548
Felix Fietkaub2ccc502010-07-30 21:02:12 +0200549 if (reg >= 0x16000 && reg < 0x17000)
550 ath9k_hw_analog_shift_regwrite(ah, reg, val);
551 else
552 REG_WRITE(ah, reg, val);
553
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400554 DO_DELAY(regWrites);
555 }
556}
557
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400558static int ar9003_hw_process_ini(struct ath_hw *ah,
559 struct ath9k_channel *chan)
560{
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400561 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
562 unsigned int regWrites = 0, i;
563 struct ieee80211_channel *channel = chan->chan;
564 u32 modesIndex, freqIndex;
565
566 switch (chan->chanmode) {
567 case CHANNEL_A:
568 case CHANNEL_A_HT20:
569 modesIndex = 1;
570 freqIndex = 1;
571 break;
572 case CHANNEL_A_HT40PLUS:
573 case CHANNEL_A_HT40MINUS:
574 modesIndex = 2;
575 freqIndex = 1;
576 break;
577 case CHANNEL_G:
578 case CHANNEL_G_HT20:
579 case CHANNEL_B:
580 modesIndex = 4;
581 freqIndex = 2;
582 break;
583 case CHANNEL_G_HT40PLUS:
584 case CHANNEL_G_HT40MINUS:
585 modesIndex = 3;
586 freqIndex = 2;
587 break;
588
589 default:
590 return -EINVAL;
591 }
592
593 for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
594 ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
595 ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
596 ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
597 ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
598 }
599
600 REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
601 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
602
603 /*
604 * For 5GHz channels requiring Fast Clock, apply
605 * different modal values.
606 */
Felix Fietkau6b42e8d2010-04-26 15:04:35 -0400607 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400608 REG_WRITE_ARRAY(&ah->iniModesAdditional,
609 modesIndex, regWrites);
610
611 ar9003_hw_override_ini(ah);
612 ar9003_hw_set_channel_regs(ah, chan);
613 ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
614
615 /* Set TX power */
616 ah->eep_ops->set_txpower(ah, chan,
617 ath9k_regd_get_ctl(regulatory, chan),
618 channel->max_antenna_gain * 2,
619 channel->max_power * 2,
620 min((u32) MAX_RATE_POWER,
Felix Fietkaude40f312010-10-20 03:08:53 +0200621 (u32) regulatory->power_limit), false);
Luis R. Rodriguezcffb5e42010-04-15 17:38:38 -0400622
623 return 0;
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400624}
625
626static void ar9003_hw_set_rfmode(struct ath_hw *ah,
627 struct ath9k_channel *chan)
628{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400629 u32 rfMode = 0;
630
631 if (chan == NULL)
632 return;
633
634 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
635 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
636
Felix Fietkau6b42e8d2010-04-26 15:04:35 -0400637 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400638 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
639
640 REG_WRITE(ah, AR_PHY_MODE, rfMode);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400641}
642
643static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
644{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400645 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400646}
647
648static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
649 struct ath9k_channel *chan)
650{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400651 u32 coef_scaled, ds_coef_exp, ds_coef_man;
652 u32 clockMhzScaled = 0x64000000;
653 struct chan_centers centers;
654
655 /*
656 * half and quarter rate can divide the scaled clock by 2 or 4
657 * scale for selected channel bandwidth
658 */
659 if (IS_CHAN_HALF_RATE(chan))
660 clockMhzScaled = clockMhzScaled >> 1;
661 else if (IS_CHAN_QUARTER_RATE(chan))
662 clockMhzScaled = clockMhzScaled >> 2;
663
664 /*
665 * ALGO -> coef = 1e8/fcarrier*fclock/40;
666 * scaled coef to provide precision for this floating calculation
667 */
668 ath9k_hw_get_channel_centers(ah, chan, &centers);
669 coef_scaled = clockMhzScaled / centers.synth_center;
670
671 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
672 &ds_coef_exp);
673
674 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
675 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
676 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
677 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
678
679 /*
680 * For Short GI,
681 * scaled coeff is 9/10 that of normal coeff
682 */
683 coef_scaled = (9 * coef_scaled) / 10;
684
685 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
686 &ds_coef_exp);
687
688 /* for short gi */
689 REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
690 AR_PHY_SGI_DSC_MAN, ds_coef_man);
691 REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
692 AR_PHY_SGI_DSC_EXP, ds_coef_exp);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400693}
694
695static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
696{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400697 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
698 return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
699 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400700}
701
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400702/*
703 * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
704 * Read the phy active delay register. Value is in 100ns increments.
705 */
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400706static void ar9003_hw_rfbus_done(struct ath_hw *ah)
707{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400708 u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
709 if (IS_CHAN_B(ah->curchan))
710 synthDelay = (4 * synthDelay) / 22;
711 else
712 synthDelay /= 10;
713
714 udelay(synthDelay + BASE_ACTIVATE_DELAY);
715
716 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400717}
718
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400719/*
720 * Set the interrupt and GPIO values so the ISR can disable RF
721 * on a switch signal. Assumes GPIO port and interrupt polarity
722 * are set prior to call.
723 */
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400724static void ar9003_hw_enable_rfkill(struct ath_hw *ah)
725{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400726 /* Connect rfsilent_bb_l to baseband */
727 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
728 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
729 /* Set input mux for rfsilent_bb_l to GPIO #0 */
730 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
731 AR_GPIO_INPUT_MUX2_RFSILENT);
732
733 /*
734 * Configure the desired GPIO port for input and
735 * enable baseband rf silence.
736 */
737 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
738 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400739}
740
741static void ar9003_hw_set_diversity(struct ath_hw *ah, bool value)
742{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400743 u32 v = REG_READ(ah, AR_PHY_CCK_DETECT);
744 if (value)
745 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
746 else
747 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
748 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400749}
750
Felix Fietkauc16fcb42010-04-15 17:38:39 -0400751static bool ar9003_hw_ani_control(struct ath_hw *ah,
752 enum ath9k_ani_cmd cmd, int param)
753{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400754 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400755 struct ath9k_channel *chan = ah->curchan;
Felix Fietkau093115b2010-10-04 20:09:47 +0200756 struct ar5416AniState *aniState = &chan->ani;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400757 s32 value, value2;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400758
759 switch (cmd & ah->ani_function) {
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400760 case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400761 /*
762 * on == 1 means ofdm weak signal detection is ON
763 * on == 1 is the default, for less noise immunity
764 *
765 * on == 0 means ofdm weak signal detection is OFF
766 * on == 0 means more noise imm
767 */
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400768 u32 on = param ? 1 : 0;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400769 /*
770 * make register setting for default
771 * (weak sig detect ON) come from INI file
772 */
773 int m1ThreshLow = on ?
774 aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
775 int m2ThreshLow = on ?
776 aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
777 int m1Thresh = on ?
778 aniState->iniDef.m1Thresh : m1Thresh_off;
779 int m2Thresh = on ?
780 aniState->iniDef.m2Thresh : m2Thresh_off;
781 int m2CountThr = on ?
782 aniState->iniDef.m2CountThr : m2CountThr_off;
783 int m2CountThrLow = on ?
784 aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
785 int m1ThreshLowExt = on ?
786 aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
787 int m2ThreshLowExt = on ?
788 aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
789 int m1ThreshExt = on ?
790 aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
791 int m2ThreshExt = on ?
792 aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400793
794 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
795 AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400796 m1ThreshLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400797 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
798 AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400799 m2ThreshLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400800 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400801 AR_PHY_SFCORR_M1_THRESH, m1Thresh);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400802 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400803 AR_PHY_SFCORR_M2_THRESH, m2Thresh);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400804 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400805 AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400806 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
807 AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400808 m2CountThrLow);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400809
810 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400811 AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400812 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400813 AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400814 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400815 AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400816 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400817 AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400818
819 if (on)
820 REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
821 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
822 else
823 REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
824 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
825
826 if (!on != aniState->ofdmWeakSigDetectOff) {
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400827 ath_print(common, ATH_DBG_ANI,
828 "** ch %d: ofdm weak signal: %s=>%s\n",
829 chan->channel,
830 !aniState->ofdmWeakSigDetectOff ?
831 "on" : "off",
832 on ? "on" : "off");
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400833 if (on)
834 ah->stats.ast_ani_ofdmon++;
835 else
836 ah->stats.ast_ani_ofdmoff++;
837 aniState->ofdmWeakSigDetectOff = !on;
838 }
839 break;
840 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400841 case ATH9K_ANI_FIRSTEP_LEVEL:{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400842 u32 level = param;
843
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400844 if (level >= ARRAY_SIZE(firstep_table)) {
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400845 ath_print(common, ATH_DBG_ANI,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400846 "ATH9K_ANI_FIRSTEP_LEVEL: level "
847 "out of range (%u > %u)\n",
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400848 level,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400849 (unsigned) ARRAY_SIZE(firstep_table));
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400850 return false;
851 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400852
853 /*
854 * make register setting relative to default
855 * from INI file & cap value
856 */
857 value = firstep_table[level] -
858 firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
859 aniState->iniDef.firstep;
860 if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
861 value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
862 if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
863 value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400864 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
865 AR_PHY_FIND_SIG_FIRSTEP,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400866 value);
867 /*
868 * we need to set first step low register too
869 * make register setting relative to default
870 * from INI file & cap value
871 */
872 value2 = firstep_table[level] -
873 firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
874 aniState->iniDef.firstepLow;
875 if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
876 value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
877 if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
878 value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
879
880 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
881 AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
882
883 if (level != aniState->firstepLevel) {
884 ath_print(common, ATH_DBG_ANI,
885 "** ch %d: level %d=>%d[def:%d] "
886 "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_print(common, ATH_DBG_ANI,
894 "** ch %d: level %d=>%d[def:%d] "
895 "firstep_low[level]=%d ini=%d\n",
896 chan->channel,
897 aniState->firstepLevel,
898 level,
899 ATH9K_ANI_FIRSTEP_LVL_NEW,
900 value2,
901 aniState->iniDef.firstepLow);
902 if (level > aniState->firstepLevel)
903 ah->stats.ast_ani_stepup++;
904 else if (level < aniState->firstepLevel)
905 ah->stats.ast_ani_stepdown++;
906 aniState->firstepLevel = level;
907 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400908 break;
909 }
910 case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400911 u32 level = param;
912
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400913 if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400914 ath_print(common, ATH_DBG_ANI,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400915 "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level "
916 "out of range (%u > %u)\n",
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400917 level,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400918 (unsigned) ARRAY_SIZE(cycpwrThr1_table));
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400919 return false;
920 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400921 /*
922 * make register setting relative to default
923 * from INI file & cap value
924 */
925 value = cycpwrThr1_table[level] -
926 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
927 aniState->iniDef.cycpwrThr1;
928 if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
929 value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
930 if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
931 value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400932 REG_RMW_FIELD(ah, AR_PHY_TIMING5,
933 AR_PHY_TIMING5_CYCPWR_THR1,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400934 value);
935
936 /*
937 * set AR_PHY_EXT_CCA for extension channel
938 * make register setting relative to default
939 * from INI file & cap value
940 */
941 value2 = cycpwrThr1_table[level] -
942 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
943 aniState->iniDef.cycpwrThr1Ext;
944 if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
945 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
946 if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
947 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
948 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
949 AR_PHY_EXT_CYCPWR_THR1, value2);
950
951 if (level != aniState->spurImmunityLevel) {
952 ath_print(common, ATH_DBG_ANI,
953 "** ch %d: level %d=>%d[def:%d] "
954 "cycpwrThr1[level]=%d ini=%d\n",
955 chan->channel,
956 aniState->spurImmunityLevel,
957 level,
958 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
959 value,
960 aniState->iniDef.cycpwrThr1);
961 ath_print(common, ATH_DBG_ANI,
962 "** ch %d: level %d=>%d[def:%d] "
963 "cycpwrThr1Ext[level]=%d ini=%d\n",
964 chan->channel,
965 aniState->spurImmunityLevel,
966 level,
967 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
968 value2,
969 aniState->iniDef.cycpwrThr1Ext);
970 if (level > aniState->spurImmunityLevel)
971 ah->stats.ast_ani_spurup++;
972 else if (level < aniState->spurImmunityLevel)
973 ah->stats.ast_ani_spurdown++;
974 aniState->spurImmunityLevel = level;
975 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -0400976 break;
977 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400978 case ATH9K_ANI_MRC_CCK:{
979 /*
980 * is_on == 1 means MRC CCK ON (default, less noise imm)
981 * is_on == 0 means MRC CCK is OFF (more noise imm)
982 */
983 bool is_on = param ? 1 : 0;
984 REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
985 AR_PHY_MRC_CCK_ENABLE, is_on);
986 REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
987 AR_PHY_MRC_CCK_MUX_REG, is_on);
988 if (!is_on != aniState->mrcCCKOff) {
989 ath_print(common, ATH_DBG_ANI,
990 "** ch %d: MRC CCK: %s=>%s\n",
991 chan->channel,
992 !aniState->mrcCCKOff ? "on" : "off",
993 is_on ? "on" : "off");
994 if (is_on)
995 ah->stats.ast_ani_ccklow++;
996 else
997 ah->stats.ast_ani_cckhigh++;
998 aniState->mrcCCKOff = !is_on;
999 }
1000 break;
1001 }
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001002 case ATH9K_ANI_PRESENT:
1003 break;
1004 default:
1005 ath_print(common, ATH_DBG_ANI,
1006 "invalid cmd %u\n", cmd);
1007 return false;
1008 }
1009
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001010 ath_print(common, ATH_DBG_ANI,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001011 "ANI parameters: SI=%d, ofdmWS=%s FS=%d "
Felix Fietkau9dbebc72010-10-03 19:07:17 +02001012 "MRCcck=%s listenTime=%d "
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001013 "ofdmErrs=%d cckErrs=%d\n",
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001014 aniState->spurImmunityLevel,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001015 !aniState->ofdmWeakSigDetectOff ? "on" : "off",
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001016 aniState->firstepLevel,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001017 !aniState->mrcCCKOff ? "on" : "off",
1018 aniState->listenTime,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001019 aniState->ofdmPhyErrCount,
1020 aniState->cckPhyErrCount);
Luis R. Rodriguezaf914a92010-04-15 17:38:40 -04001021 return true;
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001022}
1023
Felix Fietkau641d9922010-04-15 17:38:49 -04001024static void ar9003_hw_do_getnf(struct ath_hw *ah,
1025 int16_t nfarray[NUM_NF_READINGS])
1026{
Felix Fietkau641d9922010-04-15 17:38:49 -04001027 int16_t nf;
1028
1029 nf = MS(REG_READ(ah, AR_PHY_CCA_0), AR_PHY_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001030 nfarray[0] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001031
1032 nf = MS(REG_READ(ah, AR_PHY_CCA_1), AR_PHY_CH1_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001033 nfarray[1] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001034
1035 nf = MS(REG_READ(ah, AR_PHY_CCA_2), AR_PHY_CH2_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001036 nfarray[2] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001037
Felix Fietkau866b7782010-07-23 04:07:48 +02001038 if (!IS_CHAN_HT40(ah->curchan))
1039 return;
1040
Felix Fietkau641d9922010-04-15 17:38:49 -04001041 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001042 nfarray[3] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001043
1044 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_1), AR_PHY_CH1_EXT_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001045 nfarray[4] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001046
1047 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA_2), AR_PHY_CH2_EXT_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001048 nfarray[5] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001049}
1050
Felix Fietkauf2552e22010-07-02 00:09:50 +02001051static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
Felix Fietkau641d9922010-04-15 17:38:49 -04001052{
Felix Fietkauf2552e22010-07-02 00:09:50 +02001053 ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
1054 ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
1055 ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
1056 ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
1057 ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
1058 ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
Felix Fietkau641d9922010-04-15 17:38:49 -04001059}
1060
Luis R. Rodriguezdf23aca2010-04-15 17:39:11 -04001061/*
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001062 * Initialize the ANI register values with default (ini) values.
1063 * This routine is called during a (full) hardware reset after
1064 * all the registers are initialised from the INI.
1065 */
1066static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
1067{
1068 struct ar5416AniState *aniState;
1069 struct ath_common *common = ath9k_hw_common(ah);
1070 struct ath9k_channel *chan = ah->curchan;
1071 struct ath9k_ani_default *iniDef;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001072 u32 val;
1073
Felix Fietkau093115b2010-10-04 20:09:47 +02001074 aniState = &ah->curchan->ani;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001075 iniDef = &aniState->iniDef;
1076
1077 ath_print(common, ATH_DBG_ANI,
1078 "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
1079 ah->hw_version.macVersion,
1080 ah->hw_version.macRev,
1081 ah->opmode,
1082 chan->channel,
1083 chan->channelFlags);
1084
1085 val = REG_READ(ah, AR_PHY_SFCORR);
1086 iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
1087 iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
1088 iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
1089
1090 val = REG_READ(ah, AR_PHY_SFCORR_LOW);
1091 iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
1092 iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
1093 iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
1094
1095 val = REG_READ(ah, AR_PHY_SFCORR_EXT);
1096 iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
1097 iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
1098 iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
1099 iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
1100 iniDef->firstep = REG_READ_FIELD(ah,
1101 AR_PHY_FIND_SIG,
1102 AR_PHY_FIND_SIG_FIRSTEP);
1103 iniDef->firstepLow = REG_READ_FIELD(ah,
1104 AR_PHY_FIND_SIG_LOW,
1105 AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
1106 iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
1107 AR_PHY_TIMING5,
1108 AR_PHY_TIMING5_CYCPWR_THR1);
1109 iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
1110 AR_PHY_EXT_CCA,
1111 AR_PHY_EXT_CYCPWR_THR1);
1112
1113 /* these levels just got reset to defaults by the INI */
1114 aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
1115 aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
1116 aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
1117 aniState->mrcCCKOff = !ATH9K_ANI_ENABLE_MRC_CCK;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001118}
1119
Felix Fietkau4e8c14e2010-11-11 03:18:38 +01001120static void ar9003_hw_set_radar_params(struct ath_hw *ah,
1121 struct ath_hw_radar_conf *conf)
1122{
1123 u32 radar_0 = 0, radar_1 = 0;
1124
1125 if (!conf) {
1126 REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
1127 return;
1128 }
1129
1130 radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
1131 radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
1132 radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
1133 radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
1134 radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
1135 radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
1136
1137 radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
1138 radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
1139 radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
1140 radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
1141 radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
1142
1143 REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
1144 REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
1145 if (conf->ext_channel)
1146 REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
1147 else
1148 REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
1149}
1150
Felix Fietkauc5d08552010-11-13 20:22:41 +01001151static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
1152{
1153 struct ath_hw_radar_conf *conf = &ah->radar_conf;
1154
1155 conf->fir_power = -28;
1156 conf->radar_rssi = 0;
1157 conf->pulse_height = 10;
1158 conf->pulse_rssi = 24;
1159 conf->pulse_inband = 8;
1160 conf->pulse_maxlen = 255;
1161 conf->pulse_inband_step = 12;
1162 conf->radar_inband = 8;
1163}
1164
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001165void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
1166{
1167 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
Joe Perches07b2fa52010-11-20 18:38:53 -08001168 static const u32 ar9300_cca_regs[6] = {
Felix Fietkaubbacee12010-07-11 15:44:42 +02001169 AR_PHY_CCA_0,
1170 AR_PHY_CCA_1,
1171 AR_PHY_CCA_2,
1172 AR_PHY_EXT_CCA,
1173 AR_PHY_EXT_CCA_1,
1174 AR_PHY_EXT_CCA_2,
1175 };
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001176
1177 priv_ops->rf_set_freq = ar9003_hw_set_channel;
1178 priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
1179 priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
1180 priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
1181 priv_ops->init_bb = ar9003_hw_init_bb;
1182 priv_ops->process_ini = ar9003_hw_process_ini;
1183 priv_ops->set_rfmode = ar9003_hw_set_rfmode;
1184 priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
1185 priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
1186 priv_ops->rfbus_req = ar9003_hw_rfbus_req;
1187 priv_ops->rfbus_done = ar9003_hw_rfbus_done;
1188 priv_ops->enable_rfkill = ar9003_hw_enable_rfkill;
1189 priv_ops->set_diversity = ar9003_hw_set_diversity;
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001190 priv_ops->ani_control = ar9003_hw_ani_control;
Felix Fietkau641d9922010-04-15 17:38:49 -04001191 priv_ops->do_getnf = ar9003_hw_do_getnf;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001192 priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
Felix Fietkau4e8c14e2010-11-11 03:18:38 +01001193 priv_ops->set_radar_params = ar9003_hw_set_radar_params;
Felix Fietkauf2552e22010-07-02 00:09:50 +02001194
1195 ar9003_hw_set_nf_limits(ah);
Felix Fietkauc5d08552010-11-13 20:22:41 +01001196 ar9003_hw_set_radar_conf(ah);
Felix Fietkaubbacee12010-07-11 15:44:42 +02001197 memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
Luis R. Rodriguez8525f282010-04-15 17:38:19 -04001198}
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001199
1200void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
1201{
1202 struct ath_common *common = ath9k_hw_common(ah);
1203 u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
1204 u32 val, idle_count;
1205
1206 if (!idle_tmo_ms) {
1207 /* disable IRQ, disable chip-reset for BB panic */
1208 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
1209 REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
1210 ~(AR_PHY_WATCHDOG_RST_ENABLE |
1211 AR_PHY_WATCHDOG_IRQ_ENABLE));
1212
1213 /* disable watchdog in non-IDLE mode, disable in IDLE mode */
1214 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
1215 REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
1216 ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
1217 AR_PHY_WATCHDOG_IDLE_ENABLE));
1218
1219 ath_print(common, ATH_DBG_RESET, "Disabled BB Watchdog\n");
1220 return;
1221 }
1222
1223 /* enable IRQ, disable chip-reset for BB watchdog */
1224 val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
1225 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
1226 (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
1227 ~AR_PHY_WATCHDOG_RST_ENABLE);
1228
1229 /* bound limit to 10 secs */
1230 if (idle_tmo_ms > 10000)
1231 idle_tmo_ms = 10000;
1232
1233 /*
1234 * The time unit for watchdog event is 2^15 44/88MHz cycles.
1235 *
1236 * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
1237 * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
1238 *
1239 * Given we use fast clock now in 5 GHz, these time units should
1240 * be common for both 2 GHz and 5 GHz.
1241 */
1242 idle_count = (100 * idle_tmo_ms) / 74;
1243 if (ah->curchan && IS_CHAN_HT40(ah->curchan))
1244 idle_count = (100 * idle_tmo_ms) / 37;
1245
1246 /*
1247 * enable watchdog in non-IDLE mode, disable in IDLE mode,
1248 * set idle time-out.
1249 */
1250 REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
1251 AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
1252 AR_PHY_WATCHDOG_IDLE_MASK |
1253 (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
1254
1255 ath_print(common, ATH_DBG_RESET,
1256 "Enabled BB Watchdog timeout (%u ms)\n",
1257 idle_tmo_ms);
1258}
1259
1260void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
1261{
1262 /*
1263 * we want to avoid printing in ISR context so we save the
1264 * watchdog status to be printed later in bottom half context.
1265 */
1266 ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
1267
1268 /*
1269 * the watchdog timer should reset on status read but to be sure
1270 * sure we write 0 to the watchdog status bit.
1271 */
1272 REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
1273 ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
1274}
1275
1276void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
1277{
1278 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau9dbebc72010-10-03 19:07:17 +02001279 u32 status;
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001280
1281 if (likely(!(common->debug_mask & ATH_DBG_RESET)))
1282 return;
1283
1284 status = ah->bb_watchdog_last_status;
1285 ath_print(common, ATH_DBG_RESET,
1286 "\n==== BB update: BB status=0x%08x ====\n", status);
1287 ath_print(common, ATH_DBG_RESET,
1288 "** BB state: wd=%u det=%u rdar=%u rOFDM=%d "
1289 "rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
1290 MS(status, AR_PHY_WATCHDOG_INFO),
1291 MS(status, AR_PHY_WATCHDOG_DET_HANG),
1292 MS(status, AR_PHY_WATCHDOG_RADAR_SM),
1293 MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
1294 MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
1295 MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
1296 MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
1297 MS(status, AR_PHY_WATCHDOG_AGC_SM),
1298 MS(status,AR_PHY_WATCHDOG_SRCH_SM));
1299
1300 ath_print(common, ATH_DBG_RESET,
1301 "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
1302 REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
1303 REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
1304 ath_print(common, ATH_DBG_RESET,
1305 "** BB mode: BB_gen_controls=0x%08x **\n",
1306 REG_READ(ah, AR_PHY_GEN_CTRL));
1307
Felix Fietkaub5bfc562010-10-08 22:13:53 +02001308#define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
1309 if (common->cc_survey.cycles)
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001310 ath_print(common, ATH_DBG_RESET,
1311 "** BB busy times: rx_clear=%d%%, "
1312 "rx_frame=%d%%, tx_frame=%d%% **\n",
Felix Fietkaub5bfc562010-10-08 22:13:53 +02001313 PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001314
1315 ath_print(common, ATH_DBG_RESET,
1316 "==== BB update: done ====\n\n");
1317}
1318EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);