blob: 7bf0f8c42e6d551d8337f93965470e3dee2b8408 [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. Rodriguez3ca34032009-09-23 23:07:01 -0400903 if (!ath9k_hw_devid_supported(ah->hw_version.devid)) {
904 ath_print(common, ATH_DBG_FATAL,
905 "Unsupported device ID: 0x%0x\n",
906 ah->hw_version.devid);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700907 return -EOPNOTSUPP;
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400908 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700909
910 ath9k_hw_init_defaults(ah);
911 ath9k_hw_init_config(ah);
912
913 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700914 ath_print(common, ATH_DBG_FATAL,
915 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700916 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700917 }
918
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700919 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700920 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700921 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700922 }
923
924 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
925 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
926 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
927 ah->config.serialize_regmode =
928 SER_REG_MODE_ON;
929 } else {
930 ah->config.serialize_regmode =
931 SER_REG_MODE_OFF;
932 }
933 }
934
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700935 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700936 ah->config.serialize_regmode);
937
938 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700939 ath_print(common, ATH_DBG_FATAL,
940 "Mac Chip Rev 0x%02x.%x is not supported by "
941 "this driver\n", ah->hw_version.macVersion,
942 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700943 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700944 }
945
946 if (AR_SREV_9100(ah)) {
947 ah->iq_caldata.calData = &iq_cal_multi_sample;
948 ah->supp_cals = IQ_MISMATCH_CAL;
949 ah->is_pciexpress = false;
950 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400951
952 if (AR_SREV_9271(ah))
953 ah->is_pciexpress = false;
954
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700955 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
956
957 ath9k_hw_init_cal_settings(ah);
958
959 ah->ani_function = ATH9K_ANI_ALL;
960 if (AR_SREV_9280_10_OR_LATER(ah))
961 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
962
963 ath9k_hw_init_mode_regs(ah);
964
965 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530966 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700967 else
968 ath9k_hw_disablepcie(ah);
969
Sujith193cd452009-09-18 15:04:07 +0530970 /* Support for Japan ch.14 (2484) spread */
971 if (AR_SREV_9287_11_OR_LATER(ah)) {
972 INIT_INI_ARRAY(&ah->iniCckfirNormal,
973 ar9287Common_normal_cck_fir_coeff_92871_1,
974 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
975 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
976 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
977 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
978 }
979
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700980 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700981 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700982 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700983
984 ath9k_hw_init_mode_gain_regs(ah);
985 ath9k_hw_fill_cap_info(ah);
986 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530987
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700988 r = ath9k_hw_init_macaddr(ah);
989 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700990 ath_print(common, ATH_DBG_FATAL,
991 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700992 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700993 }
994
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400995 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530996 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700997 else
Sujith2660b812009-02-09 13:27:26 +0530998 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700999
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001000 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001001
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001002 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001003}
1004
Sujithcbe61d82009-02-09 13:27:12 +05301005static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301006 struct ath9k_channel *chan)
1007{
1008 u32 synthDelay;
1009
1010 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301011 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301012 synthDelay = (4 * synthDelay) / 22;
1013 else
1014 synthDelay /= 10;
1015
1016 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1017
1018 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1019}
1020
Sujithcbe61d82009-02-09 13:27:12 +05301021static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301022{
1023 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1024 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1025
1026 REG_WRITE(ah, AR_QOS_NO_ACK,
1027 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1028 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1029 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1030
1031 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1032 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1033 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1034 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1035 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1036}
1037
Sujithcbe61d82009-02-09 13:27:12 +05301038static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301039 struct ath9k_channel *chan)
1040{
1041 u32 pll;
1042
1043 if (AR_SREV_9100(ah)) {
1044 if (chan && IS_CHAN_5GHZ(chan))
1045 pll = 0x1450;
1046 else
1047 pll = 0x1458;
1048 } else {
1049 if (AR_SREV_9280_10_OR_LATER(ah)) {
1050 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1051
1052 if (chan && IS_CHAN_HALF_RATE(chan))
1053 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1054 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1055 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1056
1057 if (chan && IS_CHAN_5GHZ(chan)) {
1058 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1059
1060
1061 if (AR_SREV_9280_20(ah)) {
1062 if (((chan->channel % 20) == 0)
1063 || ((chan->channel % 10) == 0))
1064 pll = 0x2850;
1065 else
1066 pll = 0x142c;
1067 }
1068 } else {
1069 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1070 }
1071
1072 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1073
1074 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1075
1076 if (chan && IS_CHAN_HALF_RATE(chan))
1077 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1078 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1079 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1080
1081 if (chan && IS_CHAN_5GHZ(chan))
1082 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1083 else
1084 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1085 } else {
1086 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1087
1088 if (chan && IS_CHAN_HALF_RATE(chan))
1089 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1090 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1091 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1092
1093 if (chan && IS_CHAN_5GHZ(chan))
1094 pll |= SM(0xa, AR_RTC_PLL_DIV);
1095 else
1096 pll |= SM(0xb, AR_RTC_PLL_DIV);
1097 }
1098 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001099 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301100
1101 udelay(RTC_PLL_SETTLE_DELAY);
1102
1103 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1104}
1105
Sujithcbe61d82009-02-09 13:27:12 +05301106static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301107{
Sujithf1dc5602008-10-29 10:16:30 +05301108 int rx_chainmask, tx_chainmask;
1109
Sujith2660b812009-02-09 13:27:26 +05301110 rx_chainmask = ah->rxchainmask;
1111 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301112
1113 switch (rx_chainmask) {
1114 case 0x5:
1115 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1116 AR_PHY_SWAP_ALT_CHAIN);
1117 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301118 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301119 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1120 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1121 break;
1122 }
1123 case 0x1:
1124 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301125 case 0x7:
1126 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1127 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1128 break;
1129 default:
1130 break;
1131 }
1132
1133 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1134 if (tx_chainmask == 0x5) {
1135 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1136 AR_PHY_SWAP_ALT_CHAIN);
1137 }
1138 if (AR_SREV_9100(ah))
1139 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1140 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1141}
1142
Sujithcbe61d82009-02-09 13:27:12 +05301143static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001144 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301145{
Sujith2660b812009-02-09 13:27:26 +05301146 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301147 AR_IMR_TXURN |
1148 AR_IMR_RXERR |
1149 AR_IMR_RXORN |
1150 AR_IMR_BCNMISC;
1151
Sujith0ef1f162009-03-30 15:28:35 +05301152 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301153 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301154 else
Sujith2660b812009-02-09 13:27:26 +05301155 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301156
Sujith2660b812009-02-09 13:27:26 +05301157 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301158
Colin McCabed97809d2008-12-01 13:38:55 -08001159 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301160 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301161
Sujith2660b812009-02-09 13:27:26 +05301162 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301163 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1164
1165 if (!AR_SREV_9100(ah)) {
1166 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1167 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1168 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1169 }
1170}
1171
Sujithcbe61d82009-02-09 13:27:12 +05301172static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301173{
Sujithf1dc5602008-10-29 10:16:30 +05301174 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001175 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1176 "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301177 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301178 return false;
1179 } else {
1180 REG_RMW_FIELD(ah, AR_TIME_OUT,
1181 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301182 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301183 return true;
1184 }
1185}
1186
Sujithcbe61d82009-02-09 13:27:12 +05301187static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301188{
Sujithf1dc5602008-10-29 10:16:30 +05301189 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001190 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1191 "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301192 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301193 return false;
1194 } else {
1195 REG_RMW_FIELD(ah, AR_TIME_OUT,
1196 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301197 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301198 return true;
1199 }
1200}
1201
Sujithcbe61d82009-02-09 13:27:12 +05301202static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301203{
Sujithf1dc5602008-10-29 10:16:30 +05301204 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001205 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1206 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301207 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301208 return false;
1209 } else {
1210 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301211 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301212 return true;
1213 }
1214}
1215
Sujithcbe61d82009-02-09 13:27:12 +05301216static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301217{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001218 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1219 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301220
Sujith2660b812009-02-09 13:27:26 +05301221 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301222 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301223 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1224 if (ah->slottime != (u32) -1)
1225 ath9k_hw_setslottime(ah, ah->slottime);
1226 if (ah->acktimeout != (u32) -1)
1227 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1228 if (ah->ctstimeout != (u32) -1)
1229 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1230 if (ah->globaltxtimeout != (u32) -1)
1231 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301232}
1233
1234const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1235{
1236 return vendorid == ATHEROS_VENDOR_ID ?
1237 ath9k_hw_devname(devid) : NULL;
1238}
1239
Sujithcbe61d82009-02-09 13:27:12 +05301240void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001241{
1242 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001243 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001244
Luis R. Rodriguez081b35a2009-08-03 12:24:50 -07001245 ath9k_hw_rf_free(ah);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001246 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001247 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001248 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001249}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001250EXPORT_SYMBOL(ath9k_hw_detach);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001251
Sujithf1dc5602008-10-29 10:16:30 +05301252/*******/
1253/* INI */
1254/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001255
Sujithcbe61d82009-02-09 13:27:12 +05301256static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301257 struct ath9k_channel *chan)
1258{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001259 u32 val;
1260
1261 if (AR_SREV_9271(ah)) {
1262 /*
1263 * Enable spectral scan to solution for issues with stuck
1264 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1265 * AR9271 1.1
1266 */
1267 if (AR_SREV_9271_10(ah)) {
1268 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE;
1269 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1270 }
1271 else if (AR_SREV_9271_11(ah))
1272 /*
1273 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1274 * present on AR9271 1.1
1275 */
1276 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1277 return;
1278 }
1279
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301280 /*
1281 * Set the RX_ABORT and RX_DIS and clear if off only after
1282 * RXE is set for MAC. This prevents frames with corrupted
1283 * descriptor status.
1284 */
1285 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1286
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301287 if (AR_SREV_9280_10_OR_LATER(ah)) {
1288 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1289 (~AR_PCU_MISC_MODE2_HWWAR1);
1290
1291 if (AR_SREV_9287_10_OR_LATER(ah))
1292 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1293
1294 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1295 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301296
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001297 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301298 AR_SREV_9280_10_OR_LATER(ah))
1299 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001300 /*
1301 * Disable BB clock gating
1302 * Necessary to avoid issues on AR5416 2.0
1303 */
Sujithf1dc5602008-10-29 10:16:30 +05301304 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1305}
1306
Sujithcbe61d82009-02-09 13:27:12 +05301307static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301308 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301309 u32 reg, u32 value)
1310{
1311 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001312 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301313
Sujithd535a422009-02-09 13:27:06 +05301314 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301315 case AR9280_DEVID_PCI:
1316 if (reg == 0x7894) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001317 ath_print(common, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301318 "ini VAL: %x EEPROM: %x\n", value,
1319 (pBase->version & 0xff));
1320
1321 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001322 ath_print(common, ATH_DBG_EEPROM,
1323 "PWDCLKIND: %d\n",
1324 pBase->pwdclkind);
Sujithf1dc5602008-10-29 10:16:30 +05301325 value &= ~AR_AN_TOP2_PWDCLKIND;
1326 value |= AR_AN_TOP2_PWDCLKIND &
1327 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1328 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001329 ath_print(common, ATH_DBG_EEPROM,
1330 "PWDCLKIND Earlier Rev\n");
Sujithf1dc5602008-10-29 10:16:30 +05301331 }
1332
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001333 ath_print(common, ATH_DBG_EEPROM,
1334 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001335 }
Sujithf1dc5602008-10-29 10:16:30 +05301336 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001337 }
1338
Sujithf1dc5602008-10-29 10:16:30 +05301339 return value;
1340}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001341
Sujithcbe61d82009-02-09 13:27:12 +05301342static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301343 struct ar5416_eeprom_def *pEepData,
1344 u32 reg, u32 value)
1345{
Sujith2660b812009-02-09 13:27:26 +05301346 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301347 return value;
1348 else
1349 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1350}
1351
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301352static void ath9k_olc_init(struct ath_hw *ah)
1353{
1354 u32 i;
1355
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301356 if (OLC_FOR_AR9287_10_LATER) {
1357 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1358 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1359 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1360 AR9287_AN_TXPC0_TXPCMODE,
1361 AR9287_AN_TXPC0_TXPCMODE_S,
1362 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1363 udelay(100);
1364 } else {
1365 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1366 ah->originalGain[i] =
1367 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1368 AR_PHY_TX_GAIN);
1369 ah->PDADCdelta = 0;
1370 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301371}
1372
Bob Copeland3a702e42009-03-30 22:30:29 -04001373static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1374 struct ath9k_channel *chan)
1375{
1376 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1377
1378 if (IS_CHAN_B(chan))
1379 ctl |= CTL_11B;
1380 else if (IS_CHAN_G(chan))
1381 ctl |= CTL_11G;
1382 else
1383 ctl |= CTL_11A;
1384
1385 return ctl;
1386}
1387
Sujithcbe61d82009-02-09 13:27:12 +05301388static int ath9k_hw_process_ini(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001389 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301390{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001391 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301392 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001393 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301394 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001395
Sujithf1dc5602008-10-29 10:16:30 +05301396 switch (chan->chanmode) {
1397 case CHANNEL_A:
1398 case CHANNEL_A_HT20:
1399 modesIndex = 1;
1400 freqIndex = 1;
1401 break;
1402 case CHANNEL_A_HT40PLUS:
1403 case CHANNEL_A_HT40MINUS:
1404 modesIndex = 2;
1405 freqIndex = 1;
1406 break;
1407 case CHANNEL_G:
1408 case CHANNEL_G_HT20:
1409 case CHANNEL_B:
1410 modesIndex = 4;
1411 freqIndex = 2;
1412 break;
1413 case CHANNEL_G_HT40PLUS:
1414 case CHANNEL_G_HT40MINUS:
1415 modesIndex = 3;
1416 freqIndex = 2;
1417 break;
1418
1419 default:
1420 return -EINVAL;
1421 }
1422
1423 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301424 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301425 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301426
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001427 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301428 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301429 } else {
1430 struct ar5416IniArray temp;
1431 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301432 sizeof(u32) * ah->iniAddac.ia_rows *
1433 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301434
Sujith2660b812009-02-09 13:27:26 +05301435 memcpy(ah->addac5416_21,
1436 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301437
Sujith2660b812009-02-09 13:27:26 +05301438 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301439
Sujith2660b812009-02-09 13:27:26 +05301440 temp.ia_array = ah->addac5416_21;
1441 temp.ia_columns = ah->iniAddac.ia_columns;
1442 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301443 REG_WRITE_ARRAY(&temp, 1, regWrites);
1444 }
1445
1446 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1447
Sujith2660b812009-02-09 13:27:26 +05301448 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1449 u32 reg = INI_RA(&ah->iniModes, i, 0);
1450 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301451
Sujithf1dc5602008-10-29 10:16:30 +05301452 REG_WRITE(ah, reg, val);
1453
1454 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301455 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301456 udelay(100);
1457 }
1458
1459 DO_DELAY(regWrites);
1460 }
1461
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301462 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301463 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301464
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301465 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1466 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301467 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301468
Sujith2660b812009-02-09 13:27:26 +05301469 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1470 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1471 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301472
1473 REG_WRITE(ah, reg, val);
1474
1475 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301476 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301477 udelay(100);
1478 }
1479
1480 DO_DELAY(regWrites);
1481 }
1482
1483 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1484
1485 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301486 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301487 regWrites);
1488 }
1489
1490 ath9k_hw_override_ini(ah, chan);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001491 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301492 ath9k_hw_init_chain_masks(ah);
1493
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301494 if (OLC_FOR_AR9280_20_LATER)
1495 ath9k_olc_init(ah);
1496
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001497 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001498 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001499 channel->max_antenna_gain * 2,
1500 channel->max_power * 2,
1501 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001502 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001503
Sujithf1dc5602008-10-29 10:16:30 +05301504 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001505 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1506 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001507 return -EIO;
1508 }
1509
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001510 return 0;
1511}
1512
Sujithf1dc5602008-10-29 10:16:30 +05301513/****************************************/
1514/* Reset and Channel Switching Routines */
1515/****************************************/
1516
Sujithcbe61d82009-02-09 13:27:12 +05301517static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301518{
1519 u32 rfMode = 0;
1520
1521 if (chan == NULL)
1522 return;
1523
1524 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1525 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1526
1527 if (!AR_SREV_9280_10_OR_LATER(ah))
1528 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1529 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1530
1531 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1532 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1533
1534 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1535}
1536
Sujithcbe61d82009-02-09 13:27:12 +05301537static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301538{
1539 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1540}
1541
Sujithcbe61d82009-02-09 13:27:12 +05301542static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301543{
1544 u32 regval;
1545
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001546 /*
1547 * set AHB_MODE not to do cacheline prefetches
1548 */
Sujithf1dc5602008-10-29 10:16:30 +05301549 regval = REG_READ(ah, AR_AHB_MODE);
1550 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1551
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001552 /*
1553 * let mac dma reads be in 128 byte chunks
1554 */
Sujithf1dc5602008-10-29 10:16:30 +05301555 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1556 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1557
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001558 /*
1559 * Restore TX Trigger Level to its pre-reset value.
1560 * The initial value depends on whether aggregation is enabled, and is
1561 * adjusted whenever underruns are detected.
1562 */
Sujith2660b812009-02-09 13:27:26 +05301563 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301564
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001565 /*
1566 * let mac dma writes be in 128 byte chunks
1567 */
Sujithf1dc5602008-10-29 10:16:30 +05301568 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1569 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1570
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001571 /*
1572 * Setup receive FIFO threshold to hold off TX activities
1573 */
Sujithf1dc5602008-10-29 10:16:30 +05301574 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1575
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001576 /*
1577 * reduce the number of usable entries in PCU TXBUF to avoid
1578 * wrap around issues.
1579 */
Sujithf1dc5602008-10-29 10:16:30 +05301580 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001581 /* For AR9285 the number of Fifos are reduced to half.
1582 * So set the usable tx buf size also to half to
1583 * avoid data/delimiter underruns
1584 */
Sujithf1dc5602008-10-29 10:16:30 +05301585 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1586 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001587 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301588 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1589 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1590 }
1591}
1592
Sujithcbe61d82009-02-09 13:27:12 +05301593static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301594{
1595 u32 val;
1596
1597 val = REG_READ(ah, AR_STA_ID1);
1598 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1599 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001600 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301601 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1602 | AR_STA_ID1_KSRCH_MODE);
1603 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1604 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001605 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001606 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301607 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1608 | AR_STA_ID1_KSRCH_MODE);
1609 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1610 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001611 case NL80211_IFTYPE_STATION:
1612 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301613 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1614 break;
1615 }
1616}
1617
Sujithcbe61d82009-02-09 13:27:12 +05301618static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001619 u32 coef_scaled,
1620 u32 *coef_mantissa,
1621 u32 *coef_exponent)
1622{
1623 u32 coef_exp, coef_man;
1624
1625 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1626 if ((coef_scaled >> coef_exp) & 0x1)
1627 break;
1628
1629 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1630
1631 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1632
1633 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1634 *coef_exponent = coef_exp - 16;
1635}
1636
Sujithcbe61d82009-02-09 13:27:12 +05301637static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301638 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001639{
1640 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1641 u32 clockMhzScaled = 0x64000000;
1642 struct chan_centers centers;
1643
1644 if (IS_CHAN_HALF_RATE(chan))
1645 clockMhzScaled = clockMhzScaled >> 1;
1646 else if (IS_CHAN_QUARTER_RATE(chan))
1647 clockMhzScaled = clockMhzScaled >> 2;
1648
1649 ath9k_hw_get_channel_centers(ah, chan, &centers);
1650 coef_scaled = clockMhzScaled / centers.synth_center;
1651
1652 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1653 &ds_coef_exp);
1654
1655 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1656 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1657 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1658 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1659
1660 coef_scaled = (9 * coef_scaled) / 10;
1661
1662 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1663 &ds_coef_exp);
1664
1665 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1666 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1667 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1668 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1669}
1670
Sujithcbe61d82009-02-09 13:27:12 +05301671static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301672{
1673 u32 rst_flags;
1674 u32 tmpReg;
1675
Sujith70768492009-02-16 13:23:12 +05301676 if (AR_SREV_9100(ah)) {
1677 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1678 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1679 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1680 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1681 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1682 }
1683
Sujithf1dc5602008-10-29 10:16:30 +05301684 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1685 AR_RTC_FORCE_WAKE_ON_INT);
1686
1687 if (AR_SREV_9100(ah)) {
1688 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1689 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1690 } else {
1691 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1692 if (tmpReg &
1693 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1694 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1695 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1696 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1697 } else {
1698 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1699 }
1700
1701 rst_flags = AR_RTC_RC_MAC_WARM;
1702 if (type == ATH9K_RESET_COLD)
1703 rst_flags |= AR_RTC_RC_MAC_COLD;
1704 }
1705
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001706 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301707 udelay(50);
1708
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001709 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301710 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001711 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1712 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301713 return false;
1714 }
1715
1716 if (!AR_SREV_9100(ah))
1717 REG_WRITE(ah, AR_RC, 0);
1718
Sujithf1dc5602008-10-29 10:16:30 +05301719 if (AR_SREV_9100(ah))
1720 udelay(50);
1721
1722 return true;
1723}
1724
Sujithcbe61d82009-02-09 13:27:12 +05301725static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301726{
1727 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1728 AR_RTC_FORCE_WAKE_ON_INT);
1729
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301730 if (!AR_SREV_9100(ah))
1731 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1732
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001733 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301734 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301735
1736 if (!AR_SREV_9100(ah))
1737 REG_WRITE(ah, AR_RC, 0);
1738
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001739 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301740
1741 if (!ath9k_hw_wait(ah,
1742 AR_RTC_STATUS,
1743 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301744 AR_RTC_STATUS_ON,
1745 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001746 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1747 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301748 return false;
1749 }
1750
1751 ath9k_hw_read_revisions(ah);
1752
1753 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1754}
1755
Sujithcbe61d82009-02-09 13:27:12 +05301756static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301757{
1758 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1759 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1760
1761 switch (type) {
1762 case ATH9K_RESET_POWER_ON:
1763 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301764 case ATH9K_RESET_WARM:
1765 case ATH9K_RESET_COLD:
1766 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301767 default:
1768 return false;
1769 }
1770}
1771
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001772static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301773{
1774 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301775 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301776
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301777 if (AR_SREV_9285_10_OR_LATER(ah))
1778 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1779 AR_PHY_FC_ENABLE_DAC_FIFO);
1780
Sujithf1dc5602008-10-29 10:16:30 +05301781 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301782 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301783
1784 if (IS_CHAN_HT40(chan)) {
1785 phymode |= AR_PHY_FC_DYN2040_EN;
1786
1787 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1788 (chan->chanmode == CHANNEL_G_HT40PLUS))
1789 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1790
Sujithf1dc5602008-10-29 10:16:30 +05301791 }
1792 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1793
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001794 ath9k_hw_set11nmac2040(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301795
1796 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1797 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1798}
1799
Sujithcbe61d82009-02-09 13:27:12 +05301800static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301801 struct ath9k_channel *chan)
1802{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301803 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301804 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1805 return false;
1806 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301807 return false;
1808
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001809 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301810 return false;
1811
Sujith2660b812009-02-09 13:27:26 +05301812 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301813 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301814 ath9k_hw_set_rfmode(ah, chan);
1815
1816 return true;
1817}
1818
Sujithcbe61d82009-02-09 13:27:12 +05301819static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001820 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301821{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001822 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001823 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001824 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301825 u32 synthDelay, qnum;
1826
1827 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1828 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001829 ath_print(common, ATH_DBG_QUEUE,
1830 "Transmit frames pending on "
1831 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301832 return false;
1833 }
1834 }
1835
1836 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1837 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301838 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001839 ath_print(common, ATH_DBG_FATAL,
1840 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301841 return false;
1842 }
1843
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001844 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301845
1846 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001847 ath9k_hw_ar9280_set_channel(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301848 } else {
1849 if (!(ath9k_hw_set_channel(ah, chan))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001850 ath_print(common, ATH_DBG_FATAL,
1851 "Failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301852 return false;
1853 }
1854 }
1855
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001856 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001857 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301858 channel->max_antenna_gain * 2,
1859 channel->max_power * 2,
1860 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001861 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301862
1863 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301864 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301865 synthDelay = (4 * synthDelay) / 22;
1866 else
1867 synthDelay /= 10;
1868
1869 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1870
1871 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1872
1873 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1874 ath9k_hw_set_delta_slope(ah, chan);
1875
1876 if (AR_SREV_9280_10_OR_LATER(ah))
1877 ath9k_hw_9280_spur_mitigate(ah, chan);
1878 else
1879 ath9k_hw_spur_mitigate(ah, chan);
1880
1881 if (!chan->oneTimeCalsDone)
1882 chan->oneTimeCalsDone = true;
1883
1884 return true;
1885}
1886
Sujithcbe61d82009-02-09 13:27:12 +05301887static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001888{
1889 int bb_spur = AR_NO_SPUR;
1890 int freq;
1891 int bin, cur_bin;
1892 int bb_spur_off, spur_subchannel_sd;
1893 int spur_freq_sd;
1894 int spur_delta_phase;
1895 int denominator;
1896 int upper, lower, cur_vit_mask;
1897 int tmp, newVal;
1898 int i;
1899 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1900 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1901 };
1902 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1903 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1904 };
1905 int inc[4] = { 0, 100, 0, 0 };
1906 struct chan_centers centers;
1907
1908 int8_t mask_m[123];
1909 int8_t mask_p[123];
1910 int8_t mask_amt;
1911 int tmp_mask;
1912 int cur_bb_spur;
1913 bool is2GHz = IS_CHAN_2GHZ(chan);
1914
1915 memset(&mask_m, 0, sizeof(int8_t) * 123);
1916 memset(&mask_p, 0, sizeof(int8_t) * 123);
1917
1918 ath9k_hw_get_channel_centers(ah, chan, &centers);
1919 freq = centers.synth_center;
1920
Sujith2660b812009-02-09 13:27:26 +05301921 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001922 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301923 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001924
1925 if (is2GHz)
1926 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1927 else
1928 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1929
1930 if (AR_NO_SPUR == cur_bb_spur)
1931 break;
1932 cur_bb_spur = cur_bb_spur - freq;
1933
1934 if (IS_CHAN_HT40(chan)) {
1935 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1936 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1937 bb_spur = cur_bb_spur;
1938 break;
1939 }
1940 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1941 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1942 bb_spur = cur_bb_spur;
1943 break;
1944 }
1945 }
1946
1947 if (AR_NO_SPUR == bb_spur) {
1948 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1949 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1950 return;
1951 } else {
1952 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1953 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1954 }
1955
1956 bin = bb_spur * 320;
1957
1958 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1959
1960 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1961 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1962 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1963 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1964 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1965
1966 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1967 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1968 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1969 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1970 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1971 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1972
1973 if (IS_CHAN_HT40(chan)) {
1974 if (bb_spur < 0) {
1975 spur_subchannel_sd = 1;
1976 bb_spur_off = bb_spur + 10;
1977 } else {
1978 spur_subchannel_sd = 0;
1979 bb_spur_off = bb_spur - 10;
1980 }
1981 } else {
1982 spur_subchannel_sd = 0;
1983 bb_spur_off = bb_spur;
1984 }
1985
1986 if (IS_CHAN_HT40(chan))
1987 spur_delta_phase =
1988 ((bb_spur * 262144) /
1989 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1990 else
1991 spur_delta_phase =
1992 ((bb_spur * 524288) /
1993 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1994
1995 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1996 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1997
1998 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1999 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2000 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2001 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
2002
2003 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
2004 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
2005
2006 cur_bin = -6000;
2007 upper = bin + 100;
2008 lower = bin - 100;
2009
2010 for (i = 0; i < 4; i++) {
2011 int pilot_mask = 0;
2012 int chan_mask = 0;
2013 int bp = 0;
2014 for (bp = 0; bp < 30; bp++) {
2015 if ((cur_bin > lower) && (cur_bin < upper)) {
2016 pilot_mask = pilot_mask | 0x1 << bp;
2017 chan_mask = chan_mask | 0x1 << bp;
2018 }
2019 cur_bin += 100;
2020 }
2021 cur_bin += inc[i];
2022 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2023 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2024 }
2025
2026 cur_vit_mask = 6100;
2027 upper = bin + 120;
2028 lower = bin - 120;
2029
2030 for (i = 0; i < 123; i++) {
2031 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002032
2033 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002034 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002035
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002036 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002037 mask_amt = 1;
2038 else
2039 mask_amt = 0;
2040 if (cur_vit_mask < 0)
2041 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2042 else
2043 mask_p[cur_vit_mask / 100] = mask_amt;
2044 }
2045 cur_vit_mask -= 100;
2046 }
2047
2048 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2049 | (mask_m[48] << 26) | (mask_m[49] << 24)
2050 | (mask_m[50] << 22) | (mask_m[51] << 20)
2051 | (mask_m[52] << 18) | (mask_m[53] << 16)
2052 | (mask_m[54] << 14) | (mask_m[55] << 12)
2053 | (mask_m[56] << 10) | (mask_m[57] << 8)
2054 | (mask_m[58] << 6) | (mask_m[59] << 4)
2055 | (mask_m[60] << 2) | (mask_m[61] << 0);
2056 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2057 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2058
2059 tmp_mask = (mask_m[31] << 28)
2060 | (mask_m[32] << 26) | (mask_m[33] << 24)
2061 | (mask_m[34] << 22) | (mask_m[35] << 20)
2062 | (mask_m[36] << 18) | (mask_m[37] << 16)
2063 | (mask_m[48] << 14) | (mask_m[39] << 12)
2064 | (mask_m[40] << 10) | (mask_m[41] << 8)
2065 | (mask_m[42] << 6) | (mask_m[43] << 4)
2066 | (mask_m[44] << 2) | (mask_m[45] << 0);
2067 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2068 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2069
2070 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2071 | (mask_m[18] << 26) | (mask_m[18] << 24)
2072 | (mask_m[20] << 22) | (mask_m[20] << 20)
2073 | (mask_m[22] << 18) | (mask_m[22] << 16)
2074 | (mask_m[24] << 14) | (mask_m[24] << 12)
2075 | (mask_m[25] << 10) | (mask_m[26] << 8)
2076 | (mask_m[27] << 6) | (mask_m[28] << 4)
2077 | (mask_m[29] << 2) | (mask_m[30] << 0);
2078 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2079 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2080
2081 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2082 | (mask_m[2] << 26) | (mask_m[3] << 24)
2083 | (mask_m[4] << 22) | (mask_m[5] << 20)
2084 | (mask_m[6] << 18) | (mask_m[7] << 16)
2085 | (mask_m[8] << 14) | (mask_m[9] << 12)
2086 | (mask_m[10] << 10) | (mask_m[11] << 8)
2087 | (mask_m[12] << 6) | (mask_m[13] << 4)
2088 | (mask_m[14] << 2) | (mask_m[15] << 0);
2089 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2090 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2091
2092 tmp_mask = (mask_p[15] << 28)
2093 | (mask_p[14] << 26) | (mask_p[13] << 24)
2094 | (mask_p[12] << 22) | (mask_p[11] << 20)
2095 | (mask_p[10] << 18) | (mask_p[9] << 16)
2096 | (mask_p[8] << 14) | (mask_p[7] << 12)
2097 | (mask_p[6] << 10) | (mask_p[5] << 8)
2098 | (mask_p[4] << 6) | (mask_p[3] << 4)
2099 | (mask_p[2] << 2) | (mask_p[1] << 0);
2100 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2101 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2102
2103 tmp_mask = (mask_p[30] << 28)
2104 | (mask_p[29] << 26) | (mask_p[28] << 24)
2105 | (mask_p[27] << 22) | (mask_p[26] << 20)
2106 | (mask_p[25] << 18) | (mask_p[24] << 16)
2107 | (mask_p[23] << 14) | (mask_p[22] << 12)
2108 | (mask_p[21] << 10) | (mask_p[20] << 8)
2109 | (mask_p[19] << 6) | (mask_p[18] << 4)
2110 | (mask_p[17] << 2) | (mask_p[16] << 0);
2111 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2112 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2113
2114 tmp_mask = (mask_p[45] << 28)
2115 | (mask_p[44] << 26) | (mask_p[43] << 24)
2116 | (mask_p[42] << 22) | (mask_p[41] << 20)
2117 | (mask_p[40] << 18) | (mask_p[39] << 16)
2118 | (mask_p[38] << 14) | (mask_p[37] << 12)
2119 | (mask_p[36] << 10) | (mask_p[35] << 8)
2120 | (mask_p[34] << 6) | (mask_p[33] << 4)
2121 | (mask_p[32] << 2) | (mask_p[31] << 0);
2122 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2123 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2124
2125 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2126 | (mask_p[59] << 26) | (mask_p[58] << 24)
2127 | (mask_p[57] << 22) | (mask_p[56] << 20)
2128 | (mask_p[55] << 18) | (mask_p[54] << 16)
2129 | (mask_p[53] << 14) | (mask_p[52] << 12)
2130 | (mask_p[51] << 10) | (mask_p[50] << 8)
2131 | (mask_p[49] << 6) | (mask_p[48] << 4)
2132 | (mask_p[47] << 2) | (mask_p[46] << 0);
2133 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2134 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2135}
2136
Sujithcbe61d82009-02-09 13:27:12 +05302137static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002138{
2139 int bb_spur = AR_NO_SPUR;
2140 int bin, cur_bin;
2141 int spur_freq_sd;
2142 int spur_delta_phase;
2143 int denominator;
2144 int upper, lower, cur_vit_mask;
2145 int tmp, new;
2146 int i;
2147 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2148 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2149 };
2150 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2151 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2152 };
2153 int inc[4] = { 0, 100, 0, 0 };
2154
2155 int8_t mask_m[123];
2156 int8_t mask_p[123];
2157 int8_t mask_amt;
2158 int tmp_mask;
2159 int cur_bb_spur;
2160 bool is2GHz = IS_CHAN_2GHZ(chan);
2161
2162 memset(&mask_m, 0, sizeof(int8_t) * 123);
2163 memset(&mask_p, 0, sizeof(int8_t) * 123);
2164
2165 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05302166 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002167 if (AR_NO_SPUR == cur_bb_spur)
2168 break;
2169 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2170 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2171 bb_spur = cur_bb_spur;
2172 break;
2173 }
2174 }
2175
2176 if (AR_NO_SPUR == bb_spur)
2177 return;
2178
2179 bin = bb_spur * 32;
2180
2181 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2182 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2183 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2184 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2185 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2186
2187 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2188
2189 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2190 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2191 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2192 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2193 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2194 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2195
2196 spur_delta_phase = ((bb_spur * 524288) / 100) &
2197 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2198
2199 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2200 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2201
2202 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2203 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2204 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2205 REG_WRITE(ah, AR_PHY_TIMING11, new);
2206
2207 cur_bin = -6000;
2208 upper = bin + 100;
2209 lower = bin - 100;
2210
2211 for (i = 0; i < 4; i++) {
2212 int pilot_mask = 0;
2213 int chan_mask = 0;
2214 int bp = 0;
2215 for (bp = 0; bp < 30; bp++) {
2216 if ((cur_bin > lower) && (cur_bin < upper)) {
2217 pilot_mask = pilot_mask | 0x1 << bp;
2218 chan_mask = chan_mask | 0x1 << bp;
2219 }
2220 cur_bin += 100;
2221 }
2222 cur_bin += inc[i];
2223 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2224 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2225 }
2226
2227 cur_vit_mask = 6100;
2228 upper = bin + 120;
2229 lower = bin - 120;
2230
2231 for (i = 0; i < 123; i++) {
2232 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002233
2234 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002235 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002236
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002237 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002238 mask_amt = 1;
2239 else
2240 mask_amt = 0;
2241 if (cur_vit_mask < 0)
2242 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2243 else
2244 mask_p[cur_vit_mask / 100] = mask_amt;
2245 }
2246 cur_vit_mask -= 100;
2247 }
2248
2249 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2250 | (mask_m[48] << 26) | (mask_m[49] << 24)
2251 | (mask_m[50] << 22) | (mask_m[51] << 20)
2252 | (mask_m[52] << 18) | (mask_m[53] << 16)
2253 | (mask_m[54] << 14) | (mask_m[55] << 12)
2254 | (mask_m[56] << 10) | (mask_m[57] << 8)
2255 | (mask_m[58] << 6) | (mask_m[59] << 4)
2256 | (mask_m[60] << 2) | (mask_m[61] << 0);
2257 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2258 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2259
2260 tmp_mask = (mask_m[31] << 28)
2261 | (mask_m[32] << 26) | (mask_m[33] << 24)
2262 | (mask_m[34] << 22) | (mask_m[35] << 20)
2263 | (mask_m[36] << 18) | (mask_m[37] << 16)
2264 | (mask_m[48] << 14) | (mask_m[39] << 12)
2265 | (mask_m[40] << 10) | (mask_m[41] << 8)
2266 | (mask_m[42] << 6) | (mask_m[43] << 4)
2267 | (mask_m[44] << 2) | (mask_m[45] << 0);
2268 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2269 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2270
2271 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2272 | (mask_m[18] << 26) | (mask_m[18] << 24)
2273 | (mask_m[20] << 22) | (mask_m[20] << 20)
2274 | (mask_m[22] << 18) | (mask_m[22] << 16)
2275 | (mask_m[24] << 14) | (mask_m[24] << 12)
2276 | (mask_m[25] << 10) | (mask_m[26] << 8)
2277 | (mask_m[27] << 6) | (mask_m[28] << 4)
2278 | (mask_m[29] << 2) | (mask_m[30] << 0);
2279 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2280 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2281
2282 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2283 | (mask_m[2] << 26) | (mask_m[3] << 24)
2284 | (mask_m[4] << 22) | (mask_m[5] << 20)
2285 | (mask_m[6] << 18) | (mask_m[7] << 16)
2286 | (mask_m[8] << 14) | (mask_m[9] << 12)
2287 | (mask_m[10] << 10) | (mask_m[11] << 8)
2288 | (mask_m[12] << 6) | (mask_m[13] << 4)
2289 | (mask_m[14] << 2) | (mask_m[15] << 0);
2290 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2291 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2292
2293 tmp_mask = (mask_p[15] << 28)
2294 | (mask_p[14] << 26) | (mask_p[13] << 24)
2295 | (mask_p[12] << 22) | (mask_p[11] << 20)
2296 | (mask_p[10] << 18) | (mask_p[9] << 16)
2297 | (mask_p[8] << 14) | (mask_p[7] << 12)
2298 | (mask_p[6] << 10) | (mask_p[5] << 8)
2299 | (mask_p[4] << 6) | (mask_p[3] << 4)
2300 | (mask_p[2] << 2) | (mask_p[1] << 0);
2301 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2302 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2303
2304 tmp_mask = (mask_p[30] << 28)
2305 | (mask_p[29] << 26) | (mask_p[28] << 24)
2306 | (mask_p[27] << 22) | (mask_p[26] << 20)
2307 | (mask_p[25] << 18) | (mask_p[24] << 16)
2308 | (mask_p[23] << 14) | (mask_p[22] << 12)
2309 | (mask_p[21] << 10) | (mask_p[20] << 8)
2310 | (mask_p[19] << 6) | (mask_p[18] << 4)
2311 | (mask_p[17] << 2) | (mask_p[16] << 0);
2312 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2313 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2314
2315 tmp_mask = (mask_p[45] << 28)
2316 | (mask_p[44] << 26) | (mask_p[43] << 24)
2317 | (mask_p[42] << 22) | (mask_p[41] << 20)
2318 | (mask_p[40] << 18) | (mask_p[39] << 16)
2319 | (mask_p[38] << 14) | (mask_p[37] << 12)
2320 | (mask_p[36] << 10) | (mask_p[35] << 8)
2321 | (mask_p[34] << 6) | (mask_p[33] << 4)
2322 | (mask_p[32] << 2) | (mask_p[31] << 0);
2323 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2324 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2325
2326 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2327 | (mask_p[59] << 26) | (mask_p[58] << 24)
2328 | (mask_p[57] << 22) | (mask_p[56] << 20)
2329 | (mask_p[55] << 18) | (mask_p[54] << 16)
2330 | (mask_p[53] << 14) | (mask_p[52] << 12)
2331 | (mask_p[51] << 10) | (mask_p[50] << 8)
2332 | (mask_p[49] << 6) | (mask_p[48] << 4)
2333 | (mask_p[47] << 2) | (mask_p[46] << 0);
2334 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2335 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2336}
2337
Johannes Berg3b319aa2009-06-13 14:50:26 +05302338static void ath9k_enable_rfkill(struct ath_hw *ah)
2339{
2340 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2341 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
2342
2343 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
2344 AR_GPIO_INPUT_MUX2_RFSILENT);
2345
2346 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
2347 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
2348}
2349
Sujithcbe61d82009-02-09 13:27:12 +05302350int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002351 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002352{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002353 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002354 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05302355 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002356 u32 saveDefAntenna;
2357 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05302358 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002359 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002360
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07002361 ah->txchainmask = common->tx_chainmask;
2362 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002363
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002364 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002365 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002366
Vasanthakumar Thiagarajan9ebef7992009-09-17 09:26:44 +05302367 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002368 ath9k_hw_getnf(ah, curchan);
2369
2370 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302371 (ah->chip_fullsleep != true) &&
2372 (ah->curchan != NULL) &&
2373 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002374 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302375 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05302376 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
2377 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002378
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002379 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05302380 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002381 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002382 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002383 }
2384 }
2385
2386 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2387 if (saveDefAntenna == 0)
2388 saveDefAntenna = 1;
2389
2390 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2391
Sujith46fe7822009-09-17 09:25:25 +05302392 /* For chips on which RTC reset is done, save TSF before it gets cleared */
2393 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2394 tsf = ath9k_hw_gettsf64(ah);
2395
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002396 saveLedState = REG_READ(ah, AR_CFG_LED) &
2397 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2398 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2399
2400 ath9k_hw_mark_phy_inactive(ah);
2401
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002402 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2403 REG_WRITE(ah,
2404 AR9271_RESET_POWER_DOWN_CONTROL,
2405 AR9271_RADIO_RF_RST);
2406 udelay(50);
2407 }
2408
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002409 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002410 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002411 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002412 }
2413
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002414 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2415 ah->htc_reset_init = false;
2416 REG_WRITE(ah,
2417 AR9271_RESET_POWER_DOWN_CONTROL,
2418 AR9271_GATE_MAC_CTL);
2419 udelay(50);
2420 }
2421
Sujith46fe7822009-09-17 09:25:25 +05302422 /* Restore TSF */
2423 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2424 ath9k_hw_settsf64(ah, tsf);
2425
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302426 if (AR_SREV_9280_10_OR_LATER(ah))
2427 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002428
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302429 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302430 /* Enable ASYNC FIFO */
2431 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2432 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2433 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2434 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2435 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2436 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2437 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2438 }
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002439 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002440 if (r)
2441 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002442
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002443 /* Setup MFP options for CCMP */
2444 if (AR_SREV_9280_20_OR_LATER(ah)) {
2445 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2446 * frames when constructing CCMP AAD. */
2447 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2448 0xc7ff);
2449 ah->sw_mgmt_crypto = false;
2450 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2451 /* Disable hardware crypto for management frames */
2452 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2453 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2454 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2455 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2456 ah->sw_mgmt_crypto = true;
2457 } else
2458 ah->sw_mgmt_crypto = true;
2459
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002460 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2461 ath9k_hw_set_delta_slope(ah, chan);
2462
2463 if (AR_SREV_9280_10_OR_LATER(ah))
2464 ath9k_hw_9280_spur_mitigate(ah, chan);
2465 else
2466 ath9k_hw_spur_mitigate(ah, chan);
2467
Sujithd6509152009-03-13 08:56:05 +05302468 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002469
2470 ath9k_hw_decrease_chain_power(ah, chan);
2471
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002472 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2473 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002474 | macStaId1
2475 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302476 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302477 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302478 | ah->sta_id1_defaults);
2479 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002480
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002481 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002482
2483 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2484
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002485 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002486
2487 REG_WRITE(ah, AR_ISR, ~0);
2488
2489 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2490
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002491 if (AR_SREV_9280_10_OR_LATER(ah))
2492 ath9k_hw_ar9280_set_channel(ah, chan);
2493 else
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002494 if (!(ath9k_hw_set_channel(ah, chan)))
2495 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002496
2497 for (i = 0; i < AR_NUM_DCU; i++)
2498 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2499
Sujith2660b812009-02-09 13:27:26 +05302500 ah->intr_txqs = 0;
2501 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002502 ath9k_hw_resettxqueue(ah, i);
2503
Sujith2660b812009-02-09 13:27:26 +05302504 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002505 ath9k_hw_init_qos(ah);
2506
Sujith2660b812009-02-09 13:27:26 +05302507 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302508 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302509
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002510 ath9k_hw_init_user_settings(ah);
2511
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302512 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302513 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2514 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2515 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2516 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2517 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2518 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2519
2520 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2521 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2522
2523 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2524 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2525 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2526 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2527 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302528 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302529 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2530 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2531 }
2532
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002533 REG_WRITE(ah, AR_STA_ID1,
2534 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2535
2536 ath9k_hw_set_dma(ah);
2537
2538 REG_WRITE(ah, AR_OBS, 8);
2539
Sujith0ef1f162009-03-30 15:28:35 +05302540 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002541 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2542 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2543 }
2544
2545 ath9k_hw_init_bb(ah, chan);
2546
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002547 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002548 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002549
Sujith2660b812009-02-09 13:27:26 +05302550 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002551 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2552 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2553 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2554 }
2555
2556 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2557
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002558 /*
2559 * For big endian systems turn on swapping for descriptors
2560 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002561 if (AR_SREV_9100(ah)) {
2562 u32 mask;
2563 mask = REG_READ(ah, AR_CFG);
2564 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002565 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302566 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002567 } else {
2568 mask =
2569 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2570 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002571 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302572 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002573 }
2574 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002575 /* Configure AR9271 target WLAN */
2576 if (AR_SREV_9271(ah))
2577 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002578#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002579 else
2580 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002581#endif
2582 }
2583
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002584 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302585 ath9k_hw_btcoex_enable(ah);
2586
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002587 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002588}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002589EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002590
Sujithf1dc5602008-10-29 10:16:30 +05302591/************************/
2592/* Key Cache Management */
2593/************************/
2594
Sujithcbe61d82009-02-09 13:27:12 +05302595bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002596{
Sujithf1dc5602008-10-29 10:16:30 +05302597 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002598
Sujith2660b812009-02-09 13:27:26 +05302599 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002600 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2601 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002602 return false;
2603 }
2604
Sujithf1dc5602008-10-29 10:16:30 +05302605 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002606
Sujithf1dc5602008-10-29 10:16:30 +05302607 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2608 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2609 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2610 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2611 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2612 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2613 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2614 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2615
2616 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2617 u16 micentry = entry + 64;
2618
2619 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2620 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2621 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2622 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2623
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002624 }
2625
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002626 return true;
2627}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002628EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002629
Sujithcbe61d82009-02-09 13:27:12 +05302630bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002631{
Sujithf1dc5602008-10-29 10:16:30 +05302632 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002633
Sujith2660b812009-02-09 13:27:26 +05302634 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002635 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2636 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002637 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002638 }
2639
Sujithf1dc5602008-10-29 10:16:30 +05302640 if (mac != NULL) {
2641 macHi = (mac[5] << 8) | mac[4];
2642 macLo = (mac[3] << 24) |
2643 (mac[2] << 16) |
2644 (mac[1] << 8) |
2645 mac[0];
2646 macLo >>= 1;
2647 macLo |= (macHi & 1) << 31;
2648 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002649 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302650 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002651 }
Sujithf1dc5602008-10-29 10:16:30 +05302652 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2653 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002654
2655 return true;
2656}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002657EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002658
Sujithcbe61d82009-02-09 13:27:12 +05302659bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302660 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002661 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002662{
Sujith2660b812009-02-09 13:27:26 +05302663 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002664 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302665 u32 key0, key1, key2, key3, key4;
2666 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002667
Sujithf1dc5602008-10-29 10:16:30 +05302668 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002669 ath_print(common, ATH_DBG_FATAL,
2670 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302671 return false;
2672 }
2673
2674 switch (k->kv_type) {
2675 case ATH9K_CIPHER_AES_OCB:
2676 keyType = AR_KEYTABLE_TYPE_AES;
2677 break;
2678 case ATH9K_CIPHER_AES_CCM:
2679 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002680 ath_print(common, ATH_DBG_ANY,
2681 "AES-CCM not supported by mac rev 0x%x\n",
2682 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002683 return false;
2684 }
Sujithf1dc5602008-10-29 10:16:30 +05302685 keyType = AR_KEYTABLE_TYPE_CCM;
2686 break;
2687 case ATH9K_CIPHER_TKIP:
2688 keyType = AR_KEYTABLE_TYPE_TKIP;
2689 if (ATH9K_IS_MIC_ENABLED(ah)
2690 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002691 ath_print(common, ATH_DBG_ANY,
2692 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002693 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002694 }
Sujithf1dc5602008-10-29 10:16:30 +05302695 break;
2696 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002697 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002698 ath_print(common, ATH_DBG_ANY,
2699 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302700 return false;
2701 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002702 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302703 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002704 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302705 keyType = AR_KEYTABLE_TYPE_104;
2706 else
2707 keyType = AR_KEYTABLE_TYPE_128;
2708 break;
2709 case ATH9K_CIPHER_CLR:
2710 keyType = AR_KEYTABLE_TYPE_CLR;
2711 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002712 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002713 ath_print(common, ATH_DBG_FATAL,
2714 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002715 return false;
2716 }
Sujithf1dc5602008-10-29 10:16:30 +05302717
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002718 key0 = get_unaligned_le32(k->kv_val + 0);
2719 key1 = get_unaligned_le16(k->kv_val + 4);
2720 key2 = get_unaligned_le32(k->kv_val + 6);
2721 key3 = get_unaligned_le16(k->kv_val + 10);
2722 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002723 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302724 key4 &= 0xff;
2725
Jouni Malinen672903b2009-03-02 15:06:31 +02002726 /*
2727 * Note: Key cache registers access special memory area that requires
2728 * two 32-bit writes to actually update the values in the internal
2729 * memory. Consequently, the exact order and pairs used here must be
2730 * maintained.
2731 */
2732
Sujithf1dc5602008-10-29 10:16:30 +05302733 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2734 u16 micentry = entry + 64;
2735
Jouni Malinen672903b2009-03-02 15:06:31 +02002736 /*
2737 * Write inverted key[47:0] first to avoid Michael MIC errors
2738 * on frames that could be sent or received at the same time.
2739 * The correct key will be written in the end once everything
2740 * else is ready.
2741 */
Sujithf1dc5602008-10-29 10:16:30 +05302742 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2743 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002744
2745 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302746 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2747 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002748
2749 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302750 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2751 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002752
2753 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302754 (void) ath9k_hw_keysetmac(ah, entry, mac);
2755
Sujith2660b812009-02-09 13:27:26 +05302756 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002757 /*
2758 * TKIP uses two key cache entries:
2759 * Michael MIC TX/RX keys in the same key cache entry
2760 * (idx = main index + 64):
2761 * key0 [31:0] = RX key [31:0]
2762 * key1 [15:0] = TX key [31:16]
2763 * key1 [31:16] = reserved
2764 * key2 [31:0] = RX key [63:32]
2765 * key3 [15:0] = TX key [15:0]
2766 * key3 [31:16] = reserved
2767 * key4 [31:0] = TX key [63:32]
2768 */
Sujithf1dc5602008-10-29 10:16:30 +05302769 u32 mic0, mic1, mic2, mic3, mic4;
2770
2771 mic0 = get_unaligned_le32(k->kv_mic + 0);
2772 mic2 = get_unaligned_le32(k->kv_mic + 4);
2773 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2774 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2775 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002776
2777 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302778 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2779 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002780
2781 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302782 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2783 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002784
2785 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302786 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2787 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2788 AR_KEYTABLE_TYPE_CLR);
2789
2790 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002791 /*
2792 * TKIP uses four key cache entries (two for group
2793 * keys):
2794 * Michael MIC TX/RX keys are in different key cache
2795 * entries (idx = main index + 64 for TX and
2796 * main index + 32 + 96 for RX):
2797 * key0 [31:0] = TX/RX MIC key [31:0]
2798 * key1 [31:0] = reserved
2799 * key2 [31:0] = TX/RX MIC key [63:32]
2800 * key3 [31:0] = reserved
2801 * key4 [31:0] = reserved
2802 *
2803 * Upper layer code will call this function separately
2804 * for TX and RX keys when these registers offsets are
2805 * used.
2806 */
Sujithf1dc5602008-10-29 10:16:30 +05302807 u32 mic0, mic2;
2808
2809 mic0 = get_unaligned_le32(k->kv_mic + 0);
2810 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002811
2812 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302813 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2814 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002815
2816 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302817 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2818 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002819
2820 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302821 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2822 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2823 AR_KEYTABLE_TYPE_CLR);
2824 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002825
2826 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302827 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2828 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002829
2830 /*
2831 * Write the correct (un-inverted) key[47:0] last to enable
2832 * TKIP now that all other registers are set with correct
2833 * values.
2834 */
Sujithf1dc5602008-10-29 10:16:30 +05302835 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2836 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2837 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002838 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302839 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2840 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002841
2842 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302843 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2844 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002845
2846 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302847 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2848 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2849
Jouni Malinen672903b2009-03-02 15:06:31 +02002850 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302851 (void) ath9k_hw_keysetmac(ah, entry, mac);
2852 }
2853
Sujithf1dc5602008-10-29 10:16:30 +05302854 return true;
2855}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002856EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302857
Sujithcbe61d82009-02-09 13:27:12 +05302858bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302859{
Sujith2660b812009-02-09 13:27:26 +05302860 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302861 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2862 if (val & AR_KEYTABLE_VALID)
2863 return true;
2864 }
2865 return false;
2866}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002867EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302868
2869/******************************/
2870/* Power Management (Chipset) */
2871/******************************/
2872
Sujithcbe61d82009-02-09 13:27:12 +05302873static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302874{
2875 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2876 if (setChip) {
2877 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2878 AR_RTC_FORCE_WAKE_EN);
2879 if (!AR_SREV_9100(ah))
2880 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2881
Sujith4921be82009-09-18 15:04:27 +05302882 if(!AR_SREV_5416(ah))
2883 REG_CLR_BIT(ah, (AR_RTC_RESET),
2884 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302885 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002886}
2887
Sujithcbe61d82009-02-09 13:27:12 +05302888static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002889{
Sujithf1dc5602008-10-29 10:16:30 +05302890 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2891 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302892 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002893
Sujithf1dc5602008-10-29 10:16:30 +05302894 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2895 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2896 AR_RTC_FORCE_WAKE_ON_INT);
2897 } else {
2898 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2899 AR_RTC_FORCE_WAKE_EN);
2900 }
2901 }
2902}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002903
Sujithcbe61d82009-02-09 13:27:12 +05302904static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302905{
2906 u32 val;
2907 int i;
2908
2909 if (setChip) {
2910 if ((REG_READ(ah, AR_RTC_STATUS) &
2911 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2912 if (ath9k_hw_set_reset_reg(ah,
2913 ATH9K_RESET_POWER_ON) != true) {
2914 return false;
2915 }
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302916 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302917 }
2918 if (AR_SREV_9100(ah))
2919 REG_SET_BIT(ah, AR_RTC_RESET,
2920 AR_RTC_RESET_EN);
2921
2922 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2923 AR_RTC_FORCE_WAKE_EN);
2924 udelay(50);
2925
2926 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2927 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2928 if (val == AR_RTC_STATUS_ON)
2929 break;
2930 udelay(50);
2931 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2932 AR_RTC_FORCE_WAKE_EN);
2933 }
2934 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002935 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2936 "Failed to wakeup in %uus\n",
2937 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302938 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002939 }
2940 }
2941
Sujithf1dc5602008-10-29 10:16:30 +05302942 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2943
2944 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002945}
2946
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002947bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302948{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002949 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302950 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302951 static const char *modes[] = {
2952 "AWAKE",
2953 "FULL-SLEEP",
2954 "NETWORK SLEEP",
2955 "UNDEFINED"
2956 };
Sujithf1dc5602008-10-29 10:16:30 +05302957
Gabor Juhoscbdec972009-07-24 17:27:22 +02002958 if (ah->power_mode == mode)
2959 return status;
2960
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002961 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2962 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302963
2964 switch (mode) {
2965 case ATH9K_PM_AWAKE:
2966 status = ath9k_hw_set_power_awake(ah, setChip);
2967 break;
2968 case ATH9K_PM_FULL_SLEEP:
2969 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302970 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302971 break;
2972 case ATH9K_PM_NETWORK_SLEEP:
2973 ath9k_set_power_network_sleep(ah, setChip);
2974 break;
2975 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002976 ath_print(common, ATH_DBG_FATAL,
2977 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302978 return false;
2979 }
Sujith2660b812009-02-09 13:27:26 +05302980 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302981
2982 return status;
2983}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002984EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302985
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002986/*
2987 * Helper for ASPM support.
2988 *
2989 * Disable PLL when in L0s as well as receiver clock when in L1.
2990 * This power saving option must be enabled through the SerDes.
2991 *
2992 * Programming the SerDes must go through the same 288 bit serial shift
2993 * register as the other analog registers. Hence the 9 writes.
2994 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302995void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302996{
Sujithf1dc5602008-10-29 10:16:30 +05302997 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302998 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302999
Sujith2660b812009-02-09 13:27:26 +05303000 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05303001 return;
3002
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003003 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05303004 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05303005 return;
3006
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003007 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303008 if (!restore) {
3009 if (AR_SREV_9280_20_OR_LATER(ah)) {
3010 /*
3011 * AR9280 2.0 or later chips use SerDes values from the
3012 * initvals.h initialized depending on chipset during
3013 * ath9k_hw_init()
3014 */
3015 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
3016 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
3017 INI_RA(&ah->iniPcieSerdes, i, 1));
3018 }
3019 } else if (AR_SREV_9280(ah) &&
3020 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
3021 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
3022 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05303023
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303024 /* RX shut off when elecidle is asserted */
3025 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
3026 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
3027 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
3028
3029 /* Shut off CLKREQ active in L1 */
3030 if (ah->config.pcie_clock_req)
3031 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
3032 else
3033 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
3034
3035 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3036 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3037 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
3038
3039 /* Load the new settings */
3040 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
3041
3042 } else {
3043 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
3044 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
3045
3046 /* RX shut off when elecidle is asserted */
3047 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
3048 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
3049 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
3050
3051 /*
3052 * Ignore ah->ah_config.pcie_clock_req setting for
3053 * pre-AR9280 11n
3054 */
3055 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
3056
3057 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3058 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3059 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
3060
3061 /* Load the new settings */
3062 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05303063 }
Sujithf1dc5602008-10-29 10:16:30 +05303064
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303065 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05303066
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303067 /* set bit 19 to allow forcing of pcie core into L1 state */
3068 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05303069
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303070 /* Several PCIe massages to ensure proper behaviour */
3071 if (ah->config.pcie_waen) {
3072 val = ah->config.pcie_waen;
3073 if (!power_off)
3074 val &= (~AR_WA_D3_L1_DISABLE);
3075 } else {
3076 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3077 AR_SREV_9287(ah)) {
3078 val = AR9285_WA_DEFAULT;
3079 if (!power_off)
3080 val &= (~AR_WA_D3_L1_DISABLE);
3081 } else if (AR_SREV_9280(ah)) {
3082 /*
3083 * On AR9280 chips bit 22 of 0x4004 needs to be
3084 * set otherwise card may disappear.
3085 */
3086 val = AR9280_WA_DEFAULT;
3087 if (!power_off)
3088 val &= (~AR_WA_D3_L1_DISABLE);
3089 } else
3090 val = AR_WA_DEFAULT;
3091 }
Sujithf1dc5602008-10-29 10:16:30 +05303092
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303093 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05303094 }
3095
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303096 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003097 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303098 * Set PCIe workaround bits
3099 * bit 14 in WA register (disable L1) should only
3100 * be set when device enters D3 and be cleared
3101 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003102 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303103 if (ah->config.pcie_waen) {
3104 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
3105 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3106 } else {
3107 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3108 AR_SREV_9287(ah)) &&
3109 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
3110 (AR_SREV_9280(ah) &&
3111 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
3112 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3113 }
3114 }
Sujithf1dc5602008-10-29 10:16:30 +05303115 }
3116}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003117EXPORT_SYMBOL(ath9k_hw_configpcipowersave);
Sujithf1dc5602008-10-29 10:16:30 +05303118
3119/**********************/
3120/* Interrupt Handling */
3121/**********************/
3122
Sujithcbe61d82009-02-09 13:27:12 +05303123bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003124{
3125 u32 host_isr;
3126
3127 if (AR_SREV_9100(ah))
3128 return true;
3129
3130 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
3131 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
3132 return true;
3133
3134 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
3135 if ((host_isr & AR_INTR_SYNC_DEFAULT)
3136 && (host_isr != AR_INTR_SPURIOUS))
3137 return true;
3138
3139 return false;
3140}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003141EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003142
Sujithcbe61d82009-02-09 13:27:12 +05303143bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003144{
3145 u32 isr = 0;
3146 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05303147 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003148 u32 sync_cause = 0;
3149 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003150 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003151
3152 if (!AR_SREV_9100(ah)) {
3153 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
3154 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
3155 == AR_RTC_STATUS_ON) {
3156 isr = REG_READ(ah, AR_ISR);
3157 }
3158 }
3159
Sujithf1dc5602008-10-29 10:16:30 +05303160 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
3161 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003162
3163 *masked = 0;
3164
3165 if (!isr && !sync_cause)
3166 return false;
3167 } else {
3168 *masked = 0;
3169 isr = REG_READ(ah, AR_ISR);
3170 }
3171
3172 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003173 if (isr & AR_ISR_BCNMISC) {
3174 u32 isr2;
3175 isr2 = REG_READ(ah, AR_ISR_S2);
3176 if (isr2 & AR_ISR_S2_TIM)
3177 mask2 |= ATH9K_INT_TIM;
3178 if (isr2 & AR_ISR_S2_DTIM)
3179 mask2 |= ATH9K_INT_DTIM;
3180 if (isr2 & AR_ISR_S2_DTIMSYNC)
3181 mask2 |= ATH9K_INT_DTIMSYNC;
3182 if (isr2 & (AR_ISR_S2_CABEND))
3183 mask2 |= ATH9K_INT_CABEND;
3184 if (isr2 & AR_ISR_S2_GTT)
3185 mask2 |= ATH9K_INT_GTT;
3186 if (isr2 & AR_ISR_S2_CST)
3187 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05303188 if (isr2 & AR_ISR_S2_TSFOOR)
3189 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003190 }
3191
3192 isr = REG_READ(ah, AR_ISR_RAC);
3193 if (isr == 0xffffffff) {
3194 *masked = 0;
3195 return false;
3196 }
3197
3198 *masked = isr & ATH9K_INT_COMMON;
3199
Sujith0ef1f162009-03-30 15:28:35 +05303200 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003201 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
3202 *masked |= ATH9K_INT_RX;
3203 }
3204
3205 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
3206 *masked |= ATH9K_INT_RX;
3207 if (isr &
3208 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
3209 AR_ISR_TXEOL)) {
3210 u32 s0_s, s1_s;
3211
3212 *masked |= ATH9K_INT_TX;
3213
3214 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05303215 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
3216 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003217
3218 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05303219 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
3220 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003221 }
3222
3223 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003224 ath_print(common, ATH_DBG_INTERRUPT,
3225 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003226 }
3227
3228 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05303229 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003230 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
3231 if (isr5 & AR_ISR_S5_TIM_TIMER)
3232 *masked |= ATH9K_INT_TIM_TIMER;
3233 }
3234 }
3235
3236 *masked |= mask2;
3237 }
Sujithf1dc5602008-10-29 10:16:30 +05303238
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003239 if (AR_SREV_9100(ah))
3240 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303241
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303242 if (isr & AR_ISR_GENTMR) {
3243 u32 s5_s;
3244
3245 s5_s = REG_READ(ah, AR_ISR_S5_S);
3246 if (isr & AR_ISR_GENTMR) {
3247 ah->intr_gen_timer_trigger =
3248 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
3249
3250 ah->intr_gen_timer_thresh =
3251 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
3252
3253 if (ah->intr_gen_timer_trigger)
3254 *masked |= ATH9K_INT_GENTIMER;
3255
3256 }
3257 }
3258
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003259 if (sync_cause) {
3260 fatal_int =
3261 (sync_cause &
3262 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
3263 ? true : false;
3264
3265 if (fatal_int) {
3266 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003267 ath_print(common, ATH_DBG_ANY,
3268 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003269 }
3270 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003271 ath_print(common, ATH_DBG_ANY,
3272 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003273 }
Steven Luoa89bff92009-04-12 02:57:54 -07003274 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003275 }
3276 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003277 ath_print(common, ATH_DBG_INTERRUPT,
3278 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003279 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
3280 REG_WRITE(ah, AR_RC, 0);
3281 *masked |= ATH9K_INT_FATAL;
3282 }
3283 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003284 ath_print(common, ATH_DBG_INTERRUPT,
3285 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003286 }
3287
3288 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3289 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3290 }
Sujithf1dc5602008-10-29 10:16:30 +05303291
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003292 return true;
3293}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003294EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003295
Sujithcbe61d82009-02-09 13:27:12 +05303296enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003297{
Sujith2660b812009-02-09 13:27:26 +05303298 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003299 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303300 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003301 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003302
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003303 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003304
3305 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003306 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003307 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3308 (void) REG_READ(ah, AR_IER);
3309 if (!AR_SREV_9100(ah)) {
3310 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3311 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3312
3313 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3314 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3315 }
3316 }
3317
3318 mask = ints & ATH9K_INT_COMMON;
3319 mask2 = 0;
3320
3321 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05303322 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003323 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303324 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003325 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303326 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003327 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303328 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003329 mask |= AR_IMR_TXEOL;
3330 }
3331 if (ints & ATH9K_INT_RX) {
3332 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05303333 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003334 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3335 else
3336 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303337 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003338 mask |= AR_IMR_GENTMR;
3339 }
3340
3341 if (ints & (ATH9K_INT_BMISC)) {
3342 mask |= AR_IMR_BCNMISC;
3343 if (ints & ATH9K_INT_TIM)
3344 mask2 |= AR_IMR_S2_TIM;
3345 if (ints & ATH9K_INT_DTIM)
3346 mask2 |= AR_IMR_S2_DTIM;
3347 if (ints & ATH9K_INT_DTIMSYNC)
3348 mask2 |= AR_IMR_S2_DTIMSYNC;
3349 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05303350 mask2 |= AR_IMR_S2_CABEND;
3351 if (ints & ATH9K_INT_TSFOOR)
3352 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003353 }
3354
3355 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3356 mask |= AR_IMR_BCNMISC;
3357 if (ints & ATH9K_INT_GTT)
3358 mask2 |= AR_IMR_S2_GTT;
3359 if (ints & ATH9K_INT_CST)
3360 mask2 |= AR_IMR_S2_CST;
3361 }
3362
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003363 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003364 REG_WRITE(ah, AR_IMR, mask);
3365 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3366 AR_IMR_S2_DTIM |
3367 AR_IMR_S2_DTIMSYNC |
3368 AR_IMR_S2_CABEND |
3369 AR_IMR_S2_CABTO |
3370 AR_IMR_S2_TSFOOR |
3371 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3372 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303373 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003374
Sujith60b67f52008-08-07 10:52:38 +05303375 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003376 if (ints & ATH9K_INT_TIM_TIMER)
3377 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3378 else
3379 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3380 }
3381
3382 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003383 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003384 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3385 if (!AR_SREV_9100(ah)) {
3386 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3387 AR_INTR_MAC_IRQ);
3388 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3389
3390
3391 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3392 AR_INTR_SYNC_DEFAULT);
3393 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3394 AR_INTR_SYNC_DEFAULT);
3395 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003396 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3397 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003398 }
3399
3400 return omask;
3401}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003402EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003403
Sujithf1dc5602008-10-29 10:16:30 +05303404/*******************/
3405/* Beacon Handling */
3406/*******************/
3407
Sujithcbe61d82009-02-09 13:27:12 +05303408void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003409{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003410 int flags = 0;
3411
Sujith2660b812009-02-09 13:27:26 +05303412 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003413
Sujith2660b812009-02-09 13:27:26 +05303414 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003415 case NL80211_IFTYPE_STATION:
3416 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003417 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3418 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3419 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3420 flags |= AR_TBTT_TIMER_EN;
3421 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003422 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003423 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003424 REG_SET_BIT(ah, AR_TXCFG,
3425 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3426 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3427 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303428 (ah->atim_window ? ah->
3429 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003430 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003431 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003432 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3433 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3434 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303435 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303436 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003437 REG_WRITE(ah, AR_NEXT_SWBA,
3438 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303439 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303440 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003441 flags |=
3442 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3443 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003444 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003445 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
3446 "%s: unsupported opmode: %d\n",
3447 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003448 return;
3449 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003450 }
3451
3452 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3453 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3454 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3455 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3456
3457 beacon_period &= ~ATH9K_BEACON_ENA;
3458 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003459 ath9k_hw_reset_tsf(ah);
3460 }
3461
3462 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3463}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003464EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003465
Sujithcbe61d82009-02-09 13:27:12 +05303466void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303467 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003468{
3469 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303470 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003471 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003472
3473 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3474
3475 REG_WRITE(ah, AR_BEACON_PERIOD,
3476 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3477 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3478 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3479
3480 REG_RMW_FIELD(ah, AR_RSSI_THR,
3481 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3482
3483 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3484
3485 if (bs->bs_sleepduration > beaconintval)
3486 beaconintval = bs->bs_sleepduration;
3487
3488 dtimperiod = bs->bs_dtimperiod;
3489 if (bs->bs_sleepduration > dtimperiod)
3490 dtimperiod = bs->bs_sleepduration;
3491
3492 if (beaconintval == dtimperiod)
3493 nextTbtt = bs->bs_nextdtim;
3494 else
3495 nextTbtt = bs->bs_nexttbtt;
3496
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003497 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3498 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3499 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3500 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003501
3502 REG_WRITE(ah, AR_NEXT_DTIM,
3503 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3504 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3505
3506 REG_WRITE(ah, AR_SLEEP1,
3507 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3508 | AR_SLEEP1_ASSUME_DTIM);
3509
Sujith60b67f52008-08-07 10:52:38 +05303510 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003511 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3512 else
3513 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3514
3515 REG_WRITE(ah, AR_SLEEP2,
3516 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3517
3518 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3519 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3520
3521 REG_SET_BIT(ah, AR_TIMER_MODE,
3522 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3523 AR_DTIM_TIMER_EN);
3524
Sujith4af9cf42009-02-12 10:06:47 +05303525 /* TSF Out of Range Threshold */
3526 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003527}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003528EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003529
Sujithf1dc5602008-10-29 10:16:30 +05303530/*******************/
3531/* HW Capabilities */
3532/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003533
Sujitheef7a572009-03-30 15:28:28 +05303534void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003535{
Sujith2660b812009-02-09 13:27:26 +05303536 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003537 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003538 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003539 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003540
Sujithf1dc5602008-10-29 10:16:30 +05303541 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003542
Sujithf74df6f2009-02-09 13:27:24 +05303543 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003544 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303545
Sujithf74df6f2009-02-09 13:27:24 +05303546 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303547 if (AR_SREV_9285_10_OR_LATER(ah))
3548 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003549 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303550
Sujithf74df6f2009-02-09 13:27:24 +05303551 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303552
Sujith2660b812009-02-09 13:27:26 +05303553 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303554 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003555 if (regulatory->current_rd == 0x64 ||
3556 regulatory->current_rd == 0x65)
3557 regulatory->current_rd += 5;
3558 else if (regulatory->current_rd == 0x41)
3559 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003560 ath_print(common, ATH_DBG_REGULATORY,
3561 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003562 }
Sujithdc2222a2008-08-14 13:26:55 +05303563
Sujithf74df6f2009-02-09 13:27:24 +05303564 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303565 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003566
Sujithf1dc5602008-10-29 10:16:30 +05303567 if (eeval & AR5416_OPFLAGS_11A) {
3568 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303569 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303570 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3571 set_bit(ATH9K_MODE_11NA_HT20,
3572 pCap->wireless_modes);
3573 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3574 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3575 pCap->wireless_modes);
3576 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3577 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003578 }
3579 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003580 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003581
Sujithf1dc5602008-10-29 10:16:30 +05303582 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303583 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303584 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303585 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3586 set_bit(ATH9K_MODE_11NG_HT20,
3587 pCap->wireless_modes);
3588 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3589 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3590 pCap->wireless_modes);
3591 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3592 pCap->wireless_modes);
3593 }
3594 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003595 }
Sujithf1dc5602008-10-29 10:16:30 +05303596
Sujithf74df6f2009-02-09 13:27:24 +05303597 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003598 /*
3599 * For AR9271 we will temporarilly uses the rx chainmax as read from
3600 * the EEPROM.
3601 */
Sujith8147f5d2009-02-20 15:13:23 +05303602 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003603 !(eeval & AR5416_OPFLAGS_11A) &&
3604 !(AR_SREV_9271(ah)))
3605 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303606 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3607 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003608 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303609 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303610
Sujithd535a422009-02-09 13:27:06 +05303611 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303612 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303613
3614 pCap->low_2ghz_chan = 2312;
3615 pCap->high_2ghz_chan = 2732;
3616
3617 pCap->low_5ghz_chan = 4920;
3618 pCap->high_5ghz_chan = 6100;
3619
3620 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3621 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3622 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3623
3624 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3625 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3626 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3627
Sujith2660b812009-02-09 13:27:26 +05303628 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303629 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3630 else
3631 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3632
3633 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3634 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3635 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3636 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3637
3638 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3639 pCap->total_queues =
3640 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3641 else
3642 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3643
3644 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3645 pCap->keycache_size =
3646 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3647 else
3648 pCap->keycache_size = AR_KEYTABLE_SIZE;
3649
3650 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303651 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3652
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303653 if (AR_SREV_9285_10_OR_LATER(ah))
3654 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3655 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303656 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3657 else
3658 pCap->num_gpio_pins = AR_NUM_GPIO;
3659
Sujithf1dc5602008-10-29 10:16:30 +05303660 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3661 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3662 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3663 } else {
3664 pCap->rts_aggr_limit = (8 * 1024);
3665 }
3666
3667 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3668
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303669#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303670 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3671 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3672 ah->rfkill_gpio =
3673 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3674 ah->rfkill_polarity =
3675 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303676
3677 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3678 }
3679#endif
3680
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303681 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303682
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303683 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303684 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3685 else
3686 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3687
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003688 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303689 pCap->reg_cap =
3690 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3691 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3692 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3693 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3694 } else {
3695 pCap->reg_cap =
3696 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3697 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3698 }
3699
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05303700 /* Advertise midband for AR5416 with FCC midband set in eeprom */
3701 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
3702 AR_SREV_5416(ah))
3703 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05303704
3705 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303706 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303707 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303708 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303709
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303710 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003711 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003712 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3713 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303714
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303715 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003716 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3717 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303718 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003719 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303720 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303721 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003722 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303723 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003724}
3725
Sujithcbe61d82009-02-09 13:27:12 +05303726bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303727 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003728{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003729 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303730 switch (type) {
3731 case ATH9K_CAP_CIPHER:
3732 switch (capability) {
3733 case ATH9K_CIPHER_AES_CCM:
3734 case ATH9K_CIPHER_AES_OCB:
3735 case ATH9K_CIPHER_TKIP:
3736 case ATH9K_CIPHER_WEP:
3737 case ATH9K_CIPHER_MIC:
3738 case ATH9K_CIPHER_CLR:
3739 return true;
3740 default:
3741 return false;
3742 }
3743 case ATH9K_CAP_TKIP_MIC:
3744 switch (capability) {
3745 case 0:
3746 return true;
3747 case 1:
Sujith2660b812009-02-09 13:27:26 +05303748 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303749 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3750 false;
3751 }
3752 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303753 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303754 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303755 case ATH9K_CAP_DIVERSITY:
3756 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3757 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3758 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303759 case ATH9K_CAP_MCAST_KEYSRCH:
3760 switch (capability) {
3761 case 0:
3762 return true;
3763 case 1:
3764 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3765 return false;
3766 } else {
Sujith2660b812009-02-09 13:27:26 +05303767 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303768 AR_STA_ID1_MCAST_KSRCH) ? true :
3769 false;
3770 }
3771 }
3772 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303773 case ATH9K_CAP_TXPOW:
3774 switch (capability) {
3775 case 0:
3776 return 0;
3777 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003778 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303779 return 0;
3780 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003781 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303782 return 0;
3783 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003784 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303785 return 0;
3786 }
3787 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303788 case ATH9K_CAP_DS:
3789 return (AR_SREV_9280_20_OR_LATER(ah) &&
3790 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3791 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303792 default:
3793 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003794 }
Sujithf1dc5602008-10-29 10:16:30 +05303795}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003796EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003797
Sujithcbe61d82009-02-09 13:27:12 +05303798bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303799 u32 capability, u32 setting, int *status)
3800{
Sujithf1dc5602008-10-29 10:16:30 +05303801 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003802
Sujithf1dc5602008-10-29 10:16:30 +05303803 switch (type) {
3804 case ATH9K_CAP_TKIP_MIC:
3805 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303806 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303807 AR_STA_ID1_CRPT_MIC_ENABLE;
3808 else
Sujith2660b812009-02-09 13:27:26 +05303809 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303810 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3811 return true;
3812 case ATH9K_CAP_DIVERSITY:
3813 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3814 if (setting)
3815 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3816 else
3817 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3818 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3819 return true;
3820 case ATH9K_CAP_MCAST_KEYSRCH:
3821 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303822 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303823 else
Sujith2660b812009-02-09 13:27:26 +05303824 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303825 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303826 default:
3827 return false;
3828 }
3829}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003830EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303831
3832/****************************/
3833/* GPIO / RFKILL / Antennae */
3834/****************************/
3835
Sujithcbe61d82009-02-09 13:27:12 +05303836static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303837 u32 gpio, u32 type)
3838{
3839 int addr;
3840 u32 gpio_shift, tmp;
3841
3842 if (gpio > 11)
3843 addr = AR_GPIO_OUTPUT_MUX3;
3844 else if (gpio > 5)
3845 addr = AR_GPIO_OUTPUT_MUX2;
3846 else
3847 addr = AR_GPIO_OUTPUT_MUX1;
3848
3849 gpio_shift = (gpio % 6) * 5;
3850
3851 if (AR_SREV_9280_20_OR_LATER(ah)
3852 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3853 REG_RMW(ah, addr, (type << gpio_shift),
3854 (0x1f << gpio_shift));
3855 } else {
3856 tmp = REG_READ(ah, addr);
3857 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3858 tmp &= ~(0x1f << gpio_shift);
3859 tmp |= (type << gpio_shift);
3860 REG_WRITE(ah, addr, tmp);
3861 }
3862}
3863
Sujithcbe61d82009-02-09 13:27:12 +05303864void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303865{
3866 u32 gpio_shift;
3867
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003868 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303869
3870 gpio_shift = gpio << 1;
3871
3872 REG_RMW(ah,
3873 AR_GPIO_OE_OUT,
3874 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3875 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3876}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003877EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303878
Sujithcbe61d82009-02-09 13:27:12 +05303879u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303880{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303881#define MS_REG_READ(x, y) \
3882 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3883
Sujith2660b812009-02-09 13:27:26 +05303884 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303885 return 0xffffffff;
3886
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303887 if (AR_SREV_9287_10_OR_LATER(ah))
3888 return MS_REG_READ(AR9287, gpio) != 0;
3889 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303890 return MS_REG_READ(AR9285, gpio) != 0;
3891 else if (AR_SREV_9280_10_OR_LATER(ah))
3892 return MS_REG_READ(AR928X, gpio) != 0;
3893 else
3894 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303895}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003896EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303897
Sujithcbe61d82009-02-09 13:27:12 +05303898void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303899 u32 ah_signal_type)
3900{
3901 u32 gpio_shift;
3902
3903 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3904
3905 gpio_shift = 2 * gpio;
3906
3907 REG_RMW(ah,
3908 AR_GPIO_OE_OUT,
3909 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3910 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3911}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003912EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303913
Sujithcbe61d82009-02-09 13:27:12 +05303914void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303915{
3916 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3917 AR_GPIO_BIT(gpio));
3918}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003919EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303920
Sujithcbe61d82009-02-09 13:27:12 +05303921u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303922{
3923 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3924}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003925EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303926
Sujithcbe61d82009-02-09 13:27:12 +05303927void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303928{
3929 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3930}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003931EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303932
Sujithcbe61d82009-02-09 13:27:12 +05303933bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303934 enum ath9k_ant_setting settings,
3935 struct ath9k_channel *chan,
3936 u8 *tx_chainmask,
3937 u8 *rx_chainmask,
3938 u8 *antenna_cfgd)
3939{
Sujithf1dc5602008-10-29 10:16:30 +05303940 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3941
3942 if (AR_SREV_9280(ah)) {
3943 if (!tx_chainmask_cfg) {
3944
3945 tx_chainmask_cfg = *tx_chainmask;
3946 rx_chainmask_cfg = *rx_chainmask;
3947 }
3948
3949 switch (settings) {
3950 case ATH9K_ANT_FIXED_A:
3951 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3952 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3953 *antenna_cfgd = true;
3954 break;
3955 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303956 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303957 ATH9K_ANTENNA1_CHAINMASK) {
3958 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3959 }
3960 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3961 *antenna_cfgd = true;
3962 break;
3963 case ATH9K_ANT_VARIABLE:
3964 *tx_chainmask = tx_chainmask_cfg;
3965 *rx_chainmask = rx_chainmask_cfg;
3966 *antenna_cfgd = true;
3967 break;
3968 default:
3969 break;
3970 }
3971 } else {
Sujith1cf68732009-08-13 09:34:32 +05303972 ah->config.diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303973 }
3974
3975 return true;
3976}
3977
3978/*********************/
3979/* General Operation */
3980/*********************/
3981
Sujithcbe61d82009-02-09 13:27:12 +05303982u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303983{
3984 u32 bits = REG_READ(ah, AR_RX_FILTER);
3985 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3986
3987 if (phybits & AR_PHY_ERR_RADAR)
3988 bits |= ATH9K_RX_FILTER_PHYRADAR;
3989 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3990 bits |= ATH9K_RX_FILTER_PHYERR;
3991
3992 return bits;
3993}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003994EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303995
Sujithcbe61d82009-02-09 13:27:12 +05303996void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303997{
3998 u32 phybits;
3999
Sujith7ea310b2009-09-03 12:08:43 +05304000 REG_WRITE(ah, AR_RX_FILTER, bits);
4001
Sujithf1dc5602008-10-29 10:16:30 +05304002 phybits = 0;
4003 if (bits & ATH9K_RX_FILTER_PHYRADAR)
4004 phybits |= AR_PHY_ERR_RADAR;
4005 if (bits & ATH9K_RX_FILTER_PHYERR)
4006 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
4007 REG_WRITE(ah, AR_PHY_ERR, phybits);
4008
4009 if (phybits)
4010 REG_WRITE(ah, AR_RXCFG,
4011 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
4012 else
4013 REG_WRITE(ah, AR_RXCFG,
4014 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
4015}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004016EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304017
Sujithcbe61d82009-02-09 13:27:12 +05304018bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304019{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05304020 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
4021 return false;
4022
4023 ath9k_hw_init_pll(ah, NULL);
4024 return true;
Sujithf1dc5602008-10-29 10:16:30 +05304025}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004026EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05304027
Sujithcbe61d82009-02-09 13:27:12 +05304028bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304029{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07004030 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05304031 return false;
4032
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05304033 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
4034 return false;
4035
4036 ath9k_hw_init_pll(ah, NULL);
4037 return true;
Sujithf1dc5602008-10-29 10:16:30 +05304038}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004039EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05304040
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004041void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05304042{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004043 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05304044 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08004045 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05304046
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004047 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05304048
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004049 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004050 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004051 channel->max_antenna_gain * 2,
4052 channel->max_power * 2,
4053 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004054 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05304055}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004056EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05304057
Sujithcbe61d82009-02-09 13:27:12 +05304058void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05304059{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004060 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05304061}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004062EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05304063
Sujithcbe61d82009-02-09 13:27:12 +05304064void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304065{
Sujith2660b812009-02-09 13:27:26 +05304066 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05304067}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004068EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05304069
Sujithcbe61d82009-02-09 13:27:12 +05304070void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05304071{
4072 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
4073 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
4074}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004075EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05304076
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07004077void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304078{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004079 struct ath_common *common = ath9k_hw_common(ah);
4080
4081 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
4082 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
4083 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05304084}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004085EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05304086
Sujithcbe61d82009-02-09 13:27:12 +05304087u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304088{
4089 u64 tsf;
4090
4091 tsf = REG_READ(ah, AR_TSF_U32);
4092 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
4093
4094 return tsf;
4095}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004096EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05304097
Sujithcbe61d82009-02-09 13:27:12 +05304098void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004099{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004100 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01004101 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004102}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004103EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004104
Sujithcbe61d82009-02-09 13:27:12 +05304105void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304106{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004107 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
4108 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004109 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4110 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004111
Sujithf1dc5602008-10-29 10:16:30 +05304112 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004113}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004114EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004115
Sujith54e4cec2009-08-07 09:45:09 +05304116void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004117{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004118 if (setting)
Sujith2660b812009-02-09 13:27:26 +05304119 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004120 else
Sujith2660b812009-02-09 13:27:26 +05304121 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004122}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004123EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004124
Sujithcbe61d82009-02-09 13:27:12 +05304125bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004126{
Sujithf1dc5602008-10-29 10:16:30 +05304127 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004128 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4129 "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05304130 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05304131 return false;
4132 } else {
4133 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05304134 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05304135 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004136 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004137}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004138EXPORT_SYMBOL(ath9k_hw_setslottime);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004139
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004140void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004141{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004142 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05304143 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004144
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07004145 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05304146 macmode = AR_2040_JOINED_RX_CLEAR;
4147 else
4148 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004149
Sujithf1dc5602008-10-29 10:16:30 +05304150 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004151}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304152
4153/* HW Generic timers configuration */
4154
4155static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
4156{
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_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4162 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4163 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4164 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4165 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
4166 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
4167 AR_NDP2_TIMER_MODE, 0x0002},
4168 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
4169 AR_NDP2_TIMER_MODE, 0x0004},
4170 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
4171 AR_NDP2_TIMER_MODE, 0x0008},
4172 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
4173 AR_NDP2_TIMER_MODE, 0x0010},
4174 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
4175 AR_NDP2_TIMER_MODE, 0x0020},
4176 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
4177 AR_NDP2_TIMER_MODE, 0x0040},
4178 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
4179 AR_NDP2_TIMER_MODE, 0x0080}
4180};
4181
4182/* HW generic timer primitives */
4183
4184/* compute and clear index of rightmost 1 */
4185static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
4186{
4187 u32 b;
4188
4189 b = *mask;
4190 b &= (0-b);
4191 *mask &= ~b;
4192 b *= debruijn32;
4193 b >>= 27;
4194
4195 return timer_table->gen_timer_index[b];
4196}
4197
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05304198u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304199{
4200 return REG_READ(ah, AR_TSF_L32);
4201}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004202EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304203
4204struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
4205 void (*trigger)(void *),
4206 void (*overflow)(void *),
4207 void *arg,
4208 u8 timer_index)
4209{
4210 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4211 struct ath_gen_timer *timer;
4212
4213 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
4214
4215 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004216 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
4217 "Failed to allocate memory"
4218 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304219 return NULL;
4220 }
4221
4222 /* allocate a hardware generic timer slot */
4223 timer_table->timers[timer_index] = timer;
4224 timer->index = timer_index;
4225 timer->trigger = trigger;
4226 timer->overflow = overflow;
4227 timer->arg = arg;
4228
4229 return timer;
4230}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004231EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304232
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004233void ath9k_hw_gen_timer_start(struct ath_hw *ah,
4234 struct ath_gen_timer *timer,
4235 u32 timer_next,
4236 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304237{
4238 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4239 u32 tsf;
4240
4241 BUG_ON(!timer_period);
4242
4243 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
4244
4245 tsf = ath9k_hw_gettsf32(ah);
4246
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004247 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
4248 "curent tsf %x period %x"
4249 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304250
4251 /*
4252 * Pull timer_next forward if the current TSF already passed it
4253 * because of software latency
4254 */
4255 if (timer_next < tsf)
4256 timer_next = tsf + timer_period;
4257
4258 /*
4259 * Program generic timer registers
4260 */
4261 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
4262 timer_next);
4263 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
4264 timer_period);
4265 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4266 gen_tmr_configuration[timer->index].mode_mask);
4267
4268 /* Enable both trigger and thresh interrupt masks */
4269 REG_SET_BIT(ah, AR_IMR_S5,
4270 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4271 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304272}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004273EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304274
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004275void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304276{
4277 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4278
4279 if ((timer->index < AR_FIRST_NDP_TIMER) ||
4280 (timer->index >= ATH_MAX_GEN_TIMER)) {
4281 return;
4282 }
4283
4284 /* Clear generic timer enable bits. */
4285 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4286 gen_tmr_configuration[timer->index].mode_mask);
4287
4288 /* Disable both trigger and thresh interrupt masks */
4289 REG_CLR_BIT(ah, AR_IMR_S5,
4290 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4291 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
4292
4293 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304294}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004295EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304296
4297void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
4298{
4299 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4300
4301 /* free the hardware generic timer slot */
4302 timer_table->timers[timer->index] = NULL;
4303 kfree(timer);
4304}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004305EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304306
4307/*
4308 * Generic Timer Interrupts handling
4309 */
4310void ath_gen_timer_isr(struct ath_hw *ah)
4311{
4312 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4313 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004314 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304315 u32 trigger_mask, thresh_mask, index;
4316
4317 /* get hardware generic timer interrupt status */
4318 trigger_mask = ah->intr_gen_timer_trigger;
4319 thresh_mask = ah->intr_gen_timer_thresh;
4320 trigger_mask &= timer_table->timer_mask.val;
4321 thresh_mask &= timer_table->timer_mask.val;
4322
4323 trigger_mask &= ~thresh_mask;
4324
4325 while (thresh_mask) {
4326 index = rightmost_index(timer_table, &thresh_mask);
4327 timer = timer_table->timers[index];
4328 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004329 ath_print(common, ATH_DBG_HWTIMER,
4330 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304331 timer->overflow(timer->arg);
4332 }
4333
4334 while (trigger_mask) {
4335 index = rightmost_index(timer_table, &trigger_mask);
4336 timer = timer_table->timers[index];
4337 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004338 ath_print(common, ATH_DBG_HWTIMER,
4339 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304340 timer->trigger(timer->arg);
4341 }
4342}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04004343EXPORT_SYMBOL(ath_gen_timer_isr);