blob: 13ab4d7eb7aaa7e6582d76129c0ec54ebbab04de [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. Rodriguez131d1d02009-10-19 02:33:35 -040044/**
45 * ath9k_hw_write_regs - ??
46 *
47 * @ah: atheros hardware structure
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -040048 * @freqIndex:
49 * @regWrites:
50 *
51 * Used for both the chipsets with an external AR2133/AR5133 radios and
52 * single-chip devices.
53 */
Luis R. Rodriguez896ff262009-10-19 02:33:44 -040054void ath9k_hw_write_regs(struct ath_hw *ah, u32 freqIndex, int regWrites)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070055{
Sujith2660b812009-02-09 13:27:26 +053056 REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070057}
58
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -040059/**
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -040060 * ath9k_hw_ar9280_set_channel - set channel on single-chip device
61 * @ah: atheros hardware structure
62 * @chan:
63 *
64 * This is the function to change channel on single-chip devices, that is
65 * all devices after ar9280.
66 *
67 * This function takes the channel value in MHz and sets
68 * hardware channel value. Assumes writes have been enabled to analog bus.
69 *
70 * Actual Expression,
71 *
72 * For 2GHz channel,
73 * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
74 * (freq_ref = 40MHz)
75 *
76 * For 5GHz channel,
77 * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
78 * (freq_ref = 40MHz/(24>>amodeRefSel))
79 */
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -040080int ath9k_hw_ar9280_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070081{
82 u16 bMode, fracMode, aModeRefSel = 0;
83 u32 freq, ndiv, channelSel = 0, channelFrac = 0, reg32 = 0;
84 struct chan_centers centers;
85 u32 refDivA = 24;
86
87 ath9k_hw_get_channel_centers(ah, chan, &centers);
88 freq = centers.synth_center;
89
90 reg32 = REG_READ(ah, AR_PHY_SYNTH_CONTROL);
91 reg32 &= 0xc0000000;
92
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -040093 if (freq < 4800) { /* 2 GHz, fractional mode */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070094 u32 txctl;
Sujith193cd452009-09-18 15:04:07 +053095 int regWrites = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070096
97 bMode = 1;
98 fracMode = 1;
99 aModeRefSel = 0;
100 channelSel = (freq * 0x10000) / 15;
101
Sujith193cd452009-09-18 15:04:07 +0530102 if (AR_SREV_9287_11_OR_LATER(ah)) {
103 if (freq == 2484) {
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400104 /* Enable channel spreading for channel 14 */
Sujith193cd452009-09-18 15:04:07 +0530105 REG_WRITE_ARRAY(&ah->iniCckfirJapan2484,
106 1, regWrites);
107 } else {
108 REG_WRITE_ARRAY(&ah->iniCckfirNormal,
109 1, regWrites);
110 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700111 } else {
Sujith193cd452009-09-18 15:04:07 +0530112 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
113 if (freq == 2484) {
114 /* Enable channel spreading for channel 14 */
115 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
116 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
117 } else {
118 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
119 txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
120 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700121 }
122 } else {
123 bMode = 0;
124 fracMode = 0;
125
Sujith06d0f062009-02-12 10:06:45 +0530126 switch(ah->eep_ops->get_eeprom(ah, EEP_FRAC_N_5G)) {
127 case 0:
128 if ((freq % 20) == 0) {
129 aModeRefSel = 3;
130 } else if ((freq % 10) == 0) {
131 aModeRefSel = 2;
132 }
133 if (aModeRefSel)
134 break;
135 case 1:
136 default:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700137 aModeRefSel = 0;
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400138 /*
139 * Enable 2G (fractional) mode for channels
140 * which are 5MHz spaced.
141 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700142 fracMode = 1;
143 refDivA = 1;
144 channelSel = (freq * 0x8000) / 15;
145
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400146 /* RefDivA setting */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700147 REG_RMW_FIELD(ah, AR_AN_SYNTH9,
148 AR_AN_SYNTH9_REFDIVA, refDivA);
Sujith06d0f062009-02-12 10:06:45 +0530149
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700150 }
Sujith06d0f062009-02-12 10:06:45 +0530151
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700152 if (!fracMode) {
153 ndiv = (freq * (refDivA >> aModeRefSel)) / 60;
154 channelSel = ndiv & 0x1ff;
155 channelFrac = (ndiv & 0xfffffe00) * 2;
156 channelSel = (channelSel << 17) | channelFrac;
157 }
158 }
159
160 reg32 = reg32 |
161 (bMode << 29) |
162 (fracMode << 28) | (aModeRefSel << 26) | (channelSel);
163
164 REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
165
Sujith2660b812009-02-09 13:27:26 +0530166 ah->curchan = chan;
167 ah->curchan_rad_index = -1;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -0400168
169 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700170}
171
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400172/**
Luis R. Rodrigueze16393b2009-10-19 02:33:42 -0400173 * ath9k_hw_9280_spur_mitigate - convert baseband spur frequency
174 * @ah: atheros hardware structure
175 * @chan:
176 *
177 * For single-chip solutions. Converts to baseband spur frequency given the
178 * input channel frequency and compute register settings below.
179 */
180void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
181{
182 int bb_spur = AR_NO_SPUR;
183 int freq;
184 int bin, cur_bin;
185 int bb_spur_off, spur_subchannel_sd;
186 int spur_freq_sd;
187 int spur_delta_phase;
188 int denominator;
189 int upper, lower, cur_vit_mask;
190 int tmp, newVal;
191 int i;
192 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
193 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
194 };
195 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
196 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
197 };
198 int inc[4] = { 0, 100, 0, 0 };
199 struct chan_centers centers;
200
201 int8_t mask_m[123];
202 int8_t mask_p[123];
203 int8_t mask_amt;
204 int tmp_mask;
205 int cur_bb_spur;
206 bool is2GHz = IS_CHAN_2GHZ(chan);
207
208 memset(&mask_m, 0, sizeof(int8_t) * 123);
209 memset(&mask_p, 0, sizeof(int8_t) * 123);
210
211 ath9k_hw_get_channel_centers(ah, chan, &centers);
212 freq = centers.synth_center;
213
214 ah->config.spurmode = SPUR_ENABLE_EEPROM;
215 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
216 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
217
218 if (is2GHz)
219 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
220 else
221 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
222
223 if (AR_NO_SPUR == cur_bb_spur)
224 break;
225 cur_bb_spur = cur_bb_spur - freq;
226
227 if (IS_CHAN_HT40(chan)) {
228 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
229 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
230 bb_spur = cur_bb_spur;
231 break;
232 }
233 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
234 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
235 bb_spur = cur_bb_spur;
236 break;
237 }
238 }
239
240 if (AR_NO_SPUR == bb_spur) {
241 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
242 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
243 return;
244 } else {
245 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
246 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
247 }
248
249 bin = bb_spur * 320;
250
251 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
252
253 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
254 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
255 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
256 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
257 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
258
259 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
260 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
261 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
262 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
263 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
264 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
265
266 if (IS_CHAN_HT40(chan)) {
267 if (bb_spur < 0) {
268 spur_subchannel_sd = 1;
269 bb_spur_off = bb_spur + 10;
270 } else {
271 spur_subchannel_sd = 0;
272 bb_spur_off = bb_spur - 10;
273 }
274 } else {
275 spur_subchannel_sd = 0;
276 bb_spur_off = bb_spur;
277 }
278
279 if (IS_CHAN_HT40(chan))
280 spur_delta_phase =
281 ((bb_spur * 262144) /
282 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
283 else
284 spur_delta_phase =
285 ((bb_spur * 524288) /
286 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
287
288 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
289 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
290
291 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
292 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
293 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
294 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
295
296 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
297 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
298
299 cur_bin = -6000;
300 upper = bin + 100;
301 lower = bin - 100;
302
303 for (i = 0; i < 4; i++) {
304 int pilot_mask = 0;
305 int chan_mask = 0;
306 int bp = 0;
307 for (bp = 0; bp < 30; bp++) {
308 if ((cur_bin > lower) && (cur_bin < upper)) {
309 pilot_mask = pilot_mask | 0x1 << bp;
310 chan_mask = chan_mask | 0x1 << bp;
311 }
312 cur_bin += 100;
313 }
314 cur_bin += inc[i];
315 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
316 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
317 }
318
319 cur_vit_mask = 6100;
320 upper = bin + 120;
321 lower = bin - 120;
322
323 for (i = 0; i < 123; i++) {
324 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
325
326 /* workaround for gcc bug #37014 */
327 volatile int tmp_v = abs(cur_vit_mask - bin);
328
329 if (tmp_v < 75)
330 mask_amt = 1;
331 else
332 mask_amt = 0;
333 if (cur_vit_mask < 0)
334 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
335 else
336 mask_p[cur_vit_mask / 100] = mask_amt;
337 }
338 cur_vit_mask -= 100;
339 }
340
341 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
342 | (mask_m[48] << 26) | (mask_m[49] << 24)
343 | (mask_m[50] << 22) | (mask_m[51] << 20)
344 | (mask_m[52] << 18) | (mask_m[53] << 16)
345 | (mask_m[54] << 14) | (mask_m[55] << 12)
346 | (mask_m[56] << 10) | (mask_m[57] << 8)
347 | (mask_m[58] << 6) | (mask_m[59] << 4)
348 | (mask_m[60] << 2) | (mask_m[61] << 0);
349 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
350 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
351
352 tmp_mask = (mask_m[31] << 28)
353 | (mask_m[32] << 26) | (mask_m[33] << 24)
354 | (mask_m[34] << 22) | (mask_m[35] << 20)
355 | (mask_m[36] << 18) | (mask_m[37] << 16)
356 | (mask_m[48] << 14) | (mask_m[39] << 12)
357 | (mask_m[40] << 10) | (mask_m[41] << 8)
358 | (mask_m[42] << 6) | (mask_m[43] << 4)
359 | (mask_m[44] << 2) | (mask_m[45] << 0);
360 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
361 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
362
363 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
364 | (mask_m[18] << 26) | (mask_m[18] << 24)
365 | (mask_m[20] << 22) | (mask_m[20] << 20)
366 | (mask_m[22] << 18) | (mask_m[22] << 16)
367 | (mask_m[24] << 14) | (mask_m[24] << 12)
368 | (mask_m[25] << 10) | (mask_m[26] << 8)
369 | (mask_m[27] << 6) | (mask_m[28] << 4)
370 | (mask_m[29] << 2) | (mask_m[30] << 0);
371 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
372 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
373
374 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
375 | (mask_m[2] << 26) | (mask_m[3] << 24)
376 | (mask_m[4] << 22) | (mask_m[5] << 20)
377 | (mask_m[6] << 18) | (mask_m[7] << 16)
378 | (mask_m[8] << 14) | (mask_m[9] << 12)
379 | (mask_m[10] << 10) | (mask_m[11] << 8)
380 | (mask_m[12] << 6) | (mask_m[13] << 4)
381 | (mask_m[14] << 2) | (mask_m[15] << 0);
382 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
383 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
384
385 tmp_mask = (mask_p[15] << 28)
386 | (mask_p[14] << 26) | (mask_p[13] << 24)
387 | (mask_p[12] << 22) | (mask_p[11] << 20)
388 | (mask_p[10] << 18) | (mask_p[9] << 16)
389 | (mask_p[8] << 14) | (mask_p[7] << 12)
390 | (mask_p[6] << 10) | (mask_p[5] << 8)
391 | (mask_p[4] << 6) | (mask_p[3] << 4)
392 | (mask_p[2] << 2) | (mask_p[1] << 0);
393 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
394 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
395
396 tmp_mask = (mask_p[30] << 28)
397 | (mask_p[29] << 26) | (mask_p[28] << 24)
398 | (mask_p[27] << 22) | (mask_p[26] << 20)
399 | (mask_p[25] << 18) | (mask_p[24] << 16)
400 | (mask_p[23] << 14) | (mask_p[22] << 12)
401 | (mask_p[21] << 10) | (mask_p[20] << 8)
402 | (mask_p[19] << 6) | (mask_p[18] << 4)
403 | (mask_p[17] << 2) | (mask_p[16] << 0);
404 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
405 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
406
407 tmp_mask = (mask_p[45] << 28)
408 | (mask_p[44] << 26) | (mask_p[43] << 24)
409 | (mask_p[42] << 22) | (mask_p[41] << 20)
410 | (mask_p[40] << 18) | (mask_p[39] << 16)
411 | (mask_p[38] << 14) | (mask_p[37] << 12)
412 | (mask_p[36] << 10) | (mask_p[35] << 8)
413 | (mask_p[34] << 6) | (mask_p[33] << 4)
414 | (mask_p[32] << 2) | (mask_p[31] << 0);
415 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
416 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
417
418 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
419 | (mask_p[59] << 26) | (mask_p[58] << 24)
420 | (mask_p[57] << 22) | (mask_p[56] << 20)
421 | (mask_p[55] << 18) | (mask_p[54] << 16)
422 | (mask_p[53] << 14) | (mask_p[52] << 12)
423 | (mask_p[51] << 10) | (mask_p[50] << 8)
424 | (mask_p[49] << 6) | (mask_p[48] << 4)
425 | (mask_p[47] << 2) | (mask_p[46] << 0);
426 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
427 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
428}
429
430/* All code below is for non single-chip solutions */
431
Luis R. Rodriguezddcd4c02009-10-19 02:33:46 -0400432/**
433 * ath9k_phy_modify_rx_buffer() - perform analog swizzling of parameters
434 * @rfbuf:
435 * @reg32:
436 * @numBits:
437 * @firstBit:
438 * @column:
439 *
440 * Performs analog "swizzling" of parameters into their location.
441 * Used on external AR2133/AR5133 radios.
442 */
443static void ath9k_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
444 u32 numBits, u32 firstBit,
445 u32 column)
446{
447 u32 tmp32, mask, arrayEntry, lastBit;
448 int32_t bitPosition, bitsLeft;
449
450 tmp32 = ath9k_hw_reverse_bits(reg32, numBits);
451 arrayEntry = (firstBit - 1) / 8;
452 bitPosition = (firstBit - 1) % 8;
453 bitsLeft = numBits;
454 while (bitsLeft > 0) {
455 lastBit = (bitPosition + bitsLeft > 8) ?
456 8 : bitPosition + bitsLeft;
457 mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) <<
458 (column * 8);
459 rfBuf[arrayEntry] &= ~mask;
460 rfBuf[arrayEntry] |= ((tmp32 << bitPosition) <<
461 (column * 8)) & mask;
462 bitsLeft -= 8 - bitPosition;
463 tmp32 = tmp32 >> (8 - bitPosition);
464 bitPosition = 0;
465 arrayEntry++;
466 }
467}
468
Luis R. Rodrigueza7765822009-10-19 02:33:45 -0400469/*
470 * Fix on 2.4 GHz band for orientation sensitivity issue by increasing
471 * rf_pwd_icsyndiv.
472 *
473 * Theoretical Rules:
474 * if 2 GHz band
475 * if forceBiasAuto
476 * if synth_freq < 2412
477 * bias = 0
478 * else if 2412 <= synth_freq <= 2422
479 * bias = 1
480 * else // synth_freq > 2422
481 * bias = 2
482 * else if forceBias > 0
483 * bias = forceBias & 7
484 * else
485 * no change, use value from ini file
486 * else
487 * no change, invalid band
488 *
489 * 1st Mod:
490 * 2422 also uses value of 2
491 * <approved>
492 *
493 * 2nd Mod:
494 * Less than 2412 uses value of 0, 2412 and above uses value of 2
495 */
496static void ath9k_hw_force_bias(struct ath_hw *ah, u16 synth_freq)
497{
498 struct ath_common *common = ath9k_hw_common(ah);
499 u32 tmp_reg;
500 int reg_writes = 0;
501 u32 new_bias = 0;
502
503 if (!AR_SREV_5416(ah) || synth_freq >= 3000) {
504 return;
505 }
506
507 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
508
509 if (synth_freq < 2412)
510 new_bias = 0;
511 else if (synth_freq < 2422)
512 new_bias = 1;
513 else
514 new_bias = 2;
515
516 /* pre-reverse this field */
517 tmp_reg = ath9k_hw_reverse_bits(new_bias, 3);
518
519 ath_print(common, ATH_DBG_CONFIG,
520 "Force rf_pwd_icsyndiv to %1d on %4d\n",
521 new_bias, synth_freq);
522
523 /* swizzle rf_pwd_icsyndiv */
524 ath9k_phy_modify_rx_buffer(ah->analogBank6Data, tmp_reg, 3, 181, 3);
525
526 /* write Bank 6 with new params */
527 REG_WRITE_RF_ARRAY(&ah->iniBank6, ah->analogBank6Data, reg_writes);
528}
529
Luis R. Rodrigueze16393b2009-10-19 02:33:42 -0400530/**
Luis R. Rodriguezddcd4c02009-10-19 02:33:46 -0400531 * ath9k_hw_decrease_chain_power()
532 *
533 * @ah: atheros hardware structure
534 * @chan:
535 *
536 * Only used on the AR5416 and AR5418 with the external AR2133/AR5133 radios.
537 *
538 * Sets a chain internal RF path to the lowest output power. Any
539 * further writes to bank6 after this setting will override these
540 * changes. Thus this function must be the last function in the
541 * sequence to modify bank 6.
542 *
543 * This function must be called after ar5416SetRfRegs() which is
544 * called from ath9k_hw_process_ini() due to swizzling of bank 6.
545 * Depends on ah->analogBank6Data being initialized by
546 * ath9k_hw_set_rf_regs()
547 *
548 * Additional additive reduction in power -
549 * change chain's switch table so chain's tx state is actually the rx
550 * state value. May produce different results in 2GHz/5GHz as well as
551 * board to board but in general should be a reduction.
552 *
553 * Activated by #ifdef ALTER_SWITCH. Not tried yet. If so, must be
554 * called after ah->eep_ops->set_board_values() due to RMW of
555 * PHY_SWITCH_CHAIN_0.
556 */
557void ath9k_hw_decrease_chain_power(struct ath_hw *ah,
558 struct ath9k_channel *chan)
559{
560 int i, regWrites = 0;
561 u32 bank6SelMask;
562 u32 *bank6Temp = ah->bank6Temp;
563
564 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
565
566 switch (ah->config.diversity_control) {
567 case ATH9K_ANT_FIXED_A:
568 bank6SelMask =
569 (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
570 REDUCE_CHAIN_0 : /* swapped, reduce chain 0 */
571 REDUCE_CHAIN_1; /* normal, select chain 1/2 to reduce */
572 break;
573 case ATH9K_ANT_FIXED_B:
574 bank6SelMask =
575 (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
576 REDUCE_CHAIN_1 : /* swapped, reduce chain 1/2 */
577 REDUCE_CHAIN_0; /* normal, select chain 0 to reduce */
578 break;
579 case ATH9K_ANT_VARIABLE:
580 return; /* do not change anything */
581 break;
582 default:
583 return; /* do not change anything */
584 break;
585 }
586
587 for (i = 0; i < ah->iniBank6.ia_rows; i++)
588 bank6Temp[i] = ah->analogBank6Data[i];
589
590 /* Write Bank 5 to switch Bank 6 write to selected chain only */
591 REG_WRITE(ah, AR_PHY_BASE + 0xD8, bank6SelMask);
592
593 /*
594 * Modify Bank6 selected chain to use lowest amplification.
595 * Modifies the parameters to a value of 1.
596 * Depends on existing bank 6 values to be cached in
597 * ah->analogBank6Data
598 */
599 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 189, 0);
600 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 190, 0);
601 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 191, 0);
602 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 192, 0);
603 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 193, 0);
604 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 222, 0);
605 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 245, 0);
606 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 246, 0);
607 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 247, 0);
608
609 REG_WRITE_RF_ARRAY(&ah->iniBank6, bank6Temp, regWrites);
610
611 REG_WRITE(ah, AR_PHY_BASE + 0xD8, 0x00000053);
612#ifdef ALTER_SWITCH
613 REG_WRITE(ah, PHY_SWITCH_CHAIN_0,
614 (REG_READ(ah, PHY_SWITCH_CHAIN_0) & ~0x38)
615 | ((REG_READ(ah, PHY_SWITCH_CHAIN_0) >> 3) & 0x38));
616#endif
617}
618
619/**
Luis R. Rodrigueze16393b2009-10-19 02:33:42 -0400620 * ath9k_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios
621 * @ah: atheros hardware stucture
622 * @chan:
623 *
624 * For the external AR2133/AR5133 radios, takes the MHz channel value and set
625 * the channel value. Assumes writes enabled to analog bus and bank6 register
626 * cache in ah->analogBank6Data.
627 */
628int ath9k_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
629{
630 struct ath_common *common = ath9k_hw_common(ah);
631 u32 channelSel = 0;
632 u32 bModeSynth = 0;
633 u32 aModeRefSel = 0;
634 u32 reg32 = 0;
635 u16 freq;
636 struct chan_centers centers;
637
638 ath9k_hw_get_channel_centers(ah, chan, &centers);
639 freq = centers.synth_center;
640
641 if (freq < 4800) {
642 u32 txctl;
643
644 if (((freq - 2192) % 5) == 0) {
645 channelSel = ((freq - 672) * 2 - 3040) / 10;
646 bModeSynth = 0;
647 } else if (((freq - 2224) % 5) == 0) {
648 channelSel = ((freq - 704) * 2 - 3040) / 10;
649 bModeSynth = 1;
650 } else {
651 ath_print(common, ATH_DBG_FATAL,
652 "Invalid channel %u MHz\n", freq);
653 return -EINVAL;
654 }
655
656 channelSel = (channelSel << 2) & 0xff;
657 channelSel = ath9k_hw_reverse_bits(channelSel, 8);
658
659 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
660 if (freq == 2484) {
661
662 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
663 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
664 } else {
665 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
666 txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
667 }
668
669 } else if ((freq % 20) == 0 && freq >= 5120) {
670 channelSel =
671 ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
672 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
673 } else if ((freq % 10) == 0) {
674 channelSel =
675 ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
676 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
677 aModeRefSel = ath9k_hw_reverse_bits(2, 2);
678 else
679 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
680 } else if ((freq % 5) == 0) {
681 channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
682 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
683 } else {
684 ath_print(common, ATH_DBG_FATAL,
685 "Invalid channel %u MHz\n", freq);
686 return -EINVAL;
687 }
688
Luis R. Rodrigueza7765822009-10-19 02:33:45 -0400689 ath9k_hw_force_bias(ah, freq);
690 ath9k_hw_decrease_chain_power(ah, chan);
691
Luis R. Rodrigueze16393b2009-10-19 02:33:42 -0400692 reg32 =
693 (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
694 (1 << 5) | 0x1;
695
696 REG_WRITE(ah, AR_PHY(0x37), reg32);
697
698 ah->curchan = chan;
699 ah->curchan_rad_index = -1;
700
701 return 0;
702}
703
704/**
705 * ath9k_hw_spur_mitigate - convert baseband spur frequency for external radios
706 * @ah: atheros hardware structure
707 * @chan:
708 *
709 * For non single-chip solutions. Converts to baseband spur frequency given the
710 * input channel frequency and compute register settings below.
711 */
712void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
713{
714 int bb_spur = AR_NO_SPUR;
715 int bin, cur_bin;
716 int spur_freq_sd;
717 int spur_delta_phase;
718 int denominator;
719 int upper, lower, cur_vit_mask;
720 int tmp, new;
721 int i;
722 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
723 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
724 };
725 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
726 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
727 };
728 int inc[4] = { 0, 100, 0, 0 };
729
730 int8_t mask_m[123];
731 int8_t mask_p[123];
732 int8_t mask_amt;
733 int tmp_mask;
734 int cur_bb_spur;
735 bool is2GHz = IS_CHAN_2GHZ(chan);
736
737 memset(&mask_m, 0, sizeof(int8_t) * 123);
738 memset(&mask_p, 0, sizeof(int8_t) * 123);
739
740 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
741 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
742 if (AR_NO_SPUR == cur_bb_spur)
743 break;
744 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
745 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
746 bb_spur = cur_bb_spur;
747 break;
748 }
749 }
750
751 if (AR_NO_SPUR == bb_spur)
752 return;
753
754 bin = bb_spur * 32;
755
756 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
757 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
758 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
759 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
760 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
761
762 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
763
764 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
765 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
766 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
767 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
768 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
769 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
770
771 spur_delta_phase = ((bb_spur * 524288) / 100) &
772 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
773
774 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
775 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
776
777 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
778 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
779 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
780 REG_WRITE(ah, AR_PHY_TIMING11, new);
781
782 cur_bin = -6000;
783 upper = bin + 100;
784 lower = bin - 100;
785
786 for (i = 0; i < 4; i++) {
787 int pilot_mask = 0;
788 int chan_mask = 0;
789 int bp = 0;
790 for (bp = 0; bp < 30; bp++) {
791 if ((cur_bin > lower) && (cur_bin < upper)) {
792 pilot_mask = pilot_mask | 0x1 << bp;
793 chan_mask = chan_mask | 0x1 << bp;
794 }
795 cur_bin += 100;
796 }
797 cur_bin += inc[i];
798 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
799 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
800 }
801
802 cur_vit_mask = 6100;
803 upper = bin + 120;
804 lower = bin - 120;
805
806 for (i = 0; i < 123; i++) {
807 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
808
809 /* workaround for gcc bug #37014 */
810 volatile int tmp_v = abs(cur_vit_mask - bin);
811
812 if (tmp_v < 75)
813 mask_amt = 1;
814 else
815 mask_amt = 0;
816 if (cur_vit_mask < 0)
817 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
818 else
819 mask_p[cur_vit_mask / 100] = mask_amt;
820 }
821 cur_vit_mask -= 100;
822 }
823
824 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
825 | (mask_m[48] << 26) | (mask_m[49] << 24)
826 | (mask_m[50] << 22) | (mask_m[51] << 20)
827 | (mask_m[52] << 18) | (mask_m[53] << 16)
828 | (mask_m[54] << 14) | (mask_m[55] << 12)
829 | (mask_m[56] << 10) | (mask_m[57] << 8)
830 | (mask_m[58] << 6) | (mask_m[59] << 4)
831 | (mask_m[60] << 2) | (mask_m[61] << 0);
832 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
833 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
834
835 tmp_mask = (mask_m[31] << 28)
836 | (mask_m[32] << 26) | (mask_m[33] << 24)
837 | (mask_m[34] << 22) | (mask_m[35] << 20)
838 | (mask_m[36] << 18) | (mask_m[37] << 16)
839 | (mask_m[48] << 14) | (mask_m[39] << 12)
840 | (mask_m[40] << 10) | (mask_m[41] << 8)
841 | (mask_m[42] << 6) | (mask_m[43] << 4)
842 | (mask_m[44] << 2) | (mask_m[45] << 0);
843 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
844 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
845
846 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
847 | (mask_m[18] << 26) | (mask_m[18] << 24)
848 | (mask_m[20] << 22) | (mask_m[20] << 20)
849 | (mask_m[22] << 18) | (mask_m[22] << 16)
850 | (mask_m[24] << 14) | (mask_m[24] << 12)
851 | (mask_m[25] << 10) | (mask_m[26] << 8)
852 | (mask_m[27] << 6) | (mask_m[28] << 4)
853 | (mask_m[29] << 2) | (mask_m[30] << 0);
854 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
855 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
856
857 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
858 | (mask_m[2] << 26) | (mask_m[3] << 24)
859 | (mask_m[4] << 22) | (mask_m[5] << 20)
860 | (mask_m[6] << 18) | (mask_m[7] << 16)
861 | (mask_m[8] << 14) | (mask_m[9] << 12)
862 | (mask_m[10] << 10) | (mask_m[11] << 8)
863 | (mask_m[12] << 6) | (mask_m[13] << 4)
864 | (mask_m[14] << 2) | (mask_m[15] << 0);
865 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
866 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
867
868 tmp_mask = (mask_p[15] << 28)
869 | (mask_p[14] << 26) | (mask_p[13] << 24)
870 | (mask_p[12] << 22) | (mask_p[11] << 20)
871 | (mask_p[10] << 18) | (mask_p[9] << 16)
872 | (mask_p[8] << 14) | (mask_p[7] << 12)
873 | (mask_p[6] << 10) | (mask_p[5] << 8)
874 | (mask_p[4] << 6) | (mask_p[3] << 4)
875 | (mask_p[2] << 2) | (mask_p[1] << 0);
876 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
877 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
878
879 tmp_mask = (mask_p[30] << 28)
880 | (mask_p[29] << 26) | (mask_p[28] << 24)
881 | (mask_p[27] << 22) | (mask_p[26] << 20)
882 | (mask_p[25] << 18) | (mask_p[24] << 16)
883 | (mask_p[23] << 14) | (mask_p[22] << 12)
884 | (mask_p[21] << 10) | (mask_p[20] << 8)
885 | (mask_p[19] << 6) | (mask_p[18] << 4)
886 | (mask_p[17] << 2) | (mask_p[16] << 0);
887 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
888 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
889
890 tmp_mask = (mask_p[45] << 28)
891 | (mask_p[44] << 26) | (mask_p[43] << 24)
892 | (mask_p[42] << 22) | (mask_p[41] << 20)
893 | (mask_p[40] << 18) | (mask_p[39] << 16)
894 | (mask_p[38] << 14) | (mask_p[37] << 12)
895 | (mask_p[36] << 10) | (mask_p[35] << 8)
896 | (mask_p[34] << 6) | (mask_p[33] << 4)
897 | (mask_p[32] << 2) | (mask_p[31] << 0);
898 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
899 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
900
901 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
902 | (mask_p[59] << 26) | (mask_p[58] << 24)
903 | (mask_p[57] << 22) | (mask_p[56] << 20)
904 | (mask_p[55] << 18) | (mask_p[54] << 16)
905 | (mask_p[53] << 14) | (mask_p[52] << 12)
906 | (mask_p[51] << 10) | (mask_p[50] << 8)
907 | (mask_p[49] << 6) | (mask_p[48] << 4)
908 | (mask_p[47] << 2) | (mask_p[46] << 0);
909 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
910 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
911}
912
913/**
914 * ath9k_hw_rf_alloc_ext_banks - allocates banks for external radio programming
915 * @ah: atheros hardware structure
916 *
917 * Only required for older devices with external AR2133/AR5133 radios.
918 */
919int ath9k_hw_rf_alloc_ext_banks(struct ath_hw *ah)
920{
921#define ATH_ALLOC_BANK(bank, size) do { \
922 bank = kzalloc((sizeof(u32) * size), GFP_KERNEL); \
923 if (!bank) { \
924 ath_print(common, ATH_DBG_FATAL, \
925 "Cannot allocate RF banks\n"); \
926 return -ENOMEM; \
927 } \
928 } while (0);
929
930 struct ath_common *common = ath9k_hw_common(ah);
931
932 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
933
934 ATH_ALLOC_BANK(ah->analogBank0Data, ah->iniBank0.ia_rows);
935 ATH_ALLOC_BANK(ah->analogBank1Data, ah->iniBank1.ia_rows);
936 ATH_ALLOC_BANK(ah->analogBank2Data, ah->iniBank2.ia_rows);
937 ATH_ALLOC_BANK(ah->analogBank3Data, ah->iniBank3.ia_rows);
938 ATH_ALLOC_BANK(ah->analogBank6Data, ah->iniBank6.ia_rows);
939 ATH_ALLOC_BANK(ah->analogBank6TPCData, ah->iniBank6TPC.ia_rows);
940 ATH_ALLOC_BANK(ah->analogBank7Data, ah->iniBank7.ia_rows);
941 ATH_ALLOC_BANK(ah->addac5416_21,
942 ah->iniAddac.ia_rows * ah->iniAddac.ia_columns);
943 ATH_ALLOC_BANK(ah->bank6Temp, ah->iniBank6.ia_rows);
944
945 return 0;
946#undef ATH_ALLOC_BANK
947}
948
949
950/**
951 * ath9k_hw_rf_free_ext_banks - Free memory for analog bank scratch buffers
952 * @ah: atheros hardware struture
953 * For the external AR2133/AR5133 radios banks.
954 */
955void
956ath9k_hw_rf_free_ext_banks(struct ath_hw *ah)
957{
958#define ATH_FREE_BANK(bank) do { \
959 kfree(bank); \
960 bank = NULL; \
961 } while (0);
962
963 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
964
965 ATH_FREE_BANK(ah->analogBank0Data);
966 ATH_FREE_BANK(ah->analogBank1Data);
967 ATH_FREE_BANK(ah->analogBank2Data);
968 ATH_FREE_BANK(ah->analogBank3Data);
969 ATH_FREE_BANK(ah->analogBank6Data);
970 ATH_FREE_BANK(ah->analogBank6TPCData);
971 ATH_FREE_BANK(ah->analogBank7Data);
972 ATH_FREE_BANK(ah->addac5416_21);
973 ATH_FREE_BANK(ah->bank6Temp);
974
975#undef ATH_FREE_BANK
976}
977
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400978/* *
979 * ath9k_hw_set_rf_regs - programs rf registers based on EEPROM
980 * @ah: atheros hardware structure
981 * @chan:
982 * @modesIndex:
983 *
984 * Used for the external AR2133/AR5133 radios.
985 *
986 * Reads the EEPROM header info from the device structure and programs
987 * all rf registers. This routine requires access to the analog
988 * rf device. This is not required for single-chip devices.
989 */
Luis R. Rodrigueze16393b2009-10-19 02:33:42 -0400990bool ath9k_hw_set_rf_regs(struct ath_hw *ah, struct ath9k_channel *chan,
991 u16 modesIndex)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700992{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700993 u32 eepMinorRev;
994 u32 ob5GHz = 0, db5GHz = 0;
995 u32 ob2GHz = 0, db2GHz = 0;
996 int regWrites = 0;
997
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400998 /*
999 * Software does not need to program bank data
1000 * for single chip devices, that is AR9280 or anything
1001 * after that.
1002 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001003 if (AR_SREV_9280_10_OR_LATER(ah))
1004 return true;
1005
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001006 /* Setup rf parameters */
Sujithf74df6f2009-02-09 13:27:24 +05301007 eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001008
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001009 /* Setup Bank 0 Write */
Sujith2660b812009-02-09 13:27:26 +05301010 RF_BANK_SETUP(ah->analogBank0Data, &ah->iniBank0, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001011
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001012 /* Setup Bank 1 Write */
Sujith2660b812009-02-09 13:27:26 +05301013 RF_BANK_SETUP(ah->analogBank1Data, &ah->iniBank1, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001014
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001015 /* Setup Bank 2 Write */
Sujith2660b812009-02-09 13:27:26 +05301016 RF_BANK_SETUP(ah->analogBank2Data, &ah->iniBank2, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001017
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001018 /* Setup Bank 6 Write */
Sujith2660b812009-02-09 13:27:26 +05301019 RF_BANK_SETUP(ah->analogBank3Data, &ah->iniBank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001020 modesIndex);
1021 {
1022 int i;
Sujith2660b812009-02-09 13:27:26 +05301023 for (i = 0; i < ah->iniBank6TPC.ia_rows; i++) {
1024 ah->analogBank6Data[i] =
1025 INI_RA(&ah->iniBank6TPC, i, modesIndex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001026 }
1027 }
1028
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001029 /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001030 if (eepMinorRev >= 2) {
1031 if (IS_CHAN_2GHZ(chan)) {
Sujithf74df6f2009-02-09 13:27:24 +05301032 ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
1033 db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2);
Sujith2660b812009-02-09 13:27:26 +05301034 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001035 ob2GHz, 3, 197, 0);
Sujith2660b812009-02-09 13:27:26 +05301036 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001037 db2GHz, 3, 194, 0);
1038 } else {
Sujithf74df6f2009-02-09 13:27:24 +05301039 ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5);
1040 db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5);
Sujith2660b812009-02-09 13:27:26 +05301041 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001042 ob5GHz, 3, 203, 0);
Sujith2660b812009-02-09 13:27:26 +05301043 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001044 db5GHz, 3, 200, 0);
1045 }
1046 }
1047
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001048 /* Setup Bank 7 Setup */
Sujith2660b812009-02-09 13:27:26 +05301049 RF_BANK_SETUP(ah->analogBank7Data, &ah->iniBank7, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001050
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -04001051 /* Write Analog registers */
Sujith2660b812009-02-09 13:27:26 +05301052 REG_WRITE_RF_ARRAY(&ah->iniBank0, ah->analogBank0Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001053 regWrites);
Sujith2660b812009-02-09 13:27:26 +05301054 REG_WRITE_RF_ARRAY(&ah->iniBank1, ah->analogBank1Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001055 regWrites);
Sujith2660b812009-02-09 13:27:26 +05301056 REG_WRITE_RF_ARRAY(&ah->iniBank2, ah->analogBank2Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001057 regWrites);
Sujith2660b812009-02-09 13:27:26 +05301058 REG_WRITE_RF_ARRAY(&ah->iniBank3, ah->analogBank3Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001059 regWrites);
Sujith2660b812009-02-09 13:27:26 +05301060 REG_WRITE_RF_ARRAY(&ah->iniBank6TPC, ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001061 regWrites);
Sujith2660b812009-02-09 13:27:26 +05301062 REG_WRITE_RF_ARRAY(&ah->iniBank7, ah->analogBank7Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001063 regWrites);
1064
1065 return true;
1066}