blob: 8c840cad3ac29d540717db15eb6b154c20da98cb [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"
Sujith Manoharanf4701b52012-02-22 12:41:18 +053026#include "ar9003_mci.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027
Sujithcbe61d82009-02-09 13:27:12 +053028static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070029
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040030MODULE_AUTHOR("Atheros Communications");
31MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
32MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
33MODULE_LICENSE("Dual BSD/GPL");
34
35static int __init ath9k_init(void)
36{
37 return 0;
38}
39module_init(ath9k_init);
40
41static void __exit ath9k_exit(void)
42{
43 return;
44}
45module_exit(ath9k_exit);
46
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040047/* Private hardware callbacks */
48
49static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
50{
51 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
52}
53
54static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
55{
56 ath9k_hw_private_ops(ah)->init_mode_regs(ah);
57}
58
Luis R. Rodriguez64773962010-04-15 17:38:17 -040059static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
60 struct ath9k_channel *chan)
61{
62 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
63}
64
Luis R. Rodriguez991312d2010-04-15 17:39:05 -040065static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
66{
67 if (!ath9k_hw_private_ops(ah)->init_mode_gain_regs)
68 return;
69
70 ath9k_hw_private_ops(ah)->init_mode_gain_regs(ah);
71}
72
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -040073static void ath9k_hw_ani_cache_ini_regs(struct ath_hw *ah)
74{
75 /* You will not have this callback if using the old ANI */
76 if (!ath9k_hw_private_ops(ah)->ani_cache_ini_regs)
77 return;
78
79 ath9k_hw_private_ops(ah)->ani_cache_ini_regs(ah);
80}
81
Sujithf1dc5602008-10-29 10:16:30 +053082/********************/
83/* Helper Functions */
84/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070085
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020086static void ath9k_hw_set_clockrate(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +053087{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070088 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020089 struct ath_common *common = ath9k_hw_common(ah);
90 unsigned int clockrate;
Sujithcbe61d82009-02-09 13:27:12 +053091
Felix Fietkau087b6ff2011-07-09 11:12:49 +070092 /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
93 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
94 clockrate = 117;
95 else if (!ah->curchan) /* should really check for CCK instead */
Felix Fietkaudfdac8a2010-10-08 22:13:51 +020096 clockrate = ATH9K_CLOCK_RATE_CCK;
97 else if (conf->channel->band == IEEE80211_BAND_2GHZ)
98 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
99 else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
100 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
Vasanthakumar Thiagarajane5553722010-04-26 15:04:33 -0400101 else
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200102 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
103
104 if (conf_is_ht40(conf))
105 clockrate *= 2;
106
Felix Fietkau906c7202011-07-09 11:12:48 +0700107 if (ah->curchan) {
108 if (IS_CHAN_HALF_RATE(ah->curchan))
109 clockrate /= 2;
110 if (IS_CHAN_QUARTER_RATE(ah->curchan))
111 clockrate /= 4;
112 }
113
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200114 common->clockrate = clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530115}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700116
Sujithcbe61d82009-02-09 13:27:12 +0530117static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +0530118{
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200119 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +0530120
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200121 return usecs * common->clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530122}
123
Sujith0caa7b12009-02-16 13:23:20 +0530124bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700125{
126 int i;
127
Sujith0caa7b12009-02-16 13:23:20 +0530128 BUG_ON(timeout < AH_TIME_QUANTUM);
129
130 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700131 if ((REG_READ(ah, reg) & mask) == val)
132 return true;
133
134 udelay(AH_TIME_QUANTUM);
135 }
Sujith04bd46382008-11-28 22:18:05 +0530136
Joe Perchesd2182b62011-12-15 14:55:53 -0800137 ath_dbg(ath9k_hw_common(ah), ANY,
Joe Perches226afe62010-12-02 19:12:37 -0800138 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
139 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530140
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700141 return false;
142}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400143EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700144
Felix Fietkaua9b6b252011-03-23 20:57:27 +0100145void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
146 int column, unsigned int *writecnt)
147{
148 int r;
149
150 ENABLE_REGWRITE_BUFFER(ah);
151 for (r = 0; r < array->ia_rows; r++) {
152 REG_WRITE(ah, INI_RA(array, r, 0),
153 INI_RA(array, r, column));
154 DO_DELAY(*writecnt);
155 }
156 REGWRITE_BUFFER_FLUSH(ah);
157}
158
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700159u32 ath9k_hw_reverse_bits(u32 val, u32 n)
160{
161 u32 retval;
162 int i;
163
164 for (i = 0, retval = 0; i < n; i++) {
165 retval = (retval << 1) | (val & 1);
166 val >>= 1;
167 }
168 return retval;
169}
170
Sujithcbe61d82009-02-09 13:27:12 +0530171u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100172 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530173 u32 frameLen, u16 rateix,
174 bool shortPreamble)
175{
176 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530177
178 if (kbps == 0)
179 return 0;
180
Felix Fietkau545750d2009-11-23 22:21:01 +0100181 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530182 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530183 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100184 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530185 phyTime >>= 1;
186 numBits = frameLen << 3;
187 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
188 break;
Sujith46d14a52008-11-18 09:08:13 +0530189 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530190 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530191 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
192 numBits = OFDM_PLCP_BITS + (frameLen << 3);
193 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
194 txTime = OFDM_SIFS_TIME_QUARTER
195 + OFDM_PREAMBLE_TIME_QUARTER
196 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530197 } else if (ah->curchan &&
198 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530199 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
200 numBits = OFDM_PLCP_BITS + (frameLen << 3);
201 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
202 txTime = OFDM_SIFS_TIME_HALF +
203 OFDM_PREAMBLE_TIME_HALF
204 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
205 } else {
206 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
207 numBits = OFDM_PLCP_BITS + (frameLen << 3);
208 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
209 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
210 + (numSymbols * OFDM_SYMBOL_TIME);
211 }
212 break;
213 default:
Joe Perches38002762010-12-02 19:12:36 -0800214 ath_err(ath9k_hw_common(ah),
215 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530216 txTime = 0;
217 break;
218 }
219
220 return txTime;
221}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400222EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530223
Sujithcbe61d82009-02-09 13:27:12 +0530224void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530225 struct ath9k_channel *chan,
226 struct chan_centers *centers)
227{
228 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530229
230 if (!IS_CHAN_HT40(chan)) {
231 centers->ctl_center = centers->ext_center =
232 centers->synth_center = chan->channel;
233 return;
234 }
235
236 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
237 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
238 centers->synth_center =
239 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
240 extoff = 1;
241 } else {
242 centers->synth_center =
243 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
244 extoff = -1;
245 }
246
247 centers->ctl_center =
248 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700249 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530250 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700251 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530252}
253
254/******************/
255/* Chip Revisions */
256/******************/
257
Sujithcbe61d82009-02-09 13:27:12 +0530258static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530259{
260 u32 val;
261
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530262 switch (ah->hw_version.devid) {
263 case AR5416_AR9100_DEVID:
264 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
265 break;
Gabor Juhos37625612011-06-21 11:23:23 +0200266 case AR9300_DEVID_AR9330:
267 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
268 if (ah->get_mac_revision) {
269 ah->hw_version.macRev = ah->get_mac_revision();
270 } else {
271 val = REG_READ(ah, AR_SREV);
272 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
273 }
274 return;
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530275 case AR9300_DEVID_AR9340:
276 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
277 val = REG_READ(ah, AR_SREV);
278 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
279 return;
280 }
281
Sujithf1dc5602008-10-29 10:16:30 +0530282 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
283
284 if (val == 0xFF) {
285 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530286 ah->hw_version.macVersion =
287 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
288 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530289
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530290 if (AR_SREV_9462(ah))
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530291 ah->is_pciexpress = true;
292 else
293 ah->is_pciexpress = (val &
294 AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530295 } else {
296 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530297 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530298
Sujithd535a422009-02-09 13:27:06 +0530299 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530300
Sujithd535a422009-02-09 13:27:06 +0530301 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530302 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530303 }
304}
305
Sujithf1dc5602008-10-29 10:16:30 +0530306/************************************/
307/* HW Attach, Detach, Init Routines */
308/************************************/
309
Sujithcbe61d82009-02-09 13:27:12 +0530310static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530311{
Felix Fietkau040b74f2010-12-12 00:51:07 +0100312 if (!AR_SREV_5416(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530313 return;
314
315 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
316 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
317 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
318 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
319 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
320 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
321 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
322 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
323 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
324
325 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
326}
327
Stanislaw Gruszkad4930082011-07-29 15:59:08 +0200328static void ath9k_hw_aspm_init(struct ath_hw *ah)
329{
330 struct ath_common *common = ath9k_hw_common(ah);
331
332 if (common->bus_ops->aspm_init)
333 common->bus_ops->aspm_init(common);
334}
335
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400336/* This should work for all families including legacy */
Sujithcbe61d82009-02-09 13:27:12 +0530337static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530338{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700339 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400340 u32 regAddr[2] = { AR_STA_ID0 };
Sujithf1dc5602008-10-29 10:16:30 +0530341 u32 regHold[2];
Joe Perches07b2fa52010-11-20 18:38:53 -0800342 static const u32 patternData[4] = {
343 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
344 };
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400345 int i, j, loop_max;
Sujithf1dc5602008-10-29 10:16:30 +0530346
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400347 if (!AR_SREV_9300_20_OR_LATER(ah)) {
348 loop_max = 2;
349 regAddr[1] = AR_PHY_BASE + (8 << 2);
350 } else
351 loop_max = 1;
352
353 for (i = 0; i < loop_max; i++) {
Sujithf1dc5602008-10-29 10:16:30 +0530354 u32 addr = regAddr[i];
355 u32 wrData, rdData;
356
357 regHold[i] = REG_READ(ah, addr);
358 for (j = 0; j < 0x100; j++) {
359 wrData = (j << 16) | j;
360 REG_WRITE(ah, addr, wrData);
361 rdData = REG_READ(ah, addr);
362 if (rdData != wrData) {
Joe Perches38002762010-12-02 19:12:36 -0800363 ath_err(common,
364 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
365 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530366 return false;
367 }
368 }
369 for (j = 0; j < 4; j++) {
370 wrData = patternData[j];
371 REG_WRITE(ah, addr, wrData);
372 rdData = REG_READ(ah, addr);
373 if (wrData != rdData) {
Joe Perches38002762010-12-02 19:12:36 -0800374 ath_err(common,
375 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
376 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530377 return false;
378 }
379 }
380 REG_WRITE(ah, regAddr[i], regHold[i]);
381 }
382 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530383
Sujithf1dc5602008-10-29 10:16:30 +0530384 return true;
385}
386
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700387static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700388{
389 int i;
390
Sujith2660b812009-02-09 13:27:26 +0530391 ah->config.dma_beacon_response_time = 2;
392 ah->config.sw_beacon_response_time = 10;
393 ah->config.additional_swba_backoff = 0;
394 ah->config.ack_6mb = 0x0;
395 ah->config.cwm_ignore_extcca = 0;
Sujith2660b812009-02-09 13:27:26 +0530396 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530397 ah->config.pcie_waen = 0;
398 ah->config.analog_shiftreg = 1;
Luis R. Rodriguez03c72512010-06-12 00:33:46 -0400399 ah->config.enable_ani = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700400
401 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530402 ah->config.spurchans[i][0] = AR_NO_SPUR;
403 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700404 }
405
Luis R. Rodriguez6f481012011-01-20 17:47:39 -0800406 /* PAPRD needs some more work to be enabled */
407 ah->config.paprd_disable = 1;
408
Sujith0ce024c2009-12-14 14:57:00 +0530409 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez6a0ec302010-06-21 18:38:49 -0400410 ah->config.pcieSerDesWrite = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400411
412 /*
413 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
414 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
415 * This means we use it for all AR5416 devices, and the few
416 * minor PCI AR9280 devices out there.
417 *
418 * Serialization is required because these devices do not handle
419 * well the case of two concurrent reads/writes due to the latency
420 * involved. During one read/write another read/write can be issued
421 * on another CPU while the previous read/write may still be working
422 * on our hardware, if we hit this case the hardware poops in a loop.
423 * We prevent this by serializing reads and writes.
424 *
425 * This issue is not present on PCI-Express devices or pre-AR5416
426 * devices (legacy, 802.11abg).
427 */
428 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700429 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700430}
431
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700432static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700433{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700434 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
435
436 regulatory->country_code = CTRY_DEFAULT;
437 regulatory->power_limit = MAX_RATE_POWER;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700438
Sujithd535a422009-02-09 13:27:06 +0530439 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530440 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700441
Sujith2660b812009-02-09 13:27:26 +0530442 ah->atim_window = 0;
Felix Fietkau16f24112010-06-12 17:22:32 +0200443 ah->sta_id1_defaults =
444 AR_STA_ID1_CRPT_MIC_ENABLE |
445 AR_STA_ID1_MCAST_KSRCH;
Felix Fietkauf1717602011-03-19 13:55:41 +0100446 if (AR_SREV_9100(ah))
447 ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
Sujith2660b812009-02-09 13:27:26 +0530448 ah->enable_32kHz_clock = DONT_USE_32KHZ;
Rajkumar Manoharane3f2acc2011-08-27 11:22:59 +0530449 ah->slottime = ATH9K_SLOT_TIME_9;
Sujith2660b812009-02-09 13:27:26 +0530450 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200451 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700452}
453
Sujithcbe61d82009-02-09 13:27:12 +0530454static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700455{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700456 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530457 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530459 u16 eeval;
Joe Perches07b2fa52010-11-20 18:38:53 -0800460 static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700461
Sujithf1dc5602008-10-29 10:16:30 +0530462 sum = 0;
463 for (i = 0; i < 3; i++) {
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400464 eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530465 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700466 common->macaddr[2 * i] = eeval >> 8;
467 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700468 }
Sujithd8baa932009-03-30 15:28:25 +0530469 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530470 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700471
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700472 return 0;
473}
474
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700475static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700476{
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530477 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700478 int ecode;
479
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530480 if (common->bus_ops->ath_bus_type != ATH_USB) {
Sujith527d4852010-03-17 14:25:16 +0530481 if (!ath9k_hw_chip_test(ah))
482 return -ENODEV;
483 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700484
Luis R. Rodriguezebd5a142010-04-15 17:39:18 -0400485 if (!AR_SREV_9300_20_OR_LATER(ah)) {
486 ecode = ar9002_hw_rf_claim(ah);
487 if (ecode != 0)
488 return ecode;
489 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700490
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700491 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700492 if (ecode != 0)
493 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530494
Joe Perchesd2182b62011-12-15 14:55:53 -0800495 ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n",
Joe Perches226afe62010-12-02 19:12:37 -0800496 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 Perchesd2182b62011-12-15 14:55:53 -0800570 ath_dbg(common, 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 Martynov4f17c482011-12-06 21:57:17 -0500613 /* disable ANI for 9340 */
614 if (AR_SREV_9340(ah))
Nikolay Martynov42794252011-12-02 22:39:16 -0500615 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 Perchesd2182b62011-12-15 14:55:53 -0800961 ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n",
962 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 Perchesd2182b62011-12-15 14:55:53 -0800983 ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n",
Joe Perches226afe62010-12-02 19:12:37 -0800984 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
Felix Fietkau55a2bb42012-02-05 21:15:18 +01001041 * initval's 64us ack timeout value. Use 48us for the CTS timeout.
Felix Fietkau42c45682010-02-11 18:07:19 +01001042 * 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 */
Felix Fietkau55a2bb42012-02-05 21:15:18 +01001046 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ) {
Felix Fietkau42c45682010-02-11 18:07:19 +01001047 acktimeout += 64 - sifstime - ah->slottime;
Felix Fietkau55a2bb42012-02-05 21:15:18 +01001048 ctstimeout += 48 - sifstime - ah->slottime;
1049 }
1050
Felix Fietkau42c45682010-02-11 18:07:19 +01001051
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001052 ath9k_hw_set_sifs_time(ah, sifstime);
1053 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001054 ath9k_hw_set_ack_timeout(ah, acktimeout);
Felix Fietkauadb50662011-08-28 01:52:10 +02001055 ath9k_hw_set_cts_timeout(ah, ctstimeout);
Sujith2660b812009-02-09 13:27:26 +05301056 if (ah->globaltxtimeout != (u32) -1)
1057 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001058
1059 REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
1060 REG_RMW(ah, AR_USEC,
1061 (common->clockrate - 1) |
1062 SM(rx_lat, AR_USEC_RX_LAT) |
1063 SM(tx_lat, AR_USEC_TX_LAT),
1064 AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
1065
Sujithf1dc5602008-10-29 10:16:30 +05301066}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001067EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301068
Sujith285f2dd2010-01-08 10:36:07 +05301069void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001070{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001071 struct ath_common *common = ath9k_hw_common(ah);
1072
Sujith736b3a22010-03-17 14:25:24 +05301073 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001074 goto free_hw;
1075
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001076 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001077
1078free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001079 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001080}
Sujith285f2dd2010-01-08 10:36:07 +05301081EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001082
Sujithf1dc5602008-10-29 10:16:30 +05301083/*******/
1084/* INI */
1085/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001086
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001087u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001088{
1089 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1090
1091 if (IS_CHAN_B(chan))
1092 ctl |= CTL_11B;
1093 else if (IS_CHAN_G(chan))
1094 ctl |= CTL_11G;
1095 else
1096 ctl |= CTL_11A;
1097
1098 return ctl;
1099}
1100
Sujithf1dc5602008-10-29 10:16:30 +05301101/****************************************/
1102/* Reset and Channel Switching Routines */
1103/****************************************/
1104
Sujithcbe61d82009-02-09 13:27:12 +05301105static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301106{
Felix Fietkau57b32222010-04-15 17:39:22 -04001107 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301108
Sujith7d0d0df2010-04-16 11:53:57 +05301109 ENABLE_REGWRITE_BUFFER(ah);
1110
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001111 /*
1112 * set AHB_MODE not to do cacheline prefetches
1113 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001114 if (!AR_SREV_9300_20_OR_LATER(ah))
1115 REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301116
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001117 /*
1118 * let mac dma reads be in 128 byte chunks
1119 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001120 REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301121
Sujith7d0d0df2010-04-16 11:53:57 +05301122 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301123
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001124 /*
1125 * Restore TX Trigger Level to its pre-reset value.
1126 * The initial value depends on whether aggregation is enabled, and is
1127 * adjusted whenever underruns are detected.
1128 */
Felix Fietkau57b32222010-04-15 17:39:22 -04001129 if (!AR_SREV_9300_20_OR_LATER(ah))
1130 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301131
Sujith7d0d0df2010-04-16 11:53:57 +05301132 ENABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301133
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001134 /*
1135 * let mac dma writes be in 128 byte chunks
1136 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001137 REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301138
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001139 /*
1140 * Setup receive FIFO threshold to hold off TX activities
1141 */
Sujithf1dc5602008-10-29 10:16:30 +05301142 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1143
Felix Fietkau57b32222010-04-15 17:39:22 -04001144 if (AR_SREV_9300_20_OR_LATER(ah)) {
1145 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
1146 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
1147
1148 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
1149 ah->caps.rx_status_len);
1150 }
1151
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001152 /*
1153 * reduce the number of usable entries in PCU TXBUF to avoid
1154 * wrap around issues.
1155 */
Sujithf1dc5602008-10-29 10:16:30 +05301156 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001157 /* For AR9285 the number of Fifos are reduced to half.
1158 * So set the usable tx buf size also to half to
1159 * avoid data/delimiter underruns
1160 */
Sujithf1dc5602008-10-29 10:16:30 +05301161 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1162 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001163 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301164 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1165 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1166 }
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001167
Sujith7d0d0df2010-04-16 11:53:57 +05301168 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301169
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001170 if (AR_SREV_9300_20_OR_LATER(ah))
1171 ath9k_hw_reset_txstatus_ring(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301172}
1173
Sujithcbe61d82009-02-09 13:27:12 +05301174static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301175{
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001176 u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
1177 u32 set = AR_STA_ID1_KSRCH_MODE;
Sujithf1dc5602008-10-29 10:16:30 +05301178
Sujithf1dc5602008-10-29 10:16:30 +05301179 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001180 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001181 case NL80211_IFTYPE_MESH_POINT:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001182 set |= AR_STA_ID1_ADHOC;
Sujithf1dc5602008-10-29 10:16:30 +05301183 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1184 break;
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001185 case NL80211_IFTYPE_AP:
1186 set |= AR_STA_ID1_STA_AP;
1187 /* fall through */
Colin McCabed97809d2008-12-01 13:38:55 -08001188 case NL80211_IFTYPE_STATION:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001189 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
Sujithf1dc5602008-10-29 10:16:30 +05301190 break;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301191 default:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001192 if (!ah->is_monitoring)
1193 set = 0;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301194 break;
Sujithf1dc5602008-10-29 10:16:30 +05301195 }
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001196 REG_RMW(ah, AR_STA_ID1, set, mask);
Sujithf1dc5602008-10-29 10:16:30 +05301197}
1198
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001199void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1200 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001201{
1202 u32 coef_exp, coef_man;
1203
1204 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1205 if ((coef_scaled >> coef_exp) & 0x1)
1206 break;
1207
1208 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1209
1210 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1211
1212 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1213 *coef_exponent = coef_exp - 16;
1214}
1215
Sujithcbe61d82009-02-09 13:27:12 +05301216static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301217{
1218 u32 rst_flags;
1219 u32 tmpReg;
1220
Sujith70768492009-02-16 13:23:12 +05301221 if (AR_SREV_9100(ah)) {
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001222 REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
1223 AR_RTC_DERIVED_CLK_PERIOD, 1);
Sujith70768492009-02-16 13:23:12 +05301224 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1225 }
1226
Sujith7d0d0df2010-04-16 11:53:57 +05301227 ENABLE_REGWRITE_BUFFER(ah);
1228
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001229 if (AR_SREV_9300_20_OR_LATER(ah)) {
1230 REG_WRITE(ah, AR_WA, ah->WARegVal);
1231 udelay(10);
1232 }
1233
Sujithf1dc5602008-10-29 10:16:30 +05301234 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1235 AR_RTC_FORCE_WAKE_ON_INT);
1236
1237 if (AR_SREV_9100(ah)) {
1238 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1239 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1240 } else {
1241 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1242 if (tmpReg &
1243 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1244 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001245 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301246 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001247
1248 val = AR_RC_HOSTIF;
1249 if (!AR_SREV_9300_20_OR_LATER(ah))
1250 val |= AR_RC_AHB;
1251 REG_WRITE(ah, AR_RC, val);
1252
1253 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301254 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301255
1256 rst_flags = AR_RTC_RC_MAC_WARM;
1257 if (type == ATH9K_RESET_COLD)
1258 rst_flags |= AR_RTC_RC_MAC_COLD;
1259 }
1260
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001261 if (AR_SREV_9330(ah)) {
1262 int npend = 0;
1263 int i;
1264
1265 /* AR9330 WAR:
1266 * call external reset function to reset WMAC if:
1267 * - doing a cold reset
1268 * - we have pending frames in the TX queues
1269 */
1270
1271 for (i = 0; i < AR_NUM_QCU; i++) {
1272 npend = ath9k_hw_numtxpending(ah, i);
1273 if (npend)
1274 break;
1275 }
1276
1277 if (ah->external_reset &&
1278 (npend || type == ATH9K_RESET_COLD)) {
1279 int reset_err = 0;
1280
Joe Perchesd2182b62011-12-15 14:55:53 -08001281 ath_dbg(ath9k_hw_common(ah), RESET,
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001282 "reset MAC via external reset\n");
1283
1284 reset_err = ah->external_reset();
1285 if (reset_err) {
1286 ath_err(ath9k_hw_common(ah),
1287 "External reset failed, err=%d\n",
1288 reset_err);
1289 return false;
1290 }
1291
1292 REG_WRITE(ah, AR_RTC_RESET, 1);
1293 }
1294 }
1295
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001296 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujith7d0d0df2010-04-16 11:53:57 +05301297
1298 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301299
Sujithf1dc5602008-10-29 10:16:30 +05301300 udelay(50);
1301
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001302 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301303 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001304 ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301305 return false;
1306 }
1307
1308 if (!AR_SREV_9100(ah))
1309 REG_WRITE(ah, AR_RC, 0);
1310
Sujithf1dc5602008-10-29 10:16:30 +05301311 if (AR_SREV_9100(ah))
1312 udelay(50);
1313
1314 return true;
1315}
1316
Sujithcbe61d82009-02-09 13:27:12 +05301317static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301318{
Sujith7d0d0df2010-04-16 11:53:57 +05301319 ENABLE_REGWRITE_BUFFER(ah);
1320
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001321 if (AR_SREV_9300_20_OR_LATER(ah)) {
1322 REG_WRITE(ah, AR_WA, ah->WARegVal);
1323 udelay(10);
1324 }
1325
Sujithf1dc5602008-10-29 10:16:30 +05301326 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1327 AR_RTC_FORCE_WAKE_ON_INT);
1328
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001329 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301330 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1331
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001332 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301333
Sujith7d0d0df2010-04-16 11:53:57 +05301334 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301335
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001336 if (!AR_SREV_9300_20_OR_LATER(ah))
1337 udelay(2);
1338
1339 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301340 REG_WRITE(ah, AR_RC, 0);
1341
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001342 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301343
1344 if (!ath9k_hw_wait(ah,
1345 AR_RTC_STATUS,
1346 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301347 AR_RTC_STATUS_ON,
1348 AH_WAIT_TIMEOUT)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001349 ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301350 return false;
1351 }
1352
Sujithf1dc5602008-10-29 10:16:30 +05301353 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1354}
1355
Sujithcbe61d82009-02-09 13:27:12 +05301356static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301357{
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301358 bool ret = false;
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301359
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001360 if (AR_SREV_9300_20_OR_LATER(ah)) {
1361 REG_WRITE(ah, AR_WA, ah->WARegVal);
1362 udelay(10);
1363 }
1364
Sujithf1dc5602008-10-29 10:16:30 +05301365 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1366 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1367
1368 switch (type) {
1369 case ATH9K_RESET_POWER_ON:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301370 ret = ath9k_hw_set_reset_power_on(ah);
1371 break;
Sujithf1dc5602008-10-29 10:16:30 +05301372 case ATH9K_RESET_WARM:
1373 case ATH9K_RESET_COLD:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301374 ret = ath9k_hw_set_reset(ah, type);
1375 break;
Sujithf1dc5602008-10-29 10:16:30 +05301376 default:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301377 break;
Sujithf1dc5602008-10-29 10:16:30 +05301378 }
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301379
1380 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
1381 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
1382
1383 return ret;
Sujithf1dc5602008-10-29 10:16:30 +05301384}
1385
Sujithcbe61d82009-02-09 13:27:12 +05301386static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301387 struct ath9k_channel *chan)
1388{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301389 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301390 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1391 return false;
1392 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301393 return false;
1394
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001395 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301396 return false;
1397
Sujith2660b812009-02-09 13:27:26 +05301398 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301399 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301400 ath9k_hw_set_rfmode(ah, chan);
1401
1402 return true;
1403}
1404
Sujithcbe61d82009-02-09 13:27:12 +05301405static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001406 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301407{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001408 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001409 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001410 int r;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301411 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1412 bool band_switch, mode_diff;
1413 u8 ini_reloaded;
1414
1415 band_switch = (chan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ)) !=
1416 (ah->curchan->channelFlags & (CHANNEL_2GHZ |
1417 CHANNEL_5GHZ));
1418 mode_diff = (chan->chanmode != ah->curchan->chanmode);
Sujithf1dc5602008-10-29 10:16:30 +05301419
1420 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1421 if (ath9k_hw_numtxpending(ah, qnum)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001422 ath_dbg(common, QUEUE,
Joe Perches226afe62010-12-02 19:12:37 -08001423 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301424 return false;
1425 }
1426 }
1427
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001428 if (!ath9k_hw_rfbus_req(ah)) {
Joe Perches38002762010-12-02 19:12:36 -08001429 ath_err(common, "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301430 return false;
1431 }
1432
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301433 if (edma && (band_switch || mode_diff)) {
1434 ath9k_hw_mark_phy_inactive(ah);
1435 udelay(5);
1436
1437 ath9k_hw_init_pll(ah, NULL);
1438
1439 if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
1440 ath_err(common, "Failed to do fast channel change\n");
1441 return false;
1442 }
1443 }
1444
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001445 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301446
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001447 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001448 if (r) {
Joe Perches38002762010-12-02 19:12:36 -08001449 ath_err(common, "Failed to set channel\n");
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001450 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301451 }
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001452 ath9k_hw_set_clockrate(ah);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02001453 ath9k_hw_apply_txpower(ah, chan);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001454 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301455
1456 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1457 ath9k_hw_set_delta_slope(ah, chan);
1458
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001459 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301460
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301461 if (edma && (band_switch || mode_diff)) {
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301462 ah->ah_flags |= AH_FASTCC;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301463 if (band_switch || ini_reloaded)
1464 ah->eep_ops->set_board_values(ah, chan);
1465
1466 ath9k_hw_init_bb(ah, chan);
1467
1468 if (band_switch || ini_reloaded)
1469 ath9k_hw_init_cal(ah, chan);
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301470 ah->ah_flags &= ~AH_FASTCC;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301471 }
1472
Sujithf1dc5602008-10-29 10:16:30 +05301473 return true;
1474}
1475
Felix Fietkau691680b2011-03-19 13:55:38 +01001476static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
1477{
1478 u32 gpio_mask = ah->gpio_mask;
1479 int i;
1480
1481 for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
1482 if (!(gpio_mask & 1))
1483 continue;
1484
1485 ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1486 ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
1487 }
1488}
1489
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001490bool ath9k_hw_check_alive(struct ath_hw *ah)
Johannes Berg3b319aa2009-06-13 14:50:26 +05301491{
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001492 int count = 50;
1493 u32 reg;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301494
Felix Fietkaue17f83e2010-09-22 12:34:53 +02001495 if (AR_SREV_9285_12_OR_LATER(ah))
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001496 return true;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301497
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001498 do {
1499 reg = REG_READ(ah, AR_OBS_BUS_1);
1500
1501 if ((reg & 0x7E7FFFEF) == 0x00702400)
1502 continue;
1503
1504 switch (reg & 0x7E000B00) {
1505 case 0x1E000000:
1506 case 0x52000B00:
1507 case 0x18000B00:
1508 continue;
1509 default:
1510 return true;
1511 }
1512 } while (count-- > 0);
1513
1514 return false;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301515}
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001516EXPORT_SYMBOL(ath9k_hw_check_alive);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301517
Sujithcbe61d82009-02-09 13:27:12 +05301518int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001519 struct ath9k_hw_cal_data *caldata, bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001520{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001521 struct ath_common *common = ath9k_hw_common(ah);
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;
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301528 bool allow_fbs = false, start_mci_reset = 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) {
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301533 start_mci_reset = ar9003_mci_start_reset(ah, chan);
1534 if (start_mci_reset)
1535 return 0;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301536 }
1537
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001538 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001539 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001540
Felix Fietkaud9891c72010-09-29 17:15:27 +02001541 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001542 ath9k_hw_getnf(ah, curchan);
1543
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001544 ah->caldata = caldata;
1545 if (caldata &&
1546 (chan->channel != caldata->channel ||
1547 (chan->channelFlags & ~CHANNEL_CW_INT) !=
1548 (caldata->channelFlags & ~CHANNEL_CW_INT))) {
1549 /* Operating channel changed, reset channel calibration data */
1550 memset(caldata, 0, sizeof(*caldata));
1551 ath9k_init_nfcal_hist_buffer(ah, chan);
1552 }
Felix Fietkauf23fba42011-07-28 14:08:56 +02001553 ah->noise = ath9k_hw_getchan_noise(ah, chan);
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001554
Rajkumar Manoharan19787b22011-10-13 11:00:39 +05301555 if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
Rajkumar Manoharan7db062a2011-09-14 14:20:30 +05301556 bChannelChange = false;
1557
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301558 if (caldata &&
1559 caldata->done_txiqcal_once &&
1560 caldata->done_txclcal_once &&
1561 caldata->rtt_hist.num_readings)
1562 allow_fbs = true;
1563
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001564 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301565 (ah->chip_fullsleep != true) &&
1566 (ah->curchan != NULL) &&
1567 (chan->channel != ah->curchan->channel) &&
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301568 (allow_fbs ||
1569 ((chan->channelFlags & CHANNEL_ALL) ==
1570 (ah->curchan->channelFlags & CHANNEL_ALL)))) {
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001571 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301572 ath9k_hw_loadnf(ah, ah->curchan);
Felix Fietkau00c86592010-07-30 21:02:09 +02001573 ath9k_hw_start_nfcal(ah, true);
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301574 if (mci && ar9003_mci_is_ready(ah))
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301575 ar9003_mci_2g5g_switch(ah, true);
1576
Rajkumar Manoharanc2ba33422010-09-03 16:00:00 +05301577 if (AR_SREV_9271(ah))
1578 ar9002_hw_load_ani_reg(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001579 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001580 }
1581 }
1582
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301583 if (mci)
1584 ar9003_mci_stop_bt(ah, save_fullsleep);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301585
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001586 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1587 if (saveDefAntenna == 0)
1588 saveDefAntenna = 1;
1589
1590 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1591
Sujith46fe7822009-09-17 09:25:25 +05301592 /* For chips on which RTC reset is done, save TSF before it gets cleared */
Felix Fietkauf860d522010-06-30 02:07:48 +02001593 if (AR_SREV_9100(ah) ||
1594 (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)))
Sujith46fe7822009-09-17 09:25:25 +05301595 tsf = ath9k_hw_gettsf64(ah);
1596
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001597 saveLedState = REG_READ(ah, AR_CFG_LED) &
1598 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1599 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1600
1601 ath9k_hw_mark_phy_inactive(ah);
1602
Vasanthakumar Thiagarajan45ef6a02010-12-15 07:30:53 -08001603 ah->paprd_table_write_done = false;
1604
Sujith05020d22010-03-17 14:25:23 +05301605 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001606 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1607 REG_WRITE(ah,
1608 AR9271_RESET_POWER_DOWN_CONTROL,
1609 AR9271_RADIO_RF_RST);
1610 udelay(50);
1611 }
1612
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001613 if (!ath9k_hw_chip_reset(ah, chan)) {
Joe Perches38002762010-12-02 19:12:36 -08001614 ath_err(common, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001615 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001616 }
1617
Sujith05020d22010-03-17 14:25:23 +05301618 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001619 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1620 ah->htc_reset_init = false;
1621 REG_WRITE(ah,
1622 AR9271_RESET_POWER_DOWN_CONTROL,
1623 AR9271_GATE_MAC_CTL);
1624 udelay(50);
1625 }
1626
Sujith46fe7822009-09-17 09:25:25 +05301627 /* Restore TSF */
Felix Fietkauf860d522010-06-30 02:07:48 +02001628 if (tsf)
Sujith46fe7822009-09-17 09:25:25 +05301629 ath9k_hw_settsf64(ah, tsf);
1630
Felix Fietkau7a370812010-09-22 12:34:52 +02001631 if (AR_SREV_9280_20_OR_LATER(ah))
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301632 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001633
Sujithe9141f72010-06-01 15:14:10 +05301634 if (!AR_SREV_9300_20_OR_LATER(ah))
1635 ar9002_hw_enable_async_fifo(ah);
1636
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001637 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001638 if (r)
1639 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001640
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301641 if (mci)
1642 ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
1643
Felix Fietkauf860d522010-06-30 02:07:48 +02001644 /*
1645 * Some AR91xx SoC devices frequently fail to accept TSF writes
1646 * right after the chip reset. When that happens, write a new
1647 * value after the initvals have been applied, with an offset
1648 * based on measured time difference
1649 */
1650 if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
1651 tsf += 1500;
1652 ath9k_hw_settsf64(ah, tsf);
1653 }
1654
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001655 /* Setup MFP options for CCMP */
1656 if (AR_SREV_9280_20_OR_LATER(ah)) {
1657 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1658 * frames when constructing CCMP AAD. */
1659 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1660 0xc7ff);
1661 ah->sw_mgmt_crypto = false;
1662 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1663 /* Disable hardware crypto for management frames */
1664 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1665 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1666 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1667 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1668 ah->sw_mgmt_crypto = true;
1669 } else
1670 ah->sw_mgmt_crypto = true;
1671
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001672 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1673 ath9k_hw_set_delta_slope(ah, chan);
1674
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001675 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301676 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001677
Sujith7d0d0df2010-04-16 11:53:57 +05301678 ENABLE_REGWRITE_BUFFER(ah);
1679
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001680 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1681 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001682 | macStaId1
1683 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301684 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301685 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301686 | ah->sta_id1_defaults);
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001687 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001688 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001689 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001690 REG_WRITE(ah, AR_ISR, ~0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001691 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1692
Sujith7d0d0df2010-04-16 11:53:57 +05301693 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301694
Sujith Manoharan00e00032011-01-26 21:59:05 +05301695 ath9k_hw_set_operating_mode(ah, ah->opmode);
1696
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001697 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001698 if (r)
1699 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001700
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001701 ath9k_hw_set_clockrate(ah);
1702
Sujith7d0d0df2010-04-16 11:53:57 +05301703 ENABLE_REGWRITE_BUFFER(ah);
1704
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001705 for (i = 0; i < AR_NUM_DCU; i++)
1706 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1707
Sujith7d0d0df2010-04-16 11:53:57 +05301708 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301709
Sujith2660b812009-02-09 13:27:26 +05301710 ah->intr_txqs = 0;
Felix Fietkauf4c607d2011-03-23 20:57:28 +01001711 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001712 ath9k_hw_resettxqueue(ah, i);
1713
Sujith2660b812009-02-09 13:27:26 +05301714 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001715 ath9k_hw_ani_cache_ini_regs(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001716 ath9k_hw_init_qos(ah);
1717
Sujith2660b812009-02-09 13:27:26 +05301718 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Felix Fietkau55821322010-12-17 00:57:01 +01001719 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301720
Felix Fietkau0005baf2010-01-15 02:33:40 +01001721 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001722
Felix Fietkaufe2b6af2011-07-09 11:12:51 +07001723 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1724 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1725 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1726 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1727 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1728 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1729 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301730 }
1731
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001732 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001733
1734 ath9k_hw_set_dma(ah);
1735
1736 REG_WRITE(ah, AR_OBS, 8);
1737
Sujith0ce024c2009-12-14 14:57:00 +05301738 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001739 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1740 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1741 }
1742
Vasanthakumar Thiagarajan7f62a132010-04-15 17:39:19 -04001743 if (ah->config.tx_intr_mitigation) {
1744 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1745 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1746 }
1747
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001748 ath9k_hw_init_bb(ah, chan);
1749
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301750 if (caldata) {
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301751 caldata->done_txiqcal_once = false;
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301752 caldata->done_txclcal_once = false;
Rajkumar Manoharan324c74a2011-10-13 11:00:41 +05301753 caldata->rtt_hist.num_readings = 0;
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301754 }
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001755 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001756 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001757
Rajkumar Manoharan93348922011-10-25 16:47:36 +05301758 ath9k_hw_loadnf(ah, chan);
1759 ath9k_hw_start_nfcal(ah, true);
1760
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301761 if (mci && ar9003_mci_end_reset(ah, chan, caldata))
1762 return -EIO;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301763
Sujith7d0d0df2010-04-16 11:53:57 +05301764 ENABLE_REGWRITE_BUFFER(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001765
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001766 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001767 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1768
Sujith7d0d0df2010-04-16 11:53:57 +05301769 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301770
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001771 /*
1772 * For big endian systems turn on swapping for descriptors
1773 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001774 if (AR_SREV_9100(ah)) {
1775 u32 mask;
1776 mask = REG_READ(ah, AR_CFG);
1777 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001778 ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n",
1779 mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001780 } else {
1781 mask =
1782 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1783 REG_WRITE(ah, AR_CFG, mask);
Joe Perchesd2182b62011-12-15 14:55:53 -08001784 ath_dbg(common, RESET, "Setting CFG 0x%x\n",
1785 REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001786 }
1787 } else {
Sujithcbba8cd2010-06-02 15:53:31 +05301788 if (common->bus_ops->ath_bus_type == ATH_USB) {
1789 /* Configure AR9271 target WLAN */
1790 if (AR_SREV_9271(ah))
1791 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
1792 else
1793 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1794 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001795#ifdef __BIG_ENDIAN
Gabor Juhos4033bda2011-06-21 11:23:35 +02001796 else if (AR_SREV_9330(ah) || AR_SREV_9340(ah))
Vasanthakumar Thiagarajan2be7bfe2011-04-19 19:29:14 +05301797 REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
1798 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001799 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001800#endif
1801 }
1802
Sujith Manoharandbccdd12012-02-22 17:55:47 +05301803 if (ath9k_hw_btcoex_is_enabled(ah))
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05301804 ath9k_hw_btcoex_enable(ah);
1805
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301806 if (mci)
1807 ar9003_mci_check_bt(ah);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301808
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05301809 if (AR_SREV_9300_20_OR_LATER(ah)) {
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04001810 ar9003_hw_bb_watchdog_config(ah);
Vasanthakumar Thiagarajand8903a52010-04-15 17:39:25 -04001811
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05301812 ar9003_hw_disable_phy_restart(ah);
1813 }
1814
Felix Fietkau691680b2011-03-19 13:55:38 +01001815 ath9k_hw_apply_gpio_override(ah);
1816
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001817 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001818}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001819EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001820
Sujithf1dc5602008-10-29 10:16:30 +05301821/******************************/
1822/* Power Management (Chipset) */
1823/******************************/
1824
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001825/*
1826 * Notify Power Mgt is disabled in self-generated frames.
1827 * If requested, force chip to sleep.
1828 */
Sujithcbe61d82009-02-09 13:27:12 +05301829static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301830{
1831 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1832 if (setChip) {
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05301833 if (AR_SREV_9462(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301834 REG_WRITE(ah, AR_TIMER_MODE,
1835 REG_READ(ah, AR_TIMER_MODE) & 0xFFFFFF00);
1836 REG_WRITE(ah, AR_NDP2_TIMER_MODE, REG_READ(ah,
1837 AR_NDP2_TIMER_MODE) & 0xFFFFFF00);
1838 REG_WRITE(ah, AR_SLP32_INC,
1839 REG_READ(ah, AR_SLP32_INC) & 0xFFF00000);
1840 /* xxx Required for WLAN only case ? */
1841 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
1842 udelay(100);
1843 }
1844
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001845 /*
1846 * Clear the RTC force wake bit to allow the
1847 * mac to go to sleep.
1848 */
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301849 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
1850
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05301851 if (AR_SREV_9462(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301852 udelay(100);
1853
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001854 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301855 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1856
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001857 /* Shutdown chip. Active low */
Sujith Manoharanc91ec462012-02-22 12:40:03 +05301858 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301859 REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
1860 udelay(2);
1861 }
Sujithf1dc5602008-10-29 10:16:30 +05301862 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001863
1864 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
Rafael J. Wysockia7322812011-11-26 23:37:43 +01001865 if (AR_SREV_9300_20_OR_LATER(ah))
1866 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001867}
1868
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001869/*
1870 * Notify Power Management is enabled in self-generating
1871 * frames. If request, set power mode of chip to
1872 * auto/normal. Duration in units of 128us (1/8 TU).
1873 */
Sujithcbe61d82009-02-09 13:27:12 +05301874static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001875{
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301876 u32 val;
1877
Sujithf1dc5602008-10-29 10:16:30 +05301878 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1879 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05301880 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001881
Sujithf1dc5602008-10-29 10:16:30 +05301882 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001883 /* Set WakeOnInterrupt bit; clear ForceWake bit */
Sujithf1dc5602008-10-29 10:16:30 +05301884 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1885 AR_RTC_FORCE_WAKE_ON_INT);
1886 } else {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301887
1888 /* When chip goes into network sleep, it could be waken
1889 * up by MCI_INT interrupt caused by BT's HW messages
1890 * (LNA_xxx, CONT_xxx) which chould be in a very fast
1891 * rate (~100us). This will cause chip to leave and
1892 * re-enter network sleep mode frequently, which in
1893 * consequence will have WLAN MCI HW to generate lots of
1894 * SYS_WAKING and SYS_SLEEPING messages which will make
1895 * BT CPU to busy to process.
1896 */
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05301897 if (AR_SREV_9462(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301898 val = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_EN) &
1899 ~AR_MCI_INTERRUPT_RX_HW_MSG_MASK;
1900 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, val);
1901 }
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04001902 /*
1903 * Clear the RTC force wake bit to allow the
1904 * mac to go to sleep.
1905 */
Sujithf1dc5602008-10-29 10:16:30 +05301906 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
1907 AR_RTC_FORCE_WAKE_EN);
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301908
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05301909 if (AR_SREV_9462(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301910 udelay(30);
Sujithf1dc5602008-10-29 10:16:30 +05301911 }
1912 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001913
1914 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
1915 if (AR_SREV_9300_20_OR_LATER(ah))
1916 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Sujithf1dc5602008-10-29 10:16:30 +05301917}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001918
Sujithcbe61d82009-02-09 13:27:12 +05301919static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05301920{
1921 u32 val;
1922 int i;
1923
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001924 /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
1925 if (AR_SREV_9300_20_OR_LATER(ah)) {
1926 REG_WRITE(ah, AR_WA, ah->WARegVal);
1927 udelay(10);
1928 }
1929
Sujithf1dc5602008-10-29 10:16:30 +05301930 if (setChip) {
1931 if ((REG_READ(ah, AR_RTC_STATUS) &
1932 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
1933 if (ath9k_hw_set_reset_reg(ah,
1934 ATH9K_RESET_POWER_ON) != true) {
1935 return false;
1936 }
Luis R. Rodrigueze0412282010-04-15 17:38:15 -04001937 if (!AR_SREV_9300_20_OR_LATER(ah))
1938 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05301939 }
1940 if (AR_SREV_9100(ah))
1941 REG_SET_BIT(ah, AR_RTC_RESET,
1942 AR_RTC_RESET_EN);
1943
1944 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
1945 AR_RTC_FORCE_WAKE_EN);
1946 udelay(50);
1947
1948 for (i = POWER_UP_TIME / 50; i > 0; i--) {
1949 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
1950 if (val == AR_RTC_STATUS_ON)
1951 break;
1952 udelay(50);
1953 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
1954 AR_RTC_FORCE_WAKE_EN);
1955 }
1956 if (i == 0) {
Joe Perches38002762010-12-02 19:12:36 -08001957 ath_err(ath9k_hw_common(ah),
1958 "Failed to wakeup in %uus\n",
1959 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05301960 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001961 }
1962 }
1963
Sujithf1dc5602008-10-29 10:16:30 +05301964 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1965
1966 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001967}
1968
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001969bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05301970{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001971 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05301972 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05301973 static const char *modes[] = {
1974 "AWAKE",
1975 "FULL-SLEEP",
1976 "NETWORK SLEEP",
1977 "UNDEFINED"
1978 };
Sujithf1dc5602008-10-29 10:16:30 +05301979
Gabor Juhoscbdec972009-07-24 17:27:22 +02001980 if (ah->power_mode == mode)
1981 return status;
1982
Joe Perchesd2182b62011-12-15 14:55:53 -08001983 ath_dbg(common, RESET, "%s -> %s\n",
Joe Perches226afe62010-12-02 19:12:37 -08001984 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05301985
1986 switch (mode) {
1987 case ATH9K_PM_AWAKE:
1988 status = ath9k_hw_set_power_awake(ah, setChip);
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05301989
1990 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
1991 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
1992
Sujithf1dc5602008-10-29 10:16:30 +05301993 break;
1994 case ATH9K_PM_FULL_SLEEP:
Sujith Manoharand1ca8b82012-02-22 12:41:01 +05301995 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
1996 ar9003_mci_set_full_sleep(ah);
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05301997
Sujithf1dc5602008-10-29 10:16:30 +05301998 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05301999 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302000 break;
2001 case ATH9K_PM_NETWORK_SLEEP:
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05302002
2003 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
2004 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
2005
Sujithf1dc5602008-10-29 10:16:30 +05302006 ath9k_set_power_network_sleep(ah, setChip);
2007 break;
2008 default:
Joe Perches38002762010-12-02 19:12:36 -08002009 ath_err(common, "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302010 return false;
2011 }
Sujith2660b812009-02-09 13:27:26 +05302012 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302013
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002014 /*
2015 * XXX: If this warning never comes up after a while then
2016 * simply keep the ATH_DBG_WARN_ON_ONCE() but make
2017 * ath9k_hw_setpower() return type void.
2018 */
Sujith Manoharan97dcec52010-12-20 08:02:42 +05302019
2020 if (!(ah->ah_flags & AH_UNPLUGGED))
2021 ATH_DBG_WARN_ON_ONCE(!status);
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002022
Sujithf1dc5602008-10-29 10:16:30 +05302023 return status;
2024}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002025EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302026
Sujithf1dc5602008-10-29 10:16:30 +05302027/*******************/
2028/* Beacon Handling */
2029/*******************/
2030
Sujithcbe61d82009-02-09 13:27:12 +05302031void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002032{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002033 int flags = 0;
2034
Sujith7d0d0df2010-04-16 11:53:57 +05302035 ENABLE_REGWRITE_BUFFER(ah);
2036
Sujith2660b812009-02-09 13:27:26 +05302037 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002038 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002039 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002040 REG_SET_BIT(ah, AR_TXCFG,
2041 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
Felix Fietkaudd347f22011-03-22 21:54:17 +01002042 REG_WRITE(ah, AR_NEXT_NDP_TIMER, next_beacon +
2043 TU_TO_USEC(ah->atim_window ? ah->atim_window : 1));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002044 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002045 case NL80211_IFTYPE_AP:
Felix Fietkaudd347f22011-03-22 21:54:17 +01002046 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
2047 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
2048 TU_TO_USEC(ah->config.dma_beacon_response_time));
2049 REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
2050 TU_TO_USEC(ah->config.sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002051 flags |=
2052 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2053 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002054 default:
Joe Perchesd2182b62011-12-15 14:55:53 -08002055 ath_dbg(ath9k_hw_common(ah), BEACON,
2056 "%s: unsupported opmode: %d\n", __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002057 return;
2058 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002059 }
2060
Felix Fietkaudd347f22011-03-22 21:54:17 +01002061 REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
2062 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
2063 REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
2064 REG_WRITE(ah, AR_NDP_PERIOD, beacon_period);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002065
Sujith7d0d0df2010-04-16 11:53:57 +05302066 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302067
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002068 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2069}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002070EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002071
Sujithcbe61d82009-02-09 13:27:12 +05302072void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302073 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002074{
2075 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302076 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002077 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002078
Sujith7d0d0df2010-04-16 11:53:57 +05302079 ENABLE_REGWRITE_BUFFER(ah);
2080
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002081 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2082
2083 REG_WRITE(ah, AR_BEACON_PERIOD,
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302084 TU_TO_USEC(bs->bs_intval));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002085 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302086 TU_TO_USEC(bs->bs_intval));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002087
Sujith7d0d0df2010-04-16 11:53:57 +05302088 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302089
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002090 REG_RMW_FIELD(ah, AR_RSSI_THR,
2091 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2092
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302093 beaconintval = bs->bs_intval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002094
2095 if (bs->bs_sleepduration > beaconintval)
2096 beaconintval = bs->bs_sleepduration;
2097
2098 dtimperiod = bs->bs_dtimperiod;
2099 if (bs->bs_sleepduration > dtimperiod)
2100 dtimperiod = bs->bs_sleepduration;
2101
2102 if (beaconintval == dtimperiod)
2103 nextTbtt = bs->bs_nextdtim;
2104 else
2105 nextTbtt = bs->bs_nexttbtt;
2106
Joe Perchesd2182b62011-12-15 14:55:53 -08002107 ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2108 ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt);
2109 ath_dbg(common, BEACON, "beacon period %d\n", beaconintval);
2110 ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002111
Sujith7d0d0df2010-04-16 11:53:57 +05302112 ENABLE_REGWRITE_BUFFER(ah);
2113
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002114 REG_WRITE(ah, AR_NEXT_DTIM,
2115 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2116 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2117
2118 REG_WRITE(ah, AR_SLEEP1,
2119 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2120 | AR_SLEEP1_ASSUME_DTIM);
2121
Sujith60b67f52008-08-07 10:52:38 +05302122 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002123 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2124 else
2125 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2126
2127 REG_WRITE(ah, AR_SLEEP2,
2128 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2129
2130 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2131 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2132
Sujith7d0d0df2010-04-16 11:53:57 +05302133 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302134
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002135 REG_SET_BIT(ah, AR_TIMER_MODE,
2136 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2137 AR_DTIM_TIMER_EN);
2138
Sujith4af9cf42009-02-12 10:06:47 +05302139 /* TSF Out of Range Threshold */
2140 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002141}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002142EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002143
Sujithf1dc5602008-10-29 10:16:30 +05302144/*******************/
2145/* HW Capabilities */
2146/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002147
Felix Fietkau60540692011-07-19 08:46:44 +02002148static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
2149{
2150 eeprom_chainmask &= chip_chainmask;
2151 if (eeprom_chainmask)
2152 return eeprom_chainmask;
2153 else
2154 return chip_chainmask;
2155}
2156
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002157/**
2158 * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset
2159 * @ah: the atheros hardware data structure
2160 *
2161 * We enable DFS support upstream on chipsets which have passed a series
2162 * of tests. The testing requirements are going to be documented. Desired
2163 * test requirements are documented at:
2164 *
2165 * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs
2166 *
2167 * Once a new chipset gets properly tested an individual commit can be used
2168 * to document the testing for DFS for that chipset.
2169 */
2170static bool ath9k_hw_dfs_tested(struct ath_hw *ah)
2171{
2172
2173 switch (ah->hw_version.macVersion) {
2174 /* AR9580 will likely be our first target to get testing on */
2175 case AR_SREV_VERSION_9580:
2176 default:
2177 return false;
2178 }
2179}
2180
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002181int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002182{
Sujith2660b812009-02-09 13:27:26 +05302183 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002184 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002185 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau60540692011-07-19 08:46:44 +02002186 unsigned int chip_chainmask;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002187
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +05302188 u16 eeval;
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002189 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002190
Sujithf74df6f2009-02-09 13:27:24 +05302191 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002192 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302193
Sujith2660b812009-02-09 13:27:26 +05302194 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302195 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002196 if (regulatory->current_rd == 0x64 ||
2197 regulatory->current_rd == 0x65)
2198 regulatory->current_rd += 5;
2199 else if (regulatory->current_rd == 0x41)
2200 regulatory->current_rd = 0x43;
Joe Perchesd2182b62011-12-15 14:55:53 -08002201 ath_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n",
2202 regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002203 }
Sujithdc2222a2008-08-14 13:26:55 +05302204
Sujithf74df6f2009-02-09 13:27:24 +05302205 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002206 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
Joe Perches38002762010-12-02 19:12:36 -08002207 ath_err(common,
2208 "no band has been marked as supported in EEPROM\n");
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002209 return -EINVAL;
2210 }
2211
Felix Fietkaud4659912010-10-14 16:02:39 +02002212 if (eeval & AR5416_OPFLAGS_11A)
2213 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002214
Felix Fietkaud4659912010-10-14 16:02:39 +02002215 if (eeval & AR5416_OPFLAGS_11G)
2216 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
Sujithf1dc5602008-10-29 10:16:30 +05302217
Felix Fietkau60540692011-07-19 08:46:44 +02002218 if (AR_SREV_9485(ah) || AR_SREV_9285(ah) || AR_SREV_9330(ah))
2219 chip_chainmask = 1;
Mohammed Shafi Shajakhanba5736a2011-11-30 21:10:52 +05302220 else if (AR_SREV_9462(ah))
2221 chip_chainmask = 3;
Felix Fietkau60540692011-07-19 08:46:44 +02002222 else if (!AR_SREV_9280_20_OR_LATER(ah))
2223 chip_chainmask = 7;
2224 else if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9340(ah))
2225 chip_chainmask = 3;
2226 else
2227 chip_chainmask = 7;
2228
Sujithf74df6f2009-02-09 13:27:24 +05302229 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002230 /*
2231 * For AR9271 we will temporarilly uses the rx chainmax as read from
2232 * the EEPROM.
2233 */
Sujith8147f5d2009-02-20 15:13:23 +05302234 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002235 !(eeval & AR5416_OPFLAGS_11A) &&
2236 !(AR_SREV_9271(ah)))
2237 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302238 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
Felix Fietkau598cdd52011-03-19 13:55:42 +01002239 else if (AR_SREV_9100(ah))
2240 pCap->rx_chainmask = 0x7;
Sujith8147f5d2009-02-20 15:13:23 +05302241 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002242 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302243 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302244
Felix Fietkau60540692011-07-19 08:46:44 +02002245 pCap->tx_chainmask = fixup_chainmask(chip_chainmask, pCap->tx_chainmask);
2246 pCap->rx_chainmask = fixup_chainmask(chip_chainmask, pCap->rx_chainmask);
Felix Fietkau82b2d332011-09-03 01:40:23 +02002247 ah->txchainmask = pCap->tx_chainmask;
2248 ah->rxchainmask = pCap->rx_chainmask;
Felix Fietkau60540692011-07-19 08:46:44 +02002249
Felix Fietkau7a370812010-09-22 12:34:52 +02002250 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302251
Felix Fietkau02d2ebb2010-11-22 15:39:39 +01002252 /* enable key search for every frame in an aggregate */
2253 if (AR_SREV_9300_20_OR_LATER(ah))
2254 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
2255
Bruno Randolfce2220d2010-09-17 11:36:25 +09002256 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
2257
Felix Fietkau0db156e2011-03-23 20:57:29 +01002258 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
Sujithf1dc5602008-10-29 10:16:30 +05302259 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2260 else
2261 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2262
Sujith5b5fa352010-03-17 14:25:15 +05302263 if (AR_SREV_9271(ah))
2264 pCap->num_gpio_pins = AR9271_NUM_GPIO;
Sujith88c1f4f2010-06-30 14:46:31 +05302265 else if (AR_DEVID_7010(ah))
2266 pCap->num_gpio_pins = AR7010_NUM_GPIO;
Mohammed Shafi Shajakhan6321eb02011-09-30 11:31:27 +05302267 else if (AR_SREV_9300_20_OR_LATER(ah))
2268 pCap->num_gpio_pins = AR9300_NUM_GPIO;
2269 else if (AR_SREV_9287_11_OR_LATER(ah))
2270 pCap->num_gpio_pins = AR9287_NUM_GPIO;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002271 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302272 pCap->num_gpio_pins = AR9285_NUM_GPIO;
Felix Fietkau7a370812010-09-22 12:34:52 +02002273 else if (AR_SREV_9280_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302274 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2275 else
2276 pCap->num_gpio_pins = AR_NUM_GPIO;
2277
Mohammed Shafi Shajakhan1b2538b2011-12-07 16:51:39 +05302278 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302279 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
Mohammed Shafi Shajakhan1b2538b2011-12-07 16:51:39 +05302280 else
Sujithf1dc5602008-10-29 10:16:30 +05302281 pCap->rts_aggr_limit = (8 * 1024);
Sujithf1dc5602008-10-29 10:16:30 +05302282
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302283#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302284 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2285 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2286 ah->rfkill_gpio =
2287 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2288 ah->rfkill_polarity =
2289 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302290
2291 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2292 }
2293#endif
Vasanthakumar Thiagarajand5d11542010-05-17 18:57:56 -07002294 if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302295 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2296 else
2297 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302298
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302299 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302300 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2301 else
2302 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2303
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002304 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002305 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
Gabor Juhos0e707a92011-06-21 11:23:31 +02002306 if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah))
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002307 pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
2308
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002309 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2310 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2311 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002312 pCap->tx_desc_len = sizeof(struct ar9003_txc);
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002313 pCap->txs_len = sizeof(struct ar9003_txs);
Luis R. Rodriguez6f481012011-01-20 17:47:39 -08002314 if (!ah->config.paprd_disable &&
2315 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
Felix Fietkau49352502010-06-12 00:33:59 -04002316 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002317 } else {
2318 pCap->tx_desc_len = sizeof(struct ath_desc);
Felix Fietkaua949b172011-07-09 11:12:47 +07002319 if (AR_SREV_9280_20(ah))
Felix Fietkau6b42e8d2010-04-26 15:04:35 -04002320 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002321 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002322
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -04002323 if (AR_SREV_9300_20_OR_LATER(ah))
2324 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2325
Senthil Balasubramanian6ee63f52010-11-10 05:03:16 -08002326 if (AR_SREV_9300_20_OR_LATER(ah))
2327 ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
2328
Felix Fietkaua42acef2010-09-22 12:34:54 +02002329 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
Vasanthakumar Thiagarajan6473d242010-05-13 18:42:38 -07002330 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
2331
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002332 if (AR_SREV_9285(ah))
2333 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
2334 ant_div_ctl1 =
2335 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2336 if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))
2337 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2338 }
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302339 if (AR_SREV_9300_20_OR_LATER(ah)) {
2340 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
2341 pCap->hw_caps |= ATH9K_HW_CAP_APM;
2342 }
2343
2344
Gabor Juhos431da562011-06-21 11:23:41 +02002345 if (AR_SREV_9330(ah) || AR_SREV_9485(ah)) {
Mohammed Shafi Shajakhan21d2c632011-05-13 20:29:31 +05302346 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2347 /*
2348 * enable the diversity-combining algorithm only when
2349 * both enable_lna_div and enable_fast_div are set
2350 * Table for Diversity
2351 * ant_div_alt_lnaconf bit 0-1
2352 * ant_div_main_lnaconf bit 2-3
2353 * ant_div_alt_gaintb bit 4
2354 * ant_div_main_gaintb bit 5
2355 * enable_ant_div_lnadiv bit 6
2356 * enable_ant_fast_div bit 7
2357 */
2358 if ((ant_div_ctl1 >> 0x6) == 0x3)
2359 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2360 }
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002361
Vasanthakumar Thiagarajan8060e162010-12-06 04:27:42 -08002362 if (AR_SREV_9485_10(ah)) {
2363 pCap->pcie_lcr_extsync_en = true;
2364 pCap->pcie_lcr_offset = 0x80;
2365 }
2366
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002367 if (ath9k_hw_dfs_tested(ah))
2368 pCap->hw_caps |= ATH9K_HW_CAP_DFS;
2369
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002370 tx_chainmask = pCap->tx_chainmask;
2371 rx_chainmask = pCap->rx_chainmask;
2372 while (tx_chainmask || rx_chainmask) {
2373 if (tx_chainmask & BIT(0))
2374 pCap->max_txchains++;
2375 if (rx_chainmask & BIT(0))
2376 pCap->max_rxchains++;
2377
2378 tx_chainmask >>= 1;
2379 rx_chainmask >>= 1;
2380 }
2381
Rajkumar Manoharan8ad74c42011-10-13 11:00:38 +05302382 if (AR_SREV_9300_20_OR_LATER(ah)) {
2383 ah->enabled_cals |= TX_IQ_CAL;
Mohammed Shafi Shajakhan6fea5932011-11-30 21:01:31 +05302384 if (AR_SREV_9485_OR_LATER(ah))
Rajkumar Manoharan8ad74c42011-10-13 11:00:38 +05302385 ah->enabled_cals |= TX_IQ_ON_AGC_CAL;
2386 }
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302387 if (AR_SREV_9462(ah))
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +05302388 pCap->hw_caps |= ATH9K_HW_CAP_RTT | ATH9K_HW_CAP_MCI;
Rajkumar Manoharan324c74a2011-10-13 11:00:41 +05302389
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002390 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002391}
2392
Sujithf1dc5602008-10-29 10:16:30 +05302393/****************************/
2394/* GPIO / RFKILL / Antennae */
2395/****************************/
2396
Sujithcbe61d82009-02-09 13:27:12 +05302397static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302398 u32 gpio, u32 type)
2399{
2400 int addr;
2401 u32 gpio_shift, tmp;
2402
2403 if (gpio > 11)
2404 addr = AR_GPIO_OUTPUT_MUX3;
2405 else if (gpio > 5)
2406 addr = AR_GPIO_OUTPUT_MUX2;
2407 else
2408 addr = AR_GPIO_OUTPUT_MUX1;
2409
2410 gpio_shift = (gpio % 6) * 5;
2411
2412 if (AR_SREV_9280_20_OR_LATER(ah)
2413 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2414 REG_RMW(ah, addr, (type << gpio_shift),
2415 (0x1f << gpio_shift));
2416 } else {
2417 tmp = REG_READ(ah, addr);
2418 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2419 tmp &= ~(0x1f << gpio_shift);
2420 tmp |= (type << gpio_shift);
2421 REG_WRITE(ah, addr, tmp);
2422 }
2423}
2424
Sujithcbe61d82009-02-09 13:27:12 +05302425void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302426{
2427 u32 gpio_shift;
2428
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002429 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302430
Sujith88c1f4f2010-06-30 14:46:31 +05302431 if (AR_DEVID_7010(ah)) {
2432 gpio_shift = gpio;
2433 REG_RMW(ah, AR7010_GPIO_OE,
2434 (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
2435 (AR7010_GPIO_OE_MASK << gpio_shift));
2436 return;
2437 }
Sujithf1dc5602008-10-29 10:16:30 +05302438
Sujith88c1f4f2010-06-30 14:46:31 +05302439 gpio_shift = gpio << 1;
Sujithf1dc5602008-10-29 10:16:30 +05302440 REG_RMW(ah,
2441 AR_GPIO_OE_OUT,
2442 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2443 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2444}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002445EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302446
Sujithcbe61d82009-02-09 13:27:12 +05302447u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302448{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302449#define MS_REG_READ(x, y) \
2450 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2451
Sujith2660b812009-02-09 13:27:26 +05302452 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05302453 return 0xffffffff;
2454
Sujith88c1f4f2010-06-30 14:46:31 +05302455 if (AR_DEVID_7010(ah)) {
2456 u32 val;
2457 val = REG_READ(ah, AR7010_GPIO_IN);
2458 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
2459 } else if (AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan93069902010-11-30 23:24:09 -08002460 return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
2461 AR_GPIO_BIT(gpio)) != 0;
Felix Fietkau783dfca2010-04-15 17:38:11 -04002462 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05302463 return MS_REG_READ(AR9271, gpio) != 0;
Felix Fietkaua42acef2010-09-22 12:34:54 +02002464 else if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302465 return MS_REG_READ(AR9287, gpio) != 0;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002466 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302467 return MS_REG_READ(AR9285, gpio) != 0;
Felix Fietkau7a370812010-09-22 12:34:52 +02002468 else if (AR_SREV_9280_20_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302469 return MS_REG_READ(AR928X, gpio) != 0;
2470 else
2471 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05302472}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002473EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05302474
Sujithcbe61d82009-02-09 13:27:12 +05302475void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05302476 u32 ah_signal_type)
2477{
2478 u32 gpio_shift;
2479
Sujith88c1f4f2010-06-30 14:46:31 +05302480 if (AR_DEVID_7010(ah)) {
2481 gpio_shift = gpio;
2482 REG_RMW(ah, AR7010_GPIO_OE,
2483 (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
2484 (AR7010_GPIO_OE_MASK << gpio_shift));
2485 return;
2486 }
2487
Sujithf1dc5602008-10-29 10:16:30 +05302488 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
Sujithf1dc5602008-10-29 10:16:30 +05302489 gpio_shift = 2 * gpio;
Sujithf1dc5602008-10-29 10:16:30 +05302490 REG_RMW(ah,
2491 AR_GPIO_OE_OUT,
2492 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2493 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2494}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002495EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05302496
Sujithcbe61d82009-02-09 13:27:12 +05302497void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05302498{
Sujith88c1f4f2010-06-30 14:46:31 +05302499 if (AR_DEVID_7010(ah)) {
2500 val = val ? 0 : 1;
2501 REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
2502 AR_GPIO_BIT(gpio));
2503 return;
2504 }
2505
Sujith5b5fa352010-03-17 14:25:15 +05302506 if (AR_SREV_9271(ah))
2507 val = ~val;
2508
Sujithf1dc5602008-10-29 10:16:30 +05302509 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2510 AR_GPIO_BIT(gpio));
2511}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002512EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05302513
Sujithcbe61d82009-02-09 13:27:12 +05302514u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302515{
2516 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
2517}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002518EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302519
Sujithcbe61d82009-02-09 13:27:12 +05302520void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05302521{
2522 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2523}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002524EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302525
Sujithf1dc5602008-10-29 10:16:30 +05302526/*********************/
2527/* General Operation */
2528/*********************/
2529
Sujithcbe61d82009-02-09 13:27:12 +05302530u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302531{
2532 u32 bits = REG_READ(ah, AR_RX_FILTER);
2533 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2534
2535 if (phybits & AR_PHY_ERR_RADAR)
2536 bits |= ATH9K_RX_FILTER_PHYRADAR;
2537 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2538 bits |= ATH9K_RX_FILTER_PHYERR;
2539
2540 return bits;
2541}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002542EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302543
Sujithcbe61d82009-02-09 13:27:12 +05302544void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05302545{
2546 u32 phybits;
2547
Sujith7d0d0df2010-04-16 11:53:57 +05302548 ENABLE_REGWRITE_BUFFER(ah);
2549
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302550 if (AR_SREV_9462(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302551 bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
2552
Sujith7ea310b2009-09-03 12:08:43 +05302553 REG_WRITE(ah, AR_RX_FILTER, bits);
2554
Sujithf1dc5602008-10-29 10:16:30 +05302555 phybits = 0;
2556 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2557 phybits |= AR_PHY_ERR_RADAR;
2558 if (bits & ATH9K_RX_FILTER_PHYERR)
2559 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2560 REG_WRITE(ah, AR_PHY_ERR, phybits);
2561
2562 if (phybits)
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002563 REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujithf1dc5602008-10-29 10:16:30 +05302564 else
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002565 REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujith7d0d0df2010-04-16 11:53:57 +05302566
2567 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302568}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002569EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302570
Sujithcbe61d82009-02-09 13:27:12 +05302571bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302572{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302573 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2574 return false;
2575
2576 ath9k_hw_init_pll(ah, NULL);
2577 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302578}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002579EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302580
Sujithcbe61d82009-02-09 13:27:12 +05302581bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302582{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002583 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05302584 return false;
2585
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302586 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2587 return false;
2588
2589 ath9k_hw_init_pll(ah, NULL);
2590 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302591}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002592EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302593
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002594static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05302595{
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002596 enum eeprom_param gain_param;
Felix Fietkau9c204b42011-07-27 15:01:05 +02002597
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002598 if (IS_CHAN_2GHZ(chan))
2599 gain_param = EEP_ANTENNA_GAIN_2G;
2600 else
2601 gain_param = EEP_ANTENNA_GAIN_5G;
Sujithf1dc5602008-10-29 10:16:30 +05302602
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002603 return ah->eep_ops->get_eeprom(ah, gain_param);
2604}
2605
2606void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan)
2607{
2608 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2609 struct ieee80211_channel *channel;
2610 int chan_pwr, new_pwr, max_gain;
2611 int ant_gain, ant_reduction = 0;
2612
2613 if (!chan)
2614 return;
2615
2616 channel = chan->chan;
2617 chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
2618 new_pwr = min_t(int, chan_pwr, reg->power_limit);
2619 max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
2620
2621 ant_gain = get_antenna_gain(ah, chan);
2622 if (ant_gain > max_gain)
2623 ant_reduction = ant_gain - max_gain;
Sujithf1dc5602008-10-29 10:16:30 +05302624
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002625 ah->eep_ops->set_txpower(ah, chan,
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002626 ath9k_regd_get_ctl(reg, chan),
2627 ant_reduction, new_pwr, false);
2628}
2629
2630void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
2631{
2632 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2633 struct ath9k_channel *chan = ah->curchan;
2634 struct ieee80211_channel *channel = chan->chan;
2635
Dan Carpenter48ef5c42011-10-17 10:28:23 +03002636 reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002637 if (test)
2638 channel->max_power = MAX_RATE_POWER / 2;
2639
2640 ath9k_hw_apply_txpower(ah, chan);
2641
2642 if (test)
2643 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
Sujithf1dc5602008-10-29 10:16:30 +05302644}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002645EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05302646
Sujithcbe61d82009-02-09 13:27:12 +05302647void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302648{
Sujith2660b812009-02-09 13:27:26 +05302649 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05302650}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002651EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05302652
Sujithcbe61d82009-02-09 13:27:12 +05302653void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05302654{
2655 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2656 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2657}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002658EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302659
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002660void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302661{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002662 struct ath_common *common = ath9k_hw_common(ah);
2663
2664 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2665 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2666 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05302667}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002668EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05302669
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002670#define ATH9K_MAX_TSF_READ 10
2671
Sujithcbe61d82009-02-09 13:27:12 +05302672u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302673{
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002674 u32 tsf_lower, tsf_upper1, tsf_upper2;
2675 int i;
Sujithf1dc5602008-10-29 10:16:30 +05302676
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002677 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2678 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2679 tsf_lower = REG_READ(ah, AR_TSF_L32);
2680 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2681 if (tsf_upper2 == tsf_upper1)
2682 break;
2683 tsf_upper1 = tsf_upper2;
2684 }
Sujithf1dc5602008-10-29 10:16:30 +05302685
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002686 WARN_ON( i == ATH9K_MAX_TSF_READ );
2687
2688 return (((u64)tsf_upper1 << 32) | tsf_lower);
Sujithf1dc5602008-10-29 10:16:30 +05302689}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002690EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05302691
Sujithcbe61d82009-02-09 13:27:12 +05302692void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002693{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002694 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01002695 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002696}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002697EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002698
Sujithcbe61d82009-02-09 13:27:12 +05302699void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302700{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002701 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2702 AH_TSF_WRITE_TIMEOUT))
Joe Perchesd2182b62011-12-15 14:55:53 -08002703 ath_dbg(ath9k_hw_common(ah), RESET,
Joe Perches226afe62010-12-02 19:12:37 -08002704 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002705
Sujithf1dc5602008-10-29 10:16:30 +05302706 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002707}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002708EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002709
Sujith54e4cec2009-08-07 09:45:09 +05302710void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002711{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002712 if (setting)
Sujith2660b812009-02-09 13:27:26 +05302713 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002714 else
Sujith2660b812009-02-09 13:27:26 +05302715 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002716}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002717EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002718
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002719void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002720{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002721 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05302722 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002723
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002724 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05302725 macmode = AR_2040_JOINED_RX_CLEAR;
2726 else
2727 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002728
Sujithf1dc5602008-10-29 10:16:30 +05302729 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002730}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302731
2732/* HW Generic timers configuration */
2733
2734static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2735{
2736 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2737 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2738 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2739 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2740 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2741 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2742 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2743 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2744 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2745 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2746 AR_NDP2_TIMER_MODE, 0x0002},
2747 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2748 AR_NDP2_TIMER_MODE, 0x0004},
2749 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2750 AR_NDP2_TIMER_MODE, 0x0008},
2751 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2752 AR_NDP2_TIMER_MODE, 0x0010},
2753 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2754 AR_NDP2_TIMER_MODE, 0x0020},
2755 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2756 AR_NDP2_TIMER_MODE, 0x0040},
2757 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2758 AR_NDP2_TIMER_MODE, 0x0080}
2759};
2760
2761/* HW generic timer primitives */
2762
2763/* compute and clear index of rightmost 1 */
2764static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
2765{
2766 u32 b;
2767
2768 b = *mask;
2769 b &= (0-b);
2770 *mask &= ~b;
2771 b *= debruijn32;
2772 b >>= 27;
2773
2774 return timer_table->gen_timer_index[b];
2775}
2776
Felix Fietkaudd347f22011-03-22 21:54:17 +01002777u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302778{
2779 return REG_READ(ah, AR_TSF_L32);
2780}
Felix Fietkaudd347f22011-03-22 21:54:17 +01002781EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302782
2783struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2784 void (*trigger)(void *),
2785 void (*overflow)(void *),
2786 void *arg,
2787 u8 timer_index)
2788{
2789 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2790 struct ath_gen_timer *timer;
2791
2792 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
2793
2794 if (timer == NULL) {
Joe Perches38002762010-12-02 19:12:36 -08002795 ath_err(ath9k_hw_common(ah),
2796 "Failed to allocate memory for hw timer[%d]\n",
2797 timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302798 return NULL;
2799 }
2800
2801 /* allocate a hardware generic timer slot */
2802 timer_table->timers[timer_index] = timer;
2803 timer->index = timer_index;
2804 timer->trigger = trigger;
2805 timer->overflow = overflow;
2806 timer->arg = arg;
2807
2808 return timer;
2809}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002810EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302811
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002812void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2813 struct ath_gen_timer *timer,
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05302814 u32 trig_timeout,
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002815 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302816{
2817 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05302818 u32 tsf, timer_next;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302819
2820 BUG_ON(!timer_period);
2821
2822 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
2823
2824 tsf = ath9k_hw_gettsf32(ah);
2825
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05302826 timer_next = tsf + trig_timeout;
2827
Joe Perchesd2182b62011-12-15 14:55:53 -08002828 ath_dbg(ath9k_hw_common(ah), HWTIMER,
Joe Perches226afe62010-12-02 19:12:37 -08002829 "current tsf %x period %x timer_next %x\n",
2830 tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302831
2832 /*
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302833 * Program generic timer registers
2834 */
2835 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
2836 timer_next);
2837 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
2838 timer_period);
2839 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2840 gen_tmr_configuration[timer->index].mode_mask);
2841
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302842 if (AR_SREV_9462(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302843 /*
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302844 * Starting from AR9462, each generic timer can select which tsf
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302845 * to use. But we still follow the old rule, 0 - 7 use tsf and
2846 * 8 - 15 use tsf2.
2847 */
2848 if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
2849 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2850 (1 << timer->index));
2851 else
2852 REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2853 (1 << timer->index));
2854 }
2855
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302856 /* Enable both trigger and thresh interrupt masks */
2857 REG_SET_BIT(ah, AR_IMR_S5,
2858 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
2859 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302860}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002861EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302862
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002863void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302864{
2865 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2866
2867 if ((timer->index < AR_FIRST_NDP_TIMER) ||
2868 (timer->index >= ATH_MAX_GEN_TIMER)) {
2869 return;
2870 }
2871
2872 /* Clear generic timer enable bits. */
2873 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2874 gen_tmr_configuration[timer->index].mode_mask);
2875
2876 /* Disable both trigger and thresh interrupt masks */
2877 REG_CLR_BIT(ah, AR_IMR_S5,
2878 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
2879 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
2880
2881 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302882}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002883EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302884
2885void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
2886{
2887 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2888
2889 /* free the hardware generic timer slot */
2890 timer_table->timers[timer->index] = NULL;
2891 kfree(timer);
2892}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002893EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302894
2895/*
2896 * Generic Timer Interrupts handling
2897 */
2898void ath_gen_timer_isr(struct ath_hw *ah)
2899{
2900 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2901 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002902 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302903 u32 trigger_mask, thresh_mask, index;
2904
2905 /* get hardware generic timer interrupt status */
2906 trigger_mask = ah->intr_gen_timer_trigger;
2907 thresh_mask = ah->intr_gen_timer_thresh;
2908 trigger_mask &= timer_table->timer_mask.val;
2909 thresh_mask &= timer_table->timer_mask.val;
2910
2911 trigger_mask &= ~thresh_mask;
2912
2913 while (thresh_mask) {
2914 index = rightmost_index(timer_table, &thresh_mask);
2915 timer = timer_table->timers[index];
2916 BUG_ON(!timer);
Joe Perchesd2182b62011-12-15 14:55:53 -08002917 ath_dbg(common, HWTIMER, "TSF overflow for Gen timer %d\n",
2918 index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302919 timer->overflow(timer->arg);
2920 }
2921
2922 while (trigger_mask) {
2923 index = rightmost_index(timer_table, &trigger_mask);
2924 timer = timer_table->timers[index];
2925 BUG_ON(!timer);
Joe Perchesd2182b62011-12-15 14:55:53 -08002926 ath_dbg(common, HWTIMER,
Joe Perches226afe62010-12-02 19:12:37 -08002927 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302928 timer->trigger(timer->arg);
2929 }
2930}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002931EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002932
Sujith05020d22010-03-17 14:25:23 +05302933/********/
2934/* HTC */
2935/********/
2936
2937void ath9k_hw_htc_resetinit(struct ath_hw *ah)
2938{
2939 ah->htc_reset_init = true;
2940}
2941EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
2942
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002943static struct {
2944 u32 version;
2945 const char * name;
2946} ath_mac_bb_names[] = {
2947 /* Devices with external radios */
2948 { AR_SREV_VERSION_5416_PCI, "5416" },
2949 { AR_SREV_VERSION_5416_PCIE, "5418" },
2950 { AR_SREV_VERSION_9100, "9100" },
2951 { AR_SREV_VERSION_9160, "9160" },
2952 /* Single-chip solutions */
2953 { AR_SREV_VERSION_9280, "9280" },
2954 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04002955 { AR_SREV_VERSION_9287, "9287" },
2956 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguezec839032010-04-15 17:39:20 -04002957 { AR_SREV_VERSION_9300, "9300" },
Gabor Juhos2c8e5932011-06-21 11:23:21 +02002958 { AR_SREV_VERSION_9330, "9330" },
Florian Fainelli397e5d52011-08-25 21:33:48 +02002959 { AR_SREV_VERSION_9340, "9340" },
Senthil Balasubramanian8f06ca22011-04-01 17:16:33 +05302960 { AR_SREV_VERSION_9485, "9485" },
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05302961 { AR_SREV_VERSION_9462, "9462" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002962};
2963
2964/* For devices with external radios */
2965static struct {
2966 u16 version;
2967 const char * name;
2968} ath_rf_names[] = {
2969 { 0, "5133" },
2970 { AR_RAD5133_SREV_MAJOR, "5133" },
2971 { AR_RAD5122_SREV_MAJOR, "5122" },
2972 { AR_RAD2133_SREV_MAJOR, "2133" },
2973 { AR_RAD2122_SREV_MAJOR, "2122" }
2974};
2975
2976/*
2977 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
2978 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002979static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002980{
2981 int i;
2982
2983 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
2984 if (ath_mac_bb_names[i].version == mac_bb_version) {
2985 return ath_mac_bb_names[i].name;
2986 }
2987 }
2988
2989 return "????";
2990}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002991
2992/*
2993 * Return the RF name. "????" is returned if the RF is unknown.
2994 * Used for devices with external radios.
2995 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04002996static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04002997{
2998 int i;
2999
3000 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3001 if (ath_rf_names[i].version == rf_version) {
3002 return ath_rf_names[i].name;
3003 }
3004 }
3005
3006 return "????";
3007}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003008
3009void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3010{
3011 int used;
3012
3013 /* chipsets >= AR9280 are single-chip */
Felix Fietkau7a370812010-09-22 12:34:52 +02003014 if (AR_SREV_9280_20_OR_LATER(ah)) {
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003015 used = snprintf(hw_name, len,
3016 "Atheros AR%s Rev:%x",
3017 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3018 ah->hw_version.macRev);
3019 }
3020 else {
3021 used = snprintf(hw_name, len,
3022 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3023 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3024 ah->hw_version.macRev,
3025 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3026 AR_RADIO_SREV_MAJOR)),
3027 ah->hw_version.phyRev);
3028 }
3029
3030 hw_name[used] = '\0';
3031}
3032EXPORT_SYMBOL(ath9k_hw_name);