blob: df55e28a6560e4dd72f00fe0f7bf41f3a842d2ee [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
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
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -040017/**
18 * DOC: Programming Atheros 802.11n analog front end radios
19 *
20 * AR5416 MAC based PCI devices and AR518 MAC based PCI-Express
21 * devices have either an external AR2133 analog front end radio for single
22 * band 2.4 GHz communication or an AR5133 analog front end radio for dual
23 * band 2.4 GHz / 5 GHz communication.
24 *
25 * All devices after the AR5416 and AR5418 family starting with the AR9280
26 * have their analog front radios, MAC/BB and host PCIe/USB interface embedded
27 * into a single-chip and require less programming.
28 *
29 * The following single-chips exist with a respective embedded radio:
30 *
31 * AR9280 - 11n dual-band 2x2 MIMO for PCIe
32 * AR9281 - 11n single-band 1x2 MIMO for PCIe
33 * AR9285 - 11n single-band 1x1 for PCIe
34 * AR9287 - 11n single-band 2x2 MIMO for PCIe
35 *
36 * AR9220 - 11n dual-band 2x2 MIMO for PCI
37 * AR9223 - 11n single-band 2x2 MIMO for PCI
38 *
39 * AR9287 - 11n single-band 1x1 MIMO for USB
40 */
41
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070042#include "hw.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070043
Luis R. Rodrigueza7765822009-10-19 02:33:45 -040044static void ath9k_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
45 u32 numBits, u32 firstBit,
46 u32 column);
47
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -040048/**
49 * ath9k_hw_write_regs - ??
50 *
51 * @ah: atheros hardware structure
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -040052 * @freqIndex:
53 * @regWrites:
54 *
55 * Used for both the chipsets with an external AR2133/AR5133 radios and
56 * single-chip devices.
57 */
Luis R. Rodriguez896ff262009-10-19 02:33:44 -040058void ath9k_hw_write_regs(struct ath_hw *ah, u32 freqIndex, int regWrites)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070059{
Sujith2660b812009-02-09 13:27:26 +053060 REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070061}
62
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -040063/**
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -040064 * ath9k_hw_ar9280_set_channel - set channel on single-chip device
65 * @ah: atheros hardware structure
66 * @chan:
67 *
68 * This is the function to change channel on single-chip devices, that is
69 * all devices after ar9280.
70 *
71 * This function takes the channel value in MHz and sets
72 * hardware channel value. Assumes writes have been enabled to analog bus.
73 *
74 * Actual Expression,
75 *
76 * For 2GHz channel,
77 * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
78 * (freq_ref = 40MHz)
79 *
80 * For 5GHz channel,
81 * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
82 * (freq_ref = 40MHz/(24>>amodeRefSel))
83 */
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -040084int ath9k_hw_ar9280_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070085{
86 u16 bMode, fracMode, aModeRefSel = 0;
87 u32 freq, ndiv, channelSel = 0, channelFrac = 0, reg32 = 0;
88 struct chan_centers centers;
89 u32 refDivA = 24;
90
91 ath9k_hw_get_channel_centers(ah, chan, &centers);
92 freq = centers.synth_center;
93
94 reg32 = REG_READ(ah, AR_PHY_SYNTH_CONTROL);
95 reg32 &= 0xc0000000;
96
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -040097 if (freq < 4800) { /* 2 GHz, fractional mode */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070098 u32 txctl;
Sujith193cd452009-09-18 15:04:07 +053099 int regWrites = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700100
101 bMode = 1;
102 fracMode = 1;
103 aModeRefSel = 0;
104 channelSel = (freq * 0x10000) / 15;
105
Sujith193cd452009-09-18 15:04:07 +0530106 if (AR_SREV_9287_11_OR_LATER(ah)) {
107 if (freq == 2484) {
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400108 /* Enable channel spreading for channel 14 */
Sujith193cd452009-09-18 15:04:07 +0530109 REG_WRITE_ARRAY(&ah->iniCckfirJapan2484,
110 1, regWrites);
111 } else {
112 REG_WRITE_ARRAY(&ah->iniCckfirNormal,
113 1, regWrites);
114 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700115 } else {
Sujith193cd452009-09-18 15:04:07 +0530116 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
117 if (freq == 2484) {
118 /* Enable channel spreading for channel 14 */
119 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
120 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
121 } else {
122 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
123 txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
124 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700125 }
126 } else {
127 bMode = 0;
128 fracMode = 0;
129
Sujith06d0f062009-02-12 10:06:45 +0530130 switch(ah->eep_ops->get_eeprom(ah, EEP_FRAC_N_5G)) {
131 case 0:
132 if ((freq % 20) == 0) {
133 aModeRefSel = 3;
134 } else if ((freq % 10) == 0) {
135 aModeRefSel = 2;
136 }
137 if (aModeRefSel)
138 break;
139 case 1:
140 default:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700141 aModeRefSel = 0;
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400142 /*
143 * Enable 2G (fractional) mode for channels
144 * which are 5MHz spaced.
145 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700146 fracMode = 1;
147 refDivA = 1;
148 channelSel = (freq * 0x8000) / 15;
149
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400150 /* RefDivA setting */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700151 REG_RMW_FIELD(ah, AR_AN_SYNTH9,
152 AR_AN_SYNTH9_REFDIVA, refDivA);
Sujith06d0f062009-02-12 10:06:45 +0530153
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700154 }
Sujith06d0f062009-02-12 10:06:45 +0530155
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700156 if (!fracMode) {
157 ndiv = (freq * (refDivA >> aModeRefSel)) / 60;
158 channelSel = ndiv & 0x1ff;
159 channelFrac = (ndiv & 0xfffffe00) * 2;
160 channelSel = (channelSel << 17) | channelFrac;
161 }
162 }
163
164 reg32 = reg32 |
165 (bMode << 29) |
166 (fracMode << 28) | (aModeRefSel << 26) | (channelSel);
167
168 REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
169
Sujith2660b812009-02-09 13:27:26 +0530170 ah->curchan = chan;
171 ah->curchan_rad_index = -1;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -0400172
173 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700174}
175
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400176/**
Luis R. Rodrigueze16393b2009-10-19 02:33:42 -0400177 * ath9k_hw_9280_spur_mitigate - convert baseband spur frequency
178 * @ah: atheros hardware structure
179 * @chan:
180 *
181 * For single-chip solutions. Converts to baseband spur frequency given the
182 * input channel frequency and compute register settings below.
183 */
184void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
185{
186 int bb_spur = AR_NO_SPUR;
187 int freq;
188 int bin, cur_bin;
189 int bb_spur_off, spur_subchannel_sd;
190 int spur_freq_sd;
191 int spur_delta_phase;
192 int denominator;
193 int upper, lower, cur_vit_mask;
194 int tmp, newVal;
195 int i;
196 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
197 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
198 };
199 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
200 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
201 };
202 int inc[4] = { 0, 100, 0, 0 };
203 struct chan_centers centers;
204
205 int8_t mask_m[123];
206 int8_t mask_p[123];
207 int8_t mask_amt;
208 int tmp_mask;
209 int cur_bb_spur;
210 bool is2GHz = IS_CHAN_2GHZ(chan);
211
212 memset(&mask_m, 0, sizeof(int8_t) * 123);
213 memset(&mask_p, 0, sizeof(int8_t) * 123);
214
215 ath9k_hw_get_channel_centers(ah, chan, &centers);
216 freq = centers.synth_center;
217
218 ah->config.spurmode = SPUR_ENABLE_EEPROM;
219 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
220 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
221
222 if (is2GHz)
223 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
224 else
225 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
226
227 if (AR_NO_SPUR == cur_bb_spur)
228 break;
229 cur_bb_spur = cur_bb_spur - freq;
230
231 if (IS_CHAN_HT40(chan)) {
232 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
233 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
234 bb_spur = cur_bb_spur;
235 break;
236 }
237 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
238 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
239 bb_spur = cur_bb_spur;
240 break;
241 }
242 }
243
244 if (AR_NO_SPUR == bb_spur) {
245 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
246 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
247 return;
248 } else {
249 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
250 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
251 }
252
253 bin = bb_spur * 320;
254
255 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
256
257 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
258 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
259 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
260 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
261 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
262
263 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
264 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
265 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
266 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
267 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
268 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
269
270 if (IS_CHAN_HT40(chan)) {
271 if (bb_spur < 0) {
272 spur_subchannel_sd = 1;
273 bb_spur_off = bb_spur + 10;
274 } else {
275 spur_subchannel_sd = 0;
276 bb_spur_off = bb_spur - 10;
277 }
278 } else {
279 spur_subchannel_sd = 0;
280 bb_spur_off = bb_spur;
281 }
282
283 if (IS_CHAN_HT40(chan))
284 spur_delta_phase =
285 ((bb_spur * 262144) /
286 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
287 else
288 spur_delta_phase =
289 ((bb_spur * 524288) /
290 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
291
292 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
293 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
294
295 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
296 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
297 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
298 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
299
300 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
301 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
302
303 cur_bin = -6000;
304 upper = bin + 100;
305 lower = bin - 100;
306
307 for (i = 0; i < 4; i++) {
308 int pilot_mask = 0;
309 int chan_mask = 0;
310 int bp = 0;
311 for (bp = 0; bp < 30; bp++) {
312 if ((cur_bin > lower) && (cur_bin < upper)) {
313 pilot_mask = pilot_mask | 0x1 << bp;
314 chan_mask = chan_mask | 0x1 << bp;
315 }
316 cur_bin += 100;
317 }
318 cur_bin += inc[i];
319 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
320 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
321 }
322
323 cur_vit_mask = 6100;
324 upper = bin + 120;
325 lower = bin - 120;
326
327 for (i = 0; i < 123; i++) {
328 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
329
330 /* workaround for gcc bug #37014 */
331 volatile int tmp_v = abs(cur_vit_mask - bin);
332
333 if (tmp_v < 75)
334 mask_amt = 1;
335 else
336 mask_amt = 0;
337 if (cur_vit_mask < 0)
338 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
339 else
340 mask_p[cur_vit_mask / 100] = mask_amt;
341 }
342 cur_vit_mask -= 100;
343 }
344
345 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
346 | (mask_m[48] << 26) | (mask_m[49] << 24)
347 | (mask_m[50] << 22) | (mask_m[51] << 20)
348 | (mask_m[52] << 18) | (mask_m[53] << 16)
349 | (mask_m[54] << 14) | (mask_m[55] << 12)
350 | (mask_m[56] << 10) | (mask_m[57] << 8)
351 | (mask_m[58] << 6) | (mask_m[59] << 4)
352 | (mask_m[60] << 2) | (mask_m[61] << 0);
353 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
354 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
355
356 tmp_mask = (mask_m[31] << 28)
357 | (mask_m[32] << 26) | (mask_m[33] << 24)
358 | (mask_m[34] << 22) | (mask_m[35] << 20)
359 | (mask_m[36] << 18) | (mask_m[37] << 16)
360 | (mask_m[48] << 14) | (mask_m[39] << 12)
361 | (mask_m[40] << 10) | (mask_m[41] << 8)
362 | (mask_m[42] << 6) | (mask_m[43] << 4)
363 | (mask_m[44] << 2) | (mask_m[45] << 0);
364 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
365 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
366
367 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
368 | (mask_m[18] << 26) | (mask_m[18] << 24)
369 | (mask_m[20] << 22) | (mask_m[20] << 20)
370 | (mask_m[22] << 18) | (mask_m[22] << 16)
371 | (mask_m[24] << 14) | (mask_m[24] << 12)
372 | (mask_m[25] << 10) | (mask_m[26] << 8)
373 | (mask_m[27] << 6) | (mask_m[28] << 4)
374 | (mask_m[29] << 2) | (mask_m[30] << 0);
375 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
376 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
377
378 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
379 | (mask_m[2] << 26) | (mask_m[3] << 24)
380 | (mask_m[4] << 22) | (mask_m[5] << 20)
381 | (mask_m[6] << 18) | (mask_m[7] << 16)
382 | (mask_m[8] << 14) | (mask_m[9] << 12)
383 | (mask_m[10] << 10) | (mask_m[11] << 8)
384 | (mask_m[12] << 6) | (mask_m[13] << 4)
385 | (mask_m[14] << 2) | (mask_m[15] << 0);
386 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
387 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
388
389 tmp_mask = (mask_p[15] << 28)
390 | (mask_p[14] << 26) | (mask_p[13] << 24)
391 | (mask_p[12] << 22) | (mask_p[11] << 20)
392 | (mask_p[10] << 18) | (mask_p[9] << 16)
393 | (mask_p[8] << 14) | (mask_p[7] << 12)
394 | (mask_p[6] << 10) | (mask_p[5] << 8)
395 | (mask_p[4] << 6) | (mask_p[3] << 4)
396 | (mask_p[2] << 2) | (mask_p[1] << 0);
397 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
398 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
399
400 tmp_mask = (mask_p[30] << 28)
401 | (mask_p[29] << 26) | (mask_p[28] << 24)
402 | (mask_p[27] << 22) | (mask_p[26] << 20)
403 | (mask_p[25] << 18) | (mask_p[24] << 16)
404 | (mask_p[23] << 14) | (mask_p[22] << 12)
405 | (mask_p[21] << 10) | (mask_p[20] << 8)
406 | (mask_p[19] << 6) | (mask_p[18] << 4)
407 | (mask_p[17] << 2) | (mask_p[16] << 0);
408 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
409 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
410
411 tmp_mask = (mask_p[45] << 28)
412 | (mask_p[44] << 26) | (mask_p[43] << 24)
413 | (mask_p[42] << 22) | (mask_p[41] << 20)
414 | (mask_p[40] << 18) | (mask_p[39] << 16)
415 | (mask_p[38] << 14) | (mask_p[37] << 12)
416 | (mask_p[36] << 10) | (mask_p[35] << 8)
417 | (mask_p[34] << 6) | (mask_p[33] << 4)
418 | (mask_p[32] << 2) | (mask_p[31] << 0);
419 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
420 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
421
422 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
423 | (mask_p[59] << 26) | (mask_p[58] << 24)
424 | (mask_p[57] << 22) | (mask_p[56] << 20)
425 | (mask_p[55] << 18) | (mask_p[54] << 16)
426 | (mask_p[53] << 14) | (mask_p[52] << 12)
427 | (mask_p[51] << 10) | (mask_p[50] << 8)
428 | (mask_p[49] << 6) | (mask_p[48] << 4)
429 | (mask_p[47] << 2) | (mask_p[46] << 0);
430 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
431 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
432}
433
434/* All code below is for non single-chip solutions */
435
Luis R. Rodrigueza7765822009-10-19 02:33:45 -0400436/*
437 * Fix on 2.4 GHz band for orientation sensitivity issue by increasing
438 * rf_pwd_icsyndiv.
439 *
440 * Theoretical Rules:
441 * if 2 GHz band
442 * if forceBiasAuto
443 * if synth_freq < 2412
444 * bias = 0
445 * else if 2412 <= synth_freq <= 2422
446 * bias = 1
447 * else // synth_freq > 2422
448 * bias = 2
449 * else if forceBias > 0
450 * bias = forceBias & 7
451 * else
452 * no change, use value from ini file
453 * else
454 * no change, invalid band
455 *
456 * 1st Mod:
457 * 2422 also uses value of 2
458 * <approved>
459 *
460 * 2nd Mod:
461 * Less than 2412 uses value of 0, 2412 and above uses value of 2
462 */
463static void ath9k_hw_force_bias(struct ath_hw *ah, u16 synth_freq)
464{
465 struct ath_common *common = ath9k_hw_common(ah);
466 u32 tmp_reg;
467 int reg_writes = 0;
468 u32 new_bias = 0;
469
470 if (!AR_SREV_5416(ah) || synth_freq >= 3000) {
471 return;
472 }
473
474 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
475
476 if (synth_freq < 2412)
477 new_bias = 0;
478 else if (synth_freq < 2422)
479 new_bias = 1;
480 else
481 new_bias = 2;
482
483 /* pre-reverse this field */
484 tmp_reg = ath9k_hw_reverse_bits(new_bias, 3);
485
486 ath_print(common, ATH_DBG_CONFIG,
487 "Force rf_pwd_icsyndiv to %1d on %4d\n",
488 new_bias, synth_freq);
489
490 /* swizzle rf_pwd_icsyndiv */
491 ath9k_phy_modify_rx_buffer(ah->analogBank6Data, tmp_reg, 3, 181, 3);
492
493 /* write Bank 6 with new params */
494 REG_WRITE_RF_ARRAY(&ah->iniBank6, ah->analogBank6Data, reg_writes);
495}
496
Luis R. Rodrigueze16393b2009-10-19 02:33:42 -0400497/**
498 * ath9k_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios
499 * @ah: atheros hardware stucture
500 * @chan:
501 *
502 * For the external AR2133/AR5133 radios, takes the MHz channel value and set
503 * the channel value. Assumes writes enabled to analog bus and bank6 register
504 * cache in ah->analogBank6Data.
505 */
506int ath9k_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
507{
508 struct ath_common *common = ath9k_hw_common(ah);
509 u32 channelSel = 0;
510 u32 bModeSynth = 0;
511 u32 aModeRefSel = 0;
512 u32 reg32 = 0;
513 u16 freq;
514 struct chan_centers centers;
515
516 ath9k_hw_get_channel_centers(ah, chan, &centers);
517 freq = centers.synth_center;
518
519 if (freq < 4800) {
520 u32 txctl;
521
522 if (((freq - 2192) % 5) == 0) {
523 channelSel = ((freq - 672) * 2 - 3040) / 10;
524 bModeSynth = 0;
525 } else if (((freq - 2224) % 5) == 0) {
526 channelSel = ((freq - 704) * 2 - 3040) / 10;
527 bModeSynth = 1;
528 } else {
529 ath_print(common, ATH_DBG_FATAL,
530 "Invalid channel %u MHz\n", freq);
531 return -EINVAL;
532 }
533
534 channelSel = (channelSel << 2) & 0xff;
535 channelSel = ath9k_hw_reverse_bits(channelSel, 8);
536
537 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
538 if (freq == 2484) {
539
540 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
541 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
542 } else {
543 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
544 txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
545 }
546
547 } else if ((freq % 20) == 0 && freq >= 5120) {
548 channelSel =
549 ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
550 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
551 } else if ((freq % 10) == 0) {
552 channelSel =
553 ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
554 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
555 aModeRefSel = ath9k_hw_reverse_bits(2, 2);
556 else
557 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
558 } else if ((freq % 5) == 0) {
559 channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
560 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
561 } else {
562 ath_print(common, ATH_DBG_FATAL,
563 "Invalid channel %u MHz\n", freq);
564 return -EINVAL;
565 }
566
Luis R. Rodrigueza7765822009-10-19 02:33:45 -0400567 ath9k_hw_force_bias(ah, freq);
568 ath9k_hw_decrease_chain_power(ah, chan);
569
Luis R. Rodrigueze16393b2009-10-19 02:33:42 -0400570 reg32 =
571 (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
572 (1 << 5) | 0x1;
573
574 REG_WRITE(ah, AR_PHY(0x37), reg32);
575
576 ah->curchan = chan;
577 ah->curchan_rad_index = -1;
578
579 return 0;
580}
581
582/**
583 * ath9k_hw_spur_mitigate - convert baseband spur frequency for external radios
584 * @ah: atheros hardware structure
585 * @chan:
586 *
587 * For non single-chip solutions. Converts to baseband spur frequency given the
588 * input channel frequency and compute register settings below.
589 */
590void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
591{
592 int bb_spur = AR_NO_SPUR;
593 int bin, cur_bin;
594 int spur_freq_sd;
595 int spur_delta_phase;
596 int denominator;
597 int upper, lower, cur_vit_mask;
598 int tmp, new;
599 int i;
600 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
601 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
602 };
603 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
604 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
605 };
606 int inc[4] = { 0, 100, 0, 0 };
607
608 int8_t mask_m[123];
609 int8_t mask_p[123];
610 int8_t mask_amt;
611 int tmp_mask;
612 int cur_bb_spur;
613 bool is2GHz = IS_CHAN_2GHZ(chan);
614
615 memset(&mask_m, 0, sizeof(int8_t) * 123);
616 memset(&mask_p, 0, sizeof(int8_t) * 123);
617
618 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
619 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
620 if (AR_NO_SPUR == cur_bb_spur)
621 break;
622 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
623 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
624 bb_spur = cur_bb_spur;
625 break;
626 }
627 }
628
629 if (AR_NO_SPUR == bb_spur)
630 return;
631
632 bin = bb_spur * 32;
633
634 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
635 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
636 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
637 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
638 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
639
640 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
641
642 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
643 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
644 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
645 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
646 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
647 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
648
649 spur_delta_phase = ((bb_spur * 524288) / 100) &
650 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
651
652 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
653 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
654
655 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
656 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
657 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
658 REG_WRITE(ah, AR_PHY_TIMING11, new);
659
660 cur_bin = -6000;
661 upper = bin + 100;
662 lower = bin - 100;
663
664 for (i = 0; i < 4; i++) {
665 int pilot_mask = 0;
666 int chan_mask = 0;
667 int bp = 0;
668 for (bp = 0; bp < 30; bp++) {
669 if ((cur_bin > lower) && (cur_bin < upper)) {
670 pilot_mask = pilot_mask | 0x1 << bp;
671 chan_mask = chan_mask | 0x1 << bp;
672 }
673 cur_bin += 100;
674 }
675 cur_bin += inc[i];
676 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
677 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
678 }
679
680 cur_vit_mask = 6100;
681 upper = bin + 120;
682 lower = bin - 120;
683
684 for (i = 0; i < 123; i++) {
685 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
686
687 /* workaround for gcc bug #37014 */
688 volatile int tmp_v = abs(cur_vit_mask - bin);
689
690 if (tmp_v < 75)
691 mask_amt = 1;
692 else
693 mask_amt = 0;
694 if (cur_vit_mask < 0)
695 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
696 else
697 mask_p[cur_vit_mask / 100] = mask_amt;
698 }
699 cur_vit_mask -= 100;
700 }
701
702 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
703 | (mask_m[48] << 26) | (mask_m[49] << 24)
704 | (mask_m[50] << 22) | (mask_m[51] << 20)
705 | (mask_m[52] << 18) | (mask_m[53] << 16)
706 | (mask_m[54] << 14) | (mask_m[55] << 12)
707 | (mask_m[56] << 10) | (mask_m[57] << 8)
708 | (mask_m[58] << 6) | (mask_m[59] << 4)
709 | (mask_m[60] << 2) | (mask_m[61] << 0);
710 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
711 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
712
713 tmp_mask = (mask_m[31] << 28)
714 | (mask_m[32] << 26) | (mask_m[33] << 24)
715 | (mask_m[34] << 22) | (mask_m[35] << 20)
716 | (mask_m[36] << 18) | (mask_m[37] << 16)
717 | (mask_m[48] << 14) | (mask_m[39] << 12)
718 | (mask_m[40] << 10) | (mask_m[41] << 8)
719 | (mask_m[42] << 6) | (mask_m[43] << 4)
720 | (mask_m[44] << 2) | (mask_m[45] << 0);
721 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
722 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
723
724 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
725 | (mask_m[18] << 26) | (mask_m[18] << 24)
726 | (mask_m[20] << 22) | (mask_m[20] << 20)
727 | (mask_m[22] << 18) | (mask_m[22] << 16)
728 | (mask_m[24] << 14) | (mask_m[24] << 12)
729 | (mask_m[25] << 10) | (mask_m[26] << 8)
730 | (mask_m[27] << 6) | (mask_m[28] << 4)
731 | (mask_m[29] << 2) | (mask_m[30] << 0);
732 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
733 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
734
735 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
736 | (mask_m[2] << 26) | (mask_m[3] << 24)
737 | (mask_m[4] << 22) | (mask_m[5] << 20)
738 | (mask_m[6] << 18) | (mask_m[7] << 16)
739 | (mask_m[8] << 14) | (mask_m[9] << 12)
740 | (mask_m[10] << 10) | (mask_m[11] << 8)
741 | (mask_m[12] << 6) | (mask_m[13] << 4)
742 | (mask_m[14] << 2) | (mask_m[15] << 0);
743 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
744 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
745
746 tmp_mask = (mask_p[15] << 28)
747 | (mask_p[14] << 26) | (mask_p[13] << 24)
748 | (mask_p[12] << 22) | (mask_p[11] << 20)
749 | (mask_p[10] << 18) | (mask_p[9] << 16)
750 | (mask_p[8] << 14) | (mask_p[7] << 12)
751 | (mask_p[6] << 10) | (mask_p[5] << 8)
752 | (mask_p[4] << 6) | (mask_p[3] << 4)
753 | (mask_p[2] << 2) | (mask_p[1] << 0);
754 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
755 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
756
757 tmp_mask = (mask_p[30] << 28)
758 | (mask_p[29] << 26) | (mask_p[28] << 24)
759 | (mask_p[27] << 22) | (mask_p[26] << 20)
760 | (mask_p[25] << 18) | (mask_p[24] << 16)
761 | (mask_p[23] << 14) | (mask_p[22] << 12)
762 | (mask_p[21] << 10) | (mask_p[20] << 8)
763 | (mask_p[19] << 6) | (mask_p[18] << 4)
764 | (mask_p[17] << 2) | (mask_p[16] << 0);
765 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
766 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
767
768 tmp_mask = (mask_p[45] << 28)
769 | (mask_p[44] << 26) | (mask_p[43] << 24)
770 | (mask_p[42] << 22) | (mask_p[41] << 20)
771 | (mask_p[40] << 18) | (mask_p[39] << 16)
772 | (mask_p[38] << 14) | (mask_p[37] << 12)
773 | (mask_p[36] << 10) | (mask_p[35] << 8)
774 | (mask_p[34] << 6) | (mask_p[33] << 4)
775 | (mask_p[32] << 2) | (mask_p[31] << 0);
776 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
777 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
778
779 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
780 | (mask_p[59] << 26) | (mask_p[58] << 24)
781 | (mask_p[57] << 22) | (mask_p[56] << 20)
782 | (mask_p[55] << 18) | (mask_p[54] << 16)
783 | (mask_p[53] << 14) | (mask_p[52] << 12)
784 | (mask_p[51] << 10) | (mask_p[50] << 8)
785 | (mask_p[49] << 6) | (mask_p[48] << 4)
786 | (mask_p[47] << 2) | (mask_p[46] << 0);
787 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
788 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
789}
790
791/**
792 * ath9k_hw_rf_alloc_ext_banks - allocates banks for external radio programming
793 * @ah: atheros hardware structure
794 *
795 * Only required for older devices with external AR2133/AR5133 radios.
796 */
797int ath9k_hw_rf_alloc_ext_banks(struct ath_hw *ah)
798{
799#define ATH_ALLOC_BANK(bank, size) do { \
800 bank = kzalloc((sizeof(u32) * size), GFP_KERNEL); \
801 if (!bank) { \
802 ath_print(common, ATH_DBG_FATAL, \
803 "Cannot allocate RF banks\n"); \
804 return -ENOMEM; \
805 } \
806 } while (0);
807
808 struct ath_common *common = ath9k_hw_common(ah);
809
810 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
811
812 ATH_ALLOC_BANK(ah->analogBank0Data, ah->iniBank0.ia_rows);
813 ATH_ALLOC_BANK(ah->analogBank1Data, ah->iniBank1.ia_rows);
814 ATH_ALLOC_BANK(ah->analogBank2Data, ah->iniBank2.ia_rows);
815 ATH_ALLOC_BANK(ah->analogBank3Data, ah->iniBank3.ia_rows);
816 ATH_ALLOC_BANK(ah->analogBank6Data, ah->iniBank6.ia_rows);
817 ATH_ALLOC_BANK(ah->analogBank6TPCData, ah->iniBank6TPC.ia_rows);
818 ATH_ALLOC_BANK(ah->analogBank7Data, ah->iniBank7.ia_rows);
819 ATH_ALLOC_BANK(ah->addac5416_21,
820 ah->iniAddac.ia_rows * ah->iniAddac.ia_columns);
821 ATH_ALLOC_BANK(ah->bank6Temp, ah->iniBank6.ia_rows);
822
823 return 0;
824#undef ATH_ALLOC_BANK
825}
826
827
828/**
829 * ath9k_hw_rf_free_ext_banks - Free memory for analog bank scratch buffers
830 * @ah: atheros hardware struture
831 * For the external AR2133/AR5133 radios banks.
832 */
833void
834ath9k_hw_rf_free_ext_banks(struct ath_hw *ah)
835{
836#define ATH_FREE_BANK(bank) do { \
837 kfree(bank); \
838 bank = NULL; \
839 } while (0);
840
841 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
842
843 ATH_FREE_BANK(ah->analogBank0Data);
844 ATH_FREE_BANK(ah->analogBank1Data);
845 ATH_FREE_BANK(ah->analogBank2Data);
846 ATH_FREE_BANK(ah->analogBank3Data);
847 ATH_FREE_BANK(ah->analogBank6Data);
848 ATH_FREE_BANK(ah->analogBank6TPCData);
849 ATH_FREE_BANK(ah->analogBank7Data);
850 ATH_FREE_BANK(ah->addac5416_21);
851 ATH_FREE_BANK(ah->bank6Temp);
852
853#undef ATH_FREE_BANK
854}
855
856/**
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400857 * ath9k_phy_modify_rx_buffer() - perform analog swizzling of parameters
858 * @rfbuf:
859 * @reg32:
860 * @numBits:
861 * @firstBit:
862 * @column:
863 *
864 * Performs analog "swizzling" of parameters into their location.
865 * Used on external AR2133/AR5133 radios.
866 */
Luis R. Rodrigueze16393b2009-10-19 02:33:42 -0400867static void ath9k_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
868 u32 numBits, u32 firstBit,
869 u32 column)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700870{
871 u32 tmp32, mask, arrayEntry, lastBit;
872 int32_t bitPosition, bitsLeft;
873
874 tmp32 = ath9k_hw_reverse_bits(reg32, numBits);
875 arrayEntry = (firstBit - 1) / 8;
876 bitPosition = (firstBit - 1) % 8;
877 bitsLeft = numBits;
878 while (bitsLeft > 0) {
879 lastBit = (bitPosition + bitsLeft > 8) ?
880 8 : bitPosition + bitsLeft;
881 mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) <<
882 (column * 8);
883 rfBuf[arrayEntry] &= ~mask;
884 rfBuf[arrayEntry] |= ((tmp32 << bitPosition) <<
885 (column * 8)) & mask;
886 bitsLeft -= 8 - bitPosition;
887 tmp32 = tmp32 >> (8 - bitPosition);
888 bitPosition = 0;
889 arrayEntry++;
890 }
891}
892
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400893/* *
894 * ath9k_hw_set_rf_regs - programs rf registers based on EEPROM
895 * @ah: atheros hardware structure
896 * @chan:
897 * @modesIndex:
898 *
899 * Used for the external AR2133/AR5133 radios.
900 *
901 * Reads the EEPROM header info from the device structure and programs
902 * all rf registers. This routine requires access to the analog
903 * rf device. This is not required for single-chip devices.
904 */
Luis R. Rodrigueze16393b2009-10-19 02:33:42 -0400905bool ath9k_hw_set_rf_regs(struct ath_hw *ah, struct ath9k_channel *chan,
906 u16 modesIndex)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700907{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700908 u32 eepMinorRev;
909 u32 ob5GHz = 0, db5GHz = 0;
910 u32 ob2GHz = 0, db2GHz = 0;
911 int regWrites = 0;
912
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400913 /*
914 * Software does not need to program bank data
915 * for single chip devices, that is AR9280 or anything
916 * after that.
917 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700918 if (AR_SREV_9280_10_OR_LATER(ah))
919 return true;
920
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400921 /* Setup rf parameters */
Sujithf74df6f2009-02-09 13:27:24 +0530922 eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700923
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400924 /* Setup Bank 0 Write */
Sujith2660b812009-02-09 13:27:26 +0530925 RF_BANK_SETUP(ah->analogBank0Data, &ah->iniBank0, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700926
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400927 /* Setup Bank 1 Write */
Sujith2660b812009-02-09 13:27:26 +0530928 RF_BANK_SETUP(ah->analogBank1Data, &ah->iniBank1, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700929
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400930 /* Setup Bank 2 Write */
Sujith2660b812009-02-09 13:27:26 +0530931 RF_BANK_SETUP(ah->analogBank2Data, &ah->iniBank2, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700932
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400933 /* Setup Bank 6 Write */
Sujith2660b812009-02-09 13:27:26 +0530934 RF_BANK_SETUP(ah->analogBank3Data, &ah->iniBank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700935 modesIndex);
936 {
937 int i;
Sujith2660b812009-02-09 13:27:26 +0530938 for (i = 0; i < ah->iniBank6TPC.ia_rows; i++) {
939 ah->analogBank6Data[i] =
940 INI_RA(&ah->iniBank6TPC, i, modesIndex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700941 }
942 }
943
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400944 /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700945 if (eepMinorRev >= 2) {
946 if (IS_CHAN_2GHZ(chan)) {
Sujithf74df6f2009-02-09 13:27:24 +0530947 ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
948 db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2);
Sujith2660b812009-02-09 13:27:26 +0530949 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700950 ob2GHz, 3, 197, 0);
Sujith2660b812009-02-09 13:27:26 +0530951 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700952 db2GHz, 3, 194, 0);
953 } else {
Sujithf74df6f2009-02-09 13:27:24 +0530954 ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5);
955 db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5);
Sujith2660b812009-02-09 13:27:26 +0530956 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700957 ob5GHz, 3, 203, 0);
Sujith2660b812009-02-09 13:27:26 +0530958 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700959 db5GHz, 3, 200, 0);
960 }
961 }
962
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400963 /* Setup Bank 7 Setup */
Sujith2660b812009-02-09 13:27:26 +0530964 RF_BANK_SETUP(ah->analogBank7Data, &ah->iniBank7, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700965
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400966 /* Write Analog registers */
Sujith2660b812009-02-09 13:27:26 +0530967 REG_WRITE_RF_ARRAY(&ah->iniBank0, ah->analogBank0Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700968 regWrites);
Sujith2660b812009-02-09 13:27:26 +0530969 REG_WRITE_RF_ARRAY(&ah->iniBank1, ah->analogBank1Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700970 regWrites);
Sujith2660b812009-02-09 13:27:26 +0530971 REG_WRITE_RF_ARRAY(&ah->iniBank2, ah->analogBank2Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700972 regWrites);
Sujith2660b812009-02-09 13:27:26 +0530973 REG_WRITE_RF_ARRAY(&ah->iniBank3, ah->analogBank3Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700974 regWrites);
Sujith2660b812009-02-09 13:27:26 +0530975 REG_WRITE_RF_ARRAY(&ah->iniBank6TPC, ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700976 regWrites);
Sujith2660b812009-02-09 13:27:26 +0530977 REG_WRITE_RF_ARRAY(&ah->iniBank7, ah->analogBank7Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700978 regWrites);
979
980 return true;
981}
982
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400983/**
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400984 * ath9k_hw_decrease_chain_power()
985 *
986 * @ah: atheros hardware structure
987 * @chan:
988 *
989 * Only used on the AR5416 and AR5418 with the external AR2133/AR5133 radios.
990 *
991 * Sets a chain internal RF path to the lowest output power. Any
992 * further writes to bank6 after this setting will override these
993 * changes. Thus this function must be the last function in the
994 * sequence to modify bank 6.
995 *
996 * This function must be called after ar5416SetRfRegs() which is
997 * called from ath9k_hw_process_ini() due to swizzling of bank 6.
998 * Depends on ah->analogBank6Data being initialized by
999 * ath9k_hw_set_rf_regs()
1000 *
1001 * Additional additive reduction in power -
1002 * change chain's switch table so chain's tx state is actually the rx
1003 * state value. May produce different results in 2GHz/5GHz as well as
1004 * board to board but in general should be a reduction.
1005 *
1006 * Activated by #ifdef ALTER_SWITCH. Not tried yet. If so, must be
1007 * called after ah->eep_ops->set_board_values() due to RMW of
1008 * PHY_SWITCH_CHAIN_0.
1009 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001010void
Sujithcbe61d82009-02-09 13:27:12 +05301011ath9k_hw_decrease_chain_power(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001012{
1013 int i, regWrites = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001014 u32 bank6SelMask;
Sujith2660b812009-02-09 13:27:26 +05301015 u32 *bank6Temp = ah->bank6Temp;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001016
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001017 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
1018
Sujith1cf68732009-08-13 09:34:32 +05301019 switch (ah->config.diversity_control) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001020 case ATH9K_ANT_FIXED_A:
1021 bank6SelMask =
Sujith1cf68732009-08-13 09:34:32 +05301022 (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001023 REDUCE_CHAIN_0 : /* swapped, reduce chain 0 */
1024 REDUCE_CHAIN_1; /* normal, select chain 1/2 to reduce */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001025 break;
1026 case ATH9K_ANT_FIXED_B:
1027 bank6SelMask =
Sujith1cf68732009-08-13 09:34:32 +05301028 (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001029 REDUCE_CHAIN_1 : /* swapped, reduce chain 1/2 */
1030 REDUCE_CHAIN_0; /* normal, select chain 0 to reduce */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001031 break;
1032 case ATH9K_ANT_VARIABLE:
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001033 return; /* do not change anything */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001034 break;
1035 default:
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001036 return; /* do not change anything */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001037 break;
1038 }
1039
Sujith2660b812009-02-09 13:27:26 +05301040 for (i = 0; i < ah->iniBank6.ia_rows; i++)
1041 bank6Temp[i] = ah->analogBank6Data[i];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001042
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001043 /* Write Bank 5 to switch Bank 6 write to selected chain only */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001044 REG_WRITE(ah, AR_PHY_BASE + 0xD8, bank6SelMask);
1045
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001046 /*
1047 * Modify Bank6 selected chain to use lowest amplification.
1048 * Modifies the parameters to a value of 1.
1049 * Depends on existing bank 6 values to be cached in
1050 * ah->analogBank6Data
1051 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001052 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 189, 0);
1053 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 190, 0);
1054 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 191, 0);
1055 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 192, 0);
1056 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 193, 0);
1057 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 222, 0);
1058 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 245, 0);
1059 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 246, 0);
1060 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 247, 0);
1061
Sujith2660b812009-02-09 13:27:26 +05301062 REG_WRITE_RF_ARRAY(&ah->iniBank6, bank6Temp, regWrites);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001063
1064 REG_WRITE(ah, AR_PHY_BASE + 0xD8, 0x00000053);
1065#ifdef ALTER_SWITCH
1066 REG_WRITE(ah, PHY_SWITCH_CHAIN_0,
1067 (REG_READ(ah, PHY_SWITCH_CHAIN_0) & ~0x38)
1068 | ((REG_READ(ah, PHY_SWITCH_CHAIN_0) >> 3) & 0x38));
1069#endif
1070}