blob: 06e34d293dc8a59e1727cde6ee716d13b3cfa904 [file] [log] [blame]
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001/*
2 * Copyright (c) 2008-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"
18#include "hw-ops.h"
19#include "../regd.h"
20#include "ar9002_phy.h"
21
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -040022/* All code below is for AR5008, AR9001, AR9002 */
23
24static const int firstep_table[] =
25/* level: 0 1 2 3 4 5 6 7 8 */
26 { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
27
28static const int cycpwrThr1_table[] =
29/* level: 0 1 2 3 4 5 6 7 8 */
30 { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
31
32/*
33 * register values to turn OFDM weak signal detection OFF
34 */
35static const int m1ThreshLow_off = 127;
36static const int m2ThreshLow_off = 127;
37static const int m1Thresh_off = 127;
38static const int m2Thresh_off = 127;
39static const int m2CountThr_off = 31;
40static const int m2CountThrLow_off = 63;
41static const int m1ThreshLowExt_off = 127;
42static const int m2ThreshLowExt_off = 127;
43static const int m1ThreshExt_off = 127;
44static const int m2ThreshExt_off = 127;
45
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -040046
47/**
48 * ar5008_hw_phy_modify_rx_buffer() - perform analog swizzling of parameters
49 * @rfbuf:
50 * @reg32:
51 * @numBits:
52 * @firstBit:
53 * @column:
54 *
55 * Performs analog "swizzling" of parameters into their location.
56 * Used on external AR2133/AR5133 radios.
57 */
58static void ar5008_hw_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
59 u32 numBits, u32 firstBit,
60 u32 column)
61{
62 u32 tmp32, mask, arrayEntry, lastBit;
63 int32_t bitPosition, bitsLeft;
64
65 tmp32 = ath9k_hw_reverse_bits(reg32, numBits);
66 arrayEntry = (firstBit - 1) / 8;
67 bitPosition = (firstBit - 1) % 8;
68 bitsLeft = numBits;
69 while (bitsLeft > 0) {
70 lastBit = (bitPosition + bitsLeft > 8) ?
71 8 : bitPosition + bitsLeft;
72 mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) <<
73 (column * 8);
74 rfBuf[arrayEntry] &= ~mask;
75 rfBuf[arrayEntry] |= ((tmp32 << bitPosition) <<
76 (column * 8)) & mask;
77 bitsLeft -= 8 - bitPosition;
78 tmp32 = tmp32 >> (8 - bitPosition);
79 bitPosition = 0;
80 arrayEntry++;
81 }
82}
83
84/*
85 * Fix on 2.4 GHz band for orientation sensitivity issue by increasing
86 * rf_pwd_icsyndiv.
87 *
88 * Theoretical Rules:
89 * if 2 GHz band
90 * if forceBiasAuto
91 * if synth_freq < 2412
92 * bias = 0
93 * else if 2412 <= synth_freq <= 2422
94 * bias = 1
95 * else // synth_freq > 2422
96 * bias = 2
97 * else if forceBias > 0
98 * bias = forceBias & 7
99 * else
100 * no change, use value from ini file
101 * else
102 * no change, invalid band
103 *
104 * 1st Mod:
105 * 2422 also uses value of 2
106 * <approved>
107 *
108 * 2nd Mod:
109 * Less than 2412 uses value of 0, 2412 and above uses value of 2
110 */
111static void ar5008_hw_force_bias(struct ath_hw *ah, u16 synth_freq)
112{
113 struct ath_common *common = ath9k_hw_common(ah);
114 u32 tmp_reg;
115 int reg_writes = 0;
116 u32 new_bias = 0;
117
118 if (!AR_SREV_5416(ah) || synth_freq >= 3000)
119 return;
120
Felix Fietkau7a370812010-09-22 12:34:52 +0200121 BUG_ON(AR_SREV_9280_20_OR_LATER(ah));
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400122
123 if (synth_freq < 2412)
124 new_bias = 0;
125 else if (synth_freq < 2422)
126 new_bias = 1;
127 else
128 new_bias = 2;
129
130 /* pre-reverse this field */
131 tmp_reg = ath9k_hw_reverse_bits(new_bias, 3);
132
133 ath_print(common, ATH_DBG_CONFIG,
134 "Force rf_pwd_icsyndiv to %1d on %4d\n",
135 new_bias, synth_freq);
136
137 /* swizzle rf_pwd_icsyndiv */
138 ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data, tmp_reg, 3, 181, 3);
139
140 /* write Bank 6 with new params */
141 REG_WRITE_RF_ARRAY(&ah->iniBank6, ah->analogBank6Data, reg_writes);
142}
143
144/**
145 * ar5008_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios
146 * @ah: atheros hardware stucture
147 * @chan:
148 *
149 * For the external AR2133/AR5133 radios, takes the MHz channel value and set
150 * the channel value. Assumes writes enabled to analog bus and bank6 register
151 * cache in ah->analogBank6Data.
152 */
153static int ar5008_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
154{
155 struct ath_common *common = ath9k_hw_common(ah);
156 u32 channelSel = 0;
157 u32 bModeSynth = 0;
158 u32 aModeRefSel = 0;
159 u32 reg32 = 0;
160 u16 freq;
161 struct chan_centers centers;
162
163 ath9k_hw_get_channel_centers(ah, chan, &centers);
164 freq = centers.synth_center;
165
166 if (freq < 4800) {
167 u32 txctl;
168
169 if (((freq - 2192) % 5) == 0) {
170 channelSel = ((freq - 672) * 2 - 3040) / 10;
171 bModeSynth = 0;
172 } else if (((freq - 2224) % 5) == 0) {
173 channelSel = ((freq - 704) * 2 - 3040) / 10;
174 bModeSynth = 1;
175 } else {
176 ath_print(common, ATH_DBG_FATAL,
177 "Invalid channel %u MHz\n", freq);
178 return -EINVAL;
179 }
180
181 channelSel = (channelSel << 2) & 0xff;
182 channelSel = ath9k_hw_reverse_bits(channelSel, 8);
183
184 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
185 if (freq == 2484) {
186
187 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
188 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
189 } else {
190 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
191 txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
192 }
193
194 } else if ((freq % 20) == 0 && freq >= 5120) {
195 channelSel =
196 ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
197 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
198 } else if ((freq % 10) == 0) {
199 channelSel =
200 ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
201 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
202 aModeRefSel = ath9k_hw_reverse_bits(2, 2);
203 else
204 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
205 } else if ((freq % 5) == 0) {
206 channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
207 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
208 } else {
209 ath_print(common, ATH_DBG_FATAL,
210 "Invalid channel %u MHz\n", freq);
211 return -EINVAL;
212 }
213
214 ar5008_hw_force_bias(ah, freq);
215
216 reg32 =
217 (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
218 (1 << 5) | 0x1;
219
220 REG_WRITE(ah, AR_PHY(0x37), reg32);
221
222 ah->curchan = chan;
223 ah->curchan_rad_index = -1;
224
225 return 0;
226}
227
228/**
229 * ar5008_hw_spur_mitigate - convert baseband spur frequency for external radios
230 * @ah: atheros hardware structure
231 * @chan:
232 *
233 * For non single-chip solutions. Converts to baseband spur frequency given the
234 * input channel frequency and compute register settings below.
235 */
236static void ar5008_hw_spur_mitigate(struct ath_hw *ah,
237 struct ath9k_channel *chan)
238{
239 int bb_spur = AR_NO_SPUR;
240 int bin, cur_bin;
241 int spur_freq_sd;
242 int spur_delta_phase;
243 int denominator;
244 int upper, lower, cur_vit_mask;
245 int tmp, new;
246 int i;
Joe Perches07b2fa52010-11-20 18:38:53 -0800247 static int pilot_mask_reg[4] = {
248 AR_PHY_TIMING7, AR_PHY_TIMING8,
249 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400250 };
Joe Perches07b2fa52010-11-20 18:38:53 -0800251 static int chan_mask_reg[4] = {
252 AR_PHY_TIMING9, AR_PHY_TIMING10,
253 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400254 };
Joe Perches07b2fa52010-11-20 18:38:53 -0800255 static int inc[4] = { 0, 100, 0, 0 };
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400256
257 int8_t mask_m[123];
258 int8_t mask_p[123];
259 int8_t mask_amt;
260 int tmp_mask;
261 int cur_bb_spur;
262 bool is2GHz = IS_CHAN_2GHZ(chan);
263
264 memset(&mask_m, 0, sizeof(int8_t) * 123);
265 memset(&mask_p, 0, sizeof(int8_t) * 123);
266
267 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
268 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
269 if (AR_NO_SPUR == cur_bb_spur)
270 break;
271 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
272 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
273 bb_spur = cur_bb_spur;
274 break;
275 }
276 }
277
278 if (AR_NO_SPUR == bb_spur)
279 return;
280
281 bin = bb_spur * 32;
282
283 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
284 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
285 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
286 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
287 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
288
289 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
290
291 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
292 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
293 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
294 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
295 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
296 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
297
298 spur_delta_phase = ((bb_spur * 524288) / 100) &
299 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
300
301 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
302 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
303
304 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
305 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
306 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
307 REG_WRITE(ah, AR_PHY_TIMING11, new);
308
309 cur_bin = -6000;
310 upper = bin + 100;
311 lower = bin - 100;
312
313 for (i = 0; i < 4; i++) {
314 int pilot_mask = 0;
315 int chan_mask = 0;
316 int bp = 0;
317 for (bp = 0; bp < 30; bp++) {
318 if ((cur_bin > lower) && (cur_bin < upper)) {
319 pilot_mask = pilot_mask | 0x1 << bp;
320 chan_mask = chan_mask | 0x1 << bp;
321 }
322 cur_bin += 100;
323 }
324 cur_bin += inc[i];
325 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
326 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
327 }
328
329 cur_vit_mask = 6100;
330 upper = bin + 120;
331 lower = bin - 120;
332
333 for (i = 0; i < 123; i++) {
334 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
335
336 /* workaround for gcc bug #37014 */
337 volatile int tmp_v = abs(cur_vit_mask - bin);
338
339 if (tmp_v < 75)
340 mask_amt = 1;
341 else
342 mask_amt = 0;
343 if (cur_vit_mask < 0)
344 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
345 else
346 mask_p[cur_vit_mask / 100] = mask_amt;
347 }
348 cur_vit_mask -= 100;
349 }
350
351 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
352 | (mask_m[48] << 26) | (mask_m[49] << 24)
353 | (mask_m[50] << 22) | (mask_m[51] << 20)
354 | (mask_m[52] << 18) | (mask_m[53] << 16)
355 | (mask_m[54] << 14) | (mask_m[55] << 12)
356 | (mask_m[56] << 10) | (mask_m[57] << 8)
357 | (mask_m[58] << 6) | (mask_m[59] << 4)
358 | (mask_m[60] << 2) | (mask_m[61] << 0);
359 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
360 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
361
362 tmp_mask = (mask_m[31] << 28)
363 | (mask_m[32] << 26) | (mask_m[33] << 24)
364 | (mask_m[34] << 22) | (mask_m[35] << 20)
365 | (mask_m[36] << 18) | (mask_m[37] << 16)
366 | (mask_m[48] << 14) | (mask_m[39] << 12)
367 | (mask_m[40] << 10) | (mask_m[41] << 8)
368 | (mask_m[42] << 6) | (mask_m[43] << 4)
369 | (mask_m[44] << 2) | (mask_m[45] << 0);
370 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
371 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
372
373 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
374 | (mask_m[18] << 26) | (mask_m[18] << 24)
375 | (mask_m[20] << 22) | (mask_m[20] << 20)
376 | (mask_m[22] << 18) | (mask_m[22] << 16)
377 | (mask_m[24] << 14) | (mask_m[24] << 12)
378 | (mask_m[25] << 10) | (mask_m[26] << 8)
379 | (mask_m[27] << 6) | (mask_m[28] << 4)
380 | (mask_m[29] << 2) | (mask_m[30] << 0);
381 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
382 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
383
384 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
385 | (mask_m[2] << 26) | (mask_m[3] << 24)
386 | (mask_m[4] << 22) | (mask_m[5] << 20)
387 | (mask_m[6] << 18) | (mask_m[7] << 16)
388 | (mask_m[8] << 14) | (mask_m[9] << 12)
389 | (mask_m[10] << 10) | (mask_m[11] << 8)
390 | (mask_m[12] << 6) | (mask_m[13] << 4)
391 | (mask_m[14] << 2) | (mask_m[15] << 0);
392 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
393 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
394
395 tmp_mask = (mask_p[15] << 28)
396 | (mask_p[14] << 26) | (mask_p[13] << 24)
397 | (mask_p[12] << 22) | (mask_p[11] << 20)
398 | (mask_p[10] << 18) | (mask_p[9] << 16)
399 | (mask_p[8] << 14) | (mask_p[7] << 12)
400 | (mask_p[6] << 10) | (mask_p[5] << 8)
401 | (mask_p[4] << 6) | (mask_p[3] << 4)
402 | (mask_p[2] << 2) | (mask_p[1] << 0);
403 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
404 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
405
406 tmp_mask = (mask_p[30] << 28)
407 | (mask_p[29] << 26) | (mask_p[28] << 24)
408 | (mask_p[27] << 22) | (mask_p[26] << 20)
409 | (mask_p[25] << 18) | (mask_p[24] << 16)
410 | (mask_p[23] << 14) | (mask_p[22] << 12)
411 | (mask_p[21] << 10) | (mask_p[20] << 8)
412 | (mask_p[19] << 6) | (mask_p[18] << 4)
413 | (mask_p[17] << 2) | (mask_p[16] << 0);
414 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
415 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
416
417 tmp_mask = (mask_p[45] << 28)
418 | (mask_p[44] << 26) | (mask_p[43] << 24)
419 | (mask_p[42] << 22) | (mask_p[41] << 20)
420 | (mask_p[40] << 18) | (mask_p[39] << 16)
421 | (mask_p[38] << 14) | (mask_p[37] << 12)
422 | (mask_p[36] << 10) | (mask_p[35] << 8)
423 | (mask_p[34] << 6) | (mask_p[33] << 4)
424 | (mask_p[32] << 2) | (mask_p[31] << 0);
425 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
426 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
427
428 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
429 | (mask_p[59] << 26) | (mask_p[58] << 24)
430 | (mask_p[57] << 22) | (mask_p[56] << 20)
431 | (mask_p[55] << 18) | (mask_p[54] << 16)
432 | (mask_p[53] << 14) | (mask_p[52] << 12)
433 | (mask_p[51] << 10) | (mask_p[50] << 8)
434 | (mask_p[49] << 6) | (mask_p[48] << 4)
435 | (mask_p[47] << 2) | (mask_p[46] << 0);
436 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
437 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
438}
439
440/**
441 * ar5008_hw_rf_alloc_ext_banks - allocates banks for external radio programming
442 * @ah: atheros hardware structure
443 *
444 * Only required for older devices with external AR2133/AR5133 radios.
445 */
446static int ar5008_hw_rf_alloc_ext_banks(struct ath_hw *ah)
447{
448#define ATH_ALLOC_BANK(bank, size) do { \
449 bank = kzalloc((sizeof(u32) * size), GFP_KERNEL); \
450 if (!bank) { \
451 ath_print(common, ATH_DBG_FATAL, \
452 "Cannot allocate RF banks\n"); \
453 return -ENOMEM; \
454 } \
455 } while (0);
456
457 struct ath_common *common = ath9k_hw_common(ah);
458
Felix Fietkau7a370812010-09-22 12:34:52 +0200459 BUG_ON(AR_SREV_9280_20_OR_LATER(ah));
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400460
461 ATH_ALLOC_BANK(ah->analogBank0Data, ah->iniBank0.ia_rows);
462 ATH_ALLOC_BANK(ah->analogBank1Data, ah->iniBank1.ia_rows);
463 ATH_ALLOC_BANK(ah->analogBank2Data, ah->iniBank2.ia_rows);
464 ATH_ALLOC_BANK(ah->analogBank3Data, ah->iniBank3.ia_rows);
465 ATH_ALLOC_BANK(ah->analogBank6Data, ah->iniBank6.ia_rows);
466 ATH_ALLOC_BANK(ah->analogBank6TPCData, ah->iniBank6TPC.ia_rows);
467 ATH_ALLOC_BANK(ah->analogBank7Data, ah->iniBank7.ia_rows);
468 ATH_ALLOC_BANK(ah->addac5416_21,
469 ah->iniAddac.ia_rows * ah->iniAddac.ia_columns);
470 ATH_ALLOC_BANK(ah->bank6Temp, ah->iniBank6.ia_rows);
471
472 return 0;
473#undef ATH_ALLOC_BANK
474}
475
476
477/**
478 * ar5008_hw_rf_free_ext_banks - Free memory for analog bank scratch buffers
479 * @ah: atheros hardware struture
480 * For the external AR2133/AR5133 radios banks.
481 */
482static void ar5008_hw_rf_free_ext_banks(struct ath_hw *ah)
483{
484#define ATH_FREE_BANK(bank) do { \
485 kfree(bank); \
486 bank = NULL; \
487 } while (0);
488
Felix Fietkau7a370812010-09-22 12:34:52 +0200489 BUG_ON(AR_SREV_9280_20_OR_LATER(ah));
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400490
491 ATH_FREE_BANK(ah->analogBank0Data);
492 ATH_FREE_BANK(ah->analogBank1Data);
493 ATH_FREE_BANK(ah->analogBank2Data);
494 ATH_FREE_BANK(ah->analogBank3Data);
495 ATH_FREE_BANK(ah->analogBank6Data);
496 ATH_FREE_BANK(ah->analogBank6TPCData);
497 ATH_FREE_BANK(ah->analogBank7Data);
498 ATH_FREE_BANK(ah->addac5416_21);
499 ATH_FREE_BANK(ah->bank6Temp);
500
501#undef ATH_FREE_BANK
502}
503
504/* *
505 * ar5008_hw_set_rf_regs - programs rf registers based on EEPROM
506 * @ah: atheros hardware structure
507 * @chan:
508 * @modesIndex:
509 *
510 * Used for the external AR2133/AR5133 radios.
511 *
512 * Reads the EEPROM header info from the device structure and programs
513 * all rf registers. This routine requires access to the analog
514 * rf device. This is not required for single-chip devices.
515 */
516static bool ar5008_hw_set_rf_regs(struct ath_hw *ah,
517 struct ath9k_channel *chan,
518 u16 modesIndex)
519{
520 u32 eepMinorRev;
521 u32 ob5GHz = 0, db5GHz = 0;
522 u32 ob2GHz = 0, db2GHz = 0;
523 int regWrites = 0;
524
525 /*
526 * Software does not need to program bank data
527 * for single chip devices, that is AR9280 or anything
528 * after that.
529 */
Felix Fietkau7a370812010-09-22 12:34:52 +0200530 if (AR_SREV_9280_20_OR_LATER(ah))
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400531 return true;
532
533 /* Setup rf parameters */
534 eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
535
536 /* Setup Bank 0 Write */
537 RF_BANK_SETUP(ah->analogBank0Data, &ah->iniBank0, 1);
538
539 /* Setup Bank 1 Write */
540 RF_BANK_SETUP(ah->analogBank1Data, &ah->iniBank1, 1);
541
542 /* Setup Bank 2 Write */
543 RF_BANK_SETUP(ah->analogBank2Data, &ah->iniBank2, 1);
544
545 /* Setup Bank 6 Write */
546 RF_BANK_SETUP(ah->analogBank3Data, &ah->iniBank3,
547 modesIndex);
548 {
549 int i;
550 for (i = 0; i < ah->iniBank6TPC.ia_rows; i++) {
551 ah->analogBank6Data[i] =
552 INI_RA(&ah->iniBank6TPC, i, modesIndex);
553 }
554 }
555
556 /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
557 if (eepMinorRev >= 2) {
558 if (IS_CHAN_2GHZ(chan)) {
559 ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
560 db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2);
561 ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
562 ob2GHz, 3, 197, 0);
563 ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
564 db2GHz, 3, 194, 0);
565 } else {
566 ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5);
567 db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5);
568 ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
569 ob5GHz, 3, 203, 0);
570 ar5008_hw_phy_modify_rx_buffer(ah->analogBank6Data,
571 db5GHz, 3, 200, 0);
572 }
573 }
574
575 /* Setup Bank 7 Setup */
576 RF_BANK_SETUP(ah->analogBank7Data, &ah->iniBank7, 1);
577
578 /* Write Analog registers */
579 REG_WRITE_RF_ARRAY(&ah->iniBank0, ah->analogBank0Data,
580 regWrites);
581 REG_WRITE_RF_ARRAY(&ah->iniBank1, ah->analogBank1Data,
582 regWrites);
583 REG_WRITE_RF_ARRAY(&ah->iniBank2, ah->analogBank2Data,
584 regWrites);
585 REG_WRITE_RF_ARRAY(&ah->iniBank3, ah->analogBank3Data,
586 regWrites);
587 REG_WRITE_RF_ARRAY(&ah->iniBank6TPC, ah->analogBank6Data,
588 regWrites);
589 REG_WRITE_RF_ARRAY(&ah->iniBank7, ah->analogBank7Data,
590 regWrites);
591
592 return true;
593}
594
595static void ar5008_hw_init_bb(struct ath_hw *ah,
596 struct ath9k_channel *chan)
597{
598 u32 synthDelay;
599
600 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
601 if (IS_CHAN_B(chan))
602 synthDelay = (4 * synthDelay) / 22;
603 else
604 synthDelay /= 10;
605
606 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
607
608 udelay(synthDelay + BASE_ACTIVATE_DELAY);
609}
610
611static void ar5008_hw_init_chain_masks(struct ath_hw *ah)
612{
613 int rx_chainmask, tx_chainmask;
614
615 rx_chainmask = ah->rxchainmask;
616 tx_chainmask = ah->txchainmask;
617
Sujith7d0d0df2010-04-16 11:53:57 +0530618
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400619 switch (rx_chainmask) {
620 case 0x5:
621 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
622 AR_PHY_SWAP_ALT_CHAIN);
623 case 0x3:
624 if (ah->hw_version.macVersion == AR_SREV_REVISION_5416_10) {
625 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
626 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
627 break;
628 }
629 case 0x1:
630 case 0x2:
631 case 0x7:
Felix Fietkau435c1612010-10-05 12:03:42 +0200632 ENABLE_REGWRITE_BUFFER(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400633 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
634 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
635 break;
636 default:
Felix Fietkau435c1612010-10-05 12:03:42 +0200637 ENABLE_REGWRITE_BUFFER(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400638 break;
639 }
640
641 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
Sujith7d0d0df2010-04-16 11:53:57 +0530642
643 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530644
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400645 if (tx_chainmask == 0x5) {
646 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
647 AR_PHY_SWAP_ALT_CHAIN);
648 }
649 if (AR_SREV_9100(ah))
650 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
651 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
652}
653
654static void ar5008_hw_override_ini(struct ath_hw *ah,
655 struct ath9k_channel *chan)
656{
657 u32 val;
658
659 /*
660 * Set the RX_ABORT and RX_DIS and clear if off only after
661 * RXE is set for MAC. This prevents frames with corrupted
662 * descriptor status.
663 */
664 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
665
Felix Fietkau7a370812010-09-22 12:34:52 +0200666 if (AR_SREV_9280_20_OR_LATER(ah)) {
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400667 val = REG_READ(ah, AR_PCU_MISC_MODE2);
668
669 if (!AR_SREV_9271(ah))
670 val &= ~AR_PCU_MISC_MODE2_HWWAR1;
671
Felix Fietkaua42acef2010-09-22 12:34:54 +0200672 if (AR_SREV_9287_11_OR_LATER(ah))
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400673 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
674
675 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
676 }
677
678 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Felix Fietkau7a370812010-09-22 12:34:52 +0200679 AR_SREV_9280_20_OR_LATER(ah))
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400680 return;
681 /*
682 * Disable BB clock gating
683 * Necessary to avoid issues on AR5416 2.0
684 */
685 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
686
687 /*
688 * Disable RIFS search on some chips to avoid baseband
689 * hang issues.
690 */
691 if (AR_SREV_9100(ah) || AR_SREV_9160(ah)) {
692 val = REG_READ(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS);
693 val &= ~AR_PHY_RIFS_INIT_DELAY;
694 REG_WRITE(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS, val);
695 }
696}
697
698static void ar5008_hw_set_channel_regs(struct ath_hw *ah,
699 struct ath9k_channel *chan)
700{
701 u32 phymode;
702 u32 enableDacFifo = 0;
703
Felix Fietkaue17f83e2010-09-22 12:34:53 +0200704 if (AR_SREV_9285_12_OR_LATER(ah))
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400705 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
706 AR_PHY_FC_ENABLE_DAC_FIFO);
707
708 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
709 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
710
711 if (IS_CHAN_HT40(chan)) {
712 phymode |= AR_PHY_FC_DYN2040_EN;
713
714 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
715 (chan->chanmode == CHANNEL_G_HT40PLUS))
716 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
717
718 }
719 REG_WRITE(ah, AR_PHY_TURBO, phymode);
720
721 ath9k_hw_set11nmac2040(ah);
722
Sujith7d0d0df2010-04-16 11:53:57 +0530723 ENABLE_REGWRITE_BUFFER(ah);
724
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400725 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
726 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
Sujith7d0d0df2010-04-16 11:53:57 +0530727
728 REGWRITE_BUFFER_FLUSH(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400729}
730
731
732static int ar5008_hw_process_ini(struct ath_hw *ah,
733 struct ath9k_channel *chan)
734{
735 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
736 int i, regWrites = 0;
737 struct ieee80211_channel *channel = chan->chan;
738 u32 modesIndex, freqIndex;
739
740 switch (chan->chanmode) {
741 case CHANNEL_A:
742 case CHANNEL_A_HT20:
743 modesIndex = 1;
744 freqIndex = 1;
745 break;
746 case CHANNEL_A_HT40PLUS:
747 case CHANNEL_A_HT40MINUS:
748 modesIndex = 2;
749 freqIndex = 1;
750 break;
751 case CHANNEL_G:
752 case CHANNEL_G_HT20:
753 case CHANNEL_B:
754 modesIndex = 4;
755 freqIndex = 2;
756 break;
757 case CHANNEL_G_HT40PLUS:
758 case CHANNEL_G_HT40MINUS:
759 modesIndex = 3;
760 freqIndex = 2;
761 break;
762
763 default:
764 return -EINVAL;
765 }
766
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400767 /*
768 * Set correct baseband to analog shift setting to
769 * access analog chips.
770 */
771 REG_WRITE(ah, AR_PHY(0), 0x00000007);
772
773 /* Write ADDAC shifts */
774 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
775 ah->eep_ops->set_addac(ah, chan);
776
777 if (AR_SREV_5416_22_OR_LATER(ah)) {
778 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
779 } else {
780 struct ar5416IniArray temp;
781 u32 addacSize =
782 sizeof(u32) * ah->iniAddac.ia_rows *
783 ah->iniAddac.ia_columns;
784
785 /* For AR5416 2.0/2.1 */
786 memcpy(ah->addac5416_21,
787 ah->iniAddac.ia_array, addacSize);
788
789 /* override CLKDRV value at [row, column] = [31, 1] */
790 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
791
792 temp.ia_array = ah->addac5416_21;
793 temp.ia_columns = ah->iniAddac.ia_columns;
794 temp.ia_rows = ah->iniAddac.ia_rows;
795 REG_WRITE_ARRAY(&temp, 1, regWrites);
796 }
797
798 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
799
Sujith7d0d0df2010-04-16 11:53:57 +0530800 ENABLE_REGWRITE_BUFFER(ah);
801
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400802 for (i = 0; i < ah->iniModes.ia_rows; i++) {
803 u32 reg = INI_RA(&ah->iniModes, i, 0);
804 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
805
806 if (reg == AR_AN_TOP2 && ah->need_an_top2_fixup)
807 val &= ~AR_AN_TOP2_PWDCLKIND;
808
809 REG_WRITE(ah, reg, val);
810
811 if (reg >= 0x7800 && reg < 0x78a0
812 && ah->config.analog_shiftreg) {
813 udelay(100);
814 }
815
816 DO_DELAY(regWrites);
817 }
818
Sujith7d0d0df2010-04-16 11:53:57 +0530819 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530820
Felix Fietkaua42acef2010-09-22 12:34:54 +0200821 if (AR_SREV_9280(ah) || AR_SREV_9287_11_OR_LATER(ah))
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400822 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
823
824 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
Felix Fietkaua42acef2010-09-22 12:34:54 +0200825 AR_SREV_9287_11_OR_LATER(ah))
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400826 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
827
828 if (AR_SREV_9271_10(ah))
829 REG_WRITE_ARRAY(&ah->iniModes_9271_1_0_only,
830 modesIndex, regWrites);
831
Sujith7d0d0df2010-04-16 11:53:57 +0530832 ENABLE_REGWRITE_BUFFER(ah);
833
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400834 /* Write common array parameters */
835 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
836 u32 reg = INI_RA(&ah->iniCommon, i, 0);
837 u32 val = INI_RA(&ah->iniCommon, i, 1);
838
839 REG_WRITE(ah, reg, val);
840
841 if (reg >= 0x7800 && reg < 0x78a0
842 && ah->config.analog_shiftreg) {
843 udelay(100);
844 }
845
846 DO_DELAY(regWrites);
847 }
848
Sujith7d0d0df2010-04-16 11:53:57 +0530849 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530850
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400851 if (AR_SREV_9271(ah)) {
852 if (ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE) == 1)
853 REG_WRITE_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
854 modesIndex, regWrites);
855 else
856 REG_WRITE_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
857 modesIndex, regWrites);
858 }
859
860 REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
861
Felix Fietkau6b42e8d2010-04-26 15:04:35 -0400862 if (IS_CHAN_A_FAST_CLOCK(ah, chan)) {
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400863 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
864 regWrites);
865 }
866
867 ar5008_hw_override_ini(ah, chan);
868 ar5008_hw_set_channel_regs(ah, chan);
869 ar5008_hw_init_chain_masks(ah);
870 ath9k_olc_init(ah);
871
872 /* Set TX power */
873 ah->eep_ops->set_txpower(ah, chan,
874 ath9k_regd_get_ctl(regulatory, chan),
875 channel->max_antenna_gain * 2,
876 channel->max_power * 2,
877 min((u32) MAX_RATE_POWER,
Felix Fietkaude40f312010-10-20 03:08:53 +0200878 (u32) regulatory->power_limit), false);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400879
880 /* Write analog registers */
881 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
882 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
883 "ar5416SetRfRegs failed\n");
884 return -EIO;
885 }
886
887 return 0;
888}
889
890static void ar5008_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
891{
892 u32 rfMode = 0;
893
894 if (chan == NULL)
895 return;
896
897 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
898 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
899
Felix Fietkau7a370812010-09-22 12:34:52 +0200900 if (!AR_SREV_9280_20_OR_LATER(ah))
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400901 rfMode |= (IS_CHAN_5GHZ(chan)) ?
902 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
903
Felix Fietkau6b42e8d2010-04-26 15:04:35 -0400904 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400905 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
906
907 REG_WRITE(ah, AR_PHY_MODE, rfMode);
908}
909
910static void ar5008_hw_mark_phy_inactive(struct ath_hw *ah)
911{
912 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
913}
914
915static void ar5008_hw_set_delta_slope(struct ath_hw *ah,
916 struct ath9k_channel *chan)
917{
918 u32 coef_scaled, ds_coef_exp, ds_coef_man;
919 u32 clockMhzScaled = 0x64000000;
920 struct chan_centers centers;
921
922 if (IS_CHAN_HALF_RATE(chan))
923 clockMhzScaled = clockMhzScaled >> 1;
924 else if (IS_CHAN_QUARTER_RATE(chan))
925 clockMhzScaled = clockMhzScaled >> 2;
926
927 ath9k_hw_get_channel_centers(ah, chan, &centers);
928 coef_scaled = clockMhzScaled / centers.synth_center;
929
930 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
931 &ds_coef_exp);
932
933 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
934 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
935 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
936 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
937
938 coef_scaled = (9 * coef_scaled) / 10;
939
940 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
941 &ds_coef_exp);
942
943 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
944 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
945 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
946 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
947}
948
949static bool ar5008_hw_rfbus_req(struct ath_hw *ah)
950{
951 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
952 return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
953 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
954}
955
956static void ar5008_hw_rfbus_done(struct ath_hw *ah)
957{
958 u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
959 if (IS_CHAN_B(ah->curchan))
960 synthDelay = (4 * synthDelay) / 22;
961 else
962 synthDelay /= 10;
963
964 udelay(synthDelay + BASE_ACTIVATE_DELAY);
965
966 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
967}
968
969static void ar5008_hw_enable_rfkill(struct ath_hw *ah)
970{
971 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
972 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
973
974 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
975 AR_GPIO_INPUT_MUX2_RFSILENT);
976
977 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
978 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
979}
980
981static void ar5008_restore_chainmask(struct ath_hw *ah)
982{
983 int rx_chainmask = ah->rxchainmask;
984
985 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
986 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
987 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
988 }
989}
990
991static void ar5008_set_diversity(struct ath_hw *ah, bool value)
992{
993 u32 v = REG_READ(ah, AR_PHY_CCK_DETECT);
994 if (value)
995 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
996 else
997 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
998 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
999}
1000
Luis R. Rodriguez64773962010-04-15 17:38:17 -04001001static u32 ar9100_hw_compute_pll_control(struct ath_hw *ah,
1002 struct ath9k_channel *chan)
1003{
1004 if (chan && IS_CHAN_5GHZ(chan))
1005 return 0x1450;
1006 return 0x1458;
1007}
1008
1009static u32 ar9160_hw_compute_pll_control(struct ath_hw *ah,
1010 struct ath9k_channel *chan)
1011{
1012 u32 pll;
1013
1014 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1015
1016 if (chan && IS_CHAN_HALF_RATE(chan))
1017 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1018 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1019 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1020
1021 if (chan && IS_CHAN_5GHZ(chan))
1022 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1023 else
1024 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1025
1026 return pll;
1027}
1028
1029static u32 ar5008_hw_compute_pll_control(struct ath_hw *ah,
1030 struct ath9k_channel *chan)
1031{
1032 u32 pll;
1033
1034 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1035
1036 if (chan && IS_CHAN_HALF_RATE(chan))
1037 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1038 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1039 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1040
1041 if (chan && IS_CHAN_5GHZ(chan))
1042 pll |= SM(0xa, AR_RTC_PLL_DIV);
1043 else
1044 pll |= SM(0xb, AR_RTC_PLL_DIV);
1045
1046 return pll;
1047}
1048
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001049static bool ar5008_hw_ani_control_old(struct ath_hw *ah,
1050 enum ath9k_ani_cmd cmd,
1051 int param)
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001052{
Felix Fietkau093115b2010-10-04 20:09:47 +02001053 struct ar5416AniState *aniState = &ah->curchan->ani;
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001054 struct ath_common *common = ath9k_hw_common(ah);
1055
1056 switch (cmd & ah->ani_function) {
1057 case ATH9K_ANI_NOISE_IMMUNITY_LEVEL:{
1058 u32 level = param;
1059
1060 if (level >= ARRAY_SIZE(ah->totalSizeDesired)) {
1061 ath_print(common, ATH_DBG_ANI,
1062 "level out of range (%u > %u)\n",
1063 level,
1064 (unsigned)ARRAY_SIZE(ah->totalSizeDesired));
1065 return false;
1066 }
1067
1068 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
1069 AR_PHY_DESIRED_SZ_TOT_DES,
1070 ah->totalSizeDesired[level]);
1071 REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
1072 AR_PHY_AGC_CTL1_COARSE_LOW,
1073 ah->coarse_low[level]);
1074 REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
1075 AR_PHY_AGC_CTL1_COARSE_HIGH,
1076 ah->coarse_high[level]);
1077 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
1078 AR_PHY_FIND_SIG_FIRPWR,
1079 ah->firpwr[level]);
1080
1081 if (level > aniState->noiseImmunityLevel)
1082 ah->stats.ast_ani_niup++;
1083 else if (level < aniState->noiseImmunityLevel)
1084 ah->stats.ast_ani_nidown++;
1085 aniState->noiseImmunityLevel = level;
1086 break;
1087 }
1088 case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
Joe Perches07b2fa52010-11-20 18:38:53 -08001089 static const int m1ThreshLow[] = { 127, 50 };
1090 static const int m2ThreshLow[] = { 127, 40 };
1091 static const int m1Thresh[] = { 127, 0x4d };
1092 static const int m2Thresh[] = { 127, 0x40 };
1093 static const int m2CountThr[] = { 31, 16 };
1094 static const int m2CountThrLow[] = { 63, 48 };
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001095 u32 on = param ? 1 : 0;
1096
1097 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
1098 AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
1099 m1ThreshLow[on]);
1100 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
1101 AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
1102 m2ThreshLow[on]);
1103 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
1104 AR_PHY_SFCORR_M1_THRESH,
1105 m1Thresh[on]);
1106 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
1107 AR_PHY_SFCORR_M2_THRESH,
1108 m2Thresh[on]);
1109 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
1110 AR_PHY_SFCORR_M2COUNT_THR,
1111 m2CountThr[on]);
1112 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
1113 AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
1114 m2CountThrLow[on]);
1115
1116 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
1117 AR_PHY_SFCORR_EXT_M1_THRESH_LOW,
1118 m1ThreshLow[on]);
1119 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
1120 AR_PHY_SFCORR_EXT_M2_THRESH_LOW,
1121 m2ThreshLow[on]);
1122 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
1123 AR_PHY_SFCORR_EXT_M1_THRESH,
1124 m1Thresh[on]);
1125 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
1126 AR_PHY_SFCORR_EXT_M2_THRESH,
1127 m2Thresh[on]);
1128
1129 if (on)
1130 REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
1131 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
1132 else
1133 REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
1134 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
1135
1136 if (!on != aniState->ofdmWeakSigDetectOff) {
1137 if (on)
1138 ah->stats.ast_ani_ofdmon++;
1139 else
1140 ah->stats.ast_ani_ofdmoff++;
1141 aniState->ofdmWeakSigDetectOff = !on;
1142 }
1143 break;
1144 }
1145 case ATH9K_ANI_CCK_WEAK_SIGNAL_THR:{
Joe Perches07b2fa52010-11-20 18:38:53 -08001146 static const int weakSigThrCck[] = { 8, 6 };
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001147 u32 high = param ? 1 : 0;
1148
1149 REG_RMW_FIELD(ah, AR_PHY_CCK_DETECT,
1150 AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK,
1151 weakSigThrCck[high]);
1152 if (high != aniState->cckWeakSigThreshold) {
1153 if (high)
1154 ah->stats.ast_ani_cckhigh++;
1155 else
1156 ah->stats.ast_ani_ccklow++;
1157 aniState->cckWeakSigThreshold = high;
1158 }
1159 break;
1160 }
1161 case ATH9K_ANI_FIRSTEP_LEVEL:{
Joe Perches07b2fa52010-11-20 18:38:53 -08001162 static const int firstep[] = { 0, 4, 8 };
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001163 u32 level = param;
1164
1165 if (level >= ARRAY_SIZE(firstep)) {
1166 ath_print(common, ATH_DBG_ANI,
1167 "level out of range (%u > %u)\n",
1168 level,
1169 (unsigned) ARRAY_SIZE(firstep));
1170 return false;
1171 }
1172 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
1173 AR_PHY_FIND_SIG_FIRSTEP,
1174 firstep[level]);
1175 if (level > aniState->firstepLevel)
1176 ah->stats.ast_ani_stepup++;
1177 else if (level < aniState->firstepLevel)
1178 ah->stats.ast_ani_stepdown++;
1179 aniState->firstepLevel = level;
1180 break;
1181 }
1182 case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
Joe Perches07b2fa52010-11-20 18:38:53 -08001183 static const int cycpwrThr1[] = { 2, 4, 6, 8, 10, 12, 14, 16 };
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001184 u32 level = param;
1185
1186 if (level >= ARRAY_SIZE(cycpwrThr1)) {
1187 ath_print(common, ATH_DBG_ANI,
1188 "level out of range (%u > %u)\n",
1189 level,
1190 (unsigned) ARRAY_SIZE(cycpwrThr1));
1191 return false;
1192 }
1193 REG_RMW_FIELD(ah, AR_PHY_TIMING5,
1194 AR_PHY_TIMING5_CYCPWR_THR1,
1195 cycpwrThr1[level]);
1196 if (level > aniState->spurImmunityLevel)
1197 ah->stats.ast_ani_spurup++;
1198 else if (level < aniState->spurImmunityLevel)
1199 ah->stats.ast_ani_spurdown++;
1200 aniState->spurImmunityLevel = level;
1201 break;
1202 }
1203 case ATH9K_ANI_PRESENT:
1204 break;
1205 default:
1206 ath_print(common, ATH_DBG_ANI,
1207 "invalid cmd %u\n", cmd);
1208 return false;
1209 }
1210
1211 ath_print(common, ATH_DBG_ANI, "ANI parameters:\n");
1212 ath_print(common, ATH_DBG_ANI,
1213 "noiseImmunityLevel=%d, spurImmunityLevel=%d, "
1214 "ofdmWeakSigDetectOff=%d\n",
1215 aniState->noiseImmunityLevel,
1216 aniState->spurImmunityLevel,
1217 !aniState->ofdmWeakSigDetectOff);
1218 ath_print(common, ATH_DBG_ANI,
1219 "cckWeakSigThreshold=%d, "
1220 "firstepLevel=%d, listenTime=%d\n",
1221 aniState->cckWeakSigThreshold,
1222 aniState->firstepLevel,
1223 aniState->listenTime);
1224 ath_print(common, ATH_DBG_ANI,
Felix Fietkau9dbebc72010-10-03 19:07:17 +02001225 "ofdmPhyErrCount=%d, cckPhyErrCount=%d\n\n",
Felix Fietkauc16fcb42010-04-15 17:38:39 -04001226 aniState->ofdmPhyErrCount,
1227 aniState->cckPhyErrCount);
1228
1229 return true;
1230}
1231
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001232static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
1233 enum ath9k_ani_cmd cmd,
1234 int param)
1235{
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001236 struct ath_common *common = ath9k_hw_common(ah);
1237 struct ath9k_channel *chan = ah->curchan;
Felix Fietkau093115b2010-10-04 20:09:47 +02001238 struct ar5416AniState *aniState = &chan->ani;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001239 s32 value, value2;
1240
1241 switch (cmd & ah->ani_function) {
1242 case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
1243 /*
1244 * on == 1 means ofdm weak signal detection is ON
1245 * on == 1 is the default, for less noise immunity
1246 *
1247 * on == 0 means ofdm weak signal detection is OFF
1248 * on == 0 means more noise imm
1249 */
1250 u32 on = param ? 1 : 0;
1251 /*
1252 * make register setting for default
1253 * (weak sig detect ON) come from INI file
1254 */
1255 int m1ThreshLow = on ?
1256 aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
1257 int m2ThreshLow = on ?
1258 aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
1259 int m1Thresh = on ?
1260 aniState->iniDef.m1Thresh : m1Thresh_off;
1261 int m2Thresh = on ?
1262 aniState->iniDef.m2Thresh : m2Thresh_off;
1263 int m2CountThr = on ?
1264 aniState->iniDef.m2CountThr : m2CountThr_off;
1265 int m2CountThrLow = on ?
1266 aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
1267 int m1ThreshLowExt = on ?
1268 aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
1269 int m2ThreshLowExt = on ?
1270 aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
1271 int m1ThreshExt = on ?
1272 aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
1273 int m2ThreshExt = on ?
1274 aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
1275
1276 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
1277 AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
1278 m1ThreshLow);
1279 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
1280 AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
1281 m2ThreshLow);
1282 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
1283 AR_PHY_SFCORR_M1_THRESH, m1Thresh);
1284 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
1285 AR_PHY_SFCORR_M2_THRESH, m2Thresh);
1286 REG_RMW_FIELD(ah, AR_PHY_SFCORR,
1287 AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
1288 REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
1289 AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
1290 m2CountThrLow);
1291
1292 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
1293 AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
1294 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
1295 AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
1296 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
1297 AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
1298 REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
1299 AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
1300
1301 if (on)
1302 REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
1303 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
1304 else
1305 REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
1306 AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
1307
1308 if (!on != aniState->ofdmWeakSigDetectOff) {
1309 ath_print(common, ATH_DBG_ANI,
1310 "** ch %d: ofdm weak signal: %s=>%s\n",
1311 chan->channel,
1312 !aniState->ofdmWeakSigDetectOff ?
1313 "on" : "off",
1314 on ? "on" : "off");
1315 if (on)
1316 ah->stats.ast_ani_ofdmon++;
1317 else
1318 ah->stats.ast_ani_ofdmoff++;
1319 aniState->ofdmWeakSigDetectOff = !on;
1320 }
1321 break;
1322 }
1323 case ATH9K_ANI_FIRSTEP_LEVEL:{
1324 u32 level = param;
1325
1326 if (level >= ARRAY_SIZE(firstep_table)) {
1327 ath_print(common, ATH_DBG_ANI,
1328 "ATH9K_ANI_FIRSTEP_LEVEL: level "
1329 "out of range (%u > %u)\n",
1330 level,
1331 (unsigned) ARRAY_SIZE(firstep_table));
1332 return false;
1333 }
1334
1335 /*
1336 * make register setting relative to default
1337 * from INI file & cap value
1338 */
1339 value = firstep_table[level] -
1340 firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
1341 aniState->iniDef.firstep;
1342 if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
1343 value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
1344 if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
1345 value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
1346 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
1347 AR_PHY_FIND_SIG_FIRSTEP,
1348 value);
1349 /*
1350 * we need to set first step low register too
1351 * make register setting relative to default
1352 * from INI file & cap value
1353 */
1354 value2 = firstep_table[level] -
1355 firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
1356 aniState->iniDef.firstepLow;
1357 if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
1358 value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
1359 if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
1360 value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
1361
1362 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
1363 AR_PHY_FIND_SIG_FIRSTEP_LOW, value2);
1364
1365 if (level != aniState->firstepLevel) {
1366 ath_print(common, ATH_DBG_ANI,
1367 "** ch %d: level %d=>%d[def:%d] "
1368 "firstep[level]=%d ini=%d\n",
1369 chan->channel,
1370 aniState->firstepLevel,
1371 level,
1372 ATH9K_ANI_FIRSTEP_LVL_NEW,
1373 value,
1374 aniState->iniDef.firstep);
1375 ath_print(common, ATH_DBG_ANI,
1376 "** ch %d: level %d=>%d[def:%d] "
1377 "firstep_low[level]=%d ini=%d\n",
1378 chan->channel,
1379 aniState->firstepLevel,
1380 level,
1381 ATH9K_ANI_FIRSTEP_LVL_NEW,
1382 value2,
1383 aniState->iniDef.firstepLow);
1384 if (level > aniState->firstepLevel)
1385 ah->stats.ast_ani_stepup++;
1386 else if (level < aniState->firstepLevel)
1387 ah->stats.ast_ani_stepdown++;
1388 aniState->firstepLevel = level;
1389 }
1390 break;
1391 }
1392 case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
1393 u32 level = param;
1394
1395 if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
1396 ath_print(common, ATH_DBG_ANI,
1397 "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level "
1398 "out of range (%u > %u)\n",
1399 level,
1400 (unsigned) ARRAY_SIZE(cycpwrThr1_table));
1401 return false;
1402 }
1403 /*
1404 * make register setting relative to default
1405 * from INI file & cap value
1406 */
1407 value = cycpwrThr1_table[level] -
1408 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
1409 aniState->iniDef.cycpwrThr1;
1410 if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
1411 value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
1412 if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
1413 value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
1414 REG_RMW_FIELD(ah, AR_PHY_TIMING5,
1415 AR_PHY_TIMING5_CYCPWR_THR1,
1416 value);
1417
1418 /*
1419 * set AR_PHY_EXT_CCA for extension channel
1420 * make register setting relative to default
1421 * from INI file & cap value
1422 */
1423 value2 = cycpwrThr1_table[level] -
1424 cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
1425 aniState->iniDef.cycpwrThr1Ext;
1426 if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
1427 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
1428 if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
1429 value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
1430 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
1431 AR_PHY_EXT_TIMING5_CYCPWR_THR1, value2);
1432
1433 if (level != aniState->spurImmunityLevel) {
1434 ath_print(common, ATH_DBG_ANI,
1435 "** ch %d: level %d=>%d[def:%d] "
1436 "cycpwrThr1[level]=%d ini=%d\n",
1437 chan->channel,
1438 aniState->spurImmunityLevel,
1439 level,
1440 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
1441 value,
1442 aniState->iniDef.cycpwrThr1);
1443 ath_print(common, ATH_DBG_ANI,
1444 "** ch %d: level %d=>%d[def:%d] "
1445 "cycpwrThr1Ext[level]=%d ini=%d\n",
1446 chan->channel,
1447 aniState->spurImmunityLevel,
1448 level,
1449 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
1450 value2,
1451 aniState->iniDef.cycpwrThr1Ext);
1452 if (level > aniState->spurImmunityLevel)
1453 ah->stats.ast_ani_spurup++;
1454 else if (level < aniState->spurImmunityLevel)
1455 ah->stats.ast_ani_spurdown++;
1456 aniState->spurImmunityLevel = level;
1457 }
1458 break;
1459 }
1460 case ATH9K_ANI_MRC_CCK:
1461 /*
1462 * You should not see this as AR5008, AR9001, AR9002
1463 * does not have hardware support for MRC CCK.
1464 */
1465 WARN_ON(1);
1466 break;
1467 case ATH9K_ANI_PRESENT:
1468 break;
1469 default:
1470 ath_print(common, ATH_DBG_ANI,
1471 "invalid cmd %u\n", cmd);
1472 return false;
1473 }
1474
1475 ath_print(common, ATH_DBG_ANI,
1476 "ANI parameters: SI=%d, ofdmWS=%s FS=%d "
Felix Fietkau9dbebc72010-10-03 19:07:17 +02001477 "MRCcck=%s listenTime=%d "
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001478 "ofdmErrs=%d cckErrs=%d\n",
1479 aniState->spurImmunityLevel,
1480 !aniState->ofdmWeakSigDetectOff ? "on" : "off",
1481 aniState->firstepLevel,
1482 !aniState->mrcCCKOff ? "on" : "off",
1483 aniState->listenTime,
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001484 aniState->ofdmPhyErrCount,
1485 aniState->cckPhyErrCount);
1486 return true;
1487}
1488
Felix Fietkau641d9922010-04-15 17:38:49 -04001489static void ar5008_hw_do_getnf(struct ath_hw *ah,
1490 int16_t nfarray[NUM_NF_READINGS])
1491{
Felix Fietkau641d9922010-04-15 17:38:49 -04001492 int16_t nf;
1493
1494 nf = MS(REG_READ(ah, AR_PHY_CCA), AR_PHY_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001495 nfarray[0] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001496
1497 nf = MS(REG_READ(ah, AR_PHY_CH1_CCA), AR_PHY_CH1_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001498 nfarray[1] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001499
1500 nf = MS(REG_READ(ah, AR_PHY_CH2_CCA), AR_PHY_CH2_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001501 nfarray[2] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001502
Felix Fietkau866b7782010-07-23 04:07:48 +02001503 if (!IS_CHAN_HT40(ah->curchan))
1504 return;
1505
Felix Fietkau641d9922010-04-15 17:38:49 -04001506 nf = MS(REG_READ(ah, AR_PHY_EXT_CCA), AR_PHY_EXT_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001507 nfarray[3] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001508
1509 nf = MS(REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR_PHY_CH1_EXT_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001510 nfarray[4] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001511
1512 nf = MS(REG_READ(ah, AR_PHY_CH2_EXT_CCA), AR_PHY_CH2_EXT_MINCCA_PWR);
Andreas Herrmann7919a572010-08-30 19:04:01 +00001513 nfarray[5] = sign_extend32(nf, 8);
Felix Fietkau641d9922010-04-15 17:38:49 -04001514}
1515
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001516/*
1517 * Initialize the ANI register values with default (ini) values.
1518 * This routine is called during a (full) hardware reset after
1519 * all the registers are initialised from the INI.
1520 */
1521static void ar5008_hw_ani_cache_ini_regs(struct ath_hw *ah)
1522{
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001523 struct ath_common *common = ath9k_hw_common(ah);
1524 struct ath9k_channel *chan = ah->curchan;
Felix Fietkau093115b2010-10-04 20:09:47 +02001525 struct ar5416AniState *aniState = &chan->ani;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001526 struct ath9k_ani_default *iniDef;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001527 u32 val;
1528
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001529 iniDef = &aniState->iniDef;
1530
1531 ath_print(common, ATH_DBG_ANI,
1532 "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
1533 ah->hw_version.macVersion,
1534 ah->hw_version.macRev,
1535 ah->opmode,
1536 chan->channel,
1537 chan->channelFlags);
1538
1539 val = REG_READ(ah, AR_PHY_SFCORR);
1540 iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
1541 iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
1542 iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
1543
1544 val = REG_READ(ah, AR_PHY_SFCORR_LOW);
1545 iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
1546 iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
1547 iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
1548
1549 val = REG_READ(ah, AR_PHY_SFCORR_EXT);
1550 iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
1551 iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
1552 iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
1553 iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
1554 iniDef->firstep = REG_READ_FIELD(ah,
1555 AR_PHY_FIND_SIG,
1556 AR_PHY_FIND_SIG_FIRSTEP);
1557 iniDef->firstepLow = REG_READ_FIELD(ah,
1558 AR_PHY_FIND_SIG_LOW,
1559 AR_PHY_FIND_SIG_FIRSTEP_LOW);
1560 iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
1561 AR_PHY_TIMING5,
1562 AR_PHY_TIMING5_CYCPWR_THR1);
1563 iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
1564 AR_PHY_EXT_CCA,
1565 AR_PHY_EXT_TIMING5_CYCPWR_THR1);
1566
1567 /* these levels just got reset to defaults by the INI */
1568 aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
1569 aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
1570 aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
1571 aniState->mrcCCKOff = true; /* not available on pre AR9003 */
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001572}
1573
Felix Fietkauf2552e22010-07-02 00:09:50 +02001574static void ar5008_hw_set_nf_limits(struct ath_hw *ah)
1575{
1576 ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_2GHZ;
1577 ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_2GHZ;
1578 ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_5416_2GHZ;
1579 ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_5416_5GHZ;
1580 ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_5416_5GHZ;
1581 ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_5416_5GHZ;
1582}
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001583
Felix Fietkau4e8c14e2010-11-11 03:18:38 +01001584static void ar5008_hw_set_radar_params(struct ath_hw *ah,
1585 struct ath_hw_radar_conf *conf)
1586{
1587 u32 radar_0 = 0, radar_1 = 0;
1588
1589 if (!conf) {
1590 REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
1591 return;
1592 }
1593
1594 radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
1595 radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
1596 radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
1597 radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
1598 radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
1599 radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
1600
1601 radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
1602 radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
1603 radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
1604 radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
1605 radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
1606
1607 REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
1608 REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
1609 if (conf->ext_channel)
1610 REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
1611 else
1612 REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
1613}
1614
Felix Fietkauc5d08552010-11-13 20:22:41 +01001615static void ar5008_hw_set_radar_conf(struct ath_hw *ah)
1616{
1617 struct ath_hw_radar_conf *conf = &ah->radar_conf;
1618
1619 conf->fir_power = -33;
1620 conf->radar_rssi = 20;
1621 conf->pulse_height = 10;
1622 conf->pulse_rssi = 24;
1623 conf->pulse_inband = 15;
1624 conf->pulse_maxlen = 255;
1625 conf->pulse_inband_step = 12;
1626 conf->radar_inband = 8;
1627}
1628
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001629void ar5008_hw_attach_phy_ops(struct ath_hw *ah)
1630{
1631 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
Joe Perches07b2fa52010-11-20 18:38:53 -08001632 static const u32 ar5416_cca_regs[6] = {
Felix Fietkaubbacee12010-07-11 15:44:42 +02001633 AR_PHY_CCA,
1634 AR_PHY_CH1_CCA,
1635 AR_PHY_CH2_CCA,
1636 AR_PHY_EXT_CCA,
1637 AR_PHY_CH1_EXT_CCA,
1638 AR_PHY_CH2_EXT_CCA
1639 };
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001640
1641 priv_ops->rf_set_freq = ar5008_hw_set_channel;
1642 priv_ops->spur_mitigate_freq = ar5008_hw_spur_mitigate;
1643
1644 priv_ops->rf_alloc_ext_banks = ar5008_hw_rf_alloc_ext_banks;
1645 priv_ops->rf_free_ext_banks = ar5008_hw_rf_free_ext_banks;
1646 priv_ops->set_rf_regs = ar5008_hw_set_rf_regs;
1647 priv_ops->set_channel_regs = ar5008_hw_set_channel_regs;
1648 priv_ops->init_bb = ar5008_hw_init_bb;
1649 priv_ops->process_ini = ar5008_hw_process_ini;
1650 priv_ops->set_rfmode = ar5008_hw_set_rfmode;
1651 priv_ops->mark_phy_inactive = ar5008_hw_mark_phy_inactive;
1652 priv_ops->set_delta_slope = ar5008_hw_set_delta_slope;
1653 priv_ops->rfbus_req = ar5008_hw_rfbus_req;
1654 priv_ops->rfbus_done = ar5008_hw_rfbus_done;
1655 priv_ops->enable_rfkill = ar5008_hw_enable_rfkill;
1656 priv_ops->restore_chainmask = ar5008_restore_chainmask;
1657 priv_ops->set_diversity = ar5008_set_diversity;
Felix Fietkau641d9922010-04-15 17:38:49 -04001658 priv_ops->do_getnf = ar5008_hw_do_getnf;
Felix Fietkau4e8c14e2010-11-11 03:18:38 +01001659 priv_ops->set_radar_params = ar5008_hw_set_radar_params;
Luis R. Rodriguez64773962010-04-15 17:38:17 -04001660
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001661 if (modparam_force_new_ani) {
1662 priv_ops->ani_control = ar5008_hw_ani_control_new;
1663 priv_ops->ani_cache_ini_regs = ar5008_hw_ani_cache_ini_regs;
1664 } else
1665 priv_ops->ani_control = ar5008_hw_ani_control_old;
1666
Luis R. Rodriguez64773962010-04-15 17:38:17 -04001667 if (AR_SREV_9100(ah))
1668 priv_ops->compute_pll_control = ar9100_hw_compute_pll_control;
1669 else if (AR_SREV_9160_10_OR_LATER(ah))
1670 priv_ops->compute_pll_control = ar9160_hw_compute_pll_control;
1671 else
1672 priv_ops->compute_pll_control = ar5008_hw_compute_pll_control;
Felix Fietkauf2552e22010-07-02 00:09:50 +02001673
1674 ar5008_hw_set_nf_limits(ah);
Felix Fietkauc5d08552010-11-13 20:22:41 +01001675 ar5008_hw_set_radar_conf(ah);
Felix Fietkaubbacee12010-07-11 15:44:42 +02001676 memcpy(ah->nf_regs, ar5416_cca_regs, sizeof(ah->nf_regs));
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001677}