blob: f69c62e36ed88bf493f2940c9c93a069db605612 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 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
17#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070019#include <asm/unaligned.h>
20
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070021#include "hw.h"
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040022#include "hw-ops.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070023#include "rc.h"
Luis R. Rodriguezb622a722010-04-15 17:39:28 -040024#include "ar9003_mac.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070025
Sujithcbe61d82009-02-09 13:27:12 +053026static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040028MODULE_AUTHOR("Atheros Communications");
29MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
30MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
31MODULE_LICENSE("Dual BSD/GPL");
32
33static int __init ath9k_init(void)
34{
35 return 0;
36}
37module_init(ath9k_init);
38
39static void __exit ath9k_exit(void)
40{
41 return;
42}
43module_exit(ath9k_exit);
44
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040045/* Private hardware callbacks */
46
47static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
48{
49 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
50}
51
52static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
53{
54 ath9k_hw_private_ops(ah)->init_mode_regs(ah);
55}
56
Luis R. Rodriguez64773962010-04-15 17:38:17 -040057static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
58 struct ath9k_channel *chan)
59{
60 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
61}
62
Luis R. Rodriguez991312d2010-04-15 17:39:05 -040063static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
64{
65 if (!ath9k_hw_private_ops(ah)->init_mode_gain_regs)
66 return;
67
68 ath9k_hw_private_ops(ah)->init_mode_gain_regs(ah);
69}
70
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -040071static void ath9k_hw_ani_cache_ini_regs(struct ath_hw *ah)
72{
73 /* You will not have this callback if using the old ANI */
74 if (!ath9k_hw_private_ops(ah)->ani_cache_ini_regs)
75 return;
76
77 ath9k_hw_private_ops(ah)->ani_cache_ini_regs(ah);
78}
79
Sujithf1dc5602008-10-29 10:16:30 +053080/********************/
81/* Helper Functions */
82/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070083
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020084static void ath9k_hw_set_clockrate(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +053085{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070086 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020087 struct ath_common *common = ath9k_hw_common(ah);
88 unsigned int clockrate;
Sujithcbe61d82009-02-09 13:27:12 +053089
Sujith2660b812009-02-09 13:27:26 +053090 if (!ah->curchan) /* should really check for CCK instead */
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020091 clockrate = ATH9K_CLOCK_RATE_CCK;
92 else if (conf->channel->band == IEEE80211_BAND_2GHZ)
93 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
94 else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
95 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
Vasanthakumar Thiagarajane5553722010-04-26 15:04:33 -040096 else
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020097 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
98
99 if (conf_is_ht40(conf))
100 clockrate *= 2;
101
Felix Fietkau906c7202011-07-09 11:12:48 +0700102 if (ah->curchan) {
103 if (IS_CHAN_HALF_RATE(ah->curchan))
104 clockrate /= 2;
105 if (IS_CHAN_QUARTER_RATE(ah->curchan))
106 clockrate /= 4;
107 }
108
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200109 common->clockrate = clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530110}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700111
Sujithcbe61d82009-02-09 13:27:12 +0530112static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +0530113{
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200114 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +0530115
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200116 return usecs * common->clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530117}
118
Sujith0caa7b12009-02-16 13:23:20 +0530119bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700120{
121 int i;
122
Sujith0caa7b12009-02-16 13:23:20 +0530123 BUG_ON(timeout < AH_TIME_QUANTUM);
124
125 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700126 if ((REG_READ(ah, reg) & mask) == val)
127 return true;
128
129 udelay(AH_TIME_QUANTUM);
130 }
Sujith04bd46382008-11-28 22:18:05 +0530131
Joe Perches226afe62010-12-02 19:12:37 -0800132 ath_dbg(ath9k_hw_common(ah), ATH_DBG_ANY,
133 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
134 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530135
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700136 return false;
137}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400138EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700139
Felix Fietkaua9b6b252011-03-23 20:57:27 +0100140void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
141 int column, unsigned int *writecnt)
142{
143 int r;
144
145 ENABLE_REGWRITE_BUFFER(ah);
146 for (r = 0; r < array->ia_rows; r++) {
147 REG_WRITE(ah, INI_RA(array, r, 0),
148 INI_RA(array, r, column));
149 DO_DELAY(*writecnt);
150 }
151 REGWRITE_BUFFER_FLUSH(ah);
152}
153
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700154u32 ath9k_hw_reverse_bits(u32 val, u32 n)
155{
156 u32 retval;
157 int i;
158
159 for (i = 0, retval = 0; i < n; i++) {
160 retval = (retval << 1) | (val & 1);
161 val >>= 1;
162 }
163 return retval;
164}
165
Sujithcbe61d82009-02-09 13:27:12 +0530166u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100167 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530168 u32 frameLen, u16 rateix,
169 bool shortPreamble)
170{
171 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530172
173 if (kbps == 0)
174 return 0;
175
Felix Fietkau545750d2009-11-23 22:21:01 +0100176 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530177 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530178 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100179 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530180 phyTime >>= 1;
181 numBits = frameLen << 3;
182 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
183 break;
Sujith46d14a52008-11-18 09:08:13 +0530184 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530185 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530186 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
187 numBits = OFDM_PLCP_BITS + (frameLen << 3);
188 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
189 txTime = OFDM_SIFS_TIME_QUARTER
190 + OFDM_PREAMBLE_TIME_QUARTER
191 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530192 } else if (ah->curchan &&
193 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530194 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
195 numBits = OFDM_PLCP_BITS + (frameLen << 3);
196 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
197 txTime = OFDM_SIFS_TIME_HALF +
198 OFDM_PREAMBLE_TIME_HALF
199 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
200 } else {
201 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
202 numBits = OFDM_PLCP_BITS + (frameLen << 3);
203 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
204 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
205 + (numSymbols * OFDM_SYMBOL_TIME);
206 }
207 break;
208 default:
Joe Perches38002762010-12-02 19:12:36 -0800209 ath_err(ath9k_hw_common(ah),
210 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530211 txTime = 0;
212 break;
213 }
214
215 return txTime;
216}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400217EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530218
Sujithcbe61d82009-02-09 13:27:12 +0530219void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530220 struct ath9k_channel *chan,
221 struct chan_centers *centers)
222{
223 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530224
225 if (!IS_CHAN_HT40(chan)) {
226 centers->ctl_center = centers->ext_center =
227 centers->synth_center = chan->channel;
228 return;
229 }
230
231 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
232 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
233 centers->synth_center =
234 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
235 extoff = 1;
236 } else {
237 centers->synth_center =
238 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
239 extoff = -1;
240 }
241
242 centers->ctl_center =
243 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700244 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530245 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700246 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530247}
248
249/******************/
250/* Chip Revisions */
251/******************/
252
Sujithcbe61d82009-02-09 13:27:12 +0530253static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530254{
255 u32 val;
256
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530257 switch (ah->hw_version.devid) {
258 case AR5416_AR9100_DEVID:
259 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
260 break;
Gabor Juhos37625612011-06-21 11:23:23 +0200261 case AR9300_DEVID_AR9330:
262 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
263 if (ah->get_mac_revision) {
264 ah->hw_version.macRev = ah->get_mac_revision();
265 } else {
266 val = REG_READ(ah, AR_SREV);
267 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
268 }
269 return;
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530270 case AR9300_DEVID_AR9340:
271 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
272 val = REG_READ(ah, AR_SREV);
273 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
274 return;
275 }
276
Sujithf1dc5602008-10-29 10:16:30 +0530277 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
278
279 if (val == 0xFF) {
280 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530281 ah->hw_version.macVersion =
282 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
283 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530284 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530285 } else {
286 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530287 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530288
Sujithd535a422009-02-09 13:27:06 +0530289 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530290
Sujithd535a422009-02-09 13:27:06 +0530291 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530292 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530293 }
294}
295
Sujithf1dc5602008-10-29 10:16:30 +0530296/************************************/
297/* HW Attach, Detach, Init Routines */
298/************************************/
299
Sujithcbe61d82009-02-09 13:27:12 +0530300static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530301{
Felix Fietkau040b74f2010-12-12 00:51:07 +0100302 if (!AR_SREV_5416(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530303 return;
304
305 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
306 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
307 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
308 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
309 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
310 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
311 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
312 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
313 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
314
315 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
316}
317
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400318/* This should work for all families including legacy */
Sujithcbe61d82009-02-09 13:27:12 +0530319static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530320{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700321 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400322 u32 regAddr[2] = { AR_STA_ID0 };
Sujithf1dc5602008-10-29 10:16:30 +0530323 u32 regHold[2];
Joe Perches07b2fa52010-11-20 18:38:53 -0800324 static const u32 patternData[4] = {
325 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
326 };
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400327 int i, j, loop_max;
Sujithf1dc5602008-10-29 10:16:30 +0530328
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400329 if (!AR_SREV_9300_20_OR_LATER(ah)) {
330 loop_max = 2;
331 regAddr[1] = AR_PHY_BASE + (8 << 2);
332 } else
333 loop_max = 1;
334
335 for (i = 0; i < loop_max; i++) {
Sujithf1dc5602008-10-29 10:16:30 +0530336 u32 addr = regAddr[i];
337 u32 wrData, rdData;
338
339 regHold[i] = REG_READ(ah, addr);
340 for (j = 0; j < 0x100; j++) {
341 wrData = (j << 16) | j;
342 REG_WRITE(ah, addr, wrData);
343 rdData = REG_READ(ah, addr);
344 if (rdData != wrData) {
Joe Perches38002762010-12-02 19:12:36 -0800345 ath_err(common,
346 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
347 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530348 return false;
349 }
350 }
351 for (j = 0; j < 4; j++) {
352 wrData = patternData[j];
353 REG_WRITE(ah, addr, wrData);
354 rdData = REG_READ(ah, addr);
355 if (wrData != rdData) {
Joe Perches38002762010-12-02 19:12:36 -0800356 ath_err(common,
357 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
358 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530359 return false;
360 }
361 }
362 REG_WRITE(ah, regAddr[i], regHold[i]);
363 }
364 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530365
Sujithf1dc5602008-10-29 10:16:30 +0530366 return true;
367}
368
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700369static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700370{
371 int i;
372
Sujith2660b812009-02-09 13:27:26 +0530373 ah->config.dma_beacon_response_time = 2;
374 ah->config.sw_beacon_response_time = 10;
375 ah->config.additional_swba_backoff = 0;
376 ah->config.ack_6mb = 0x0;
377 ah->config.cwm_ignore_extcca = 0;
378 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530379 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530380 ah->config.pcie_waen = 0;
381 ah->config.analog_shiftreg = 1;
Luis R. Rodriguez03c72512010-06-12 00:33:46 -0400382 ah->config.enable_ani = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700383
384 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530385 ah->config.spurchans[i][0] = AR_NO_SPUR;
386 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700387 }
388
Luis R. Rodriguez6f481012011-01-20 17:47:39 -0800389 /* PAPRD needs some more work to be enabled */
390 ah->config.paprd_disable = 1;
391
Sujith0ce024c2009-12-14 14:57:00 +0530392 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez6a0ec302010-06-21 18:38:49 -0400393 ah->config.pcieSerDesWrite = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400394
395 /*
396 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
397 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
398 * This means we use it for all AR5416 devices, and the few
399 * minor PCI AR9280 devices out there.
400 *
401 * Serialization is required because these devices do not handle
402 * well the case of two concurrent reads/writes due to the latency
403 * involved. During one read/write another read/write can be issued
404 * on another CPU while the previous read/write may still be working
405 * on our hardware, if we hit this case the hardware poops in a loop.
406 * We prevent this by serializing reads and writes.
407 *
408 * This issue is not present on PCI-Express devices or pre-AR5416
409 * devices (legacy, 802.11abg).
410 */
411 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700412 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700413}
414
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700415static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700416{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700417 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
418
419 regulatory->country_code = CTRY_DEFAULT;
420 regulatory->power_limit = MAX_RATE_POWER;
421 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
422
Sujithd535a422009-02-09 13:27:06 +0530423 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530424 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425
Sujith2660b812009-02-09 13:27:26 +0530426 ah->atim_window = 0;
Felix Fietkau16f24112010-06-12 17:22:32 +0200427 ah->sta_id1_defaults =
428 AR_STA_ID1_CRPT_MIC_ENABLE |
429 AR_STA_ID1_MCAST_KSRCH;
Felix Fietkauf1717602011-03-19 13:55:41 +0100430 if (AR_SREV_9100(ah))
431 ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
Sujith2660b812009-02-09 13:27:26 +0530432 ah->enable_32kHz_clock = DONT_USE_32KHZ;
Felix Fietkau4357c6b2010-12-13 08:40:50 +0100433 ah->slottime = 20;
Sujith2660b812009-02-09 13:27:26 +0530434 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200435 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436}
437
Sujithcbe61d82009-02-09 13:27:12 +0530438static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700439{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700440 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530441 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700442 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530443 u16 eeval;
Joe Perches07b2fa52010-11-20 18:38:53 -0800444 static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445
Sujithf1dc5602008-10-29 10:16:30 +0530446 sum = 0;
447 for (i = 0; i < 3; i++) {
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400448 eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530449 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700450 common->macaddr[2 * i] = eeval >> 8;
451 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700452 }
Sujithd8baa932009-03-30 15:28:25 +0530453 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530454 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700455
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700456 return 0;
457}
458
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700459static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700460{
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530461 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700462 int ecode;
463
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530464 if (common->bus_ops->ath_bus_type != ATH_USB) {
Sujith527d4852010-03-17 14:25:16 +0530465 if (!ath9k_hw_chip_test(ah))
466 return -ENODEV;
467 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700468
Luis R. Rodriguezebd5a142010-04-15 17:39:18 -0400469 if (!AR_SREV_9300_20_OR_LATER(ah)) {
470 ecode = ar9002_hw_rf_claim(ah);
471 if (ecode != 0)
472 return ecode;
473 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700475 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700476 if (ecode != 0)
477 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530478
Joe Perches226afe62010-12-02 19:12:37 -0800479 ath_dbg(ath9k_hw_common(ah), ATH_DBG_CONFIG,
480 "Eeprom VER: %d, REV: %d\n",
481 ah->eep_ops->get_eeprom_ver(ah),
482 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530483
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400484 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
485 if (ecode) {
Joe Perches38002762010-12-02 19:12:36 -0800486 ath_err(ath9k_hw_common(ah),
487 "Failed allocating banks for external radio\n");
Rajkumar Manoharan48a7c3d2010-11-08 20:40:53 +0530488 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400489 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400490 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700491
Vasanthakumar Thiagarajan070c4d52011-04-19 19:29:05 +0530492 if (!AR_SREV_9100(ah) && !AR_SREV_9340(ah)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700493 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700494 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700495 }
Sujithf1dc5602008-10-29 10:16:30 +0530496
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700497 return 0;
498}
499
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400500static void ath9k_hw_attach_ops(struct ath_hw *ah)
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700501{
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400502 if (AR_SREV_9300_20_OR_LATER(ah))
503 ar9003_hw_attach_ops(ah);
504 else
505 ar9002_hw_attach_ops(ah);
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700506}
507
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400508/* Called for all hardware families */
509static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700510{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700511 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700512 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700513
Senthil Balasubramanianac45c122010-12-22 21:14:20 +0530514 ath9k_hw_read_revisions(ah);
515
Senthil Balasubramanian0a8d7cb2010-12-22 19:17:18 +0530516 /*
517 * Read back AR_WA into a permanent copy and set bits 14 and 17.
518 * We need to do this to avoid RMW of this register. We cannot
519 * read the reg when chip is asleep.
520 */
521 ah->WARegVal = REG_READ(ah, AR_WA);
522 ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
523 AR_WA_ASPM_TIMER_BASED_DISABLE);
524
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700525 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Joe Perches38002762010-12-02 19:12:36 -0800526 ath_err(common, "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700527 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700528 }
529
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400530 ath9k_hw_init_defaults(ah);
531 ath9k_hw_init_config(ah);
532
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400533 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400534
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700535 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Joe Perches38002762010-12-02 19:12:36 -0800536 ath_err(common, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700537 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700538 }
539
540 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
541 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
John W. Linville4c85ab12010-07-28 10:06:35 -0400542 ((AR_SREV_9160(ah) || AR_SREV_9280(ah)) &&
543 !ah->is_pciexpress)) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700544 ah->config.serialize_regmode =
545 SER_REG_MODE_ON;
546 } else {
547 ah->config.serialize_regmode =
548 SER_REG_MODE_OFF;
549 }
550 }
551
Joe Perches226afe62010-12-02 19:12:37 -0800552 ath_dbg(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700553 ah->config.serialize_regmode);
554
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500555 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
556 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
557 else
558 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
559
Felix Fietkau6da5a722010-12-12 00:51:12 +0100560 switch (ah->hw_version.macVersion) {
561 case AR_SREV_VERSION_5416_PCI:
562 case AR_SREV_VERSION_5416_PCIE:
563 case AR_SREV_VERSION_9160:
564 case AR_SREV_VERSION_9100:
565 case AR_SREV_VERSION_9280:
566 case AR_SREV_VERSION_9285:
567 case AR_SREV_VERSION_9287:
568 case AR_SREV_VERSION_9271:
569 case AR_SREV_VERSION_9300:
Gabor Juhos2c8e5932011-06-21 11:23:21 +0200570 case AR_SREV_VERSION_9330:
Felix Fietkau6da5a722010-12-12 00:51:12 +0100571 case AR_SREV_VERSION_9485:
Vasanthakumar Thiagarajanbca04682011-04-19 19:29:20 +0530572 case AR_SREV_VERSION_9340:
Felix Fietkau6da5a722010-12-12 00:51:12 +0100573 break;
574 default:
Joe Perches38002762010-12-02 19:12:36 -0800575 ath_err(common,
576 "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
577 ah->hw_version.macVersion, ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700578 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700579 }
580
Gabor Juhos2c8e5932011-06-21 11:23:21 +0200581 if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
582 AR_SREV_9330(ah))
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400583 ah->is_pciexpress = false;
584
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700585 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700586 ath9k_hw_init_cal_settings(ah);
587
588 ah->ani_function = ATH9K_ANI_ALL;
Felix Fietkau7a370812010-09-22 12:34:52 +0200589 if (AR_SREV_9280_20_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700590 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400591 if (!AR_SREV_9300_20_OR_LATER(ah))
592 ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700593
594 ath9k_hw_init_mode_regs(ah);
595
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -0400596
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700597 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530598 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700599 else
600 ath9k_hw_disablepcie(ah);
601
Luis R. Rodriguezd8f492b2010-04-15 17:39:04 -0400602 if (!AR_SREV_9300_20_OR_LATER(ah))
603 ar9002_hw_cck_chan14_spread(ah);
Sujith193cd452009-09-18 15:04:07 +0530604
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700605 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700606 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700607 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700608
609 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100610 r = ath9k_hw_fill_cap_info(ah);
611 if (r)
612 return r;
613
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700614 r = ath9k_hw_init_macaddr(ah);
615 if (r) {
Joe Perches38002762010-12-02 19:12:36 -0800616 ath_err(common, "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700617 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700618 }
619
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400620 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530621 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700622 else
Sujith2660b812009-02-09 13:27:26 +0530623 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700624
Gabor Juhos88e641d2011-06-21 11:23:30 +0200625 if (AR_SREV_9330(ah))
626 ah->bb_watchdog_timeout_ms = 85;
627 else
628 ah->bb_watchdog_timeout_ms = 25;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700629
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400630 common->state = ATH_HW_INITIALIZED;
631
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700632 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700633}
634
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400635int ath9k_hw_init(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530636{
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400637 int ret;
638 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530639
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400640 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
641 switch (ah->hw_version.devid) {
642 case AR5416_DEVID_PCI:
643 case AR5416_DEVID_PCIE:
644 case AR5416_AR9100_DEVID:
645 case AR9160_DEVID_PCI:
646 case AR9280_DEVID_PCI:
647 case AR9280_DEVID_PCIE:
648 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400649 case AR9287_DEVID_PCI:
650 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400651 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400652 case AR9300_DEVID_PCIE:
Vasanthakumar Thiagarajan3050c912010-12-06 04:27:36 -0800653 case AR9300_DEVID_AR9485_PCIE:
Gabor Juhos999a7a82011-06-21 11:23:52 +0200654 case AR9300_DEVID_AR9330:
Vasanthakumar Thiagarajanbca04682011-04-19 19:29:20 +0530655 case AR9300_DEVID_AR9340:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400656 break;
657 default:
658 if (common->bus_ops->ath_bus_type == ATH_USB)
659 break;
Joe Perches38002762010-12-02 19:12:36 -0800660 ath_err(common, "Hardware device ID 0x%04x not supported\n",
661 ah->hw_version.devid);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400662 return -EOPNOTSUPP;
663 }
Sujithf1dc5602008-10-29 10:16:30 +0530664
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400665 ret = __ath9k_hw_init(ah);
666 if (ret) {
Joe Perches38002762010-12-02 19:12:36 -0800667 ath_err(common,
668 "Unable to initialize hardware; initialization status: %d\n",
669 ret);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400670 return ret;
671 }
Sujithf1dc5602008-10-29 10:16:30 +0530672
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400673 return 0;
Sujithf1dc5602008-10-29 10:16:30 +0530674}
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400675EXPORT_SYMBOL(ath9k_hw_init);
Sujithf1dc5602008-10-29 10:16:30 +0530676
Sujithcbe61d82009-02-09 13:27:12 +0530677static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530678{
Sujith7d0d0df2010-04-16 11:53:57 +0530679 ENABLE_REGWRITE_BUFFER(ah);
680
Sujithf1dc5602008-10-29 10:16:30 +0530681 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
682 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
683
684 REG_WRITE(ah, AR_QOS_NO_ACK,
685 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
686 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
687 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
688
689 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
690 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
691 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
692 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
693 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
Sujith7d0d0df2010-04-16 11:53:57 +0530694
695 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530696}
697
Senthil Balasubramanianb84628e2011-04-22 11:32:12 +0530698u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
Vivek Natarajanb1415812011-01-27 14:45:07 +0530699{
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100700 REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
701 udelay(100);
702 REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
703
704 while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0)
Vivek Natarajanb1415812011-01-27 14:45:07 +0530705 udelay(100);
Vivek Natarajanb1415812011-01-27 14:45:07 +0530706
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100707 return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
Vivek Natarajanb1415812011-01-27 14:45:07 +0530708}
709EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
710
Sujithcbe61d82009-02-09 13:27:12 +0530711static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530712 struct ath9k_channel *chan)
713{
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800714 u32 pll;
715
Vivek Natarajan22983c32011-01-27 14:45:09 +0530716 if (AR_SREV_9485(ah)) {
Vivek Natarajan22983c32011-01-27 14:45:09 +0530717
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530718 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
719 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
720 AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
721 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
722 AR_CH0_DPLL2_KD, 0x40);
723 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
724 AR_CH0_DPLL2_KI, 0x4);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530725
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530726 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
727 AR_CH0_BB_DPLL1_REFDIV, 0x5);
728 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
729 AR_CH0_BB_DPLL1_NINI, 0x58);
730 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
731 AR_CH0_BB_DPLL1_NFRAC, 0x0);
732
733 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
734 AR_CH0_BB_DPLL2_OUTDIV, 0x1);
735 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
736 AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
737 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
738 AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
739
740 /* program BB PLL phase_shift to 0x6 */
741 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
742 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
743
744 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
745 AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
Vivek Natarajan75e03512011-03-10 11:05:42 +0530746 udelay(1000);
Gabor Juhosa5415d62011-06-21 11:23:29 +0200747 } else if (AR_SREV_9330(ah)) {
748 u32 ddr_dpll2, pll_control2, kd;
749
750 if (ah->is_clk_25mhz) {
751 ddr_dpll2 = 0x18e82f01;
752 pll_control2 = 0xe04a3d;
753 kd = 0x1d;
754 } else {
755 ddr_dpll2 = 0x19e82f01;
756 pll_control2 = 0x886666;
757 kd = 0x3d;
758 }
759
760 /* program DDR PLL ki and kd value */
761 REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
762
763 /* program DDR PLL phase_shift */
764 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
765 AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
766
767 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
768 udelay(1000);
769
770 /* program refdiv, nint, frac to RTC register */
771 REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
772
773 /* program BB PLL kd and ki value */
774 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
775 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
776
777 /* program BB PLL phase_shift */
778 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
779 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530780 } else if (AR_SREV_9340(ah)) {
781 u32 regval, pll2_divint, pll2_divfrac, refdiv;
782
783 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
784 udelay(1000);
785
786 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
787 udelay(100);
788
789 if (ah->is_clk_25mhz) {
790 pll2_divint = 0x54;
791 pll2_divfrac = 0x1eb85;
792 refdiv = 3;
793 } else {
794 pll2_divint = 88;
795 pll2_divfrac = 0;
796 refdiv = 5;
797 }
798
799 regval = REG_READ(ah, AR_PHY_PLL_MODE);
800 regval |= (0x1 << 16);
801 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
802 udelay(100);
803
804 REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
805 (pll2_divint << 18) | pll2_divfrac);
806 udelay(100);
807
808 regval = REG_READ(ah, AR_PHY_PLL_MODE);
809 regval = (regval & 0x80071fff) | (0x1 << 30) | (0x1 << 13) |
810 (0x4 << 26) | (0x18 << 19);
811 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
812 REG_WRITE(ah, AR_PHY_PLL_MODE,
813 REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
814 udelay(1000);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530815 }
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800816
817 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +0530818
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100819 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530820
Gabor Juhosa5415d62011-06-21 11:23:29 +0200821 if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah))
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530822 udelay(1000);
823
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400824 /* Switch the core clock for ar9271 to 117Mhz */
825 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +0530826 udelay(500);
827 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400828 }
829
Sujithf1dc5602008-10-29 10:16:30 +0530830 udelay(RTC_PLL_SETTLE_DELAY);
831
832 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530833
834 if (AR_SREV_9340(ah)) {
835 if (ah->is_clk_25mhz) {
836 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
837 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
838 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
839 } else {
840 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
841 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
842 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
843 }
844 udelay(100);
845 }
Sujithf1dc5602008-10-29 10:16:30 +0530846}
847
Sujithcbe61d82009-02-09 13:27:12 +0530848static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -0800849 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +0530850{
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530851 u32 sync_default = AR_INTR_SYNC_DEFAULT;
Pavel Roskin152d5302010-03-31 18:05:37 -0400852 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +0530853 AR_IMR_TXURN |
854 AR_IMR_RXERR |
855 AR_IMR_RXORN |
856 AR_IMR_BCNMISC;
857
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530858 if (AR_SREV_9340(ah))
859 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
860
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400861 if (AR_SREV_9300_20_OR_LATER(ah)) {
862 imr_reg |= AR_IMR_RXOK_HP;
863 if (ah->config.rx_intr_mitigation)
864 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
865 else
866 imr_reg |= AR_IMR_RXOK_LP;
Sujithf1dc5602008-10-29 10:16:30 +0530867
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400868 } else {
869 if (ah->config.rx_intr_mitigation)
870 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
871 else
872 imr_reg |= AR_IMR_RXOK;
873 }
874
875 if (ah->config.tx_intr_mitigation)
876 imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
877 else
878 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +0530879
Colin McCabed97809d2008-12-01 13:38:55 -0800880 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -0400881 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +0530882
Sujith7d0d0df2010-04-16 11:53:57 +0530883 ENABLE_REGWRITE_BUFFER(ah);
884
Pavel Roskin152d5302010-03-31 18:05:37 -0400885 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -0500886 ah->imrs2_reg |= AR_IMR_S2_GTT;
887 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +0530888
889 if (!AR_SREV_9100(ah)) {
890 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530891 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
Sujithf1dc5602008-10-29 10:16:30 +0530892 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
893 }
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400894
Sujith7d0d0df2010-04-16 11:53:57 +0530895 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530896
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400897 if (AR_SREV_9300_20_OR_LATER(ah)) {
898 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
899 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
900 REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
901 REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
902 }
Sujithf1dc5602008-10-29 10:16:30 +0530903}
904
Felix Fietkau0005baf2010-01-15 02:33:40 +0100905static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530906{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100907 u32 val = ath9k_hw_mac_to_clks(ah, us);
908 val = min(val, (u32) 0xFFFF);
909 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +0530910}
911
Felix Fietkau0005baf2010-01-15 02:33:40 +0100912static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530913{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100914 u32 val = ath9k_hw_mac_to_clks(ah, us);
915 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
916 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
917}
918
919static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
920{
921 u32 val = ath9k_hw_mac_to_clks(ah, us);
922 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
923 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +0530924}
925
Sujithcbe61d82009-02-09 13:27:12 +0530926static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +0530927{
Sujithf1dc5602008-10-29 10:16:30 +0530928 if (tu > 0xFFFF) {
Joe Perches226afe62010-12-02 19:12:37 -0800929 ath_dbg(ath9k_hw_common(ah), ATH_DBG_XMIT,
930 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +0530931 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +0530932 return false;
933 } else {
934 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +0530935 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +0530936 return true;
937 }
938}
939
Felix Fietkau0005baf2010-01-15 02:33:40 +0100940void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530941{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100942 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
943 int acktimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +0100944 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +0100945 int sifstime;
946
Joe Perches226afe62010-12-02 19:12:37 -0800947 ath_dbg(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
948 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +0530949
Sujith2660b812009-02-09 13:27:26 +0530950 if (ah->misc_mode != 0)
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100951 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +0100952
953 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
954 sifstime = 16;
955 else
956 sifstime = 10;
957
Felix Fietkaue239d852010-01-15 02:34:58 +0100958 /* As defined by IEEE 802.11-2007 17.3.8.6 */
959 slottime = ah->slottime + 3 * ah->coverage_class;
960 acktimeout = slottime + sifstime;
Felix Fietkau42c45682010-02-11 18:07:19 +0100961
962 /*
963 * Workaround for early ACK timeouts, add an offset to match the
964 * initval's 64us ack timeout value.
965 * This was initially only meant to work around an issue with delayed
966 * BA frames in some implementations, but it has been found to fix ACK
967 * timeout issues in other cases as well.
968 */
969 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
970 acktimeout += 64 - sifstime - ah->slottime;
971
Felix Fietkaucaabf2b2010-12-13 08:40:51 +0100972 ath9k_hw_setslottime(ah, ah->slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +0100973 ath9k_hw_set_ack_timeout(ah, acktimeout);
974 ath9k_hw_set_cts_timeout(ah, acktimeout);
Sujith2660b812009-02-09 13:27:26 +0530975 if (ah->globaltxtimeout != (u32) -1)
976 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +0530977}
Felix Fietkau0005baf2010-01-15 02:33:40 +0100978EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +0530979
Sujith285f2dd2010-01-08 10:36:07 +0530980void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700981{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400982 struct ath_common *common = ath9k_hw_common(ah);
983
Sujith736b3a22010-03-17 14:25:24 +0530984 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400985 goto free_hw;
986
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700987 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400988
989free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400990 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700991}
Sujith285f2dd2010-01-08 10:36:07 +0530992EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700993
Sujithf1dc5602008-10-29 10:16:30 +0530994/*******/
995/* INI */
996/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700997
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400998u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -0400999{
1000 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1001
1002 if (IS_CHAN_B(chan))
1003 ctl |= CTL_11B;
1004 else if (IS_CHAN_G(chan))
1005 ctl |= CTL_11G;
1006 else
1007 ctl |= CTL_11A;
1008
1009 return ctl;
1010}
1011
Sujithf1dc5602008-10-29 10:16:30 +05301012/****************************************/
1013/* Reset and Channel Switching Routines */
1014/****************************************/
1015
Sujithcbe61d82009-02-09 13:27:12 +05301016static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301017{
Felix Fietkau57b32222010-04-15 17:39:22 -04001018 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301019
Sujith7d0d0df2010-04-16 11:53:57 +05301020 ENABLE_REGWRITE_BUFFER(ah);
1021
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001022 /*
1023 * set AHB_MODE not to do cacheline prefetches
1024 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001025 if (!AR_SREV_9300_20_OR_LATER(ah))
1026 REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301027
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001028 /*
1029 * let mac dma reads be in 128 byte chunks
1030 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001031 REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301032
Sujith7d0d0df2010-04-16 11:53:57 +05301033 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301034
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001035 /*
1036 * Restore TX Trigger Level to its pre-reset value.
1037 * The initial value depends on whether aggregation is enabled, and is
1038 * adjusted whenever underruns are detected.
1039 */
Felix Fietkau57b32222010-04-15 17:39:22 -04001040 if (!AR_SREV_9300_20_OR_LATER(ah))
1041 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301042
Sujith7d0d0df2010-04-16 11:53:57 +05301043 ENABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301044
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001045 /*
1046 * let mac dma writes be in 128 byte chunks
1047 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001048 REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301049
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001050 /*
1051 * Setup receive FIFO threshold to hold off TX activities
1052 */
Sujithf1dc5602008-10-29 10:16:30 +05301053 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1054
Felix Fietkau57b32222010-04-15 17:39:22 -04001055 if (AR_SREV_9300_20_OR_LATER(ah)) {
1056 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
1057 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
1058
1059 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
1060 ah->caps.rx_status_len);
1061 }
1062
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001063 /*
1064 * reduce the number of usable entries in PCU TXBUF to avoid
1065 * wrap around issues.
1066 */
Sujithf1dc5602008-10-29 10:16:30 +05301067 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001068 /* For AR9285 the number of Fifos are reduced to half.
1069 * So set the usable tx buf size also to half to
1070 * avoid data/delimiter underruns
1071 */
Sujithf1dc5602008-10-29 10:16:30 +05301072 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1073 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001074 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301075 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1076 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1077 }
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001078
Sujith7d0d0df2010-04-16 11:53:57 +05301079 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301080
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001081 if (AR_SREV_9300_20_OR_LATER(ah))
1082 ath9k_hw_reset_txstatus_ring(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301083}
1084
Sujithcbe61d82009-02-09 13:27:12 +05301085static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301086{
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001087 u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
1088 u32 set = AR_STA_ID1_KSRCH_MODE;
Sujithf1dc5602008-10-29 10:16:30 +05301089
Sujithf1dc5602008-10-29 10:16:30 +05301090 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001091 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001092 case NL80211_IFTYPE_MESH_POINT:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001093 set |= AR_STA_ID1_ADHOC;
Sujithf1dc5602008-10-29 10:16:30 +05301094 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1095 break;
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001096 case NL80211_IFTYPE_AP:
1097 set |= AR_STA_ID1_STA_AP;
1098 /* fall through */
Colin McCabed97809d2008-12-01 13:38:55 -08001099 case NL80211_IFTYPE_STATION:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001100 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
Sujithf1dc5602008-10-29 10:16:30 +05301101 break;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301102 default:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001103 if (!ah->is_monitoring)
1104 set = 0;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301105 break;
Sujithf1dc5602008-10-29 10:16:30 +05301106 }
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001107 REG_RMW(ah, AR_STA_ID1, set, mask);
Sujithf1dc5602008-10-29 10:16:30 +05301108}
1109
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001110void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1111 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001112{
1113 u32 coef_exp, coef_man;
1114
1115 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1116 if ((coef_scaled >> coef_exp) & 0x1)
1117 break;
1118
1119 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1120
1121 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1122
1123 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1124 *coef_exponent = coef_exp - 16;
1125}
1126
Sujithcbe61d82009-02-09 13:27:12 +05301127static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301128{
1129 u32 rst_flags;
1130 u32 tmpReg;
1131
Sujith70768492009-02-16 13:23:12 +05301132 if (AR_SREV_9100(ah)) {
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001133 REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
1134 AR_RTC_DERIVED_CLK_PERIOD, 1);
Sujith70768492009-02-16 13:23:12 +05301135 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1136 }
1137
Sujith7d0d0df2010-04-16 11:53:57 +05301138 ENABLE_REGWRITE_BUFFER(ah);
1139
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001140 if (AR_SREV_9300_20_OR_LATER(ah)) {
1141 REG_WRITE(ah, AR_WA, ah->WARegVal);
1142 udelay(10);
1143 }
1144
Sujithf1dc5602008-10-29 10:16:30 +05301145 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1146 AR_RTC_FORCE_WAKE_ON_INT);
1147
1148 if (AR_SREV_9100(ah)) {
1149 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1150 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1151 } else {
1152 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1153 if (tmpReg &
1154 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1155 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001156 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301157 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001158
1159 val = AR_RC_HOSTIF;
1160 if (!AR_SREV_9300_20_OR_LATER(ah))
1161 val |= AR_RC_AHB;
1162 REG_WRITE(ah, AR_RC, val);
1163
1164 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301165 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301166
1167 rst_flags = AR_RTC_RC_MAC_WARM;
1168 if (type == ATH9K_RESET_COLD)
1169 rst_flags |= AR_RTC_RC_MAC_COLD;
1170 }
1171
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001172 if (AR_SREV_9330(ah)) {
1173 int npend = 0;
1174 int i;
1175
1176 /* AR9330 WAR:
1177 * call external reset function to reset WMAC if:
1178 * - doing a cold reset
1179 * - we have pending frames in the TX queues
1180 */
1181
1182 for (i = 0; i < AR_NUM_QCU; i++) {
1183 npend = ath9k_hw_numtxpending(ah, i);
1184 if (npend)
1185 break;
1186 }
1187
1188 if (ah->external_reset &&
1189 (npend || type == ATH9K_RESET_COLD)) {
1190 int reset_err = 0;
1191
1192 ath_dbg(ath9k_hw_common(ah), ATH_DBG_RESET,
1193 "reset MAC via external reset\n");
1194
1195 reset_err = ah->external_reset();
1196 if (reset_err) {
1197 ath_err(ath9k_hw_common(ah),
1198 "External reset failed, err=%d\n",
1199 reset_err);
1200 return false;
1201 }
1202
1203 REG_WRITE(ah, AR_RTC_RESET, 1);
1204 }
1205 }
1206
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001207 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujith7d0d0df2010-04-16 11:53:57 +05301208
1209 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301210
Sujithf1dc5602008-10-29 10:16:30 +05301211 udelay(50);
1212
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001213 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301214 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Joe Perches226afe62010-12-02 19:12:37 -08001215 ath_dbg(ath9k_hw_common(ah), ATH_DBG_RESET,
1216 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301217 return false;
1218 }
1219
1220 if (!AR_SREV_9100(ah))
1221 REG_WRITE(ah, AR_RC, 0);
1222
Sujithf1dc5602008-10-29 10:16:30 +05301223 if (AR_SREV_9100(ah))
1224 udelay(50);
1225
1226 return true;
1227}
1228
Sujithcbe61d82009-02-09 13:27:12 +05301229static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301230{
Sujith7d0d0df2010-04-16 11:53:57 +05301231 ENABLE_REGWRITE_BUFFER(ah);
1232
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001233 if (AR_SREV_9300_20_OR_LATER(ah)) {
1234 REG_WRITE(ah, AR_WA, ah->WARegVal);
1235 udelay(10);
1236 }
1237
Sujithf1dc5602008-10-29 10:16:30 +05301238 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1239 AR_RTC_FORCE_WAKE_ON_INT);
1240
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001241 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301242 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1243
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001244 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301245
Sujith7d0d0df2010-04-16 11:53:57 +05301246 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301247
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001248 if (!AR_SREV_9300_20_OR_LATER(ah))
1249 udelay(2);
1250
1251 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301252 REG_WRITE(ah, AR_RC, 0);
1253
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001254 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301255
1256 if (!ath9k_hw_wait(ah,
1257 AR_RTC_STATUS,
1258 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301259 AR_RTC_STATUS_ON,
1260 AH_WAIT_TIMEOUT)) {
Joe Perches226afe62010-12-02 19:12:37 -08001261 ath_dbg(ath9k_hw_common(ah), ATH_DBG_RESET,
1262 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301263 return false;
1264 }
1265
Sujithf1dc5602008-10-29 10:16:30 +05301266 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1267}
1268
Sujithcbe61d82009-02-09 13:27:12 +05301269static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301270{
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001271 if (AR_SREV_9300_20_OR_LATER(ah)) {
1272 REG_WRITE(ah, AR_WA, ah->WARegVal);
1273 udelay(10);
1274 }
1275
Sujithf1dc5602008-10-29 10:16:30 +05301276 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1277 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1278
1279 switch (type) {
1280 case ATH9K_RESET_POWER_ON:
1281 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301282 case ATH9K_RESET_WARM:
1283 case ATH9K_RESET_COLD:
1284 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301285 default:
1286 return false;
1287 }
1288}
1289
Sujithcbe61d82009-02-09 13:27:12 +05301290static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301291 struct ath9k_channel *chan)
1292{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301293 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301294 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1295 return false;
1296 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301297 return false;
1298
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001299 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301300 return false;
1301
Sujith2660b812009-02-09 13:27:26 +05301302 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301303 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301304 ath9k_hw_set_rfmode(ah, chan);
1305
1306 return true;
1307}
1308
Sujithcbe61d82009-02-09 13:27:12 +05301309static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001310 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301311{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001312 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001313 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001314 struct ieee80211_channel *channel = chan->chan;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001315 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001316 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301317
1318 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1319 if (ath9k_hw_numtxpending(ah, qnum)) {
Joe Perches226afe62010-12-02 19:12:37 -08001320 ath_dbg(common, ATH_DBG_QUEUE,
1321 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301322 return false;
1323 }
1324 }
1325
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001326 if (!ath9k_hw_rfbus_req(ah)) {
Joe Perches38002762010-12-02 19:12:36 -08001327 ath_err(common, "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301328 return false;
1329 }
1330
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001331 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301332
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001333 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001334 if (r) {
Joe Perches38002762010-12-02 19:12:36 -08001335 ath_err(common, "Failed to set channel\n");
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001336 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301337 }
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001338 ath9k_hw_set_clockrate(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301339
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001340 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001341 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301342 channel->max_antenna_gain * 2,
1343 channel->max_power * 2,
1344 min((u32) MAX_RATE_POWER,
Felix Fietkaude40f312010-10-20 03:08:53 +02001345 (u32) regulatory->power_limit), false);
Sujithf1dc5602008-10-29 10:16:30 +05301346
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001347 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301348
1349 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1350 ath9k_hw_set_delta_slope(ah, chan);
1351
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001352 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301353
Sujithf1dc5602008-10-29 10:16:30 +05301354 return true;
1355}
1356
Felix Fietkau691680b2011-03-19 13:55:38 +01001357static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
1358{
1359 u32 gpio_mask = ah->gpio_mask;
1360 int i;
1361
1362 for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
1363 if (!(gpio_mask & 1))
1364 continue;
1365
1366 ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1367 ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
1368 }
1369}
1370
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001371bool ath9k_hw_check_alive(struct ath_hw *ah)
Johannes Berg3b319aa2009-06-13 14:50:26 +05301372{
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001373 int count = 50;
1374 u32 reg;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301375
Felix Fietkaue17f83e2010-09-22 12:34:53 +02001376 if (AR_SREV_9285_12_OR_LATER(ah))
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001377 return true;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301378
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001379 do {
1380 reg = REG_READ(ah, AR_OBS_BUS_1);
1381
1382 if ((reg & 0x7E7FFFEF) == 0x00702400)
1383 continue;
1384
1385 switch (reg & 0x7E000B00) {
1386 case 0x1E000000:
1387 case 0x52000B00:
1388 case 0x18000B00:
1389 continue;
1390 default:
1391 return true;
1392 }
1393 } while (count-- > 0);
1394
1395 return false;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301396}
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001397EXPORT_SYMBOL(ath9k_hw_check_alive);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301398
Sujithcbe61d82009-02-09 13:27:12 +05301399int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001400 struct ath9k_hw_cal_data *caldata, bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001401{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001402 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001403 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301404 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001405 u32 saveDefAntenna;
1406 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301407 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001408 int i, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001409
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001410 ah->txchainmask = common->tx_chainmask;
1411 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001412
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001413 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001414 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001415
Felix Fietkaud9891c72010-09-29 17:15:27 +02001416 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001417 ath9k_hw_getnf(ah, curchan);
1418
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001419 ah->caldata = caldata;
1420 if (caldata &&
1421 (chan->channel != caldata->channel ||
1422 (chan->channelFlags & ~CHANNEL_CW_INT) !=
1423 (caldata->channelFlags & ~CHANNEL_CW_INT))) {
1424 /* Operating channel changed, reset channel calibration data */
1425 memset(caldata, 0, sizeof(*caldata));
1426 ath9k_init_nfcal_hist_buffer(ah, chan);
1427 }
1428
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001429 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301430 (ah->chip_fullsleep != true) &&
1431 (ah->curchan != NULL) &&
1432 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001433 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301434 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Rajkumar Manoharan58d7e0f2010-09-08 15:57:12 +05301435 (!AR_SREV_9280(ah) || AR_DEVID_7010(ah))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001436
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001437 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301438 ath9k_hw_loadnf(ah, ah->curchan);
Felix Fietkau00c86592010-07-30 21:02:09 +02001439 ath9k_hw_start_nfcal(ah, true);
Rajkumar Manoharanc2ba3342010-09-03 16:00:00 +05301440 if (AR_SREV_9271(ah))
1441 ar9002_hw_load_ani_reg(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001442 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001443 }
1444 }
1445
1446 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1447 if (saveDefAntenna == 0)
1448 saveDefAntenna = 1;
1449
1450 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1451
Sujith46fe7822009-09-17 09:25:25 +05301452 /* For chips on which RTC reset is done, save TSF before it gets cleared */
Felix Fietkauf860d522010-06-30 02:07:48 +02001453 if (AR_SREV_9100(ah) ||
1454 (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)))
Sujith46fe7822009-09-17 09:25:25 +05301455 tsf = ath9k_hw_gettsf64(ah);
1456
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001457 saveLedState = REG_READ(ah, AR_CFG_LED) &
1458 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1459 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1460
1461 ath9k_hw_mark_phy_inactive(ah);
1462
Vasanthakumar Thiagarajan45ef6a02010-12-15 07:30:53 -08001463 ah->paprd_table_write_done = false;
1464
Sujith05020d22010-03-17 14:25:23 +05301465 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001466 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1467 REG_WRITE(ah,
1468 AR9271_RESET_POWER_DOWN_CONTROL,
1469 AR9271_RADIO_RF_RST);
1470 udelay(50);
1471 }
1472
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001473 if (!ath9k_hw_chip_reset(ah, chan)) {
Joe Perches38002762010-12-02 19:12:36 -08001474 ath_err(common, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001475 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001476 }
1477
Sujith05020d22010-03-17 14:25:23 +05301478 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001479 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1480 ah->htc_reset_init = false;
1481 REG_WRITE(ah,
1482 AR9271_RESET_POWER_DOWN_CONTROL,
1483 AR9271_GATE_MAC_CTL);
1484 udelay(50);
1485 }
1486
Sujith46fe7822009-09-17 09:25:25 +05301487 /* Restore TSF */
Felix Fietkauf860d522010-06-30 02:07:48 +02001488 if (tsf)
Sujith46fe7822009-09-17 09:25:25 +05301489 ath9k_hw_settsf64(ah, tsf);
1490
Felix Fietkau7a370812010-09-22 12:34:52 +02001491 if (AR_SREV_9280_20_OR_LATER(ah))
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301492 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001493
Sujithe9141f72010-06-01 15:14:10 +05301494 if (!AR_SREV_9300_20_OR_LATER(ah))
1495 ar9002_hw_enable_async_fifo(ah);
1496
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001497 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001498 if (r)
1499 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001500
Felix Fietkauf860d522010-06-30 02:07:48 +02001501 /*
1502 * Some AR91xx SoC devices frequently fail to accept TSF writes
1503 * right after the chip reset. When that happens, write a new
1504 * value after the initvals have been applied, with an offset
1505 * based on measured time difference
1506 */
1507 if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
1508 tsf += 1500;
1509 ath9k_hw_settsf64(ah, tsf);
1510 }
1511
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001512 /* Setup MFP options for CCMP */
1513 if (AR_SREV_9280_20_OR_LATER(ah)) {
1514 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1515 * frames when constructing CCMP AAD. */
1516 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1517 0xc7ff);
1518 ah->sw_mgmt_crypto = false;
1519 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1520 /* Disable hardware crypto for management frames */
1521 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1522 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1523 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1524 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1525 ah->sw_mgmt_crypto = true;
1526 } else
1527 ah->sw_mgmt_crypto = true;
1528
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001529 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1530 ath9k_hw_set_delta_slope(ah, chan);
1531
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001532 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301533 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001534
Sujith7d0d0df2010-04-16 11:53:57 +05301535 ENABLE_REGWRITE_BUFFER(ah);
1536
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001537 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1538 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001539 | macStaId1
1540 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301541 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301542 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301543 | ah->sta_id1_defaults);
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001544 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001545 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001546 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001547 REG_WRITE(ah, AR_ISR, ~0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001548 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1549
Sujith7d0d0df2010-04-16 11:53:57 +05301550 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301551
Sujith Manoharan00e00032011-01-26 21:59:05 +05301552 ath9k_hw_set_operating_mode(ah, ah->opmode);
1553
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001554 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001555 if (r)
1556 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001557
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001558 ath9k_hw_set_clockrate(ah);
1559
Sujith7d0d0df2010-04-16 11:53:57 +05301560 ENABLE_REGWRITE_BUFFER(ah);
1561
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001562 for (i = 0; i < AR_NUM_DCU; i++)
1563 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1564
Sujith7d0d0df2010-04-16 11:53:57 +05301565 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301566
Sujith2660b812009-02-09 13:27:26 +05301567 ah->intr_txqs = 0;
Felix Fietkauf4c607d2011-03-23 20:57:28 +01001568 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001569 ath9k_hw_resettxqueue(ah, i);
1570
Sujith2660b812009-02-09 13:27:26 +05301571 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001572 ath9k_hw_ani_cache_ini_regs(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001573 ath9k_hw_init_qos(ah);
1574
Sujith2660b812009-02-09 13:27:26 +05301575 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Felix Fietkau55821322010-12-17 00:57:01 +01001576 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301577
Felix Fietkau0005baf2010-01-15 02:33:40 +01001578 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001579
Luis R. Rodriguez6c94fdc2010-04-15 17:39:24 -04001580 if (!AR_SREV_9300_20_OR_LATER(ah)) {
Sujithe9141f72010-06-01 15:14:10 +05301581 ar9002_hw_update_async_fifo(ah);
Luis R. Rodriguez6c94fdc2010-04-15 17:39:24 -04001582 ar9002_hw_enable_wep_aggregation(ah);
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301583 }
1584
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001585 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001586
1587 ath9k_hw_set_dma(ah);
1588
1589 REG_WRITE(ah, AR_OBS, 8);
1590
Sujith0ce024c2009-12-14 14:57:00 +05301591 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001592 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1593 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1594 }
1595
Vasanthakumar Thiagarajan7f62a132010-04-15 17:39:19 -04001596 if (ah->config.tx_intr_mitigation) {
1597 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1598 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1599 }
1600
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001601 ath9k_hw_init_bb(ah, chan);
1602
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001603 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001604 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001605
Sujith7d0d0df2010-04-16 11:53:57 +05301606 ENABLE_REGWRITE_BUFFER(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001607
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001608 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001609 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1610
Sujith7d0d0df2010-04-16 11:53:57 +05301611 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301612
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001613 /*
1614 * For big endian systems turn on swapping for descriptors
1615 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001616 if (AR_SREV_9100(ah)) {
1617 u32 mask;
1618 mask = REG_READ(ah, AR_CFG);
1619 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Joe Perches226afe62010-12-02 19:12:37 -08001620 ath_dbg(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05301621 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001622 } else {
1623 mask =
1624 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1625 REG_WRITE(ah, AR_CFG, mask);
Joe Perches226afe62010-12-02 19:12:37 -08001626 ath_dbg(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05301627 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001628 }
1629 } else {
Sujithcbba8cd2010-06-02 15:53:31 +05301630 if (common->bus_ops->ath_bus_type == ATH_USB) {
1631 /* Configure AR9271 target WLAN */
1632 if (AR_SREV_9271(ah))
1633 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
1634 else
1635 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1636 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001637#ifdef __BIG_ENDIAN
Gabor Juhos4033bda2011-06-21 11:23:35 +02001638 else if (AR_SREV_9330(ah) || AR_SREV_9340(ah))
Vasanthakumar Thiagarajan2be7bfe2011-04-19 19:29:14 +05301639 REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
1640 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001641 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001642#endif
1643 }
1644
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001645 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301646 ath9k_hw_btcoex_enable(ah);
1647
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05301648 if (AR_SREV_9300_20_OR_LATER(ah)) {
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001649 ar9003_hw_bb_watchdog_config(ah);
Vasanthakumar Thiagarajand8903a52010-04-15 17:39:25 -04001650
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05301651 ar9003_hw_disable_phy_restart(ah);
1652 }
1653
Felix Fietkau691680b2011-03-19 13:55:38 +01001654 ath9k_hw_apply_gpio_override(ah);
1655
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001656 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001657}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001658EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001659
Sujithf1dc5602008-10-29 10:16:30 +05301660/******************************/
1661/* Power Management (Chipset) */
1662/******************************/
1663
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001664/*
1665 * Notify Power Mgt is disabled in self-generated frames.
1666 * If requested, force chip to sleep.
1667 */
Sujithcbe61d82009-02-09 13:27:12 +05301668static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301669{
1670 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1671 if (setChip) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001672 /*
1673 * Clear the RTC force wake bit to allow the
1674 * mac to go to sleep.
1675 */
Sujithf1dc5602008-10-29 10:16:30 +05301676 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1677 AR_RTC_FORCE_WAKE_EN);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001678 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301679 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1680
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001681 /* Shutdown chip. Active low */
Sujith14b3af32010-03-17 14:25:18 +05301682 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
Sujith4921be82009-09-18 15:04:27 +05301683 REG_CLR_BIT(ah, (AR_RTC_RESET),
1684 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301685 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001686
1687 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
1688 if (AR_SREV_9300_20_OR_LATER(ah))
1689 REG_WRITE(ah, AR_WA,
1690 ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001691}
1692
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001693/*
1694 * Notify Power Management is enabled in self-generating
1695 * frames. If request, set power mode of chip to
1696 * auto/normal. Duration in units of 128us (1/8 TU).
1697 */
Sujithcbe61d82009-02-09 13:27:12 +05301698static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001699{
Sujithf1dc5602008-10-29 10:16:30 +05301700 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1701 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05301702 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001703
Sujithf1dc5602008-10-29 10:16:30 +05301704 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001705 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05301706 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1707 AR_RTC_FORCE_WAKE_ON_INT);
1708 } else {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001709 /*
1710 * Clear the RTC force wake bit to allow the
1711 * mac to go to sleep.
1712 */
Sujithf1dc5602008-10-29 10:16:30 +05301713 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1714 AR_RTC_FORCE_WAKE_EN);
1715 }
1716 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001717
1718 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
1719 if (AR_SREV_9300_20_OR_LATER(ah))
1720 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Sujithf1dc5602008-10-29 10:16:30 +05301721}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001722
Sujithcbe61d82009-02-09 13:27:12 +05301723static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301724{
1725 u32 val;
1726 int i;
1727
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001728 /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
1729 if (AR_SREV_9300_20_OR_LATER(ah)) {
1730 REG_WRITE(ah, AR_WA, ah->WARegVal);
1731 udelay(10);
1732 }
1733
Sujithf1dc5602008-10-29 10:16:30 +05301734 if (setChip) {
1735 if ((REG_READ(ah, AR_RTC_STATUS) &
1736 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
1737 if (ath9k_hw_set_reset_reg(ah,
1738 ATH9K_RESET_POWER_ON) != true) {
1739 return false;
1740 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04001741 if (!AR_SREV_9300_20_OR_LATER(ah))
1742 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05301743 }
1744 if (AR_SREV_9100(ah))
1745 REG_SET_BIT(ah, AR_RTC_RESET,
1746 AR_RTC_RESET_EN);
1747
1748 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
1749 AR_RTC_FORCE_WAKE_EN);
1750 udelay(50);
1751
1752 for (i = POWER_UP_TIME / 50; i > 0; i--) {
1753 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
1754 if (val == AR_RTC_STATUS_ON)
1755 break;
1756 udelay(50);
1757 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
1758 AR_RTC_FORCE_WAKE_EN);
1759 }
1760 if (i == 0) {
Joe Perches38002762010-12-02 19:12:36 -08001761 ath_err(ath9k_hw_common(ah),
1762 "Failed to wakeup in %uus\n",
1763 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05301764 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001765 }
1766 }
1767
Sujithf1dc5602008-10-29 10:16:30 +05301768 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1769
1770 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001771}
1772
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001773bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05301774{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001775 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05301776 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05301777 static const char *modes[] = {
1778 "AWAKE",
1779 "FULL-SLEEP",
1780 "NETWORK SLEEP",
1781 "UNDEFINED"
1782 };
Sujithf1dc5602008-10-29 10:16:30 +05301783
Gabor Juhoscbdec972009-07-24 17:27:22 +02001784 if (ah->power_mode == mode)
1785 return status;
1786
Joe Perches226afe62010-12-02 19:12:37 -08001787 ath_dbg(common, ATH_DBG_RESET, "%s -> %s\n",
1788 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05301789
1790 switch (mode) {
1791 case ATH9K_PM_AWAKE:
1792 status = ath9k_hw_set_power_awake(ah, setChip);
1793 break;
1794 case ATH9K_PM_FULL_SLEEP:
1795 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05301796 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05301797 break;
1798 case ATH9K_PM_NETWORK_SLEEP:
1799 ath9k_set_power_network_sleep(ah, setChip);
1800 break;
1801 default:
Joe Perches38002762010-12-02 19:12:36 -08001802 ath_err(common, "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05301803 return false;
1804 }
Sujith2660b812009-02-09 13:27:26 +05301805 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05301806
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08001807 /*
1808 * XXX: If this warning never comes up after a while then
1809 * simply keep the ATH_DBG_WARN_ON_ONCE() but make
1810 * ath9k_hw_setpower() return type void.
1811 */
Sujith Manoharan97dcec52010-12-20 08:02:42 +05301812
1813 if (!(ah->ah_flags & AH_UNPLUGGED))
1814 ATH_DBG_WARN_ON_ONCE(!status);
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08001815
Sujithf1dc5602008-10-29 10:16:30 +05301816 return status;
1817}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001818EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05301819
Sujithf1dc5602008-10-29 10:16:30 +05301820/*******************/
1821/* Beacon Handling */
1822/*******************/
1823
Sujithcbe61d82009-02-09 13:27:12 +05301824void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001825{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001826 int flags = 0;
1827
Sujith7d0d0df2010-04-16 11:53:57 +05301828 ENABLE_REGWRITE_BUFFER(ah);
1829
Sujith2660b812009-02-09 13:27:26 +05301830 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001831 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001832 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001833 REG_SET_BIT(ah, AR_TXCFG,
1834 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
Felix Fietkaudd347f22011-03-22 21:54:17 +01001835 REG_WRITE(ah, AR_NEXT_NDP_TIMER, next_beacon +
1836 TU_TO_USEC(ah->atim_window ? ah->atim_window : 1));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001837 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08001838 case NL80211_IFTYPE_AP:
Felix Fietkaudd347f22011-03-22 21:54:17 +01001839 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
1840 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
1841 TU_TO_USEC(ah->config.dma_beacon_response_time));
1842 REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
1843 TU_TO_USEC(ah->config.sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001844 flags |=
1845 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
1846 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001847 default:
Joe Perches226afe62010-12-02 19:12:37 -08001848 ath_dbg(ath9k_hw_common(ah), ATH_DBG_BEACON,
1849 "%s: unsupported opmode: %d\n",
1850 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08001851 return;
1852 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001853 }
1854
Felix Fietkaudd347f22011-03-22 21:54:17 +01001855 REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
1856 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
1857 REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
1858 REG_WRITE(ah, AR_NDP_PERIOD, beacon_period);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001859
Sujith7d0d0df2010-04-16 11:53:57 +05301860 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301861
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001862 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
1863}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001864EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001865
Sujithcbe61d82009-02-09 13:27:12 +05301866void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301867 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001868{
1869 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05301870 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001871 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001872
Sujith7d0d0df2010-04-16 11:53:57 +05301873 ENABLE_REGWRITE_BUFFER(ah);
1874
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001875 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
1876
1877 REG_WRITE(ah, AR_BEACON_PERIOD,
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05301878 TU_TO_USEC(bs->bs_intval));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001879 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05301880 TU_TO_USEC(bs->bs_intval));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001881
Sujith7d0d0df2010-04-16 11:53:57 +05301882 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301883
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001884 REG_RMW_FIELD(ah, AR_RSSI_THR,
1885 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
1886
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05301887 beaconintval = bs->bs_intval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001888
1889 if (bs->bs_sleepduration > beaconintval)
1890 beaconintval = bs->bs_sleepduration;
1891
1892 dtimperiod = bs->bs_dtimperiod;
1893 if (bs->bs_sleepduration > dtimperiod)
1894 dtimperiod = bs->bs_sleepduration;
1895
1896 if (beaconintval == dtimperiod)
1897 nextTbtt = bs->bs_nextdtim;
1898 else
1899 nextTbtt = bs->bs_nexttbtt;
1900
Joe Perches226afe62010-12-02 19:12:37 -08001901 ath_dbg(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
1902 ath_dbg(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
1903 ath_dbg(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
1904 ath_dbg(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001905
Sujith7d0d0df2010-04-16 11:53:57 +05301906 ENABLE_REGWRITE_BUFFER(ah);
1907
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001908 REG_WRITE(ah, AR_NEXT_DTIM,
1909 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
1910 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
1911
1912 REG_WRITE(ah, AR_SLEEP1,
1913 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
1914 | AR_SLEEP1_ASSUME_DTIM);
1915
Sujith60b67f52008-08-07 10:52:38 +05301916 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001917 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
1918 else
1919 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
1920
1921 REG_WRITE(ah, AR_SLEEP2,
1922 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
1923
1924 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
1925 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
1926
Sujith7d0d0df2010-04-16 11:53:57 +05301927 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301928
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001929 REG_SET_BIT(ah, AR_TIMER_MODE,
1930 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
1931 AR_DTIM_TIMER_EN);
1932
Sujith4af9cf42009-02-12 10:06:47 +05301933 /* TSF Out of Range Threshold */
1934 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001935}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001936EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001937
Sujithf1dc5602008-10-29 10:16:30 +05301938/*******************/
1939/* HW Capabilities */
1940/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001941
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01001942int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001943{
Sujith2660b812009-02-09 13:27:26 +05301944 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001945 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001946 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001947 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001948
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +05301949 u16 eeval;
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08001950 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001951
Sujithf74df6f2009-02-09 13:27:24 +05301952 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001953 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05301954
Sujithf74df6f2009-02-09 13:27:24 +05301955 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Felix Fietkaue17f83e2010-09-22 12:34:53 +02001956 if (AR_SREV_9285_12_OR_LATER(ah))
Sujithfec0de12009-02-12 10:06:43 +05301957 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001958 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05301959
Sujith2660b812009-02-09 13:27:26 +05301960 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05301961 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001962 if (regulatory->current_rd == 0x64 ||
1963 regulatory->current_rd == 0x65)
1964 regulatory->current_rd += 5;
1965 else if (regulatory->current_rd == 0x41)
1966 regulatory->current_rd = 0x43;
Joe Perches226afe62010-12-02 19:12:37 -08001967 ath_dbg(common, ATH_DBG_REGULATORY,
1968 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001969 }
Sujithdc2222a2008-08-14 13:26:55 +05301970
Sujithf74df6f2009-02-09 13:27:24 +05301971 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01001972 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
Joe Perches38002762010-12-02 19:12:36 -08001973 ath_err(common,
1974 "no band has been marked as supported in EEPROM\n");
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01001975 return -EINVAL;
1976 }
1977
Felix Fietkaud4659912010-10-14 16:02:39 +02001978 if (eeval & AR5416_OPFLAGS_11A)
1979 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001980
Felix Fietkaud4659912010-10-14 16:02:39 +02001981 if (eeval & AR5416_OPFLAGS_11G)
1982 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
Sujithf1dc5602008-10-29 10:16:30 +05301983
Sujithf74df6f2009-02-09 13:27:24 +05301984 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001985 /*
1986 * For AR9271 we will temporarilly uses the rx chainmax as read from
1987 * the EEPROM.
1988 */
Sujith8147f5d2009-02-20 15:13:23 +05301989 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001990 !(eeval & AR5416_OPFLAGS_11A) &&
1991 !(AR_SREV_9271(ah)))
1992 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05301993 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
Felix Fietkau598cdd52011-03-19 13:55:42 +01001994 else if (AR_SREV_9100(ah))
1995 pCap->rx_chainmask = 0x7;
Sujith8147f5d2009-02-20 15:13:23 +05301996 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001997 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05301998 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301999
Felix Fietkau7a370812010-09-22 12:34:52 +02002000 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302001
Felix Fietkau02d2ebb2010-11-22 15:39:39 +01002002 /* enable key search for every frame in an aggregate */
2003 if (AR_SREV_9300_20_OR_LATER(ah))
2004 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
2005
Bruno Randolfce2220d2010-09-17 11:36:25 +09002006 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
2007
Felix Fietkau0db156e2011-03-23 20:57:29 +01002008 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
Sujithf1dc5602008-10-29 10:16:30 +05302009 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2010 else
2011 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2012
Sujith5b5fa352010-03-17 14:25:15 +05302013 if (AR_SREV_9271(ah))
2014 pCap->num_gpio_pins = AR9271_NUM_GPIO;
Sujith88c1f4f2010-06-30 14:46:31 +05302015 else if (AR_DEVID_7010(ah))
2016 pCap->num_gpio_pins = AR7010_NUM_GPIO;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002017 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302018 pCap->num_gpio_pins = AR9285_NUM_GPIO;
Felix Fietkau7a370812010-09-22 12:34:52 +02002019 else if (AR_SREV_9280_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302020 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2021 else
2022 pCap->num_gpio_pins = AR_NUM_GPIO;
2023
Sujithf1dc5602008-10-29 10:16:30 +05302024 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2025 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2026 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2027 } else {
2028 pCap->rts_aggr_limit = (8 * 1024);
2029 }
2030
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302031#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302032 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2033 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2034 ah->rfkill_gpio =
2035 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2036 ah->rfkill_polarity =
2037 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302038
2039 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2040 }
2041#endif
Vasanthakumar Thiagarajand5d11542010-05-17 18:57:56 -07002042 if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302043 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2044 else
2045 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302046
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302047 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302048 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2049 else
2050 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2051
Vivek Natarajana6ef5302011-04-26 10:39:53 +05302052 if (common->btcoex_enabled) {
2053 if (AR_SREV_9300_20_OR_LATER(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002054 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
Vivek Natarajana6ef5302011-04-26 10:39:53 +05302055 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO_9300;
2056 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO_9300;
2057 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO_9300;
2058 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
2059 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO_9280;
2060 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO_9280;
2061
2062 if (AR_SREV_9285(ah)) {
2063 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2064 btcoex_hw->btpriority_gpio =
2065 ATH_BTPRIORITY_GPIO_9285;
2066 } else {
2067 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
2068 }
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302069 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302070 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002071 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302072 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002073
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002074 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002075 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
Gabor Juhos0e707a92011-06-21 11:23:31 +02002076 if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah))
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002077 pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
2078
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002079 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2080 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2081 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002082 pCap->tx_desc_len = sizeof(struct ar9003_txc);
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002083 pCap->txs_len = sizeof(struct ar9003_txs);
Luis R. Rodriguez6f481012011-01-20 17:47:39 -08002084 if (!ah->config.paprd_disable &&
2085 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
Felix Fietkau49352502010-06-12 00:33:59 -04002086 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002087 } else {
2088 pCap->tx_desc_len = sizeof(struct ath_desc);
Felix Fietkaua949b172011-07-09 11:12:47 +07002089 if (AR_SREV_9280_20(ah))
Felix Fietkau6b42e8d2010-04-26 15:04:35 -04002090 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002091 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002092
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -04002093 if (AR_SREV_9300_20_OR_LATER(ah))
2094 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2095
Senthil Balasubramanian6ee63f52010-11-10 05:03:16 -08002096 if (AR_SREV_9300_20_OR_LATER(ah))
2097 ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
2098
Felix Fietkaua42acef2010-09-22 12:34:54 +02002099 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
Vasanthakumar Thiagarajan6473d242010-05-13 18:42:38 -07002100 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
2101
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002102 if (AR_SREV_9285(ah))
2103 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
2104 ant_div_ctl1 =
2105 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2106 if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))
2107 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2108 }
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302109 if (AR_SREV_9300_20_OR_LATER(ah)) {
2110 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
2111 pCap->hw_caps |= ATH9K_HW_CAP_APM;
2112 }
2113
2114
Gabor Juhos431da562011-06-21 11:23:41 +02002115 if (AR_SREV_9330(ah) || AR_SREV_9485(ah)) {
Mohammed Shafi Shajakhan21d2c632011-05-13 20:29:31 +05302116 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2117 /*
2118 * enable the diversity-combining algorithm only when
2119 * both enable_lna_div and enable_fast_div are set
2120 * Table for Diversity
2121 * ant_div_alt_lnaconf bit 0-1
2122 * ant_div_main_lnaconf bit 2-3
2123 * ant_div_alt_gaintb bit 4
2124 * ant_div_main_gaintb bit 5
2125 * enable_ant_div_lnadiv bit 6
2126 * enable_ant_fast_div bit 7
2127 */
2128 if ((ant_div_ctl1 >> 0x6) == 0x3)
2129 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2130 }
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002131
Vasanthakumar Thiagarajan8060e162010-12-06 04:27:42 -08002132 if (AR_SREV_9485_10(ah)) {
2133 pCap->pcie_lcr_extsync_en = true;
2134 pCap->pcie_lcr_offset = 0x80;
2135 }
2136
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002137 tx_chainmask = pCap->tx_chainmask;
2138 rx_chainmask = pCap->rx_chainmask;
2139 while (tx_chainmask || rx_chainmask) {
2140 if (tx_chainmask & BIT(0))
2141 pCap->max_txchains++;
2142 if (rx_chainmask & BIT(0))
2143 pCap->max_rxchains++;
2144
2145 tx_chainmask >>= 1;
2146 rx_chainmask >>= 1;
2147 }
2148
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002149 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002150}
2151
Sujithf1dc5602008-10-29 10:16:30 +05302152/****************************/
2153/* GPIO / RFKILL / Antennae */
2154/****************************/
2155
Sujithcbe61d82009-02-09 13:27:12 +05302156static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302157 u32 gpio, u32 type)
2158{
2159 int addr;
2160 u32 gpio_shift, tmp;
2161
2162 if (gpio > 11)
2163 addr = AR_GPIO_OUTPUT_MUX3;
2164 else if (gpio > 5)
2165 addr = AR_GPIO_OUTPUT_MUX2;
2166 else
2167 addr = AR_GPIO_OUTPUT_MUX1;
2168
2169 gpio_shift = (gpio % 6) * 5;
2170
2171 if (AR_SREV_9280_20_OR_LATER(ah)
2172 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2173 REG_RMW(ah, addr, (type << gpio_shift),
2174 (0x1f << gpio_shift));
2175 } else {
2176 tmp = REG_READ(ah, addr);
2177 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2178 tmp &= ~(0x1f << gpio_shift);
2179 tmp |= (type << gpio_shift);
2180 REG_WRITE(ah, addr, tmp);
2181 }
2182}
2183
Sujithcbe61d82009-02-09 13:27:12 +05302184void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302185{
2186 u32 gpio_shift;
2187
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002188 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302189
Sujith88c1f4f2010-06-30 14:46:31 +05302190 if (AR_DEVID_7010(ah)) {
2191 gpio_shift = gpio;
2192 REG_RMW(ah, AR7010_GPIO_OE,
2193 (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
2194 (AR7010_GPIO_OE_MASK << gpio_shift));
2195 return;
2196 }
Sujithf1dc5602008-10-29 10:16:30 +05302197
Sujith88c1f4f2010-06-30 14:46:31 +05302198 gpio_shift = gpio << 1;
Sujithf1dc5602008-10-29 10:16:30 +05302199 REG_RMW(ah,
2200 AR_GPIO_OE_OUT,
2201 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2202 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2203}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002204EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302205
Sujithcbe61d82009-02-09 13:27:12 +05302206u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302207{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302208#define MS_REG_READ(x, y) \
2209 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2210
Sujith2660b812009-02-09 13:27:26 +05302211 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05302212 return 0xffffffff;
2213
Sujith88c1f4f2010-06-30 14:46:31 +05302214 if (AR_DEVID_7010(ah)) {
2215 u32 val;
2216 val = REG_READ(ah, AR7010_GPIO_IN);
2217 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
2218 } else if (AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan93069902010-11-30 23:24:09 -08002219 return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
2220 AR_GPIO_BIT(gpio)) != 0;
Felix Fietkau783dfca2010-04-15 17:38:11 -04002221 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05302222 return MS_REG_READ(AR9271, gpio) != 0;
Felix Fietkaua42acef2010-09-22 12:34:54 +02002223 else if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302224 return MS_REG_READ(AR9287, gpio) != 0;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002225 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302226 return MS_REG_READ(AR9285, gpio) != 0;
Felix Fietkau7a370812010-09-22 12:34:52 +02002227 else if (AR_SREV_9280_20_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302228 return MS_REG_READ(AR928X, gpio) != 0;
2229 else
2230 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05302231}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002232EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05302233
Sujithcbe61d82009-02-09 13:27:12 +05302234void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05302235 u32 ah_signal_type)
2236{
2237 u32 gpio_shift;
2238
Sujith88c1f4f2010-06-30 14:46:31 +05302239 if (AR_DEVID_7010(ah)) {
2240 gpio_shift = gpio;
2241 REG_RMW(ah, AR7010_GPIO_OE,
2242 (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
2243 (AR7010_GPIO_OE_MASK << gpio_shift));
2244 return;
2245 }
2246
Sujithf1dc5602008-10-29 10:16:30 +05302247 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
Sujithf1dc5602008-10-29 10:16:30 +05302248 gpio_shift = 2 * gpio;
Sujithf1dc5602008-10-29 10:16:30 +05302249 REG_RMW(ah,
2250 AR_GPIO_OE_OUT,
2251 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2252 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2253}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002254EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05302255
Sujithcbe61d82009-02-09 13:27:12 +05302256void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05302257{
Sujith88c1f4f2010-06-30 14:46:31 +05302258 if (AR_DEVID_7010(ah)) {
2259 val = val ? 0 : 1;
2260 REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
2261 AR_GPIO_BIT(gpio));
2262 return;
2263 }
2264
Sujith5b5fa352010-03-17 14:25:15 +05302265 if (AR_SREV_9271(ah))
2266 val = ~val;
2267
Sujithf1dc5602008-10-29 10:16:30 +05302268 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2269 AR_GPIO_BIT(gpio));
2270}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002271EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05302272
Sujithcbe61d82009-02-09 13:27:12 +05302273u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302274{
2275 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
2276}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002277EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302278
Sujithcbe61d82009-02-09 13:27:12 +05302279void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05302280{
2281 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2282}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002283EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302284
Sujithf1dc5602008-10-29 10:16:30 +05302285/*********************/
2286/* General Operation */
2287/*********************/
2288
Sujithcbe61d82009-02-09 13:27:12 +05302289u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302290{
2291 u32 bits = REG_READ(ah, AR_RX_FILTER);
2292 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2293
2294 if (phybits & AR_PHY_ERR_RADAR)
2295 bits |= ATH9K_RX_FILTER_PHYRADAR;
2296 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2297 bits |= ATH9K_RX_FILTER_PHYERR;
2298
2299 return bits;
2300}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002301EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302302
Sujithcbe61d82009-02-09 13:27:12 +05302303void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05302304{
2305 u32 phybits;
2306
Sujith7d0d0df2010-04-16 11:53:57 +05302307 ENABLE_REGWRITE_BUFFER(ah);
2308
Sujith7ea310b2009-09-03 12:08:43 +05302309 REG_WRITE(ah, AR_RX_FILTER, bits);
2310
Sujithf1dc5602008-10-29 10:16:30 +05302311 phybits = 0;
2312 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2313 phybits |= AR_PHY_ERR_RADAR;
2314 if (bits & ATH9K_RX_FILTER_PHYERR)
2315 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2316 REG_WRITE(ah, AR_PHY_ERR, phybits);
2317
2318 if (phybits)
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002319 REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujithf1dc5602008-10-29 10:16:30 +05302320 else
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002321 REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujith7d0d0df2010-04-16 11:53:57 +05302322
2323 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302324}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002325EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302326
Sujithcbe61d82009-02-09 13:27:12 +05302327bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302328{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302329 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2330 return false;
2331
2332 ath9k_hw_init_pll(ah, NULL);
2333 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302334}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002335EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302336
Sujithcbe61d82009-02-09 13:27:12 +05302337bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302338{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002339 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05302340 return false;
2341
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302342 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2343 return false;
2344
2345 ath9k_hw_init_pll(ah, NULL);
2346 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302347}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002348EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302349
Felix Fietkaude40f312010-10-20 03:08:53 +02002350void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
Sujithf1dc5602008-10-29 10:16:30 +05302351{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002352 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05302353 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002354 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05302355
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002356 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05302357
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002358 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002359 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002360 channel->max_antenna_gain * 2,
2361 channel->max_power * 2,
2362 min((u32) MAX_RATE_POWER,
Felix Fietkaude40f312010-10-20 03:08:53 +02002363 (u32) regulatory->power_limit), test);
Sujithf1dc5602008-10-29 10:16:30 +05302364}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002365EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05302366
Sujithcbe61d82009-02-09 13:27:12 +05302367void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302368{
Sujith2660b812009-02-09 13:27:26 +05302369 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05302370}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002371EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05302372
Sujithcbe61d82009-02-09 13:27:12 +05302373void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05302374{
2375 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2376 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2377}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002378EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302379
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002380void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302381{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002382 struct ath_common *common = ath9k_hw_common(ah);
2383
2384 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2385 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2386 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05302387}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002388EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05302389
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002390#define ATH9K_MAX_TSF_READ 10
2391
Sujithcbe61d82009-02-09 13:27:12 +05302392u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302393{
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002394 u32 tsf_lower, tsf_upper1, tsf_upper2;
2395 int i;
Sujithf1dc5602008-10-29 10:16:30 +05302396
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002397 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2398 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2399 tsf_lower = REG_READ(ah, AR_TSF_L32);
2400 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2401 if (tsf_upper2 == tsf_upper1)
2402 break;
2403 tsf_upper1 = tsf_upper2;
2404 }
Sujithf1dc5602008-10-29 10:16:30 +05302405
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002406 WARN_ON( i == ATH9K_MAX_TSF_READ );
2407
2408 return (((u64)tsf_upper1 << 32) | tsf_lower);
Sujithf1dc5602008-10-29 10:16:30 +05302409}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002410EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05302411
Sujithcbe61d82009-02-09 13:27:12 +05302412void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002413{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002414 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01002415 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002416}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002417EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002418
Sujithcbe61d82009-02-09 13:27:12 +05302419void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302420{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002421 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2422 AH_TSF_WRITE_TIMEOUT))
Joe Perches226afe62010-12-02 19:12:37 -08002423 ath_dbg(ath9k_hw_common(ah), ATH_DBG_RESET,
2424 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002425
Sujithf1dc5602008-10-29 10:16:30 +05302426 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002427}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002428EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002429
Sujith54e4cec2009-08-07 09:45:09 +05302430void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002431{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002432 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302433 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002434 else
Sujith2660b812009-02-09 13:27:26 +05302435 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002436}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002437EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002438
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002439void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002440{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002441 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05302442 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002443
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002444 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05302445 macmode = AR_2040_JOINED_RX_CLEAR;
2446 else
2447 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002448
Sujithf1dc5602008-10-29 10:16:30 +05302449 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002450}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302451
2452/* HW Generic timers configuration */
2453
2454static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2455{
2456 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2457 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2458 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2459 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2460 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2461 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2462 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2463 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2464 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2465 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2466 AR_NDP2_TIMER_MODE, 0x0002},
2467 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2468 AR_NDP2_TIMER_MODE, 0x0004},
2469 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2470 AR_NDP2_TIMER_MODE, 0x0008},
2471 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2472 AR_NDP2_TIMER_MODE, 0x0010},
2473 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2474 AR_NDP2_TIMER_MODE, 0x0020},
2475 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2476 AR_NDP2_TIMER_MODE, 0x0040},
2477 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2478 AR_NDP2_TIMER_MODE, 0x0080}
2479};
2480
2481/* HW generic timer primitives */
2482
2483/* compute and clear index of rightmost 1 */
2484static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
2485{
2486 u32 b;
2487
2488 b = *mask;
2489 b &= (0-b);
2490 *mask &= ~b;
2491 b *= debruijn32;
2492 b >>= 27;
2493
2494 return timer_table->gen_timer_index[b];
2495}
2496
Felix Fietkaudd347f22011-03-22 21:54:17 +01002497u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302498{
2499 return REG_READ(ah, AR_TSF_L32);
2500}
Felix Fietkaudd347f22011-03-22 21:54:17 +01002501EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302502
2503struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2504 void (*trigger)(void *),
2505 void (*overflow)(void *),
2506 void *arg,
2507 u8 timer_index)
2508{
2509 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2510 struct ath_gen_timer *timer;
2511
2512 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
2513
2514 if (timer == NULL) {
Joe Perches38002762010-12-02 19:12:36 -08002515 ath_err(ath9k_hw_common(ah),
2516 "Failed to allocate memory for hw timer[%d]\n",
2517 timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302518 return NULL;
2519 }
2520
2521 /* allocate a hardware generic timer slot */
2522 timer_table->timers[timer_index] = timer;
2523 timer->index = timer_index;
2524 timer->trigger = trigger;
2525 timer->overflow = overflow;
2526 timer->arg = arg;
2527
2528 return timer;
2529}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002530EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302531
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002532void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2533 struct ath_gen_timer *timer,
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05302534 u32 trig_timeout,
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002535 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302536{
2537 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05302538 u32 tsf, timer_next;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302539
2540 BUG_ON(!timer_period);
2541
2542 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
2543
2544 tsf = ath9k_hw_gettsf32(ah);
2545
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05302546 timer_next = tsf + trig_timeout;
2547
Joe Perches226afe62010-12-02 19:12:37 -08002548 ath_dbg(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
2549 "current tsf %x period %x timer_next %x\n",
2550 tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302551
2552 /*
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302553 * Program generic timer registers
2554 */
2555 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
2556 timer_next);
2557 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
2558 timer_period);
2559 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2560 gen_tmr_configuration[timer->index].mode_mask);
2561
2562 /* Enable both trigger and thresh interrupt masks */
2563 REG_SET_BIT(ah, AR_IMR_S5,
2564 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
2565 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302566}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002567EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302568
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002569void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302570{
2571 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2572
2573 if ((timer->index < AR_FIRST_NDP_TIMER) ||
2574 (timer->index >= ATH_MAX_GEN_TIMER)) {
2575 return;
2576 }
2577
2578 /* Clear generic timer enable bits. */
2579 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2580 gen_tmr_configuration[timer->index].mode_mask);
2581
2582 /* Disable both trigger and thresh interrupt masks */
2583 REG_CLR_BIT(ah, AR_IMR_S5,
2584 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
2585 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
2586
2587 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302588}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002589EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302590
2591void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
2592{
2593 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2594
2595 /* free the hardware generic timer slot */
2596 timer_table->timers[timer->index] = NULL;
2597 kfree(timer);
2598}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002599EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302600
2601/*
2602 * Generic Timer Interrupts handling
2603 */
2604void ath_gen_timer_isr(struct ath_hw *ah)
2605{
2606 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2607 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002608 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302609 u32 trigger_mask, thresh_mask, index;
2610
2611 /* get hardware generic timer interrupt status */
2612 trigger_mask = ah->intr_gen_timer_trigger;
2613 thresh_mask = ah->intr_gen_timer_thresh;
2614 trigger_mask &= timer_table->timer_mask.val;
2615 thresh_mask &= timer_table->timer_mask.val;
2616
2617 trigger_mask &= ~thresh_mask;
2618
2619 while (thresh_mask) {
2620 index = rightmost_index(timer_table, &thresh_mask);
2621 timer = timer_table->timers[index];
2622 BUG_ON(!timer);
Joe Perches226afe62010-12-02 19:12:37 -08002623 ath_dbg(common, ATH_DBG_HWTIMER,
2624 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302625 timer->overflow(timer->arg);
2626 }
2627
2628 while (trigger_mask) {
2629 index = rightmost_index(timer_table, &trigger_mask);
2630 timer = timer_table->timers[index];
2631 BUG_ON(!timer);
Joe Perches226afe62010-12-02 19:12:37 -08002632 ath_dbg(common, ATH_DBG_HWTIMER,
2633 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302634 timer->trigger(timer->arg);
2635 }
2636}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002637EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002638
Sujith05020d22010-03-17 14:25:23 +05302639/********/
2640/* HTC */
2641/********/
2642
2643void ath9k_hw_htc_resetinit(struct ath_hw *ah)
2644{
2645 ah->htc_reset_init = true;
2646}
2647EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
2648
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002649static struct {
2650 u32 version;
2651 const char * name;
2652} ath_mac_bb_names[] = {
2653 /* Devices with external radios */
2654 { AR_SREV_VERSION_5416_PCI, "5416" },
2655 { AR_SREV_VERSION_5416_PCIE, "5418" },
2656 { AR_SREV_VERSION_9100, "9100" },
2657 { AR_SREV_VERSION_9160, "9160" },
2658 /* Single-chip solutions */
2659 { AR_SREV_VERSION_9280, "9280" },
2660 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04002661 { AR_SREV_VERSION_9287, "9287" },
2662 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguezec839032010-04-15 17:39:20 -04002663 { AR_SREV_VERSION_9300, "9300" },
Gabor Juhos2c8e5932011-06-21 11:23:21 +02002664 { AR_SREV_VERSION_9330, "9330" },
Senthil Balasubramanian8f06ca22011-04-01 17:16:33 +05302665 { AR_SREV_VERSION_9485, "9485" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002666};
2667
2668/* For devices with external radios */
2669static struct {
2670 u16 version;
2671 const char * name;
2672} ath_rf_names[] = {
2673 { 0, "5133" },
2674 { AR_RAD5133_SREV_MAJOR, "5133" },
2675 { AR_RAD5122_SREV_MAJOR, "5122" },
2676 { AR_RAD2133_SREV_MAJOR, "2133" },
2677 { AR_RAD2122_SREV_MAJOR, "2122" }
2678};
2679
2680/*
2681 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
2682 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002683static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002684{
2685 int i;
2686
2687 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
2688 if (ath_mac_bb_names[i].version == mac_bb_version) {
2689 return ath_mac_bb_names[i].name;
2690 }
2691 }
2692
2693 return "????";
2694}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002695
2696/*
2697 * Return the RF name. "????" is returned if the RF is unknown.
2698 * Used for devices with external radios.
2699 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002700static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002701{
2702 int i;
2703
2704 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
2705 if (ath_rf_names[i].version == rf_version) {
2706 return ath_rf_names[i].name;
2707 }
2708 }
2709
2710 return "????";
2711}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002712
2713void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
2714{
2715 int used;
2716
2717 /* chipsets >= AR9280 are single-chip */
Felix Fietkau7a370812010-09-22 12:34:52 +02002718 if (AR_SREV_9280_20_OR_LATER(ah)) {
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002719 used = snprintf(hw_name, len,
2720 "Atheros AR%s Rev:%x",
2721 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
2722 ah->hw_version.macRev);
2723 }
2724 else {
2725 used = snprintf(hw_name, len,
2726 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
2727 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
2728 ah->hw_version.macRev,
2729 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
2730 AR_RADIO_SREV_MAJOR)),
2731 ah->hw_version.phyRev);
2732 }
2733
2734 hw_name[used] = '\0';
2735}
2736EXPORT_SYMBOL(ath9k_hw_name);