blob: 9871072bbf0172c47cf02164784f95ab1278d49b [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>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040019#include <linux/module.h>
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020#include <asm/unaligned.h>
21
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070022#include "hw.h"
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040023#include "hw-ops.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070024#include "rc.h"
Luis R. Rodriguezb622a722010-04-15 17:39:28 -040025#include "ar9003_mac.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070026
Sujithcbe61d82009-02-09 13:27:12 +053027static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070028
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040029MODULE_AUTHOR("Atheros Communications");
30MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
31MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
32MODULE_LICENSE("Dual BSD/GPL");
33
34static int __init ath9k_init(void)
35{
36 return 0;
37}
38module_init(ath9k_init);
39
40static void __exit ath9k_exit(void)
41{
42 return;
43}
44module_exit(ath9k_exit);
45
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040046/* Private hardware callbacks */
47
48static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
49{
50 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
51}
52
53static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
54{
55 ath9k_hw_private_ops(ah)->init_mode_regs(ah);
56}
57
Luis R. Rodriguez64773962010-04-15 17:38:17 -040058static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
59 struct ath9k_channel *chan)
60{
61 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
62}
63
Luis R. Rodriguez991312d2010-04-15 17:39:05 -040064static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
65{
66 if (!ath9k_hw_private_ops(ah)->init_mode_gain_regs)
67 return;
68
69 ath9k_hw_private_ops(ah)->init_mode_gain_regs(ah);
70}
71
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -040072static void ath9k_hw_ani_cache_ini_regs(struct ath_hw *ah)
73{
74 /* You will not have this callback if using the old ANI */
75 if (!ath9k_hw_private_ops(ah)->ani_cache_ini_regs)
76 return;
77
78 ath9k_hw_private_ops(ah)->ani_cache_ini_regs(ah);
79}
80
Sujithf1dc5602008-10-29 10:16:30 +053081/********************/
82/* Helper Functions */
83/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070084
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020085static void ath9k_hw_set_clockrate(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +053086{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070087 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020088 struct ath_common *common = ath9k_hw_common(ah);
89 unsigned int clockrate;
Sujithcbe61d82009-02-09 13:27:12 +053090
Felix Fietkau087b6ff2011-07-09 11:12:49 +070091 /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
92 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
93 clockrate = 117;
94 else if (!ah->curchan) /* should really check for CCK instead */
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020095 clockrate = ATH9K_CLOCK_RATE_CCK;
96 else if (conf->channel->band == IEEE80211_BAND_2GHZ)
97 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
98 else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
99 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
Vasanthakumar Thiagarajane5553722010-04-26 15:04:33 -0400100 else
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200101 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
102
103 if (conf_is_ht40(conf))
104 clockrate *= 2;
105
Felix Fietkau906c7202011-07-09 11:12:48 +0700106 if (ah->curchan) {
107 if (IS_CHAN_HALF_RATE(ah->curchan))
108 clockrate /= 2;
109 if (IS_CHAN_QUARTER_RATE(ah->curchan))
110 clockrate /= 4;
111 }
112
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200113 common->clockrate = clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530114}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700115
Sujithcbe61d82009-02-09 13:27:12 +0530116static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +0530117{
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200118 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +0530119
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200120 return usecs * common->clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530121}
122
Sujith0caa7b12009-02-16 13:23:20 +0530123bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700124{
125 int i;
126
Sujith0caa7b12009-02-16 13:23:20 +0530127 BUG_ON(timeout < AH_TIME_QUANTUM);
128
129 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700130 if ((REG_READ(ah, reg) & mask) == val)
131 return true;
132
133 udelay(AH_TIME_QUANTUM);
134 }
Sujith04bd4632008-11-28 22:18:05 +0530135
Joe Perches226afe62010-12-02 19:12:37 -0800136 ath_dbg(ath9k_hw_common(ah), ATH_DBG_ANY,
137 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
138 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530139
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700140 return false;
141}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400142EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700143
Felix Fietkaua9b6b252011-03-23 20:57:27 +0100144void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
145 int column, unsigned int *writecnt)
146{
147 int r;
148
149 ENABLE_REGWRITE_BUFFER(ah);
150 for (r = 0; r < array->ia_rows; r++) {
151 REG_WRITE(ah, INI_RA(array, r, 0),
152 INI_RA(array, r, column));
153 DO_DELAY(*writecnt);
154 }
155 REGWRITE_BUFFER_FLUSH(ah);
156}
157
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700158u32 ath9k_hw_reverse_bits(u32 val, u32 n)
159{
160 u32 retval;
161 int i;
162
163 for (i = 0, retval = 0; i < n; i++) {
164 retval = (retval << 1) | (val & 1);
165 val >>= 1;
166 }
167 return retval;
168}
169
Sujithcbe61d82009-02-09 13:27:12 +0530170u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100171 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530172 u32 frameLen, u16 rateix,
173 bool shortPreamble)
174{
175 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530176
177 if (kbps == 0)
178 return 0;
179
Felix Fietkau545750d2009-11-23 22:21:01 +0100180 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530181 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530182 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100183 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530184 phyTime >>= 1;
185 numBits = frameLen << 3;
186 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
187 break;
Sujith46d14a52008-11-18 09:08:13 +0530188 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530189 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530190 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
191 numBits = OFDM_PLCP_BITS + (frameLen << 3);
192 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
193 txTime = OFDM_SIFS_TIME_QUARTER
194 + OFDM_PREAMBLE_TIME_QUARTER
195 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530196 } else if (ah->curchan &&
197 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530198 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
199 numBits = OFDM_PLCP_BITS + (frameLen << 3);
200 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
201 txTime = OFDM_SIFS_TIME_HALF +
202 OFDM_PREAMBLE_TIME_HALF
203 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
204 } else {
205 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
206 numBits = OFDM_PLCP_BITS + (frameLen << 3);
207 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
208 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
209 + (numSymbols * OFDM_SYMBOL_TIME);
210 }
211 break;
212 default:
Joe Perches38002762010-12-02 19:12:36 -0800213 ath_err(ath9k_hw_common(ah),
214 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530215 txTime = 0;
216 break;
217 }
218
219 return txTime;
220}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400221EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530222
Sujithcbe61d82009-02-09 13:27:12 +0530223void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530224 struct ath9k_channel *chan,
225 struct chan_centers *centers)
226{
227 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530228
229 if (!IS_CHAN_HT40(chan)) {
230 centers->ctl_center = centers->ext_center =
231 centers->synth_center = chan->channel;
232 return;
233 }
234
235 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
236 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
237 centers->synth_center =
238 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
239 extoff = 1;
240 } else {
241 centers->synth_center =
242 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
243 extoff = -1;
244 }
245
246 centers->ctl_center =
247 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700248 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530249 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700250 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530251}
252
253/******************/
254/* Chip Revisions */
255/******************/
256
Sujithcbe61d82009-02-09 13:27:12 +0530257static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530258{
259 u32 val;
260
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530261 switch (ah->hw_version.devid) {
262 case AR5416_AR9100_DEVID:
263 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
264 break;
Gabor Juhos37625612011-06-21 11:23:23 +0200265 case AR9300_DEVID_AR9330:
266 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
267 if (ah->get_mac_revision) {
268 ah->hw_version.macRev = ah->get_mac_revision();
269 } else {
270 val = REG_READ(ah, AR_SREV);
271 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
272 }
273 return;
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530274 case AR9300_DEVID_AR9340:
275 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
276 val = REG_READ(ah, AR_SREV);
277 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
278 return;
279 }
280
Sujithf1dc5602008-10-29 10:16:30 +0530281 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
282
283 if (val == 0xFF) {
284 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530285 ah->hw_version.macVersion =
286 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
287 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530288
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530289 if (AR_SREV_9462(ah))
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530290 ah->is_pciexpress = true;
291 else
292 ah->is_pciexpress = (val &
293 AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530294 } else {
295 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530296 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530297
Sujithd535a422009-02-09 13:27:06 +0530298 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530299
Sujithd535a422009-02-09 13:27:06 +0530300 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530301 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530302 }
303}
304
Sujithf1dc5602008-10-29 10:16:30 +0530305/************************************/
306/* HW Attach, Detach, Init Routines */
307/************************************/
308
Sujithcbe61d82009-02-09 13:27:12 +0530309static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530310{
Felix Fietkau040b74f2010-12-12 00:51:07 +0100311 if (!AR_SREV_5416(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530312 return;
313
314 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
315 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
316 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
317 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
318 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
319 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
320 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
321 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
322 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
323
324 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
325}
326
Stanislaw Gruszkad4930082011-07-29 15:59:08 +0200327static void ath9k_hw_aspm_init(struct ath_hw *ah)
328{
329 struct ath_common *common = ath9k_hw_common(ah);
330
331 if (common->bus_ops->aspm_init)
332 common->bus_ops->aspm_init(common);
333}
334
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400335/* This should work for all families including legacy */
Sujithcbe61d82009-02-09 13:27:12 +0530336static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530337{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700338 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400339 u32 regAddr[2] = { AR_STA_ID0 };
Sujithf1dc5602008-10-29 10:16:30 +0530340 u32 regHold[2];
Joe Perches07b2fa52010-11-20 18:38:53 -0800341 static const u32 patternData[4] = {
342 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
343 };
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400344 int i, j, loop_max;
Sujithf1dc5602008-10-29 10:16:30 +0530345
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400346 if (!AR_SREV_9300_20_OR_LATER(ah)) {
347 loop_max = 2;
348 regAddr[1] = AR_PHY_BASE + (8 << 2);
349 } else
350 loop_max = 1;
351
352 for (i = 0; i < loop_max; i++) {
Sujithf1dc5602008-10-29 10:16:30 +0530353 u32 addr = regAddr[i];
354 u32 wrData, rdData;
355
356 regHold[i] = REG_READ(ah, addr);
357 for (j = 0; j < 0x100; j++) {
358 wrData = (j << 16) | j;
359 REG_WRITE(ah, addr, wrData);
360 rdData = REG_READ(ah, addr);
361 if (rdData != wrData) {
Joe Perches38002762010-12-02 19:12:36 -0800362 ath_err(common,
363 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
364 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530365 return false;
366 }
367 }
368 for (j = 0; j < 4; j++) {
369 wrData = patternData[j];
370 REG_WRITE(ah, addr, wrData);
371 rdData = REG_READ(ah, addr);
372 if (wrData != rdData) {
Joe Perches38002762010-12-02 19:12:36 -0800373 ath_err(common,
374 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
375 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530376 return false;
377 }
378 }
379 REG_WRITE(ah, regAddr[i], regHold[i]);
380 }
381 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530382
Sujithf1dc5602008-10-29 10:16:30 +0530383 return true;
384}
385
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700386static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700387{
388 int i;
389
Sujith2660b812009-02-09 13:27:26 +0530390 ah->config.dma_beacon_response_time = 2;
391 ah->config.sw_beacon_response_time = 10;
392 ah->config.additional_swba_backoff = 0;
393 ah->config.ack_6mb = 0x0;
394 ah->config.cwm_ignore_extcca = 0;
Sujith2660b812009-02-09 13:27:26 +0530395 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530396 ah->config.pcie_waen = 0;
397 ah->config.analog_shiftreg = 1;
Luis R. Rodriguez03c72512010-06-12 00:33:46 -0400398 ah->config.enable_ani = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700399
400 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530401 ah->config.spurchans[i][0] = AR_NO_SPUR;
402 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700403 }
404
Luis R. Rodriguez6f481012011-01-20 17:47:39 -0800405 /* PAPRD needs some more work to be enabled */
406 ah->config.paprd_disable = 1;
407
Sujith0ce024c2009-12-14 14:57:00 +0530408 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez6a0ec302010-06-21 18:38:49 -0400409 ah->config.pcieSerDesWrite = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400410
411 /*
412 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
413 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
414 * This means we use it for all AR5416 devices, and the few
415 * minor PCI AR9280 devices out there.
416 *
417 * Serialization is required because these devices do not handle
418 * well the case of two concurrent reads/writes due to the latency
419 * involved. During one read/write another read/write can be issued
420 * on another CPU while the previous read/write may still be working
421 * on our hardware, if we hit this case the hardware poops in a loop.
422 * We prevent this by serializing reads and writes.
423 *
424 * This issue is not present on PCI-Express devices or pre-AR5416
425 * devices (legacy, 802.11abg).
426 */
427 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700428 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700429}
430
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700431static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700432{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700433 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
434
435 regulatory->country_code = CTRY_DEFAULT;
436 regulatory->power_limit = MAX_RATE_POWER;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700437
Sujithd535a422009-02-09 13:27:06 +0530438 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530439 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700440
Sujith2660b812009-02-09 13:27:26 +0530441 ah->atim_window = 0;
Felix Fietkau16f24112010-06-12 17:22:32 +0200442 ah->sta_id1_defaults =
443 AR_STA_ID1_CRPT_MIC_ENABLE |
444 AR_STA_ID1_MCAST_KSRCH;
Felix Fietkauf1717602011-03-19 13:55:41 +0100445 if (AR_SREV_9100(ah))
446 ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
Sujith2660b812009-02-09 13:27:26 +0530447 ah->enable_32kHz_clock = DONT_USE_32KHZ;
Rajkumar Manoharane3f2acc2011-08-27 11:22:59 +0530448 ah->slottime = ATH9K_SLOT_TIME_9;
Sujith2660b812009-02-09 13:27:26 +0530449 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200450 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451}
452
Sujithcbe61d82009-02-09 13:27:12 +0530453static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700454{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700455 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530456 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700457 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530458 u16 eeval;
Joe Perches07b2fa52010-11-20 18:38:53 -0800459 static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700460
Sujithf1dc5602008-10-29 10:16:30 +0530461 sum = 0;
462 for (i = 0; i < 3; i++) {
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400463 eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530464 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700465 common->macaddr[2 * i] = eeval >> 8;
466 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700467 }
Sujithd8baa932009-03-30 15:28:25 +0530468 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530469 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700470
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700471 return 0;
472}
473
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700474static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700475{
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530476 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700477 int ecode;
478
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530479 if (common->bus_ops->ath_bus_type != ATH_USB) {
Sujith527d4852010-03-17 14:25:16 +0530480 if (!ath9k_hw_chip_test(ah))
481 return -ENODEV;
482 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700483
Luis R. Rodriguezebd5a142010-04-15 17:39:18 -0400484 if (!AR_SREV_9300_20_OR_LATER(ah)) {
485 ecode = ar9002_hw_rf_claim(ah);
486 if (ecode != 0)
487 return ecode;
488 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700489
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700490 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700491 if (ecode != 0)
492 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530493
Joe Perches226afe62010-12-02 19:12:37 -0800494 ath_dbg(ath9k_hw_common(ah), ATH_DBG_CONFIG,
495 "Eeprom VER: %d, REV: %d\n",
496 ah->eep_ops->get_eeprom_ver(ah),
497 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530498
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400499 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
500 if (ecode) {
Joe Perches38002762010-12-02 19:12:36 -0800501 ath_err(ath9k_hw_common(ah),
502 "Failed allocating banks for external radio\n");
Rajkumar Manoharan48a7c3d2010-11-08 20:40:53 +0530503 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400504 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400505 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700506
Nikolay Martynov42794252011-12-02 22:39:16 -0500507 if (ah->config.enable_ani) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700508 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700509 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700510 }
Sujithf1dc5602008-10-29 10:16:30 +0530511
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700512 return 0;
513}
514
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400515static void ath9k_hw_attach_ops(struct ath_hw *ah)
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700516{
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400517 if (AR_SREV_9300_20_OR_LATER(ah))
518 ar9003_hw_attach_ops(ah);
519 else
520 ar9002_hw_attach_ops(ah);
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700521}
522
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400523/* Called for all hardware families */
524static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700525{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700526 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700527 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700528
Senthil Balasubramanianac45c122010-12-22 21:14:20 +0530529 ath9k_hw_read_revisions(ah);
530
Senthil Balasubramanian0a8d7cb2010-12-22 19:17:18 +0530531 /*
532 * Read back AR_WA into a permanent copy and set bits 14 and 17.
533 * We need to do this to avoid RMW of this register. We cannot
534 * read the reg when chip is asleep.
535 */
536 ah->WARegVal = REG_READ(ah, AR_WA);
537 ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
538 AR_WA_ASPM_TIMER_BASED_DISABLE);
539
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700540 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Joe Perches38002762010-12-02 19:12:36 -0800541 ath_err(common, "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700542 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700543 }
544
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530545 if (AR_SREV_9462(ah))
Rajkumar Manoharaneec353c2011-10-13 10:49:13 +0530546 ah->WARegVal &= ~AR_WA_D3_L1_DISABLE;
547
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400548 ath9k_hw_init_defaults(ah);
549 ath9k_hw_init_config(ah);
550
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400551 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400552
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700553 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Joe Perches38002762010-12-02 19:12:36 -0800554 ath_err(common, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700555 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700556 }
557
558 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
559 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
John W. Linville4c85ab12010-07-28 10:06:35 -0400560 ((AR_SREV_9160(ah) || AR_SREV_9280(ah)) &&
561 !ah->is_pciexpress)) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700562 ah->config.serialize_regmode =
563 SER_REG_MODE_ON;
564 } else {
565 ah->config.serialize_regmode =
566 SER_REG_MODE_OFF;
567 }
568 }
569
Joe Perches226afe62010-12-02 19:12:37 -0800570 ath_dbg(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700571 ah->config.serialize_regmode);
572
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500573 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
574 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
575 else
576 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
577
Felix Fietkau6da5a722010-12-12 00:51:12 +0100578 switch (ah->hw_version.macVersion) {
579 case AR_SREV_VERSION_5416_PCI:
580 case AR_SREV_VERSION_5416_PCIE:
581 case AR_SREV_VERSION_9160:
582 case AR_SREV_VERSION_9100:
583 case AR_SREV_VERSION_9280:
584 case AR_SREV_VERSION_9285:
585 case AR_SREV_VERSION_9287:
586 case AR_SREV_VERSION_9271:
587 case AR_SREV_VERSION_9300:
Gabor Juhos2c8e5932011-06-21 11:23:21 +0200588 case AR_SREV_VERSION_9330:
Felix Fietkau6da5a722010-12-12 00:51:12 +0100589 case AR_SREV_VERSION_9485:
Vasanthakumar Thiagarajanbca04682011-04-19 19:29:20 +0530590 case AR_SREV_VERSION_9340:
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530591 case AR_SREV_VERSION_9462:
Felix Fietkau6da5a722010-12-12 00:51:12 +0100592 break;
593 default:
Joe Perches38002762010-12-02 19:12:36 -0800594 ath_err(common,
595 "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
596 ah->hw_version.macVersion, ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700597 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700598 }
599
Gabor Juhos2c8e5932011-06-21 11:23:21 +0200600 if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
601 AR_SREV_9330(ah))
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400602 ah->is_pciexpress = false;
603
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700604 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700605 ath9k_hw_init_cal_settings(ah);
606
607 ah->ani_function = ATH9K_ANI_ALL;
Felix Fietkau7a370812010-09-22 12:34:52 +0200608 if (AR_SREV_9280_20_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700609 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400610 if (!AR_SREV_9300_20_OR_LATER(ah))
611 ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700612
Nikolay Martynov42794252011-12-02 22:39:16 -0500613 /* disable ANI for 9100 and 9340 */
614 if (AR_SREV_9100(ah) || AR_SREV_9340(ah))
615 ah->config.enable_ani = false;
616
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700617 ath9k_hw_init_mode_regs(ah);
618
Stanislaw Gruszka69ce6742011-08-05 13:10:34 +0200619 if (!ah->is_pciexpress)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700620 ath9k_hw_disablepcie(ah);
621
Luis R. Rodriguezd8f492b2010-04-15 17:39:04 -0400622 if (!AR_SREV_9300_20_OR_LATER(ah))
623 ar9002_hw_cck_chan14_spread(ah);
Sujith193cd452009-09-18 15:04:07 +0530624
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700625 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700626 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700627 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700628
629 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100630 r = ath9k_hw_fill_cap_info(ah);
631 if (r)
632 return r;
633
Stanislaw Gruszka69ce6742011-08-05 13:10:34 +0200634 if (ah->is_pciexpress)
635 ath9k_hw_aspm_init(ah);
636
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700637 r = ath9k_hw_init_macaddr(ah);
638 if (r) {
Joe Perches38002762010-12-02 19:12:36 -0800639 ath_err(common, "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700640 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700641 }
642
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400643 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530644 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700645 else
Sujith2660b812009-02-09 13:27:26 +0530646 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700647
Gabor Juhos88e641d2011-06-21 11:23:30 +0200648 if (AR_SREV_9330(ah))
649 ah->bb_watchdog_timeout_ms = 85;
650 else
651 ah->bb_watchdog_timeout_ms = 25;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700652
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400653 common->state = ATH_HW_INITIALIZED;
654
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700655 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700656}
657
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400658int ath9k_hw_init(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530659{
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400660 int ret;
661 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530662
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400663 /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
664 switch (ah->hw_version.devid) {
665 case AR5416_DEVID_PCI:
666 case AR5416_DEVID_PCIE:
667 case AR5416_AR9100_DEVID:
668 case AR9160_DEVID_PCI:
669 case AR9280_DEVID_PCI:
670 case AR9280_DEVID_PCIE:
671 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400672 case AR9287_DEVID_PCI:
673 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400674 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400675 case AR9300_DEVID_PCIE:
Vasanthakumar Thiagarajan3050c912010-12-06 04:27:36 -0800676 case AR9300_DEVID_AR9485_PCIE:
Gabor Juhos999a7a82011-06-21 11:23:52 +0200677 case AR9300_DEVID_AR9330:
Vasanthakumar Thiagarajanbca04682011-04-19 19:29:20 +0530678 case AR9300_DEVID_AR9340:
Luis R. Rodriguez5a63ef02011-08-24 15:36:08 -0700679 case AR9300_DEVID_AR9580:
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530680 case AR9300_DEVID_AR9462:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400681 break;
682 default:
683 if (common->bus_ops->ath_bus_type == ATH_USB)
684 break;
Joe Perches38002762010-12-02 19:12:36 -0800685 ath_err(common, "Hardware device ID 0x%04x not supported\n",
686 ah->hw_version.devid);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400687 return -EOPNOTSUPP;
688 }
Sujithf1dc5602008-10-29 10:16:30 +0530689
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400690 ret = __ath9k_hw_init(ah);
691 if (ret) {
Joe Perches38002762010-12-02 19:12:36 -0800692 ath_err(common,
693 "Unable to initialize hardware; initialization status: %d\n",
694 ret);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400695 return ret;
696 }
Sujithf1dc5602008-10-29 10:16:30 +0530697
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400698 return 0;
Sujithf1dc5602008-10-29 10:16:30 +0530699}
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400700EXPORT_SYMBOL(ath9k_hw_init);
Sujithf1dc5602008-10-29 10:16:30 +0530701
Sujithcbe61d82009-02-09 13:27:12 +0530702static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530703{
Sujith7d0d0df2010-04-16 11:53:57 +0530704 ENABLE_REGWRITE_BUFFER(ah);
705
Sujithf1dc5602008-10-29 10:16:30 +0530706 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
707 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
708
709 REG_WRITE(ah, AR_QOS_NO_ACK,
710 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
711 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
712 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
713
714 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
715 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
716 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
717 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
718 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
Sujith7d0d0df2010-04-16 11:53:57 +0530719
720 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530721}
722
Senthil Balasubramanianb84628e2011-04-22 11:32:12 +0530723u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
Vivek Natarajanb1415812011-01-27 14:45:07 +0530724{
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100725 REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
726 udelay(100);
727 REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
728
729 while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0)
Vivek Natarajanb1415812011-01-27 14:45:07 +0530730 udelay(100);
Vivek Natarajanb1415812011-01-27 14:45:07 +0530731
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100732 return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
Vivek Natarajanb1415812011-01-27 14:45:07 +0530733}
734EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
735
Sujithcbe61d82009-02-09 13:27:12 +0530736static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530737 struct ath9k_channel *chan)
738{
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800739 u32 pll;
740
Vivek Natarajan22983c32011-01-27 14:45:09 +0530741 if (AR_SREV_9485(ah)) {
Vivek Natarajan22983c32011-01-27 14:45:09 +0530742
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530743 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
744 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
745 AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
746 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
747 AR_CH0_DPLL2_KD, 0x40);
748 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
749 AR_CH0_DPLL2_KI, 0x4);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530750
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530751 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
752 AR_CH0_BB_DPLL1_REFDIV, 0x5);
753 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
754 AR_CH0_BB_DPLL1_NINI, 0x58);
755 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
756 AR_CH0_BB_DPLL1_NFRAC, 0x0);
757
758 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
759 AR_CH0_BB_DPLL2_OUTDIV, 0x1);
760 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
761 AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
762 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
763 AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
764
765 /* program BB PLL phase_shift to 0x6 */
766 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
767 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
768
769 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
770 AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
Vivek Natarajan75e03512011-03-10 11:05:42 +0530771 udelay(1000);
Gabor Juhosa5415d62011-06-21 11:23:29 +0200772 } else if (AR_SREV_9330(ah)) {
773 u32 ddr_dpll2, pll_control2, kd;
774
775 if (ah->is_clk_25mhz) {
776 ddr_dpll2 = 0x18e82f01;
777 pll_control2 = 0xe04a3d;
778 kd = 0x1d;
779 } else {
780 ddr_dpll2 = 0x19e82f01;
781 pll_control2 = 0x886666;
782 kd = 0x3d;
783 }
784
785 /* program DDR PLL ki and kd value */
786 REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
787
788 /* program DDR PLL phase_shift */
789 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
790 AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
791
792 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
793 udelay(1000);
794
795 /* program refdiv, nint, frac to RTC register */
796 REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
797
798 /* program BB PLL kd and ki value */
799 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
800 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
801
802 /* program BB PLL phase_shift */
803 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
804 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530805 } else if (AR_SREV_9340(ah)) {
806 u32 regval, pll2_divint, pll2_divfrac, refdiv;
807
808 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
809 udelay(1000);
810
811 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
812 udelay(100);
813
814 if (ah->is_clk_25mhz) {
815 pll2_divint = 0x54;
816 pll2_divfrac = 0x1eb85;
817 refdiv = 3;
818 } else {
819 pll2_divint = 88;
820 pll2_divfrac = 0;
821 refdiv = 5;
822 }
823
824 regval = REG_READ(ah, AR_PHY_PLL_MODE);
825 regval |= (0x1 << 16);
826 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
827 udelay(100);
828
829 REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
830 (pll2_divint << 18) | pll2_divfrac);
831 udelay(100);
832
833 regval = REG_READ(ah, AR_PHY_PLL_MODE);
834 regval = (regval & 0x80071fff) | (0x1 << 30) | (0x1 << 13) |
835 (0x4 << 26) | (0x18 << 19);
836 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
837 REG_WRITE(ah, AR_PHY_PLL_MODE,
838 REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
839 udelay(1000);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530840 }
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800841
842 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +0530843
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100844 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530845
Gabor Juhosa5415d62011-06-21 11:23:29 +0200846 if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah))
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530847 udelay(1000);
848
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400849 /* Switch the core clock for ar9271 to 117Mhz */
850 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +0530851 udelay(500);
852 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400853 }
854
Sujithf1dc5602008-10-29 10:16:30 +0530855 udelay(RTC_PLL_SETTLE_DELAY);
856
857 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530858
859 if (AR_SREV_9340(ah)) {
860 if (ah->is_clk_25mhz) {
861 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
862 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
863 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
864 } else {
865 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
866 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
867 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
868 }
869 udelay(100);
870 }
Sujithf1dc5602008-10-29 10:16:30 +0530871}
872
Sujithcbe61d82009-02-09 13:27:12 +0530873static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -0800874 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +0530875{
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530876 u32 sync_default = AR_INTR_SYNC_DEFAULT;
Pavel Roskin152d5302010-03-31 18:05:37 -0400877 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +0530878 AR_IMR_TXURN |
879 AR_IMR_RXERR |
880 AR_IMR_RXORN |
881 AR_IMR_BCNMISC;
882
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530883 if (AR_SREV_9340(ah))
884 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
885
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400886 if (AR_SREV_9300_20_OR_LATER(ah)) {
887 imr_reg |= AR_IMR_RXOK_HP;
888 if (ah->config.rx_intr_mitigation)
889 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
890 else
891 imr_reg |= AR_IMR_RXOK_LP;
Sujithf1dc5602008-10-29 10:16:30 +0530892
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400893 } else {
894 if (ah->config.rx_intr_mitigation)
895 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
896 else
897 imr_reg |= AR_IMR_RXOK;
898 }
899
900 if (ah->config.tx_intr_mitigation)
901 imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
902 else
903 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +0530904
Colin McCabed97809d2008-12-01 13:38:55 -0800905 if (opmode == NL80211_IFTYPE_AP)
Pavel Roskin152d5302010-03-31 18:05:37 -0400906 imr_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +0530907
Sujith7d0d0df2010-04-16 11:53:57 +0530908 ENABLE_REGWRITE_BUFFER(ah);
909
Pavel Roskin152d5302010-03-31 18:05:37 -0400910 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -0500911 ah->imrs2_reg |= AR_IMR_S2_GTT;
912 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +0530913
914 if (!AR_SREV_9100(ah)) {
915 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530916 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
Sujithf1dc5602008-10-29 10:16:30 +0530917 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
918 }
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400919
Sujith7d0d0df2010-04-16 11:53:57 +0530920 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530921
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400922 if (AR_SREV_9300_20_OR_LATER(ah)) {
923 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
924 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
925 REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
926 REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
927 }
Sujithf1dc5602008-10-29 10:16:30 +0530928}
929
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700930static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us)
931{
932 u32 val = ath9k_hw_mac_to_clks(ah, us - 2);
933 val = min(val, (u32) 0xFFFF);
934 REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val);
935}
936
Felix Fietkau0005baf2010-01-15 02:33:40 +0100937static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530938{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100939 u32 val = ath9k_hw_mac_to_clks(ah, us);
940 val = min(val, (u32) 0xFFFF);
941 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +0530942}
943
Felix Fietkau0005baf2010-01-15 02:33:40 +0100944static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +0530945{
Felix Fietkau0005baf2010-01-15 02:33:40 +0100946 u32 val = ath9k_hw_mac_to_clks(ah, us);
947 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
948 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
949}
950
951static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
952{
953 u32 val = ath9k_hw_mac_to_clks(ah, us);
954 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
955 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +0530956}
957
Sujithcbe61d82009-02-09 13:27:12 +0530958static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +0530959{
Sujithf1dc5602008-10-29 10:16:30 +0530960 if (tu > 0xFFFF) {
Joe Perches226afe62010-12-02 19:12:37 -0800961 ath_dbg(ath9k_hw_common(ah), ATH_DBG_XMIT,
962 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +0530963 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +0530964 return false;
965 } else {
966 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +0530967 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +0530968 return true;
969 }
970}
971
Felix Fietkau0005baf2010-01-15 02:33:40 +0100972void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530973{
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700974 struct ath_common *common = ath9k_hw_common(ah);
975 struct ieee80211_conf *conf = &common->hw->conf;
976 const struct ath9k_channel *chan = ah->curchan;
Felix Fietkauadb50662011-08-28 01:52:10 +0200977 int acktimeout, ctstimeout;
Felix Fietkaue239d852010-01-15 02:34:58 +0100978 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +0100979 int sifstime;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700980 int rx_lat = 0, tx_lat = 0, eifs = 0;
981 u32 reg;
Felix Fietkau0005baf2010-01-15 02:33:40 +0100982
Joe Perches226afe62010-12-02 19:12:37 -0800983 ath_dbg(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
984 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +0530985
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700986 if (!chan)
987 return;
988
Sujith2660b812009-02-09 13:27:26 +0530989 if (ah->misc_mode != 0)
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100990 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +0100991
Rajkumar Manoharan81a91d52011-08-31 10:47:30 +0530992 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
993 rx_lat = 41;
994 else
995 rx_lat = 37;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +0700996 tx_lat = 54;
997
998 if (IS_CHAN_HALF_RATE(chan)) {
999 eifs = 175;
1000 rx_lat *= 2;
1001 tx_lat *= 2;
1002 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1003 tx_lat += 11;
1004
1005 slottime = 13;
1006 sifstime = 32;
1007 } else if (IS_CHAN_QUARTER_RATE(chan)) {
1008 eifs = 340;
Rajkumar Manoharan81a91d52011-08-31 10:47:30 +05301009 rx_lat = (rx_lat * 4) - 1;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001010 tx_lat *= 4;
1011 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1012 tx_lat += 22;
1013
1014 slottime = 21;
1015 sifstime = 64;
1016 } else {
Rajkumar Manoharana7be0392011-08-27 12:13:21 +05301017 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1018 eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
1019 reg = AR_USEC_ASYNC_FIFO;
1020 } else {
1021 eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
1022 common->clockrate;
1023 reg = REG_READ(ah, AR_USEC);
1024 }
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001025 rx_lat = MS(reg, AR_USEC_RX_LAT);
1026 tx_lat = MS(reg, AR_USEC_TX_LAT);
1027
1028 slottime = ah->slottime;
1029 if (IS_CHAN_5GHZ(chan))
1030 sifstime = 16;
1031 else
1032 sifstime = 10;
1033 }
Felix Fietkau0005baf2010-01-15 02:33:40 +01001034
Felix Fietkaue239d852010-01-15 02:34:58 +01001035 /* As defined by IEEE 802.11-2007 17.3.8.6 */
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001036 acktimeout = slottime + sifstime + 3 * ah->coverage_class;
Felix Fietkauadb50662011-08-28 01:52:10 +02001037 ctstimeout = acktimeout;
Felix Fietkau42c45682010-02-11 18:07:19 +01001038
1039 /*
1040 * Workaround for early ACK timeouts, add an offset to match the
1041 * initval's 64us ack timeout value.
1042 * This was initially only meant to work around an issue with delayed
1043 * BA frames in some implementations, but it has been found to fix ACK
1044 * timeout issues in other cases as well.
1045 */
1046 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
1047 acktimeout += 64 - sifstime - ah->slottime;
1048
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001049 ath9k_hw_set_sifs_time(ah, sifstime);
1050 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001051 ath9k_hw_set_ack_timeout(ah, acktimeout);
Felix Fietkauadb50662011-08-28 01:52:10 +02001052 ath9k_hw_set_cts_timeout(ah, ctstimeout);
Sujith2660b812009-02-09 13:27:26 +05301053 if (ah->globaltxtimeout != (u32) -1)
1054 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001055
1056 REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
1057 REG_RMW(ah, AR_USEC,
1058 (common->clockrate - 1) |
1059 SM(rx_lat, AR_USEC_RX_LAT) |
1060 SM(tx_lat, AR_USEC_TX_LAT),
1061 AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
1062
Sujithf1dc5602008-10-29 10:16:30 +05301063}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001064EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301065
Sujith285f2dd2010-01-08 10:36:07 +05301066void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001067{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001068 struct ath_common *common = ath9k_hw_common(ah);
1069
Sujith736b3a22010-03-17 14:25:24 +05301070 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001071 goto free_hw;
1072
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001073 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001074
1075free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001076 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001077}
Sujith285f2dd2010-01-08 10:36:07 +05301078EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001079
Sujithf1dc5602008-10-29 10:16:30 +05301080/*******/
1081/* INI */
1082/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001083
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001084u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001085{
1086 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1087
1088 if (IS_CHAN_B(chan))
1089 ctl |= CTL_11B;
1090 else if (IS_CHAN_G(chan))
1091 ctl |= CTL_11G;
1092 else
1093 ctl |= CTL_11A;
1094
1095 return ctl;
1096}
1097
Sujithf1dc5602008-10-29 10:16:30 +05301098/****************************************/
1099/* Reset and Channel Switching Routines */
1100/****************************************/
1101
Sujithcbe61d82009-02-09 13:27:12 +05301102static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301103{
Felix Fietkau57b32222010-04-15 17:39:22 -04001104 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301105
Sujith7d0d0df2010-04-16 11:53:57 +05301106 ENABLE_REGWRITE_BUFFER(ah);
1107
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001108 /*
1109 * set AHB_MODE not to do cacheline prefetches
1110 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001111 if (!AR_SREV_9300_20_OR_LATER(ah))
1112 REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301113
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001114 /*
1115 * let mac dma reads be in 128 byte chunks
1116 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001117 REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301118
Sujith7d0d0df2010-04-16 11:53:57 +05301119 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301120
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001121 /*
1122 * Restore TX Trigger Level to its pre-reset value.
1123 * The initial value depends on whether aggregation is enabled, and is
1124 * adjusted whenever underruns are detected.
1125 */
Felix Fietkau57b32222010-04-15 17:39:22 -04001126 if (!AR_SREV_9300_20_OR_LATER(ah))
1127 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301128
Sujith7d0d0df2010-04-16 11:53:57 +05301129 ENABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301130
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001131 /*
1132 * let mac dma writes be in 128 byte chunks
1133 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001134 REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301135
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001136 /*
1137 * Setup receive FIFO threshold to hold off TX activities
1138 */
Sujithf1dc5602008-10-29 10:16:30 +05301139 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1140
Felix Fietkau57b32222010-04-15 17:39:22 -04001141 if (AR_SREV_9300_20_OR_LATER(ah)) {
1142 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
1143 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
1144
1145 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
1146 ah->caps.rx_status_len);
1147 }
1148
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001149 /*
1150 * reduce the number of usable entries in PCU TXBUF to avoid
1151 * wrap around issues.
1152 */
Sujithf1dc5602008-10-29 10:16:30 +05301153 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001154 /* For AR9285 the number of Fifos are reduced to half.
1155 * So set the usable tx buf size also to half to
1156 * avoid data/delimiter underruns
1157 */
Sujithf1dc5602008-10-29 10:16:30 +05301158 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1159 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001160 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301161 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1162 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1163 }
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001164
Sujith7d0d0df2010-04-16 11:53:57 +05301165 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301166
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001167 if (AR_SREV_9300_20_OR_LATER(ah))
1168 ath9k_hw_reset_txstatus_ring(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301169}
1170
Sujithcbe61d82009-02-09 13:27:12 +05301171static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301172{
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001173 u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
1174 u32 set = AR_STA_ID1_KSRCH_MODE;
Sujithf1dc5602008-10-29 10:16:30 +05301175
Sujithf1dc5602008-10-29 10:16:30 +05301176 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001177 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001178 case NL80211_IFTYPE_MESH_POINT:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001179 set |= AR_STA_ID1_ADHOC;
Sujithf1dc5602008-10-29 10:16:30 +05301180 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1181 break;
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001182 case NL80211_IFTYPE_AP:
1183 set |= AR_STA_ID1_STA_AP;
1184 /* fall through */
Colin McCabed97809d2008-12-01 13:38:55 -08001185 case NL80211_IFTYPE_STATION:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001186 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
Sujithf1dc5602008-10-29 10:16:30 +05301187 break;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301188 default:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001189 if (!ah->is_monitoring)
1190 set = 0;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301191 break;
Sujithf1dc5602008-10-29 10:16:30 +05301192 }
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001193 REG_RMW(ah, AR_STA_ID1, set, mask);
Sujithf1dc5602008-10-29 10:16:30 +05301194}
1195
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001196void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1197 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001198{
1199 u32 coef_exp, coef_man;
1200
1201 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1202 if ((coef_scaled >> coef_exp) & 0x1)
1203 break;
1204
1205 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1206
1207 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1208
1209 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1210 *coef_exponent = coef_exp - 16;
1211}
1212
Sujithcbe61d82009-02-09 13:27:12 +05301213static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301214{
1215 u32 rst_flags;
1216 u32 tmpReg;
1217
Sujith70768492009-02-16 13:23:12 +05301218 if (AR_SREV_9100(ah)) {
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001219 REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
1220 AR_RTC_DERIVED_CLK_PERIOD, 1);
Sujith70768492009-02-16 13:23:12 +05301221 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1222 }
1223
Sujith7d0d0df2010-04-16 11:53:57 +05301224 ENABLE_REGWRITE_BUFFER(ah);
1225
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001226 if (AR_SREV_9300_20_OR_LATER(ah)) {
1227 REG_WRITE(ah, AR_WA, ah->WARegVal);
1228 udelay(10);
1229 }
1230
Sujithf1dc5602008-10-29 10:16:30 +05301231 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1232 AR_RTC_FORCE_WAKE_ON_INT);
1233
1234 if (AR_SREV_9100(ah)) {
1235 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1236 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1237 } else {
1238 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1239 if (tmpReg &
1240 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1241 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001242 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301243 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001244
1245 val = AR_RC_HOSTIF;
1246 if (!AR_SREV_9300_20_OR_LATER(ah))
1247 val |= AR_RC_AHB;
1248 REG_WRITE(ah, AR_RC, val);
1249
1250 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301251 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301252
1253 rst_flags = AR_RTC_RC_MAC_WARM;
1254 if (type == ATH9K_RESET_COLD)
1255 rst_flags |= AR_RTC_RC_MAC_COLD;
1256 }
1257
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001258 if (AR_SREV_9330(ah)) {
1259 int npend = 0;
1260 int i;
1261
1262 /* AR9330 WAR:
1263 * call external reset function to reset WMAC if:
1264 * - doing a cold reset
1265 * - we have pending frames in the TX queues
1266 */
1267
1268 for (i = 0; i < AR_NUM_QCU; i++) {
1269 npend = ath9k_hw_numtxpending(ah, i);
1270 if (npend)
1271 break;
1272 }
1273
1274 if (ah->external_reset &&
1275 (npend || type == ATH9K_RESET_COLD)) {
1276 int reset_err = 0;
1277
1278 ath_dbg(ath9k_hw_common(ah), ATH_DBG_RESET,
1279 "reset MAC via external reset\n");
1280
1281 reset_err = ah->external_reset();
1282 if (reset_err) {
1283 ath_err(ath9k_hw_common(ah),
1284 "External reset failed, err=%d\n",
1285 reset_err);
1286 return false;
1287 }
1288
1289 REG_WRITE(ah, AR_RTC_RESET, 1);
1290 }
1291 }
1292
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001293 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujith7d0d0df2010-04-16 11:53:57 +05301294
1295 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301296
Sujithf1dc5602008-10-29 10:16:30 +05301297 udelay(50);
1298
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001299 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301300 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Joe Perches226afe62010-12-02 19:12:37 -08001301 ath_dbg(ath9k_hw_common(ah), ATH_DBG_RESET,
1302 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301303 return false;
1304 }
1305
1306 if (!AR_SREV_9100(ah))
1307 REG_WRITE(ah, AR_RC, 0);
1308
Sujithf1dc5602008-10-29 10:16:30 +05301309 if (AR_SREV_9100(ah))
1310 udelay(50);
1311
1312 return true;
1313}
1314
Sujithcbe61d82009-02-09 13:27:12 +05301315static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301316{
Sujith7d0d0df2010-04-16 11:53:57 +05301317 ENABLE_REGWRITE_BUFFER(ah);
1318
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001319 if (AR_SREV_9300_20_OR_LATER(ah)) {
1320 REG_WRITE(ah, AR_WA, ah->WARegVal);
1321 udelay(10);
1322 }
1323
Sujithf1dc5602008-10-29 10:16:30 +05301324 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1325 AR_RTC_FORCE_WAKE_ON_INT);
1326
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001327 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301328 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1329
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001330 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301331
Sujith7d0d0df2010-04-16 11:53:57 +05301332 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301333
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001334 if (!AR_SREV_9300_20_OR_LATER(ah))
1335 udelay(2);
1336
1337 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301338 REG_WRITE(ah, AR_RC, 0);
1339
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001340 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301341
1342 if (!ath9k_hw_wait(ah,
1343 AR_RTC_STATUS,
1344 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301345 AR_RTC_STATUS_ON,
1346 AH_WAIT_TIMEOUT)) {
Joe Perches226afe62010-12-02 19:12:37 -08001347 ath_dbg(ath9k_hw_common(ah), ATH_DBG_RESET,
1348 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301349 return false;
1350 }
1351
Sujithf1dc5602008-10-29 10:16:30 +05301352 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1353}
1354
Sujithcbe61d82009-02-09 13:27:12 +05301355static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301356{
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301357 bool ret = false;
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301358
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001359 if (AR_SREV_9300_20_OR_LATER(ah)) {
1360 REG_WRITE(ah, AR_WA, ah->WARegVal);
1361 udelay(10);
1362 }
1363
Sujithf1dc5602008-10-29 10:16:30 +05301364 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1365 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1366
1367 switch (type) {
1368 case ATH9K_RESET_POWER_ON:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301369 ret = ath9k_hw_set_reset_power_on(ah);
1370 break;
Sujithf1dc5602008-10-29 10:16:30 +05301371 case ATH9K_RESET_WARM:
1372 case ATH9K_RESET_COLD:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301373 ret = ath9k_hw_set_reset(ah, type);
1374 break;
Sujithf1dc5602008-10-29 10:16:30 +05301375 default:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301376 break;
Sujithf1dc5602008-10-29 10:16:30 +05301377 }
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301378
1379 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
1380 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
1381
1382 return ret;
Sujithf1dc5602008-10-29 10:16:30 +05301383}
1384
Sujithcbe61d82009-02-09 13:27:12 +05301385static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301386 struct ath9k_channel *chan)
1387{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301388 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301389 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1390 return false;
1391 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301392 return false;
1393
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001394 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301395 return false;
1396
Sujith2660b812009-02-09 13:27:26 +05301397 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301398 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301399 ath9k_hw_set_rfmode(ah, chan);
1400
1401 return true;
1402}
1403
Sujithcbe61d82009-02-09 13:27:12 +05301404static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001405 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301406{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001407 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001408 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001409 int r;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301410 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1411 bool band_switch, mode_diff;
1412 u8 ini_reloaded;
1413
1414 band_switch = (chan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ)) !=
1415 (ah->curchan->channelFlags & (CHANNEL_2GHZ |
1416 CHANNEL_5GHZ));
1417 mode_diff = (chan->chanmode != ah->curchan->chanmode);
Sujithf1dc5602008-10-29 10:16:30 +05301418
1419 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1420 if (ath9k_hw_numtxpending(ah, qnum)) {
Joe Perches226afe62010-12-02 19:12:37 -08001421 ath_dbg(common, ATH_DBG_QUEUE,
1422 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301423 return false;
1424 }
1425 }
1426
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001427 if (!ath9k_hw_rfbus_req(ah)) {
Joe Perches38002762010-12-02 19:12:36 -08001428 ath_err(common, "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301429 return false;
1430 }
1431
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301432 if (edma && (band_switch || mode_diff)) {
1433 ath9k_hw_mark_phy_inactive(ah);
1434 udelay(5);
1435
1436 ath9k_hw_init_pll(ah, NULL);
1437
1438 if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
1439 ath_err(common, "Failed to do fast channel change\n");
1440 return false;
1441 }
1442 }
1443
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001444 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301445
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001446 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001447 if (r) {
Joe Perches38002762010-12-02 19:12:36 -08001448 ath_err(common, "Failed to set channel\n");
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001449 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301450 }
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001451 ath9k_hw_set_clockrate(ah);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02001452 ath9k_hw_apply_txpower(ah, chan);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001453 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301454
1455 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1456 ath9k_hw_set_delta_slope(ah, chan);
1457
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001458 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301459
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301460 if (edma && (band_switch || mode_diff)) {
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301461 ah->ah_flags |= AH_FASTCC;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301462 if (band_switch || ini_reloaded)
1463 ah->eep_ops->set_board_values(ah, chan);
1464
1465 ath9k_hw_init_bb(ah, chan);
1466
1467 if (band_switch || ini_reloaded)
1468 ath9k_hw_init_cal(ah, chan);
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301469 ah->ah_flags &= ~AH_FASTCC;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301470 }
1471
Sujithf1dc5602008-10-29 10:16:30 +05301472 return true;
1473}
1474
Felix Fietkau691680b2011-03-19 13:55:38 +01001475static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
1476{
1477 u32 gpio_mask = ah->gpio_mask;
1478 int i;
1479
1480 for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
1481 if (!(gpio_mask & 1))
1482 continue;
1483
1484 ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1485 ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
1486 }
1487}
1488
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001489bool ath9k_hw_check_alive(struct ath_hw *ah)
Johannes Berg3b319aa2009-06-13 14:50:26 +05301490{
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001491 int count = 50;
1492 u32 reg;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301493
Felix Fietkaue17f83e2010-09-22 12:34:53 +02001494 if (AR_SREV_9285_12_OR_LATER(ah))
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001495 return true;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301496
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001497 do {
1498 reg = REG_READ(ah, AR_OBS_BUS_1);
1499
1500 if ((reg & 0x7E7FFFEF) == 0x00702400)
1501 continue;
1502
1503 switch (reg & 0x7E000B00) {
1504 case 0x1E000000:
1505 case 0x52000B00:
1506 case 0x18000B00:
1507 continue;
1508 default:
1509 return true;
1510 }
1511 } while (count-- > 0);
1512
1513 return false;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301514}
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001515EXPORT_SYMBOL(ath9k_hw_check_alive);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301516
Sujithcbe61d82009-02-09 13:27:12 +05301517int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001518 struct ath9k_hw_cal_data *caldata, bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001519{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001520 struct ath_common *common = ath9k_hw_common(ah);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301521 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001522 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301523 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001524 u32 saveDefAntenna;
1525 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301526 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001527 int i, r;
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301528 bool allow_fbs = false;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301529 bool mci = !!(ah->caps.hw_caps & ATH9K_HW_CAP_MCI);
1530 bool save_fullsleep = ah->chip_fullsleep;
1531
1532 if (mci) {
1533
1534 ar9003_mci_2g5g_changed(ah, IS_CHAN_2GHZ(chan));
1535
1536 if (mci_hw->bt_state == MCI_BT_CAL_START) {
1537 u32 payload[4] = {0, 0, 0, 0};
1538
1539 ath_dbg(common, ATH_DBG_MCI, "MCI stop rx for BT CAL");
1540
1541 mci_hw->bt_state = MCI_BT_CAL;
1542
1543 /*
1544 * MCI FIX: disable mci interrupt here. This is to avoid
1545 * SW_MSG_DONE or RX_MSG bits to trigger MCI_INT and
1546 * lead to mci_intr reentry.
1547 */
1548
1549 ar9003_mci_disable_interrupt(ah);
1550
1551 ath_dbg(common, ATH_DBG_MCI, "send WLAN_CAL_GRANT");
1552 MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_GRANT);
1553 ar9003_mci_send_message(ah, MCI_GPM, 0, payload,
1554 16, true, false);
1555
1556 ath_dbg(common, ATH_DBG_MCI, "\nMCI BT is calibrating");
1557
1558 /* Wait BT calibration to be completed for 25ms */
1559
1560 if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_DONE,
1561 0, 25000))
1562 ath_dbg(common, ATH_DBG_MCI,
1563 "MCI got BT_CAL_DONE\n");
1564 else
1565 ath_dbg(common, ATH_DBG_MCI,
1566 "MCI ### BT cal takes to long, force"
1567 "bt_state to be bt_awake\n");
1568 mci_hw->bt_state = MCI_BT_AWAKE;
1569 /* MCI FIX: enable mci interrupt here */
1570 ar9003_mci_enable_interrupt(ah);
1571
1572 return true;
1573 }
1574 }
1575
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001576
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001577 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001578 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001579
Felix Fietkaud9891c72010-09-29 17:15:27 +02001580 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001581 ath9k_hw_getnf(ah, curchan);
1582
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001583 ah->caldata = caldata;
1584 if (caldata &&
1585 (chan->channel != caldata->channel ||
1586 (chan->channelFlags & ~CHANNEL_CW_INT) !=
1587 (caldata->channelFlags & ~CHANNEL_CW_INT))) {
1588 /* Operating channel changed, reset channel calibration data */
1589 memset(caldata, 0, sizeof(*caldata));
1590 ath9k_init_nfcal_hist_buffer(ah, chan);
1591 }
Felix Fietkauf23fba492011-07-28 14:08:56 +02001592 ah->noise = ath9k_hw_getchan_noise(ah, chan);
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001593
Rajkumar Manoharan19787b22011-10-13 11:00:39 +05301594 if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
Rajkumar Manoharan7db062a2011-09-14 14:20:30 +05301595 bChannelChange = false;
1596
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301597 if (caldata &&
1598 caldata->done_txiqcal_once &&
1599 caldata->done_txclcal_once &&
1600 caldata->rtt_hist.num_readings)
1601 allow_fbs = true;
1602
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001603 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301604 (ah->chip_fullsleep != true) &&
1605 (ah->curchan != NULL) &&
1606 (chan->channel != ah->curchan->channel) &&
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301607 (allow_fbs ||
1608 ((chan->channelFlags & CHANNEL_ALL) ==
1609 (ah->curchan->channelFlags & CHANNEL_ALL)))) {
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001610 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301611 ath9k_hw_loadnf(ah, ah->curchan);
Felix Fietkau00c86592010-07-30 21:02:09 +02001612 ath9k_hw_start_nfcal(ah, true);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301613 if (mci && mci_hw->ready)
1614 ar9003_mci_2g5g_switch(ah, true);
1615
Rajkumar Manoharanc2ba3342010-09-03 16:00:00 +05301616 if (AR_SREV_9271(ah))
1617 ar9002_hw_load_ani_reg(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001618 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001619 }
1620 }
1621
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301622 if (mci) {
1623 ar9003_mci_disable_interrupt(ah);
1624
1625 if (mci_hw->ready && !save_fullsleep) {
1626 ar9003_mci_mute_bt(ah);
1627 udelay(20);
1628 REG_WRITE(ah, AR_BTCOEX_CTRL, 0);
1629 }
1630
1631 mci_hw->bt_state = MCI_BT_SLEEP;
1632 mci_hw->ready = false;
1633 }
1634
1635
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001636 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1637 if (saveDefAntenna == 0)
1638 saveDefAntenna = 1;
1639
1640 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1641
Sujith46fe7822009-09-17 09:25:25 +05301642 /* For chips on which RTC reset is done, save TSF before it gets cleared */
Felix Fietkauf860d522010-06-30 02:07:48 +02001643 if (AR_SREV_9100(ah) ||
1644 (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)))
Sujith46fe7822009-09-17 09:25:25 +05301645 tsf = ath9k_hw_gettsf64(ah);
1646
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001647 saveLedState = REG_READ(ah, AR_CFG_LED) &
1648 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1649 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1650
1651 ath9k_hw_mark_phy_inactive(ah);
1652
Vasanthakumar Thiagarajan45ef6a0b2010-12-15 07:30:53 -08001653 ah->paprd_table_write_done = false;
1654
Sujith05020d22010-03-17 14:25:23 +05301655 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001656 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1657 REG_WRITE(ah,
1658 AR9271_RESET_POWER_DOWN_CONTROL,
1659 AR9271_RADIO_RF_RST);
1660 udelay(50);
1661 }
1662
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001663 if (!ath9k_hw_chip_reset(ah, chan)) {
Joe Perches38002762010-12-02 19:12:36 -08001664 ath_err(common, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001665 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001666 }
1667
Sujith05020d22010-03-17 14:25:23 +05301668 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001669 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1670 ah->htc_reset_init = false;
1671 REG_WRITE(ah,
1672 AR9271_RESET_POWER_DOWN_CONTROL,
1673 AR9271_GATE_MAC_CTL);
1674 udelay(50);
1675 }
1676
Sujith46fe7822009-09-17 09:25:25 +05301677 /* Restore TSF */
Felix Fietkauf860d522010-06-30 02:07:48 +02001678 if (tsf)
Sujith46fe7822009-09-17 09:25:25 +05301679 ath9k_hw_settsf64(ah, tsf);
1680
Felix Fietkau7a370812010-09-22 12:34:52 +02001681 if (AR_SREV_9280_20_OR_LATER(ah))
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301682 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001683
Sujithe9141f72010-06-01 15:14:10 +05301684 if (!AR_SREV_9300_20_OR_LATER(ah))
1685 ar9002_hw_enable_async_fifo(ah);
1686
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001687 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001688 if (r)
1689 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001690
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301691 if (mci)
1692 ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
1693
Felix Fietkauf860d522010-06-30 02:07:48 +02001694 /*
1695 * Some AR91xx SoC devices frequently fail to accept TSF writes
1696 * right after the chip reset. When that happens, write a new
1697 * value after the initvals have been applied, with an offset
1698 * based on measured time difference
1699 */
1700 if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
1701 tsf += 1500;
1702 ath9k_hw_settsf64(ah, tsf);
1703 }
1704
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001705 /* Setup MFP options for CCMP */
1706 if (AR_SREV_9280_20_OR_LATER(ah)) {
1707 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1708 * frames when constructing CCMP AAD. */
1709 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1710 0xc7ff);
1711 ah->sw_mgmt_crypto = false;
1712 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1713 /* Disable hardware crypto for management frames */
1714 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1715 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1716 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1717 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1718 ah->sw_mgmt_crypto = true;
1719 } else
1720 ah->sw_mgmt_crypto = true;
1721
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001722 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1723 ath9k_hw_set_delta_slope(ah, chan);
1724
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001725 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301726 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001727
Sujith7d0d0df2010-04-16 11:53:57 +05301728 ENABLE_REGWRITE_BUFFER(ah);
1729
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001730 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1731 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001732 | macStaId1
1733 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301734 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301735 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301736 | ah->sta_id1_defaults);
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001737 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001738 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001739 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001740 REG_WRITE(ah, AR_ISR, ~0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001741 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1742
Sujith7d0d0df2010-04-16 11:53:57 +05301743 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301744
Sujith Manoharan00e00032011-01-26 21:59:05 +05301745 ath9k_hw_set_operating_mode(ah, ah->opmode);
1746
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001747 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001748 if (r)
1749 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001750
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001751 ath9k_hw_set_clockrate(ah);
1752
Sujith7d0d0df2010-04-16 11:53:57 +05301753 ENABLE_REGWRITE_BUFFER(ah);
1754
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001755 for (i = 0; i < AR_NUM_DCU; i++)
1756 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1757
Sujith7d0d0df2010-04-16 11:53:57 +05301758 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301759
Sujith2660b812009-02-09 13:27:26 +05301760 ah->intr_txqs = 0;
Felix Fietkauf4c607d2011-03-23 20:57:28 +01001761 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001762 ath9k_hw_resettxqueue(ah, i);
1763
Sujith2660b812009-02-09 13:27:26 +05301764 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001765 ath9k_hw_ani_cache_ini_regs(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001766 ath9k_hw_init_qos(ah);
1767
Sujith2660b812009-02-09 13:27:26 +05301768 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Felix Fietkau55821322010-12-17 00:57:01 +01001769 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301770
Felix Fietkau0005baf2010-01-15 02:33:40 +01001771 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001772
Felix Fietkaufe2b6af2011-07-09 11:12:51 +07001773 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1774 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1775 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1776 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1777 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1778 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1779 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301780 }
1781
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001782 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001783
1784 ath9k_hw_set_dma(ah);
1785
1786 REG_WRITE(ah, AR_OBS, 8);
1787
Sujith0ce024c2009-12-14 14:57:00 +05301788 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001789 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1790 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1791 }
1792
Vasanthakumar Thiagarajan7f62a132010-04-15 17:39:19 -04001793 if (ah->config.tx_intr_mitigation) {
1794 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1795 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1796 }
1797
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001798 ath9k_hw_init_bb(ah, chan);
1799
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301800 if (caldata) {
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301801 caldata->done_txiqcal_once = false;
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301802 caldata->done_txclcal_once = false;
Rajkumar Manoharan324c74a2011-10-13 11:00:41 +05301803 caldata->rtt_hist.num_readings = 0;
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301804 }
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001805 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001806 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001807
Rajkumar Manoharan93348922011-10-25 16:47:36 +05301808 ath9k_hw_loadnf(ah, chan);
1809 ath9k_hw_start_nfcal(ah, true);
1810
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301811 if (mci && mci_hw->ready) {
1812
1813 if (IS_CHAN_2GHZ(chan) &&
1814 (mci_hw->bt_state == MCI_BT_SLEEP)) {
1815
1816 if (ar9003_mci_check_int(ah,
1817 AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET) ||
1818 ar9003_mci_check_int(ah,
1819 AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE)) {
1820
1821 /*
1822 * BT is sleeping. Check if BT wakes up during
1823 * WLAN calibration. If BT wakes up during
1824 * WLAN calibration, need to go through all
1825 * message exchanges again and recal.
1826 */
1827
1828 ath_dbg(common, ATH_DBG_MCI, "MCI BT wakes up"
1829 "during WLAN calibration\n");
1830
1831 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
1832 AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET |
1833 AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE);
1834 ath_dbg(common, ATH_DBG_MCI, "MCI send"
1835 "REMOTE_RESET\n");
1836 ar9003_mci_remote_reset(ah, true);
1837 ar9003_mci_send_sys_waking(ah, true);
1838 udelay(1);
1839 if (IS_CHAN_2GHZ(chan))
1840 ar9003_mci_send_lna_transfer(ah, true);
1841
1842 mci_hw->bt_state = MCI_BT_AWAKE;
1843
1844 ath_dbg(common, ATH_DBG_MCI, "MCI re-cal\n");
1845
1846 if (caldata) {
1847 caldata->done_txiqcal_once = false;
1848 caldata->done_txclcal_once = false;
1849 caldata->rtt_hist.num_readings = 0;
1850 }
1851
1852 if (!ath9k_hw_init_cal(ah, chan))
1853 return -EIO;
1854
1855 }
1856 }
1857 ar9003_mci_enable_interrupt(ah);
1858 }
1859
Sujith7d0d0df2010-04-16 11:53:57 +05301860 ENABLE_REGWRITE_BUFFER(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001861
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001862 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001863 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1864
Sujith7d0d0df2010-04-16 11:53:57 +05301865 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301866
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001867 /*
1868 * For big endian systems turn on swapping for descriptors
1869 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001870 if (AR_SREV_9100(ah)) {
1871 u32 mask;
1872 mask = REG_READ(ah, AR_CFG);
1873 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Joe Perches226afe62010-12-02 19:12:37 -08001874 ath_dbg(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301875 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001876 } else {
1877 mask =
1878 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1879 REG_WRITE(ah, AR_CFG, mask);
Joe Perches226afe62010-12-02 19:12:37 -08001880 ath_dbg(common, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301881 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001882 }
1883 } else {
Sujithcbba8cd2010-06-02 15:53:31 +05301884 if (common->bus_ops->ath_bus_type == ATH_USB) {
1885 /* Configure AR9271 target WLAN */
1886 if (AR_SREV_9271(ah))
1887 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
1888 else
1889 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1890 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001891#ifdef __BIG_ENDIAN
Gabor Juhos4033bda2011-06-21 11:23:35 +02001892 else if (AR_SREV_9330(ah) || AR_SREV_9340(ah))
Vasanthakumar Thiagarajan2be7bfe2011-04-19 19:29:14 +05301893 REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
1894 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001895 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001896#endif
1897 }
1898
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001899 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301900 ath9k_hw_btcoex_enable(ah);
1901
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301902 if (mci && mci_hw->ready) {
1903 /*
1904 * check BT state again to make
1905 * sure it's not changed.
1906 */
1907
1908 ar9003_mci_sync_bt_state(ah);
1909 ar9003_mci_2g5g_switch(ah, true);
1910
1911 if ((mci_hw->bt_state == MCI_BT_AWAKE) &&
1912 (mci_hw->query_bt == true)) {
1913 mci_hw->need_flush_btinfo = true;
1914 }
1915 }
1916
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05301917 if (AR_SREV_9300_20_OR_LATER(ah)) {
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001918 ar9003_hw_bb_watchdog_config(ah);
Vasanthakumar Thiagarajand8903a52010-04-15 17:39:25 -04001919
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05301920 ar9003_hw_disable_phy_restart(ah);
1921 }
1922
Felix Fietkau691680b2011-03-19 13:55:38 +01001923 ath9k_hw_apply_gpio_override(ah);
1924
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001925 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001926}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001927EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001928
Sujithf1dc5602008-10-29 10:16:30 +05301929/******************************/
1930/* Power Management (Chipset) */
1931/******************************/
1932
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001933/*
1934 * Notify Power Mgt is disabled in self-generated frames.
1935 * If requested, force chip to sleep.
1936 */
Sujithcbe61d82009-02-09 13:27:12 +05301937static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301938{
1939 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1940 if (setChip) {
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05301941 if (AR_SREV_9462(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301942 REG_WRITE(ah, AR_TIMER_MODE,
1943 REG_READ(ah, AR_TIMER_MODE) & 0xFFFFFF00);
1944 REG_WRITE(ah, AR_NDP2_TIMER_MODE, REG_READ(ah,
1945 AR_NDP2_TIMER_MODE) & 0xFFFFFF00);
1946 REG_WRITE(ah, AR_SLP32_INC,
1947 REG_READ(ah, AR_SLP32_INC) & 0xFFF00000);
1948 /* xxx Required for WLAN only case ? */
1949 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
1950 udelay(100);
1951 }
1952
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001953 /*
1954 * Clear the RTC force wake bit to allow the
1955 * mac to go to sleep.
1956 */
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301957 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
1958
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05301959 if (AR_SREV_9462(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301960 udelay(100);
1961
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001962 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301963 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1964
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001965 /* Shutdown chip. Active low */
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301966 if (!AR_SREV_5416(ah) &&
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05301967 !AR_SREV_9271(ah) && !AR_SREV_9462_10(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301968 REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
1969 udelay(2);
1970 }
Sujithf1dc5602008-10-29 10:16:30 +05301971 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001972
1973 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
Rafael J. Wysockia7322812011-11-26 23:37:43 +01001974 if (AR_SREV_9300_20_OR_LATER(ah))
1975 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001976}
1977
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001978/*
1979 * Notify Power Management is enabled in self-generating
1980 * frames. If request, set power mode of chip to
1981 * auto/normal. Duration in units of 128us (1/8 TU).
1982 */
Sujithcbe61d82009-02-09 13:27:12 +05301983static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001984{
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301985 u32 val;
1986
Sujithf1dc5602008-10-29 10:16:30 +05301987 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1988 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05301989 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001990
Sujithf1dc5602008-10-29 10:16:30 +05301991 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001992 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05301993 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1994 AR_RTC_FORCE_WAKE_ON_INT);
1995 } else {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301996
1997 /* When chip goes into network sleep, it could be waken
1998 * up by MCI_INT interrupt caused by BT's HW messages
1999 * (LNA_xxx, CONT_xxx) which chould be in a very fast
2000 * rate (~100us). This will cause chip to leave and
2001 * re-enter network sleep mode frequently, which in
2002 * consequence will have WLAN MCI HW to generate lots of
2003 * SYS_WAKING and SYS_SLEEPING messages which will make
2004 * BT CPU to busy to process.
2005 */
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302006 if (AR_SREV_9462(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302007 val = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_EN) &
2008 ~AR_MCI_INTERRUPT_RX_HW_MSG_MASK;
2009 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, val);
2010 }
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002011 /*
2012 * Clear the RTC force wake bit to allow the
2013 * mac to go to sleep.
2014 */
Sujithf1dc5602008-10-29 10:16:30 +05302015 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2016 AR_RTC_FORCE_WAKE_EN);
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302017
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302018 if (AR_SREV_9462(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302019 udelay(30);
Sujithf1dc5602008-10-29 10:16:30 +05302020 }
2021 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04002022
2023 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
2024 if (AR_SREV_9300_20_OR_LATER(ah))
2025 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Sujithf1dc5602008-10-29 10:16:30 +05302026}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002027
Sujithcbe61d82009-02-09 13:27:12 +05302028static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302029{
2030 u32 val;
2031 int i;
2032
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04002033 /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
2034 if (AR_SREV_9300_20_OR_LATER(ah)) {
2035 REG_WRITE(ah, AR_WA, ah->WARegVal);
2036 udelay(10);
2037 }
2038
Sujithf1dc5602008-10-29 10:16:30 +05302039 if (setChip) {
2040 if ((REG_READ(ah, AR_RTC_STATUS) &
2041 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2042 if (ath9k_hw_set_reset_reg(ah,
2043 ATH9K_RESET_POWER_ON) != true) {
2044 return false;
2045 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04002046 if (!AR_SREV_9300_20_OR_LATER(ah))
2047 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302048 }
2049 if (AR_SREV_9100(ah))
2050 REG_SET_BIT(ah, AR_RTC_RESET,
2051 AR_RTC_RESET_EN);
2052
2053 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2054 AR_RTC_FORCE_WAKE_EN);
2055 udelay(50);
2056
2057 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2058 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2059 if (val == AR_RTC_STATUS_ON)
2060 break;
2061 udelay(50);
2062 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2063 AR_RTC_FORCE_WAKE_EN);
2064 }
2065 if (i == 0) {
Joe Perches38002762010-12-02 19:12:36 -08002066 ath_err(ath9k_hw_common(ah),
2067 "Failed to wakeup in %uus\n",
2068 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302069 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002070 }
2071 }
2072
Sujithf1dc5602008-10-29 10:16:30 +05302073 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2074
2075 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002076}
2077
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002078bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302079{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002080 struct ath_common *common = ath9k_hw_common(ah);
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05302081 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Sujithcbe61d82009-02-09 13:27:12 +05302082 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302083 static const char *modes[] = {
2084 "AWAKE",
2085 "FULL-SLEEP",
2086 "NETWORK SLEEP",
2087 "UNDEFINED"
2088 };
Sujithf1dc5602008-10-29 10:16:30 +05302089
Gabor Juhoscbdec972009-07-24 17:27:22 +02002090 if (ah->power_mode == mode)
2091 return status;
2092
Joe Perches226afe62010-12-02 19:12:37 -08002093 ath_dbg(common, ATH_DBG_RESET, "%s -> %s\n",
2094 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302095
2096 switch (mode) {
2097 case ATH9K_PM_AWAKE:
2098 status = ath9k_hw_set_power_awake(ah, setChip);
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05302099
2100 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
2101 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
2102
Sujithf1dc5602008-10-29 10:16:30 +05302103 break;
2104 case ATH9K_PM_FULL_SLEEP:
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05302105
2106 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI) {
2107 if (ar9003_mci_state(ah, MCI_STATE_ENABLE, NULL) &&
2108 (mci->bt_state != MCI_BT_SLEEP) &&
2109 !mci->halted_bt_gpm) {
2110 ath_dbg(common, ATH_DBG_MCI, "MCI halt BT GPM"
2111 "(full_sleep)");
2112 ar9003_mci_send_coex_halt_bt_gpm(ah,
2113 true, true);
2114 }
2115
2116 mci->ready = false;
2117 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
2118 }
2119
Sujithf1dc5602008-10-29 10:16:30 +05302120 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302121 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302122 break;
2123 case ATH9K_PM_NETWORK_SLEEP:
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05302124
2125 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
2126 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
2127
Sujithf1dc5602008-10-29 10:16:30 +05302128 ath9k_set_power_network_sleep(ah, setChip);
2129 break;
2130 default:
Joe Perches38002762010-12-02 19:12:36 -08002131 ath_err(common, "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302132 return false;
2133 }
Sujith2660b812009-02-09 13:27:26 +05302134 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302135
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002136 /*
2137 * XXX: If this warning never comes up after a while then
2138 * simply keep the ATH_DBG_WARN_ON_ONCE() but make
2139 * ath9k_hw_setpower() return type void.
2140 */
Sujith Manoharan97dcec52010-12-20 08:02:42 +05302141
2142 if (!(ah->ah_flags & AH_UNPLUGGED))
2143 ATH_DBG_WARN_ON_ONCE(!status);
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002144
Sujithf1dc5602008-10-29 10:16:30 +05302145 return status;
2146}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002147EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302148
Sujithf1dc5602008-10-29 10:16:30 +05302149/*******************/
2150/* Beacon Handling */
2151/*******************/
2152
Sujithcbe61d82009-02-09 13:27:12 +05302153void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002154{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002155 int flags = 0;
2156
Sujith7d0d0df2010-04-16 11:53:57 +05302157 ENABLE_REGWRITE_BUFFER(ah);
2158
Sujith2660b812009-02-09 13:27:26 +05302159 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002160 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002161 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002162 REG_SET_BIT(ah, AR_TXCFG,
2163 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
Felix Fietkaudd347f22011-03-22 21:54:17 +01002164 REG_WRITE(ah, AR_NEXT_NDP_TIMER, next_beacon +
2165 TU_TO_USEC(ah->atim_window ? ah->atim_window : 1));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002166 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002167 case NL80211_IFTYPE_AP:
Felix Fietkaudd347f22011-03-22 21:54:17 +01002168 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
2169 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
2170 TU_TO_USEC(ah->config.dma_beacon_response_time));
2171 REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
2172 TU_TO_USEC(ah->config.sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002173 flags |=
2174 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2175 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002176 default:
Joe Perches226afe62010-12-02 19:12:37 -08002177 ath_dbg(ath9k_hw_common(ah), ATH_DBG_BEACON,
2178 "%s: unsupported opmode: %d\n",
2179 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002180 return;
2181 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002182 }
2183
Felix Fietkaudd347f22011-03-22 21:54:17 +01002184 REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
2185 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
2186 REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
2187 REG_WRITE(ah, AR_NDP_PERIOD, beacon_period);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002188
Sujith7d0d0df2010-04-16 11:53:57 +05302189 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302190
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002191 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2192}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002193EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002194
Sujithcbe61d82009-02-09 13:27:12 +05302195void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302196 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002197{
2198 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302199 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002200 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002201
Sujith7d0d0df2010-04-16 11:53:57 +05302202 ENABLE_REGWRITE_BUFFER(ah);
2203
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002204 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2205
2206 REG_WRITE(ah, AR_BEACON_PERIOD,
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302207 TU_TO_USEC(bs->bs_intval));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002208 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302209 TU_TO_USEC(bs->bs_intval));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002210
Sujith7d0d0df2010-04-16 11:53:57 +05302211 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302212
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002213 REG_RMW_FIELD(ah, AR_RSSI_THR,
2214 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2215
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302216 beaconintval = bs->bs_intval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002217
2218 if (bs->bs_sleepduration > beaconintval)
2219 beaconintval = bs->bs_sleepduration;
2220
2221 dtimperiod = bs->bs_dtimperiod;
2222 if (bs->bs_sleepduration > dtimperiod)
2223 dtimperiod = bs->bs_sleepduration;
2224
2225 if (beaconintval == dtimperiod)
2226 nextTbtt = bs->bs_nextdtim;
2227 else
2228 nextTbtt = bs->bs_nexttbtt;
2229
Joe Perches226afe62010-12-02 19:12:37 -08002230 ath_dbg(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2231 ath_dbg(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
2232 ath_dbg(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
2233 ath_dbg(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002234
Sujith7d0d0df2010-04-16 11:53:57 +05302235 ENABLE_REGWRITE_BUFFER(ah);
2236
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002237 REG_WRITE(ah, AR_NEXT_DTIM,
2238 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2239 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2240
2241 REG_WRITE(ah, AR_SLEEP1,
2242 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2243 | AR_SLEEP1_ASSUME_DTIM);
2244
Sujith60b67f52008-08-07 10:52:38 +05302245 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002246 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2247 else
2248 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2249
2250 REG_WRITE(ah, AR_SLEEP2,
2251 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2252
2253 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2254 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2255
Sujith7d0d0df2010-04-16 11:53:57 +05302256 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302257
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002258 REG_SET_BIT(ah, AR_TIMER_MODE,
2259 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2260 AR_DTIM_TIMER_EN);
2261
Sujith4af9cf42009-02-12 10:06:47 +05302262 /* TSF Out of Range Threshold */
2263 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002264}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002265EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002266
Sujithf1dc5602008-10-29 10:16:30 +05302267/*******************/
2268/* HW Capabilities */
2269/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002270
Felix Fietkau60540692011-07-19 08:46:44 +02002271static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
2272{
2273 eeprom_chainmask &= chip_chainmask;
2274 if (eeprom_chainmask)
2275 return eeprom_chainmask;
2276 else
2277 return chip_chainmask;
2278}
2279
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002280int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002281{
Sujith2660b812009-02-09 13:27:26 +05302282 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002283 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002284 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002285 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Felix Fietkau60540692011-07-19 08:46:44 +02002286 unsigned int chip_chainmask;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002287
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +05302288 u16 eeval;
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002289 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002290
Sujithf74df6f2009-02-09 13:27:24 +05302291 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002292 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302293
Sujith2660b812009-02-09 13:27:26 +05302294 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302295 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002296 if (regulatory->current_rd == 0x64 ||
2297 regulatory->current_rd == 0x65)
2298 regulatory->current_rd += 5;
2299 else if (regulatory->current_rd == 0x41)
2300 regulatory->current_rd = 0x43;
Joe Perches226afe62010-12-02 19:12:37 -08002301 ath_dbg(common, ATH_DBG_REGULATORY,
2302 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002303 }
Sujithdc2222a2008-08-14 13:26:55 +05302304
Sujithf74df6f2009-02-09 13:27:24 +05302305 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002306 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
Joe Perches38002762010-12-02 19:12:36 -08002307 ath_err(common,
2308 "no band has been marked as supported in EEPROM\n");
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002309 return -EINVAL;
2310 }
2311
Felix Fietkaud4659912010-10-14 16:02:39 +02002312 if (eeval & AR5416_OPFLAGS_11A)
2313 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002314
Felix Fietkaud4659912010-10-14 16:02:39 +02002315 if (eeval & AR5416_OPFLAGS_11G)
2316 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
Sujithf1dc5602008-10-29 10:16:30 +05302317
Felix Fietkau60540692011-07-19 08:46:44 +02002318 if (AR_SREV_9485(ah) || AR_SREV_9285(ah) || AR_SREV_9330(ah))
2319 chip_chainmask = 1;
Mohammed Shafi Shajakhanba5736a2011-11-30 21:10:52 +05302320 else if (AR_SREV_9462(ah))
2321 chip_chainmask = 3;
Felix Fietkau60540692011-07-19 08:46:44 +02002322 else if (!AR_SREV_9280_20_OR_LATER(ah))
2323 chip_chainmask = 7;
2324 else if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9340(ah))
2325 chip_chainmask = 3;
2326 else
2327 chip_chainmask = 7;
2328
Sujithf74df6f2009-02-09 13:27:24 +05302329 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002330 /*
2331 * For AR9271 we will temporarilly uses the rx chainmax as read from
2332 * the EEPROM.
2333 */
Sujith8147f5d2009-02-20 15:13:23 +05302334 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002335 !(eeval & AR5416_OPFLAGS_11A) &&
2336 !(AR_SREV_9271(ah)))
2337 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302338 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
Felix Fietkau598cdd52011-03-19 13:55:42 +01002339 else if (AR_SREV_9100(ah))
2340 pCap->rx_chainmask = 0x7;
Sujith8147f5d2009-02-20 15:13:23 +05302341 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002342 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302343 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302344
Felix Fietkau60540692011-07-19 08:46:44 +02002345 pCap->tx_chainmask = fixup_chainmask(chip_chainmask, pCap->tx_chainmask);
2346 pCap->rx_chainmask = fixup_chainmask(chip_chainmask, pCap->rx_chainmask);
Felix Fietkau82b2d332011-09-03 01:40:23 +02002347 ah->txchainmask = pCap->tx_chainmask;
2348 ah->rxchainmask = pCap->rx_chainmask;
Felix Fietkau60540692011-07-19 08:46:44 +02002349
Felix Fietkau7a370812010-09-22 12:34:52 +02002350 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302351
Felix Fietkau02d2ebb2010-11-22 15:39:39 +01002352 /* enable key search for every frame in an aggregate */
2353 if (AR_SREV_9300_20_OR_LATER(ah))
2354 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
2355
Bruno Randolfce2220d2010-09-17 11:36:25 +09002356 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
2357
Felix Fietkau0db156e2011-03-23 20:57:29 +01002358 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
Sujithf1dc5602008-10-29 10:16:30 +05302359 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2360 else
2361 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2362
Sujith5b5fa352010-03-17 14:25:15 +05302363 if (AR_SREV_9271(ah))
2364 pCap->num_gpio_pins = AR9271_NUM_GPIO;
Sujith88c1f4f2010-06-30 14:46:31 +05302365 else if (AR_DEVID_7010(ah))
2366 pCap->num_gpio_pins = AR7010_NUM_GPIO;
Mohammed Shafi Shajakhan6321eb02011-09-30 11:31:27 +05302367 else if (AR_SREV_9300_20_OR_LATER(ah))
2368 pCap->num_gpio_pins = AR9300_NUM_GPIO;
2369 else if (AR_SREV_9287_11_OR_LATER(ah))
2370 pCap->num_gpio_pins = AR9287_NUM_GPIO;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002371 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302372 pCap->num_gpio_pins = AR9285_NUM_GPIO;
Felix Fietkau7a370812010-09-22 12:34:52 +02002373 else if (AR_SREV_9280_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302374 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2375 else
2376 pCap->num_gpio_pins = AR_NUM_GPIO;
2377
Sujithf1dc5602008-10-29 10:16:30 +05302378 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
2379 pCap->hw_caps |= ATH9K_HW_CAP_CST;
2380 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2381 } else {
2382 pCap->rts_aggr_limit = (8 * 1024);
2383 }
2384
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302385#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302386 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2387 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2388 ah->rfkill_gpio =
2389 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2390 ah->rfkill_polarity =
2391 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302392
2393 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2394 }
2395#endif
Vasanthakumar Thiagarajand5d11542010-05-17 18:57:56 -07002396 if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302397 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2398 else
2399 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302400
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302401 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302402 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2403 else
2404 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2405
Vivek Natarajana6ef5302011-04-26 10:39:53 +05302406 if (common->btcoex_enabled) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +05302407 if (AR_SREV_9462(ah))
2408 btcoex_hw->scheme = ATH_BTCOEX_CFG_MCI;
2409 else if (AR_SREV_9300_20_OR_LATER(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002410 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
Vivek Natarajana6ef5302011-04-26 10:39:53 +05302411 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO_9300;
2412 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO_9300;
2413 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO_9300;
2414 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
2415 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO_9280;
2416 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO_9280;
2417
2418 if (AR_SREV_9285(ah)) {
2419 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
2420 btcoex_hw->btpriority_gpio =
2421 ATH_BTPRIORITY_GPIO_9285;
2422 } else {
2423 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
2424 }
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05302425 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05302426 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002427 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05302428 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002429
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002430 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002431 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
Gabor Juhos0e707a92011-06-21 11:23:31 +02002432 if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah))
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002433 pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
2434
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002435 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2436 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2437 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002438 pCap->tx_desc_len = sizeof(struct ar9003_txc);
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002439 pCap->txs_len = sizeof(struct ar9003_txs);
Luis R. Rodriguez6f481012011-01-20 17:47:39 -08002440 if (!ah->config.paprd_disable &&
2441 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
Felix Fietkau49352502010-06-12 00:33:59 -04002442 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002443 } else {
2444 pCap->tx_desc_len = sizeof(struct ath_desc);
Felix Fietkaua949b172011-07-09 11:12:47 +07002445 if (AR_SREV_9280_20(ah))
Felix Fietkau6b42e8d2010-04-26 15:04:35 -04002446 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002447 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002448
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -04002449 if (AR_SREV_9300_20_OR_LATER(ah))
2450 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2451
Senthil Balasubramanian6ee63f52010-11-10 05:03:16 -08002452 if (AR_SREV_9300_20_OR_LATER(ah))
2453 ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
2454
Felix Fietkaua42acef2010-09-22 12:34:54 +02002455 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
Vasanthakumar Thiagarajan6473d242010-05-13 18:42:38 -07002456 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
2457
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002458 if (AR_SREV_9285(ah))
2459 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
2460 ant_div_ctl1 =
2461 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2462 if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))
2463 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2464 }
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302465 if (AR_SREV_9300_20_OR_LATER(ah)) {
2466 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
2467 pCap->hw_caps |= ATH9K_HW_CAP_APM;
2468 }
2469
2470
Gabor Juhos431da562011-06-21 11:23:41 +02002471 if (AR_SREV_9330(ah) || AR_SREV_9485(ah)) {
Mohammed Shafi Shajakhan21d2c632011-05-13 20:29:31 +05302472 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2473 /*
2474 * enable the diversity-combining algorithm only when
2475 * both enable_lna_div and enable_fast_div are set
2476 * Table for Diversity
2477 * ant_div_alt_lnaconf bit 0-1
2478 * ant_div_main_lnaconf bit 2-3
2479 * ant_div_alt_gaintb bit 4
2480 * ant_div_main_gaintb bit 5
2481 * enable_ant_div_lnadiv bit 6
2482 * enable_ant_fast_div bit 7
2483 */
2484 if ((ant_div_ctl1 >> 0x6) == 0x3)
2485 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2486 }
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002487
Vasanthakumar Thiagarajan8060e162010-12-06 04:27:42 -08002488 if (AR_SREV_9485_10(ah)) {
2489 pCap->pcie_lcr_extsync_en = true;
2490 pCap->pcie_lcr_offset = 0x80;
2491 }
2492
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002493 tx_chainmask = pCap->tx_chainmask;
2494 rx_chainmask = pCap->rx_chainmask;
2495 while (tx_chainmask || rx_chainmask) {
2496 if (tx_chainmask & BIT(0))
2497 pCap->max_txchains++;
2498 if (rx_chainmask & BIT(0))
2499 pCap->max_rxchains++;
2500
2501 tx_chainmask >>= 1;
2502 rx_chainmask >>= 1;
2503 }
2504
Rajkumar Manoharan8ad74c42011-10-13 11:00:38 +05302505 if (AR_SREV_9300_20_OR_LATER(ah)) {
2506 ah->enabled_cals |= TX_IQ_CAL;
Mohammed Shafi Shajakhan6fea5932011-11-30 21:01:31 +05302507 if (AR_SREV_9485_OR_LATER(ah))
Rajkumar Manoharan8ad74c42011-10-13 11:00:38 +05302508 ah->enabled_cals |= TX_IQ_ON_AGC_CAL;
2509 }
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302510 if (AR_SREV_9462(ah))
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +05302511 pCap->hw_caps |= ATH9K_HW_CAP_RTT | ATH9K_HW_CAP_MCI;
Rajkumar Manoharan324c74a2011-10-13 11:00:41 +05302512
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002513 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002514}
2515
Sujithf1dc5602008-10-29 10:16:30 +05302516/****************************/
2517/* GPIO / RFKILL / Antennae */
2518/****************************/
2519
Sujithcbe61d82009-02-09 13:27:12 +05302520static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302521 u32 gpio, u32 type)
2522{
2523 int addr;
2524 u32 gpio_shift, tmp;
2525
2526 if (gpio > 11)
2527 addr = AR_GPIO_OUTPUT_MUX3;
2528 else if (gpio > 5)
2529 addr = AR_GPIO_OUTPUT_MUX2;
2530 else
2531 addr = AR_GPIO_OUTPUT_MUX1;
2532
2533 gpio_shift = (gpio % 6) * 5;
2534
2535 if (AR_SREV_9280_20_OR_LATER(ah)
2536 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2537 REG_RMW(ah, addr, (type << gpio_shift),
2538 (0x1f << gpio_shift));
2539 } else {
2540 tmp = REG_READ(ah, addr);
2541 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2542 tmp &= ~(0x1f << gpio_shift);
2543 tmp |= (type << gpio_shift);
2544 REG_WRITE(ah, addr, tmp);
2545 }
2546}
2547
Sujithcbe61d82009-02-09 13:27:12 +05302548void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302549{
2550 u32 gpio_shift;
2551
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002552 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302553
Sujith88c1f4f2010-06-30 14:46:31 +05302554 if (AR_DEVID_7010(ah)) {
2555 gpio_shift = gpio;
2556 REG_RMW(ah, AR7010_GPIO_OE,
2557 (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
2558 (AR7010_GPIO_OE_MASK << gpio_shift));
2559 return;
2560 }
Sujithf1dc5602008-10-29 10:16:30 +05302561
Sujith88c1f4f2010-06-30 14:46:31 +05302562 gpio_shift = gpio << 1;
Sujithf1dc5602008-10-29 10:16:30 +05302563 REG_RMW(ah,
2564 AR_GPIO_OE_OUT,
2565 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2566 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2567}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002568EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302569
Sujithcbe61d82009-02-09 13:27:12 +05302570u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302571{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302572#define MS_REG_READ(x, y) \
2573 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2574
Sujith2660b812009-02-09 13:27:26 +05302575 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05302576 return 0xffffffff;
2577
Sujith88c1f4f2010-06-30 14:46:31 +05302578 if (AR_DEVID_7010(ah)) {
2579 u32 val;
2580 val = REG_READ(ah, AR7010_GPIO_IN);
2581 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
2582 } else if (AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan93069902010-11-30 23:24:09 -08002583 return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
2584 AR_GPIO_BIT(gpio)) != 0;
Felix Fietkau783dfca2010-04-15 17:38:11 -04002585 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05302586 return MS_REG_READ(AR9271, gpio) != 0;
Felix Fietkaua42acef2010-09-22 12:34:54 +02002587 else if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302588 return MS_REG_READ(AR9287, gpio) != 0;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002589 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302590 return MS_REG_READ(AR9285, gpio) != 0;
Felix Fietkau7a370812010-09-22 12:34:52 +02002591 else if (AR_SREV_9280_20_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302592 return MS_REG_READ(AR928X, gpio) != 0;
2593 else
2594 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05302595}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002596EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05302597
Sujithcbe61d82009-02-09 13:27:12 +05302598void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05302599 u32 ah_signal_type)
2600{
2601 u32 gpio_shift;
2602
Sujith88c1f4f2010-06-30 14:46:31 +05302603 if (AR_DEVID_7010(ah)) {
2604 gpio_shift = gpio;
2605 REG_RMW(ah, AR7010_GPIO_OE,
2606 (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
2607 (AR7010_GPIO_OE_MASK << gpio_shift));
2608 return;
2609 }
2610
Sujithf1dc5602008-10-29 10:16:30 +05302611 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
Sujithf1dc5602008-10-29 10:16:30 +05302612 gpio_shift = 2 * gpio;
Sujithf1dc5602008-10-29 10:16:30 +05302613 REG_RMW(ah,
2614 AR_GPIO_OE_OUT,
2615 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2616 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2617}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002618EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05302619
Sujithcbe61d82009-02-09 13:27:12 +05302620void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05302621{
Sujith88c1f4f2010-06-30 14:46:31 +05302622 if (AR_DEVID_7010(ah)) {
2623 val = val ? 0 : 1;
2624 REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
2625 AR_GPIO_BIT(gpio));
2626 return;
2627 }
2628
Sujith5b5fa352010-03-17 14:25:15 +05302629 if (AR_SREV_9271(ah))
2630 val = ~val;
2631
Sujithf1dc5602008-10-29 10:16:30 +05302632 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2633 AR_GPIO_BIT(gpio));
2634}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002635EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05302636
Sujithcbe61d82009-02-09 13:27:12 +05302637u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302638{
2639 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
2640}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002641EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302642
Sujithcbe61d82009-02-09 13:27:12 +05302643void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05302644{
2645 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2646}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002647EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302648
Sujithf1dc5602008-10-29 10:16:30 +05302649/*********************/
2650/* General Operation */
2651/*********************/
2652
Sujithcbe61d82009-02-09 13:27:12 +05302653u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302654{
2655 u32 bits = REG_READ(ah, AR_RX_FILTER);
2656 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2657
2658 if (phybits & AR_PHY_ERR_RADAR)
2659 bits |= ATH9K_RX_FILTER_PHYRADAR;
2660 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2661 bits |= ATH9K_RX_FILTER_PHYERR;
2662
2663 return bits;
2664}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002665EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302666
Sujithcbe61d82009-02-09 13:27:12 +05302667void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05302668{
2669 u32 phybits;
2670
Sujith7d0d0df2010-04-16 11:53:57 +05302671 ENABLE_REGWRITE_BUFFER(ah);
2672
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302673 if (AR_SREV_9462(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302674 bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
2675
Sujith7ea310b2009-09-03 12:08:43 +05302676 REG_WRITE(ah, AR_RX_FILTER, bits);
2677
Sujithf1dc5602008-10-29 10:16:30 +05302678 phybits = 0;
2679 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2680 phybits |= AR_PHY_ERR_RADAR;
2681 if (bits & ATH9K_RX_FILTER_PHYERR)
2682 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2683 REG_WRITE(ah, AR_PHY_ERR, phybits);
2684
2685 if (phybits)
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002686 REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujithf1dc5602008-10-29 10:16:30 +05302687 else
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002688 REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujith7d0d0df2010-04-16 11:53:57 +05302689
2690 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302691}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002692EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302693
Sujithcbe61d82009-02-09 13:27:12 +05302694bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302695{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302696 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2697 return false;
2698
2699 ath9k_hw_init_pll(ah, NULL);
2700 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302701}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002702EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302703
Sujithcbe61d82009-02-09 13:27:12 +05302704bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302705{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002706 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05302707 return false;
2708
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302709 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2710 return false;
2711
2712 ath9k_hw_init_pll(ah, NULL);
2713 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302714}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002715EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302716
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002717static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05302718{
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002719 enum eeprom_param gain_param;
Felix Fietkau9c204b42011-07-27 15:01:05 +02002720
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002721 if (IS_CHAN_2GHZ(chan))
2722 gain_param = EEP_ANTENNA_GAIN_2G;
2723 else
2724 gain_param = EEP_ANTENNA_GAIN_5G;
Sujithf1dc5602008-10-29 10:16:30 +05302725
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002726 return ah->eep_ops->get_eeprom(ah, gain_param);
2727}
2728
2729void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan)
2730{
2731 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2732 struct ieee80211_channel *channel;
2733 int chan_pwr, new_pwr, max_gain;
2734 int ant_gain, ant_reduction = 0;
2735
2736 if (!chan)
2737 return;
2738
2739 channel = chan->chan;
2740 chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
2741 new_pwr = min_t(int, chan_pwr, reg->power_limit);
2742 max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
2743
2744 ant_gain = get_antenna_gain(ah, chan);
2745 if (ant_gain > max_gain)
2746 ant_reduction = ant_gain - max_gain;
Sujithf1dc5602008-10-29 10:16:30 +05302747
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002748 ah->eep_ops->set_txpower(ah, chan,
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002749 ath9k_regd_get_ctl(reg, chan),
2750 ant_reduction, new_pwr, false);
2751}
2752
2753void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
2754{
2755 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2756 struct ath9k_channel *chan = ah->curchan;
2757 struct ieee80211_channel *channel = chan->chan;
2758
Dan Carpenter48ef5c42011-10-17 10:28:23 +03002759 reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002760 if (test)
2761 channel->max_power = MAX_RATE_POWER / 2;
2762
2763 ath9k_hw_apply_txpower(ah, chan);
2764
2765 if (test)
2766 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
Sujithf1dc5602008-10-29 10:16:30 +05302767}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002768EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05302769
Sujithcbe61d82009-02-09 13:27:12 +05302770void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302771{
Sujith2660b812009-02-09 13:27:26 +05302772 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05302773}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002774EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05302775
Sujithcbe61d82009-02-09 13:27:12 +05302776void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05302777{
2778 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2779 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2780}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002781EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302782
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002783void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302784{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002785 struct ath_common *common = ath9k_hw_common(ah);
2786
2787 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2788 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2789 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05302790}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002791EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05302792
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002793#define ATH9K_MAX_TSF_READ 10
2794
Sujithcbe61d82009-02-09 13:27:12 +05302795u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302796{
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002797 u32 tsf_lower, tsf_upper1, tsf_upper2;
2798 int i;
Sujithf1dc5602008-10-29 10:16:30 +05302799
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002800 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2801 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2802 tsf_lower = REG_READ(ah, AR_TSF_L32);
2803 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2804 if (tsf_upper2 == tsf_upper1)
2805 break;
2806 tsf_upper1 = tsf_upper2;
2807 }
Sujithf1dc5602008-10-29 10:16:30 +05302808
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002809 WARN_ON( i == ATH9K_MAX_TSF_READ );
2810
2811 return (((u64)tsf_upper1 << 32) | tsf_lower);
Sujithf1dc5602008-10-29 10:16:30 +05302812}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002813EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05302814
Sujithcbe61d82009-02-09 13:27:12 +05302815void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002816{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002817 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01002818 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002819}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002820EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002821
Sujithcbe61d82009-02-09 13:27:12 +05302822void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302823{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002824 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2825 AH_TSF_WRITE_TIMEOUT))
Joe Perches226afe62010-12-02 19:12:37 -08002826 ath_dbg(ath9k_hw_common(ah), ATH_DBG_RESET,
2827 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002828
Sujithf1dc5602008-10-29 10:16:30 +05302829 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002830}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002831EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002832
Sujith54e4cec2009-08-07 09:45:09 +05302833void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002834{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002835 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302836 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002837 else
Sujith2660b812009-02-09 13:27:26 +05302838 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002839}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002840EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002841
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002842void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002843{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002844 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05302845 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002846
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002847 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05302848 macmode = AR_2040_JOINED_RX_CLEAR;
2849 else
2850 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002851
Sujithf1dc5602008-10-29 10:16:30 +05302852 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002853}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302854
2855/* HW Generic timers configuration */
2856
2857static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2858{
2859 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2860 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2861 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2862 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2863 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2864 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2865 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2866 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2867 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2868 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2869 AR_NDP2_TIMER_MODE, 0x0002},
2870 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2871 AR_NDP2_TIMER_MODE, 0x0004},
2872 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2873 AR_NDP2_TIMER_MODE, 0x0008},
2874 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2875 AR_NDP2_TIMER_MODE, 0x0010},
2876 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2877 AR_NDP2_TIMER_MODE, 0x0020},
2878 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2879 AR_NDP2_TIMER_MODE, 0x0040},
2880 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2881 AR_NDP2_TIMER_MODE, 0x0080}
2882};
2883
2884/* HW generic timer primitives */
2885
2886/* compute and clear index of rightmost 1 */
2887static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
2888{
2889 u32 b;
2890
2891 b = *mask;
2892 b &= (0-b);
2893 *mask &= ~b;
2894 b *= debruijn32;
2895 b >>= 27;
2896
2897 return timer_table->gen_timer_index[b];
2898}
2899
Felix Fietkaudd347f22011-03-22 21:54:17 +01002900u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302901{
2902 return REG_READ(ah, AR_TSF_L32);
2903}
Felix Fietkaudd347f22011-03-22 21:54:17 +01002904EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302905
2906struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2907 void (*trigger)(void *),
2908 void (*overflow)(void *),
2909 void *arg,
2910 u8 timer_index)
2911{
2912 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2913 struct ath_gen_timer *timer;
2914
2915 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
2916
2917 if (timer == NULL) {
Joe Perches38002762010-12-02 19:12:36 -08002918 ath_err(ath9k_hw_common(ah),
2919 "Failed to allocate memory for hw timer[%d]\n",
2920 timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302921 return NULL;
2922 }
2923
2924 /* allocate a hardware generic timer slot */
2925 timer_table->timers[timer_index] = timer;
2926 timer->index = timer_index;
2927 timer->trigger = trigger;
2928 timer->overflow = overflow;
2929 timer->arg = arg;
2930
2931 return timer;
2932}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002933EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302934
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002935void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2936 struct ath_gen_timer *timer,
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05302937 u32 trig_timeout,
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002938 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302939{
2940 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05302941 u32 tsf, timer_next;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302942
2943 BUG_ON(!timer_period);
2944
2945 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
2946
2947 tsf = ath9k_hw_gettsf32(ah);
2948
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05302949 timer_next = tsf + trig_timeout;
2950
Joe Perches226afe62010-12-02 19:12:37 -08002951 ath_dbg(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
2952 "current tsf %x period %x timer_next %x\n",
2953 tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302954
2955 /*
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302956 * Program generic timer registers
2957 */
2958 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
2959 timer_next);
2960 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
2961 timer_period);
2962 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2963 gen_tmr_configuration[timer->index].mode_mask);
2964
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302965 if (AR_SREV_9462(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302966 /*
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302967 * Starting from AR9462, each generic timer can select which tsf
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302968 * to use. But we still follow the old rule, 0 - 7 use tsf and
2969 * 8 - 15 use tsf2.
2970 */
2971 if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
2972 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2973 (1 << timer->index));
2974 else
2975 REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2976 (1 << timer->index));
2977 }
2978
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302979 /* Enable both trigger and thresh interrupt masks */
2980 REG_SET_BIT(ah, AR_IMR_S5,
2981 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
2982 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302983}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002984EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302985
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002986void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302987{
2988 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2989
2990 if ((timer->index < AR_FIRST_NDP_TIMER) ||
2991 (timer->index >= ATH_MAX_GEN_TIMER)) {
2992 return;
2993 }
2994
2995 /* Clear generic timer enable bits. */
2996 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2997 gen_tmr_configuration[timer->index].mode_mask);
2998
2999 /* Disable both trigger and thresh interrupt masks */
3000 REG_CLR_BIT(ah, AR_IMR_S5,
3001 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3002 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3003
3004 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303005}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003006EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303007
3008void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3009{
3010 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3011
3012 /* free the hardware generic timer slot */
3013 timer_table->timers[timer->index] = NULL;
3014 kfree(timer);
3015}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003016EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303017
3018/*
3019 * Generic Timer Interrupts handling
3020 */
3021void ath_gen_timer_isr(struct ath_hw *ah)
3022{
3023 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3024 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003025 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303026 u32 trigger_mask, thresh_mask, index;
3027
3028 /* get hardware generic timer interrupt status */
3029 trigger_mask = ah->intr_gen_timer_trigger;
3030 thresh_mask = ah->intr_gen_timer_thresh;
3031 trigger_mask &= timer_table->timer_mask.val;
3032 thresh_mask &= timer_table->timer_mask.val;
3033
3034 trigger_mask &= ~thresh_mask;
3035
3036 while (thresh_mask) {
3037 index = rightmost_index(timer_table, &thresh_mask);
3038 timer = timer_table->timers[index];
3039 BUG_ON(!timer);
Joe Perches226afe62010-12-02 19:12:37 -08003040 ath_dbg(common, ATH_DBG_HWTIMER,
3041 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303042 timer->overflow(timer->arg);
3043 }
3044
3045 while (trigger_mask) {
3046 index = rightmost_index(timer_table, &trigger_mask);
3047 timer = timer_table->timers[index];
3048 BUG_ON(!timer);
Joe Perches226afe62010-12-02 19:12:37 -08003049 ath_dbg(common, ATH_DBG_HWTIMER,
3050 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303051 timer->trigger(timer->arg);
3052 }
3053}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003054EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003055
Sujith05020d22010-03-17 14:25:23 +05303056/********/
3057/* HTC */
3058/********/
3059
3060void ath9k_hw_htc_resetinit(struct ath_hw *ah)
3061{
3062 ah->htc_reset_init = true;
3063}
3064EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
3065
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003066static struct {
3067 u32 version;
3068 const char * name;
3069} ath_mac_bb_names[] = {
3070 /* Devices with external radios */
3071 { AR_SREV_VERSION_5416_PCI, "5416" },
3072 { AR_SREV_VERSION_5416_PCIE, "5418" },
3073 { AR_SREV_VERSION_9100, "9100" },
3074 { AR_SREV_VERSION_9160, "9160" },
3075 /* Single-chip solutions */
3076 { AR_SREV_VERSION_9280, "9280" },
3077 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003078 { AR_SREV_VERSION_9287, "9287" },
3079 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguezec839032010-04-15 17:39:20 -04003080 { AR_SREV_VERSION_9300, "9300" },
Gabor Juhos2c8e5932011-06-21 11:23:21 +02003081 { AR_SREV_VERSION_9330, "9330" },
Florian Fainelli397e5d52011-08-25 21:33:48 +02003082 { AR_SREV_VERSION_9340, "9340" },
Senthil Balasubramanian8f06ca22011-04-01 17:16:33 +05303083 { AR_SREV_VERSION_9485, "9485" },
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05303084 { AR_SREV_VERSION_9462, "9462" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003085};
3086
3087/* For devices with external radios */
3088static struct {
3089 u16 version;
3090 const char * name;
3091} ath_rf_names[] = {
3092 { 0, "5133" },
3093 { AR_RAD5133_SREV_MAJOR, "5133" },
3094 { AR_RAD5122_SREV_MAJOR, "5122" },
3095 { AR_RAD2133_SREV_MAJOR, "2133" },
3096 { AR_RAD2122_SREV_MAJOR, "2122" }
3097};
3098
3099/*
3100 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3101 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003102static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003103{
3104 int i;
3105
3106 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3107 if (ath_mac_bb_names[i].version == mac_bb_version) {
3108 return ath_mac_bb_names[i].name;
3109 }
3110 }
3111
3112 return "????";
3113}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003114
3115/*
3116 * Return the RF name. "????" is returned if the RF is unknown.
3117 * Used for devices with external radios.
3118 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003119static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003120{
3121 int i;
3122
3123 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3124 if (ath_rf_names[i].version == rf_version) {
3125 return ath_rf_names[i].name;
3126 }
3127 }
3128
3129 return "????";
3130}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003131
3132void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3133{
3134 int used;
3135
3136 /* chipsets >= AR9280 are single-chip */
Felix Fietkau7a370812010-09-22 12:34:52 +02003137 if (AR_SREV_9280_20_OR_LATER(ah)) {
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003138 used = snprintf(hw_name, len,
3139 "Atheros AR%s Rev:%x",
3140 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3141 ah->hw_version.macRev);
3142 }
3143 else {
3144 used = snprintf(hw_name, len,
3145 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3146 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3147 ah->hw_version.macRev,
3148 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3149 AR_RADIO_SREV_MAJOR)),
3150 ah->hw_version.phyRev);
3151 }
3152
3153 hw_name[used] = '\0';
3154}
3155EXPORT_SYMBOL(ath9k_hw_name);