blob: 7d167a1b286da03dcb3d54fcb0ab19f6206700d4 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/io.h>
18#include <asm/unaligned.h>
19
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070020#include "hw.h"
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070021#include "rc.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070022#include "initvals.h"
23
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080024#define ATH9K_CLOCK_RATE_CCK 22
25#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
26#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027
Sujithcbe61d82009-02-09 13:27:12 +053028static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -070029static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan);
Sujithcbe61d82009-02-09 13:27:12 +053030static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053031 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053032 u32 reg, u32 value);
Sujithcbe61d82009-02-09 13:27:12 +053033static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
34static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070035
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040036MODULE_AUTHOR("Atheros Communications");
37MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
38MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
39MODULE_LICENSE("Dual BSD/GPL");
40
41static int __init ath9k_init(void)
42{
43 return 0;
44}
45module_init(ath9k_init);
46
47static void __exit ath9k_exit(void)
48{
49 return;
50}
51module_exit(ath9k_exit);
52
Sujithf1dc5602008-10-29 10:16:30 +053053/********************/
54/* Helper Functions */
55/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070056
Sujithcbe61d82009-02-09 13:27:12 +053057static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053058{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070059 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053060
Sujith2660b812009-02-09 13:27:26 +053061 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080062 return clks / ATH9K_CLOCK_RATE_CCK;
63 if (conf->channel->band == IEEE80211_BAND_2GHZ)
64 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053065
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080066 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053067}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070068
Sujithcbe61d82009-02-09 13:27:12 +053069static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053070{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070071 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053072
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080073 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053074 return ath9k_hw_mac_usec(ah, clks) / 2;
75 else
76 return ath9k_hw_mac_usec(ah, clks);
77}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070078
Sujithcbe61d82009-02-09 13:27:12 +053079static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053080{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070081 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053082
Sujith2660b812009-02-09 13:27:26 +053083 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080084 return usecs *ATH9K_CLOCK_RATE_CCK;
85 if (conf->channel->band == IEEE80211_BAND_2GHZ)
86 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
87 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053088}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070089
Sujithcbe61d82009-02-09 13:27:12 +053090static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053091{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070092 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053093
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080094 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053095 return ath9k_hw_mac_clks(ah, usecs) * 2;
96 else
97 return ath9k_hw_mac_clks(ah, usecs);
98}
99
Sujith0caa7b12009-02-16 13:23:20 +0530100bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700101{
102 int i;
103
Sujith0caa7b12009-02-16 13:23:20 +0530104 BUG_ON(timeout < AH_TIME_QUANTUM);
105
106 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700107 if ((REG_READ(ah, reg) & mask) == val)
108 return true;
109
110 udelay(AH_TIME_QUANTUM);
111 }
Sujith04bd46382008-11-28 22:18:05 +0530112
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700113 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
114 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
115 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530116
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700117 return false;
118}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400119EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700120
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700121u32 ath9k_hw_reverse_bits(u32 val, u32 n)
122{
123 u32 retval;
124 int i;
125
126 for (i = 0, retval = 0; i < n; i++) {
127 retval = (retval << 1) | (val & 1);
128 val >>= 1;
129 }
130 return retval;
131}
132
Sujithcbe61d82009-02-09 13:27:12 +0530133bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530134 u16 flags, u16 *low,
135 u16 *high)
136{
Sujith2660b812009-02-09 13:27:26 +0530137 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530138
139 if (flags & CHANNEL_5GHZ) {
140 *low = pCap->low_5ghz_chan;
141 *high = pCap->high_5ghz_chan;
142 return true;
143 }
144 if ((flags & CHANNEL_2GHZ)) {
145 *low = pCap->low_2ghz_chan;
146 *high = pCap->high_2ghz_chan;
147 return true;
148 }
149 return false;
150}
151
Sujithcbe61d82009-02-09 13:27:12 +0530152u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400153 const struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530154 u32 frameLen, u16 rateix,
155 bool shortPreamble)
156{
157 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
158 u32 kbps;
159
Sujithe63835b2008-11-18 09:07:53 +0530160 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530161
162 if (kbps == 0)
163 return 0;
164
165 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530166 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530167 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530168 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530169 phyTime >>= 1;
170 numBits = frameLen << 3;
171 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
172 break;
Sujith46d14a52008-11-18 09:08:13 +0530173 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530174 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530175 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
176 numBits = OFDM_PLCP_BITS + (frameLen << 3);
177 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
178 txTime = OFDM_SIFS_TIME_QUARTER
179 + OFDM_PREAMBLE_TIME_QUARTER
180 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530181 } else if (ah->curchan &&
182 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530183 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
184 numBits = OFDM_PLCP_BITS + (frameLen << 3);
185 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
186 txTime = OFDM_SIFS_TIME_HALF +
187 OFDM_PREAMBLE_TIME_HALF
188 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
189 } else {
190 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
191 numBits = OFDM_PLCP_BITS + (frameLen << 3);
192 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
193 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
194 + (numSymbols * OFDM_SYMBOL_TIME);
195 }
196 break;
197 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700198 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
199 "Unknown phy %u (rate ix %u)\n",
200 rates->info[rateix].phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530201 txTime = 0;
202 break;
203 }
204
205 return txTime;
206}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400207EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530208
Sujithcbe61d82009-02-09 13:27:12 +0530209void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530210 struct ath9k_channel *chan,
211 struct chan_centers *centers)
212{
213 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530214
215 if (!IS_CHAN_HT40(chan)) {
216 centers->ctl_center = centers->ext_center =
217 centers->synth_center = chan->channel;
218 return;
219 }
220
221 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
222 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
223 centers->synth_center =
224 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
225 extoff = 1;
226 } else {
227 centers->synth_center =
228 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
229 extoff = -1;
230 }
231
232 centers->ctl_center =
233 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700234 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530235 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700236 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530237}
238
239/******************/
240/* Chip Revisions */
241/******************/
242
Sujithcbe61d82009-02-09 13:27:12 +0530243static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530244{
245 u32 val;
246
247 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
248
249 if (val == 0xFF) {
250 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530251 ah->hw_version.macVersion =
252 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
253 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530254 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530255 } else {
256 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530257 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530258
Sujithd535a422009-02-09 13:27:06 +0530259 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530260
Sujithd535a422009-02-09 13:27:06 +0530261 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530262 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530263 }
264}
265
Sujithcbe61d82009-02-09 13:27:12 +0530266static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530267{
268 u32 val;
269 int i;
270
271 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
272
273 for (i = 0; i < 8; i++)
274 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
275 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
276 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
277
278 return ath9k_hw_reverse_bits(val, 8);
279}
280
281/************************************/
282/* HW Attach, Detach, Init Routines */
283/************************************/
284
Sujithcbe61d82009-02-09 13:27:12 +0530285static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530286{
Sujithfeed0292009-01-29 11:37:35 +0530287 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530288 return;
289
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
293 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
294 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
295 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
296 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
297 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
298 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
299
300 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
301}
302
Sujithcbe61d82009-02-09 13:27:12 +0530303static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530304{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700305 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530306 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
307 u32 regHold[2];
308 u32 patternData[4] = { 0x55555555,
309 0xaaaaaaaa,
310 0x66666666,
311 0x99999999 };
312 int i, j;
313
314 for (i = 0; i < 2; i++) {
315 u32 addr = regAddr[i];
316 u32 wrData, rdData;
317
318 regHold[i] = REG_READ(ah, addr);
319 for (j = 0; j < 0x100; j++) {
320 wrData = (j << 16) | j;
321 REG_WRITE(ah, addr, wrData);
322 rdData = REG_READ(ah, addr);
323 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700324 ath_print(common, ATH_DBG_FATAL,
325 "address test failed "
326 "addr: 0x%08x - wr:0x%08x != "
327 "rd:0x%08x\n",
328 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530329 return false;
330 }
331 }
332 for (j = 0; j < 4; j++) {
333 wrData = patternData[j];
334 REG_WRITE(ah, addr, wrData);
335 rdData = REG_READ(ah, addr);
336 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700337 ath_print(common, ATH_DBG_FATAL,
338 "address test failed "
339 "addr: 0x%08x - wr:0x%08x != "
340 "rd:0x%08x\n",
341 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530342 return false;
343 }
344 }
345 REG_WRITE(ah, regAddr[i], regHold[i]);
346 }
347 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530348
Sujithf1dc5602008-10-29 10:16:30 +0530349 return true;
350}
351
352static const char *ath9k_hw_devname(u16 devid)
353{
354 switch (devid) {
355 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530356 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100357 case AR5416_DEVID_PCIE:
358 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530359 case AR9160_DEVID_PCI:
360 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100361 case AR5416_AR9100_DEVID:
362 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530363 case AR9280_DEVID_PCI:
364 case AR9280_DEVID_PCIE:
365 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530366 case AR9285_DEVID_PCIE:
367 return "Atheros 9285";
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530368 case AR5416_DEVID_AR9287_PCI:
369 case AR5416_DEVID_AR9287_PCIE:
370 return "Atheros 9287";
Sujithf1dc5602008-10-29 10:16:30 +0530371 }
372
373 return NULL;
374}
375
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700376static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377{
378 int i;
379
Sujith2660b812009-02-09 13:27:26 +0530380 ah->config.dma_beacon_response_time = 2;
381 ah->config.sw_beacon_response_time = 10;
382 ah->config.additional_swba_backoff = 0;
383 ah->config.ack_6mb = 0x0;
384 ah->config.cwm_ignore_extcca = 0;
385 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530386 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530387 ah->config.pcie_waen = 0;
388 ah->config.analog_shiftreg = 1;
389 ah->config.ht_enable = 1;
390 ah->config.ofdm_trig_low = 200;
391 ah->config.ofdm_trig_high = 500;
392 ah->config.cck_trig_high = 200;
393 ah->config.cck_trig_low = 100;
394 ah->config.enable_ani = 1;
Sujith1cf68732009-08-13 09:34:32 +0530395 ah->config.diversity_control = ATH9K_ANT_VARIABLE;
Sujith2660b812009-02-09 13:27:26 +0530396 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700397
398 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530399 ah->config.spurchans[i][0] = AR_NO_SPUR;
400 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700401 }
402
Sujith0ef1f162009-03-30 15:28:35 +0530403 ah->config.intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400404
405 /*
406 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
407 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
408 * This means we use it for all AR5416 devices, and the few
409 * minor PCI AR9280 devices out there.
410 *
411 * Serialization is required because these devices do not handle
412 * well the case of two concurrent reads/writes due to the latency
413 * involved. During one read/write another read/write can be issued
414 * on another CPU while the previous read/write may still be working
415 * on our hardware, if we hit this case the hardware poops in a loop.
416 * We prevent this by serializing reads and writes.
417 *
418 * This issue is not present on PCI-Express devices or pre-AR5416
419 * devices (legacy, 802.11abg).
420 */
421 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700422 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700423}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400424EXPORT_SYMBOL(ath9k_hw_init);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700426static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700427{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700428 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
429
430 regulatory->country_code = CTRY_DEFAULT;
431 regulatory->power_limit = MAX_RATE_POWER;
432 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
433
Sujithd535a422009-02-09 13:27:06 +0530434 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530435 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436
437 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700438 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530439 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700440 if (!AR_SREV_9100(ah))
441 ah->ah_flags = AH_USE_EEPROM;
442
Sujith2660b812009-02-09 13:27:26 +0530443 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530444 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
445 ah->beacon_interval = 100;
446 ah->enable_32kHz_clock = DONT_USE_32KHZ;
447 ah->slottime = (u32) -1;
448 ah->acktimeout = (u32) -1;
449 ah->ctstimeout = (u32) -1;
450 ah->globaltxtimeout = (u32) -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451
Sujith2660b812009-02-09 13:27:26 +0530452 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453
Gabor Juhoscbdec972009-07-24 17:27:22 +0200454 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700455}
456
Sujithcbe61d82009-02-09 13:27:12 +0530457static int ath9k_hw_rfattach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700458{
459 bool rfStatus = false;
460 int ecode = 0;
461
462 rfStatus = ath9k_hw_init_rf(ah, &ecode);
463 if (!rfStatus) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700464 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
465 "RF setup failed, status: %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700466 return ecode;
467 }
468
469 return 0;
470}
471
Sujithcbe61d82009-02-09 13:27:12 +0530472static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700473{
474 u32 val;
475
476 REG_WRITE(ah, AR_PHY(0), 0x00000007);
477
478 val = ath9k_hw_get_radiorev(ah);
479 switch (val & AR_RADIO_SREV_MAJOR) {
480 case 0:
481 val = AR_RAD5133_SREV_MAJOR;
482 break;
483 case AR_RAD5133_SREV_MAJOR:
484 case AR_RAD5122_SREV_MAJOR:
485 case AR_RAD2133_SREV_MAJOR:
486 case AR_RAD2122_SREV_MAJOR:
487 break;
488 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700489 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
490 "Radio Chip Rev 0x%02X not supported\n",
491 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700492 return -EOPNOTSUPP;
493 }
494
Sujithd535a422009-02-09 13:27:06 +0530495 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700496
497 return 0;
498}
499
Sujithcbe61d82009-02-09 13:27:12 +0530500static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700501{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700502 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530503 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700504 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530505 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700506
Sujithf1dc5602008-10-29 10:16:30 +0530507 sum = 0;
508 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530509 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530510 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700511 common->macaddr[2 * i] = eeval >> 8;
512 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700513 }
Sujithd8baa932009-03-30 15:28:25 +0530514 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530515 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700516
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700517 return 0;
518}
519
Sujithcbe61d82009-02-09 13:27:12 +0530520static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530521{
522 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530523
Sujithf74df6f2009-02-09 13:27:24 +0530524 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
525 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530526
527 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530528 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530529 ar9280Modes_backoff_13db_rxgain_9280_2,
530 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
531 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530532 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530533 ar9280Modes_backoff_23db_rxgain_9280_2,
534 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
535 else
Sujith2660b812009-02-09 13:27:26 +0530536 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530537 ar9280Modes_original_rxgain_9280_2,
538 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530539 } else {
Sujith2660b812009-02-09 13:27:26 +0530540 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530541 ar9280Modes_original_rxgain_9280_2,
542 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530543 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530544}
545
Sujithcbe61d82009-02-09 13:27:12 +0530546static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530547{
548 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530549
Sujithf74df6f2009-02-09 13:27:24 +0530550 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
551 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530552
553 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530554 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530555 ar9280Modes_high_power_tx_gain_9280_2,
556 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
557 else
Sujith2660b812009-02-09 13:27:26 +0530558 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530559 ar9280Modes_original_tx_gain_9280_2,
560 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530561 } else {
Sujith2660b812009-02-09 13:27:26 +0530562 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530563 ar9280Modes_original_tx_gain_9280_2,
564 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530565 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530566}
567
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700568static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700569{
570 int ecode;
571
Sujithd8baa932009-03-30 15:28:25 +0530572 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700573 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700574
575 ecode = ath9k_hw_rf_claim(ah);
576 if (ecode != 0)
577 return ecode;
578
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700579 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700580 if (ecode != 0)
581 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530582
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700583 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
584 "Eeprom VER: %d, REV: %d\n",
585 ah->eep_ops->get_eeprom_ver(ah),
586 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530587
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700588 ecode = ath9k_hw_rfattach(ah);
589 if (ecode != 0)
590 return ecode;
591
592 if (!AR_SREV_9100(ah)) {
593 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700594 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700595 }
Sujithf1dc5602008-10-29 10:16:30 +0530596
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700597 return 0;
598}
599
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700600static bool ath9k_hw_devid_supported(u16 devid)
601{
602 switch (devid) {
603 case AR5416_DEVID_PCI:
604 case AR5416_DEVID_PCIE:
605 case AR5416_AR9100_DEVID:
606 case AR9160_DEVID_PCI:
607 case AR9280_DEVID_PCI:
608 case AR9280_DEVID_PCIE:
609 case AR9285_DEVID_PCIE:
610 case AR5416_DEVID_AR9287_PCI:
611 case AR5416_DEVID_AR9287_PCIE:
612 return true;
613 default:
614 break;
615 }
616 return false;
617}
618
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700619static bool ath9k_hw_macversion_supported(u32 macversion)
620{
621 switch (macversion) {
622 case AR_SREV_VERSION_5416_PCI:
623 case AR_SREV_VERSION_5416_PCIE:
624 case AR_SREV_VERSION_9160:
625 case AR_SREV_VERSION_9100:
626 case AR_SREV_VERSION_9280:
627 case AR_SREV_VERSION_9285:
628 case AR_SREV_VERSION_9287:
629 return true;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400630 /* Not yet */
631 case AR_SREV_VERSION_9271:
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700632 default:
633 break;
634 }
635 return false;
636}
637
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700638static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700639{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700640 if (AR_SREV_9160_10_OR_LATER(ah)) {
641 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530642 ah->iq_caldata.calData = &iq_cal_single_sample;
643 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700644 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530645 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700646 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530647 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700648 &adc_init_dc_cal;
649 } else {
Sujith2660b812009-02-09 13:27:26 +0530650 ah->iq_caldata.calData = &iq_cal_multi_sample;
651 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700652 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530653 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700654 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530655 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700656 &adc_init_dc_cal;
657 }
Sujith2660b812009-02-09 13:27:26 +0530658 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700659 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700660}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700661
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700662static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
663{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400664 if (AR_SREV_9271(ah)) {
665 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0,
666 ARRAY_SIZE(ar9271Modes_9271_1_0), 6);
667 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0,
668 ARRAY_SIZE(ar9271Common_9271_1_0), 2);
669 return;
670 }
671
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530672 if (AR_SREV_9287_11_OR_LATER(ah)) {
673 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
674 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
675 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
676 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
677 if (ah->config.pcie_clock_req)
678 INIT_INI_ARRAY(&ah->iniPcieSerdes,
679 ar9287PciePhy_clkreq_off_L1_9287_1_1,
680 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
681 else
682 INIT_INI_ARRAY(&ah->iniPcieSerdes,
683 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
684 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
685 2);
686 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
687 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
688 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
689 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
690 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700691
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530692 if (ah->config.pcie_clock_req)
693 INIT_INI_ARRAY(&ah->iniPcieSerdes,
694 ar9287PciePhy_clkreq_off_L1_9287_1_0,
695 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
696 else
697 INIT_INI_ARRAY(&ah->iniPcieSerdes,
698 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
699 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
700 2);
701 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
702
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530703
Sujith2660b812009-02-09 13:27:26 +0530704 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530705 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530706 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530707 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
708
Sujith2660b812009-02-09 13:27:26 +0530709 if (ah->config.pcie_clock_req) {
710 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530711 ar9285PciePhy_clkreq_off_L1_9285_1_2,
712 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
713 } else {
Sujith2660b812009-02-09 13:27:26 +0530714 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530715 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
716 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
717 2);
718 }
719 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530720 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530721 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530722 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530723 ARRAY_SIZE(ar9285Common_9285), 2);
724
Sujith2660b812009-02-09 13:27:26 +0530725 if (ah->config.pcie_clock_req) {
726 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530727 ar9285PciePhy_clkreq_off_L1_9285,
728 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
729 } else {
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530731 ar9285PciePhy_clkreq_always_on_L1_9285,
732 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
733 }
734 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530735 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530737 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700738 ARRAY_SIZE(ar9280Common_9280_2), 2);
739
Sujith2660b812009-02-09 13:27:26 +0530740 if (ah->config.pcie_clock_req) {
741 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530742 ar9280PciePhy_clkreq_off_L1_9280,
743 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 } else {
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530746 ar9280PciePhy_clkreq_always_on_L1_9280,
747 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 }
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530751 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 ARRAY_SIZE(ar9280Common_9280), 2);
757 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530758 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530760 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530762 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700763 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530766 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank7_9160), 2);
778 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ar5416Addac_91601_1,
781 ARRAY_SIZE(ar5416Addac_91601_1), 2);
782 } else {
Sujith2660b812009-02-09 13:27:26 +0530783 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 ARRAY_SIZE(ar5416Addac_9160), 2);
785 }
786 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530789 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700790 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530791 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530793 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530807 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700808 ARRAY_SIZE(ar5416Addac_9100), 2);
809 } else {
Sujith2660b812009-02-09 13:27:26 +0530810 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700811 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530812 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700813 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530814 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700815 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530816 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700817 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530818 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700819 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530820 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700821 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530822 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700823 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530824 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700825 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530826 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700827 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530828 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700829 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530830 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700831 ARRAY_SIZE(ar5416Addac), 2);
832 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700833}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700834
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700835static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
836{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530837 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530838 INIT_INI_ARRAY(&ah->iniModesRxGain,
839 ar9287Modes_rx_gain_9287_1_1,
840 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
841 else if (AR_SREV_9287_10(ah))
842 INIT_INI_ARRAY(&ah->iniModesRxGain,
843 ar9287Modes_rx_gain_9287_1_0,
844 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
845 else if (AR_SREV_9280_20(ah))
846 ath9k_hw_init_rxgain_ini(ah);
847
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530848 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530849 INIT_INI_ARRAY(&ah->iniModesTxGain,
850 ar9287Modes_tx_gain_9287_1_1,
851 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
852 } else if (AR_SREV_9287_10(ah)) {
853 INIT_INI_ARRAY(&ah->iniModesTxGain,
854 ar9287Modes_tx_gain_9287_1_0,
855 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
856 } else if (AR_SREV_9280_20(ah)) {
857 ath9k_hw_init_txgain_ini(ah);
858 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530859 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
860
861 /* txgain table */
862 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
863 INIT_INI_ARRAY(&ah->iniModesTxGain,
864 ar9285Modes_high_power_tx_gain_9285_1_2,
865 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
866 } else {
867 INIT_INI_ARRAY(&ah->iniModesTxGain,
868 ar9285Modes_original_tx_gain_9285_1_2,
869 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
870 }
871
872 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700873}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530874
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700875static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
876{
877 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530878
879 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
880 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
881
882 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530883 for (i = 0; i < ah->iniModes.ia_rows; i++) {
884 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700885
Sujith2660b812009-02-09 13:27:26 +0530886 for (j = 1; j < ah->iniModes.ia_columns; j++) {
887 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700888
Sujith2660b812009-02-09 13:27:26 +0530889 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530890 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530891 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700892 reg, val);
893 }
894 }
895 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700896}
897
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700898int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700899{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700900 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700901 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700902
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700903 if (!ath9k_hw_devid_supported(ah->hw_version.devid))
904 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700905
906 ath9k_hw_init_defaults(ah);
907 ath9k_hw_init_config(ah);
908
909 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700910 ath_print(common, ATH_DBG_FATAL,
911 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700912 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700913 }
914
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700915 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700916 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700917 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700918 }
919
920 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
921 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
922 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
923 ah->config.serialize_regmode =
924 SER_REG_MODE_ON;
925 } else {
926 ah->config.serialize_regmode =
927 SER_REG_MODE_OFF;
928 }
929 }
930
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700931 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700932 ah->config.serialize_regmode);
933
934 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700935 ath_print(common, ATH_DBG_FATAL,
936 "Mac Chip Rev 0x%02x.%x is not supported by "
937 "this driver\n", ah->hw_version.macVersion,
938 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700939 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700940 }
941
942 if (AR_SREV_9100(ah)) {
943 ah->iq_caldata.calData = &iq_cal_multi_sample;
944 ah->supp_cals = IQ_MISMATCH_CAL;
945 ah->is_pciexpress = false;
946 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400947
948 if (AR_SREV_9271(ah))
949 ah->is_pciexpress = false;
950
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700951 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
952
953 ath9k_hw_init_cal_settings(ah);
954
955 ah->ani_function = ATH9K_ANI_ALL;
956 if (AR_SREV_9280_10_OR_LATER(ah))
957 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
958
959 ath9k_hw_init_mode_regs(ah);
960
961 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530962 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700963 else
964 ath9k_hw_disablepcie(ah);
965
Sujith193cd452009-09-18 15:04:07 +0530966 /* Support for Japan ch.14 (2484) spread */
967 if (AR_SREV_9287_11_OR_LATER(ah)) {
968 INIT_INI_ARRAY(&ah->iniCckfirNormal,
969 ar9287Common_normal_cck_fir_coeff_92871_1,
970 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
971 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
972 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
973 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
974 }
975
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700976 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700977 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700978 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700979
980 ath9k_hw_init_mode_gain_regs(ah);
981 ath9k_hw_fill_cap_info(ah);
982 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530983
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700984 r = ath9k_hw_init_macaddr(ah);
985 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700986 ath_print(common, ATH_DBG_FATAL,
987 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700988 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700989 }
990
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400991 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530992 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700993 else
Sujith2660b812009-02-09 13:27:26 +0530994 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700995
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700996 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700997
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700998 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700999}
1000
Sujithcbe61d82009-02-09 13:27:12 +05301001static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301002 struct ath9k_channel *chan)
1003{
1004 u32 synthDelay;
1005
1006 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301007 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301008 synthDelay = (4 * synthDelay) / 22;
1009 else
1010 synthDelay /= 10;
1011
1012 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1013
1014 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1015}
1016
Sujithcbe61d82009-02-09 13:27:12 +05301017static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301018{
1019 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1020 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1021
1022 REG_WRITE(ah, AR_QOS_NO_ACK,
1023 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1024 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1025 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1026
1027 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1028 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1029 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1030 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1031 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1032}
1033
Sujithcbe61d82009-02-09 13:27:12 +05301034static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301035 struct ath9k_channel *chan)
1036{
1037 u32 pll;
1038
1039 if (AR_SREV_9100(ah)) {
1040 if (chan && IS_CHAN_5GHZ(chan))
1041 pll = 0x1450;
1042 else
1043 pll = 0x1458;
1044 } else {
1045 if (AR_SREV_9280_10_OR_LATER(ah)) {
1046 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1047
1048 if (chan && IS_CHAN_HALF_RATE(chan))
1049 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1050 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1051 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1052
1053 if (chan && IS_CHAN_5GHZ(chan)) {
1054 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1055
1056
1057 if (AR_SREV_9280_20(ah)) {
1058 if (((chan->channel % 20) == 0)
1059 || ((chan->channel % 10) == 0))
1060 pll = 0x2850;
1061 else
1062 pll = 0x142c;
1063 }
1064 } else {
1065 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1066 }
1067
1068 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1069
1070 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1071
1072 if (chan && IS_CHAN_HALF_RATE(chan))
1073 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1074 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1075 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1076
1077 if (chan && IS_CHAN_5GHZ(chan))
1078 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1079 else
1080 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1081 } else {
1082 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1083
1084 if (chan && IS_CHAN_HALF_RATE(chan))
1085 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1086 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1087 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1088
1089 if (chan && IS_CHAN_5GHZ(chan))
1090 pll |= SM(0xa, AR_RTC_PLL_DIV);
1091 else
1092 pll |= SM(0xb, AR_RTC_PLL_DIV);
1093 }
1094 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001095 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301096
1097 udelay(RTC_PLL_SETTLE_DELAY);
1098
1099 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1100}
1101
Sujithcbe61d82009-02-09 13:27:12 +05301102static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301103{
Sujithf1dc5602008-10-29 10:16:30 +05301104 int rx_chainmask, tx_chainmask;
1105
Sujith2660b812009-02-09 13:27:26 +05301106 rx_chainmask = ah->rxchainmask;
1107 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301108
1109 switch (rx_chainmask) {
1110 case 0x5:
1111 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1112 AR_PHY_SWAP_ALT_CHAIN);
1113 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301114 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301115 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1116 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1117 break;
1118 }
1119 case 0x1:
1120 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301121 case 0x7:
1122 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1123 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1124 break;
1125 default:
1126 break;
1127 }
1128
1129 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1130 if (tx_chainmask == 0x5) {
1131 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1132 AR_PHY_SWAP_ALT_CHAIN);
1133 }
1134 if (AR_SREV_9100(ah))
1135 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1136 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1137}
1138
Sujithcbe61d82009-02-09 13:27:12 +05301139static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001140 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301141{
Sujith2660b812009-02-09 13:27:26 +05301142 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301143 AR_IMR_TXURN |
1144 AR_IMR_RXERR |
1145 AR_IMR_RXORN |
1146 AR_IMR_BCNMISC;
1147
Sujith0ef1f162009-03-30 15:28:35 +05301148 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301149 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301150 else
Sujith2660b812009-02-09 13:27:26 +05301151 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301152
Sujith2660b812009-02-09 13:27:26 +05301153 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301154
Colin McCabed97809d2008-12-01 13:38:55 -08001155 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301156 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301157
Sujith2660b812009-02-09 13:27:26 +05301158 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301159 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1160
1161 if (!AR_SREV_9100(ah)) {
1162 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1163 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1164 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1165 }
1166}
1167
Sujithcbe61d82009-02-09 13:27:12 +05301168static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301169{
Sujithf1dc5602008-10-29 10:16:30 +05301170 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001171 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1172 "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301173 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301174 return false;
1175 } else {
1176 REG_RMW_FIELD(ah, AR_TIME_OUT,
1177 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301178 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301179 return true;
1180 }
1181}
1182
Sujithcbe61d82009-02-09 13:27:12 +05301183static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301184{
Sujithf1dc5602008-10-29 10:16:30 +05301185 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001186 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1187 "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301188 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301189 return false;
1190 } else {
1191 REG_RMW_FIELD(ah, AR_TIME_OUT,
1192 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301193 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301194 return true;
1195 }
1196}
1197
Sujithcbe61d82009-02-09 13:27:12 +05301198static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301199{
Sujithf1dc5602008-10-29 10:16:30 +05301200 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001201 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1202 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301203 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301204 return false;
1205 } else {
1206 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301207 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301208 return true;
1209 }
1210}
1211
Sujithcbe61d82009-02-09 13:27:12 +05301212static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301213{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001214 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1215 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301216
Sujith2660b812009-02-09 13:27:26 +05301217 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301218 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301219 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1220 if (ah->slottime != (u32) -1)
1221 ath9k_hw_setslottime(ah, ah->slottime);
1222 if (ah->acktimeout != (u32) -1)
1223 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1224 if (ah->ctstimeout != (u32) -1)
1225 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1226 if (ah->globaltxtimeout != (u32) -1)
1227 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301228}
1229
1230const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1231{
1232 return vendorid == ATHEROS_VENDOR_ID ?
1233 ath9k_hw_devname(devid) : NULL;
1234}
1235
Sujithcbe61d82009-02-09 13:27:12 +05301236void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001237{
1238 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001239 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001240
Luis R. Rodriguez081b35a2009-08-03 12:24:50 -07001241 ath9k_hw_rf_free(ah);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001242 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001243 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001244 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001245}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001246EXPORT_SYMBOL(ath9k_hw_detach);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001247
Sujithf1dc5602008-10-29 10:16:30 +05301248/*******/
1249/* INI */
1250/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001251
Sujithcbe61d82009-02-09 13:27:12 +05301252static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301253 struct ath9k_channel *chan)
1254{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001255 u32 val;
1256
1257 if (AR_SREV_9271(ah)) {
1258 /*
1259 * Enable spectral scan to solution for issues with stuck
1260 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1261 * AR9271 1.1
1262 */
1263 if (AR_SREV_9271_10(ah)) {
1264 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE;
1265 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1266 }
1267 else if (AR_SREV_9271_11(ah))
1268 /*
1269 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1270 * present on AR9271 1.1
1271 */
1272 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1273 return;
1274 }
1275
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301276 /*
1277 * Set the RX_ABORT and RX_DIS and clear if off only after
1278 * RXE is set for MAC. This prevents frames with corrupted
1279 * descriptor status.
1280 */
1281 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1282
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301283 if (AR_SREV_9280_10_OR_LATER(ah)) {
1284 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1285 (~AR_PCU_MISC_MODE2_HWWAR1);
1286
1287 if (AR_SREV_9287_10_OR_LATER(ah))
1288 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1289
1290 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1291 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301292
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001293 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301294 AR_SREV_9280_10_OR_LATER(ah))
1295 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001296 /*
1297 * Disable BB clock gating
1298 * Necessary to avoid issues on AR5416 2.0
1299 */
Sujithf1dc5602008-10-29 10:16:30 +05301300 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1301}
1302
Sujithcbe61d82009-02-09 13:27:12 +05301303static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301304 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301305 u32 reg, u32 value)
1306{
1307 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001308 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301309
Sujithd535a422009-02-09 13:27:06 +05301310 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301311 case AR9280_DEVID_PCI:
1312 if (reg == 0x7894) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001313 ath_print(common, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301314 "ini VAL: %x EEPROM: %x\n", value,
1315 (pBase->version & 0xff));
1316
1317 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001318 ath_print(common, ATH_DBG_EEPROM,
1319 "PWDCLKIND: %d\n",
1320 pBase->pwdclkind);
Sujithf1dc5602008-10-29 10:16:30 +05301321 value &= ~AR_AN_TOP2_PWDCLKIND;
1322 value |= AR_AN_TOP2_PWDCLKIND &
1323 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1324 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001325 ath_print(common, ATH_DBG_EEPROM,
1326 "PWDCLKIND Earlier Rev\n");
Sujithf1dc5602008-10-29 10:16:30 +05301327 }
1328
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001329 ath_print(common, ATH_DBG_EEPROM,
1330 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001331 }
Sujithf1dc5602008-10-29 10:16:30 +05301332 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001333 }
1334
Sujithf1dc5602008-10-29 10:16:30 +05301335 return value;
1336}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001337
Sujithcbe61d82009-02-09 13:27:12 +05301338static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301339 struct ar5416_eeprom_def *pEepData,
1340 u32 reg, u32 value)
1341{
Sujith2660b812009-02-09 13:27:26 +05301342 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301343 return value;
1344 else
1345 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1346}
1347
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301348static void ath9k_olc_init(struct ath_hw *ah)
1349{
1350 u32 i;
1351
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301352 if (OLC_FOR_AR9287_10_LATER) {
1353 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1354 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1355 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1356 AR9287_AN_TXPC0_TXPCMODE,
1357 AR9287_AN_TXPC0_TXPCMODE_S,
1358 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1359 udelay(100);
1360 } else {
1361 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1362 ah->originalGain[i] =
1363 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1364 AR_PHY_TX_GAIN);
1365 ah->PDADCdelta = 0;
1366 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301367}
1368
Bob Copeland3a702e42009-03-30 22:30:29 -04001369static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1370 struct ath9k_channel *chan)
1371{
1372 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1373
1374 if (IS_CHAN_B(chan))
1375 ctl |= CTL_11B;
1376 else if (IS_CHAN_G(chan))
1377 ctl |= CTL_11G;
1378 else
1379 ctl |= CTL_11A;
1380
1381 return ctl;
1382}
1383
Sujithcbe61d82009-02-09 13:27:12 +05301384static int ath9k_hw_process_ini(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001385 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301386{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001387 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301388 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001389 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301390 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001391
Sujithf1dc5602008-10-29 10:16:30 +05301392 switch (chan->chanmode) {
1393 case CHANNEL_A:
1394 case CHANNEL_A_HT20:
1395 modesIndex = 1;
1396 freqIndex = 1;
1397 break;
1398 case CHANNEL_A_HT40PLUS:
1399 case CHANNEL_A_HT40MINUS:
1400 modesIndex = 2;
1401 freqIndex = 1;
1402 break;
1403 case CHANNEL_G:
1404 case CHANNEL_G_HT20:
1405 case CHANNEL_B:
1406 modesIndex = 4;
1407 freqIndex = 2;
1408 break;
1409 case CHANNEL_G_HT40PLUS:
1410 case CHANNEL_G_HT40MINUS:
1411 modesIndex = 3;
1412 freqIndex = 2;
1413 break;
1414
1415 default:
1416 return -EINVAL;
1417 }
1418
1419 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301420 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301421 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301422
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001423 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301424 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301425 } else {
1426 struct ar5416IniArray temp;
1427 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301428 sizeof(u32) * ah->iniAddac.ia_rows *
1429 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301430
Sujith2660b812009-02-09 13:27:26 +05301431 memcpy(ah->addac5416_21,
1432 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301433
Sujith2660b812009-02-09 13:27:26 +05301434 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301435
Sujith2660b812009-02-09 13:27:26 +05301436 temp.ia_array = ah->addac5416_21;
1437 temp.ia_columns = ah->iniAddac.ia_columns;
1438 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301439 REG_WRITE_ARRAY(&temp, 1, regWrites);
1440 }
1441
1442 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1443
Sujith2660b812009-02-09 13:27:26 +05301444 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1445 u32 reg = INI_RA(&ah->iniModes, i, 0);
1446 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301447
Sujithf1dc5602008-10-29 10:16:30 +05301448 REG_WRITE(ah, reg, val);
1449
1450 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301451 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301452 udelay(100);
1453 }
1454
1455 DO_DELAY(regWrites);
1456 }
1457
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301458 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301459 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301460
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301461 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1462 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301463 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301464
Sujith2660b812009-02-09 13:27:26 +05301465 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1466 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1467 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301468
1469 REG_WRITE(ah, reg, val);
1470
1471 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301472 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301473 udelay(100);
1474 }
1475
1476 DO_DELAY(regWrites);
1477 }
1478
1479 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1480
1481 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301482 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301483 regWrites);
1484 }
1485
1486 ath9k_hw_override_ini(ah, chan);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001487 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301488 ath9k_hw_init_chain_masks(ah);
1489
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301490 if (OLC_FOR_AR9280_20_LATER)
1491 ath9k_olc_init(ah);
1492
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001493 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001494 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001495 channel->max_antenna_gain * 2,
1496 channel->max_power * 2,
1497 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001498 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001499
Sujithf1dc5602008-10-29 10:16:30 +05301500 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001501 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1502 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001503 return -EIO;
1504 }
1505
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001506 return 0;
1507}
1508
Sujithf1dc5602008-10-29 10:16:30 +05301509/****************************************/
1510/* Reset and Channel Switching Routines */
1511/****************************************/
1512
Sujithcbe61d82009-02-09 13:27:12 +05301513static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301514{
1515 u32 rfMode = 0;
1516
1517 if (chan == NULL)
1518 return;
1519
1520 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1521 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1522
1523 if (!AR_SREV_9280_10_OR_LATER(ah))
1524 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1525 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1526
1527 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1528 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1529
1530 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1531}
1532
Sujithcbe61d82009-02-09 13:27:12 +05301533static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301534{
1535 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1536}
1537
Sujithcbe61d82009-02-09 13:27:12 +05301538static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301539{
1540 u32 regval;
1541
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001542 /*
1543 * set AHB_MODE not to do cacheline prefetches
1544 */
Sujithf1dc5602008-10-29 10:16:30 +05301545 regval = REG_READ(ah, AR_AHB_MODE);
1546 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1547
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001548 /*
1549 * let mac dma reads be in 128 byte chunks
1550 */
Sujithf1dc5602008-10-29 10:16:30 +05301551 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1552 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1553
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001554 /*
1555 * Restore TX Trigger Level to its pre-reset value.
1556 * The initial value depends on whether aggregation is enabled, and is
1557 * adjusted whenever underruns are detected.
1558 */
Sujith2660b812009-02-09 13:27:26 +05301559 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301560
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001561 /*
1562 * let mac dma writes be in 128 byte chunks
1563 */
Sujithf1dc5602008-10-29 10:16:30 +05301564 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1565 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1566
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001567 /*
1568 * Setup receive FIFO threshold to hold off TX activities
1569 */
Sujithf1dc5602008-10-29 10:16:30 +05301570 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1571
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001572 /*
1573 * reduce the number of usable entries in PCU TXBUF to avoid
1574 * wrap around issues.
1575 */
Sujithf1dc5602008-10-29 10:16:30 +05301576 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001577 /* For AR9285 the number of Fifos are reduced to half.
1578 * So set the usable tx buf size also to half to
1579 * avoid data/delimiter underruns
1580 */
Sujithf1dc5602008-10-29 10:16:30 +05301581 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1582 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001583 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301584 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1585 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1586 }
1587}
1588
Sujithcbe61d82009-02-09 13:27:12 +05301589static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301590{
1591 u32 val;
1592
1593 val = REG_READ(ah, AR_STA_ID1);
1594 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1595 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001596 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301597 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1598 | AR_STA_ID1_KSRCH_MODE);
1599 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1600 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001601 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001602 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301603 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1604 | AR_STA_ID1_KSRCH_MODE);
1605 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1606 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001607 case NL80211_IFTYPE_STATION:
1608 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301609 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1610 break;
1611 }
1612}
1613
Sujithcbe61d82009-02-09 13:27:12 +05301614static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001615 u32 coef_scaled,
1616 u32 *coef_mantissa,
1617 u32 *coef_exponent)
1618{
1619 u32 coef_exp, coef_man;
1620
1621 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1622 if ((coef_scaled >> coef_exp) & 0x1)
1623 break;
1624
1625 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1626
1627 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1628
1629 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1630 *coef_exponent = coef_exp - 16;
1631}
1632
Sujithcbe61d82009-02-09 13:27:12 +05301633static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301634 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001635{
1636 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1637 u32 clockMhzScaled = 0x64000000;
1638 struct chan_centers centers;
1639
1640 if (IS_CHAN_HALF_RATE(chan))
1641 clockMhzScaled = clockMhzScaled >> 1;
1642 else if (IS_CHAN_QUARTER_RATE(chan))
1643 clockMhzScaled = clockMhzScaled >> 2;
1644
1645 ath9k_hw_get_channel_centers(ah, chan, &centers);
1646 coef_scaled = clockMhzScaled / centers.synth_center;
1647
1648 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1649 &ds_coef_exp);
1650
1651 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1652 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1653 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1654 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1655
1656 coef_scaled = (9 * coef_scaled) / 10;
1657
1658 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1659 &ds_coef_exp);
1660
1661 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1662 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1663 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1664 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1665}
1666
Sujithcbe61d82009-02-09 13:27:12 +05301667static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301668{
1669 u32 rst_flags;
1670 u32 tmpReg;
1671
Sujith70768492009-02-16 13:23:12 +05301672 if (AR_SREV_9100(ah)) {
1673 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1674 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1675 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1676 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1677 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1678 }
1679
Sujithf1dc5602008-10-29 10:16:30 +05301680 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1681 AR_RTC_FORCE_WAKE_ON_INT);
1682
1683 if (AR_SREV_9100(ah)) {
1684 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1685 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1686 } else {
1687 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1688 if (tmpReg &
1689 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1690 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1691 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1692 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1693 } else {
1694 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1695 }
1696
1697 rst_flags = AR_RTC_RC_MAC_WARM;
1698 if (type == ATH9K_RESET_COLD)
1699 rst_flags |= AR_RTC_RC_MAC_COLD;
1700 }
1701
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001702 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301703 udelay(50);
1704
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001705 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301706 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001707 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1708 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301709 return false;
1710 }
1711
1712 if (!AR_SREV_9100(ah))
1713 REG_WRITE(ah, AR_RC, 0);
1714
Sujithf1dc5602008-10-29 10:16:30 +05301715 if (AR_SREV_9100(ah))
1716 udelay(50);
1717
1718 return true;
1719}
1720
Sujithcbe61d82009-02-09 13:27:12 +05301721static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301722{
1723 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1724 AR_RTC_FORCE_WAKE_ON_INT);
1725
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301726 if (!AR_SREV_9100(ah))
1727 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1728
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001729 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301730 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301731
1732 if (!AR_SREV_9100(ah))
1733 REG_WRITE(ah, AR_RC, 0);
1734
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001735 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301736
1737 if (!ath9k_hw_wait(ah,
1738 AR_RTC_STATUS,
1739 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301740 AR_RTC_STATUS_ON,
1741 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001742 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1743 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301744 return false;
1745 }
1746
1747 ath9k_hw_read_revisions(ah);
1748
1749 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1750}
1751
Sujithcbe61d82009-02-09 13:27:12 +05301752static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301753{
1754 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1755 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1756
1757 switch (type) {
1758 case ATH9K_RESET_POWER_ON:
1759 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301760 case ATH9K_RESET_WARM:
1761 case ATH9K_RESET_COLD:
1762 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301763 default:
1764 return false;
1765 }
1766}
1767
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001768static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301769{
1770 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301771 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301772
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301773 if (AR_SREV_9285_10_OR_LATER(ah))
1774 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1775 AR_PHY_FC_ENABLE_DAC_FIFO);
1776
Sujithf1dc5602008-10-29 10:16:30 +05301777 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301778 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301779
1780 if (IS_CHAN_HT40(chan)) {
1781 phymode |= AR_PHY_FC_DYN2040_EN;
1782
1783 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1784 (chan->chanmode == CHANNEL_G_HT40PLUS))
1785 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1786
Sujithf1dc5602008-10-29 10:16:30 +05301787 }
1788 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1789
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001790 ath9k_hw_set11nmac2040(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301791
1792 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1793 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1794}
1795
Sujithcbe61d82009-02-09 13:27:12 +05301796static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301797 struct ath9k_channel *chan)
1798{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301799 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301800 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1801 return false;
1802 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301803 return false;
1804
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001805 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301806 return false;
1807
Sujith2660b812009-02-09 13:27:26 +05301808 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301809 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301810 ath9k_hw_set_rfmode(ah, chan);
1811
1812 return true;
1813}
1814
Sujithcbe61d82009-02-09 13:27:12 +05301815static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001816 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301817{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001818 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001819 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001820 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301821 u32 synthDelay, qnum;
1822
1823 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1824 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001825 ath_print(common, ATH_DBG_QUEUE,
1826 "Transmit frames pending on "
1827 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301828 return false;
1829 }
1830 }
1831
1832 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1833 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301834 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001835 ath_print(common, ATH_DBG_FATAL,
1836 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301837 return false;
1838 }
1839
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001840 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301841
1842 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001843 ath9k_hw_ar9280_set_channel(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301844 } else {
1845 if (!(ath9k_hw_set_channel(ah, chan))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001846 ath_print(common, ATH_DBG_FATAL,
1847 "Failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301848 return false;
1849 }
1850 }
1851
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001852 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001853 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301854 channel->max_antenna_gain * 2,
1855 channel->max_power * 2,
1856 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001857 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301858
1859 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301860 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301861 synthDelay = (4 * synthDelay) / 22;
1862 else
1863 synthDelay /= 10;
1864
1865 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1866
1867 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1868
1869 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1870 ath9k_hw_set_delta_slope(ah, chan);
1871
1872 if (AR_SREV_9280_10_OR_LATER(ah))
1873 ath9k_hw_9280_spur_mitigate(ah, chan);
1874 else
1875 ath9k_hw_spur_mitigate(ah, chan);
1876
1877 if (!chan->oneTimeCalsDone)
1878 chan->oneTimeCalsDone = true;
1879
1880 return true;
1881}
1882
Sujithcbe61d82009-02-09 13:27:12 +05301883static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001884{
1885 int bb_spur = AR_NO_SPUR;
1886 int freq;
1887 int bin, cur_bin;
1888 int bb_spur_off, spur_subchannel_sd;
1889 int spur_freq_sd;
1890 int spur_delta_phase;
1891 int denominator;
1892 int upper, lower, cur_vit_mask;
1893 int tmp, newVal;
1894 int i;
1895 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1896 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1897 };
1898 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1899 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1900 };
1901 int inc[4] = { 0, 100, 0, 0 };
1902 struct chan_centers centers;
1903
1904 int8_t mask_m[123];
1905 int8_t mask_p[123];
1906 int8_t mask_amt;
1907 int tmp_mask;
1908 int cur_bb_spur;
1909 bool is2GHz = IS_CHAN_2GHZ(chan);
1910
1911 memset(&mask_m, 0, sizeof(int8_t) * 123);
1912 memset(&mask_p, 0, sizeof(int8_t) * 123);
1913
1914 ath9k_hw_get_channel_centers(ah, chan, &centers);
1915 freq = centers.synth_center;
1916
Sujith2660b812009-02-09 13:27:26 +05301917 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001918 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301919 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001920
1921 if (is2GHz)
1922 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1923 else
1924 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1925
1926 if (AR_NO_SPUR == cur_bb_spur)
1927 break;
1928 cur_bb_spur = cur_bb_spur - freq;
1929
1930 if (IS_CHAN_HT40(chan)) {
1931 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1932 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1933 bb_spur = cur_bb_spur;
1934 break;
1935 }
1936 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1937 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1938 bb_spur = cur_bb_spur;
1939 break;
1940 }
1941 }
1942
1943 if (AR_NO_SPUR == bb_spur) {
1944 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1945 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1946 return;
1947 } else {
1948 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1949 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1950 }
1951
1952 bin = bb_spur * 320;
1953
1954 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1955
1956 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1957 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1958 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1959 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1960 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1961
1962 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1963 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1964 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1965 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1966 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1967 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1968
1969 if (IS_CHAN_HT40(chan)) {
1970 if (bb_spur < 0) {
1971 spur_subchannel_sd = 1;
1972 bb_spur_off = bb_spur + 10;
1973 } else {
1974 spur_subchannel_sd = 0;
1975 bb_spur_off = bb_spur - 10;
1976 }
1977 } else {
1978 spur_subchannel_sd = 0;
1979 bb_spur_off = bb_spur;
1980 }
1981
1982 if (IS_CHAN_HT40(chan))
1983 spur_delta_phase =
1984 ((bb_spur * 262144) /
1985 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1986 else
1987 spur_delta_phase =
1988 ((bb_spur * 524288) /
1989 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1990
1991 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1992 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1993
1994 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1995 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1996 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1997 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1998
1999 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
2000 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
2001
2002 cur_bin = -6000;
2003 upper = bin + 100;
2004 lower = bin - 100;
2005
2006 for (i = 0; i < 4; i++) {
2007 int pilot_mask = 0;
2008 int chan_mask = 0;
2009 int bp = 0;
2010 for (bp = 0; bp < 30; bp++) {
2011 if ((cur_bin > lower) && (cur_bin < upper)) {
2012 pilot_mask = pilot_mask | 0x1 << bp;
2013 chan_mask = chan_mask | 0x1 << bp;
2014 }
2015 cur_bin += 100;
2016 }
2017 cur_bin += inc[i];
2018 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2019 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2020 }
2021
2022 cur_vit_mask = 6100;
2023 upper = bin + 120;
2024 lower = bin - 120;
2025
2026 for (i = 0; i < 123; i++) {
2027 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002028
2029 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002030 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002031
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002032 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002033 mask_amt = 1;
2034 else
2035 mask_amt = 0;
2036 if (cur_vit_mask < 0)
2037 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2038 else
2039 mask_p[cur_vit_mask / 100] = mask_amt;
2040 }
2041 cur_vit_mask -= 100;
2042 }
2043
2044 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2045 | (mask_m[48] << 26) | (mask_m[49] << 24)
2046 | (mask_m[50] << 22) | (mask_m[51] << 20)
2047 | (mask_m[52] << 18) | (mask_m[53] << 16)
2048 | (mask_m[54] << 14) | (mask_m[55] << 12)
2049 | (mask_m[56] << 10) | (mask_m[57] << 8)
2050 | (mask_m[58] << 6) | (mask_m[59] << 4)
2051 | (mask_m[60] << 2) | (mask_m[61] << 0);
2052 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2053 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2054
2055 tmp_mask = (mask_m[31] << 28)
2056 | (mask_m[32] << 26) | (mask_m[33] << 24)
2057 | (mask_m[34] << 22) | (mask_m[35] << 20)
2058 | (mask_m[36] << 18) | (mask_m[37] << 16)
2059 | (mask_m[48] << 14) | (mask_m[39] << 12)
2060 | (mask_m[40] << 10) | (mask_m[41] << 8)
2061 | (mask_m[42] << 6) | (mask_m[43] << 4)
2062 | (mask_m[44] << 2) | (mask_m[45] << 0);
2063 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2064 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2065
2066 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2067 | (mask_m[18] << 26) | (mask_m[18] << 24)
2068 | (mask_m[20] << 22) | (mask_m[20] << 20)
2069 | (mask_m[22] << 18) | (mask_m[22] << 16)
2070 | (mask_m[24] << 14) | (mask_m[24] << 12)
2071 | (mask_m[25] << 10) | (mask_m[26] << 8)
2072 | (mask_m[27] << 6) | (mask_m[28] << 4)
2073 | (mask_m[29] << 2) | (mask_m[30] << 0);
2074 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2075 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2076
2077 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2078 | (mask_m[2] << 26) | (mask_m[3] << 24)
2079 | (mask_m[4] << 22) | (mask_m[5] << 20)
2080 | (mask_m[6] << 18) | (mask_m[7] << 16)
2081 | (mask_m[8] << 14) | (mask_m[9] << 12)
2082 | (mask_m[10] << 10) | (mask_m[11] << 8)
2083 | (mask_m[12] << 6) | (mask_m[13] << 4)
2084 | (mask_m[14] << 2) | (mask_m[15] << 0);
2085 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2086 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2087
2088 tmp_mask = (mask_p[15] << 28)
2089 | (mask_p[14] << 26) | (mask_p[13] << 24)
2090 | (mask_p[12] << 22) | (mask_p[11] << 20)
2091 | (mask_p[10] << 18) | (mask_p[9] << 16)
2092 | (mask_p[8] << 14) | (mask_p[7] << 12)
2093 | (mask_p[6] << 10) | (mask_p[5] << 8)
2094 | (mask_p[4] << 6) | (mask_p[3] << 4)
2095 | (mask_p[2] << 2) | (mask_p[1] << 0);
2096 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2097 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2098
2099 tmp_mask = (mask_p[30] << 28)
2100 | (mask_p[29] << 26) | (mask_p[28] << 24)
2101 | (mask_p[27] << 22) | (mask_p[26] << 20)
2102 | (mask_p[25] << 18) | (mask_p[24] << 16)
2103 | (mask_p[23] << 14) | (mask_p[22] << 12)
2104 | (mask_p[21] << 10) | (mask_p[20] << 8)
2105 | (mask_p[19] << 6) | (mask_p[18] << 4)
2106 | (mask_p[17] << 2) | (mask_p[16] << 0);
2107 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2108 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2109
2110 tmp_mask = (mask_p[45] << 28)
2111 | (mask_p[44] << 26) | (mask_p[43] << 24)
2112 | (mask_p[42] << 22) | (mask_p[41] << 20)
2113 | (mask_p[40] << 18) | (mask_p[39] << 16)
2114 | (mask_p[38] << 14) | (mask_p[37] << 12)
2115 | (mask_p[36] << 10) | (mask_p[35] << 8)
2116 | (mask_p[34] << 6) | (mask_p[33] << 4)
2117 | (mask_p[32] << 2) | (mask_p[31] << 0);
2118 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2119 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2120
2121 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2122 | (mask_p[59] << 26) | (mask_p[58] << 24)
2123 | (mask_p[57] << 22) | (mask_p[56] << 20)
2124 | (mask_p[55] << 18) | (mask_p[54] << 16)
2125 | (mask_p[53] << 14) | (mask_p[52] << 12)
2126 | (mask_p[51] << 10) | (mask_p[50] << 8)
2127 | (mask_p[49] << 6) | (mask_p[48] << 4)
2128 | (mask_p[47] << 2) | (mask_p[46] << 0);
2129 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2130 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2131}
2132
Sujithcbe61d82009-02-09 13:27:12 +05302133static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002134{
2135 int bb_spur = AR_NO_SPUR;
2136 int bin, cur_bin;
2137 int spur_freq_sd;
2138 int spur_delta_phase;
2139 int denominator;
2140 int upper, lower, cur_vit_mask;
2141 int tmp, new;
2142 int i;
2143 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2144 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2145 };
2146 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2147 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2148 };
2149 int inc[4] = { 0, 100, 0, 0 };
2150
2151 int8_t mask_m[123];
2152 int8_t mask_p[123];
2153 int8_t mask_amt;
2154 int tmp_mask;
2155 int cur_bb_spur;
2156 bool is2GHz = IS_CHAN_2GHZ(chan);
2157
2158 memset(&mask_m, 0, sizeof(int8_t) * 123);
2159 memset(&mask_p, 0, sizeof(int8_t) * 123);
2160
2161 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05302162 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002163 if (AR_NO_SPUR == cur_bb_spur)
2164 break;
2165 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2166 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2167 bb_spur = cur_bb_spur;
2168 break;
2169 }
2170 }
2171
2172 if (AR_NO_SPUR == bb_spur)
2173 return;
2174
2175 bin = bb_spur * 32;
2176
2177 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2178 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2179 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2180 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2181 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2182
2183 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2184
2185 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2186 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2187 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2188 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2189 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2190 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2191
2192 spur_delta_phase = ((bb_spur * 524288) / 100) &
2193 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2194
2195 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2196 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2197
2198 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2199 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2200 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2201 REG_WRITE(ah, AR_PHY_TIMING11, new);
2202
2203 cur_bin = -6000;
2204 upper = bin + 100;
2205 lower = bin - 100;
2206
2207 for (i = 0; i < 4; i++) {
2208 int pilot_mask = 0;
2209 int chan_mask = 0;
2210 int bp = 0;
2211 for (bp = 0; bp < 30; bp++) {
2212 if ((cur_bin > lower) && (cur_bin < upper)) {
2213 pilot_mask = pilot_mask | 0x1 << bp;
2214 chan_mask = chan_mask | 0x1 << bp;
2215 }
2216 cur_bin += 100;
2217 }
2218 cur_bin += inc[i];
2219 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2220 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2221 }
2222
2223 cur_vit_mask = 6100;
2224 upper = bin + 120;
2225 lower = bin - 120;
2226
2227 for (i = 0; i < 123; i++) {
2228 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002229
2230 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002231 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002232
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002233 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002234 mask_amt = 1;
2235 else
2236 mask_amt = 0;
2237 if (cur_vit_mask < 0)
2238 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2239 else
2240 mask_p[cur_vit_mask / 100] = mask_amt;
2241 }
2242 cur_vit_mask -= 100;
2243 }
2244
2245 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2246 | (mask_m[48] << 26) | (mask_m[49] << 24)
2247 | (mask_m[50] << 22) | (mask_m[51] << 20)
2248 | (mask_m[52] << 18) | (mask_m[53] << 16)
2249 | (mask_m[54] << 14) | (mask_m[55] << 12)
2250 | (mask_m[56] << 10) | (mask_m[57] << 8)
2251 | (mask_m[58] << 6) | (mask_m[59] << 4)
2252 | (mask_m[60] << 2) | (mask_m[61] << 0);
2253 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2254 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2255
2256 tmp_mask = (mask_m[31] << 28)
2257 | (mask_m[32] << 26) | (mask_m[33] << 24)
2258 | (mask_m[34] << 22) | (mask_m[35] << 20)
2259 | (mask_m[36] << 18) | (mask_m[37] << 16)
2260 | (mask_m[48] << 14) | (mask_m[39] << 12)
2261 | (mask_m[40] << 10) | (mask_m[41] << 8)
2262 | (mask_m[42] << 6) | (mask_m[43] << 4)
2263 | (mask_m[44] << 2) | (mask_m[45] << 0);
2264 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2265 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2266
2267 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2268 | (mask_m[18] << 26) | (mask_m[18] << 24)
2269 | (mask_m[20] << 22) | (mask_m[20] << 20)
2270 | (mask_m[22] << 18) | (mask_m[22] << 16)
2271 | (mask_m[24] << 14) | (mask_m[24] << 12)
2272 | (mask_m[25] << 10) | (mask_m[26] << 8)
2273 | (mask_m[27] << 6) | (mask_m[28] << 4)
2274 | (mask_m[29] << 2) | (mask_m[30] << 0);
2275 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2276 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2277
2278 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2279 | (mask_m[2] << 26) | (mask_m[3] << 24)
2280 | (mask_m[4] << 22) | (mask_m[5] << 20)
2281 | (mask_m[6] << 18) | (mask_m[7] << 16)
2282 | (mask_m[8] << 14) | (mask_m[9] << 12)
2283 | (mask_m[10] << 10) | (mask_m[11] << 8)
2284 | (mask_m[12] << 6) | (mask_m[13] << 4)
2285 | (mask_m[14] << 2) | (mask_m[15] << 0);
2286 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2287 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2288
2289 tmp_mask = (mask_p[15] << 28)
2290 | (mask_p[14] << 26) | (mask_p[13] << 24)
2291 | (mask_p[12] << 22) | (mask_p[11] << 20)
2292 | (mask_p[10] << 18) | (mask_p[9] << 16)
2293 | (mask_p[8] << 14) | (mask_p[7] << 12)
2294 | (mask_p[6] << 10) | (mask_p[5] << 8)
2295 | (mask_p[4] << 6) | (mask_p[3] << 4)
2296 | (mask_p[2] << 2) | (mask_p[1] << 0);
2297 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2298 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2299
2300 tmp_mask = (mask_p[30] << 28)
2301 | (mask_p[29] << 26) | (mask_p[28] << 24)
2302 | (mask_p[27] << 22) | (mask_p[26] << 20)
2303 | (mask_p[25] << 18) | (mask_p[24] << 16)
2304 | (mask_p[23] << 14) | (mask_p[22] << 12)
2305 | (mask_p[21] << 10) | (mask_p[20] << 8)
2306 | (mask_p[19] << 6) | (mask_p[18] << 4)
2307 | (mask_p[17] << 2) | (mask_p[16] << 0);
2308 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2309 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2310
2311 tmp_mask = (mask_p[45] << 28)
2312 | (mask_p[44] << 26) | (mask_p[43] << 24)
2313 | (mask_p[42] << 22) | (mask_p[41] << 20)
2314 | (mask_p[40] << 18) | (mask_p[39] << 16)
2315 | (mask_p[38] << 14) | (mask_p[37] << 12)
2316 | (mask_p[36] << 10) | (mask_p[35] << 8)
2317 | (mask_p[34] << 6) | (mask_p[33] << 4)
2318 | (mask_p[32] << 2) | (mask_p[31] << 0);
2319 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2320 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2321
2322 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2323 | (mask_p[59] << 26) | (mask_p[58] << 24)
2324 | (mask_p[57] << 22) | (mask_p[56] << 20)
2325 | (mask_p[55] << 18) | (mask_p[54] << 16)
2326 | (mask_p[53] << 14) | (mask_p[52] << 12)
2327 | (mask_p[51] << 10) | (mask_p[50] << 8)
2328 | (mask_p[49] << 6) | (mask_p[48] << 4)
2329 | (mask_p[47] << 2) | (mask_p[46] << 0);
2330 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2331 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2332}
2333
Johannes Berg3b319aa2009-06-13 14:50:26 +05302334static void ath9k_enable_rfkill(struct ath_hw *ah)
2335{
2336 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2337 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
2338
2339 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
2340 AR_GPIO_INPUT_MUX2_RFSILENT);
2341
2342 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
2343 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
2344}
2345
Sujithcbe61d82009-02-09 13:27:12 +05302346int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002347 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002348{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002349 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002350 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05302351 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002352 u32 saveDefAntenna;
2353 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05302354 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002355 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002356
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07002357 ah->txchainmask = common->tx_chainmask;
2358 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002359
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002360 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002361 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002362
Vasanthakumar Thiagarajan9ebef7992009-09-17 09:26:44 +05302363 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002364 ath9k_hw_getnf(ah, curchan);
2365
2366 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302367 (ah->chip_fullsleep != true) &&
2368 (ah->curchan != NULL) &&
2369 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002370 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302371 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05302372 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
2373 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002374
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002375 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05302376 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002377 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002378 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002379 }
2380 }
2381
2382 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2383 if (saveDefAntenna == 0)
2384 saveDefAntenna = 1;
2385
2386 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2387
Sujith46fe7822009-09-17 09:25:25 +05302388 /* For chips on which RTC reset is done, save TSF before it gets cleared */
2389 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2390 tsf = ath9k_hw_gettsf64(ah);
2391
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002392 saveLedState = REG_READ(ah, AR_CFG_LED) &
2393 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2394 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2395
2396 ath9k_hw_mark_phy_inactive(ah);
2397
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002398 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2399 REG_WRITE(ah,
2400 AR9271_RESET_POWER_DOWN_CONTROL,
2401 AR9271_RADIO_RF_RST);
2402 udelay(50);
2403 }
2404
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002405 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002406 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002407 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002408 }
2409
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002410 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2411 ah->htc_reset_init = false;
2412 REG_WRITE(ah,
2413 AR9271_RESET_POWER_DOWN_CONTROL,
2414 AR9271_GATE_MAC_CTL);
2415 udelay(50);
2416 }
2417
Sujith46fe7822009-09-17 09:25:25 +05302418 /* Restore TSF */
2419 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2420 ath9k_hw_settsf64(ah, tsf);
2421
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302422 if (AR_SREV_9280_10_OR_LATER(ah))
2423 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002424
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302425 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302426 /* Enable ASYNC FIFO */
2427 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2428 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2429 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2430 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2431 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2432 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2433 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2434 }
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002435 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002436 if (r)
2437 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002438
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002439 /* Setup MFP options for CCMP */
2440 if (AR_SREV_9280_20_OR_LATER(ah)) {
2441 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2442 * frames when constructing CCMP AAD. */
2443 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2444 0xc7ff);
2445 ah->sw_mgmt_crypto = false;
2446 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2447 /* Disable hardware crypto for management frames */
2448 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2449 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2450 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2451 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2452 ah->sw_mgmt_crypto = true;
2453 } else
2454 ah->sw_mgmt_crypto = true;
2455
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002456 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2457 ath9k_hw_set_delta_slope(ah, chan);
2458
2459 if (AR_SREV_9280_10_OR_LATER(ah))
2460 ath9k_hw_9280_spur_mitigate(ah, chan);
2461 else
2462 ath9k_hw_spur_mitigate(ah, chan);
2463
Sujithd6509152009-03-13 08:56:05 +05302464 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002465
2466 ath9k_hw_decrease_chain_power(ah, chan);
2467
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002468 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2469 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002470 | macStaId1
2471 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302472 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302473 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302474 | ah->sta_id1_defaults);
2475 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002476
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002477 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002478
2479 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2480
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002481 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002482
2483 REG_WRITE(ah, AR_ISR, ~0);
2484
2485 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2486
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002487 if (AR_SREV_9280_10_OR_LATER(ah))
2488 ath9k_hw_ar9280_set_channel(ah, chan);
2489 else
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002490 if (!(ath9k_hw_set_channel(ah, chan)))
2491 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002492
2493 for (i = 0; i < AR_NUM_DCU; i++)
2494 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2495
Sujith2660b812009-02-09 13:27:26 +05302496 ah->intr_txqs = 0;
2497 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002498 ath9k_hw_resettxqueue(ah, i);
2499
Sujith2660b812009-02-09 13:27:26 +05302500 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002501 ath9k_hw_init_qos(ah);
2502
Sujith2660b812009-02-09 13:27:26 +05302503 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302504 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302505
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002506 ath9k_hw_init_user_settings(ah);
2507
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302508 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302509 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2510 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2511 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2512 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2513 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2514 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2515
2516 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2517 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2518
2519 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2520 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2521 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2522 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2523 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302524 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302525 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2526 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2527 }
2528
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002529 REG_WRITE(ah, AR_STA_ID1,
2530 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2531
2532 ath9k_hw_set_dma(ah);
2533
2534 REG_WRITE(ah, AR_OBS, 8);
2535
Sujith0ef1f162009-03-30 15:28:35 +05302536 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002537 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2538 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2539 }
2540
2541 ath9k_hw_init_bb(ah, chan);
2542
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002543 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002544 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002545
Sujith2660b812009-02-09 13:27:26 +05302546 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002547 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2548 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2549 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2550 }
2551
2552 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2553
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002554 /*
2555 * For big endian systems turn on swapping for descriptors
2556 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002557 if (AR_SREV_9100(ah)) {
2558 u32 mask;
2559 mask = REG_READ(ah, AR_CFG);
2560 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002561 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302562 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002563 } else {
2564 mask =
2565 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2566 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002567 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302568 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002569 }
2570 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002571 /* Configure AR9271 target WLAN */
2572 if (AR_SREV_9271(ah))
2573 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002574#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002575 else
2576 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002577#endif
2578 }
2579
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002580 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302581 ath9k_hw_btcoex_enable(ah);
2582
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002583 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002584}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002585EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002586
Sujithf1dc5602008-10-29 10:16:30 +05302587/************************/
2588/* Key Cache Management */
2589/************************/
2590
Sujithcbe61d82009-02-09 13:27:12 +05302591bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002592{
Sujithf1dc5602008-10-29 10:16:30 +05302593 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002594
Sujith2660b812009-02-09 13:27:26 +05302595 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002596 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2597 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002598 return false;
2599 }
2600
Sujithf1dc5602008-10-29 10:16:30 +05302601 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002602
Sujithf1dc5602008-10-29 10:16:30 +05302603 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2604 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2605 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2606 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2607 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2608 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2609 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2610 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2611
2612 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2613 u16 micentry = entry + 64;
2614
2615 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2616 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2617 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2618 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2619
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002620 }
2621
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002622 return true;
2623}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002624EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002625
Sujithcbe61d82009-02-09 13:27:12 +05302626bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002627{
Sujithf1dc5602008-10-29 10:16:30 +05302628 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002629
Sujith2660b812009-02-09 13:27:26 +05302630 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002631 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2632 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002633 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002634 }
2635
Sujithf1dc5602008-10-29 10:16:30 +05302636 if (mac != NULL) {
2637 macHi = (mac[5] << 8) | mac[4];
2638 macLo = (mac[3] << 24) |
2639 (mac[2] << 16) |
2640 (mac[1] << 8) |
2641 mac[0];
2642 macLo >>= 1;
2643 macLo |= (macHi & 1) << 31;
2644 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002645 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302646 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002647 }
Sujithf1dc5602008-10-29 10:16:30 +05302648 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2649 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002650
2651 return true;
2652}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002653EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002654
Sujithcbe61d82009-02-09 13:27:12 +05302655bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302656 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002657 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002658{
Sujith2660b812009-02-09 13:27:26 +05302659 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002660 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302661 u32 key0, key1, key2, key3, key4;
2662 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002663
Sujithf1dc5602008-10-29 10:16:30 +05302664 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002665 ath_print(common, ATH_DBG_FATAL,
2666 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302667 return false;
2668 }
2669
2670 switch (k->kv_type) {
2671 case ATH9K_CIPHER_AES_OCB:
2672 keyType = AR_KEYTABLE_TYPE_AES;
2673 break;
2674 case ATH9K_CIPHER_AES_CCM:
2675 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002676 ath_print(common, ATH_DBG_ANY,
2677 "AES-CCM not supported by mac rev 0x%x\n",
2678 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002679 return false;
2680 }
Sujithf1dc5602008-10-29 10:16:30 +05302681 keyType = AR_KEYTABLE_TYPE_CCM;
2682 break;
2683 case ATH9K_CIPHER_TKIP:
2684 keyType = AR_KEYTABLE_TYPE_TKIP;
2685 if (ATH9K_IS_MIC_ENABLED(ah)
2686 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002687 ath_print(common, ATH_DBG_ANY,
2688 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002689 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002690 }
Sujithf1dc5602008-10-29 10:16:30 +05302691 break;
2692 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002693 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002694 ath_print(common, ATH_DBG_ANY,
2695 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302696 return false;
2697 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002698 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302699 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002700 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302701 keyType = AR_KEYTABLE_TYPE_104;
2702 else
2703 keyType = AR_KEYTABLE_TYPE_128;
2704 break;
2705 case ATH9K_CIPHER_CLR:
2706 keyType = AR_KEYTABLE_TYPE_CLR;
2707 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002708 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002709 ath_print(common, ATH_DBG_FATAL,
2710 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002711 return false;
2712 }
Sujithf1dc5602008-10-29 10:16:30 +05302713
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002714 key0 = get_unaligned_le32(k->kv_val + 0);
2715 key1 = get_unaligned_le16(k->kv_val + 4);
2716 key2 = get_unaligned_le32(k->kv_val + 6);
2717 key3 = get_unaligned_le16(k->kv_val + 10);
2718 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002719 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302720 key4 &= 0xff;
2721
Jouni Malinen672903b2009-03-02 15:06:31 +02002722 /*
2723 * Note: Key cache registers access special memory area that requires
2724 * two 32-bit writes to actually update the values in the internal
2725 * memory. Consequently, the exact order and pairs used here must be
2726 * maintained.
2727 */
2728
Sujithf1dc5602008-10-29 10:16:30 +05302729 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2730 u16 micentry = entry + 64;
2731
Jouni Malinen672903b2009-03-02 15:06:31 +02002732 /*
2733 * Write inverted key[47:0] first to avoid Michael MIC errors
2734 * on frames that could be sent or received at the same time.
2735 * The correct key will be written in the end once everything
2736 * else is ready.
2737 */
Sujithf1dc5602008-10-29 10:16:30 +05302738 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2739 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002740
2741 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302742 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2743 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002744
2745 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302746 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2747 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002748
2749 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302750 (void) ath9k_hw_keysetmac(ah, entry, mac);
2751
Sujith2660b812009-02-09 13:27:26 +05302752 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002753 /*
2754 * TKIP uses two key cache entries:
2755 * Michael MIC TX/RX keys in the same key cache entry
2756 * (idx = main index + 64):
2757 * key0 [31:0] = RX key [31:0]
2758 * key1 [15:0] = TX key [31:16]
2759 * key1 [31:16] = reserved
2760 * key2 [31:0] = RX key [63:32]
2761 * key3 [15:0] = TX key [15:0]
2762 * key3 [31:16] = reserved
2763 * key4 [31:0] = TX key [63:32]
2764 */
Sujithf1dc5602008-10-29 10:16:30 +05302765 u32 mic0, mic1, mic2, mic3, mic4;
2766
2767 mic0 = get_unaligned_le32(k->kv_mic + 0);
2768 mic2 = get_unaligned_le32(k->kv_mic + 4);
2769 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2770 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2771 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002772
2773 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302774 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2775 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002776
2777 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302778 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2779 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002780
2781 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302782 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2783 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2784 AR_KEYTABLE_TYPE_CLR);
2785
2786 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002787 /*
2788 * TKIP uses four key cache entries (two for group
2789 * keys):
2790 * Michael MIC TX/RX keys are in different key cache
2791 * entries (idx = main index + 64 for TX and
2792 * main index + 32 + 96 for RX):
2793 * key0 [31:0] = TX/RX MIC key [31:0]
2794 * key1 [31:0] = reserved
2795 * key2 [31:0] = TX/RX MIC key [63:32]
2796 * key3 [31:0] = reserved
2797 * key4 [31:0] = reserved
2798 *
2799 * Upper layer code will call this function separately
2800 * for TX and RX keys when these registers offsets are
2801 * used.
2802 */
Sujithf1dc5602008-10-29 10:16:30 +05302803 u32 mic0, mic2;
2804
2805 mic0 = get_unaligned_le32(k->kv_mic + 0);
2806 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002807
2808 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302809 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2810 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002811
2812 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302813 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2814 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002815
2816 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302817 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2818 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2819 AR_KEYTABLE_TYPE_CLR);
2820 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002821
2822 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302823 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2824 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002825
2826 /*
2827 * Write the correct (un-inverted) key[47:0] last to enable
2828 * TKIP now that all other registers are set with correct
2829 * values.
2830 */
Sujithf1dc5602008-10-29 10:16:30 +05302831 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2832 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2833 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002834 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302835 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2836 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002837
2838 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302839 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2840 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002841
2842 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302843 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2844 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2845
Jouni Malinen672903b2009-03-02 15:06:31 +02002846 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302847 (void) ath9k_hw_keysetmac(ah, entry, mac);
2848 }
2849
Sujithf1dc5602008-10-29 10:16:30 +05302850 return true;
2851}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002852EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302853
Sujithcbe61d82009-02-09 13:27:12 +05302854bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302855{
Sujith2660b812009-02-09 13:27:26 +05302856 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302857 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2858 if (val & AR_KEYTABLE_VALID)
2859 return true;
2860 }
2861 return false;
2862}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002863EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302864
2865/******************************/
2866/* Power Management (Chipset) */
2867/******************************/
2868
Sujithcbe61d82009-02-09 13:27:12 +05302869static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302870{
2871 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2872 if (setChip) {
2873 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2874 AR_RTC_FORCE_WAKE_EN);
2875 if (!AR_SREV_9100(ah))
2876 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2877
Sujith4921be82009-09-18 15:04:27 +05302878 if(!AR_SREV_5416(ah))
2879 REG_CLR_BIT(ah, (AR_RTC_RESET),
2880 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302881 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002882}
2883
Sujithcbe61d82009-02-09 13:27:12 +05302884static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002885{
Sujithf1dc5602008-10-29 10:16:30 +05302886 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2887 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302888 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002889
Sujithf1dc5602008-10-29 10:16:30 +05302890 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2891 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2892 AR_RTC_FORCE_WAKE_ON_INT);
2893 } else {
2894 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2895 AR_RTC_FORCE_WAKE_EN);
2896 }
2897 }
2898}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002899
Sujithcbe61d82009-02-09 13:27:12 +05302900static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302901{
2902 u32 val;
2903 int i;
2904
2905 if (setChip) {
2906 if ((REG_READ(ah, AR_RTC_STATUS) &
2907 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2908 if (ath9k_hw_set_reset_reg(ah,
2909 ATH9K_RESET_POWER_ON) != true) {
2910 return false;
2911 }
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302912 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302913 }
2914 if (AR_SREV_9100(ah))
2915 REG_SET_BIT(ah, AR_RTC_RESET,
2916 AR_RTC_RESET_EN);
2917
2918 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2919 AR_RTC_FORCE_WAKE_EN);
2920 udelay(50);
2921
2922 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2923 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2924 if (val == AR_RTC_STATUS_ON)
2925 break;
2926 udelay(50);
2927 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2928 AR_RTC_FORCE_WAKE_EN);
2929 }
2930 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002931 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2932 "Failed to wakeup in %uus\n",
2933 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302934 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002935 }
2936 }
2937
Sujithf1dc5602008-10-29 10:16:30 +05302938 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2939
2940 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002941}
2942
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002943bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302944{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002945 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302946 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302947 static const char *modes[] = {
2948 "AWAKE",
2949 "FULL-SLEEP",
2950 "NETWORK SLEEP",
2951 "UNDEFINED"
2952 };
Sujithf1dc5602008-10-29 10:16:30 +05302953
Gabor Juhoscbdec972009-07-24 17:27:22 +02002954 if (ah->power_mode == mode)
2955 return status;
2956
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002957 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2958 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302959
2960 switch (mode) {
2961 case ATH9K_PM_AWAKE:
2962 status = ath9k_hw_set_power_awake(ah, setChip);
2963 break;
2964 case ATH9K_PM_FULL_SLEEP:
2965 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302966 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302967 break;
2968 case ATH9K_PM_NETWORK_SLEEP:
2969 ath9k_set_power_network_sleep(ah, setChip);
2970 break;
2971 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002972 ath_print(common, ATH_DBG_FATAL,
2973 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302974 return false;
2975 }
Sujith2660b812009-02-09 13:27:26 +05302976 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302977
2978 return status;
2979}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002980EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302981
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002982/*
2983 * Helper for ASPM support.
2984 *
2985 * Disable PLL when in L0s as well as receiver clock when in L1.
2986 * This power saving option must be enabled through the SerDes.
2987 *
2988 * Programming the SerDes must go through the same 288 bit serial shift
2989 * register as the other analog registers. Hence the 9 writes.
2990 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302991void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302992{
Sujithf1dc5602008-10-29 10:16:30 +05302993 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302994 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302995
Sujith2660b812009-02-09 13:27:26 +05302996 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302997 return;
2998
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002999 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05303000 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05303001 return;
3002
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003003 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303004 if (!restore) {
3005 if (AR_SREV_9280_20_OR_LATER(ah)) {
3006 /*
3007 * AR9280 2.0 or later chips use SerDes values from the
3008 * initvals.h initialized depending on chipset during
3009 * ath9k_hw_init()
3010 */
3011 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
3012 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
3013 INI_RA(&ah->iniPcieSerdes, i, 1));
3014 }
3015 } else if (AR_SREV_9280(ah) &&
3016 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
3017 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
3018 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05303019
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303020 /* RX shut off when elecidle is asserted */
3021 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
3022 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
3023 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
3024
3025 /* Shut off CLKREQ active in L1 */
3026 if (ah->config.pcie_clock_req)
3027 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
3028 else
3029 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
3030
3031 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3032 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3033 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
3034
3035 /* Load the new settings */
3036 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
3037
3038 } else {
3039 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
3040 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
3041
3042 /* RX shut off when elecidle is asserted */
3043 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
3044 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
3045 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
3046
3047 /*
3048 * Ignore ah->ah_config.pcie_clock_req setting for
3049 * pre-AR9280 11n
3050 */
3051 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
3052
3053 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3054 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3055 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
3056
3057 /* Load the new settings */
3058 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05303059 }
Sujithf1dc5602008-10-29 10:16:30 +05303060
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303061 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05303062
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303063 /* set bit 19 to allow forcing of pcie core into L1 state */
3064 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05303065
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303066 /* Several PCIe massages to ensure proper behaviour */
3067 if (ah->config.pcie_waen) {
3068 val = ah->config.pcie_waen;
3069 if (!power_off)
3070 val &= (~AR_WA_D3_L1_DISABLE);
3071 } else {
3072 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3073 AR_SREV_9287(ah)) {
3074 val = AR9285_WA_DEFAULT;
3075 if (!power_off)
3076 val &= (~AR_WA_D3_L1_DISABLE);
3077 } else if (AR_SREV_9280(ah)) {
3078 /*
3079 * On AR9280 chips bit 22 of 0x4004 needs to be
3080 * set otherwise card may disappear.
3081 */
3082 val = AR9280_WA_DEFAULT;
3083 if (!power_off)
3084 val &= (~AR_WA_D3_L1_DISABLE);
3085 } else
3086 val = AR_WA_DEFAULT;
3087 }
Sujithf1dc5602008-10-29 10:16:30 +05303088
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303089 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05303090 }
3091
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303092 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003093 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303094 * Set PCIe workaround bits
3095 * bit 14 in WA register (disable L1) should only
3096 * be set when device enters D3 and be cleared
3097 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003098 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303099 if (ah->config.pcie_waen) {
3100 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
3101 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3102 } else {
3103 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3104 AR_SREV_9287(ah)) &&
3105 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
3106 (AR_SREV_9280(ah) &&
3107 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
3108 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3109 }
3110 }
Sujithf1dc5602008-10-29 10:16:30 +05303111 }
3112}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003113EXPORT_SYMBOL(ath9k_hw_configpcipowersave);
Sujithf1dc5602008-10-29 10:16:30 +05303114
3115/**********************/
3116/* Interrupt Handling */
3117/**********************/
3118
Sujithcbe61d82009-02-09 13:27:12 +05303119bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003120{
3121 u32 host_isr;
3122
3123 if (AR_SREV_9100(ah))
3124 return true;
3125
3126 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
3127 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
3128 return true;
3129
3130 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
3131 if ((host_isr & AR_INTR_SYNC_DEFAULT)
3132 && (host_isr != AR_INTR_SPURIOUS))
3133 return true;
3134
3135 return false;
3136}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003137EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003138
Sujithcbe61d82009-02-09 13:27:12 +05303139bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003140{
3141 u32 isr = 0;
3142 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05303143 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003144 u32 sync_cause = 0;
3145 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003146 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003147
3148 if (!AR_SREV_9100(ah)) {
3149 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
3150 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
3151 == AR_RTC_STATUS_ON) {
3152 isr = REG_READ(ah, AR_ISR);
3153 }
3154 }
3155
Sujithf1dc5602008-10-29 10:16:30 +05303156 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
3157 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003158
3159 *masked = 0;
3160
3161 if (!isr && !sync_cause)
3162 return false;
3163 } else {
3164 *masked = 0;
3165 isr = REG_READ(ah, AR_ISR);
3166 }
3167
3168 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003169 if (isr & AR_ISR_BCNMISC) {
3170 u32 isr2;
3171 isr2 = REG_READ(ah, AR_ISR_S2);
3172 if (isr2 & AR_ISR_S2_TIM)
3173 mask2 |= ATH9K_INT_TIM;
3174 if (isr2 & AR_ISR_S2_DTIM)
3175 mask2 |= ATH9K_INT_DTIM;
3176 if (isr2 & AR_ISR_S2_DTIMSYNC)
3177 mask2 |= ATH9K_INT_DTIMSYNC;
3178 if (isr2 & (AR_ISR_S2_CABEND))
3179 mask2 |= ATH9K_INT_CABEND;
3180 if (isr2 & AR_ISR_S2_GTT)
3181 mask2 |= ATH9K_INT_GTT;
3182 if (isr2 & AR_ISR_S2_CST)
3183 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05303184 if (isr2 & AR_ISR_S2_TSFOOR)
3185 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003186 }
3187
3188 isr = REG_READ(ah, AR_ISR_RAC);
3189 if (isr == 0xffffffff) {
3190 *masked = 0;
3191 return false;
3192 }
3193
3194 *masked = isr & ATH9K_INT_COMMON;
3195
Sujith0ef1f162009-03-30 15:28:35 +05303196 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003197 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
3198 *masked |= ATH9K_INT_RX;
3199 }
3200
3201 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
3202 *masked |= ATH9K_INT_RX;
3203 if (isr &
3204 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
3205 AR_ISR_TXEOL)) {
3206 u32 s0_s, s1_s;
3207
3208 *masked |= ATH9K_INT_TX;
3209
3210 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05303211 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
3212 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003213
3214 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05303215 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
3216 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003217 }
3218
3219 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003220 ath_print(common, ATH_DBG_INTERRUPT,
3221 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003222 }
3223
3224 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05303225 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003226 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
3227 if (isr5 & AR_ISR_S5_TIM_TIMER)
3228 *masked |= ATH9K_INT_TIM_TIMER;
3229 }
3230 }
3231
3232 *masked |= mask2;
3233 }
Sujithf1dc5602008-10-29 10:16:30 +05303234
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003235 if (AR_SREV_9100(ah))
3236 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303237
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303238 if (isr & AR_ISR_GENTMR) {
3239 u32 s5_s;
3240
3241 s5_s = REG_READ(ah, AR_ISR_S5_S);
3242 if (isr & AR_ISR_GENTMR) {
3243 ah->intr_gen_timer_trigger =
3244 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
3245
3246 ah->intr_gen_timer_thresh =
3247 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
3248
3249 if (ah->intr_gen_timer_trigger)
3250 *masked |= ATH9K_INT_GENTIMER;
3251
3252 }
3253 }
3254
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003255 if (sync_cause) {
3256 fatal_int =
3257 (sync_cause &
3258 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
3259 ? true : false;
3260
3261 if (fatal_int) {
3262 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003263 ath_print(common, ATH_DBG_ANY,
3264 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003265 }
3266 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003267 ath_print(common, ATH_DBG_ANY,
3268 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003269 }
Steven Luoa89bff92009-04-12 02:57:54 -07003270 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003271 }
3272 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003273 ath_print(common, ATH_DBG_INTERRUPT,
3274 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003275 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
3276 REG_WRITE(ah, AR_RC, 0);
3277 *masked |= ATH9K_INT_FATAL;
3278 }
3279 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003280 ath_print(common, ATH_DBG_INTERRUPT,
3281 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003282 }
3283
3284 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3285 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3286 }
Sujithf1dc5602008-10-29 10:16:30 +05303287
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003288 return true;
3289}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003290EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003291
Sujithcbe61d82009-02-09 13:27:12 +05303292enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003293{
Sujith2660b812009-02-09 13:27:26 +05303294 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003295 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303296 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003297 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003298
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003299 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003300
3301 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003302 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003303 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3304 (void) REG_READ(ah, AR_IER);
3305 if (!AR_SREV_9100(ah)) {
3306 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3307 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3308
3309 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3310 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3311 }
3312 }
3313
3314 mask = ints & ATH9K_INT_COMMON;
3315 mask2 = 0;
3316
3317 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05303318 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003319 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303320 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003321 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303322 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003323 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303324 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003325 mask |= AR_IMR_TXEOL;
3326 }
3327 if (ints & ATH9K_INT_RX) {
3328 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05303329 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003330 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3331 else
3332 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303333 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003334 mask |= AR_IMR_GENTMR;
3335 }
3336
3337 if (ints & (ATH9K_INT_BMISC)) {
3338 mask |= AR_IMR_BCNMISC;
3339 if (ints & ATH9K_INT_TIM)
3340 mask2 |= AR_IMR_S2_TIM;
3341 if (ints & ATH9K_INT_DTIM)
3342 mask2 |= AR_IMR_S2_DTIM;
3343 if (ints & ATH9K_INT_DTIMSYNC)
3344 mask2 |= AR_IMR_S2_DTIMSYNC;
3345 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05303346 mask2 |= AR_IMR_S2_CABEND;
3347 if (ints & ATH9K_INT_TSFOOR)
3348 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003349 }
3350
3351 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3352 mask |= AR_IMR_BCNMISC;
3353 if (ints & ATH9K_INT_GTT)
3354 mask2 |= AR_IMR_S2_GTT;
3355 if (ints & ATH9K_INT_CST)
3356 mask2 |= AR_IMR_S2_CST;
3357 }
3358
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003359 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003360 REG_WRITE(ah, AR_IMR, mask);
3361 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3362 AR_IMR_S2_DTIM |
3363 AR_IMR_S2_DTIMSYNC |
3364 AR_IMR_S2_CABEND |
3365 AR_IMR_S2_CABTO |
3366 AR_IMR_S2_TSFOOR |
3367 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3368 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303369 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003370
Sujith60b67f52008-08-07 10:52:38 +05303371 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003372 if (ints & ATH9K_INT_TIM_TIMER)
3373 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3374 else
3375 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3376 }
3377
3378 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003379 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003380 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3381 if (!AR_SREV_9100(ah)) {
3382 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3383 AR_INTR_MAC_IRQ);
3384 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3385
3386
3387 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3388 AR_INTR_SYNC_DEFAULT);
3389 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3390 AR_INTR_SYNC_DEFAULT);
3391 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003392 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3393 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003394 }
3395
3396 return omask;
3397}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003398EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003399
Sujithf1dc5602008-10-29 10:16:30 +05303400/*******************/
3401/* Beacon Handling */
3402/*******************/
3403
Sujithcbe61d82009-02-09 13:27:12 +05303404void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003405{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003406 int flags = 0;
3407
Sujith2660b812009-02-09 13:27:26 +05303408 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003409
Sujith2660b812009-02-09 13:27:26 +05303410 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003411 case NL80211_IFTYPE_STATION:
3412 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003413 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3414 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3415 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3416 flags |= AR_TBTT_TIMER_EN;
3417 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003418 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003419 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003420 REG_SET_BIT(ah, AR_TXCFG,
3421 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3422 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3423 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303424 (ah->atim_window ? ah->
3425 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003426 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003427 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003428 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3429 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3430 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303431 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303432 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003433 REG_WRITE(ah, AR_NEXT_SWBA,
3434 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303435 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303436 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003437 flags |=
3438 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3439 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003440 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003441 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
3442 "%s: unsupported opmode: %d\n",
3443 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003444 return;
3445 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003446 }
3447
3448 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3449 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3450 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3451 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3452
3453 beacon_period &= ~ATH9K_BEACON_ENA;
3454 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003455 ath9k_hw_reset_tsf(ah);
3456 }
3457
3458 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3459}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003460EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003461
Sujithcbe61d82009-02-09 13:27:12 +05303462void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303463 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003464{
3465 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303466 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003467 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003468
3469 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3470
3471 REG_WRITE(ah, AR_BEACON_PERIOD,
3472 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3473 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3474 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3475
3476 REG_RMW_FIELD(ah, AR_RSSI_THR,
3477 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3478
3479 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3480
3481 if (bs->bs_sleepduration > beaconintval)
3482 beaconintval = bs->bs_sleepduration;
3483
3484 dtimperiod = bs->bs_dtimperiod;
3485 if (bs->bs_sleepduration > dtimperiod)
3486 dtimperiod = bs->bs_sleepduration;
3487
3488 if (beaconintval == dtimperiod)
3489 nextTbtt = bs->bs_nextdtim;
3490 else
3491 nextTbtt = bs->bs_nexttbtt;
3492
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003493 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3494 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3495 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3496 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003497
3498 REG_WRITE(ah, AR_NEXT_DTIM,
3499 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3500 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3501
3502 REG_WRITE(ah, AR_SLEEP1,
3503 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3504 | AR_SLEEP1_ASSUME_DTIM);
3505
Sujith60b67f52008-08-07 10:52:38 +05303506 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003507 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3508 else
3509 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3510
3511 REG_WRITE(ah, AR_SLEEP2,
3512 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3513
3514 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3515 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3516
3517 REG_SET_BIT(ah, AR_TIMER_MODE,
3518 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3519 AR_DTIM_TIMER_EN);
3520
Sujith4af9cf42009-02-12 10:06:47 +05303521 /* TSF Out of Range Threshold */
3522 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003523}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003524EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003525
Sujithf1dc5602008-10-29 10:16:30 +05303526/*******************/
3527/* HW Capabilities */
3528/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003529
Sujitheef7a572009-03-30 15:28:28 +05303530void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003531{
Sujith2660b812009-02-09 13:27:26 +05303532 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003533 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003534 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003535 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003536
Sujithf1dc5602008-10-29 10:16:30 +05303537 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003538
Sujithf74df6f2009-02-09 13:27:24 +05303539 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003540 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303541
Sujithf74df6f2009-02-09 13:27:24 +05303542 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303543 if (AR_SREV_9285_10_OR_LATER(ah))
3544 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003545 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303546
Sujithf74df6f2009-02-09 13:27:24 +05303547 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303548
Sujith2660b812009-02-09 13:27:26 +05303549 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303550 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003551 if (regulatory->current_rd == 0x64 ||
3552 regulatory->current_rd == 0x65)
3553 regulatory->current_rd += 5;
3554 else if (regulatory->current_rd == 0x41)
3555 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003556 ath_print(common, ATH_DBG_REGULATORY,
3557 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003558 }
Sujithdc2222a2008-08-14 13:26:55 +05303559
Sujithf74df6f2009-02-09 13:27:24 +05303560 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303561 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003562
Sujithf1dc5602008-10-29 10:16:30 +05303563 if (eeval & AR5416_OPFLAGS_11A) {
3564 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303565 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303566 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3567 set_bit(ATH9K_MODE_11NA_HT20,
3568 pCap->wireless_modes);
3569 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3570 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3571 pCap->wireless_modes);
3572 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3573 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003574 }
3575 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003576 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003577
Sujithf1dc5602008-10-29 10:16:30 +05303578 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303579 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303580 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303581 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3582 set_bit(ATH9K_MODE_11NG_HT20,
3583 pCap->wireless_modes);
3584 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3585 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3586 pCap->wireless_modes);
3587 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3588 pCap->wireless_modes);
3589 }
3590 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003591 }
Sujithf1dc5602008-10-29 10:16:30 +05303592
Sujithf74df6f2009-02-09 13:27:24 +05303593 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003594 /*
3595 * For AR9271 we will temporarilly uses the rx chainmax as read from
3596 * the EEPROM.
3597 */
Sujith8147f5d2009-02-20 15:13:23 +05303598 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003599 !(eeval & AR5416_OPFLAGS_11A) &&
3600 !(AR_SREV_9271(ah)))
3601 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303602 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3603 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003604 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303605 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303606
Sujithd535a422009-02-09 13:27:06 +05303607 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303608 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303609
3610 pCap->low_2ghz_chan = 2312;
3611 pCap->high_2ghz_chan = 2732;
3612
3613 pCap->low_5ghz_chan = 4920;
3614 pCap->high_5ghz_chan = 6100;
3615
3616 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3617 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3618 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3619
3620 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3621 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3622 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3623
Sujith2660b812009-02-09 13:27:26 +05303624 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303625 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3626 else
3627 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3628
3629 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3630 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3631 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3632 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3633
3634 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3635 pCap->total_queues =
3636 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3637 else
3638 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3639
3640 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3641 pCap->keycache_size =
3642 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3643 else
3644 pCap->keycache_size = AR_KEYTABLE_SIZE;
3645
3646 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303647 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3648
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303649 if (AR_SREV_9285_10_OR_LATER(ah))
3650 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3651 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303652 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3653 else
3654 pCap->num_gpio_pins = AR_NUM_GPIO;
3655
Sujithf1dc5602008-10-29 10:16:30 +05303656 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3657 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3658 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3659 } else {
3660 pCap->rts_aggr_limit = (8 * 1024);
3661 }
3662
3663 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3664
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303665#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303666 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3667 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3668 ah->rfkill_gpio =
3669 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3670 ah->rfkill_polarity =
3671 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303672
3673 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3674 }
3675#endif
3676
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303677 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303678
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303679 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303680 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3681 else
3682 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3683
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003684 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303685 pCap->reg_cap =
3686 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3687 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3688 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3689 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3690 } else {
3691 pCap->reg_cap =
3692 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3693 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3694 }
3695
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05303696 /* Advertise midband for AR5416 with FCC midband set in eeprom */
3697 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
3698 AR_SREV_5416(ah))
3699 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05303700
3701 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303702 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303703 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303704 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303705
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303706 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003707 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003708 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3709 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303710
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303711 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003712 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3713 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303714 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003715 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303716 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303717 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003718 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303719 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003720}
3721
Sujithcbe61d82009-02-09 13:27:12 +05303722bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303723 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003724{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003725 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303726 switch (type) {
3727 case ATH9K_CAP_CIPHER:
3728 switch (capability) {
3729 case ATH9K_CIPHER_AES_CCM:
3730 case ATH9K_CIPHER_AES_OCB:
3731 case ATH9K_CIPHER_TKIP:
3732 case ATH9K_CIPHER_WEP:
3733 case ATH9K_CIPHER_MIC:
3734 case ATH9K_CIPHER_CLR:
3735 return true;
3736 default:
3737 return false;
3738 }
3739 case ATH9K_CAP_TKIP_MIC:
3740 switch (capability) {
3741 case 0:
3742 return true;
3743 case 1:
Sujith2660b812009-02-09 13:27:26 +05303744 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303745 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3746 false;
3747 }
3748 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303749 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303750 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303751 case ATH9K_CAP_DIVERSITY:
3752 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3753 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3754 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303755 case ATH9K_CAP_MCAST_KEYSRCH:
3756 switch (capability) {
3757 case 0:
3758 return true;
3759 case 1:
3760 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3761 return false;
3762 } else {
Sujith2660b812009-02-09 13:27:26 +05303763 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303764 AR_STA_ID1_MCAST_KSRCH) ? true :
3765 false;
3766 }
3767 }
3768 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303769 case ATH9K_CAP_TXPOW:
3770 switch (capability) {
3771 case 0:
3772 return 0;
3773 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003774 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303775 return 0;
3776 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003777 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303778 return 0;
3779 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003780 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303781 return 0;
3782 }
3783 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303784 case ATH9K_CAP_DS:
3785 return (AR_SREV_9280_20_OR_LATER(ah) &&
3786 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3787 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303788 default:
3789 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003790 }
Sujithf1dc5602008-10-29 10:16:30 +05303791}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003792EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003793
Sujithcbe61d82009-02-09 13:27:12 +05303794bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303795 u32 capability, u32 setting, int *status)
3796{
Sujithf1dc5602008-10-29 10:16:30 +05303797 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003798
Sujithf1dc5602008-10-29 10:16:30 +05303799 switch (type) {
3800 case ATH9K_CAP_TKIP_MIC:
3801 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303802 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303803 AR_STA_ID1_CRPT_MIC_ENABLE;
3804 else
Sujith2660b812009-02-09 13:27:26 +05303805 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303806 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3807 return true;
3808 case ATH9K_CAP_DIVERSITY:
3809 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3810 if (setting)
3811 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3812 else
3813 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3814 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3815 return true;
3816 case ATH9K_CAP_MCAST_KEYSRCH:
3817 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303818 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303819 else
Sujith2660b812009-02-09 13:27:26 +05303820 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303821 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303822 default:
3823 return false;
3824 }
3825}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003826EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303827
3828/****************************/
3829/* GPIO / RFKILL / Antennae */
3830/****************************/
3831
Sujithcbe61d82009-02-09 13:27:12 +05303832static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303833 u32 gpio, u32 type)
3834{
3835 int addr;
3836 u32 gpio_shift, tmp;
3837
3838 if (gpio > 11)
3839 addr = AR_GPIO_OUTPUT_MUX3;
3840 else if (gpio > 5)
3841 addr = AR_GPIO_OUTPUT_MUX2;
3842 else
3843 addr = AR_GPIO_OUTPUT_MUX1;
3844
3845 gpio_shift = (gpio % 6) * 5;
3846
3847 if (AR_SREV_9280_20_OR_LATER(ah)
3848 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3849 REG_RMW(ah, addr, (type << gpio_shift),
3850 (0x1f << gpio_shift));
3851 } else {
3852 tmp = REG_READ(ah, addr);
3853 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3854 tmp &= ~(0x1f << gpio_shift);
3855 tmp |= (type << gpio_shift);
3856 REG_WRITE(ah, addr, tmp);
3857 }
3858}
3859
Sujithcbe61d82009-02-09 13:27:12 +05303860void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303861{
3862 u32 gpio_shift;
3863
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003864 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303865
3866 gpio_shift = gpio << 1;
3867
3868 REG_RMW(ah,
3869 AR_GPIO_OE_OUT,
3870 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3871 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3872}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003873EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303874
Sujithcbe61d82009-02-09 13:27:12 +05303875u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303876{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303877#define MS_REG_READ(x, y) \
3878 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3879
Sujith2660b812009-02-09 13:27:26 +05303880 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303881 return 0xffffffff;
3882
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303883 if (AR_SREV_9287_10_OR_LATER(ah))
3884 return MS_REG_READ(AR9287, gpio) != 0;
3885 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303886 return MS_REG_READ(AR9285, gpio) != 0;
3887 else if (AR_SREV_9280_10_OR_LATER(ah))
3888 return MS_REG_READ(AR928X, gpio) != 0;
3889 else
3890 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303891}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003892EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303893
Sujithcbe61d82009-02-09 13:27:12 +05303894void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303895 u32 ah_signal_type)
3896{
3897 u32 gpio_shift;
3898
3899 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3900
3901 gpio_shift = 2 * gpio;
3902
3903 REG_RMW(ah,
3904 AR_GPIO_OE_OUT,
3905 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3906 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3907}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003908EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303909
Sujithcbe61d82009-02-09 13:27:12 +05303910void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303911{
3912 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3913 AR_GPIO_BIT(gpio));
3914}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003915EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303916
Sujithcbe61d82009-02-09 13:27:12 +05303917u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303918{
3919 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3920}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003921EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303922
Sujithcbe61d82009-02-09 13:27:12 +05303923void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303924{
3925 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3926}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003927EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303928
Sujithcbe61d82009-02-09 13:27:12 +05303929bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303930 enum ath9k_ant_setting settings,
3931 struct ath9k_channel *chan,
3932 u8 *tx_chainmask,
3933 u8 *rx_chainmask,
3934 u8 *antenna_cfgd)
3935{
Sujithf1dc5602008-10-29 10:16:30 +05303936 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3937
3938 if (AR_SREV_9280(ah)) {
3939 if (!tx_chainmask_cfg) {
3940
3941 tx_chainmask_cfg = *tx_chainmask;
3942 rx_chainmask_cfg = *rx_chainmask;
3943 }
3944
3945 switch (settings) {
3946 case ATH9K_ANT_FIXED_A:
3947 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3948 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3949 *antenna_cfgd = true;
3950 break;
3951 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303952 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303953 ATH9K_ANTENNA1_CHAINMASK) {
3954 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3955 }
3956 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3957 *antenna_cfgd = true;
3958 break;
3959 case ATH9K_ANT_VARIABLE:
3960 *tx_chainmask = tx_chainmask_cfg;
3961 *rx_chainmask = rx_chainmask_cfg;
3962 *antenna_cfgd = true;
3963 break;
3964 default:
3965 break;
3966 }
3967 } else {
Sujith1cf68732009-08-13 09:34:32 +05303968 ah->config.diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303969 }
3970
3971 return true;
3972}
3973
3974/*********************/
3975/* General Operation */
3976/*********************/
3977
Sujithcbe61d82009-02-09 13:27:12 +05303978u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303979{
3980 u32 bits = REG_READ(ah, AR_RX_FILTER);
3981 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3982
3983 if (phybits & AR_PHY_ERR_RADAR)
3984 bits |= ATH9K_RX_FILTER_PHYRADAR;
3985 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3986 bits |= ATH9K_RX_FILTER_PHYERR;
3987
3988 return bits;
3989}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003990EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303991
Sujithcbe61d82009-02-09 13:27:12 +05303992void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303993{
3994 u32 phybits;
3995
Sujith7ea310b2009-09-03 12:08:43 +05303996 REG_WRITE(ah, AR_RX_FILTER, bits);
3997
Sujithf1dc5602008-10-29 10:16:30 +05303998 phybits = 0;
3999 if (bits & ATH9K_RX_FILTER_PHYRADAR)
4000 phybits |= AR_PHY_ERR_RADAR;
4001 if (bits & ATH9K_RX_FILTER_PHYERR)
4002 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
4003 REG_WRITE(ah, AR_PHY_ERR, phybits);
4004
4005 if (phybits)
4006 REG_WRITE(ah, AR_RXCFG,
4007 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
4008 else
4009 REG_WRITE(ah, AR_RXCFG,
4010 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
4011}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004012EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304013
Sujithcbe61d82009-02-09 13:27:12 +05304014bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304015{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05304016 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
4017 return false;
4018
4019 ath9k_hw_init_pll(ah, NULL);
4020 return true;
Sujithf1dc5602008-10-29 10:16:30 +05304021}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004022EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05304023
Sujithcbe61d82009-02-09 13:27:12 +05304024bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304025{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07004026 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05304027 return false;
4028
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05304029 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
4030 return false;
4031
4032 ath9k_hw_init_pll(ah, NULL);
4033 return true;
Sujithf1dc5602008-10-29 10:16:30 +05304034}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004035EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05304036
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004037void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05304038{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004039 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05304040 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08004041 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05304042
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004043 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05304044
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004045 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004046 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004047 channel->max_antenna_gain * 2,
4048 channel->max_power * 2,
4049 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004050 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05304051}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004052EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05304053
Sujithcbe61d82009-02-09 13:27:12 +05304054void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05304055{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004056 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05304057}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004058EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05304059
Sujithcbe61d82009-02-09 13:27:12 +05304060void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304061{
Sujith2660b812009-02-09 13:27:26 +05304062 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05304063}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004064EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05304065
Sujithcbe61d82009-02-09 13:27:12 +05304066void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05304067{
4068 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
4069 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
4070}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004071EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304072
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07004073void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304074{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004075 struct ath_common *common = ath9k_hw_common(ah);
4076
4077 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
4078 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
4079 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05304080}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004081EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05304082
Sujithcbe61d82009-02-09 13:27:12 +05304083u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304084{
4085 u64 tsf;
4086
4087 tsf = REG_READ(ah, AR_TSF_U32);
4088 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
4089
4090 return tsf;
4091}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004092EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05304093
Sujithcbe61d82009-02-09 13:27:12 +05304094void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004095{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004096 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01004097 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004098}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004099EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004100
Sujithcbe61d82009-02-09 13:27:12 +05304101void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304102{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004103 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
4104 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004105 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4106 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004107
Sujithf1dc5602008-10-29 10:16:30 +05304108 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004109}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004110EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004111
Sujith54e4cec2009-08-07 09:45:09 +05304112void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004113{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004114 if (setting)
Sujith2660b812009-02-09 13:27:26 +05304115 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004116 else
Sujith2660b812009-02-09 13:27:26 +05304117 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004118}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004119EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004120
Sujithcbe61d82009-02-09 13:27:12 +05304121bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004122{
Sujithf1dc5602008-10-29 10:16:30 +05304123 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004124 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4125 "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05304126 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05304127 return false;
4128 } else {
4129 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05304130 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05304131 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004132 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004133}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004134EXPORT_SYMBOL(ath9k_hw_setslottime);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004135
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004136void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004137{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004138 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05304139 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004140
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004141 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05304142 macmode = AR_2040_JOINED_RX_CLEAR;
4143 else
4144 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004145
Sujithf1dc5602008-10-29 10:16:30 +05304146 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004147}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304148
4149/* HW Generic timers configuration */
4150
4151static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
4152{
4153 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4154 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4155 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4156 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4157 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4158 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4159 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4160 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4161 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
4162 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
4163 AR_NDP2_TIMER_MODE, 0x0002},
4164 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
4165 AR_NDP2_TIMER_MODE, 0x0004},
4166 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
4167 AR_NDP2_TIMER_MODE, 0x0008},
4168 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
4169 AR_NDP2_TIMER_MODE, 0x0010},
4170 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
4171 AR_NDP2_TIMER_MODE, 0x0020},
4172 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
4173 AR_NDP2_TIMER_MODE, 0x0040},
4174 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
4175 AR_NDP2_TIMER_MODE, 0x0080}
4176};
4177
4178/* HW generic timer primitives */
4179
4180/* compute and clear index of rightmost 1 */
4181static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
4182{
4183 u32 b;
4184
4185 b = *mask;
4186 b &= (0-b);
4187 *mask &= ~b;
4188 b *= debruijn32;
4189 b >>= 27;
4190
4191 return timer_table->gen_timer_index[b];
4192}
4193
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05304194u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304195{
4196 return REG_READ(ah, AR_TSF_L32);
4197}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004198EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304199
4200struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
4201 void (*trigger)(void *),
4202 void (*overflow)(void *),
4203 void *arg,
4204 u8 timer_index)
4205{
4206 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4207 struct ath_gen_timer *timer;
4208
4209 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
4210
4211 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004212 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
4213 "Failed to allocate memory"
4214 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304215 return NULL;
4216 }
4217
4218 /* allocate a hardware generic timer slot */
4219 timer_table->timers[timer_index] = timer;
4220 timer->index = timer_index;
4221 timer->trigger = trigger;
4222 timer->overflow = overflow;
4223 timer->arg = arg;
4224
4225 return timer;
4226}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004227EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304228
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004229void ath9k_hw_gen_timer_start(struct ath_hw *ah,
4230 struct ath_gen_timer *timer,
4231 u32 timer_next,
4232 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304233{
4234 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4235 u32 tsf;
4236
4237 BUG_ON(!timer_period);
4238
4239 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
4240
4241 tsf = ath9k_hw_gettsf32(ah);
4242
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004243 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
4244 "curent tsf %x period %x"
4245 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304246
4247 /*
4248 * Pull timer_next forward if the current TSF already passed it
4249 * because of software latency
4250 */
4251 if (timer_next < tsf)
4252 timer_next = tsf + timer_period;
4253
4254 /*
4255 * Program generic timer registers
4256 */
4257 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
4258 timer_next);
4259 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
4260 timer_period);
4261 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4262 gen_tmr_configuration[timer->index].mode_mask);
4263
4264 /* Enable both trigger and thresh interrupt masks */
4265 REG_SET_BIT(ah, AR_IMR_S5,
4266 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4267 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304268}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004269EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304270
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004271void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304272{
4273 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4274
4275 if ((timer->index < AR_FIRST_NDP_TIMER) ||
4276 (timer->index >= ATH_MAX_GEN_TIMER)) {
4277 return;
4278 }
4279
4280 /* Clear generic timer enable bits. */
4281 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4282 gen_tmr_configuration[timer->index].mode_mask);
4283
4284 /* Disable both trigger and thresh interrupt masks */
4285 REG_CLR_BIT(ah, AR_IMR_S5,
4286 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4287 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
4288
4289 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304290}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004291EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304292
4293void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
4294{
4295 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4296
4297 /* free the hardware generic timer slot */
4298 timer_table->timers[timer->index] = NULL;
4299 kfree(timer);
4300}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004301EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304302
4303/*
4304 * Generic Timer Interrupts handling
4305 */
4306void ath_gen_timer_isr(struct ath_hw *ah)
4307{
4308 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4309 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004310 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304311 u32 trigger_mask, thresh_mask, index;
4312
4313 /* get hardware generic timer interrupt status */
4314 trigger_mask = ah->intr_gen_timer_trigger;
4315 thresh_mask = ah->intr_gen_timer_thresh;
4316 trigger_mask &= timer_table->timer_mask.val;
4317 thresh_mask &= timer_table->timer_mask.val;
4318
4319 trigger_mask &= ~thresh_mask;
4320
4321 while (thresh_mask) {
4322 index = rightmost_index(timer_table, &thresh_mask);
4323 timer = timer_table->timers[index];
4324 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004325 ath_print(common, ATH_DBG_HWTIMER,
4326 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304327 timer->overflow(timer->arg);
4328 }
4329
4330 while (trigger_mask) {
4331 index = rightmost_index(timer_table, &trigger_mask);
4332 timer = timer_table->timers[index];
4333 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004334 ath_print(common, ATH_DBG_HWTIMER,
4335 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304336 timer->trigger(timer->arg);
4337 }
4338}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004339EXPORT_SYMBOL(ath_gen_timer_isr);