blob: 9474f9f6d4005c37eba9f672325eb94b5178f386 [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);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070033
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040034MODULE_AUTHOR("Atheros Communications");
35MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
36MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
37MODULE_LICENSE("Dual BSD/GPL");
38
39static int __init ath9k_init(void)
40{
41 return 0;
42}
43module_init(ath9k_init);
44
45static void __exit ath9k_exit(void)
46{
47 return;
48}
49module_exit(ath9k_exit);
50
Sujithf1dc5602008-10-29 10:16:30 +053051/********************/
52/* Helper Functions */
53/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070054
Sujithcbe61d82009-02-09 13:27:12 +053055static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053056{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070057 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053058
Sujith2660b812009-02-09 13:27:26 +053059 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080060 return clks / ATH9K_CLOCK_RATE_CCK;
61 if (conf->channel->band == IEEE80211_BAND_2GHZ)
62 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053063
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080064 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053065}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070066
Sujithcbe61d82009-02-09 13:27:12 +053067static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053068{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070069 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053070
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080071 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053072 return ath9k_hw_mac_usec(ah, clks) / 2;
73 else
74 return ath9k_hw_mac_usec(ah, clks);
75}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070076
Sujithcbe61d82009-02-09 13:27:12 +053077static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053078{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070079 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053080
Sujith2660b812009-02-09 13:27:26 +053081 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080082 return usecs *ATH9K_CLOCK_RATE_CCK;
83 if (conf->channel->band == IEEE80211_BAND_2GHZ)
84 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
85 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053086}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070087
Sujithcbe61d82009-02-09 13:27:12 +053088static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053089{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070090 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053091
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080092 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053093 return ath9k_hw_mac_clks(ah, usecs) * 2;
94 else
95 return ath9k_hw_mac_clks(ah, usecs);
96}
97
Sujith0caa7b12009-02-16 13:23:20 +053098bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070099{
100 int i;
101
Sujith0caa7b12009-02-16 13:23:20 +0530102 BUG_ON(timeout < AH_TIME_QUANTUM);
103
104 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700105 if ((REG_READ(ah, reg) & mask) == val)
106 return true;
107
108 udelay(AH_TIME_QUANTUM);
109 }
Sujith04bd46382008-11-28 22:18:05 +0530110
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700111 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
112 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
113 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530114
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700115 return false;
116}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400117EXPORT_SYMBOL(ath9k_hw_wait);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700118
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700119u32 ath9k_hw_reverse_bits(u32 val, u32 n)
120{
121 u32 retval;
122 int i;
123
124 for (i = 0, retval = 0; i < n; i++) {
125 retval = (retval << 1) | (val & 1);
126 val >>= 1;
127 }
128 return retval;
129}
130
Sujithcbe61d82009-02-09 13:27:12 +0530131bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530132 u16 flags, u16 *low,
133 u16 *high)
134{
Sujith2660b812009-02-09 13:27:26 +0530135 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530136
137 if (flags & CHANNEL_5GHZ) {
138 *low = pCap->low_5ghz_chan;
139 *high = pCap->high_5ghz_chan;
140 return true;
141 }
142 if ((flags & CHANNEL_2GHZ)) {
143 *low = pCap->low_2ghz_chan;
144 *high = pCap->high_2ghz_chan;
145 return true;
146 }
147 return false;
148}
149
Sujithcbe61d82009-02-09 13:27:12 +0530150u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Felix Fietkau545750d2009-11-23 22:21:01 +0100151 u8 phy, int kbps,
Sujithf1dc5602008-10-29 10:16:30 +0530152 u32 frameLen, u16 rateix,
153 bool shortPreamble)
154{
155 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
Sujithf1dc5602008-10-29 10:16:30 +0530156
157 if (kbps == 0)
158 return 0;
159
Felix Fietkau545750d2009-11-23 22:21:01 +0100160 switch (phy) {
Sujith46d14a52008-11-18 09:08:13 +0530161 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530162 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100163 if (shortPreamble)
Sujithf1dc5602008-10-29 10:16:30 +0530164 phyTime >>= 1;
165 numBits = frameLen << 3;
166 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
167 break;
Sujith46d14a52008-11-18 09:08:13 +0530168 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530169 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530170 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
171 numBits = OFDM_PLCP_BITS + (frameLen << 3);
172 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
173 txTime = OFDM_SIFS_TIME_QUARTER
174 + OFDM_PREAMBLE_TIME_QUARTER
175 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530176 } else if (ah->curchan &&
177 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530178 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
179 numBits = OFDM_PLCP_BITS + (frameLen << 3);
180 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
181 txTime = OFDM_SIFS_TIME_HALF +
182 OFDM_PREAMBLE_TIME_HALF
183 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
184 } else {
185 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
186 numBits = OFDM_PLCP_BITS + (frameLen << 3);
187 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
188 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
189 + (numSymbols * OFDM_SYMBOL_TIME);
190 }
191 break;
192 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700193 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
Felix Fietkau545750d2009-11-23 22:21:01 +0100194 "Unknown phy %u (rate ix %u)\n", phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530195 txTime = 0;
196 break;
197 }
198
199 return txTime;
200}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400201EXPORT_SYMBOL(ath9k_hw_computetxtime);
Sujithf1dc5602008-10-29 10:16:30 +0530202
Sujithcbe61d82009-02-09 13:27:12 +0530203void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530204 struct ath9k_channel *chan,
205 struct chan_centers *centers)
206{
207 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530208
209 if (!IS_CHAN_HT40(chan)) {
210 centers->ctl_center = centers->ext_center =
211 centers->synth_center = chan->channel;
212 return;
213 }
214
215 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
216 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
217 centers->synth_center =
218 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
219 extoff = 1;
220 } else {
221 centers->synth_center =
222 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
223 extoff = -1;
224 }
225
226 centers->ctl_center =
227 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700228 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530229 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700230 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530231}
232
233/******************/
234/* Chip Revisions */
235/******************/
236
Sujithcbe61d82009-02-09 13:27:12 +0530237static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530238{
239 u32 val;
240
241 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
242
243 if (val == 0xFF) {
244 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530245 ah->hw_version.macVersion =
246 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
247 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530248 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530249 } else {
250 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530251 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530252
Sujithd535a422009-02-09 13:27:06 +0530253 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530254
Sujithd535a422009-02-09 13:27:06 +0530255 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530256 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530257 }
258}
259
Sujithcbe61d82009-02-09 13:27:12 +0530260static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530261{
262 u32 val;
263 int i;
264
265 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
266
267 for (i = 0; i < 8; i++)
268 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
269 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
270 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
271
272 return ath9k_hw_reverse_bits(val, 8);
273}
274
275/************************************/
276/* HW Attach, Detach, Init Routines */
277/************************************/
278
Sujithcbe61d82009-02-09 13:27:12 +0530279static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530280{
Sujithfeed0292009-01-29 11:37:35 +0530281 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530282 return;
283
284 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
285 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
286 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
287 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
288 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
293
294 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
295}
296
Sujithcbe61d82009-02-09 13:27:12 +0530297static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530298{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700299 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530300 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
301 u32 regHold[2];
302 u32 patternData[4] = { 0x55555555,
303 0xaaaaaaaa,
304 0x66666666,
305 0x99999999 };
306 int i, j;
307
308 for (i = 0; i < 2; i++) {
309 u32 addr = regAddr[i];
310 u32 wrData, rdData;
311
312 regHold[i] = REG_READ(ah, addr);
313 for (j = 0; j < 0x100; j++) {
314 wrData = (j << 16) | j;
315 REG_WRITE(ah, addr, wrData);
316 rdData = REG_READ(ah, addr);
317 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700318 ath_print(common, ATH_DBG_FATAL,
319 "address test failed "
320 "addr: 0x%08x - wr:0x%08x != "
321 "rd:0x%08x\n",
322 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530323 return false;
324 }
325 }
326 for (j = 0; j < 4; j++) {
327 wrData = patternData[j];
328 REG_WRITE(ah, addr, wrData);
329 rdData = REG_READ(ah, addr);
330 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700331 ath_print(common, ATH_DBG_FATAL,
332 "address test failed "
333 "addr: 0x%08x - wr:0x%08x != "
334 "rd:0x%08x\n",
335 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530336 return false;
337 }
338 }
339 REG_WRITE(ah, regAddr[i], regHold[i]);
340 }
341 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530342
Sujithf1dc5602008-10-29 10:16:30 +0530343 return true;
344}
345
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700346static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700347{
348 int i;
349
Sujith2660b812009-02-09 13:27:26 +0530350 ah->config.dma_beacon_response_time = 2;
351 ah->config.sw_beacon_response_time = 10;
352 ah->config.additional_swba_backoff = 0;
353 ah->config.ack_6mb = 0x0;
354 ah->config.cwm_ignore_extcca = 0;
355 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530356 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530357 ah->config.pcie_waen = 0;
358 ah->config.analog_shiftreg = 1;
359 ah->config.ht_enable = 1;
360 ah->config.ofdm_trig_low = 200;
361 ah->config.ofdm_trig_high = 500;
362 ah->config.cck_trig_high = 200;
363 ah->config.cck_trig_low = 100;
364 ah->config.enable_ani = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700365
366 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530367 ah->config.spurchans[i][0] = AR_NO_SPUR;
368 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700369 }
370
Sujith0ce024c2009-12-14 14:57:00 +0530371 ah->config.rx_intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400372
373 /*
374 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
375 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
376 * This means we use it for all AR5416 devices, and the few
377 * minor PCI AR9280 devices out there.
378 *
379 * Serialization is required because these devices do not handle
380 * well the case of two concurrent reads/writes due to the latency
381 * involved. During one read/write another read/write can be issued
382 * on another CPU while the previous read/write may still be working
383 * on our hardware, if we hit this case the hardware poops in a loop.
384 * We prevent this by serializing reads and writes.
385 *
386 * This issue is not present on PCI-Express devices or pre-AR5416
387 * devices (legacy, 802.11abg).
388 */
389 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700390 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700391}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400392EXPORT_SYMBOL(ath9k_hw_init);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700393
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700394static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700395{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700396 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
397
398 regulatory->country_code = CTRY_DEFAULT;
399 regulatory->power_limit = MAX_RATE_POWER;
400 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
401
Sujithd535a422009-02-09 13:27:06 +0530402 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530403 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700404
405 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700406 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530407 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700408 if (!AR_SREV_9100(ah))
409 ah->ah_flags = AH_USE_EEPROM;
410
Sujith2660b812009-02-09 13:27:26 +0530411 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530412 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
413 ah->beacon_interval = 100;
414 ah->enable_32kHz_clock = DONT_USE_32KHZ;
415 ah->slottime = (u32) -1;
416 ah->acktimeout = (u32) -1;
417 ah->ctstimeout = (u32) -1;
418 ah->globaltxtimeout = (u32) -1;
Gabor Juhoscbdec972009-07-24 17:27:22 +0200419 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700420}
421
Sujithcbe61d82009-02-09 13:27:12 +0530422static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700423{
424 u32 val;
425
426 REG_WRITE(ah, AR_PHY(0), 0x00000007);
427
428 val = ath9k_hw_get_radiorev(ah);
429 switch (val & AR_RADIO_SREV_MAJOR) {
430 case 0:
431 val = AR_RAD5133_SREV_MAJOR;
432 break;
433 case AR_RAD5133_SREV_MAJOR:
434 case AR_RAD5122_SREV_MAJOR:
435 case AR_RAD2133_SREV_MAJOR:
436 case AR_RAD2122_SREV_MAJOR:
437 break;
438 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700439 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
440 "Radio Chip Rev 0x%02X not supported\n",
441 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700442 return -EOPNOTSUPP;
443 }
444
Sujithd535a422009-02-09 13:27:06 +0530445 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700446
447 return 0;
448}
449
Sujithcbe61d82009-02-09 13:27:12 +0530450static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700452 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530453 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700454 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530455 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700456
Sujithf1dc5602008-10-29 10:16:30 +0530457 sum = 0;
458 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530459 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530460 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700461 common->macaddr[2 * i] = eeval >> 8;
462 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463 }
Sujithd8baa932009-03-30 15:28:25 +0530464 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530465 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700466
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700467 return 0;
468}
469
Sujithcbe61d82009-02-09 13:27:12 +0530470static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530471{
472 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530473
Sujithf74df6f2009-02-09 13:27:24 +0530474 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
475 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530476
477 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530478 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530479 ar9280Modes_backoff_13db_rxgain_9280_2,
480 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
481 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530482 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530483 ar9280Modes_backoff_23db_rxgain_9280_2,
484 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
485 else
Sujith2660b812009-02-09 13:27:26 +0530486 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530487 ar9280Modes_original_rxgain_9280_2,
488 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530489 } else {
Sujith2660b812009-02-09 13:27:26 +0530490 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530491 ar9280Modes_original_rxgain_9280_2,
492 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530493 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530494}
495
Sujithcbe61d82009-02-09 13:27:12 +0530496static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530497{
498 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530499
Sujithf74df6f2009-02-09 13:27:24 +0530500 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
501 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530502
503 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530504 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530505 ar9280Modes_high_power_tx_gain_9280_2,
506 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
507 else
Sujith2660b812009-02-09 13:27:26 +0530508 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530509 ar9280Modes_original_tx_gain_9280_2,
510 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530511 } else {
Sujith2660b812009-02-09 13:27:26 +0530512 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530513 ar9280Modes_original_tx_gain_9280_2,
514 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530515 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530516}
517
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700518static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700519{
520 int ecode;
521
Sujithd8baa932009-03-30 15:28:25 +0530522 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700523 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700524
525 ecode = ath9k_hw_rf_claim(ah);
526 if (ecode != 0)
527 return ecode;
528
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700529 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700530 if (ecode != 0)
531 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530532
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700533 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
534 "Eeprom VER: %d, REV: %d\n",
535 ah->eep_ops->get_eeprom_ver(ah),
536 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530537
Luis R. Rodriguez574d6b12009-10-19 02:33:37 -0400538 if (!AR_SREV_9280_10_OR_LATER(ah)) {
539 ecode = ath9k_hw_rf_alloc_ext_banks(ah);
540 if (ecode) {
541 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
542 "Failed allocating banks for "
543 "external radio\n");
544 return ecode;
545 }
546 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700547
548 if (!AR_SREV_9100(ah)) {
549 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700550 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700551 }
Sujithf1dc5602008-10-29 10:16:30 +0530552
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700553 return 0;
554}
555
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700556static bool ath9k_hw_devid_supported(u16 devid)
557{
558 switch (devid) {
559 case AR5416_DEVID_PCI:
560 case AR5416_DEVID_PCIE:
561 case AR5416_AR9100_DEVID:
562 case AR9160_DEVID_PCI:
563 case AR9280_DEVID_PCI:
564 case AR9280_DEVID_PCIE:
565 case AR9285_DEVID_PCIE:
566 case AR5416_DEVID_AR9287_PCI:
567 case AR5416_DEVID_AR9287_PCIE:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400568 case AR9271_USB:
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700569 return true;
570 default:
571 break;
572 }
573 return false;
574}
575
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700576static bool ath9k_hw_macversion_supported(u32 macversion)
577{
578 switch (macversion) {
579 case AR_SREV_VERSION_5416_PCI:
580 case AR_SREV_VERSION_5416_PCIE:
581 case AR_SREV_VERSION_9160:
582 case AR_SREV_VERSION_9100:
583 case AR_SREV_VERSION_9280:
584 case AR_SREV_VERSION_9285:
585 case AR_SREV_VERSION_9287:
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400586 case AR_SREV_VERSION_9271:
Luis R. Rodriguez7976b422009-09-23 23:07:02 -0400587 return true;
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700588 default:
589 break;
590 }
591 return false;
592}
593
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700594static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700595{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700596 if (AR_SREV_9160_10_OR_LATER(ah)) {
597 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530598 ah->iq_caldata.calData = &iq_cal_single_sample;
599 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700600 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530601 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700602 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530603 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700604 &adc_init_dc_cal;
605 } else {
Sujith2660b812009-02-09 13:27:26 +0530606 ah->iq_caldata.calData = &iq_cal_multi_sample;
607 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700608 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530609 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700610 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530611 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700612 &adc_init_dc_cal;
613 }
Sujith2660b812009-02-09 13:27:26 +0530614 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700615 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700616}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700617
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700618static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
619{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400620 if (AR_SREV_9271(ah)) {
Luis R. Rodriguez85643282009-10-19 02:33:33 -0400621 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
622 ARRAY_SIZE(ar9271Modes_9271), 6);
623 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
624 ARRAY_SIZE(ar9271Common_9271), 2);
625 INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
626 ar9271Modes_9271_1_0_only,
627 ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400628 return;
629 }
630
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530631 if (AR_SREV_9287_11_OR_LATER(ah)) {
632 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
633 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
634 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
635 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
636 if (ah->config.pcie_clock_req)
637 INIT_INI_ARRAY(&ah->iniPcieSerdes,
638 ar9287PciePhy_clkreq_off_L1_9287_1_1,
639 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
640 else
641 INIT_INI_ARRAY(&ah->iniPcieSerdes,
642 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
643 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
644 2);
645 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
646 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
647 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
648 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
649 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700650
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530651 if (ah->config.pcie_clock_req)
652 INIT_INI_ARRAY(&ah->iniPcieSerdes,
653 ar9287PciePhy_clkreq_off_L1_9287_1_0,
654 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
655 else
656 INIT_INI_ARRAY(&ah->iniPcieSerdes,
657 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
658 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
659 2);
660 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
661
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530662
Sujith2660b812009-02-09 13:27:26 +0530663 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530664 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530665 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530666 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
667
Sujith2660b812009-02-09 13:27:26 +0530668 if (ah->config.pcie_clock_req) {
669 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530670 ar9285PciePhy_clkreq_off_L1_9285_1_2,
671 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
672 } else {
Sujith2660b812009-02-09 13:27:26 +0530673 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530674 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
675 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
676 2);
677 }
678 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530679 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530680 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530681 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530682 ARRAY_SIZE(ar9285Common_9285), 2);
683
Sujith2660b812009-02-09 13:27:26 +0530684 if (ah->config.pcie_clock_req) {
685 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530686 ar9285PciePhy_clkreq_off_L1_9285,
687 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
688 } else {
Sujith2660b812009-02-09 13:27:26 +0530689 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530690 ar9285PciePhy_clkreq_always_on_L1_9285,
691 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
692 }
693 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530694 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700695 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530696 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700697 ARRAY_SIZE(ar9280Common_9280_2), 2);
698
Sujith2660b812009-02-09 13:27:26 +0530699 if (ah->config.pcie_clock_req) {
700 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530701 ar9280PciePhy_clkreq_off_L1_9280,
702 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700703 } else {
Sujith2660b812009-02-09 13:27:26 +0530704 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530705 ar9280PciePhy_clkreq_always_on_L1_9280,
706 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700707 }
Sujith2660b812009-02-09 13:27:26 +0530708 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700709 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530710 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700711 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530712 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700713 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530714 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700715 ARRAY_SIZE(ar9280Common_9280), 2);
716 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530717 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700718 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530719 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700720 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530721 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700722 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530723 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700724 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530725 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700726 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530727 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700728 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530729 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700730 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530731 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700732 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530733 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700734 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530735 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 ARRAY_SIZE(ar5416Bank7_9160), 2);
737 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530738 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700739 ar5416Addac_91601_1,
740 ARRAY_SIZE(ar5416Addac_91601_1), 2);
741 } else {
Sujith2660b812009-02-09 13:27:26 +0530742 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700743 ARRAY_SIZE(ar5416Addac_9160), 2);
744 }
745 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530746 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700747 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530748 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700749 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530750 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700751 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530752 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530754 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530756 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700757 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530758 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530760 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530762 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700763 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530766 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 ARRAY_SIZE(ar5416Addac_9100), 2);
768 } else {
Sujith2660b812009-02-09 13:27:26 +0530769 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700770 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530771 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530773 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700774 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530775 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700776 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530777 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700778 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530779 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530781 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700782 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530783 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530785 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700786 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530789 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700790 ARRAY_SIZE(ar5416Addac), 2);
791 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700792}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700793
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700794static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
795{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530796 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530797 INIT_INI_ARRAY(&ah->iniModesRxGain,
798 ar9287Modes_rx_gain_9287_1_1,
799 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
800 else if (AR_SREV_9287_10(ah))
801 INIT_INI_ARRAY(&ah->iniModesRxGain,
802 ar9287Modes_rx_gain_9287_1_0,
803 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
804 else if (AR_SREV_9280_20(ah))
805 ath9k_hw_init_rxgain_ini(ah);
806
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530807 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530808 INIT_INI_ARRAY(&ah->iniModesTxGain,
809 ar9287Modes_tx_gain_9287_1_1,
810 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
811 } else if (AR_SREV_9287_10(ah)) {
812 INIT_INI_ARRAY(&ah->iniModesTxGain,
813 ar9287Modes_tx_gain_9287_1_0,
814 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
815 } else if (AR_SREV_9280_20(ah)) {
816 ath9k_hw_init_txgain_ini(ah);
817 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530818 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
819
820 /* txgain table */
821 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
822 INIT_INI_ARRAY(&ah->iniModesTxGain,
823 ar9285Modes_high_power_tx_gain_9285_1_2,
824 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
825 } else {
826 INIT_INI_ARRAY(&ah->iniModesTxGain,
827 ar9285Modes_original_tx_gain_9285_1_2,
828 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
829 }
830
831 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700832}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530833
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700834static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
835{
836 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530837
838 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
839 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
840
841 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530842 for (i = 0; i < ah->iniModes.ia_rows; i++) {
843 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700844
Sujith2660b812009-02-09 13:27:26 +0530845 for (j = 1; j < ah->iniModes.ia_columns; j++) {
846 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700847
Sujith2660b812009-02-09 13:27:26 +0530848 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530849 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530850 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700851 reg, val);
852 }
853 }
854 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700855}
856
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700857int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700858{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700859 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700860 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700861
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400862 if (!ath9k_hw_devid_supported(ah->hw_version.devid)) {
863 ath_print(common, ATH_DBG_FATAL,
864 "Unsupported device ID: 0x%0x\n",
865 ah->hw_version.devid);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700866 return -EOPNOTSUPP;
Luis R. Rodriguez3ca34032009-09-23 23:07:01 -0400867 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700868
869 ath9k_hw_init_defaults(ah);
870 ath9k_hw_init_config(ah);
871
872 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700873 ath_print(common, ATH_DBG_FATAL,
874 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700875 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700876 }
877
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700878 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700879 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700880 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700881 }
882
883 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
884 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
885 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
886 ah->config.serialize_regmode =
887 SER_REG_MODE_ON;
888 } else {
889 ah->config.serialize_regmode =
890 SER_REG_MODE_OFF;
891 }
892 }
893
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700894 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700895 ah->config.serialize_regmode);
896
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -0500897 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
898 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
899 else
900 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
901
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700902 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700903 ath_print(common, ATH_DBG_FATAL,
904 "Mac Chip Rev 0x%02x.%x is not supported by "
905 "this driver\n", ah->hw_version.macVersion,
906 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700907 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700908 }
909
910 if (AR_SREV_9100(ah)) {
911 ah->iq_caldata.calData = &iq_cal_multi_sample;
912 ah->supp_cals = IQ_MISMATCH_CAL;
913 ah->is_pciexpress = false;
914 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400915
916 if (AR_SREV_9271(ah))
917 ah->is_pciexpress = false;
918
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700919 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
920
921 ath9k_hw_init_cal_settings(ah);
922
923 ah->ani_function = ATH9K_ANI_ALL;
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -0400924 if (AR_SREV_9280_10_OR_LATER(ah)) {
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700925 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -0400926 ah->ath9k_hw_rf_set_freq = &ath9k_hw_ar9280_set_channel;
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -0400927 ah->ath9k_hw_spur_mitigate_freq = &ath9k_hw_9280_spur_mitigate;
928 } else {
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -0400929 ah->ath9k_hw_rf_set_freq = &ath9k_hw_set_channel;
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -0400930 ah->ath9k_hw_spur_mitigate_freq = &ath9k_hw_spur_mitigate;
931 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700932
933 ath9k_hw_init_mode_regs(ah);
934
935 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530936 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700937 else
938 ath9k_hw_disablepcie(ah);
939
Sujith193cd452009-09-18 15:04:07 +0530940 /* Support for Japan ch.14 (2484) spread */
941 if (AR_SREV_9287_11_OR_LATER(ah)) {
942 INIT_INI_ARRAY(&ah->iniCckfirNormal,
943 ar9287Common_normal_cck_fir_coeff_92871_1,
944 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
945 INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
946 ar9287Common_japan_2484_cck_fir_coeff_92871_1,
947 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
948 }
949
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700950 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700951 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700952 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700953
954 ath9k_hw_init_mode_gain_regs(ah);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +0100955 r = ath9k_hw_fill_cap_info(ah);
956 if (r)
957 return r;
958
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700959 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530960
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700961 r = ath9k_hw_init_macaddr(ah);
962 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700963 ath_print(common, ATH_DBG_FATAL,
964 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700965 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700966 }
967
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400968 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530969 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700970 else
Sujith2660b812009-02-09 13:27:26 +0530971 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700972
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700973 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700974
Luis R. Rodriguez211f5852009-10-06 21:19:07 -0400975 common->state = ATH_HW_INITIALIZED;
976
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700977 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700978}
979
Sujithcbe61d82009-02-09 13:27:12 +0530980static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530981 struct ath9k_channel *chan)
982{
983 u32 synthDelay;
984
985 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +0530986 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +0530987 synthDelay = (4 * synthDelay) / 22;
988 else
989 synthDelay /= 10;
990
991 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
992
993 udelay(synthDelay + BASE_ACTIVATE_DELAY);
994}
995
Sujithcbe61d82009-02-09 13:27:12 +0530996static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530997{
998 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
999 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1000
1001 REG_WRITE(ah, AR_QOS_NO_ACK,
1002 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1003 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1004 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1005
1006 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1007 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1008 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1009 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1010 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1011}
1012
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001013static void ath9k_hw_change_target_baud(struct ath_hw *ah, u32 freq, u32 baud)
1014{
1015 u32 lcr;
1016 u32 baud_divider = freq * 1000 * 1000 / 16 / baud;
1017
1018 lcr = REG_READ(ah , 0x5100c);
1019 lcr |= 0x80;
1020
1021 REG_WRITE(ah, 0x5100c, lcr);
1022 REG_WRITE(ah, 0x51004, (baud_divider >> 8));
1023 REG_WRITE(ah, 0x51000, (baud_divider & 0xff));
1024
1025 lcr &= ~0x80;
1026 REG_WRITE(ah, 0x5100c, lcr);
1027}
1028
Sujithcbe61d82009-02-09 13:27:12 +05301029static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301030 struct ath9k_channel *chan)
1031{
1032 u32 pll;
1033
1034 if (AR_SREV_9100(ah)) {
1035 if (chan && IS_CHAN_5GHZ(chan))
1036 pll = 0x1450;
1037 else
1038 pll = 0x1458;
1039 } else {
1040 if (AR_SREV_9280_10_OR_LATER(ah)) {
1041 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1042
1043 if (chan && IS_CHAN_HALF_RATE(chan))
1044 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1045 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1046 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1047
1048 if (chan && IS_CHAN_5GHZ(chan)) {
1049 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1050
1051
1052 if (AR_SREV_9280_20(ah)) {
1053 if (((chan->channel % 20) == 0)
1054 || ((chan->channel % 10) == 0))
1055 pll = 0x2850;
1056 else
1057 pll = 0x142c;
1058 }
1059 } else {
1060 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1061 }
1062
1063 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1064
1065 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1066
1067 if (chan && IS_CHAN_HALF_RATE(chan))
1068 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1069 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1070 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1071
1072 if (chan && IS_CHAN_5GHZ(chan))
1073 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1074 else
1075 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1076 } else {
1077 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1078
1079 if (chan && IS_CHAN_HALF_RATE(chan))
1080 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1081 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1082 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1083
1084 if (chan && IS_CHAN_5GHZ(chan))
1085 pll |= SM(0xa, AR_RTC_PLL_DIV);
1086 else
1087 pll |= SM(0xb, AR_RTC_PLL_DIV);
1088 }
1089 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001090 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301091
Luis R. Rodriguezc75724d2009-10-19 02:33:34 -04001092 /* Switch the core clock for ar9271 to 117Mhz */
1093 if (AR_SREV_9271(ah)) {
1094 if ((pll == 0x142c) || (pll == 0x2850) ) {
1095 udelay(500);
1096 /* set CLKOBS to output AHB clock */
1097 REG_WRITE(ah, 0x7020, 0xe);
1098 /*
1099 * 0x304: 117Mhz, ahb_ratio: 1x1
1100 * 0x306: 40Mhz, ahb_ratio: 1x1
1101 */
1102 REG_WRITE(ah, 0x50040, 0x304);
1103 /*
1104 * makes adjustments for the baud dividor to keep the
1105 * targetted baud rate based on the used core clock.
1106 */
1107 ath9k_hw_change_target_baud(ah, AR9271_CORE_CLOCK,
1108 AR9271_TARGET_BAUD_RATE);
1109 }
1110 }
1111
Sujithf1dc5602008-10-29 10:16:30 +05301112 udelay(RTC_PLL_SETTLE_DELAY);
1113
1114 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1115}
1116
Sujithcbe61d82009-02-09 13:27:12 +05301117static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301118{
Sujithf1dc5602008-10-29 10:16:30 +05301119 int rx_chainmask, tx_chainmask;
1120
Sujith2660b812009-02-09 13:27:26 +05301121 rx_chainmask = ah->rxchainmask;
1122 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301123
1124 switch (rx_chainmask) {
1125 case 0x5:
1126 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1127 AR_PHY_SWAP_ALT_CHAIN);
1128 case 0x3:
Sujithcb53a152009-11-16 11:40:57 +05301129 if (ah->hw_version.macVersion == AR_SREV_REVISION_5416_10) {
Sujithf1dc5602008-10-29 10:16:30 +05301130 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1131 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1132 break;
1133 }
1134 case 0x1:
1135 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301136 case 0x7:
1137 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1138 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1139 break;
1140 default:
1141 break;
1142 }
1143
1144 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1145 if (tx_chainmask == 0x5) {
1146 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1147 AR_PHY_SWAP_ALT_CHAIN);
1148 }
1149 if (AR_SREV_9100(ah))
1150 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1151 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1152}
1153
Sujithcbe61d82009-02-09 13:27:12 +05301154static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001155 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301156{
Sujith2660b812009-02-09 13:27:26 +05301157 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301158 AR_IMR_TXURN |
1159 AR_IMR_RXERR |
1160 AR_IMR_RXORN |
1161 AR_IMR_BCNMISC;
1162
Sujith0ce024c2009-12-14 14:57:00 +05301163 if (ah->config.rx_intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301164 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301165 else
Sujith2660b812009-02-09 13:27:26 +05301166 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301167
Sujith2660b812009-02-09 13:27:26 +05301168 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301169
Colin McCabed97809d2008-12-01 13:38:55 -08001170 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301171 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301172
Sujith2660b812009-02-09 13:27:26 +05301173 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301174 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1175
1176 if (!AR_SREV_9100(ah)) {
1177 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1178 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1179 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1180 }
1181}
1182
Sujithcbe61d82009-02-09 13:27:12 +05301183static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301184{
Sujithf1dc5602008-10-29 10:16:30 +05301185 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001186 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1187 "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301188 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301189 return false;
1190 } else {
1191 REG_RMW_FIELD(ah, AR_TIME_OUT,
1192 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301193 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301194 return true;
1195 }
1196}
1197
Sujithcbe61d82009-02-09 13:27:12 +05301198static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301199{
Sujithf1dc5602008-10-29 10:16:30 +05301200 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001201 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1202 "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301203 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301204 return false;
1205 } else {
1206 REG_RMW_FIELD(ah, AR_TIME_OUT,
1207 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301208 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301209 return true;
1210 }
1211}
1212
Sujithcbe61d82009-02-09 13:27:12 +05301213static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301214{
Sujithf1dc5602008-10-29 10:16:30 +05301215 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001216 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1217 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301218 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301219 return false;
1220 } else {
1221 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301222 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301223 return true;
1224 }
1225}
1226
Sujithcbe61d82009-02-09 13:27:12 +05301227static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301228{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001229 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1230 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301231
Sujith2660b812009-02-09 13:27:26 +05301232 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301233 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301234 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1235 if (ah->slottime != (u32) -1)
1236 ath9k_hw_setslottime(ah, ah->slottime);
1237 if (ah->acktimeout != (u32) -1)
1238 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1239 if (ah->ctstimeout != (u32) -1)
1240 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1241 if (ah->globaltxtimeout != (u32) -1)
1242 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301243}
1244
Sujithcbe61d82009-02-09 13:27:12 +05301245void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001246{
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001247 struct ath_common *common = ath9k_hw_common(ah);
1248
1249 if (common->state <= ATH_HW_INITIALIZED)
1250 goto free_hw;
1251
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001252 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001253 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001254
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001255 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguez211f5852009-10-06 21:19:07 -04001256
1257free_hw:
Luis R. Rodriguezdc51dd52009-10-19 02:33:39 -04001258 if (!AR_SREV_9280_10_OR_LATER(ah))
1259 ath9k_hw_rf_free_ext_banks(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001260 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001261 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001262}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04001263EXPORT_SYMBOL(ath9k_hw_detach);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001264
Sujithf1dc5602008-10-29 10:16:30 +05301265/*******/
1266/* INI */
1267/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001268
Sujithcbe61d82009-02-09 13:27:12 +05301269static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301270 struct ath9k_channel *chan)
1271{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001272 u32 val;
1273
1274 if (AR_SREV_9271(ah)) {
1275 /*
1276 * Enable spectral scan to solution for issues with stuck
1277 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1278 * AR9271 1.1
1279 */
1280 if (AR_SREV_9271_10(ah)) {
Luis R. Rodriguezec11bb82009-10-27 12:59:36 -04001281 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) |
1282 AR_PHY_SPECTRAL_SCAN_ENABLE;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001283 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1284 }
1285 else if (AR_SREV_9271_11(ah))
1286 /*
1287 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1288 * present on AR9271 1.1
1289 */
1290 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1291 return;
1292 }
1293
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301294 /*
1295 * Set the RX_ABORT and RX_DIS and clear if off only after
1296 * RXE is set for MAC. This prevents frames with corrupted
1297 * descriptor status.
1298 */
1299 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1300
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301301 if (AR_SREV_9280_10_OR_LATER(ah)) {
1302 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1303 (~AR_PCU_MISC_MODE2_HWWAR1);
1304
1305 if (AR_SREV_9287_10_OR_LATER(ah))
1306 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1307
1308 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1309 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301310
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001311 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301312 AR_SREV_9280_10_OR_LATER(ah))
1313 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001314 /*
1315 * Disable BB clock gating
1316 * Necessary to avoid issues on AR5416 2.0
1317 */
Sujithf1dc5602008-10-29 10:16:30 +05301318 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1319}
1320
Sujithcbe61d82009-02-09 13:27:12 +05301321static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301322 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301323 u32 reg, u32 value)
1324{
1325 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001326 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301327
Sujithd535a422009-02-09 13:27:06 +05301328 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301329 case AR9280_DEVID_PCI:
1330 if (reg == 0x7894) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001331 ath_print(common, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301332 "ini VAL: %x EEPROM: %x\n", value,
1333 (pBase->version & 0xff));
1334
1335 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001336 ath_print(common, ATH_DBG_EEPROM,
1337 "PWDCLKIND: %d\n",
1338 pBase->pwdclkind);
Sujithf1dc5602008-10-29 10:16:30 +05301339 value &= ~AR_AN_TOP2_PWDCLKIND;
1340 value |= AR_AN_TOP2_PWDCLKIND &
1341 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1342 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001343 ath_print(common, ATH_DBG_EEPROM,
1344 "PWDCLKIND Earlier Rev\n");
Sujithf1dc5602008-10-29 10:16:30 +05301345 }
1346
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001347 ath_print(common, ATH_DBG_EEPROM,
1348 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001349 }
Sujithf1dc5602008-10-29 10:16:30 +05301350 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001351 }
1352
Sujithf1dc5602008-10-29 10:16:30 +05301353 return value;
1354}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001355
Sujithcbe61d82009-02-09 13:27:12 +05301356static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301357 struct ar5416_eeprom_def *pEepData,
1358 u32 reg, u32 value)
1359{
Sujith2660b812009-02-09 13:27:26 +05301360 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301361 return value;
1362 else
1363 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1364}
1365
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301366static void ath9k_olc_init(struct ath_hw *ah)
1367{
1368 u32 i;
1369
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301370 if (OLC_FOR_AR9287_10_LATER) {
1371 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1372 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1373 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1374 AR9287_AN_TXPC0_TXPCMODE,
1375 AR9287_AN_TXPC0_TXPCMODE_S,
1376 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1377 udelay(100);
1378 } else {
1379 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1380 ah->originalGain[i] =
1381 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1382 AR_PHY_TX_GAIN);
1383 ah->PDADCdelta = 0;
1384 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301385}
1386
Bob Copeland3a702e42009-03-30 22:30:29 -04001387static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1388 struct ath9k_channel *chan)
1389{
1390 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1391
1392 if (IS_CHAN_B(chan))
1393 ctl |= CTL_11B;
1394 else if (IS_CHAN_G(chan))
1395 ctl |= CTL_11G;
1396 else
1397 ctl |= CTL_11A;
1398
1399 return ctl;
1400}
1401
Sujithcbe61d82009-02-09 13:27:12 +05301402static int ath9k_hw_process_ini(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001403 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301404{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001405 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301406 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001407 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301408 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001409
Sujithf1dc5602008-10-29 10:16:30 +05301410 switch (chan->chanmode) {
1411 case CHANNEL_A:
1412 case CHANNEL_A_HT20:
1413 modesIndex = 1;
1414 freqIndex = 1;
1415 break;
1416 case CHANNEL_A_HT40PLUS:
1417 case CHANNEL_A_HT40MINUS:
1418 modesIndex = 2;
1419 freqIndex = 1;
1420 break;
1421 case CHANNEL_G:
1422 case CHANNEL_G_HT20:
1423 case CHANNEL_B:
1424 modesIndex = 4;
1425 freqIndex = 2;
1426 break;
1427 case CHANNEL_G_HT40PLUS:
1428 case CHANNEL_G_HT40MINUS:
1429 modesIndex = 3;
1430 freqIndex = 2;
1431 break;
1432
1433 default:
1434 return -EINVAL;
1435 }
1436
1437 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301438 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301439 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301440
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001441 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301442 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301443 } else {
1444 struct ar5416IniArray temp;
1445 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301446 sizeof(u32) * ah->iniAddac.ia_rows *
1447 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301448
Sujith2660b812009-02-09 13:27:26 +05301449 memcpy(ah->addac5416_21,
1450 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301451
Sujith2660b812009-02-09 13:27:26 +05301452 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301453
Sujith2660b812009-02-09 13:27:26 +05301454 temp.ia_array = ah->addac5416_21;
1455 temp.ia_columns = ah->iniAddac.ia_columns;
1456 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301457 REG_WRITE_ARRAY(&temp, 1, regWrites);
1458 }
1459
1460 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1461
Sujith2660b812009-02-09 13:27:26 +05301462 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1463 u32 reg = INI_RA(&ah->iniModes, i, 0);
1464 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301465
Sujithf1dc5602008-10-29 10:16:30 +05301466 REG_WRITE(ah, reg, val);
1467
1468 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301469 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301470 udelay(100);
1471 }
1472
1473 DO_DELAY(regWrites);
1474 }
1475
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301476 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301477 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301478
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301479 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1480 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301481 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301482
Sujith2660b812009-02-09 13:27:26 +05301483 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1484 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1485 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301486
1487 REG_WRITE(ah, reg, val);
1488
1489 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301490 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301491 udelay(100);
1492 }
1493
1494 DO_DELAY(regWrites);
1495 }
1496
Luis R. Rodriguez896ff262009-10-19 02:33:44 -04001497 ath9k_hw_write_regs(ah, freqIndex, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301498
Luis R. Rodriguez85643282009-10-19 02:33:33 -04001499 if (AR_SREV_9271_10(ah))
1500 REG_WRITE_ARRAY(&ah->iniModes_9271_1_0_only,
1501 modesIndex, regWrites);
1502
Sujithf1dc5602008-10-29 10:16:30 +05301503 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301504 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301505 regWrites);
1506 }
1507
1508 ath9k_hw_override_ini(ah, chan);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001509 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301510 ath9k_hw_init_chain_masks(ah);
1511
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301512 if (OLC_FOR_AR9280_20_LATER)
1513 ath9k_olc_init(ah);
1514
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001515 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001516 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001517 channel->max_antenna_gain * 2,
1518 channel->max_power * 2,
1519 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001520 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001521
Sujithf1dc5602008-10-29 10:16:30 +05301522 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001523 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1524 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001525 return -EIO;
1526 }
1527
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001528 return 0;
1529}
1530
Sujithf1dc5602008-10-29 10:16:30 +05301531/****************************************/
1532/* Reset and Channel Switching Routines */
1533/****************************************/
1534
Sujithcbe61d82009-02-09 13:27:12 +05301535static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301536{
1537 u32 rfMode = 0;
1538
1539 if (chan == NULL)
1540 return;
1541
1542 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1543 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1544
1545 if (!AR_SREV_9280_10_OR_LATER(ah))
1546 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1547 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1548
1549 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1550 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1551
1552 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1553}
1554
Sujithcbe61d82009-02-09 13:27:12 +05301555static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301556{
1557 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1558}
1559
Sujithcbe61d82009-02-09 13:27:12 +05301560static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301561{
1562 u32 regval;
1563
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001564 /*
1565 * set AHB_MODE not to do cacheline prefetches
1566 */
Sujithf1dc5602008-10-29 10:16:30 +05301567 regval = REG_READ(ah, AR_AHB_MODE);
1568 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1569
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001570 /*
1571 * let mac dma reads be in 128 byte chunks
1572 */
Sujithf1dc5602008-10-29 10:16:30 +05301573 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1574 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1575
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001576 /*
1577 * Restore TX Trigger Level to its pre-reset value.
1578 * The initial value depends on whether aggregation is enabled, and is
1579 * adjusted whenever underruns are detected.
1580 */
Sujith2660b812009-02-09 13:27:26 +05301581 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301582
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001583 /*
1584 * let mac dma writes be in 128 byte chunks
1585 */
Sujithf1dc5602008-10-29 10:16:30 +05301586 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1587 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1588
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001589 /*
1590 * Setup receive FIFO threshold to hold off TX activities
1591 */
Sujithf1dc5602008-10-29 10:16:30 +05301592 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1593
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001594 /*
1595 * reduce the number of usable entries in PCU TXBUF to avoid
1596 * wrap around issues.
1597 */
Sujithf1dc5602008-10-29 10:16:30 +05301598 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001599 /* For AR9285 the number of Fifos are reduced to half.
1600 * So set the usable tx buf size also to half to
1601 * avoid data/delimiter underruns
1602 */
Sujithf1dc5602008-10-29 10:16:30 +05301603 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1604 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001605 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301606 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1607 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1608 }
1609}
1610
Sujithcbe61d82009-02-09 13:27:12 +05301611static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301612{
1613 u32 val;
1614
1615 val = REG_READ(ah, AR_STA_ID1);
1616 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1617 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001618 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301619 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1620 | AR_STA_ID1_KSRCH_MODE);
1621 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1622 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001623 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001624 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301625 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1626 | AR_STA_ID1_KSRCH_MODE);
1627 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1628 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001629 case NL80211_IFTYPE_STATION:
1630 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301631 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1632 break;
1633 }
1634}
1635
Sujithcbe61d82009-02-09 13:27:12 +05301636static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001637 u32 coef_scaled,
1638 u32 *coef_mantissa,
1639 u32 *coef_exponent)
1640{
1641 u32 coef_exp, coef_man;
1642
1643 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1644 if ((coef_scaled >> coef_exp) & 0x1)
1645 break;
1646
1647 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1648
1649 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1650
1651 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1652 *coef_exponent = coef_exp - 16;
1653}
1654
Sujithcbe61d82009-02-09 13:27:12 +05301655static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301656 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001657{
1658 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1659 u32 clockMhzScaled = 0x64000000;
1660 struct chan_centers centers;
1661
1662 if (IS_CHAN_HALF_RATE(chan))
1663 clockMhzScaled = clockMhzScaled >> 1;
1664 else if (IS_CHAN_QUARTER_RATE(chan))
1665 clockMhzScaled = clockMhzScaled >> 2;
1666
1667 ath9k_hw_get_channel_centers(ah, chan, &centers);
1668 coef_scaled = clockMhzScaled / centers.synth_center;
1669
1670 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1671 &ds_coef_exp);
1672
1673 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1674 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1675 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1676 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1677
1678 coef_scaled = (9 * coef_scaled) / 10;
1679
1680 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1681 &ds_coef_exp);
1682
1683 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1684 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1685 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1686 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1687}
1688
Sujithcbe61d82009-02-09 13:27:12 +05301689static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301690{
1691 u32 rst_flags;
1692 u32 tmpReg;
1693
Sujith70768492009-02-16 13:23:12 +05301694 if (AR_SREV_9100(ah)) {
1695 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1696 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1697 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1698 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1699 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1700 }
1701
Sujithf1dc5602008-10-29 10:16:30 +05301702 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1703 AR_RTC_FORCE_WAKE_ON_INT);
1704
1705 if (AR_SREV_9100(ah)) {
1706 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1707 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1708 } else {
1709 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1710 if (tmpReg &
1711 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1712 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1713 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1714 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1715 } else {
1716 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1717 }
1718
1719 rst_flags = AR_RTC_RC_MAC_WARM;
1720 if (type == ATH9K_RESET_COLD)
1721 rst_flags |= AR_RTC_RC_MAC_COLD;
1722 }
1723
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001724 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301725 udelay(50);
1726
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001727 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301728 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001729 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1730 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301731 return false;
1732 }
1733
1734 if (!AR_SREV_9100(ah))
1735 REG_WRITE(ah, AR_RC, 0);
1736
Sujithf1dc5602008-10-29 10:16:30 +05301737 if (AR_SREV_9100(ah))
1738 udelay(50);
1739
1740 return true;
1741}
1742
Sujithcbe61d82009-02-09 13:27:12 +05301743static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301744{
1745 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1746 AR_RTC_FORCE_WAKE_ON_INT);
1747
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301748 if (!AR_SREV_9100(ah))
1749 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1750
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001751 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301752 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301753
1754 if (!AR_SREV_9100(ah))
1755 REG_WRITE(ah, AR_RC, 0);
1756
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001757 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301758
1759 if (!ath9k_hw_wait(ah,
1760 AR_RTC_STATUS,
1761 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301762 AR_RTC_STATUS_ON,
1763 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001764 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1765 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301766 return false;
1767 }
1768
1769 ath9k_hw_read_revisions(ah);
1770
1771 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1772}
1773
Sujithcbe61d82009-02-09 13:27:12 +05301774static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301775{
1776 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1777 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1778
1779 switch (type) {
1780 case ATH9K_RESET_POWER_ON:
1781 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301782 case ATH9K_RESET_WARM:
1783 case ATH9K_RESET_COLD:
1784 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301785 default:
1786 return false;
1787 }
1788}
1789
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001790static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301791{
1792 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301793 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301794
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301795 if (AR_SREV_9285_10_OR_LATER(ah))
1796 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1797 AR_PHY_FC_ENABLE_DAC_FIFO);
1798
Sujithf1dc5602008-10-29 10:16:30 +05301799 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301800 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301801
1802 if (IS_CHAN_HT40(chan)) {
1803 phymode |= AR_PHY_FC_DYN2040_EN;
1804
1805 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1806 (chan->chanmode == CHANNEL_G_HT40PLUS))
1807 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1808
Sujithf1dc5602008-10-29 10:16:30 +05301809 }
1810 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1811
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001812 ath9k_hw_set11nmac2040(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301813
1814 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1815 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1816}
1817
Sujithcbe61d82009-02-09 13:27:12 +05301818static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301819 struct ath9k_channel *chan)
1820{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301821 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301822 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1823 return false;
1824 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301825 return false;
1826
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001827 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301828 return false;
1829
Sujith2660b812009-02-09 13:27:26 +05301830 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301831 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301832 ath9k_hw_set_rfmode(ah, chan);
1833
1834 return true;
1835}
1836
Sujithcbe61d82009-02-09 13:27:12 +05301837static bool ath9k_hw_channel_change(struct ath_hw *ah,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001838 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301839{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001840 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001841 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001842 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301843 u32 synthDelay, qnum;
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001844 int r;
Sujithf1dc5602008-10-29 10:16:30 +05301845
1846 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1847 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001848 ath_print(common, ATH_DBG_QUEUE,
1849 "Transmit frames pending on "
1850 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301851 return false;
1852 }
1853 }
1854
1855 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1856 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301857 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001858 ath_print(common, ATH_DBG_FATAL,
1859 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301860 return false;
1861 }
1862
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001863 ath9k_hw_set_regs(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301864
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -04001865 r = ah->ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04001866 if (r) {
1867 ath_print(common, ATH_DBG_FATAL,
1868 "Failed to set channel\n");
1869 return false;
Sujithf1dc5602008-10-29 10:16:30 +05301870 }
1871
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001872 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001873 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301874 channel->max_antenna_gain * 2,
1875 channel->max_power * 2,
1876 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001877 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301878
1879 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301880 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301881 synthDelay = (4 * synthDelay) / 22;
1882 else
1883 synthDelay /= 10;
1884
1885 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1886
1887 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1888
1889 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1890 ath9k_hw_set_delta_slope(ah, chan);
1891
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -04001892 ah->ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301893
1894 if (!chan->oneTimeCalsDone)
1895 chan->oneTimeCalsDone = true;
1896
1897 return true;
1898}
1899
Johannes Berg3b319aa2009-06-13 14:50:26 +05301900static void ath9k_enable_rfkill(struct ath_hw *ah)
1901{
1902 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
1903 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
1904
1905 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
1906 AR_GPIO_INPUT_MUX2_RFSILENT);
1907
1908 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
1909 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
1910}
1911
Sujithcbe61d82009-02-09 13:27:12 +05301912int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001913 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001914{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001915 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001916 u32 saveLedState;
Sujith2660b812009-02-09 13:27:26 +05301917 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001918 u32 saveDefAntenna;
1919 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05301920 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001921 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001922
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001923 ah->txchainmask = common->tx_chainmask;
1924 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001925
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001926 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001927 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001928
Vasanthakumar Thiagarajan9ebef7992009-09-17 09:26:44 +05301929 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001930 ath9k_hw_getnf(ah, curchan);
1931
1932 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05301933 (ah->chip_fullsleep != true) &&
1934 (ah->curchan != NULL) &&
1935 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001936 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05301937 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05301938 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
1939 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001940
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001941 if (ath9k_hw_channel_change(ah, chan)) {
Sujith2660b812009-02-09 13:27:26 +05301942 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001943 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001944 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001945 }
1946 }
1947
1948 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1949 if (saveDefAntenna == 0)
1950 saveDefAntenna = 1;
1951
1952 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1953
Sujith46fe7822009-09-17 09:25:25 +05301954 /* For chips on which RTC reset is done, save TSF before it gets cleared */
1955 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1956 tsf = ath9k_hw_gettsf64(ah);
1957
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001958 saveLedState = REG_READ(ah, AR_CFG_LED) &
1959 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1960 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1961
1962 ath9k_hw_mark_phy_inactive(ah);
1963
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001964 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1965 REG_WRITE(ah,
1966 AR9271_RESET_POWER_DOWN_CONTROL,
1967 AR9271_RADIO_RF_RST);
1968 udelay(50);
1969 }
1970
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001971 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001972 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001973 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001974 }
1975
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001976 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1977 ah->htc_reset_init = false;
1978 REG_WRITE(ah,
1979 AR9271_RESET_POWER_DOWN_CONTROL,
1980 AR9271_GATE_MAC_CTL);
1981 udelay(50);
1982 }
1983
Sujith46fe7822009-09-17 09:25:25 +05301984 /* Restore TSF */
1985 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1986 ath9k_hw_settsf64(ah, tsf);
1987
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05301988 if (AR_SREV_9280_10_OR_LATER(ah))
1989 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001990
Vivek Natarajan326bebb2009-08-14 11:33:36 +05301991 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301992 /* Enable ASYNC FIFO */
1993 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
1994 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
1995 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
1996 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
1997 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
1998 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
1999 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2000 }
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002001 r = ath9k_hw_process_ini(ah, chan);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002002 if (r)
2003 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002004
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002005 /* Setup MFP options for CCMP */
2006 if (AR_SREV_9280_20_OR_LATER(ah)) {
2007 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2008 * frames when constructing CCMP AAD. */
2009 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2010 0xc7ff);
2011 ah->sw_mgmt_crypto = false;
2012 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2013 /* Disable hardware crypto for management frames */
2014 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2015 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2016 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2017 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2018 ah->sw_mgmt_crypto = true;
2019 } else
2020 ah->sw_mgmt_crypto = true;
2021
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002022 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2023 ath9k_hw_set_delta_slope(ah, chan);
2024
Luis R. Rodriguezae478cf2009-10-19 02:33:43 -04002025 ah->ath9k_hw_spur_mitigate_freq(ah, chan);
Sujithd6509152009-03-13 08:56:05 +05302026 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodrigueza7765822009-10-19 02:33:45 -04002027
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002028 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2029 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002030 | macStaId1
2031 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302032 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302033 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302034 | ah->sta_id1_defaults);
2035 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002036
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002037 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002038
2039 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2040
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002041 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002042
2043 REG_WRITE(ah, AR_ISR, ~0);
2044
2045 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2046
Luis R. Rodrigueze68a0602009-10-19 02:33:41 -04002047 r = ah->ath9k_hw_rf_set_freq(ah, chan);
Luis R. Rodriguez0a3b7ba2009-10-19 02:33:40 -04002048 if (r)
2049 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002050
2051 for (i = 0; i < AR_NUM_DCU; i++)
2052 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2053
Sujith2660b812009-02-09 13:27:26 +05302054 ah->intr_txqs = 0;
2055 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002056 ath9k_hw_resettxqueue(ah, i);
2057
Sujith2660b812009-02-09 13:27:26 +05302058 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002059 ath9k_hw_init_qos(ah);
2060
Sujith2660b812009-02-09 13:27:26 +05302061 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302062 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302063
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002064 ath9k_hw_init_user_settings(ah);
2065
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302066 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302067 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2068 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2069 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2070 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2071 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2072 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2073
2074 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2075 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2076
2077 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2078 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2079 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2080 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2081 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302082 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302083 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2084 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2085 }
2086
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002087 REG_WRITE(ah, AR_STA_ID1,
2088 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2089
2090 ath9k_hw_set_dma(ah);
2091
2092 REG_WRITE(ah, AR_OBS, 8);
2093
Sujith0ce024c2009-12-14 14:57:00 +05302094 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002095 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2096 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2097 }
2098
2099 ath9k_hw_init_bb(ah, chan);
2100
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002101 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002102 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002103
Sujith2660b812009-02-09 13:27:26 +05302104 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002105 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2106 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2107 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2108 }
2109
2110 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2111
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002112 /*
2113 * For big endian systems turn on swapping for descriptors
2114 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002115 if (AR_SREV_9100(ah)) {
2116 u32 mask;
2117 mask = REG_READ(ah, AR_CFG);
2118 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002119 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302120 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002121 } else {
2122 mask =
2123 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2124 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002125 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302126 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002127 }
2128 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002129 /* Configure AR9271 target WLAN */
2130 if (AR_SREV_9271(ah))
2131 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002132#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002133 else
2134 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002135#endif
2136 }
2137
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002138 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302139 ath9k_hw_btcoex_enable(ah);
2140
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002141 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002142}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002143EXPORT_SYMBOL(ath9k_hw_reset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002144
Sujithf1dc5602008-10-29 10:16:30 +05302145/************************/
2146/* Key Cache Management */
2147/************************/
2148
Sujithcbe61d82009-02-09 13:27:12 +05302149bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002150{
Sujithf1dc5602008-10-29 10:16:30 +05302151 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002152
Sujith2660b812009-02-09 13:27:26 +05302153 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002154 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2155 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002156 return false;
2157 }
2158
Sujithf1dc5602008-10-29 10:16:30 +05302159 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002160
Sujithf1dc5602008-10-29 10:16:30 +05302161 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2162 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2163 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2164 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2165 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2166 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2167 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2168 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2169
2170 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2171 u16 micentry = entry + 64;
2172
2173 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2174 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2175 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2176 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2177
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002178 }
2179
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002180 return true;
2181}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002182EXPORT_SYMBOL(ath9k_hw_keyreset);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002183
Sujithcbe61d82009-02-09 13:27:12 +05302184bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002185{
Sujithf1dc5602008-10-29 10:16:30 +05302186 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002187
Sujith2660b812009-02-09 13:27:26 +05302188 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002189 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2190 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002191 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002192 }
2193
Sujithf1dc5602008-10-29 10:16:30 +05302194 if (mac != NULL) {
2195 macHi = (mac[5] << 8) | mac[4];
2196 macLo = (mac[3] << 24) |
2197 (mac[2] << 16) |
2198 (mac[1] << 8) |
2199 mac[0];
2200 macLo >>= 1;
2201 macLo |= (macHi & 1) << 31;
2202 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002203 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302204 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002205 }
Sujithf1dc5602008-10-29 10:16:30 +05302206 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2207 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002208
2209 return true;
2210}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002211EXPORT_SYMBOL(ath9k_hw_keysetmac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002212
Sujithcbe61d82009-02-09 13:27:12 +05302213bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302214 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002215 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002216{
Sujith2660b812009-02-09 13:27:26 +05302217 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002218 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302219 u32 key0, key1, key2, key3, key4;
2220 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002221
Sujithf1dc5602008-10-29 10:16:30 +05302222 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002223 ath_print(common, ATH_DBG_FATAL,
2224 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302225 return false;
2226 }
2227
2228 switch (k->kv_type) {
2229 case ATH9K_CIPHER_AES_OCB:
2230 keyType = AR_KEYTABLE_TYPE_AES;
2231 break;
2232 case ATH9K_CIPHER_AES_CCM:
2233 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002234 ath_print(common, ATH_DBG_ANY,
2235 "AES-CCM not supported by mac rev 0x%x\n",
2236 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002237 return false;
2238 }
Sujithf1dc5602008-10-29 10:16:30 +05302239 keyType = AR_KEYTABLE_TYPE_CCM;
2240 break;
2241 case ATH9K_CIPHER_TKIP:
2242 keyType = AR_KEYTABLE_TYPE_TKIP;
2243 if (ATH9K_IS_MIC_ENABLED(ah)
2244 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002245 ath_print(common, ATH_DBG_ANY,
2246 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002247 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002248 }
Sujithf1dc5602008-10-29 10:16:30 +05302249 break;
2250 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002251 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002252 ath_print(common, ATH_DBG_ANY,
2253 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302254 return false;
2255 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002256 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302257 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002258 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302259 keyType = AR_KEYTABLE_TYPE_104;
2260 else
2261 keyType = AR_KEYTABLE_TYPE_128;
2262 break;
2263 case ATH9K_CIPHER_CLR:
2264 keyType = AR_KEYTABLE_TYPE_CLR;
2265 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002266 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002267 ath_print(common, ATH_DBG_FATAL,
2268 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002269 return false;
2270 }
Sujithf1dc5602008-10-29 10:16:30 +05302271
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002272 key0 = get_unaligned_le32(k->kv_val + 0);
2273 key1 = get_unaligned_le16(k->kv_val + 4);
2274 key2 = get_unaligned_le32(k->kv_val + 6);
2275 key3 = get_unaligned_le16(k->kv_val + 10);
2276 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002277 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302278 key4 &= 0xff;
2279
Jouni Malinen672903b2009-03-02 15:06:31 +02002280 /*
2281 * Note: Key cache registers access special memory area that requires
2282 * two 32-bit writes to actually update the values in the internal
2283 * memory. Consequently, the exact order and pairs used here must be
2284 * maintained.
2285 */
2286
Sujithf1dc5602008-10-29 10:16:30 +05302287 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2288 u16 micentry = entry + 64;
2289
Jouni Malinen672903b2009-03-02 15:06:31 +02002290 /*
2291 * Write inverted key[47:0] first to avoid Michael MIC errors
2292 * on frames that could be sent or received at the same time.
2293 * The correct key will be written in the end once everything
2294 * else is ready.
2295 */
Sujithf1dc5602008-10-29 10:16:30 +05302296 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2297 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002298
2299 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302300 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2301 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002302
2303 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302304 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2305 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002306
2307 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302308 (void) ath9k_hw_keysetmac(ah, entry, mac);
2309
Sujith2660b812009-02-09 13:27:26 +05302310 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002311 /*
2312 * TKIP uses two key cache entries:
2313 * Michael MIC TX/RX keys in the same key cache entry
2314 * (idx = main index + 64):
2315 * key0 [31:0] = RX key [31:0]
2316 * key1 [15:0] = TX key [31:16]
2317 * key1 [31:16] = reserved
2318 * key2 [31:0] = RX key [63:32]
2319 * key3 [15:0] = TX key [15:0]
2320 * key3 [31:16] = reserved
2321 * key4 [31:0] = TX key [63:32]
2322 */
Sujithf1dc5602008-10-29 10:16:30 +05302323 u32 mic0, mic1, mic2, mic3, mic4;
2324
2325 mic0 = get_unaligned_le32(k->kv_mic + 0);
2326 mic2 = get_unaligned_le32(k->kv_mic + 4);
2327 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2328 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2329 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002330
2331 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302332 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2333 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002334
2335 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302336 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2337 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002338
2339 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302340 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2341 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2342 AR_KEYTABLE_TYPE_CLR);
2343
2344 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002345 /*
2346 * TKIP uses four key cache entries (two for group
2347 * keys):
2348 * Michael MIC TX/RX keys are in different key cache
2349 * entries (idx = main index + 64 for TX and
2350 * main index + 32 + 96 for RX):
2351 * key0 [31:0] = TX/RX MIC key [31:0]
2352 * key1 [31:0] = reserved
2353 * key2 [31:0] = TX/RX MIC key [63:32]
2354 * key3 [31:0] = reserved
2355 * key4 [31:0] = reserved
2356 *
2357 * Upper layer code will call this function separately
2358 * for TX and RX keys when these registers offsets are
2359 * used.
2360 */
Sujithf1dc5602008-10-29 10:16:30 +05302361 u32 mic0, mic2;
2362
2363 mic0 = get_unaligned_le32(k->kv_mic + 0);
2364 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002365
2366 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302367 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2368 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002369
2370 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302371 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2372 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002373
2374 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302375 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2376 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2377 AR_KEYTABLE_TYPE_CLR);
2378 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002379
2380 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302381 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2382 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002383
2384 /*
2385 * Write the correct (un-inverted) key[47:0] last to enable
2386 * TKIP now that all other registers are set with correct
2387 * values.
2388 */
Sujithf1dc5602008-10-29 10:16:30 +05302389 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2390 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2391 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002392 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302393 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2394 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002395
2396 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302397 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2398 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002399
2400 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302401 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2402 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2403
Jouni Malinen672903b2009-03-02 15:06:31 +02002404 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302405 (void) ath9k_hw_keysetmac(ah, entry, mac);
2406 }
2407
Sujithf1dc5602008-10-29 10:16:30 +05302408 return true;
2409}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002410EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
Sujithf1dc5602008-10-29 10:16:30 +05302411
Sujithcbe61d82009-02-09 13:27:12 +05302412bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302413{
Sujith2660b812009-02-09 13:27:26 +05302414 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302415 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2416 if (val & AR_KEYTABLE_VALID)
2417 return true;
2418 }
2419 return false;
2420}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002421EXPORT_SYMBOL(ath9k_hw_keyisvalid);
Sujithf1dc5602008-10-29 10:16:30 +05302422
2423/******************************/
2424/* Power Management (Chipset) */
2425/******************************/
2426
Sujithcbe61d82009-02-09 13:27:12 +05302427static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302428{
2429 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2430 if (setChip) {
2431 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2432 AR_RTC_FORCE_WAKE_EN);
2433 if (!AR_SREV_9100(ah))
2434 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2435
Sujith4921be82009-09-18 15:04:27 +05302436 if(!AR_SREV_5416(ah))
2437 REG_CLR_BIT(ah, (AR_RTC_RESET),
2438 AR_RTC_RESET_EN);
Sujithf1dc5602008-10-29 10:16:30 +05302439 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002440}
2441
Sujithcbe61d82009-02-09 13:27:12 +05302442static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002443{
Sujithf1dc5602008-10-29 10:16:30 +05302444 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2445 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302446 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002447
Sujithf1dc5602008-10-29 10:16:30 +05302448 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2449 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2450 AR_RTC_FORCE_WAKE_ON_INT);
2451 } else {
2452 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2453 AR_RTC_FORCE_WAKE_EN);
2454 }
2455 }
2456}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002457
Sujithcbe61d82009-02-09 13:27:12 +05302458static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302459{
2460 u32 val;
2461 int i;
2462
2463 if (setChip) {
2464 if ((REG_READ(ah, AR_RTC_STATUS) &
2465 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2466 if (ath9k_hw_set_reset_reg(ah,
2467 ATH9K_RESET_POWER_ON) != true) {
2468 return false;
2469 }
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05302470 ath9k_hw_init_pll(ah, NULL);
Sujithf1dc5602008-10-29 10:16:30 +05302471 }
2472 if (AR_SREV_9100(ah))
2473 REG_SET_BIT(ah, AR_RTC_RESET,
2474 AR_RTC_RESET_EN);
2475
2476 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2477 AR_RTC_FORCE_WAKE_EN);
2478 udelay(50);
2479
2480 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2481 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2482 if (val == AR_RTC_STATUS_ON)
2483 break;
2484 udelay(50);
2485 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2486 AR_RTC_FORCE_WAKE_EN);
2487 }
2488 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002489 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2490 "Failed to wakeup in %uus\n",
2491 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302492 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002493 }
2494 }
2495
Sujithf1dc5602008-10-29 10:16:30 +05302496 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2497
2498 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002499}
2500
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002501bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302502{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002503 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302504 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302505 static const char *modes[] = {
2506 "AWAKE",
2507 "FULL-SLEEP",
2508 "NETWORK SLEEP",
2509 "UNDEFINED"
2510 };
Sujithf1dc5602008-10-29 10:16:30 +05302511
Gabor Juhoscbdec972009-07-24 17:27:22 +02002512 if (ah->power_mode == mode)
2513 return status;
2514
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002515 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2516 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302517
2518 switch (mode) {
2519 case ATH9K_PM_AWAKE:
2520 status = ath9k_hw_set_power_awake(ah, setChip);
2521 break;
2522 case ATH9K_PM_FULL_SLEEP:
2523 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302524 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302525 break;
2526 case ATH9K_PM_NETWORK_SLEEP:
2527 ath9k_set_power_network_sleep(ah, setChip);
2528 break;
2529 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002530 ath_print(common, ATH_DBG_FATAL,
2531 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302532 return false;
2533 }
Sujith2660b812009-02-09 13:27:26 +05302534 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302535
2536 return status;
2537}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002538EXPORT_SYMBOL(ath9k_hw_setpower);
Sujithf1dc5602008-10-29 10:16:30 +05302539
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002540/*
2541 * Helper for ASPM support.
2542 *
2543 * Disable PLL when in L0s as well as receiver clock when in L1.
2544 * This power saving option must be enabled through the SerDes.
2545 *
2546 * Programming the SerDes must go through the same 288 bit serial shift
2547 * register as the other analog registers. Hence the 9 writes.
2548 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302549void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302550{
Sujithf1dc5602008-10-29 10:16:30 +05302551 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302552 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302553
Sujith2660b812009-02-09 13:27:26 +05302554 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302555 return;
2556
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002557 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302558 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302559 return;
2560
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002561 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302562 if (!restore) {
2563 if (AR_SREV_9280_20_OR_LATER(ah)) {
2564 /*
2565 * AR9280 2.0 or later chips use SerDes values from the
2566 * initvals.h initialized depending on chipset during
2567 * ath9k_hw_init()
2568 */
2569 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2570 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2571 INI_RA(&ah->iniPcieSerdes, i, 1));
2572 }
2573 } else if (AR_SREV_9280(ah) &&
2574 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2575 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2576 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302577
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302578 /* RX shut off when elecidle is asserted */
2579 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2580 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2581 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2582
2583 /* Shut off CLKREQ active in L1 */
2584 if (ah->config.pcie_clock_req)
2585 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2586 else
2587 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2588
2589 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2590 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2591 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2592
2593 /* Load the new settings */
2594 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2595
2596 } else {
2597 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2598 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2599
2600 /* RX shut off when elecidle is asserted */
2601 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
2602 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
2603 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
2604
2605 /*
2606 * Ignore ah->ah_config.pcie_clock_req setting for
2607 * pre-AR9280 11n
2608 */
2609 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
2610
2611 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2612 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2613 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
2614
2615 /* Load the new settings */
2616 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05302617 }
Sujithf1dc5602008-10-29 10:16:30 +05302618
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302619 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05302620
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302621 /* set bit 19 to allow forcing of pcie core into L1 state */
2622 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05302623
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302624 /* Several PCIe massages to ensure proper behaviour */
2625 if (ah->config.pcie_waen) {
2626 val = ah->config.pcie_waen;
2627 if (!power_off)
2628 val &= (~AR_WA_D3_L1_DISABLE);
2629 } else {
2630 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2631 AR_SREV_9287(ah)) {
2632 val = AR9285_WA_DEFAULT;
2633 if (!power_off)
2634 val &= (~AR_WA_D3_L1_DISABLE);
2635 } else if (AR_SREV_9280(ah)) {
2636 /*
2637 * On AR9280 chips bit 22 of 0x4004 needs to be
2638 * set otherwise card may disappear.
2639 */
2640 val = AR9280_WA_DEFAULT;
2641 if (!power_off)
2642 val &= (~AR_WA_D3_L1_DISABLE);
2643 } else
2644 val = AR_WA_DEFAULT;
2645 }
Sujithf1dc5602008-10-29 10:16:30 +05302646
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302647 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05302648 }
2649
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302650 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002651 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302652 * Set PCIe workaround bits
2653 * bit 14 in WA register (disable L1) should only
2654 * be set when device enters D3 and be cleared
2655 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002656 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302657 if (ah->config.pcie_waen) {
2658 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
2659 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2660 } else {
2661 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
2662 AR_SREV_9287(ah)) &&
2663 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
2664 (AR_SREV_9280(ah) &&
2665 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
2666 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
2667 }
2668 }
Sujithf1dc5602008-10-29 10:16:30 +05302669 }
2670}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002671EXPORT_SYMBOL(ath9k_hw_configpcipowersave);
Sujithf1dc5602008-10-29 10:16:30 +05302672
2673/**********************/
2674/* Interrupt Handling */
2675/**********************/
2676
Sujithcbe61d82009-02-09 13:27:12 +05302677bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002678{
2679 u32 host_isr;
2680
2681 if (AR_SREV_9100(ah))
2682 return true;
2683
2684 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
2685 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
2686 return true;
2687
2688 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
2689 if ((host_isr & AR_INTR_SYNC_DEFAULT)
2690 && (host_isr != AR_INTR_SPURIOUS))
2691 return true;
2692
2693 return false;
2694}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002695EXPORT_SYMBOL(ath9k_hw_intrpend);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002696
Sujithcbe61d82009-02-09 13:27:12 +05302697bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002698{
2699 u32 isr = 0;
2700 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05302701 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002702 u32 sync_cause = 0;
2703 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002704 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002705
2706 if (!AR_SREV_9100(ah)) {
2707 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
2708 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
2709 == AR_RTC_STATUS_ON) {
2710 isr = REG_READ(ah, AR_ISR);
2711 }
2712 }
2713
Sujithf1dc5602008-10-29 10:16:30 +05302714 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
2715 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002716
2717 *masked = 0;
2718
2719 if (!isr && !sync_cause)
2720 return false;
2721 } else {
2722 *masked = 0;
2723 isr = REG_READ(ah, AR_ISR);
2724 }
2725
2726 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002727 if (isr & AR_ISR_BCNMISC) {
2728 u32 isr2;
2729 isr2 = REG_READ(ah, AR_ISR_S2);
2730 if (isr2 & AR_ISR_S2_TIM)
2731 mask2 |= ATH9K_INT_TIM;
2732 if (isr2 & AR_ISR_S2_DTIM)
2733 mask2 |= ATH9K_INT_DTIM;
2734 if (isr2 & AR_ISR_S2_DTIMSYNC)
2735 mask2 |= ATH9K_INT_DTIMSYNC;
2736 if (isr2 & (AR_ISR_S2_CABEND))
2737 mask2 |= ATH9K_INT_CABEND;
2738 if (isr2 & AR_ISR_S2_GTT)
2739 mask2 |= ATH9K_INT_GTT;
2740 if (isr2 & AR_ISR_S2_CST)
2741 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05302742 if (isr2 & AR_ISR_S2_TSFOOR)
2743 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002744 }
2745
2746 isr = REG_READ(ah, AR_ISR_RAC);
2747 if (isr == 0xffffffff) {
2748 *masked = 0;
2749 return false;
2750 }
2751
2752 *masked = isr & ATH9K_INT_COMMON;
2753
Sujith0ce024c2009-12-14 14:57:00 +05302754 if (ah->config.rx_intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002755 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2756 *masked |= ATH9K_INT_RX;
2757 }
2758
2759 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
2760 *masked |= ATH9K_INT_RX;
2761 if (isr &
2762 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
2763 AR_ISR_TXEOL)) {
2764 u32 s0_s, s1_s;
2765
2766 *masked |= ATH9K_INT_TX;
2767
2768 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05302769 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
2770 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002771
2772 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05302773 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
2774 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002775 }
2776
2777 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002778 ath_print(common, ATH_DBG_INTERRUPT,
2779 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002780 }
2781
2782 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05302783 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002784 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
2785 if (isr5 & AR_ISR_S5_TIM_TIMER)
2786 *masked |= ATH9K_INT_TIM_TIMER;
2787 }
2788 }
2789
2790 *masked |= mask2;
2791 }
Sujithf1dc5602008-10-29 10:16:30 +05302792
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002793 if (AR_SREV_9100(ah))
2794 return true;
Sujithf1dc5602008-10-29 10:16:30 +05302795
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05302796 if (isr & AR_ISR_GENTMR) {
2797 u32 s5_s;
2798
2799 s5_s = REG_READ(ah, AR_ISR_S5_S);
2800 if (isr & AR_ISR_GENTMR) {
2801 ah->intr_gen_timer_trigger =
2802 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
2803
2804 ah->intr_gen_timer_thresh =
2805 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
2806
2807 if (ah->intr_gen_timer_trigger)
2808 *masked |= ATH9K_INT_GENTIMER;
2809
2810 }
2811 }
2812
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002813 if (sync_cause) {
2814 fatal_int =
2815 (sync_cause &
2816 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
2817 ? true : false;
2818
2819 if (fatal_int) {
2820 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002821 ath_print(common, ATH_DBG_ANY,
2822 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002823 }
2824 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002825 ath_print(common, ATH_DBG_ANY,
2826 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002827 }
Steven Luoa89bff92009-04-12 02:57:54 -07002828 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002829 }
2830 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002831 ath_print(common, ATH_DBG_INTERRUPT,
2832 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002833 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
2834 REG_WRITE(ah, AR_RC, 0);
2835 *masked |= ATH9K_INT_FATAL;
2836 }
2837 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002838 ath_print(common, ATH_DBG_INTERRUPT,
2839 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002840 }
2841
2842 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
2843 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
2844 }
Sujithf1dc5602008-10-29 10:16:30 +05302845
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002846 return true;
2847}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002848EXPORT_SYMBOL(ath9k_hw_getisr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002849
Sujithcbe61d82009-02-09 13:27:12 +05302850enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002851{
Sujith2660b812009-02-09 13:27:26 +05302852 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002853 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05302854 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002855 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002856
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002857 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002858
2859 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002860 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002861 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
2862 (void) REG_READ(ah, AR_IER);
2863 if (!AR_SREV_9100(ah)) {
2864 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
2865 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
2866
2867 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
2868 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
2869 }
2870 }
2871
2872 mask = ints & ATH9K_INT_COMMON;
2873 mask2 = 0;
2874
2875 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05302876 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002877 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05302878 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002879 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05302880 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002881 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05302882 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002883 mask |= AR_IMR_TXEOL;
2884 }
2885 if (ints & ATH9K_INT_RX) {
2886 mask |= AR_IMR_RXERR;
Sujith0ce024c2009-12-14 14:57:00 +05302887 if (ah->config.rx_intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002888 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
2889 else
2890 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05302891 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002892 mask |= AR_IMR_GENTMR;
2893 }
2894
2895 if (ints & (ATH9K_INT_BMISC)) {
2896 mask |= AR_IMR_BCNMISC;
2897 if (ints & ATH9K_INT_TIM)
2898 mask2 |= AR_IMR_S2_TIM;
2899 if (ints & ATH9K_INT_DTIM)
2900 mask2 |= AR_IMR_S2_DTIM;
2901 if (ints & ATH9K_INT_DTIMSYNC)
2902 mask2 |= AR_IMR_S2_DTIMSYNC;
2903 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05302904 mask2 |= AR_IMR_S2_CABEND;
2905 if (ints & ATH9K_INT_TSFOOR)
2906 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002907 }
2908
2909 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
2910 mask |= AR_IMR_BCNMISC;
2911 if (ints & ATH9K_INT_GTT)
2912 mask2 |= AR_IMR_S2_GTT;
2913 if (ints & ATH9K_INT_CST)
2914 mask2 |= AR_IMR_S2_CST;
2915 }
2916
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002917 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002918 REG_WRITE(ah, AR_IMR, mask);
2919 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
2920 AR_IMR_S2_DTIM |
2921 AR_IMR_S2_DTIMSYNC |
2922 AR_IMR_S2_CABEND |
2923 AR_IMR_S2_CABTO |
2924 AR_IMR_S2_TSFOOR |
2925 AR_IMR_S2_GTT | AR_IMR_S2_CST);
2926 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05302927 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002928
Sujith60b67f52008-08-07 10:52:38 +05302929 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002930 if (ints & ATH9K_INT_TIM_TIMER)
2931 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2932 else
2933 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
2934 }
2935
2936 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002937 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002938 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
2939 if (!AR_SREV_9100(ah)) {
2940 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
2941 AR_INTR_MAC_IRQ);
2942 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
2943
2944
2945 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
2946 AR_INTR_SYNC_DEFAULT);
2947 REG_WRITE(ah, AR_INTR_SYNC_MASK,
2948 AR_INTR_SYNC_DEFAULT);
2949 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002950 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
2951 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002952 }
2953
2954 return omask;
2955}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04002956EXPORT_SYMBOL(ath9k_hw_set_interrupts);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002957
Sujithf1dc5602008-10-29 10:16:30 +05302958/*******************/
2959/* Beacon Handling */
2960/*******************/
2961
Sujithcbe61d82009-02-09 13:27:12 +05302962void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002963{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002964 int flags = 0;
2965
Sujith2660b812009-02-09 13:27:26 +05302966 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002967
Sujith2660b812009-02-09 13:27:26 +05302968 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08002969 case NL80211_IFTYPE_STATION:
2970 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002971 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2972 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
2973 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
2974 flags |= AR_TBTT_TIMER_EN;
2975 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002976 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002977 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002978 REG_SET_BIT(ah, AR_TXCFG,
2979 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2980 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
2981 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05302982 (ah->atim_window ? ah->
2983 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002984 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08002985 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002986 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
2987 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
2988 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302989 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302990 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002991 REG_WRITE(ah, AR_NEXT_SWBA,
2992 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05302993 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302994 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002995 flags |=
2996 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2997 break;
Colin McCabed97809d2008-12-01 13:38:55 -08002998 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002999 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
3000 "%s: unsupported opmode: %d\n",
3001 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003002 return;
3003 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003004 }
3005
3006 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3007 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3008 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3009 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3010
3011 beacon_period &= ~ATH9K_BEACON_ENA;
3012 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003013 ath9k_hw_reset_tsf(ah);
3014 }
3015
3016 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3017}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003018EXPORT_SYMBOL(ath9k_hw_beaconinit);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003019
Sujithcbe61d82009-02-09 13:27:12 +05303020void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303021 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003022{
3023 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303024 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003025 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003026
3027 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3028
3029 REG_WRITE(ah, AR_BEACON_PERIOD,
3030 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3031 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3032 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3033
3034 REG_RMW_FIELD(ah, AR_RSSI_THR,
3035 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3036
3037 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3038
3039 if (bs->bs_sleepduration > beaconintval)
3040 beaconintval = bs->bs_sleepduration;
3041
3042 dtimperiod = bs->bs_dtimperiod;
3043 if (bs->bs_sleepduration > dtimperiod)
3044 dtimperiod = bs->bs_sleepduration;
3045
3046 if (beaconintval == dtimperiod)
3047 nextTbtt = bs->bs_nextdtim;
3048 else
3049 nextTbtt = bs->bs_nexttbtt;
3050
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003051 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3052 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3053 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3054 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003055
3056 REG_WRITE(ah, AR_NEXT_DTIM,
3057 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3058 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3059
3060 REG_WRITE(ah, AR_SLEEP1,
3061 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3062 | AR_SLEEP1_ASSUME_DTIM);
3063
Sujith60b67f52008-08-07 10:52:38 +05303064 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003065 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3066 else
3067 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3068
3069 REG_WRITE(ah, AR_SLEEP2,
3070 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3071
3072 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3073 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3074
3075 REG_SET_BIT(ah, AR_TIMER_MODE,
3076 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3077 AR_DTIM_TIMER_EN);
3078
Sujith4af9cf42009-02-12 10:06:47 +05303079 /* TSF Out of Range Threshold */
3080 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003081}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003082EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003083
Sujithf1dc5602008-10-29 10:16:30 +05303084/*******************/
3085/* HW Capabilities */
3086/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003087
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01003088int ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003089{
Sujith2660b812009-02-09 13:27:26 +05303090 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003091 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003092 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003093 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003094
Sujithf1dc5602008-10-29 10:16:30 +05303095 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003096
Sujithf74df6f2009-02-09 13:27:24 +05303097 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003098 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303099
Sujithf74df6f2009-02-09 13:27:24 +05303100 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303101 if (AR_SREV_9285_10_OR_LATER(ah))
3102 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003103 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303104
Sujithf74df6f2009-02-09 13:27:24 +05303105 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303106
Sujith2660b812009-02-09 13:27:26 +05303107 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303108 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003109 if (regulatory->current_rd == 0x64 ||
3110 regulatory->current_rd == 0x65)
3111 regulatory->current_rd += 5;
3112 else if (regulatory->current_rd == 0x41)
3113 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003114 ath_print(common, ATH_DBG_REGULATORY,
3115 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003116 }
Sujithdc2222a2008-08-14 13:26:55 +05303117
Sujithf74df6f2009-02-09 13:27:24 +05303118 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01003119 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
3120 ath_print(common, ATH_DBG_FATAL,
3121 "no band has been marked as supported in EEPROM.\n");
3122 return -EINVAL;
3123 }
3124
Sujithf1dc5602008-10-29 10:16:30 +05303125 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003126
Sujithf1dc5602008-10-29 10:16:30 +05303127 if (eeval & AR5416_OPFLAGS_11A) {
3128 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303129 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303130 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3131 set_bit(ATH9K_MODE_11NA_HT20,
3132 pCap->wireless_modes);
3133 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3134 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3135 pCap->wireless_modes);
3136 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3137 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003138 }
3139 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003140 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003141
Sujithf1dc5602008-10-29 10:16:30 +05303142 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303143 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303144 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303145 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3146 set_bit(ATH9K_MODE_11NG_HT20,
3147 pCap->wireless_modes);
3148 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3149 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3150 pCap->wireless_modes);
3151 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3152 pCap->wireless_modes);
3153 }
3154 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003155 }
Sujithf1dc5602008-10-29 10:16:30 +05303156
Sujithf74df6f2009-02-09 13:27:24 +05303157 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003158 /*
3159 * For AR9271 we will temporarilly uses the rx chainmax as read from
3160 * the EEPROM.
3161 */
Sujith8147f5d2009-02-20 15:13:23 +05303162 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003163 !(eeval & AR5416_OPFLAGS_11A) &&
3164 !(AR_SREV_9271(ah)))
3165 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303166 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3167 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003168 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303169 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303170
Sujithd535a422009-02-09 13:27:06 +05303171 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303172 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303173
3174 pCap->low_2ghz_chan = 2312;
3175 pCap->high_2ghz_chan = 2732;
3176
3177 pCap->low_5ghz_chan = 4920;
3178 pCap->high_5ghz_chan = 6100;
3179
3180 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3181 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3182 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3183
3184 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3185 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3186 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3187
Sujith2660b812009-02-09 13:27:26 +05303188 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303189 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3190 else
3191 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3192
3193 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3194 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3195 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3196 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3197
3198 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3199 pCap->total_queues =
3200 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3201 else
3202 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3203
3204 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3205 pCap->keycache_size =
3206 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3207 else
3208 pCap->keycache_size = AR_KEYTABLE_SIZE;
3209
3210 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Luis R. Rodriguezf4709fd2009-11-24 21:37:57 -05003211
3212 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
3213 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
3214 else
3215 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
Sujithf1dc5602008-10-29 10:16:30 +05303216
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303217 if (AR_SREV_9285_10_OR_LATER(ah))
3218 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3219 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303220 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3221 else
3222 pCap->num_gpio_pins = AR_NUM_GPIO;
3223
Sujithf1dc5602008-10-29 10:16:30 +05303224 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3225 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3226 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3227 } else {
3228 pCap->rts_aggr_limit = (8 * 1024);
3229 }
3230
3231 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3232
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303233#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303234 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3235 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3236 ah->rfkill_gpio =
3237 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3238 ah->rfkill_polarity =
3239 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303240
3241 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3242 }
3243#endif
3244
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303245 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303246
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303247 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303248 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3249 else
3250 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3251
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003252 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303253 pCap->reg_cap =
3254 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3255 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3256 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3257 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3258 } else {
3259 pCap->reg_cap =
3260 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3261 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3262 }
3263
Senthil Balasubramanianebb90cf2009-09-18 15:07:33 +05303264 /* Advertise midband for AR5416 with FCC midband set in eeprom */
3265 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
3266 AR_SREV_5416(ah))
3267 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
Sujithf1dc5602008-10-29 10:16:30 +05303268
3269 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303270 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303271 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303272 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303273
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303274 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003275 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003276 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3277 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303278
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303279 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003280 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3281 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303282 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003283 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303284 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303285 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003286 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303287 }
Gabor Juhosa9a29ce2009-11-27 12:01:35 +01003288
3289 return 0;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003290}
3291
Sujithcbe61d82009-02-09 13:27:12 +05303292bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303293 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003294{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003295 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303296 switch (type) {
3297 case ATH9K_CAP_CIPHER:
3298 switch (capability) {
3299 case ATH9K_CIPHER_AES_CCM:
3300 case ATH9K_CIPHER_AES_OCB:
3301 case ATH9K_CIPHER_TKIP:
3302 case ATH9K_CIPHER_WEP:
3303 case ATH9K_CIPHER_MIC:
3304 case ATH9K_CIPHER_CLR:
3305 return true;
3306 default:
3307 return false;
3308 }
3309 case ATH9K_CAP_TKIP_MIC:
3310 switch (capability) {
3311 case 0:
3312 return true;
3313 case 1:
Sujith2660b812009-02-09 13:27:26 +05303314 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303315 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3316 false;
3317 }
3318 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303319 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303320 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303321 case ATH9K_CAP_DIVERSITY:
3322 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3323 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3324 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303325 case ATH9K_CAP_MCAST_KEYSRCH:
3326 switch (capability) {
3327 case 0:
3328 return true;
3329 case 1:
3330 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3331 return false;
3332 } else {
Sujith2660b812009-02-09 13:27:26 +05303333 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303334 AR_STA_ID1_MCAST_KSRCH) ? true :
3335 false;
3336 }
3337 }
3338 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303339 case ATH9K_CAP_TXPOW:
3340 switch (capability) {
3341 case 0:
3342 return 0;
3343 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003344 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303345 return 0;
3346 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003347 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303348 return 0;
3349 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003350 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303351 return 0;
3352 }
3353 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303354 case ATH9K_CAP_DS:
3355 return (AR_SREV_9280_20_OR_LATER(ah) &&
3356 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3357 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303358 default:
3359 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003360 }
Sujithf1dc5602008-10-29 10:16:30 +05303361}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003362EXPORT_SYMBOL(ath9k_hw_getcapability);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003363
Sujithcbe61d82009-02-09 13:27:12 +05303364bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303365 u32 capability, u32 setting, int *status)
3366{
Sujithf1dc5602008-10-29 10:16:30 +05303367 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003368
Sujithf1dc5602008-10-29 10:16:30 +05303369 switch (type) {
3370 case ATH9K_CAP_TKIP_MIC:
3371 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303372 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303373 AR_STA_ID1_CRPT_MIC_ENABLE;
3374 else
Sujith2660b812009-02-09 13:27:26 +05303375 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303376 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3377 return true;
3378 case ATH9K_CAP_DIVERSITY:
3379 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3380 if (setting)
3381 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3382 else
3383 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3384 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3385 return true;
3386 case ATH9K_CAP_MCAST_KEYSRCH:
3387 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303388 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303389 else
Sujith2660b812009-02-09 13:27:26 +05303390 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303391 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303392 default:
3393 return false;
3394 }
3395}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003396EXPORT_SYMBOL(ath9k_hw_setcapability);
Sujithf1dc5602008-10-29 10:16:30 +05303397
3398/****************************/
3399/* GPIO / RFKILL / Antennae */
3400/****************************/
3401
Sujithcbe61d82009-02-09 13:27:12 +05303402static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303403 u32 gpio, u32 type)
3404{
3405 int addr;
3406 u32 gpio_shift, tmp;
3407
3408 if (gpio > 11)
3409 addr = AR_GPIO_OUTPUT_MUX3;
3410 else if (gpio > 5)
3411 addr = AR_GPIO_OUTPUT_MUX2;
3412 else
3413 addr = AR_GPIO_OUTPUT_MUX1;
3414
3415 gpio_shift = (gpio % 6) * 5;
3416
3417 if (AR_SREV_9280_20_OR_LATER(ah)
3418 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3419 REG_RMW(ah, addr, (type << gpio_shift),
3420 (0x1f << gpio_shift));
3421 } else {
3422 tmp = REG_READ(ah, addr);
3423 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3424 tmp &= ~(0x1f << gpio_shift);
3425 tmp |= (type << gpio_shift);
3426 REG_WRITE(ah, addr, tmp);
3427 }
3428}
3429
Sujithcbe61d82009-02-09 13:27:12 +05303430void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303431{
3432 u32 gpio_shift;
3433
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07003434 BUG_ON(gpio >= ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303435
3436 gpio_shift = gpio << 1;
3437
3438 REG_RMW(ah,
3439 AR_GPIO_OE_OUT,
3440 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3441 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3442}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003443EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
Sujithf1dc5602008-10-29 10:16:30 +05303444
Sujithcbe61d82009-02-09 13:27:12 +05303445u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303446{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303447#define MS_REG_READ(x, y) \
3448 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3449
Sujith2660b812009-02-09 13:27:26 +05303450 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303451 return 0xffffffff;
3452
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303453 if (AR_SREV_9287_10_OR_LATER(ah))
3454 return MS_REG_READ(AR9287, gpio) != 0;
3455 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303456 return MS_REG_READ(AR9285, gpio) != 0;
3457 else if (AR_SREV_9280_10_OR_LATER(ah))
3458 return MS_REG_READ(AR928X, gpio) != 0;
3459 else
3460 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303461}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003462EXPORT_SYMBOL(ath9k_hw_gpio_get);
Sujithf1dc5602008-10-29 10:16:30 +05303463
Sujithcbe61d82009-02-09 13:27:12 +05303464void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303465 u32 ah_signal_type)
3466{
3467 u32 gpio_shift;
3468
3469 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3470
3471 gpio_shift = 2 * gpio;
3472
3473 REG_RMW(ah,
3474 AR_GPIO_OE_OUT,
3475 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3476 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3477}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003478EXPORT_SYMBOL(ath9k_hw_cfg_output);
Sujithf1dc5602008-10-29 10:16:30 +05303479
Sujithcbe61d82009-02-09 13:27:12 +05303480void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303481{
3482 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3483 AR_GPIO_BIT(gpio));
3484}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003485EXPORT_SYMBOL(ath9k_hw_set_gpio);
Sujithf1dc5602008-10-29 10:16:30 +05303486
Sujithcbe61d82009-02-09 13:27:12 +05303487u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303488{
3489 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3490}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003491EXPORT_SYMBOL(ath9k_hw_getdefantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303492
Sujithcbe61d82009-02-09 13:27:12 +05303493void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303494{
3495 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3496}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003497EXPORT_SYMBOL(ath9k_hw_setantenna);
Sujithf1dc5602008-10-29 10:16:30 +05303498
Sujithf1dc5602008-10-29 10:16:30 +05303499/*********************/
3500/* General Operation */
3501/*********************/
3502
Sujithcbe61d82009-02-09 13:27:12 +05303503u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303504{
3505 u32 bits = REG_READ(ah, AR_RX_FILTER);
3506 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3507
3508 if (phybits & AR_PHY_ERR_RADAR)
3509 bits |= ATH9K_RX_FILTER_PHYRADAR;
3510 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3511 bits |= ATH9K_RX_FILTER_PHYERR;
3512
3513 return bits;
3514}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003515EXPORT_SYMBOL(ath9k_hw_getrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303516
Sujithcbe61d82009-02-09 13:27:12 +05303517void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303518{
3519 u32 phybits;
3520
Sujith7ea310b2009-09-03 12:08:43 +05303521 REG_WRITE(ah, AR_RX_FILTER, bits);
3522
Sujithf1dc5602008-10-29 10:16:30 +05303523 phybits = 0;
3524 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3525 phybits |= AR_PHY_ERR_RADAR;
3526 if (bits & ATH9K_RX_FILTER_PHYERR)
3527 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3528 REG_WRITE(ah, AR_PHY_ERR, phybits);
3529
3530 if (phybits)
3531 REG_WRITE(ah, AR_RXCFG,
3532 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3533 else
3534 REG_WRITE(ah, AR_RXCFG,
3535 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3536}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003537EXPORT_SYMBOL(ath9k_hw_setrxfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303538
Sujithcbe61d82009-02-09 13:27:12 +05303539bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303540{
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303541 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
3542 return false;
3543
3544 ath9k_hw_init_pll(ah, NULL);
3545 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303546}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003547EXPORT_SYMBOL(ath9k_hw_phy_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303548
Sujithcbe61d82009-02-09 13:27:12 +05303549bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303550{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003551 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303552 return false;
3553
Senthil Balasubramanian63a75b92009-09-18 15:07:03 +05303554 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
3555 return false;
3556
3557 ath9k_hw_init_pll(ah, NULL);
3558 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303559}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003560EXPORT_SYMBOL(ath9k_hw_disable);
Sujithf1dc5602008-10-29 10:16:30 +05303561
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003562void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303563{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003564 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303565 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003566 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303567
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003568 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303569
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003570 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003571 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003572 channel->max_antenna_gain * 2,
3573 channel->max_power * 2,
3574 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003575 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303576}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003577EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
Sujithf1dc5602008-10-29 10:16:30 +05303578
Sujithcbe61d82009-02-09 13:27:12 +05303579void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303580{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003581 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303582}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003583EXPORT_SYMBOL(ath9k_hw_setmac);
Sujithf1dc5602008-10-29 10:16:30 +05303584
Sujithcbe61d82009-02-09 13:27:12 +05303585void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303586{
Sujith2660b812009-02-09 13:27:26 +05303587 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303588}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003589EXPORT_SYMBOL(ath9k_hw_setopmode);
Sujithf1dc5602008-10-29 10:16:30 +05303590
Sujithcbe61d82009-02-09 13:27:12 +05303591void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303592{
3593 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3594 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3595}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003596EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
Sujithf1dc5602008-10-29 10:16:30 +05303597
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003598void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303599{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003600 struct ath_common *common = ath9k_hw_common(ah);
3601
3602 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3603 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3604 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05303605}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003606EXPORT_SYMBOL(ath9k_hw_write_associd);
Sujithf1dc5602008-10-29 10:16:30 +05303607
Sujithcbe61d82009-02-09 13:27:12 +05303608u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303609{
3610 u64 tsf;
3611
3612 tsf = REG_READ(ah, AR_TSF_U32);
3613 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
3614
3615 return tsf;
3616}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003617EXPORT_SYMBOL(ath9k_hw_gettsf64);
Sujithf1dc5602008-10-29 10:16:30 +05303618
Sujithcbe61d82009-02-09 13:27:12 +05303619void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003620{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003621 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01003622 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003623}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003624EXPORT_SYMBOL(ath9k_hw_settsf64);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01003625
Sujithcbe61d82009-02-09 13:27:12 +05303626void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303627{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003628 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
3629 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003630 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3631 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02003632
Sujithf1dc5602008-10-29 10:16:30 +05303633 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003634}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003635EXPORT_SYMBOL(ath9k_hw_reset_tsf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003636
Sujith54e4cec2009-08-07 09:45:09 +05303637void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003638{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003639 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303640 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003641 else
Sujith2660b812009-02-09 13:27:26 +05303642 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003643}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003644EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003645
Luis R. Rodriguez30cbd422009-11-03 16:10:46 -08003646/*
3647 * Extend 15-bit time stamp from rx descriptor to
3648 * a full 64-bit TSF using the current h/w TSF.
3649*/
3650u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
3651{
3652 u64 tsf;
3653
3654 tsf = ath9k_hw_gettsf64(ah);
3655 if ((tsf & 0x7fff) < rstamp)
3656 tsf -= 0x8000;
3657 return (tsf & ~0x7fff) | rstamp;
3658}
3659EXPORT_SYMBOL(ath9k_hw_extend_tsf);
3660
Sujithcbe61d82009-02-09 13:27:12 +05303661bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003662{
Sujithf1dc5602008-10-29 10:16:30 +05303663 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003664 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
3665 "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05303666 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05303667 return false;
3668 } else {
3669 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05303670 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05303671 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003672 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003673}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003674EXPORT_SYMBOL(ath9k_hw_setslottime);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003675
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003676void ath9k_hw_set11nmac2040(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003677{
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003678 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +05303679 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003680
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07003681 if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05303682 macmode = AR_2040_JOINED_RX_CLEAR;
3683 else
3684 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003685
Sujithf1dc5602008-10-29 10:16:30 +05303686 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003687}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303688
3689/* HW Generic timers configuration */
3690
3691static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
3692{
3693 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3694 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3695 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3696 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3697 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3698 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3699 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3700 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
3701 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
3702 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
3703 AR_NDP2_TIMER_MODE, 0x0002},
3704 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
3705 AR_NDP2_TIMER_MODE, 0x0004},
3706 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
3707 AR_NDP2_TIMER_MODE, 0x0008},
3708 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
3709 AR_NDP2_TIMER_MODE, 0x0010},
3710 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
3711 AR_NDP2_TIMER_MODE, 0x0020},
3712 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
3713 AR_NDP2_TIMER_MODE, 0x0040},
3714 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
3715 AR_NDP2_TIMER_MODE, 0x0080}
3716};
3717
3718/* HW generic timer primitives */
3719
3720/* compute and clear index of rightmost 1 */
3721static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
3722{
3723 u32 b;
3724
3725 b = *mask;
3726 b &= (0-b);
3727 *mask &= ~b;
3728 b *= debruijn32;
3729 b >>= 27;
3730
3731 return timer_table->gen_timer_index[b];
3732}
3733
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05303734u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303735{
3736 return REG_READ(ah, AR_TSF_L32);
3737}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003738EXPORT_SYMBOL(ath9k_hw_gettsf32);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303739
3740struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3741 void (*trigger)(void *),
3742 void (*overflow)(void *),
3743 void *arg,
3744 u8 timer_index)
3745{
3746 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3747 struct ath_gen_timer *timer;
3748
3749 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3750
3751 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003752 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
3753 "Failed to allocate memory"
3754 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303755 return NULL;
3756 }
3757
3758 /* allocate a hardware generic timer slot */
3759 timer_table->timers[timer_index] = timer;
3760 timer->index = timer_index;
3761 timer->trigger = trigger;
3762 timer->overflow = overflow;
3763 timer->arg = arg;
3764
3765 return timer;
3766}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003767EXPORT_SYMBOL(ath_gen_timer_alloc);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303768
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003769void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3770 struct ath_gen_timer *timer,
3771 u32 timer_next,
3772 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303773{
3774 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3775 u32 tsf;
3776
3777 BUG_ON(!timer_period);
3778
3779 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
3780
3781 tsf = ath9k_hw_gettsf32(ah);
3782
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003783 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
3784 "curent tsf %x period %x"
3785 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303786
3787 /*
3788 * Pull timer_next forward if the current TSF already passed it
3789 * because of software latency
3790 */
3791 if (timer_next < tsf)
3792 timer_next = tsf + timer_period;
3793
3794 /*
3795 * Program generic timer registers
3796 */
3797 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3798 timer_next);
3799 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3800 timer_period);
3801 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3802 gen_tmr_configuration[timer->index].mode_mask);
3803
3804 /* Enable both trigger and thresh interrupt masks */
3805 REG_SET_BIT(ah, AR_IMR_S5,
3806 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3807 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303808}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003809EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303810
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07003811void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303812{
3813 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3814
3815 if ((timer->index < AR_FIRST_NDP_TIMER) ||
3816 (timer->index >= ATH_MAX_GEN_TIMER)) {
3817 return;
3818 }
3819
3820 /* Clear generic timer enable bits. */
3821 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3822 gen_tmr_configuration[timer->index].mode_mask);
3823
3824 /* Disable both trigger and thresh interrupt masks */
3825 REG_CLR_BIT(ah, AR_IMR_S5,
3826 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3827 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3828
3829 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303830}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003831EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303832
3833void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3834{
3835 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3836
3837 /* free the hardware generic timer slot */
3838 timer_table->timers[timer->index] = NULL;
3839 kfree(timer);
3840}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003841EXPORT_SYMBOL(ath_gen_timer_free);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303842
3843/*
3844 * Generic Timer Interrupts handling
3845 */
3846void ath_gen_timer_isr(struct ath_hw *ah)
3847{
3848 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3849 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003850 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303851 u32 trigger_mask, thresh_mask, index;
3852
3853 /* get hardware generic timer interrupt status */
3854 trigger_mask = ah->intr_gen_timer_trigger;
3855 thresh_mask = ah->intr_gen_timer_thresh;
3856 trigger_mask &= timer_table->timer_mask.val;
3857 thresh_mask &= timer_table->timer_mask.val;
3858
3859 trigger_mask &= ~thresh_mask;
3860
3861 while (thresh_mask) {
3862 index = rightmost_index(timer_table, &thresh_mask);
3863 timer = timer_table->timers[index];
3864 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003865 ath_print(common, ATH_DBG_HWTIMER,
3866 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303867 timer->overflow(timer->arg);
3868 }
3869
3870 while (trigger_mask) {
3871 index = rightmost_index(timer_table, &trigger_mask);
3872 timer = timer_table->timers[index];
3873 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003874 ath_print(common, ATH_DBG_HWTIMER,
3875 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303876 timer->trigger(timer->arg);
3877 }
3878}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -04003879EXPORT_SYMBOL(ath_gen_timer_isr);
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003880
3881static struct {
3882 u32 version;
3883 const char * name;
3884} ath_mac_bb_names[] = {
3885 /* Devices with external radios */
3886 { AR_SREV_VERSION_5416_PCI, "5416" },
3887 { AR_SREV_VERSION_5416_PCIE, "5418" },
3888 { AR_SREV_VERSION_9100, "9100" },
3889 { AR_SREV_VERSION_9160, "9160" },
3890 /* Single-chip solutions */
3891 { AR_SREV_VERSION_9280, "9280" },
3892 { AR_SREV_VERSION_9285, "9285" },
Luis R. Rodriguez11158472009-10-27 12:59:35 -04003893 { AR_SREV_VERSION_9287, "9287" },
3894 { AR_SREV_VERSION_9271, "9271" },
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003895};
3896
3897/* For devices with external radios */
3898static struct {
3899 u16 version;
3900 const char * name;
3901} ath_rf_names[] = {
3902 { 0, "5133" },
3903 { AR_RAD5133_SREV_MAJOR, "5133" },
3904 { AR_RAD5122_SREV_MAJOR, "5122" },
3905 { AR_RAD2133_SREV_MAJOR, "2133" },
3906 { AR_RAD2122_SREV_MAJOR, "2122" }
3907};
3908
3909/*
3910 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3911 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003912static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003913{
3914 int i;
3915
3916 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3917 if (ath_mac_bb_names[i].version == mac_bb_version) {
3918 return ath_mac_bb_names[i].name;
3919 }
3920 }
3921
3922 return "????";
3923}
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003924
3925/*
3926 * Return the RF name. "????" is returned if the RF is unknown.
3927 * Used for devices with external radios.
3928 */
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003929static const char *ath9k_hw_rf_name(u16 rf_version)
Luis R. Rodriguez2da4f012009-10-27 12:59:33 -04003930{
3931 int i;
3932
3933 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3934 if (ath_rf_names[i].version == rf_version) {
3935 return ath_rf_names[i].name;
3936 }
3937 }
3938
3939 return "????";
3940}
Luis R. Rodriguezf934c4d2009-10-27 12:59:34 -04003941
3942void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3943{
3944 int used;
3945
3946 /* chipsets >= AR9280 are single-chip */
3947 if (AR_SREV_9280_10_OR_LATER(ah)) {
3948 used = snprintf(hw_name, len,
3949 "Atheros AR%s Rev:%x",
3950 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3951 ah->hw_version.macRev);
3952 }
3953 else {
3954 used = snprintf(hw_name, len,
3955 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3956 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3957 ah->hw_version.macRev,
3958 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
3959 AR_RADIO_SREV_MAJOR)),
3960 ah->hw_version.phyRev);
3961 }
3962
3963 hw_name[used] = '\0';
3964}
3965EXPORT_SYMBOL(ath9k_hw_name);