blob: 71cd9f0c96af35e7b643c91d7b0b380685802db6 [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"
Sujith Manoharan362cd032012-09-16 08:06:36 +053027#include "ar9003_phy.h"
Ben Greear462e58f2012-04-12 10:04:00 -070028#include "debug.h"
29#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070030
Sujithcbe61d82009-02-09 13:27:12 +053031static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070032
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040033MODULE_AUTHOR("Atheros Communications");
34MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
35MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
36MODULE_LICENSE("Dual BSD/GPL");
37
38static int __init ath9k_init(void)
39{
40 return 0;
41}
42module_init(ath9k_init);
43
44static void __exit ath9k_exit(void)
45{
46 return;
47}
48module_exit(ath9k_exit);
49
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -040050/* Private hardware callbacks */
51
52static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
53{
54 ath9k_hw_private_ops(ah)->init_cal_settings(ah);
55}
56
57static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
58{
59 ath9k_hw_private_ops(ah)->init_mode_regs(ah);
60}
61
Luis R. Rodriguez64773962010-04-15 17:38:17 -040062static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
63 struct ath9k_channel *chan)
64{
65 return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
66}
67
Luis R. Rodriguez991312d2010-04-15 17:39:05 -040068static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
69{
70 if (!ath9k_hw_private_ops(ah)->init_mode_gain_regs)
71 return;
72
73 ath9k_hw_private_ops(ah)->init_mode_gain_regs(ah);
74}
75
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -040076static void ath9k_hw_ani_cache_ini_regs(struct ath_hw *ah)
77{
78 /* You will not have this callback if using the old ANI */
79 if (!ath9k_hw_private_ops(ah)->ani_cache_ini_regs)
80 return;
81
82 ath9k_hw_private_ops(ah)->ani_cache_ini_regs(ah);
83}
84
Sujithf1dc5602008-10-29 10:16:30 +053085/********************/
86/* Helper Functions */
87/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070088
Ben Greear462e58f2012-04-12 10:04:00 -070089#ifdef CONFIG_ATH9K_DEBUGFS
90
91void ath9k_debug_sync_cause(struct ath_common *common, u32 sync_cause)
92{
93 struct ath_softc *sc = common->priv;
94 if (sync_cause)
95 sc->debug.stats.istats.sync_cause_all++;
96 if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
97 sc->debug.stats.istats.sync_rtc_irq++;
98 if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
99 sc->debug.stats.istats.sync_mac_irq++;
100 if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
101 sc->debug.stats.istats.eeprom_illegal_access++;
102 if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
103 sc->debug.stats.istats.apb_timeout++;
104 if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
105 sc->debug.stats.istats.pci_mode_conflict++;
106 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
107 sc->debug.stats.istats.host1_fatal++;
108 if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
109 sc->debug.stats.istats.host1_perr++;
110 if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
111 sc->debug.stats.istats.trcv_fifo_perr++;
112 if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
113 sc->debug.stats.istats.radm_cpl_ep++;
114 if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
115 sc->debug.stats.istats.radm_cpl_dllp_abort++;
116 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
117 sc->debug.stats.istats.radm_cpl_tlp_abort++;
118 if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
119 sc->debug.stats.istats.radm_cpl_ecrc_err++;
120 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
121 sc->debug.stats.istats.radm_cpl_timeout++;
122 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
123 sc->debug.stats.istats.local_timeout++;
124 if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
125 sc->debug.stats.istats.pm_access++;
126 if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
127 sc->debug.stats.istats.mac_awake++;
128 if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
129 sc->debug.stats.istats.mac_asleep++;
130 if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
131 sc->debug.stats.istats.mac_sleep_access++;
132}
133#endif
134
135
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200136static void ath9k_hw_set_clockrate(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530137{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -0700138 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200139 struct ath_common *common = ath9k_hw_common(ah);
140 unsigned int clockrate;
Sujithcbe61d82009-02-09 13:27:12 +0530141
Felix Fietkau087b6ff2011-07-09 11:12:49 +0700142 /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
143 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
144 clockrate = 117;
145 else if (!ah->curchan) /* should really check for CCK instead */
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200146 clockrate = ATH9K_CLOCK_RATE_CCK;
147 else if (conf->channel->band == IEEE80211_BAND_2GHZ)
148 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
149 else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
150 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
Vasanthakumar Thiagarajane5553722010-04-26 15:04:33 -0400151 else
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200152 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
153
154 if (conf_is_ht40(conf))
155 clockrate *= 2;
156
Felix Fietkau906c7202011-07-09 11:12:48 +0700157 if (ah->curchan) {
158 if (IS_CHAN_HALF_RATE(ah->curchan))
159 clockrate /= 2;
160 if (IS_CHAN_QUARTER_RATE(ah->curchan))
161 clockrate /= 4;
162 }
163
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200164 common->clockrate = clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530165}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700166
Sujithcbe61d82009-02-09 13:27:12 +0530167static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +0530168{
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200169 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +0530170
Felix Fietkaudfdac8a2010-10-08 22:13:51 +0200171 return usecs * common->clockrate;
Sujithf1dc5602008-10-29 10:16:30 +0530172}
173
Sujith0caa7b12009-02-16 13:23:20 +0530174bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700175{
176 int i;
177
Sujith0caa7b12009-02-16 13:23:20 +0530178 BUG_ON(timeout < AH_TIME_QUANTUM);
179
180 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700181 if ((REG_READ(ah, reg) & mask) == val)
182 return true;
183
184 udelay(AH_TIME_QUANTUM);
185 }
Sujith04bd46382008-11-28 22:18:05 +0530186
Joe Perchesd2182b62011-12-15 14:55:53 -0800187 ath_dbg(ath9k_hw_common(ah), ANY,
Joe Perches226afe62010-12-02 19:12:37 -0800188 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
189 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530190
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700191 return false;
192}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400193EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700194
Felix Fietkau7c5adc82012-04-19 21:18:26 +0200195void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
196 int hw_delay)
197{
198 if (IS_CHAN_B(chan))
199 hw_delay = (4 * hw_delay) / 22;
200 else
201 hw_delay /= 10;
202
203 if (IS_CHAN_HALF_RATE(chan))
204 hw_delay *= 2;
205 else if (IS_CHAN_QUARTER_RATE(chan))
206 hw_delay *= 4;
207
208 udelay(hw_delay + BASE_ACTIVATE_DELAY);
209}
210
Felix Fietkaua9b6b252011-03-23 20:57:27 +0100211void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
212 int column, unsigned int *writecnt)
213{
214 int r;
215
216 ENABLE_REGWRITE_BUFFER(ah);
217 for (r = 0; r < array->ia_rows; r++) {
218 REG_WRITE(ah, INI_RA(array, r, 0),
219 INI_RA(array, r, column));
220 DO_DELAY(*writecnt);
221 }
222 REGWRITE_BUFFER_FLUSH(ah);
223}
224
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700225u32 ath9k_hw_reverse_bits(u32 val, u32 n)
226{
227 u32 retval;
228 int i;
229
230 for (i = 0, retval = 0; i < n; i++) {
231 retval = (retval << 1) | (val & 1);
232 val >>= 1;
233 }
234 return retval;
235}
236
Sujithcbe61d82009-02-09 13:27:12 +0530237u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100238 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530239 u32 frameLen, u16 rateix,
240 bool shortPreamble)
241{
242 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530243
244 if (kbps == 0)
245 return 0;
246
Felix Fietkau545750d2009-11-23 22:21:01 +0100247 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530248 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530249 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100250 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530251 phyTime >>= 1;
252 numBits = frameLen << 3;
253 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
254 break;
Sujith46d14a52008-11-18 09:08:13 +0530255 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530256 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530257 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
258 numBits = OFDM_PLCP_BITS + (frameLen << 3);
259 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
260 txTime = OFDM_SIFS_TIME_QUARTER
261 + OFDM_PREAMBLE_TIME_QUARTER
262 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530263 } else if (ah->curchan &&
264 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530265 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
266 numBits = OFDM_PLCP_BITS + (frameLen << 3);
267 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
268 txTime = OFDM_SIFS_TIME_HALF +
269 OFDM_PREAMBLE_TIME_HALF
270 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
271 } else {
272 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
273 numBits = OFDM_PLCP_BITS + (frameLen << 3);
274 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
275 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
276 + (numSymbols * OFDM_SYMBOL_TIME);
277 }
278 break;
279 default:
Joe Perches38002762010-12-02 19:12:36 -0800280 ath_err(ath9k_hw_common(ah),
281 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530282 txTime = 0;
283 break;
284 }
285
286 return txTime;
287}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400288EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530289
Sujithcbe61d82009-02-09 13:27:12 +0530290void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530291 struct ath9k_channel *chan,
292 struct chan_centers *centers)
293{
294 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530295
296 if (!IS_CHAN_HT40(chan)) {
297 centers->ctl_center = centers->ext_center =
298 centers->synth_center = chan->channel;
299 return;
300 }
301
302 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
303 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
304 centers->synth_center =
305 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
306 extoff = 1;
307 } else {
308 centers->synth_center =
309 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
310 extoff = -1;
311 }
312
313 centers->ctl_center =
314 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700315 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530316 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700317 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530318}
319
320/******************/
321/* Chip Revisions */
322/******************/
323
Sujithcbe61d82009-02-09 13:27:12 +0530324static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530325{
326 u32 val;
327
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530328 switch (ah->hw_version.devid) {
329 case AR5416_AR9100_DEVID:
330 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
331 break;
Gabor Juhos37625612011-06-21 11:23:23 +0200332 case AR9300_DEVID_AR9330:
333 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
334 if (ah->get_mac_revision) {
335 ah->hw_version.macRev = ah->get_mac_revision();
336 } else {
337 val = REG_READ(ah, AR_SREV);
338 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
339 }
340 return;
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530341 case AR9300_DEVID_AR9340:
342 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
343 val = REG_READ(ah, AR_SREV);
344 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
345 return;
Gabor Juhos813831d2012-07-03 19:13:17 +0200346 case AR9300_DEVID_QCA955X:
347 ah->hw_version.macVersion = AR_SREV_VERSION_9550;
348 return;
Vasanthakumar Thiagarajanecb1d382011-04-19 19:29:18 +0530349 }
350
Sujithf1dc5602008-10-29 10:16:30 +0530351 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
352
353 if (val == 0xFF) {
354 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530355 ah->hw_version.macVersion =
356 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
357 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530358
Sujith Manoharan77fac462012-09-11 20:09:18 +0530359 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
Mohammed Shafi Shajakhan76ed94b2011-09-30 11:31:28 +0530360 ah->is_pciexpress = true;
361 else
362 ah->is_pciexpress = (val &
363 AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530364 } else {
365 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530366 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530367
Sujithd535a422009-02-09 13:27:06 +0530368 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530369
Sujithd535a422009-02-09 13:27:06 +0530370 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530371 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530372 }
373}
374
Sujithf1dc5602008-10-29 10:16:30 +0530375/************************************/
376/* HW Attach, Detach, Init Routines */
377/************************************/
378
Sujithcbe61d82009-02-09 13:27:12 +0530379static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530380{
Felix Fietkau040b74f2010-12-12 00:51:07 +0100381 if (!AR_SREV_5416(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530382 return;
383
384 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
385 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
386 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
387 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
388 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
389 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
390 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
391 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
392 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
393
394 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
395}
396
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400397/* This should work for all families including legacy */
Sujithcbe61d82009-02-09 13:27:12 +0530398static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530399{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700400 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400401 u32 regAddr[2] = { AR_STA_ID0 };
Sujithf1dc5602008-10-29 10:16:30 +0530402 u32 regHold[2];
Joe Perches07b2fa52010-11-20 18:38:53 -0800403 static const u32 patternData[4] = {
404 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
405 };
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400406 int i, j, loop_max;
Sujithf1dc5602008-10-29 10:16:30 +0530407
Senthil Balasubramanian1f3f0612010-04-15 17:38:29 -0400408 if (!AR_SREV_9300_20_OR_LATER(ah)) {
409 loop_max = 2;
410 regAddr[1] = AR_PHY_BASE + (8 << 2);
411 } else
412 loop_max = 1;
413
414 for (i = 0; i < loop_max; i++) {
Sujithf1dc5602008-10-29 10:16:30 +0530415 u32 addr = regAddr[i];
416 u32 wrData, rdData;
417
418 regHold[i] = REG_READ(ah, addr);
419 for (j = 0; j < 0x100; j++) {
420 wrData = (j << 16) | j;
421 REG_WRITE(ah, addr, wrData);
422 rdData = REG_READ(ah, addr);
423 if (rdData != wrData) {
Joe Perches38002762010-12-02 19:12:36 -0800424 ath_err(common,
425 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
426 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530427 return false;
428 }
429 }
430 for (j = 0; j < 4; j++) {
431 wrData = patternData[j];
432 REG_WRITE(ah, addr, wrData);
433 rdData = REG_READ(ah, addr);
434 if (wrData != rdData) {
Joe Perches38002762010-12-02 19:12:36 -0800435 ath_err(common,
436 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
437 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530438 return false;
439 }
440 }
441 REG_WRITE(ah, regAddr[i], regHold[i]);
442 }
443 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530444
Sujithf1dc5602008-10-29 10:16:30 +0530445 return true;
446}
447
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700448static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700449{
450 int i;
451
Felix Fietkau689e7562012-04-12 22:35:56 +0200452 ah->config.dma_beacon_response_time = 1;
453 ah->config.sw_beacon_response_time = 6;
Sujith2660b812009-02-09 13:27:26 +0530454 ah->config.additional_swba_backoff = 0;
455 ah->config.ack_6mb = 0x0;
456 ah->config.cwm_ignore_extcca = 0;
Sujith2660b812009-02-09 13:27:26 +0530457 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530458 ah->config.pcie_waen = 0;
459 ah->config.analog_shiftreg = 1;
Luis R. Rodriguez03c72512010-06-12 00:33:46 -0400460 ah->config.enable_ani = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700461
462 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530463 ah->config.spurchans[i][0] = AR_NO_SPUR;
464 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700465 }
466
Sujith0ce024c2009-12-14 14:57:00 +0530467 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez6a0ec302010-06-21 18:38:49 -0400468 ah->config.pcieSerDesWrite = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400469
470 /*
471 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
472 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
473 * This means we use it for all AR5416 devices, and the few
474 * minor PCI AR9280 devices out there.
475 *
476 * Serialization is required because these devices do not handle
477 * well the case of two concurrent reads/writes due to the latency
478 * involved. During one read/write another read/write can be issued
479 * on another CPU while the previous read/write may still be working
480 * on our hardware, if we hit this case the hardware poops in a loop.
481 * We prevent this by serializing reads and writes.
482 *
483 * This issue is not present on PCI-Express devices or pre-AR5416
484 * devices (legacy, 802.11abg).
485 */
486 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700487 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700488}
489
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700490static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700491{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700492 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
493
494 regulatory->country_code = CTRY_DEFAULT;
495 regulatory->power_limit = MAX_RATE_POWER;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700496
Sujithd535a422009-02-09 13:27:06 +0530497 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530498 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700499
Sujith2660b812009-02-09 13:27:26 +0530500 ah->atim_window = 0;
Felix Fietkau16f24112010-06-12 17:22:32 +0200501 ah->sta_id1_defaults =
502 AR_STA_ID1_CRPT_MIC_ENABLE |
503 AR_STA_ID1_MCAST_KSRCH;
Felix Fietkauf1717602011-03-19 13:55:41 +0100504 if (AR_SREV_9100(ah))
505 ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
Rajkumar Manoharane3f2acc2011-08-27 11:22:59 +0530506 ah->slottime = ATH9K_SLOT_TIME_9;
Sujith2660b812009-02-09 13:27:26 +0530507 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200508 ah->power_mode = ATH9K_PM_UNDEFINED;
Felix Fietkau8efa7a82012-03-14 16:40:23 +0100509 ah->htc_reset_init = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700510}
511
Sujithcbe61d82009-02-09 13:27:12 +0530512static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700513{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700514 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530515 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700516 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530517 u16 eeval;
Joe Perches07b2fa52010-11-20 18:38:53 -0800518 static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700519
Sujithf1dc5602008-10-29 10:16:30 +0530520 sum = 0;
521 for (i = 0; i < 3; i++) {
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400522 eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
Sujithf1dc5602008-10-29 10:16:30 +0530523 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700524 common->macaddr[2 * i] = eeval >> 8;
525 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700526 }
Sujithd8baa932009-03-30 15:28:25 +0530527 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530528 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700529
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700530 return 0;
531}
532
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700533static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700534{
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530535 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700536 int ecode;
537
Sujith Manoharan6cae913d2011-01-04 13:16:37 +0530538 if (common->bus_ops->ath_bus_type != ATH_USB) {
Sujith527d4852010-03-17 14:25:16 +0530539 if (!ath9k_hw_chip_test(ah))
540 return -ENODEV;
541 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700542
Luis R. Rodriguezebd5a142010-04-15 17:39:18 -0400543 if (!AR_SREV_9300_20_OR_LATER(ah)) {
544 ecode = ar9002_hw_rf_claim(ah);
545 if (ecode != 0)
546 return ecode;
547 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700548
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700549 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700550 if (ecode != 0)
551 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530552
Joe Perchesd2182b62011-12-15 14:55:53 -0800553 ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n",
Joe Perches226afe62010-12-02 19:12:37 -0800554 ah->eep_ops->get_eeprom_ver(ah),
555 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530556
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400557 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
558 if (ecode) {
Joe Perches38002762010-12-02 19:12:36 -0800559 ath_err(ath9k_hw_common(ah),
560 "Failed allocating banks for external radio\n");
Rajkumar Manoharan48a7c3d2010-11-08 20:40:53 +0530561 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -0400562 return ecode;
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400563 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700564
Nikolay Martynov42794252011-12-02 22:39:16 -0500565 if (ah->config.enable_ani) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700566 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700567 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700568 }
Sujithf1dc5602008-10-29 10:16:30 +0530569
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700570 return 0;
571}
572
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400573static void ath9k_hw_attach_ops(struct ath_hw *ah)
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700574{
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400575 if (AR_SREV_9300_20_OR_LATER(ah))
576 ar9003_hw_attach_ops(ah);
577 else
578 ar9002_hw_attach_ops(ah);
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700579}
580
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400581/* Called for all hardware families */
582static int __ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700583{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700584 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700585 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700586
Senthil Balasubramanianac45c122010-12-22 21:14:20 +0530587 ath9k_hw_read_revisions(ah);
588
Senthil Balasubramanian0a8d7cb2010-12-22 19:17:18 +0530589 /*
590 * Read back AR_WA into a permanent copy and set bits 14 and 17.
591 * We need to do this to avoid RMW of this register. We cannot
592 * read the reg when chip is asleep.
593 */
594 ah->WARegVal = REG_READ(ah, AR_WA);
595 ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
596 AR_WA_ASPM_TIMER_BASED_DISABLE);
597
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700598 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Joe Perches38002762010-12-02 19:12:36 -0800599 ath_err(common, "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700600 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700601 }
602
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530603 if (AR_SREV_9462(ah))
Rajkumar Manoharaneec353c2011-10-13 10:49:13 +0530604 ah->WARegVal &= ~AR_WA_D3_L1_DISABLE;
605
Sujith Manoharana4a29542012-09-10 09:20:03 +0530606 if (AR_SREV_9565(ah)) {
607 ah->WARegVal |= AR_WA_BIT22;
608 REG_WRITE(ah, AR_WA, ah->WARegVal);
609 }
610
Luis R. Rodriguezbab1f622010-04-15 17:38:20 -0400611 ath9k_hw_init_defaults(ah);
612 ath9k_hw_init_config(ah);
613
Luis R. Rodriguez8525f282010-04-15 17:38:19 -0400614 ath9k_hw_attach_ops(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400615
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700616 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Joe Perches38002762010-12-02 19:12:36 -0800617 ath_err(common, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700618 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700619 }
620
Felix Fietkauf3eef642012-03-14 16:40:25 +0100621 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700622 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
Panayiotis Karabassis7508b652012-06-26 23:37:17 +0300623 ((AR_SREV_9160(ah) || AR_SREV_9280(ah) || AR_SREV_9287(ah)) &&
John W. Linville4c85ab12010-07-28 10:06:35 -0400624 !ah->is_pciexpress)) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700625 ah->config.serialize_regmode =
626 SER_REG_MODE_ON;
627 } else {
628 ah->config.serialize_regmode =
629 SER_REG_MODE_OFF;
630 }
631 }
632
Joe Perchesd2182b62011-12-15 14:55:53 -0800633 ath_dbg(common, RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700634 ah->config.serialize_regmode);
635
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500636 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
637 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
638 else
639 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
640
Felix Fietkau6da5a722010-12-12 00:51:12 +0100641 switch (ah->hw_version.macVersion) {
642 case AR_SREV_VERSION_5416_PCI:
643 case AR_SREV_VERSION_5416_PCIE:
644 case AR_SREV_VERSION_9160:
645 case AR_SREV_VERSION_9100:
646 case AR_SREV_VERSION_9280:
647 case AR_SREV_VERSION_9285:
648 case AR_SREV_VERSION_9287:
649 case AR_SREV_VERSION_9271:
650 case AR_SREV_VERSION_9300:
Gabor Juhos2c8e5932011-06-21 11:23:21 +0200651 case AR_SREV_VERSION_9330:
Felix Fietkau6da5a722010-12-12 00:51:12 +0100652 case AR_SREV_VERSION_9485:
Vasanthakumar Thiagarajanbca04682011-04-19 19:29:20 +0530653 case AR_SREV_VERSION_9340:
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530654 case AR_SREV_VERSION_9462:
Gabor Juhos2b943a32012-07-03 19:13:34 +0200655 case AR_SREV_VERSION_9550:
Sujith Manoharan77fac462012-09-11 20:09:18 +0530656 case AR_SREV_VERSION_9565:
Felix Fietkau6da5a722010-12-12 00:51:12 +0100657 break;
658 default:
Joe Perches38002762010-12-02 19:12:36 -0800659 ath_err(common,
660 "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
661 ah->hw_version.macVersion, ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700662 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700663 }
664
Gabor Juhos2c8e5932011-06-21 11:23:21 +0200665 if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
Gabor Juhosc95b5842012-07-03 19:13:20 +0200666 AR_SREV_9330(ah) || AR_SREV_9550(ah))
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400667 ah->is_pciexpress = false;
668
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700669 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700670 ath9k_hw_init_cal_settings(ah);
671
672 ah->ani_function = ATH9K_ANI_ALL;
Felix Fietkau7a370812010-09-22 12:34:52 +0200673 if (AR_SREV_9280_20_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700674 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400675 if (!AR_SREV_9300_20_OR_LATER(ah))
676 ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700677
678 ath9k_hw_init_mode_regs(ah);
679
Stanislaw Gruszka69ce6742011-08-05 13:10:34 +0200680 if (!ah->is_pciexpress)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700681 ath9k_hw_disablepcie(ah);
682
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700683 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700684 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700685 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700686
687 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100688 r = ath9k_hw_fill_cap_info(ah);
689 if (r)
690 return r;
691
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700692 r = ath9k_hw_init_macaddr(ah);
693 if (r) {
Joe Perches38002762010-12-02 19:12:36 -0800694 ath_err(common, "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700695 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700696 }
697
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400698 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530699 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700700 else
Sujith2660b812009-02-09 13:27:26 +0530701 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700702
Gabor Juhos88e641d2011-06-21 11:23:30 +0200703 if (AR_SREV_9330(ah))
704 ah->bb_watchdog_timeout_ms = 85;
705 else
706 ah->bb_watchdog_timeout_ms = 25;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700707
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400708 common->state = ATH_HW_INITIALIZED;
709
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700710 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700711}
712
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400713int ath9k_hw_init(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530714{
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400715 int ret;
716 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530717
Sujith Manoharan77fac462012-09-11 20:09:18 +0530718 /* These are all the AR5008/AR9001/AR9002/AR9003 hardware family of chipsets */
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400719 switch (ah->hw_version.devid) {
720 case AR5416_DEVID_PCI:
721 case AR5416_DEVID_PCIE:
722 case AR5416_AR9100_DEVID:
723 case AR9160_DEVID_PCI:
724 case AR9280_DEVID_PCI:
725 case AR9280_DEVID_PCIE:
726 case AR9285_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400727 case AR9287_DEVID_PCI:
728 case AR9287_DEVID_PCIE:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400729 case AR2427_DEVID_PCIE:
Senthil Balasubramaniandb3cc532010-04-15 17:38:18 -0400730 case AR9300_DEVID_PCIE:
Vasanthakumar Thiagarajan3050c912010-12-06 04:27:36 -0800731 case AR9300_DEVID_AR9485_PCIE:
Gabor Juhos999a7a82011-06-21 11:23:52 +0200732 case AR9300_DEVID_AR9330:
Vasanthakumar Thiagarajanbca04682011-04-19 19:29:20 +0530733 case AR9300_DEVID_AR9340:
Gabor Juhos2b943a32012-07-03 19:13:34 +0200734 case AR9300_DEVID_QCA955X:
Luis R. Rodriguez5a63ef02011-08-24 15:36:08 -0700735 case AR9300_DEVID_AR9580:
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +0530736 case AR9300_DEVID_AR9462:
Mohammed Shafi Shajakhand4e59792012-08-02 11:58:50 +0530737 case AR9485_DEVID_AR1111:
Sujith Manoharan77fac462012-09-11 20:09:18 +0530738 case AR9300_DEVID_AR9565:
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400739 break;
740 default:
741 if (common->bus_ops->ath_bus_type == ATH_USB)
742 break;
Joe Perches38002762010-12-02 19:12:36 -0800743 ath_err(common, "Hardware device ID 0x%04x not supported\n",
744 ah->hw_version.devid);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400745 return -EOPNOTSUPP;
746 }
Sujithf1dc5602008-10-29 10:16:30 +0530747
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400748 ret = __ath9k_hw_init(ah);
749 if (ret) {
Joe Perches38002762010-12-02 19:12:36 -0800750 ath_err(common,
751 "Unable to initialize hardware; initialization status: %d\n",
752 ret);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400753 return ret;
754 }
Sujithf1dc5602008-10-29 10:16:30 +0530755
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400756 return 0;
Sujithf1dc5602008-10-29 10:16:30 +0530757}
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400758EXPORT_SYMBOL(ath9k_hw_init);
Sujithf1dc5602008-10-29 10:16:30 +0530759
Sujithcbe61d82009-02-09 13:27:12 +0530760static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530761{
Sujith7d0d0df2010-04-16 11:53:57 +0530762 ENABLE_REGWRITE_BUFFER(ah);
763
Sujithf1dc5602008-10-29 10:16:30 +0530764 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
765 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
766
767 REG_WRITE(ah, AR_QOS_NO_ACK,
768 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
769 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
770 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
771
772 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
773 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
774 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
775 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
776 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
Sujith7d0d0df2010-04-16 11:53:57 +0530777
778 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530779}
780
Senthil Balasubramanianb84628e2011-04-22 11:32:12 +0530781u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
Vivek Natarajanb1415812011-01-27 14:45:07 +0530782{
Mohammed Shafi Shajakhanf18e3c62012-06-18 13:13:30 +0530783 struct ath_common *common = ath9k_hw_common(ah);
784 int i = 0;
785
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100786 REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
787 udelay(100);
788 REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
789
Mohammed Shafi Shajakhanf18e3c62012-06-18 13:13:30 +0530790 while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0) {
791
Vivek Natarajanb1415812011-01-27 14:45:07 +0530792 udelay(100);
Vivek Natarajanb1415812011-01-27 14:45:07 +0530793
Mohammed Shafi Shajakhanf18e3c62012-06-18 13:13:30 +0530794 if (WARN_ON_ONCE(i >= 100)) {
795 ath_err(common, "PLL4 meaurement not done\n");
796 break;
797 }
798
799 i++;
800 }
801
Felix Fietkauca7a4de2011-03-23 20:57:26 +0100802 return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
Vivek Natarajanb1415812011-01-27 14:45:07 +0530803}
804EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
805
Sujithcbe61d82009-02-09 13:27:12 +0530806static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530807 struct ath9k_channel *chan)
808{
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800809 u32 pll;
810
Sujith Manoharana4a29542012-09-10 09:20:03 +0530811 if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530812 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
813 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
814 AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
815 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
816 AR_CH0_DPLL2_KD, 0x40);
817 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
818 AR_CH0_DPLL2_KI, 0x4);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530819
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530820 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
821 AR_CH0_BB_DPLL1_REFDIV, 0x5);
822 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
823 AR_CH0_BB_DPLL1_NINI, 0x58);
824 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
825 AR_CH0_BB_DPLL1_NFRAC, 0x0);
826
827 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
828 AR_CH0_BB_DPLL2_OUTDIV, 0x1);
829 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
830 AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
831 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
832 AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
833
834 /* program BB PLL phase_shift to 0x6 */
835 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
836 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
837
838 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
839 AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
Vivek Natarajan75e03512011-03-10 11:05:42 +0530840 udelay(1000);
Gabor Juhosa5415d62011-06-21 11:23:29 +0200841 } else if (AR_SREV_9330(ah)) {
842 u32 ddr_dpll2, pll_control2, kd;
843
844 if (ah->is_clk_25mhz) {
845 ddr_dpll2 = 0x18e82f01;
846 pll_control2 = 0xe04a3d;
847 kd = 0x1d;
848 } else {
849 ddr_dpll2 = 0x19e82f01;
850 pll_control2 = 0x886666;
851 kd = 0x3d;
852 }
853
854 /* program DDR PLL ki and kd value */
855 REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
856
857 /* program DDR PLL phase_shift */
858 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
859 AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
860
861 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
862 udelay(1000);
863
864 /* program refdiv, nint, frac to RTC register */
865 REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
866
867 /* program BB PLL kd and ki value */
868 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
869 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
870
871 /* program BB PLL phase_shift */
872 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
873 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
Gabor Juhosfc05a312012-07-03 19:13:31 +0200874 } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) {
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530875 u32 regval, pll2_divint, pll2_divfrac, refdiv;
876
877 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
878 udelay(1000);
879
880 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
881 udelay(100);
882
883 if (ah->is_clk_25mhz) {
884 pll2_divint = 0x54;
885 pll2_divfrac = 0x1eb85;
886 refdiv = 3;
887 } else {
Gabor Juhosfc05a312012-07-03 19:13:31 +0200888 if (AR_SREV_9340(ah)) {
889 pll2_divint = 88;
890 pll2_divfrac = 0;
891 refdiv = 5;
892 } else {
893 pll2_divint = 0x11;
894 pll2_divfrac = 0x26666;
895 refdiv = 1;
896 }
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530897 }
898
899 regval = REG_READ(ah, AR_PHY_PLL_MODE);
900 regval |= (0x1 << 16);
901 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
902 udelay(100);
903
904 REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
905 (pll2_divint << 18) | pll2_divfrac);
906 udelay(100);
907
908 regval = REG_READ(ah, AR_PHY_PLL_MODE);
Gabor Juhosfc05a312012-07-03 19:13:31 +0200909 if (AR_SREV_9340(ah))
910 regval = (regval & 0x80071fff) | (0x1 << 30) |
911 (0x1 << 13) | (0x4 << 26) | (0x18 << 19);
912 else
913 regval = (regval & 0x80071fff) | (0x3 << 30) |
914 (0x1 << 13) | (0x4 << 26) | (0x60 << 19);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530915 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
916 REG_WRITE(ah, AR_PHY_PLL_MODE,
917 REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
918 udelay(1000);
Vivek Natarajan22983c32011-01-27 14:45:09 +0530919 }
Vasanthakumar Thiagarajand09b17f2010-12-06 04:27:44 -0800920
921 pll = ath9k_hw_compute_pll_control(ah, chan);
Sujith Manoharan8565f8b2012-09-10 09:20:29 +0530922 if (AR_SREV_9565(ah))
923 pll |= 0x40000;
Gabor Juhosd03a66c2009-01-14 20:17:09 +0100924 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +0530925
Gabor Juhosfc05a312012-07-03 19:13:31 +0200926 if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
927 AR_SREV_9550(ah))
Vasanthakumar Thiagarajan3dfd7f62011-04-11 16:39:40 +0530928 udelay(1000);
929
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400930 /* Switch the core clock for ar9271 to 117Mhz */
931 if (AR_SREV_9271(ah)) {
Sujith25e2ab12010-03-17 14:25:22 +0530932 udelay(500);
933 REG_WRITE(ah, 0x50040, 0x304);
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -0400934 }
935
Sujithf1dc5602008-10-29 10:16:30 +0530936 udelay(RTC_PLL_SETTLE_DELAY);
937
938 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530939
Gabor Juhosfc05a312012-07-03 19:13:31 +0200940 if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) {
Vasanthakumar Thiagarajan0b488ac2011-04-20 10:26:15 +0530941 if (ah->is_clk_25mhz) {
942 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
943 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
944 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
945 } else {
946 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
947 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
948 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
949 }
950 udelay(100);
951 }
Sujithf1dc5602008-10-29 10:16:30 +0530952}
953
Sujithcbe61d82009-02-09 13:27:12 +0530954static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -0800955 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +0530956{
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530957 u32 sync_default = AR_INTR_SYNC_DEFAULT;
Pavel Roskin152d5302010-03-31 18:05:37 -0400958 u32 imr_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +0530959 AR_IMR_TXURN |
960 AR_IMR_RXERR |
961 AR_IMR_RXORN |
962 AR_IMR_BCNMISC;
963
Gabor Juhos3b8a0572012-07-03 19:13:29 +0200964 if (AR_SREV_9340(ah) || AR_SREV_9550(ah))
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530965 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
966
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400967 if (AR_SREV_9300_20_OR_LATER(ah)) {
968 imr_reg |= AR_IMR_RXOK_HP;
969 if (ah->config.rx_intr_mitigation)
970 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
971 else
972 imr_reg |= AR_IMR_RXOK_LP;
Sujithf1dc5602008-10-29 10:16:30 +0530973
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400974 } else {
975 if (ah->config.rx_intr_mitigation)
976 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
977 else
978 imr_reg |= AR_IMR_RXOK;
979 }
980
981 if (ah->config.tx_intr_mitigation)
982 imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
983 else
984 imr_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +0530985
Sujith7d0d0df2010-04-16 11:53:57 +0530986 ENABLE_REGWRITE_BUFFER(ah);
987
Pavel Roskin152d5302010-03-31 18:05:37 -0400988 REG_WRITE(ah, AR_IMR, imr_reg);
Pavel Roskin74bad5c2010-02-23 18:15:27 -0500989 ah->imrs2_reg |= AR_IMR_S2_GTT;
990 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
Sujithf1dc5602008-10-29 10:16:30 +0530991
992 if (!AR_SREV_9100(ah)) {
993 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
Vasanthakumar Thiagarajan79d1d2b2011-04-19 19:29:19 +0530994 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
Sujithf1dc5602008-10-29 10:16:30 +0530995 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
996 }
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -0400997
Sujith7d0d0df2010-04-16 11:53:57 +0530998 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530999
Vasanthakumar Thiagarajan66860242010-04-15 17:39:07 -04001000 if (AR_SREV_9300_20_OR_LATER(ah)) {
1001 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
1002 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
1003 REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
1004 REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
1005 }
Sujithf1dc5602008-10-29 10:16:30 +05301006}
1007
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001008static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us)
1009{
1010 u32 val = ath9k_hw_mac_to_clks(ah, us - 2);
1011 val = min(val, (u32) 0xFFFF);
1012 REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val);
1013}
1014
Felix Fietkau0005baf2010-01-15 02:33:40 +01001015static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301016{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001017 u32 val = ath9k_hw_mac_to_clks(ah, us);
1018 val = min(val, (u32) 0xFFFF);
1019 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
Sujithf1dc5602008-10-29 10:16:30 +05301020}
1021
Felix Fietkau0005baf2010-01-15 02:33:40 +01001022static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301023{
Felix Fietkau0005baf2010-01-15 02:33:40 +01001024 u32 val = ath9k_hw_mac_to_clks(ah, us);
1025 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
1026 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
1027}
1028
1029static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
1030{
1031 u32 val = ath9k_hw_mac_to_clks(ah, us);
1032 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
1033 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
Sujithf1dc5602008-10-29 10:16:30 +05301034}
1035
Sujithcbe61d82009-02-09 13:27:12 +05301036static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301037{
Sujithf1dc5602008-10-29 10:16:30 +05301038 if (tu > 0xFFFF) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001039 ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n",
1040 tu);
Sujith2660b812009-02-09 13:27:26 +05301041 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301042 return false;
1043 } else {
1044 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301045 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301046 return true;
1047 }
1048}
1049
Felix Fietkau0005baf2010-01-15 02:33:40 +01001050void ath9k_hw_init_global_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301051{
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001052 struct ath_common *common = ath9k_hw_common(ah);
1053 struct ieee80211_conf *conf = &common->hw->conf;
1054 const struct ath9k_channel *chan = ah->curchan;
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001055 int acktimeout, ctstimeout, ack_offset = 0;
Felix Fietkaue239d852010-01-15 02:34:58 +01001056 int slottime;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001057 int sifstime;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001058 int rx_lat = 0, tx_lat = 0, eifs = 0;
1059 u32 reg;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001060
Joe Perchesd2182b62011-12-15 14:55:53 -08001061 ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n",
Joe Perches226afe62010-12-02 19:12:37 -08001062 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301063
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001064 if (!chan)
1065 return;
1066
Sujith2660b812009-02-09 13:27:26 +05301067 if (ah->misc_mode != 0)
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001068 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001069
Rajkumar Manoharan81a91d52011-08-31 10:47:30 +05301070 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1071 rx_lat = 41;
1072 else
1073 rx_lat = 37;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001074 tx_lat = 54;
1075
Felix Fietkaue88e4862012-04-19 21:18:22 +02001076 if (IS_CHAN_5GHZ(chan))
1077 sifstime = 16;
1078 else
1079 sifstime = 10;
1080
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001081 if (IS_CHAN_HALF_RATE(chan)) {
1082 eifs = 175;
1083 rx_lat *= 2;
1084 tx_lat *= 2;
1085 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1086 tx_lat += 11;
1087
Felix Fietkaue88e4862012-04-19 21:18:22 +02001088 sifstime *= 2;
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001089 ack_offset = 16;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001090 slottime = 13;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001091 } else if (IS_CHAN_QUARTER_RATE(chan)) {
1092 eifs = 340;
Rajkumar Manoharan81a91d52011-08-31 10:47:30 +05301093 rx_lat = (rx_lat * 4) - 1;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001094 tx_lat *= 4;
1095 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1096 tx_lat += 22;
1097
Felix Fietkaue88e4862012-04-19 21:18:22 +02001098 sifstime *= 4;
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001099 ack_offset = 32;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001100 slottime = 21;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001101 } else {
Rajkumar Manoharana7be0392011-08-27 12:13:21 +05301102 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1103 eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
1104 reg = AR_USEC_ASYNC_FIFO;
1105 } else {
1106 eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
1107 common->clockrate;
1108 reg = REG_READ(ah, AR_USEC);
1109 }
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001110 rx_lat = MS(reg, AR_USEC_RX_LAT);
1111 tx_lat = MS(reg, AR_USEC_TX_LAT);
1112
1113 slottime = ah->slottime;
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001114 }
Felix Fietkau0005baf2010-01-15 02:33:40 +01001115
Felix Fietkaue239d852010-01-15 02:34:58 +01001116 /* As defined by IEEE 802.11-2007 17.3.8.6 */
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001117 acktimeout = slottime + sifstime + 3 * ah->coverage_class + ack_offset;
Felix Fietkauadb50662011-08-28 01:52:10 +02001118 ctstimeout = acktimeout;
Felix Fietkau42c45682010-02-11 18:07:19 +01001119
1120 /*
1121 * Workaround for early ACK timeouts, add an offset to match the
Felix Fietkau55a2bb42012-02-05 21:15:18 +01001122 * initval's 64us ack timeout value. Use 48us for the CTS timeout.
Felix Fietkau42c45682010-02-11 18:07:19 +01001123 * This was initially only meant to work around an issue with delayed
1124 * BA frames in some implementations, but it has been found to fix ACK
1125 * timeout issues in other cases as well.
1126 */
Felix Fietkaue115b7e2012-04-19 21:18:23 +02001127 if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ &&
1128 !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) {
Felix Fietkau42c45682010-02-11 18:07:19 +01001129 acktimeout += 64 - sifstime - ah->slottime;
Felix Fietkau55a2bb42012-02-05 21:15:18 +01001130 ctstimeout += 48 - sifstime - ah->slottime;
1131 }
1132
Felix Fietkau42c45682010-02-11 18:07:19 +01001133
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001134 ath9k_hw_set_sifs_time(ah, sifstime);
1135 ath9k_hw_setslottime(ah, slottime);
Felix Fietkau0005baf2010-01-15 02:33:40 +01001136 ath9k_hw_set_ack_timeout(ah, acktimeout);
Felix Fietkauadb50662011-08-28 01:52:10 +02001137 ath9k_hw_set_cts_timeout(ah, ctstimeout);
Sujith2660b812009-02-09 13:27:26 +05301138 if (ah->globaltxtimeout != (u32) -1)
1139 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Felix Fietkaub6ba41b2011-07-09 11:12:50 +07001140
1141 REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
1142 REG_RMW(ah, AR_USEC,
1143 (common->clockrate - 1) |
1144 SM(rx_lat, AR_USEC_RX_LAT) |
1145 SM(tx_lat, AR_USEC_TX_LAT),
1146 AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
1147
Sujithf1dc5602008-10-29 10:16:30 +05301148}
Felix Fietkau0005baf2010-01-15 02:33:40 +01001149EXPORT_SYMBOL(ath9k_hw_init_global_settings);
Sujithf1dc5602008-10-29 10:16:30 +05301150
Sujith285f2dd2010-01-08 10:36:07 +05301151void ath9k_hw_deinit(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001152{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001153 struct ath_common *common = ath9k_hw_common(ah);
1154
Sujith736b3a22010-03-17 14:25:24 +05301155 if (common->state < ATH_HW_INITIALIZED)
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001156 goto free_hw;
1157
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001158 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001159
1160free_hw:
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001161 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001162}
Sujith285f2dd2010-01-08 10:36:07 +05301163EXPORT_SYMBOL(ath9k_hw_deinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001164
Sujithf1dc5602008-10-29 10:16:30 +05301165/*******/
1166/* INI */
1167/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001168
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001169u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
Bob Copeland3a702e42009-03-30 22:30:29 -04001170{
1171 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1172
1173 if (IS_CHAN_B(chan))
1174 ctl |= CTL_11B;
1175 else if (IS_CHAN_G(chan))
1176 ctl |= CTL_11G;
1177 else
1178 ctl |= CTL_11A;
1179
1180 return ctl;
1181}
1182
Sujithf1dc5602008-10-29 10:16:30 +05301183/****************************************/
1184/* Reset and Channel Switching Routines */
1185/****************************************/
1186
Sujithcbe61d82009-02-09 13:27:12 +05301187static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301188{
Felix Fietkau57b32222010-04-15 17:39:22 -04001189 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301190
Sujith7d0d0df2010-04-16 11:53:57 +05301191 ENABLE_REGWRITE_BUFFER(ah);
1192
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001193 /*
1194 * set AHB_MODE not to do cacheline prefetches
1195 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001196 if (!AR_SREV_9300_20_OR_LATER(ah))
1197 REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
Sujithf1dc5602008-10-29 10:16:30 +05301198
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001199 /*
1200 * let mac dma reads be in 128 byte chunks
1201 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001202 REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301203
Sujith7d0d0df2010-04-16 11:53:57 +05301204 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301205
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001206 /*
1207 * Restore TX Trigger Level to its pre-reset value.
1208 * The initial value depends on whether aggregation is enabled, and is
1209 * adjusted whenever underruns are detected.
1210 */
Felix Fietkau57b32222010-04-15 17:39:22 -04001211 if (!AR_SREV_9300_20_OR_LATER(ah))
1212 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301213
Sujith7d0d0df2010-04-16 11:53:57 +05301214 ENABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301215
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001216 /*
1217 * let mac dma writes be in 128 byte chunks
1218 */
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001219 REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05301220
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001221 /*
1222 * Setup receive FIFO threshold to hold off TX activities
1223 */
Sujithf1dc5602008-10-29 10:16:30 +05301224 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1225
Felix Fietkau57b32222010-04-15 17:39:22 -04001226 if (AR_SREV_9300_20_OR_LATER(ah)) {
1227 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
1228 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
1229
1230 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
1231 ah->caps.rx_status_len);
1232 }
1233
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001234 /*
1235 * reduce the number of usable entries in PCU TXBUF to avoid
1236 * wrap around issues.
1237 */
Sujithf1dc5602008-10-29 10:16:30 +05301238 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001239 /* For AR9285 the number of Fifos are reduced to half.
1240 * So set the usable tx buf size also to half to
1241 * avoid data/delimiter underruns
1242 */
Sujithf1dc5602008-10-29 10:16:30 +05301243 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1244 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001245 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301246 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1247 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1248 }
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001249
Sujith7d0d0df2010-04-16 11:53:57 +05301250 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301251
Vasanthakumar Thiagarajan744d4022010-04-15 17:39:27 -04001252 if (AR_SREV_9300_20_OR_LATER(ah))
1253 ath9k_hw_reset_txstatus_ring(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301254}
1255
Sujithcbe61d82009-02-09 13:27:12 +05301256static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301257{
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001258 u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
1259 u32 set = AR_STA_ID1_KSRCH_MODE;
Sujithf1dc5602008-10-29 10:16:30 +05301260
Sujithf1dc5602008-10-29 10:16:30 +05301261 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001262 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001263 case NL80211_IFTYPE_MESH_POINT:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001264 set |= AR_STA_ID1_ADHOC;
Sujithf1dc5602008-10-29 10:16:30 +05301265 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1266 break;
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001267 case NL80211_IFTYPE_AP:
1268 set |= AR_STA_ID1_STA_AP;
1269 /* fall through */
Colin McCabed97809d2008-12-01 13:38:55 -08001270 case NL80211_IFTYPE_STATION:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001271 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
Sujithf1dc5602008-10-29 10:16:30 +05301272 break;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301273 default:
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001274 if (!ah->is_monitoring)
1275 set = 0;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301276 break;
Sujithf1dc5602008-10-29 10:16:30 +05301277 }
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001278 REG_RMW(ah, AR_STA_ID1, set, mask);
Sujithf1dc5602008-10-29 10:16:30 +05301279}
1280
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001281void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1282 u32 *coef_mantissa, u32 *coef_exponent)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001283{
1284 u32 coef_exp, coef_man;
1285
1286 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1287 if ((coef_scaled >> coef_exp) & 0x1)
1288 break;
1289
1290 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1291
1292 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1293
1294 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1295 *coef_exponent = coef_exp - 16;
1296}
1297
Sujithcbe61d82009-02-09 13:27:12 +05301298static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301299{
1300 u32 rst_flags;
1301 u32 tmpReg;
1302
Sujith70768492009-02-16 13:23:12 +05301303 if (AR_SREV_9100(ah)) {
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001304 REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
1305 AR_RTC_DERIVED_CLK_PERIOD, 1);
Sujith70768492009-02-16 13:23:12 +05301306 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1307 }
1308
Sujith7d0d0df2010-04-16 11:53:57 +05301309 ENABLE_REGWRITE_BUFFER(ah);
1310
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001311 if (AR_SREV_9300_20_OR_LATER(ah)) {
1312 REG_WRITE(ah, AR_WA, ah->WARegVal);
1313 udelay(10);
1314 }
1315
Sujithf1dc5602008-10-29 10:16:30 +05301316 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1317 AR_RTC_FORCE_WAKE_ON_INT);
1318
1319 if (AR_SREV_9100(ah)) {
1320 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1321 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1322 } else {
1323 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1324 if (tmpReg &
1325 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1326 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001327 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05301328 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001329
1330 val = AR_RC_HOSTIF;
1331 if (!AR_SREV_9300_20_OR_LATER(ah))
1332 val |= AR_RC_AHB;
1333 REG_WRITE(ah, AR_RC, val);
1334
1335 } else if (!AR_SREV_9300_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05301336 REG_WRITE(ah, AR_RC, AR_RC_AHB);
Sujithf1dc5602008-10-29 10:16:30 +05301337
1338 rst_flags = AR_RTC_RC_MAC_WARM;
1339 if (type == ATH9K_RESET_COLD)
1340 rst_flags |= AR_RTC_RC_MAC_COLD;
1341 }
1342
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001343 if (AR_SREV_9330(ah)) {
1344 int npend = 0;
1345 int i;
1346
1347 /* AR9330 WAR:
1348 * call external reset function to reset WMAC if:
1349 * - doing a cold reset
1350 * - we have pending frames in the TX queues
1351 */
1352
1353 for (i = 0; i < AR_NUM_QCU; i++) {
1354 npend = ath9k_hw_numtxpending(ah, i);
1355 if (npend)
1356 break;
1357 }
1358
1359 if (ah->external_reset &&
1360 (npend || type == ATH9K_RESET_COLD)) {
1361 int reset_err = 0;
1362
Joe Perchesd2182b62011-12-15 14:55:53 -08001363 ath_dbg(ath9k_hw_common(ah), RESET,
Gabor Juhos7d95847c2011-06-21 11:23:51 +02001364 "reset MAC via external reset\n");
1365
1366 reset_err = ah->external_reset();
1367 if (reset_err) {
1368 ath_err(ath9k_hw_common(ah),
1369 "External reset failed, err=%d\n",
1370 reset_err);
1371 return false;
1372 }
1373
1374 REG_WRITE(ah, AR_RTC_RESET, 1);
1375 }
1376 }
1377
Rajkumar Manoharan38634952012-06-11 12:19:32 +05301378 if (ath9k_hw_mci_is_enabled(ah))
Rajkumar Manoharan506847a2012-06-12 20:18:16 +05301379 ar9003_mci_check_gpm_offset(ah);
Rajkumar Manoharan38634952012-06-11 12:19:32 +05301380
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001381 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujith7d0d0df2010-04-16 11:53:57 +05301382
1383 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301384
Sujithf1dc5602008-10-29 10:16:30 +05301385 udelay(50);
1386
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001387 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301388 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001389 ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301390 return false;
1391 }
1392
1393 if (!AR_SREV_9100(ah))
1394 REG_WRITE(ah, AR_RC, 0);
1395
Sujithf1dc5602008-10-29 10:16:30 +05301396 if (AR_SREV_9100(ah))
1397 udelay(50);
1398
1399 return true;
1400}
1401
Sujithcbe61d82009-02-09 13:27:12 +05301402static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301403{
Sujith7d0d0df2010-04-16 11:53:57 +05301404 ENABLE_REGWRITE_BUFFER(ah);
1405
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001406 if (AR_SREV_9300_20_OR_LATER(ah)) {
1407 REG_WRITE(ah, AR_WA, ah->WARegVal);
1408 udelay(10);
1409 }
1410
Sujithf1dc5602008-10-29 10:16:30 +05301411 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1412 AR_RTC_FORCE_WAKE_ON_INT);
1413
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04001414 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301415 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1416
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001417 REG_WRITE(ah, AR_RTC_RESET, 0);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301418
Sujith7d0d0df2010-04-16 11:53:57 +05301419 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301420
Senthil Balasubramanian84e21692010-04-15 17:38:30 -04001421 if (!AR_SREV_9300_20_OR_LATER(ah))
1422 udelay(2);
1423
1424 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301425 REG_WRITE(ah, AR_RC, 0);
1426
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001427 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301428
1429 if (!ath9k_hw_wait(ah,
1430 AR_RTC_STATUS,
1431 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301432 AR_RTC_STATUS_ON,
1433 AH_WAIT_TIMEOUT)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001434 ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301435 return false;
1436 }
1437
Sujithf1dc5602008-10-29 10:16:30 +05301438 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1439}
1440
Sujithcbe61d82009-02-09 13:27:12 +05301441static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301442{
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301443 bool ret = false;
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05301444
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04001445 if (AR_SREV_9300_20_OR_LATER(ah)) {
1446 REG_WRITE(ah, AR_WA, ah->WARegVal);
1447 udelay(10);
1448 }
1449
Sujithf1dc5602008-10-29 10:16:30 +05301450 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1451 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1452
Felix Fietkauceb26a62012-10-03 21:07:51 +02001453 if (!ah->reset_power_on)
1454 type = ATH9K_RESET_POWER_ON;
1455
Sujithf1dc5602008-10-29 10:16:30 +05301456 switch (type) {
1457 case ATH9K_RESET_POWER_ON:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301458 ret = ath9k_hw_set_reset_power_on(ah);
Felix Fietkauceb26a62012-10-03 21:07:51 +02001459 if (!ret)
1460 ah->reset_power_on = true;
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301461 break;
Sujithf1dc5602008-10-29 10:16:30 +05301462 case ATH9K_RESET_WARM:
1463 case ATH9K_RESET_COLD:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301464 ret = ath9k_hw_set_reset(ah, type);
1465 break;
Sujithf1dc5602008-10-29 10:16:30 +05301466 default:
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301467 break;
Sujithf1dc5602008-10-29 10:16:30 +05301468 }
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301469
Mohammed Shafi Shajakhan7a9233f2011-11-30 10:41:25 +05301470 return ret;
Sujithf1dc5602008-10-29 10:16:30 +05301471}
1472
Sujithcbe61d82009-02-09 13:27:12 +05301473static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301474 struct ath9k_channel *chan)
1475{
Felix Fietkau9c083af2012-03-03 15:17:02 +01001476 int reset_type = ATH9K_RESET_WARM;
1477
1478 if (AR_SREV_9280(ah)) {
1479 if (ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1480 reset_type = ATH9K_RESET_POWER_ON;
1481 else
1482 reset_type = ATH9K_RESET_COLD;
1483 }
1484
1485 if (!ath9k_hw_set_reset_reg(ah, reset_type))
Sujithf1dc5602008-10-29 10:16:30 +05301486 return false;
1487
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001488 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301489 return false;
1490
Sujith2660b812009-02-09 13:27:26 +05301491 ah->chip_fullsleep = false;
Felix Fietkaubfc441a2012-05-24 14:32:22 +02001492
1493 if (AR_SREV_9330(ah))
1494 ar9003_hw_internal_regulator_apply(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301495 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301496 ath9k_hw_set_rfmode(ah, chan);
1497
1498 return true;
1499}
1500
Sujithcbe61d82009-02-09 13:27:12 +05301501static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001502 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301503{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001504 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001505 u32 qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001506 int r;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301507 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
1508 bool band_switch, mode_diff;
1509 u8 ini_reloaded;
1510
1511 band_switch = (chan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ)) !=
1512 (ah->curchan->channelFlags & (CHANNEL_2GHZ |
1513 CHANNEL_5GHZ));
1514 mode_diff = (chan->chanmode != ah->curchan->chanmode);
Sujithf1dc5602008-10-29 10:16:30 +05301515
1516 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1517 if (ath9k_hw_numtxpending(ah, qnum)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001518 ath_dbg(common, QUEUE,
Joe Perches226afe62010-12-02 19:12:37 -08001519 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301520 return false;
1521 }
1522 }
1523
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001524 if (!ath9k_hw_rfbus_req(ah)) {
Joe Perches38002762010-12-02 19:12:36 -08001525 ath_err(common, "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301526 return false;
1527 }
1528
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301529 if (edma && (band_switch || mode_diff)) {
1530 ath9k_hw_mark_phy_inactive(ah);
1531 udelay(5);
1532
1533 ath9k_hw_init_pll(ah, NULL);
1534
1535 if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
1536 ath_err(common, "Failed to do fast channel change\n");
1537 return false;
1538 }
1539 }
1540
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001541 ath9k_hw_set_channel_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301542
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001543 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001544 if (r) {
Joe Perches38002762010-12-02 19:12:36 -08001545 ath_err(common, "Failed to set channel\n");
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001546 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301547 }
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001548 ath9k_hw_set_clockrate(ah);
Gabor Juhos64ea57d2012-04-15 20:38:05 +02001549 ath9k_hw_apply_txpower(ah, chan, false);
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001550 ath9k_hw_rfbus_done(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301551
1552 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1553 ath9k_hw_set_delta_slope(ah, chan);
1554
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001555 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301556
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301557 if (edma && (band_switch || mode_diff)) {
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301558 ah->ah_flags |= AH_FASTCC;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301559 if (band_switch || ini_reloaded)
1560 ah->eep_ops->set_board_values(ah, chan);
1561
1562 ath9k_hw_init_bb(ah, chan);
1563
1564 if (band_switch || ini_reloaded)
1565 ath9k_hw_init_cal(ah, chan);
Rajkumar Manoharana126ff52011-10-13 11:00:42 +05301566 ah->ah_flags &= ~AH_FASTCC;
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301567 }
1568
Sujithf1dc5602008-10-29 10:16:30 +05301569 return true;
1570}
1571
Felix Fietkau691680b2011-03-19 13:55:38 +01001572static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
1573{
1574 u32 gpio_mask = ah->gpio_mask;
1575 int i;
1576
1577 for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
1578 if (!(gpio_mask & 1))
1579 continue;
1580
1581 ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1582 ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
1583 }
1584}
1585
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301586static bool ath9k_hw_check_dcs(u32 dma_dbg, u32 num_dcu_states,
1587 int *hang_state, int *hang_pos)
1588{
1589 static u32 dcu_chain_state[] = {5, 6, 9}; /* DCU chain stuck states */
1590 u32 chain_state, dcs_pos, i;
1591
1592 for (dcs_pos = 0; dcs_pos < num_dcu_states; dcs_pos++) {
1593 chain_state = (dma_dbg >> (5 * dcs_pos)) & 0x1f;
1594 for (i = 0; i < 3; i++) {
1595 if (chain_state == dcu_chain_state[i]) {
1596 *hang_state = chain_state;
1597 *hang_pos = dcs_pos;
1598 return true;
1599 }
1600 }
1601 }
1602 return false;
1603}
1604
1605#define DCU_COMPLETE_STATE 1
1606#define DCU_COMPLETE_STATE_MASK 0x3
1607#define NUM_STATUS_READS 50
1608static bool ath9k_hw_detect_mac_hang(struct ath_hw *ah)
1609{
1610 u32 chain_state, comp_state, dcs_reg = AR_DMADBG_4;
1611 u32 i, hang_pos, hang_state, num_state = 6;
1612
1613 comp_state = REG_READ(ah, AR_DMADBG_6);
1614
1615 if ((comp_state & DCU_COMPLETE_STATE_MASK) != DCU_COMPLETE_STATE) {
1616 ath_dbg(ath9k_hw_common(ah), RESET,
1617 "MAC Hang signature not found at DCU complete\n");
1618 return false;
1619 }
1620
1621 chain_state = REG_READ(ah, dcs_reg);
1622 if (ath9k_hw_check_dcs(chain_state, num_state, &hang_state, &hang_pos))
1623 goto hang_check_iter;
1624
1625 dcs_reg = AR_DMADBG_5;
1626 num_state = 4;
1627 chain_state = REG_READ(ah, dcs_reg);
1628 if (ath9k_hw_check_dcs(chain_state, num_state, &hang_state, &hang_pos))
1629 goto hang_check_iter;
1630
1631 ath_dbg(ath9k_hw_common(ah), RESET,
1632 "MAC Hang signature 1 not found\n");
1633 return false;
1634
1635hang_check_iter:
1636 ath_dbg(ath9k_hw_common(ah), RESET,
1637 "DCU registers: chain %08x complete %08x Hang: state %d pos %d\n",
1638 chain_state, comp_state, hang_state, hang_pos);
1639
1640 for (i = 0; i < NUM_STATUS_READS; i++) {
1641 chain_state = REG_READ(ah, dcs_reg);
1642 chain_state = (chain_state >> (5 * hang_pos)) & 0x1f;
1643 comp_state = REG_READ(ah, AR_DMADBG_6);
1644
1645 if (((comp_state & DCU_COMPLETE_STATE_MASK) !=
1646 DCU_COMPLETE_STATE) ||
1647 (chain_state != hang_state))
1648 return false;
1649 }
1650
1651 ath_dbg(ath9k_hw_common(ah), RESET, "MAC Hang signature 1 found\n");
1652
1653 return true;
1654}
1655
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001656bool ath9k_hw_check_alive(struct ath_hw *ah)
Johannes Berg3b319aa2009-06-13 14:50:26 +05301657{
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001658 int count = 50;
1659 u32 reg;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301660
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301661 if (AR_SREV_9300(ah))
1662 return !ath9k_hw_detect_mac_hang(ah);
1663
Felix Fietkaue17f83e2010-09-22 12:34:53 +02001664 if (AR_SREV_9285_12_OR_LATER(ah))
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001665 return true;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301666
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001667 do {
1668 reg = REG_READ(ah, AR_OBS_BUS_1);
1669
1670 if ((reg & 0x7E7FFFEF) == 0x00702400)
1671 continue;
1672
1673 switch (reg & 0x7E000B00) {
1674 case 0x1E000000:
1675 case 0x52000B00:
1676 case 0x18000B00:
1677 continue;
1678 default:
1679 return true;
1680 }
1681 } while (count-- > 0);
1682
1683 return false;
Johannes Berg3b319aa2009-06-13 14:50:26 +05301684}
Felix Fietkauc9c99e52010-04-19 19:57:29 +02001685EXPORT_SYMBOL(ath9k_hw_check_alive);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301686
Sujith Manoharancaed6572012-03-14 14:40:46 +05301687/*
1688 * Fast channel change:
1689 * (Change synthesizer based on channel freq without resetting chip)
1690 *
1691 * Don't do FCC when
1692 * - Flag is not set
1693 * - Chip is just coming out of full sleep
1694 * - Channel to be set is same as current channel
1695 * - Channel flags are different, (eg.,moving from 2GHz to 5GHz channel)
1696 */
1697static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
1698{
1699 struct ath_common *common = ath9k_hw_common(ah);
1700 int ret;
1701
1702 if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
1703 goto fail;
1704
1705 if (ah->chip_fullsleep)
1706 goto fail;
1707
1708 if (!ah->curchan)
1709 goto fail;
1710
1711 if (chan->channel == ah->curchan->channel)
1712 goto fail;
1713
Felix Fietkaufeb7bc92012-04-19 21:18:28 +02001714 if ((ah->curchan->channelFlags | chan->channelFlags) &
1715 (CHANNEL_HALF | CHANNEL_QUARTER))
1716 goto fail;
1717
Sujith Manoharancaed6572012-03-14 14:40:46 +05301718 if ((chan->channelFlags & CHANNEL_ALL) !=
1719 (ah->curchan->channelFlags & CHANNEL_ALL))
1720 goto fail;
1721
1722 if (!ath9k_hw_check_alive(ah))
1723 goto fail;
1724
1725 /*
1726 * For AR9462, make sure that calibration data for
1727 * re-using are present.
1728 */
Sujith Manoharan8a905552012-05-04 13:23:59 +05301729 if (AR_SREV_9462(ah) && (ah->caldata &&
1730 (!ah->caldata->done_txiqcal_once ||
1731 !ah->caldata->done_txclcal_once ||
1732 !ah->caldata->rtt_done)))
Sujith Manoharancaed6572012-03-14 14:40:46 +05301733 goto fail;
1734
1735 ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n",
1736 ah->curchan->channel, chan->channel);
1737
1738 ret = ath9k_hw_channel_change(ah, chan);
1739 if (!ret)
1740 goto fail;
1741
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301742 if (ath9k_hw_mci_is_enabled(ah))
Rajkumar Manoharan1bde95fa2012-06-11 12:19:33 +05301743 ar9003_mci_2g5g_switch(ah, false);
Sujith Manoharancaed6572012-03-14 14:40:46 +05301744
Rajkumar Manoharan88033312012-09-12 18:59:19 +05301745 ath9k_hw_loadnf(ah, ah->curchan);
1746 ath9k_hw_start_nfcal(ah, true);
1747
Sujith Manoharancaed6572012-03-14 14:40:46 +05301748 if (AR_SREV_9271(ah))
1749 ar9002_hw_load_ani_reg(ah, chan);
1750
1751 return 0;
1752fail:
1753 return -EINVAL;
1754}
1755
Sujithcbe61d82009-02-09 13:27:12 +05301756int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Sujith Manoharancaed6572012-03-14 14:40:46 +05301757 struct ath9k_hw_cal_data *caldata, bool fastcc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001758{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001759 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001760 u32 saveLedState;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001761 u32 saveDefAntenna;
1762 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301763 u64 tsf = 0;
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001764 int i, r;
Sujith Manoharancaed6572012-03-14 14:40:46 +05301765 bool start_mci_reset = false;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301766 bool save_fullsleep = ah->chip_fullsleep;
1767
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301768 if (ath9k_hw_mci_is_enabled(ah)) {
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301769 start_mci_reset = ar9003_mci_start_reset(ah, chan);
1770 if (start_mci_reset)
1771 return 0;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301772 }
1773
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001774 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001775 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001776
Sujith Manoharancaed6572012-03-14 14:40:46 +05301777 if (ah->curchan && !ah->chip_fullsleep)
1778 ath9k_hw_getnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001779
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001780 ah->caldata = caldata;
1781 if (caldata &&
1782 (chan->channel != caldata->channel ||
1783 (chan->channelFlags & ~CHANNEL_CW_INT) !=
1784 (caldata->channelFlags & ~CHANNEL_CW_INT))) {
1785 /* Operating channel changed, reset channel calibration data */
1786 memset(caldata, 0, sizeof(*caldata));
1787 ath9k_init_nfcal_hist_buffer(ah, chan);
Felix Fietkau51dea9b2012-08-27 17:00:07 +02001788 } else if (caldata) {
1789 caldata->paprd_packet_sent = false;
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001790 }
Felix Fietkauf23fba42011-07-28 14:08:56 +02001791 ah->noise = ath9k_hw_getchan_noise(ah, chan);
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001792
Sujith Manoharancaed6572012-03-14 14:40:46 +05301793 if (fastcc) {
1794 r = ath9k_hw_do_fastcc(ah, chan);
1795 if (!r)
1796 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001797 }
1798
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301799 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301800 ar9003_mci_stop_bt(ah, save_fullsleep);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301801
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001802 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1803 if (saveDefAntenna == 0)
1804 saveDefAntenna = 1;
1805
1806 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1807
Sujith46fe7822009-09-17 09:25:25 +05301808 /* For chips on which RTC reset is done, save TSF before it gets cleared */
Felix Fietkauf860d522010-06-30 02:07:48 +02001809 if (AR_SREV_9100(ah) ||
1810 (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)))
Sujith46fe7822009-09-17 09:25:25 +05301811 tsf = ath9k_hw_gettsf64(ah);
1812
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001813 saveLedState = REG_READ(ah, AR_CFG_LED) &
1814 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1815 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1816
1817 ath9k_hw_mark_phy_inactive(ah);
1818
Vasanthakumar Thiagarajan45ef6a02010-12-15 07:30:53 -08001819 ah->paprd_table_write_done = false;
1820
Sujith05020d22010-03-17 14:25:23 +05301821 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001822 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1823 REG_WRITE(ah,
1824 AR9271_RESET_POWER_DOWN_CONTROL,
1825 AR9271_RADIO_RF_RST);
1826 udelay(50);
1827 }
1828
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001829 if (!ath9k_hw_chip_reset(ah, chan)) {
Joe Perches38002762010-12-02 19:12:36 -08001830 ath_err(common, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001831 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001832 }
1833
Sujith05020d22010-03-17 14:25:23 +05301834 /* Only required on the first reset */
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001835 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1836 ah->htc_reset_init = false;
1837 REG_WRITE(ah,
1838 AR9271_RESET_POWER_DOWN_CONTROL,
1839 AR9271_GATE_MAC_CTL);
1840 udelay(50);
1841 }
1842
Sujith46fe7822009-09-17 09:25:25 +05301843 /* Restore TSF */
Felix Fietkauf860d522010-06-30 02:07:48 +02001844 if (tsf)
Sujith46fe7822009-09-17 09:25:25 +05301845 ath9k_hw_settsf64(ah, tsf);
1846
Felix Fietkau7a370812010-09-22 12:34:52 +02001847 if (AR_SREV_9280_20_OR_LATER(ah))
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301848 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001849
Sujithe9141f72010-06-01 15:14:10 +05301850 if (!AR_SREV_9300_20_OR_LATER(ah))
1851 ar9002_hw_enable_async_fifo(ah);
1852
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001853 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001854 if (r)
1855 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001856
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301857 if (ath9k_hw_mci_is_enabled(ah))
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301858 ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
1859
Felix Fietkauf860d522010-06-30 02:07:48 +02001860 /*
1861 * Some AR91xx SoC devices frequently fail to accept TSF writes
1862 * right after the chip reset. When that happens, write a new
1863 * value after the initvals have been applied, with an offset
1864 * based on measured time difference
1865 */
1866 if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
1867 tsf += 1500;
1868 ath9k_hw_settsf64(ah, tsf);
1869 }
1870
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001871 /* Setup MFP options for CCMP */
1872 if (AR_SREV_9280_20_OR_LATER(ah)) {
1873 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1874 * frames when constructing CCMP AAD. */
1875 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1876 0xc7ff);
1877 ah->sw_mgmt_crypto = false;
1878 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1879 /* Disable hardware crypto for management frames */
1880 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1881 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1882 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1883 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1884 ah->sw_mgmt_crypto = true;
1885 } else
1886 ah->sw_mgmt_crypto = true;
1887
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001888 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1889 ath9k_hw_set_delta_slope(ah, chan);
1890
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001891 ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05301892 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04001893
Sujith7d0d0df2010-04-16 11:53:57 +05301894 ENABLE_REGWRITE_BUFFER(ah);
1895
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001896 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
1897 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001898 | macStaId1
1899 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05301900 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05301901 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05301902 | ah->sta_id1_defaults);
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001903 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001904 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07001905 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001906 REG_WRITE(ah, AR_ISR, ~0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001907 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1908
Sujith7d0d0df2010-04-16 11:53:57 +05301909 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301910
Sujith Manoharan00e00032011-01-26 21:59:05 +05301911 ath9k_hw_set_operating_mode(ah, ah->opmode);
1912
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001913 r = ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001914 if (r)
1915 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001916
Felix Fietkaudfdac8a2010-10-08 22:13:51 +02001917 ath9k_hw_set_clockrate(ah);
1918
Sujith7d0d0df2010-04-16 11:53:57 +05301919 ENABLE_REGWRITE_BUFFER(ah);
1920
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001921 for (i = 0; i < AR_NUM_DCU; i++)
1922 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1923
Sujith7d0d0df2010-04-16 11:53:57 +05301924 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301925
Sujith2660b812009-02-09 13:27:26 +05301926 ah->intr_txqs = 0;
Felix Fietkauf4c607d2011-03-23 20:57:28 +01001927 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001928 ath9k_hw_resettxqueue(ah, i);
1929
Sujith2660b812009-02-09 13:27:26 +05301930 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001931 ath9k_hw_ani_cache_ini_regs(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001932 ath9k_hw_init_qos(ah);
1933
Sujith2660b812009-02-09 13:27:26 +05301934 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Felix Fietkau55821322010-12-17 00:57:01 +01001935 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
Johannes Berg3b319aa2009-06-13 14:50:26 +05301936
Felix Fietkau0005baf2010-01-15 02:33:40 +01001937 ath9k_hw_init_global_settings(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001938
Felix Fietkaufe2b6af2011-07-09 11:12:51 +07001939 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1940 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1941 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1942 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1943 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1944 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1945 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301946 }
1947
Felix Fietkauca7a4de2011-03-23 20:57:26 +01001948 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001949
1950 ath9k_hw_set_dma(ah);
1951
Rajkumar Manoharaned6ebd82012-06-11 12:19:34 +05301952 if (!ath9k_hw_mci_is_enabled(ah))
1953 REG_WRITE(ah, AR_OBS, 8);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001954
Sujith0ce024c2009-12-14 14:57:00 +05301955 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001956 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1957 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1958 }
1959
Vasanthakumar Thiagarajan7f62a132010-04-15 17:39:19 -04001960 if (ah->config.tx_intr_mitigation) {
1961 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1962 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1963 }
1964
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001965 ath9k_hw_init_bb(ah, chan);
1966
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301967 if (caldata) {
Rajkumar Manoharan5f0c04e2011-10-13 11:00:35 +05301968 caldata->done_txiqcal_once = false;
Rajkumar Manoharan77a5a662011-10-13 11:00:37 +05301969 caldata->done_txclcal_once = false;
1970 }
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001971 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07001972 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001973
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05301974 if (ath9k_hw_mci_is_enabled(ah) && ar9003_mci_end_reset(ah, chan, caldata))
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301975 return -EIO;
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05301976
Sujith7d0d0df2010-04-16 11:53:57 +05301977 ENABLE_REGWRITE_BUFFER(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001978
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -04001979 ath9k_hw_restore_chainmask(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001980 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1981
Sujith7d0d0df2010-04-16 11:53:57 +05301982 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05301983
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001984 /*
1985 * For big endian systems turn on swapping for descriptors
1986 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001987 if (AR_SREV_9100(ah)) {
1988 u32 mask;
1989 mask = REG_READ(ah, AR_CFG);
1990 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001991 ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n",
1992 mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001993 } else {
1994 mask =
1995 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1996 REG_WRITE(ah, AR_CFG, mask);
Joe Perchesd2182b62011-12-15 14:55:53 -08001997 ath_dbg(common, RESET, "Setting CFG 0x%x\n",
1998 REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001999 }
2000 } else {
Sujithcbba8cd2010-06-02 15:53:31 +05302001 if (common->bus_ops->ath_bus_type == ATH_USB) {
2002 /* Configure AR9271 target WLAN */
2003 if (AR_SREV_9271(ah))
2004 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
2005 else
2006 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
2007 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002008#ifdef __BIG_ENDIAN
Gabor Juhos2f8d10fd2012-07-03 19:13:21 +02002009 else if (AR_SREV_9330(ah) || AR_SREV_9340(ah) ||
2010 AR_SREV_9550(ah))
Vasanthakumar Thiagarajan2be7bfe2011-04-19 19:29:14 +05302011 REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
2012 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002013 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002014#endif
2015 }
2016
Sujith Manoharandbccdd12012-02-22 17:55:47 +05302017 if (ath9k_hw_btcoex_is_enabled(ah))
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302018 ath9k_hw_btcoex_enable(ah);
2019
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05302020 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan528e5d32012-02-22 12:41:12 +05302021 ar9003_mci_check_bt(ah);
Mohammed Shafi Shajakhan63d32962011-11-30 10:41:27 +05302022
Rajkumar Manoharan1fe860ed2012-07-01 19:53:51 +05302023 ath9k_hw_loadnf(ah, chan);
2024 ath9k_hw_start_nfcal(ah, true);
2025
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05302026 if (AR_SREV_9300_20_OR_LATER(ah)) {
Luis R. Rodriguezaea702b2010-05-13 13:33:43 -04002027 ar9003_hw_bb_watchdog_config(ah);
Vasanthakumar Thiagarajand8903a52010-04-15 17:39:25 -04002028
Rajkumar Manoharan51ac8cb2011-05-20 17:52:13 +05302029 ar9003_hw_disable_phy_restart(ah);
2030 }
2031
Felix Fietkau691680b2011-03-19 13:55:38 +01002032 ath9k_hw_apply_gpio_override(ah);
2033
Sujith Manoharan362cd032012-09-16 08:06:36 +05302034 if (AR_SREV_9565(ah) && ah->shared_chain_lnadiv)
2035 REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON);
2036
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002037 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002038}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002039EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002040
Sujithf1dc5602008-10-29 10:16:30 +05302041/******************************/
2042/* Power Management (Chipset) */
2043/******************************/
2044
Luis R. Rodriguez42d5bc32010-04-15 17:38:12 -04002045/*
2046 * Notify Power Mgt is disabled in self-generated frames.
2047 * If requested, force chip to sleep.
2048 */
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302049static void ath9k_set_power_sleep(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302050{
2051 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302052
Sujith Manoharana4a29542012-09-10 09:20:03 +05302053 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05302054 REG_CLR_BIT(ah, AR_TIMER_MODE, 0xff);
2055 REG_CLR_BIT(ah, AR_NDP2_TIMER_MODE, 0xff);
2056 REG_CLR_BIT(ah, AR_SLP32_INC, 0xfffff);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302057 /* xxx Required for WLAN only case ? */
2058 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
2059 udelay(100);
2060 }
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302061
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302062 /*
2063 * Clear the RTC force wake bit to allow the
2064 * mac to go to sleep.
2065 */
2066 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302067
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05302068 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302069 udelay(100);
Sujithf1dc5602008-10-29 10:16:30 +05302070
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302071 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
2072 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2073
2074 /* Shutdown chip. Active low */
2075 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
2076 REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
2077 udelay(2);
Sujithf1dc5602008-10-29 10:16:30 +05302078 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04002079
2080 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
Rafael J. Wysockia7322812011-11-26 23:37:43 +01002081 if (AR_SREV_9300_20_OR_LATER(ah))
2082 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002083}
2084
Luis R. Rodriguezbbd79af2010-04-15 17:38:16 -04002085/*
2086 * Notify Power Management is enabled in self-generating
2087 * frames. If request, set power mode of chip to
2088 * auto/normal. Duration in units of 128us (1/8 TU).
2089 */
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302090static void ath9k_set_power_network_sleep(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002091{
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302092 struct ath9k_hw_capabilities *pCap = &ah->caps;
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302093
Sujithf1dc5602008-10-29 10:16:30 +05302094 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002095
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302096 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2097 /* Set WakeOnInterrupt bit; clear ForceWake bit */
2098 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2099 AR_RTC_FORCE_WAKE_ON_INT);
2100 } else {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302101
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302102 /* When chip goes into network sleep, it could be waken
2103 * up by MCI_INT interrupt caused by BT's HW messages
2104 * (LNA_xxx, CONT_xxx) which chould be in a very fast
2105 * rate (~100us). This will cause chip to leave and
2106 * re-enter network sleep mode frequently, which in
2107 * consequence will have WLAN MCI HW to generate lots of
2108 * SYS_WAKING and SYS_SLEEPING messages which will make
2109 * BT CPU to busy to process.
2110 */
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05302111 if (ath9k_hw_mci_is_enabled(ah))
2112 REG_CLR_BIT(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
2113 AR_MCI_INTERRUPT_RX_HW_MSG_MASK);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302114 /*
2115 * Clear the RTC force wake bit to allow the
2116 * mac to go to sleep.
2117 */
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05302118 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302119
Rajkumar Manoharan153dccd2012-06-04 16:28:47 +05302120 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302121 udelay(30);
Sujithf1dc5602008-10-29 10:16:30 +05302122 }
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04002123
2124 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
2125 if (AR_SREV_9300_20_OR_LATER(ah))
2126 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
Sujithf1dc5602008-10-29 10:16:30 +05302127}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002128
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302129static bool ath9k_hw_set_power_awake(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302130{
2131 u32 val;
2132 int i;
2133
Luis R. Rodriguez9a658d22010-06-21 18:38:47 -04002134 /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
2135 if (AR_SREV_9300_20_OR_LATER(ah)) {
2136 REG_WRITE(ah, AR_WA, ah->WARegVal);
2137 udelay(10);
2138 }
2139
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302140 if ((REG_READ(ah, AR_RTC_STATUS) &
2141 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2142 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Sujithf1dc5602008-10-29 10:16:30 +05302143 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002144 }
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302145 if (!AR_SREV_9300_20_OR_LATER(ah))
2146 ath9k_hw_init_pll(ah, NULL);
2147 }
2148 if (AR_SREV_9100(ah))
2149 REG_SET_BIT(ah, AR_RTC_RESET,
2150 AR_RTC_RESET_EN);
2151
2152 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2153 AR_RTC_FORCE_WAKE_EN);
2154 udelay(50);
2155
2156 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2157 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2158 if (val == AR_RTC_STATUS_ON)
2159 break;
2160 udelay(50);
2161 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2162 AR_RTC_FORCE_WAKE_EN);
2163 }
2164 if (i == 0) {
2165 ath_err(ath9k_hw_common(ah),
2166 "Failed to wakeup in %uus\n",
2167 POWER_UP_TIME / 20);
2168 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002169 }
2170
Rajkumar Manoharancdbe4082012-10-25 17:16:53 +05302171 if (ath9k_hw_mci_is_enabled(ah))
2172 ar9003_mci_set_power_awake(ah);
2173
Sujithf1dc5602008-10-29 10:16:30 +05302174 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2175
2176 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002177}
2178
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002179bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302180{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002181 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302182 int status = true;
Sujithf1dc5602008-10-29 10:16:30 +05302183 static const char *modes[] = {
2184 "AWAKE",
2185 "FULL-SLEEP",
2186 "NETWORK SLEEP",
2187 "UNDEFINED"
2188 };
Sujithf1dc5602008-10-29 10:16:30 +05302189
Gabor Juhoscbdec972009-07-24 17:27:22 +02002190 if (ah->power_mode == mode)
2191 return status;
2192
Joe Perchesd2182b62011-12-15 14:55:53 -08002193 ath_dbg(common, RESET, "%s -> %s\n",
Joe Perches226afe62010-12-02 19:12:37 -08002194 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302195
2196 switch (mode) {
2197 case ATH9K_PM_AWAKE:
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302198 status = ath9k_hw_set_power_awake(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302199 break;
2200 case ATH9K_PM_FULL_SLEEP:
Sujith Manoharan5955b2b2012-06-04 16:27:30 +05302201 if (ath9k_hw_mci_is_enabled(ah))
Sujith Manoharand1ca8b82012-02-22 12:41:01 +05302202 ar9003_mci_set_full_sleep(ah);
Mohammed Shafi Shajakhan10109112011-11-30 10:41:24 +05302203
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302204 ath9k_set_power_sleep(ah);
Sujith2660b812009-02-09 13:27:26 +05302205 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302206 break;
2207 case ATH9K_PM_NETWORK_SLEEP:
Sujith Manoharan31604cf2012-06-04 16:27:36 +05302208 ath9k_set_power_network_sleep(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302209 break;
2210 default:
Joe Perches38002762010-12-02 19:12:36 -08002211 ath_err(common, "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302212 return false;
2213 }
Sujith2660b812009-02-09 13:27:26 +05302214 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302215
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002216 /*
2217 * XXX: If this warning never comes up after a while then
2218 * simply keep the ATH_DBG_WARN_ON_ONCE() but make
2219 * ath9k_hw_setpower() return type void.
2220 */
Sujith Manoharan97dcec52010-12-20 08:02:42 +05302221
2222 if (!(ah->ah_flags & AH_UNPLUGGED))
2223 ATH_DBG_WARN_ON_ONCE(!status);
Luis R. Rodriguez69f4aab2010-12-07 15:13:23 -08002224
Sujithf1dc5602008-10-29 10:16:30 +05302225 return status;
2226}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002227EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302228
Sujithf1dc5602008-10-29 10:16:30 +05302229/*******************/
2230/* Beacon Handling */
2231/*******************/
2232
Sujithcbe61d82009-02-09 13:27:12 +05302233void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002234{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002235 int flags = 0;
2236
Sujith7d0d0df2010-04-16 11:53:57 +05302237 ENABLE_REGWRITE_BUFFER(ah);
2238
Sujith2660b812009-02-09 13:27:26 +05302239 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002240 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002241 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002242 REG_SET_BIT(ah, AR_TXCFG,
2243 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
Felix Fietkaudd347f22011-03-22 21:54:17 +01002244 REG_WRITE(ah, AR_NEXT_NDP_TIMER, next_beacon +
2245 TU_TO_USEC(ah->atim_window ? ah->atim_window : 1));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002246 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002247 case NL80211_IFTYPE_AP:
Felix Fietkaudd347f22011-03-22 21:54:17 +01002248 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
2249 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
2250 TU_TO_USEC(ah->config.dma_beacon_response_time));
2251 REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
2252 TU_TO_USEC(ah->config.sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002253 flags |=
2254 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2255 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002256 default:
Joe Perchesd2182b62011-12-15 14:55:53 -08002257 ath_dbg(ath9k_hw_common(ah), BEACON,
2258 "%s: unsupported opmode: %d\n", __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08002259 return;
2260 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002261 }
2262
Felix Fietkaudd347f22011-03-22 21:54:17 +01002263 REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
2264 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
2265 REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
2266 REG_WRITE(ah, AR_NDP_PERIOD, beacon_period);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002267
Sujith7d0d0df2010-04-16 11:53:57 +05302268 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302269
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002270 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2271}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002272EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002273
Sujithcbe61d82009-02-09 13:27:12 +05302274void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302275 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002276{
2277 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05302278 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002279 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002280
Sujith7d0d0df2010-04-16 11:53:57 +05302281 ENABLE_REGWRITE_BUFFER(ah);
2282
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002283 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
2284
2285 REG_WRITE(ah, AR_BEACON_PERIOD,
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302286 TU_TO_USEC(bs->bs_intval));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002287 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302288 TU_TO_USEC(bs->bs_intval));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002289
Sujith7d0d0df2010-04-16 11:53:57 +05302290 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302291
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002292 REG_RMW_FIELD(ah, AR_RSSI_THR,
2293 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2294
Rajkumar Manoharanf29f5c02011-05-20 17:52:11 +05302295 beaconintval = bs->bs_intval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002296
2297 if (bs->bs_sleepduration > beaconintval)
2298 beaconintval = bs->bs_sleepduration;
2299
2300 dtimperiod = bs->bs_dtimperiod;
2301 if (bs->bs_sleepduration > dtimperiod)
2302 dtimperiod = bs->bs_sleepduration;
2303
2304 if (beaconintval == dtimperiod)
2305 nextTbtt = bs->bs_nextdtim;
2306 else
2307 nextTbtt = bs->bs_nexttbtt;
2308
Joe Perchesd2182b62011-12-15 14:55:53 -08002309 ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2310 ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt);
2311 ath_dbg(common, BEACON, "beacon period %d\n", beaconintval);
2312 ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002313
Sujith7d0d0df2010-04-16 11:53:57 +05302314 ENABLE_REGWRITE_BUFFER(ah);
2315
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002316 REG_WRITE(ah, AR_NEXT_DTIM,
2317 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
2318 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
2319
2320 REG_WRITE(ah, AR_SLEEP1,
2321 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2322 | AR_SLEEP1_ASSUME_DTIM);
2323
Sujith60b67f52008-08-07 10:52:38 +05302324 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002325 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2326 else
2327 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2328
2329 REG_WRITE(ah, AR_SLEEP2,
2330 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2331
2332 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
2333 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
2334
Sujith7d0d0df2010-04-16 11:53:57 +05302335 REGWRITE_BUFFER_FLUSH(ah);
Sujith7d0d0df2010-04-16 11:53:57 +05302336
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002337 REG_SET_BIT(ah, AR_TIMER_MODE,
2338 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2339 AR_DTIM_TIMER_EN);
2340
Sujith4af9cf42009-02-12 10:06:47 +05302341 /* TSF Out of Range Threshold */
2342 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002343}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002344EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002345
Sujithf1dc5602008-10-29 10:16:30 +05302346/*******************/
2347/* HW Capabilities */
2348/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002349
Felix Fietkau60540692011-07-19 08:46:44 +02002350static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
2351{
2352 eeprom_chainmask &= chip_chainmask;
2353 if (eeprom_chainmask)
2354 return eeprom_chainmask;
2355 else
2356 return chip_chainmask;
2357}
2358
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002359/**
2360 * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset
2361 * @ah: the atheros hardware data structure
2362 *
2363 * We enable DFS support upstream on chipsets which have passed a series
2364 * of tests. The testing requirements are going to be documented. Desired
2365 * test requirements are documented at:
2366 *
2367 * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs
2368 *
2369 * Once a new chipset gets properly tested an individual commit can be used
2370 * to document the testing for DFS for that chipset.
2371 */
2372static bool ath9k_hw_dfs_tested(struct ath_hw *ah)
2373{
2374
2375 switch (ah->hw_version.macVersion) {
2376 /* AR9580 will likely be our first target to get testing on */
2377 case AR_SREV_VERSION_9580:
2378 default:
2379 return false;
2380 }
2381}
2382
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002383int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002384{
Sujith2660b812009-02-09 13:27:26 +05302385 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002386 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002387 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau60540692011-07-19 08:46:44 +02002388 unsigned int chip_chainmask;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002389
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +05302390 u16 eeval;
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002391 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002392
Sujithf74df6f2009-02-09 13:27:24 +05302393 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002394 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05302395
Sujith2660b812009-02-09 13:27:26 +05302396 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05302397 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07002398 if (regulatory->current_rd == 0x64 ||
2399 regulatory->current_rd == 0x65)
2400 regulatory->current_rd += 5;
2401 else if (regulatory->current_rd == 0x41)
2402 regulatory->current_rd = 0x43;
Joe Perchesd2182b62011-12-15 14:55:53 -08002403 ath_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n",
2404 regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002405 }
Sujithdc2222a2008-08-14 13:26:55 +05302406
Sujithf74df6f2009-02-09 13:27:24 +05302407 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002408 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
Joe Perches38002762010-12-02 19:12:36 -08002409 ath_err(common,
2410 "no band has been marked as supported in EEPROM\n");
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002411 return -EINVAL;
2412 }
2413
Felix Fietkaud4659912010-10-14 16:02:39 +02002414 if (eeval & AR5416_OPFLAGS_11A)
2415 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002416
Felix Fietkaud4659912010-10-14 16:02:39 +02002417 if (eeval & AR5416_OPFLAGS_11G)
2418 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
Sujithf1dc5602008-10-29 10:16:30 +05302419
Sujith Manoharane41db612012-09-10 09:20:12 +05302420 if (AR_SREV_9485(ah) ||
2421 AR_SREV_9285(ah) ||
2422 AR_SREV_9330(ah) ||
2423 AR_SREV_9565(ah))
Felix Fietkau60540692011-07-19 08:46:44 +02002424 chip_chainmask = 1;
Mohammed Shafi Shajakhanba5736a2011-11-30 21:10:52 +05302425 else if (AR_SREV_9462(ah))
2426 chip_chainmask = 3;
Felix Fietkau60540692011-07-19 08:46:44 +02002427 else if (!AR_SREV_9280_20_OR_LATER(ah))
2428 chip_chainmask = 7;
2429 else if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9340(ah))
2430 chip_chainmask = 3;
2431 else
2432 chip_chainmask = 7;
2433
Sujithf74df6f2009-02-09 13:27:24 +05302434 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002435 /*
2436 * For AR9271 we will temporarilly uses the rx chainmax as read from
2437 * the EEPROM.
2438 */
Sujith8147f5d2009-02-20 15:13:23 +05302439 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002440 !(eeval & AR5416_OPFLAGS_11A) &&
2441 !(AR_SREV_9271(ah)))
2442 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05302443 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
Felix Fietkau598cdd52011-03-19 13:55:42 +01002444 else if (AR_SREV_9100(ah))
2445 pCap->rx_chainmask = 0x7;
Sujith8147f5d2009-02-20 15:13:23 +05302446 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002447 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05302448 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05302449
Felix Fietkau60540692011-07-19 08:46:44 +02002450 pCap->tx_chainmask = fixup_chainmask(chip_chainmask, pCap->tx_chainmask);
2451 pCap->rx_chainmask = fixup_chainmask(chip_chainmask, pCap->rx_chainmask);
Felix Fietkau82b2d332011-09-03 01:40:23 +02002452 ah->txchainmask = pCap->tx_chainmask;
2453 ah->rxchainmask = pCap->rx_chainmask;
Felix Fietkau60540692011-07-19 08:46:44 +02002454
Felix Fietkau7a370812010-09-22 12:34:52 +02002455 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05302456
Felix Fietkau02d2ebb2010-11-22 15:39:39 +01002457 /* enable key search for every frame in an aggregate */
2458 if (AR_SREV_9300_20_OR_LATER(ah))
2459 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
2460
Bruno Randolfce2220d2010-09-17 11:36:25 +09002461 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
2462
Felix Fietkau0db156e2011-03-23 20:57:29 +01002463 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
Sujithf1dc5602008-10-29 10:16:30 +05302464 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2465 else
2466 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2467
Sujith5b5fa352010-03-17 14:25:15 +05302468 if (AR_SREV_9271(ah))
2469 pCap->num_gpio_pins = AR9271_NUM_GPIO;
Sujith88c1f4f2010-06-30 14:46:31 +05302470 else if (AR_DEVID_7010(ah))
2471 pCap->num_gpio_pins = AR7010_NUM_GPIO;
Mohammed Shafi Shajakhan6321eb02011-09-30 11:31:27 +05302472 else if (AR_SREV_9300_20_OR_LATER(ah))
2473 pCap->num_gpio_pins = AR9300_NUM_GPIO;
2474 else if (AR_SREV_9287_11_OR_LATER(ah))
2475 pCap->num_gpio_pins = AR9287_NUM_GPIO;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002476 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302477 pCap->num_gpio_pins = AR9285_NUM_GPIO;
Felix Fietkau7a370812010-09-22 12:34:52 +02002478 else if (AR_SREV_9280_20_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302479 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2480 else
2481 pCap->num_gpio_pins = AR_NUM_GPIO;
2482
Mohammed Shafi Shajakhan1b2538b2011-12-07 16:51:39 +05302483 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302484 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
Mohammed Shafi Shajakhan1b2538b2011-12-07 16:51:39 +05302485 else
Sujithf1dc5602008-10-29 10:16:30 +05302486 pCap->rts_aggr_limit = (8 * 1024);
Sujithf1dc5602008-10-29 10:16:30 +05302487
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302488#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302489 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2490 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2491 ah->rfkill_gpio =
2492 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2493 ah->rfkill_polarity =
2494 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05302495
2496 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2497 }
2498#endif
Vasanthakumar Thiagarajand5d11542010-05-17 18:57:56 -07002499 if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
Vivek Natarajanbde748a2010-04-05 14:48:05 +05302500 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2501 else
2502 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05302503
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302504 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302505 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2506 else
2507 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2508
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002509 if (AR_SREV_9300_20_OR_LATER(ah)) {
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002510 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
Sujith Manoharana4a29542012-09-10 09:20:03 +05302511 if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah) && !AR_SREV_9565(ah))
Vasanthakumar Thiagarajan784ad502010-12-06 04:27:40 -08002512 pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
2513
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002514 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2515 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2516 pCap->rx_status_len = sizeof(struct ar9003_rxs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002517 pCap->tx_desc_len = sizeof(struct ar9003_txc);
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002518 pCap->txs_len = sizeof(struct ar9003_txs);
Vasanthakumar Thiagarajan162c3be2010-04-15 17:38:41 -04002519 } else {
2520 pCap->tx_desc_len = sizeof(struct ath_desc);
Felix Fietkaua949b172011-07-09 11:12:47 +07002521 if (AR_SREV_9280_20(ah))
Felix Fietkau6b42e8d2010-04-26 15:04:35 -04002522 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
Vasanthakumar Thiagarajanceb26442010-04-15 17:38:25 -04002523 }
Vasanthakumar Thiagarajan1adf02f2010-04-15 17:38:24 -04002524
Vasanthakumar Thiagarajan6c84ce02010-04-15 17:39:16 -04002525 if (AR_SREV_9300_20_OR_LATER(ah))
2526 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2527
Senthil Balasubramanian6ee63f52010-11-10 05:03:16 -08002528 if (AR_SREV_9300_20_OR_LATER(ah))
2529 ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
2530
Felix Fietkaua42acef2010-09-22 12:34:54 +02002531 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
Vasanthakumar Thiagarajan6473d242010-05-13 18:42:38 -07002532 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
2533
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002534 if (AR_SREV_9285(ah))
2535 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
2536 ant_div_ctl1 =
2537 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2538 if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))
2539 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2540 }
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302541 if (AR_SREV_9300_20_OR_LATER(ah)) {
2542 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
2543 pCap->hw_caps |= ATH9K_HW_CAP_APM;
2544 }
2545
2546
Sujith Manoharan06236e52012-09-16 08:07:12 +05302547 if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
Mohammed Shafi Shajakhan21d2c632011-05-13 20:29:31 +05302548 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2549 /*
2550 * enable the diversity-combining algorithm only when
2551 * both enable_lna_div and enable_fast_div are set
2552 * Table for Diversity
2553 * ant_div_alt_lnaconf bit 0-1
2554 * ant_div_main_lnaconf bit 2-3
2555 * ant_div_alt_gaintb bit 4
2556 * ant_div_main_gaintb bit 5
2557 * enable_ant_div_lnadiv bit 6
2558 * enable_ant_fast_div bit 7
2559 */
2560 if ((ant_div_ctl1 >> 0x6) == 0x3)
2561 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2562 }
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -07002563
Vasanthakumar Thiagarajan8060e162010-12-06 04:27:42 -08002564 if (AR_SREV_9485_10(ah)) {
2565 pCap->pcie_lcr_extsync_en = true;
2566 pCap->pcie_lcr_offset = 0x80;
2567 }
2568
Zefir Kurtisi9a66af32011-12-14 20:16:33 -08002569 if (ath9k_hw_dfs_tested(ah))
2570 pCap->hw_caps |= ATH9K_HW_CAP_DFS;
2571
Vasanthakumar Thiagarajan47c80de2010-12-06 04:27:43 -08002572 tx_chainmask = pCap->tx_chainmask;
2573 rx_chainmask = pCap->rx_chainmask;
2574 while (tx_chainmask || rx_chainmask) {
2575 if (tx_chainmask & BIT(0))
2576 pCap->max_txchains++;
2577 if (rx_chainmask & BIT(0))
2578 pCap->max_rxchains++;
2579
2580 tx_chainmask >>= 1;
2581 rx_chainmask >>= 1;
2582 }
2583
Rajkumar Manoharan8ad74c42011-10-13 11:00:38 +05302584 if (AR_SREV_9300_20_OR_LATER(ah)) {
2585 ah->enabled_cals |= TX_IQ_CAL;
Mohammed Shafi Shajakhan6fea5932011-11-30 21:01:31 +05302586 if (AR_SREV_9485_OR_LATER(ah))
Rajkumar Manoharan8ad74c42011-10-13 11:00:38 +05302587 ah->enabled_cals |= TX_IQ_ON_AGC_CAL;
2588 }
Mohammed Shafi Shajakhan3789d592012-03-09 12:01:55 +05302589
Sujith Manoharana4a29542012-09-10 09:20:03 +05302590 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
Mohammed Shafi Shajakhan3789d592012-03-09 12:01:55 +05302591 if (!(ah->ent_mode & AR_ENT_OTP_49GHZ_DISABLE))
2592 pCap->hw_caps |= ATH9K_HW_CAP_MCI;
2593
2594 if (AR_SREV_9462_20(ah))
2595 pCap->hw_caps |= ATH9K_HW_CAP_RTT;
Mohammed Shafi Shajakhan3789d592012-03-09 12:01:55 +05302596 }
2597
Rajkumar Manoharan324c74a2011-10-13 11:00:41 +05302598
Mohammed Shafi Shajakhand6878092012-07-10 14:55:17 +05302599 if (AR_SREV_9280_20_OR_LATER(ah)) {
2600 pCap->hw_caps |= ATH9K_HW_WOW_DEVICE_CAPABLE |
2601 ATH9K_HW_WOW_PATTERN_MATCH_EXACT;
2602
2603 if (AR_SREV_9280(ah))
2604 pCap->hw_caps |= ATH9K_HW_WOW_PATTERN_MATCH_DWORD;
2605 }
2606
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01002607 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002608}
2609
Sujithf1dc5602008-10-29 10:16:30 +05302610/****************************/
2611/* GPIO / RFKILL / Antennae */
2612/****************************/
2613
Sujithcbe61d82009-02-09 13:27:12 +05302614static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05302615 u32 gpio, u32 type)
2616{
2617 int addr;
2618 u32 gpio_shift, tmp;
2619
2620 if (gpio > 11)
2621 addr = AR_GPIO_OUTPUT_MUX3;
2622 else if (gpio > 5)
2623 addr = AR_GPIO_OUTPUT_MUX2;
2624 else
2625 addr = AR_GPIO_OUTPUT_MUX1;
2626
2627 gpio_shift = (gpio % 6) * 5;
2628
2629 if (AR_SREV_9280_20_OR_LATER(ah)
2630 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2631 REG_RMW(ah, addr, (type << gpio_shift),
2632 (0x1f << gpio_shift));
2633 } else {
2634 tmp = REG_READ(ah, addr);
2635 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2636 tmp &= ~(0x1f << gpio_shift);
2637 tmp |= (type << gpio_shift);
2638 REG_WRITE(ah, addr, tmp);
2639 }
2640}
2641
Sujithcbe61d82009-02-09 13:27:12 +05302642void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302643{
2644 u32 gpio_shift;
2645
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002646 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05302647
Sujith88c1f4f2010-06-30 14:46:31 +05302648 if (AR_DEVID_7010(ah)) {
2649 gpio_shift = gpio;
2650 REG_RMW(ah, AR7010_GPIO_OE,
2651 (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
2652 (AR7010_GPIO_OE_MASK << gpio_shift));
2653 return;
2654 }
Sujithf1dc5602008-10-29 10:16:30 +05302655
Sujith88c1f4f2010-06-30 14:46:31 +05302656 gpio_shift = gpio << 1;
Sujithf1dc5602008-10-29 10:16:30 +05302657 REG_RMW(ah,
2658 AR_GPIO_OE_OUT,
2659 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2660 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2661}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002662EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05302663
Sujithcbe61d82009-02-09 13:27:12 +05302664u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05302665{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302666#define MS_REG_READ(x, y) \
2667 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2668
Sujith2660b812009-02-09 13:27:26 +05302669 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05302670 return 0xffffffff;
2671
Sujith88c1f4f2010-06-30 14:46:31 +05302672 if (AR_DEVID_7010(ah)) {
2673 u32 val;
2674 val = REG_READ(ah, AR7010_GPIO_IN);
2675 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
2676 } else if (AR_SREV_9300_20_OR_LATER(ah))
Vasanthakumar Thiagarajan93069902010-11-30 23:24:09 -08002677 return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
2678 AR_GPIO_BIT(gpio)) != 0;
Felix Fietkau783dfca2010-04-15 17:38:11 -04002679 else if (AR_SREV_9271(ah))
Sujith5b5fa352010-03-17 14:25:15 +05302680 return MS_REG_READ(AR9271, gpio) != 0;
Felix Fietkaua42acef2010-09-22 12:34:54 +02002681 else if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302682 return MS_REG_READ(AR9287, gpio) != 0;
Felix Fietkaue17f83e2010-09-22 12:34:53 +02002683 else if (AR_SREV_9285_12_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302684 return MS_REG_READ(AR9285, gpio) != 0;
Felix Fietkau7a370812010-09-22 12:34:52 +02002685 else if (AR_SREV_9280_20_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05302686 return MS_REG_READ(AR928X, gpio) != 0;
2687 else
2688 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05302689}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002690EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05302691
Sujithcbe61d82009-02-09 13:27:12 +05302692void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05302693 u32 ah_signal_type)
2694{
2695 u32 gpio_shift;
2696
Sujith88c1f4f2010-06-30 14:46:31 +05302697 if (AR_DEVID_7010(ah)) {
2698 gpio_shift = gpio;
2699 REG_RMW(ah, AR7010_GPIO_OE,
2700 (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
2701 (AR7010_GPIO_OE_MASK << gpio_shift));
2702 return;
2703 }
2704
Sujithf1dc5602008-10-29 10:16:30 +05302705 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
Sujithf1dc5602008-10-29 10:16:30 +05302706 gpio_shift = 2 * gpio;
Sujithf1dc5602008-10-29 10:16:30 +05302707 REG_RMW(ah,
2708 AR_GPIO_OE_OUT,
2709 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2710 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2711}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002712EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05302713
Sujithcbe61d82009-02-09 13:27:12 +05302714void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05302715{
Sujith88c1f4f2010-06-30 14:46:31 +05302716 if (AR_DEVID_7010(ah)) {
2717 val = val ? 0 : 1;
2718 REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
2719 AR_GPIO_BIT(gpio));
2720 return;
2721 }
2722
Sujith5b5fa352010-03-17 14:25:15 +05302723 if (AR_SREV_9271(ah))
2724 val = ~val;
2725
Sujithf1dc5602008-10-29 10:16:30 +05302726 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2727 AR_GPIO_BIT(gpio));
2728}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002729EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05302730
Sujithcbe61d82009-02-09 13:27:12 +05302731void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05302732{
2733 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2734}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002735EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05302736
Sujithf1dc5602008-10-29 10:16:30 +05302737/*********************/
2738/* General Operation */
2739/*********************/
2740
Sujithcbe61d82009-02-09 13:27:12 +05302741u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302742{
2743 u32 bits = REG_READ(ah, AR_RX_FILTER);
2744 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2745
2746 if (phybits & AR_PHY_ERR_RADAR)
2747 bits |= ATH9K_RX_FILTER_PHYRADAR;
2748 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2749 bits |= ATH9K_RX_FILTER_PHYERR;
2750
2751 return bits;
2752}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002753EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302754
Sujithcbe61d82009-02-09 13:27:12 +05302755void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05302756{
2757 u32 phybits;
2758
Sujith7d0d0df2010-04-16 11:53:57 +05302759 ENABLE_REGWRITE_BUFFER(ah);
2760
Sujith Manoharana4a29542012-09-10 09:20:03 +05302761 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05302762 bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
2763
Sujith7ea310b2009-09-03 12:08:43 +05302764 REG_WRITE(ah, AR_RX_FILTER, bits);
2765
Sujithf1dc5602008-10-29 10:16:30 +05302766 phybits = 0;
2767 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2768 phybits |= AR_PHY_ERR_RADAR;
2769 if (bits & ATH9K_RX_FILTER_PHYERR)
2770 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2771 REG_WRITE(ah, AR_PHY_ERR, phybits);
2772
2773 if (phybits)
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002774 REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujithf1dc5602008-10-29 10:16:30 +05302775 else
Felix Fietkauca7a4de2011-03-23 20:57:26 +01002776 REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
Sujith7d0d0df2010-04-16 11:53:57 +05302777
2778 REGWRITE_BUFFER_FLUSH(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302779}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002780EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302781
Sujithcbe61d82009-02-09 13:27:12 +05302782bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302783{
Rajkumar Manoharan99922a42012-06-04 16:28:31 +05302784 if (ath9k_hw_mci_is_enabled(ah))
2785 ar9003_mci_bt_gain_ctrl(ah);
2786
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302787 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2788 return false;
2789
2790 ath9k_hw_init_pll(ah, NULL);
Felix Fietkau8efa7a82012-03-14 16:40:23 +01002791 ah->htc_reset_init = true;
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302792 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302793}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002794EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302795
Sujithcbe61d82009-02-09 13:27:12 +05302796bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302797{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002798 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05302799 return false;
2800
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302801 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2802 return false;
2803
2804 ath9k_hw_init_pll(ah, NULL);
2805 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302806}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002807EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05302808
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002809static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05302810{
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002811 enum eeprom_param gain_param;
Felix Fietkau9c204b42011-07-27 15:01:05 +02002812
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002813 if (IS_CHAN_2GHZ(chan))
2814 gain_param = EEP_ANTENNA_GAIN_2G;
2815 else
2816 gain_param = EEP_ANTENNA_GAIN_5G;
Sujithf1dc5602008-10-29 10:16:30 +05302817
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002818 return ah->eep_ops->get_eeprom(ah, gain_param);
2819}
2820
Gabor Juhos64ea57d2012-04-15 20:38:05 +02002821void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
2822 bool test)
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002823{
2824 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2825 struct ieee80211_channel *channel;
2826 int chan_pwr, new_pwr, max_gain;
2827 int ant_gain, ant_reduction = 0;
2828
2829 if (!chan)
2830 return;
2831
2832 channel = chan->chan;
2833 chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
2834 new_pwr = min_t(int, chan_pwr, reg->power_limit);
2835 max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
2836
2837 ant_gain = get_antenna_gain(ah, chan);
2838 if (ant_gain > max_gain)
2839 ant_reduction = ant_gain - max_gain;
Sujithf1dc5602008-10-29 10:16:30 +05302840
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002841 ah->eep_ops->set_txpower(ah, chan,
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002842 ath9k_regd_get_ctl(reg, chan),
Gabor Juhos64ea57d2012-04-15 20:38:05 +02002843 ant_reduction, new_pwr, test);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002844}
2845
2846void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
2847{
2848 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2849 struct ath9k_channel *chan = ah->curchan;
2850 struct ieee80211_channel *channel = chan->chan;
2851
Dan Carpenter48ef5c42011-10-17 10:28:23 +03002852 reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002853 if (test)
2854 channel->max_power = MAX_RATE_POWER / 2;
2855
Gabor Juhos64ea57d2012-04-15 20:38:05 +02002856 ath9k_hw_apply_txpower(ah, chan, test);
Felix Fietkauca2c68c2011-10-08 20:06:20 +02002857
2858 if (test)
2859 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
Sujithf1dc5602008-10-29 10:16:30 +05302860}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002861EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05302862
Sujithcbe61d82009-02-09 13:27:12 +05302863void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302864{
Sujith2660b812009-02-09 13:27:26 +05302865 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05302866}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002867EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05302868
Sujithcbe61d82009-02-09 13:27:12 +05302869void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05302870{
2871 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2872 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2873}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002874EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05302875
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002876void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302877{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002878 struct ath_common *common = ath9k_hw_common(ah);
2879
2880 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2881 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2882 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05302883}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002884EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05302885
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002886#define ATH9K_MAX_TSF_READ 10
2887
Sujithcbe61d82009-02-09 13:27:12 +05302888u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302889{
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002890 u32 tsf_lower, tsf_upper1, tsf_upper2;
2891 int i;
Sujithf1dc5602008-10-29 10:16:30 +05302892
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002893 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2894 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2895 tsf_lower = REG_READ(ah, AR_TSF_L32);
2896 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2897 if (tsf_upper2 == tsf_upper1)
2898 break;
2899 tsf_upper1 = tsf_upper2;
2900 }
Sujithf1dc5602008-10-29 10:16:30 +05302901
Benoit Papillault1c0fc652010-04-16 00:07:26 +02002902 WARN_ON( i == ATH9K_MAX_TSF_READ );
2903
2904 return (((u64)tsf_upper1 << 32) | tsf_lower);
Sujithf1dc5602008-10-29 10:16:30 +05302905}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002906EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05302907
Sujithcbe61d82009-02-09 13:27:12 +05302908void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002909{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002910 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01002911 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002912}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002913EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01002914
Sujithcbe61d82009-02-09 13:27:12 +05302915void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302916{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002917 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2918 AH_TSF_WRITE_TIMEOUT))
Joe Perchesd2182b62011-12-15 14:55:53 -08002919 ath_dbg(ath9k_hw_common(ah), RESET,
Joe Perches226afe62010-12-02 19:12:37 -08002920 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02002921
Sujithf1dc5602008-10-29 10:16:30 +05302922 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002923}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002924EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002925
Sujith Manoharan60ca9f82012-07-17 17:15:37 +05302926void ath9k_hw_set_tsfadjust(struct ath_hw *ah, bool set)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002927{
Sujith Manoharan60ca9f82012-07-17 17:15:37 +05302928 if (set)
Sujith2660b812009-02-09 13:27:26 +05302929 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002930 else
Sujith2660b812009-02-09 13:27:26 +05302931 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002932}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002933EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002934
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002935void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002936{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002937 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05302938 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002939
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002940 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05302941 macmode = AR_2040_JOINED_RX_CLEAR;
2942 else
2943 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002944
Sujithf1dc5602008-10-29 10:16:30 +05302945 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002946}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302947
2948/* HW Generic timers configuration */
2949
2950static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2951{
2952 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2953 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2954 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2955 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2956 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2957 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2958 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2959 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2960 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2961 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2962 AR_NDP2_TIMER_MODE, 0x0002},
2963 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2964 AR_NDP2_TIMER_MODE, 0x0004},
2965 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2966 AR_NDP2_TIMER_MODE, 0x0008},
2967 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2968 AR_NDP2_TIMER_MODE, 0x0010},
2969 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2970 AR_NDP2_TIMER_MODE, 0x0020},
2971 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2972 AR_NDP2_TIMER_MODE, 0x0040},
2973 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2974 AR_NDP2_TIMER_MODE, 0x0080}
2975};
2976
2977/* HW generic timer primitives */
2978
2979/* compute and clear index of rightmost 1 */
2980static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
2981{
2982 u32 b;
2983
2984 b = *mask;
2985 b &= (0-b);
2986 *mask &= ~b;
2987 b *= debruijn32;
2988 b >>= 27;
2989
2990 return timer_table->gen_timer_index[b];
2991}
2992
Felix Fietkaudd347f22011-03-22 21:54:17 +01002993u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302994{
2995 return REG_READ(ah, AR_TSF_L32);
2996}
Felix Fietkaudd347f22011-03-22 21:54:17 +01002997EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302998
2999struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3000 void (*trigger)(void *),
3001 void (*overflow)(void *),
3002 void *arg,
3003 u8 timer_index)
3004{
3005 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3006 struct ath_gen_timer *timer;
3007
3008 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3009
3010 if (timer == NULL) {
Joe Perches38002762010-12-02 19:12:36 -08003011 ath_err(ath9k_hw_common(ah),
3012 "Failed to allocate memory for hw timer[%d]\n",
3013 timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303014 return NULL;
3015 }
3016
3017 /* allocate a hardware generic timer slot */
3018 timer_table->timers[timer_index] = timer;
3019 timer->index = timer_index;
3020 timer->trigger = trigger;
3021 timer->overflow = overflow;
3022 timer->arg = arg;
3023
3024 return timer;
3025}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003026EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303027
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003028void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3029 struct ath_gen_timer *timer,
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05303030 u32 trig_timeout,
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003031 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303032{
3033 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05303034 u32 tsf, timer_next;
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303035
3036 BUG_ON(!timer_period);
3037
3038 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3039
3040 tsf = ath9k_hw_gettsf32(ah);
3041
Vasanthakumar Thiagarajan788f6872011-04-21 18:33:27 +05303042 timer_next = tsf + trig_timeout;
3043
Joe Perchesd2182b62011-12-15 14:55:53 -08003044 ath_dbg(ath9k_hw_common(ah), HWTIMER,
Joe Perches226afe62010-12-02 19:12:37 -08003045 "current tsf %x period %x timer_next %x\n",
3046 tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303047
3048 /*
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303049 * Program generic timer registers
3050 */
3051 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3052 timer_next);
3053 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3054 timer_period);
3055 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3056 gen_tmr_configuration[timer->index].mode_mask);
3057
Sujith Manoharana4a29542012-09-10 09:20:03 +05303058 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05303059 /*
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05303060 * Starting from AR9462, each generic timer can select which tsf
Senthil Balasubramanian2577c6e2011-09-13 22:38:18 +05303061 * to use. But we still follow the old rule, 0 - 7 use tsf and
3062 * 8 - 15 use tsf2.
3063 */
3064 if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
3065 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
3066 (1 << timer->index));
3067 else
3068 REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
3069 (1 << timer->index));
3070 }
3071
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303072 /* Enable both trigger and thresh interrupt masks */
3073 REG_SET_BIT(ah, AR_IMR_S5,
3074 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3075 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303076}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003077EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303078
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003079void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303080{
3081 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3082
3083 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3084 (timer->index >= ATH_MAX_GEN_TIMER)) {
3085 return;
3086 }
3087
3088 /* Clear generic timer enable bits. */
3089 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3090 gen_tmr_configuration[timer->index].mode_mask);
3091
Sujith Manoharanb7f59762012-09-11 10:46:24 +05303092 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
3093 /*
3094 * Need to switch back to TSF if it was using TSF2.
3095 */
3096 if ((timer->index >= AR_GEN_TIMER_BANK_1_LEN)) {
3097 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
3098 (1 << timer->index));
3099 }
3100 }
3101
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303102 /* Disable both trigger and thresh interrupt masks */
3103 REG_CLR_BIT(ah, AR_IMR_S5,
3104 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3105 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3106
3107 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303108}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003109EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303110
3111void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3112{
3113 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3114
3115 /* free the hardware generic timer slot */
3116 timer_table->timers[timer->index] = NULL;
3117 kfree(timer);
3118}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003119EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303120
3121/*
3122 * Generic Timer Interrupts handling
3123 */
3124void ath_gen_timer_isr(struct ath_hw *ah)
3125{
3126 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3127 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003128 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303129 u32 trigger_mask, thresh_mask, index;
3130
3131 /* get hardware generic timer interrupt status */
3132 trigger_mask = ah->intr_gen_timer_trigger;
3133 thresh_mask = ah->intr_gen_timer_thresh;
3134 trigger_mask &= timer_table->timer_mask.val;
3135 thresh_mask &= timer_table->timer_mask.val;
3136
3137 trigger_mask &= ~thresh_mask;
3138
3139 while (thresh_mask) {
3140 index = rightmost_index(timer_table, &thresh_mask);
3141 timer = timer_table->timers[index];
3142 BUG_ON(!timer);
Joe Perchesd2182b62011-12-15 14:55:53 -08003143 ath_dbg(common, HWTIMER, "TSF overflow for Gen timer %d\n",
3144 index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303145 timer->overflow(timer->arg);
3146 }
3147
3148 while (trigger_mask) {
3149 index = rightmost_index(timer_table, &trigger_mask);
3150 timer = timer_table->timers[index];
3151 BUG_ON(!timer);
Joe Perchesd2182b62011-12-15 14:55:53 -08003152 ath_dbg(common, HWTIMER,
Joe Perches226afe62010-12-02 19:12:37 -08003153 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303154 timer->trigger(timer->arg);
3155 }
3156}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003157EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003158
Sujith05020d22010-03-17 14:25:23 +05303159/********/
3160/* HTC */
3161/********/
3162
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003163static struct {
3164 u32 version;
3165 const char * name;
3166} ath_mac_bb_names[] = {
3167 /* Devices with external radios */
3168 { AR_SREV_VERSION_5416_PCI, "5416" },
3169 { AR_SREV_VERSION_5416_PCIE, "5418" },
3170 { AR_SREV_VERSION_9100, "9100" },
3171 { AR_SREV_VERSION_9160, "9160" },
3172 /* Single-chip solutions */
3173 { AR_SREV_VERSION_9280, "9280" },
3174 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003175 { AR_SREV_VERSION_9287, "9287" },
3176 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguezec839032010-04-15 17:39:20 -04003177 { AR_SREV_VERSION_9300, "9300" },
Gabor Juhos2c8e5932011-06-21 11:23:21 +02003178 { AR_SREV_VERSION_9330, "9330" },
Florian Fainelli397e5d52011-08-25 21:33:48 +02003179 { AR_SREV_VERSION_9340, "9340" },
Senthil Balasubramanian8f06ca22011-04-01 17:16:33 +05303180 { AR_SREV_VERSION_9485, "9485" },
Rajkumar Manoharan423e38e2011-10-13 11:00:44 +05303181 { AR_SREV_VERSION_9462, "9462" },
Gabor Juhos485124c2012-07-03 19:13:19 +02003182 { AR_SREV_VERSION_9550, "9550" },
Sujith Manoharan77fac462012-09-11 20:09:18 +05303183 { AR_SREV_VERSION_9565, "9565" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003184};
3185
3186/* For devices with external radios */
3187static struct {
3188 u16 version;
3189 const char * name;
3190} ath_rf_names[] = {
3191 { 0, "5133" },
3192 { AR_RAD5133_SREV_MAJOR, "5133" },
3193 { AR_RAD5122_SREV_MAJOR, "5122" },
3194 { AR_RAD2133_SREV_MAJOR, "2133" },
3195 { AR_RAD2122_SREV_MAJOR, "2122" }
3196};
3197
3198/*
3199 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3200 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003201static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003202{
3203 int i;
3204
3205 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3206 if (ath_mac_bb_names[i].version == mac_bb_version) {
3207 return ath_mac_bb_names[i].name;
3208 }
3209 }
3210
3211 return "????";
3212}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003213
3214/*
3215 * Return the RF name. "????" is returned if the RF is unknown.
3216 * Used for devices with external radios.
3217 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003218static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003219{
3220 int i;
3221
3222 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3223 if (ath_rf_names[i].version == rf_version) {
3224 return ath_rf_names[i].name;
3225 }
3226 }
3227
3228 return "????";
3229}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003230
3231void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3232{
3233 int used;
3234
3235 /* chipsets >= AR9280 are single-chip */
Felix Fietkau7a370812010-09-22 12:34:52 +02003236 if (AR_SREV_9280_20_OR_LATER(ah)) {
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003237 used = snprintf(hw_name, len,
3238 "Atheros AR%s Rev:%x",
3239 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3240 ah->hw_version.macRev);
3241 }
3242 else {
3243 used = snprintf(hw_name, len,
3244 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3245 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3246 ah->hw_version.macRev,
3247 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3248 AR_RADIO_SREV_MAJOR)),
3249 ah->hw_version.phyRev);
3250 }
3251
3252 hw_name[used] = '\0';
3253}
3254EXPORT_SYMBOL(ath9k_hw_name);