blob: bfcb9af4ae3c1fabadfa187cfe8bbd69e6593253 [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
48 * @modesIndex:
49 * @freqIndex:
50 * @regWrites:
51 *
52 * Used for both the chipsets with an external AR2133/AR5133 radios and
53 * single-chip devices.
54 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070055void
Sujithcbe61d82009-02-09 13:27:12 +053056ath9k_hw_write_regs(struct ath_hw *ah, u32 modesIndex, u32 freqIndex,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070057 int regWrites)
58{
Sujith2660b812009-02-09 13:27:26 +053059 REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070060}
61
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -040062/**
63 * ath9k_hw_set_channel - tune to a channel on the external AR2133/AR5133 radios
64 * @ah: atheros hardware stucture
65 * @chan:
66 *
67 * For the external AR2133/AR5133 radios, takes the MHz channel value and set
68 * the channel value. Assumes writes enabled to analog bus and bank6 register
69 * cache in ah->analogBank6Data.
70 */
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -040071int ath9k_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070072{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070073 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070074 u32 channelSel = 0;
75 u32 bModeSynth = 0;
76 u32 aModeRefSel = 0;
77 u32 reg32 = 0;
78 u16 freq;
79 struct chan_centers centers;
80
81 ath9k_hw_get_channel_centers(ah, chan, &centers);
82 freq = centers.synth_center;
83
84 if (freq < 4800) {
85 u32 txctl;
86
87 if (((freq - 2192) % 5) == 0) {
88 channelSel = ((freq - 672) * 2 - 3040) / 10;
89 bModeSynth = 0;
90 } else if (((freq - 2224) % 5) == 0) {
91 channelSel = ((freq - 704) * 2 - 3040) / 10;
92 bModeSynth = 1;
93 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070094 ath_print(common, ATH_DBG_FATAL,
95 "Invalid channel %u MHz\n", freq);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -040096 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070097 }
98
99 channelSel = (channelSel << 2) & 0xff;
100 channelSel = ath9k_hw_reverse_bits(channelSel, 8);
101
102 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
103 if (freq == 2484) {
104
105 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
106 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
107 } else {
108 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
109 txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
110 }
111
112 } else if ((freq % 20) == 0 && freq >= 5120) {
113 channelSel =
114 ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
115 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
116 } else if ((freq % 10) == 0) {
117 channelSel =
118 ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
119 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
120 aModeRefSel = ath9k_hw_reverse_bits(2, 2);
121 else
122 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
123 } else if ((freq % 5) == 0) {
124 channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
125 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
126 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700127 ath_print(common, ATH_DBG_FATAL,
128 "Invalid channel %u MHz\n", freq);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -0400129 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700130 }
131
132 reg32 =
133 (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
134 (1 << 5) | 0x1;
135
136 REG_WRITE(ah, AR_PHY(0x37), reg32);
137
Sujith2660b812009-02-09 13:27:26 +0530138 ah->curchan = chan;
139 ah->curchan_rad_index = -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700140
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -0400141 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700142}
143
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400144/**
145 * ath9k_hw_ar9280_set_channel - set channel on single-chip device
146 * @ah: atheros hardware structure
147 * @chan:
148 *
149 * This is the function to change channel on single-chip devices, that is
150 * all devices after ar9280.
151 *
152 * This function takes the channel value in MHz and sets
153 * hardware channel value. Assumes writes have been enabled to analog bus.
154 *
155 * Actual Expression,
156 *
157 * For 2GHz channel,
158 * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
159 * (freq_ref = 40MHz)
160 *
161 * For 5GHz channel,
162 * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
163 * (freq_ref = 40MHz/(24>>amodeRefSel))
164 */
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -0400165int ath9k_hw_ar9280_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700166{
167 u16 bMode, fracMode, aModeRefSel = 0;
168 u32 freq, ndiv, channelSel = 0, channelFrac = 0, reg32 = 0;
169 struct chan_centers centers;
170 u32 refDivA = 24;
171
172 ath9k_hw_get_channel_centers(ah, chan, &centers);
173 freq = centers.synth_center;
174
175 reg32 = REG_READ(ah, AR_PHY_SYNTH_CONTROL);
176 reg32 &= 0xc0000000;
177
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400178 if (freq < 4800) { /* 2 GHz, fractional mode */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700179 u32 txctl;
Sujith193cd452009-09-18 15:04:07 +0530180 int regWrites = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700181
182 bMode = 1;
183 fracMode = 1;
184 aModeRefSel = 0;
185 channelSel = (freq * 0x10000) / 15;
186
Sujith193cd452009-09-18 15:04:07 +0530187 if (AR_SREV_9287_11_OR_LATER(ah)) {
188 if (freq == 2484) {
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400189 /* Enable channel spreading for channel 14 */
Sujith193cd452009-09-18 15:04:07 +0530190 REG_WRITE_ARRAY(&ah->iniCckfirJapan2484,
191 1, regWrites);
192 } else {
193 REG_WRITE_ARRAY(&ah->iniCckfirNormal,
194 1, regWrites);
195 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700196 } else {
Sujith193cd452009-09-18 15:04:07 +0530197 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
198 if (freq == 2484) {
199 /* Enable channel spreading for channel 14 */
200 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
201 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
202 } else {
203 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
204 txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
205 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700206 }
207 } else {
208 bMode = 0;
209 fracMode = 0;
210
Sujith06d0f062009-02-12 10:06:45 +0530211 switch(ah->eep_ops->get_eeprom(ah, EEP_FRAC_N_5G)) {
212 case 0:
213 if ((freq % 20) == 0) {
214 aModeRefSel = 3;
215 } else if ((freq % 10) == 0) {
216 aModeRefSel = 2;
217 }
218 if (aModeRefSel)
219 break;
220 case 1:
221 default:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700222 aModeRefSel = 0;
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400223 /*
224 * Enable 2G (fractional) mode for channels
225 * which are 5MHz spaced.
226 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700227 fracMode = 1;
228 refDivA = 1;
229 channelSel = (freq * 0x8000) / 15;
230
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400231 /* RefDivA setting */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700232 REG_RMW_FIELD(ah, AR_AN_SYNTH9,
233 AR_AN_SYNTH9_REFDIVA, refDivA);
Sujith06d0f062009-02-12 10:06:45 +0530234
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700235 }
Sujith06d0f062009-02-12 10:06:45 +0530236
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700237 if (!fracMode) {
238 ndiv = (freq * (refDivA >> aModeRefSel)) / 60;
239 channelSel = ndiv & 0x1ff;
240 channelFrac = (ndiv & 0xfffffe00) * 2;
241 channelSel = (channelSel << 17) | channelFrac;
242 }
243 }
244
245 reg32 = reg32 |
246 (bMode << 29) |
247 (fracMode << 28) | (aModeRefSel << 26) | (channelSel);
248
249 REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
250
Sujith2660b812009-02-09 13:27:26 +0530251 ah->curchan = chan;
252 ah->curchan_rad_index = -1;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -0400253
254 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700255}
256
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400257/**
258 * ath9k_phy_modify_rx_buffer() - perform analog swizzling of parameters
259 * @rfbuf:
260 * @reg32:
261 * @numBits:
262 * @firstBit:
263 * @column:
264 *
265 * Performs analog "swizzling" of parameters into their location.
266 * Used on external AR2133/AR5133 radios.
267 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700268static void
269ath9k_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
270 u32 numBits, u32 firstBit,
271 u32 column)
272{
273 u32 tmp32, mask, arrayEntry, lastBit;
274 int32_t bitPosition, bitsLeft;
275
276 tmp32 = ath9k_hw_reverse_bits(reg32, numBits);
277 arrayEntry = (firstBit - 1) / 8;
278 bitPosition = (firstBit - 1) % 8;
279 bitsLeft = numBits;
280 while (bitsLeft > 0) {
281 lastBit = (bitPosition + bitsLeft > 8) ?
282 8 : bitPosition + bitsLeft;
283 mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) <<
284 (column * 8);
285 rfBuf[arrayEntry] &= ~mask;
286 rfBuf[arrayEntry] |= ((tmp32 << bitPosition) <<
287 (column * 8)) & mask;
288 bitsLeft -= 8 - bitPosition;
289 tmp32 = tmp32 >> (8 - bitPosition);
290 bitPosition = 0;
291 arrayEntry++;
292 }
293}
294
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400295/* *
296 * ath9k_hw_set_rf_regs - programs rf registers based on EEPROM
297 * @ah: atheros hardware structure
298 * @chan:
299 * @modesIndex:
300 *
301 * Used for the external AR2133/AR5133 radios.
302 *
303 * Reads the EEPROM header info from the device structure and programs
304 * all rf registers. This routine requires access to the analog
305 * rf device. This is not required for single-chip devices.
306 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700307bool
Sujithcbe61d82009-02-09 13:27:12 +0530308ath9k_hw_set_rf_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700309 u16 modesIndex)
310{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700311 u32 eepMinorRev;
312 u32 ob5GHz = 0, db5GHz = 0;
313 u32 ob2GHz = 0, db2GHz = 0;
314 int regWrites = 0;
315
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400316 /*
317 * Software does not need to program bank data
318 * for single chip devices, that is AR9280 or anything
319 * after that.
320 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700321 if (AR_SREV_9280_10_OR_LATER(ah))
322 return true;
323
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400324 /* Setup rf parameters */
Sujithf74df6f2009-02-09 13:27:24 +0530325 eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700326
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400327 /* Setup Bank 0 Write */
Sujith2660b812009-02-09 13:27:26 +0530328 RF_BANK_SETUP(ah->analogBank0Data, &ah->iniBank0, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700329
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400330 /* Setup Bank 1 Write */
Sujith2660b812009-02-09 13:27:26 +0530331 RF_BANK_SETUP(ah->analogBank1Data, &ah->iniBank1, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700332
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400333 /* Setup Bank 2 Write */
Sujith2660b812009-02-09 13:27:26 +0530334 RF_BANK_SETUP(ah->analogBank2Data, &ah->iniBank2, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700335
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400336 /* Setup Bank 6 Write */
Sujith2660b812009-02-09 13:27:26 +0530337 RF_BANK_SETUP(ah->analogBank3Data, &ah->iniBank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700338 modesIndex);
339 {
340 int i;
Sujith2660b812009-02-09 13:27:26 +0530341 for (i = 0; i < ah->iniBank6TPC.ia_rows; i++) {
342 ah->analogBank6Data[i] =
343 INI_RA(&ah->iniBank6TPC, i, modesIndex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700344 }
345 }
346
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400347 /* Only the 5 or 2 GHz OB/DB need to be set for a mode */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700348 if (eepMinorRev >= 2) {
349 if (IS_CHAN_2GHZ(chan)) {
Sujithf74df6f2009-02-09 13:27:24 +0530350 ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
351 db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2);
Sujith2660b812009-02-09 13:27:26 +0530352 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700353 ob2GHz, 3, 197, 0);
Sujith2660b812009-02-09 13:27:26 +0530354 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700355 db2GHz, 3, 194, 0);
356 } else {
Sujithf74df6f2009-02-09 13:27:24 +0530357 ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5);
358 db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5);
Sujith2660b812009-02-09 13:27:26 +0530359 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700360 ob5GHz, 3, 203, 0);
Sujith2660b812009-02-09 13:27:26 +0530361 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700362 db5GHz, 3, 200, 0);
363 }
364 }
365
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400366 /* Setup Bank 7 Setup */
Sujith2660b812009-02-09 13:27:26 +0530367 RF_BANK_SETUP(ah->analogBank7Data, &ah->iniBank7, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700368
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400369 /* Write Analog registers */
Sujith2660b812009-02-09 13:27:26 +0530370 REG_WRITE_RF_ARRAY(&ah->iniBank0, ah->analogBank0Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700371 regWrites);
Sujith2660b812009-02-09 13:27:26 +0530372 REG_WRITE_RF_ARRAY(&ah->iniBank1, ah->analogBank1Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700373 regWrites);
Sujith2660b812009-02-09 13:27:26 +0530374 REG_WRITE_RF_ARRAY(&ah->iniBank2, ah->analogBank2Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700375 regWrites);
Sujith2660b812009-02-09 13:27:26 +0530376 REG_WRITE_RF_ARRAY(&ah->iniBank3, ah->analogBank3Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377 regWrites);
Sujith2660b812009-02-09 13:27:26 +0530378 REG_WRITE_RF_ARRAY(&ah->iniBank6TPC, ah->analogBank6Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700379 regWrites);
Sujith2660b812009-02-09 13:27:26 +0530380 REG_WRITE_RF_ARRAY(&ah->iniBank7, ah->analogBank7Data,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700381 regWrites);
382
383 return true;
384}
385
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400386/**
Luis R. Rodriguezdc51dd52009-10-19 02:33:39 -0400387 * ath9k_hw_rf_free_ext_banks - Free memory for analog bank scratch buffers
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400388 * @ah: atheros hardware struture
Luis R. Rodriguezdc51dd52009-10-19 02:33:39 -0400389 * For the external AR2133/AR5133 radios banks.
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400390 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700391void
Luis R. Rodriguezdc51dd52009-10-19 02:33:39 -0400392ath9k_hw_rf_free_ext_banks(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700393{
Luis R. Rodriguez6b827522009-08-03 12:24:49 -0700394#define ATH_FREE_BANK(bank) do { \
395 kfree(bank); \
396 bank = NULL; \
397 } while (0);
Luis R. Rodriguez39a21952009-08-03 12:24:48 -0700398
Luis R. Rodriguezdc51dd52009-10-19 02:33:39 -0400399 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
400
Luis R. Rodriguez6b827522009-08-03 12:24:49 -0700401 ATH_FREE_BANK(ah->analogBank0Data);
402 ATH_FREE_BANK(ah->analogBank1Data);
403 ATH_FREE_BANK(ah->analogBank2Data);
404 ATH_FREE_BANK(ah->analogBank3Data);
405 ATH_FREE_BANK(ah->analogBank6Data);
406 ATH_FREE_BANK(ah->analogBank6TPCData);
407 ATH_FREE_BANK(ah->analogBank7Data);
408 ATH_FREE_BANK(ah->addac5416_21);
409 ATH_FREE_BANK(ah->bank6Temp);
Luis R. Rodriguezdc51dd52009-10-19 02:33:39 -0400410
Luis R. Rodriguez6b827522009-08-03 12:24:49 -0700411#undef ATH_FREE_BANK
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700412}
413
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400414/**
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400415 * ath9k_hw_rf_alloc_ext_banks - allocates banks for external radio programming
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400416 * @ah: atheros hardware structure
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400417 *
418 * Only required for older devices with external AR2133/AR5133 radios.
419 */
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400420int ath9k_hw_rf_alloc_ext_banks(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700421{
Luis R. Rodriguez431ba3c2009-10-19 02:33:38 -0400422#define ATH_ALLOC_BANK(bank, size) do { \
423 bank = kzalloc((sizeof(u32) * size), GFP_KERNEL); \
424 if (!bank) { \
425 ath_print(common, ATH_DBG_FATAL, \
426 "Cannot allocate RF banks\n"); \
427 return -ENOMEM; \
428 } \
429 } while (0);
430
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700431 struct ath_common *common = ath9k_hw_common(ah);
432
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400433 BUG_ON(AR_SREV_9280_10_OR_LATER(ah));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700434
Luis R. Rodriguez431ba3c2009-10-19 02:33:38 -0400435 ATH_ALLOC_BANK(ah->analogBank0Data, ah->iniBank0.ia_rows);
436 ATH_ALLOC_BANK(ah->analogBank1Data, ah->iniBank1.ia_rows);
437 ATH_ALLOC_BANK(ah->analogBank2Data, ah->iniBank2.ia_rows);
438 ATH_ALLOC_BANK(ah->analogBank3Data, ah->iniBank3.ia_rows);
439 ATH_ALLOC_BANK(ah->analogBank6Data, ah->iniBank6.ia_rows);
440 ATH_ALLOC_BANK(ah->analogBank6TPCData, ah->iniBank6TPC.ia_rows);
441 ATH_ALLOC_BANK(ah->analogBank7Data, ah->iniBank7.ia_rows);
442 ATH_ALLOC_BANK(ah->addac5416_21,
443 ah->iniAddac.ia_rows * ah->iniAddac.ia_columns);
444 ATH_ALLOC_BANK(ah->bank6Temp, ah->iniBank6.ia_rows);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400446 return 0;
Luis R. Rodriguez431ba3c2009-10-19 02:33:38 -0400447#undef ATH_ALLOC_BANK
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700448}
449
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400450/**
451 * ath9k_hw_decrease_chain_power()
452 *
453 * @ah: atheros hardware structure
454 * @chan:
455 *
456 * Only used on the AR5416 and AR5418 with the external AR2133/AR5133 radios.
457 *
458 * Sets a chain internal RF path to the lowest output power. Any
459 * further writes to bank6 after this setting will override these
460 * changes. Thus this function must be the last function in the
461 * sequence to modify bank 6.
462 *
463 * This function must be called after ar5416SetRfRegs() which is
464 * called from ath9k_hw_process_ini() due to swizzling of bank 6.
465 * Depends on ah->analogBank6Data being initialized by
466 * ath9k_hw_set_rf_regs()
467 *
468 * Additional additive reduction in power -
469 * change chain's switch table so chain's tx state is actually the rx
470 * state value. May produce different results in 2GHz/5GHz as well as
471 * board to board but in general should be a reduction.
472 *
473 * Activated by #ifdef ALTER_SWITCH. Not tried yet. If so, must be
474 * called after ah->eep_ops->set_board_values() due to RMW of
475 * PHY_SWITCH_CHAIN_0.
476 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700477void
Sujithcbe61d82009-02-09 13:27:12 +0530478ath9k_hw_decrease_chain_power(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700479{
480 int i, regWrites = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700481 u32 bank6SelMask;
Sujith2660b812009-02-09 13:27:26 +0530482 u32 *bank6Temp = ah->bank6Temp;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700483
Sujith1cf68732009-08-13 09:34:32 +0530484 switch (ah->config.diversity_control) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700485 case ATH9K_ANT_FIXED_A:
486 bank6SelMask =
Sujith1cf68732009-08-13 09:34:32 +0530487 (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400488 REDUCE_CHAIN_0 : /* swapped, reduce chain 0 */
489 REDUCE_CHAIN_1; /* normal, select chain 1/2 to reduce */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700490 break;
491 case ATH9K_ANT_FIXED_B:
492 bank6SelMask =
Sujith1cf68732009-08-13 09:34:32 +0530493 (ah->config.antenna_switch_swap & ANTSWAP_AB) ?
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400494 REDUCE_CHAIN_1 : /* swapped, reduce chain 1/2 */
495 REDUCE_CHAIN_0; /* normal, select chain 0 to reduce */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700496 break;
497 case ATH9K_ANT_VARIABLE:
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400498 return; /* do not change anything */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700499 break;
500 default:
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400501 return; /* do not change anything */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700502 break;
503 }
504
Sujith2660b812009-02-09 13:27:26 +0530505 for (i = 0; i < ah->iniBank6.ia_rows; i++)
506 bank6Temp[i] = ah->analogBank6Data[i];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700507
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400508 /* Write Bank 5 to switch Bank 6 write to selected chain only */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700509 REG_WRITE(ah, AR_PHY_BASE + 0xD8, bank6SelMask);
510
Luis R. Rodriguez131d1d02009-10-19 02:33:35 -0400511 /*
512 * Modify Bank6 selected chain to use lowest amplification.
513 * Modifies the parameters to a value of 1.
514 * Depends on existing bank 6 values to be cached in
515 * ah->analogBank6Data
516 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700517 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 189, 0);
518 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 190, 0);
519 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 191, 0);
520 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 192, 0);
521 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 193, 0);
522 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 222, 0);
523 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 245, 0);
524 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 246, 0);
525 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 247, 0);
526
Sujith2660b812009-02-09 13:27:26 +0530527 REG_WRITE_RF_ARRAY(&ah->iniBank6, bank6Temp, regWrites);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700528
529 REG_WRITE(ah, AR_PHY_BASE + 0xD8, 0x00000053);
530#ifdef ALTER_SWITCH
531 REG_WRITE(ah, PHY_SWITCH_CHAIN_0,
532 (REG_READ(ah, PHY_SWITCH_CHAIN_0) & ~0x38)
533 | ((REG_READ(ah, PHY_SWITCH_CHAIN_0) >> 3) & 0x38));
534#endif
535}