blob: 6d2ac33a2764fa927b8e38b0b72b9c3b1c3ea377 [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"
Sujith394cf0a2009-02-09 13:26:54 +053021#include "ath9k.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);
29static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +053030 enum ath9k_ht_macmode macmode);
Sujithcbe61d82009-02-09 13:27:12 +053031static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053032 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053033 u32 reg, u32 value);
Sujithcbe61d82009-02-09 13:27:12 +053034static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
35static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070036
Sujithf1dc5602008-10-29 10:16:30 +053037/********************/
38/* Helper Functions */
39/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070040
Sujithcbe61d82009-02-09 13:27:12 +053041static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053042{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070043 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053044
Sujith2660b812009-02-09 13:27:26 +053045 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080046 return clks / ATH9K_CLOCK_RATE_CCK;
47 if (conf->channel->band == IEEE80211_BAND_2GHZ)
48 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053049
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080050 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053051}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070052
Sujithcbe61d82009-02-09 13:27:12 +053053static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053054{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070055 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053056
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080057 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053058 return ath9k_hw_mac_usec(ah, clks) / 2;
59 else
60 return ath9k_hw_mac_usec(ah, clks);
61}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070062
Sujithcbe61d82009-02-09 13:27:12 +053063static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053064{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070065 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053066
Sujith2660b812009-02-09 13:27:26 +053067 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080068 return usecs *ATH9K_CLOCK_RATE_CCK;
69 if (conf->channel->band == IEEE80211_BAND_2GHZ)
70 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
71 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053072}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070073
Sujithcbe61d82009-02-09 13:27:12 +053074static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053075{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -070076 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053077
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080078 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053079 return ath9k_hw_mac_clks(ah, usecs) * 2;
80 else
81 return ath9k_hw_mac_clks(ah, usecs);
82}
83
Sujith0caa7b12009-02-16 13:23:20 +053084bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070085{
86 int i;
87
Sujith0caa7b12009-02-16 13:23:20 +053088 BUG_ON(timeout < AH_TIME_QUANTUM);
89
90 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070091 if ((REG_READ(ah, reg) & mask) == val)
92 return true;
93
94 udelay(AH_TIME_QUANTUM);
95 }
Sujith04bd46382008-11-28 22:18:05 +053096
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070097 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
98 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
99 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530100
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700101 return false;
102}
103
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700104u32 ath9k_hw_reverse_bits(u32 val, u32 n)
105{
106 u32 retval;
107 int i;
108
109 for (i = 0, retval = 0; i < n; i++) {
110 retval = (retval << 1) | (val & 1);
111 val >>= 1;
112 }
113 return retval;
114}
115
Sujithcbe61d82009-02-09 13:27:12 +0530116bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530117 u16 flags, u16 *low,
118 u16 *high)
119{
Sujith2660b812009-02-09 13:27:26 +0530120 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530121
122 if (flags & CHANNEL_5GHZ) {
123 *low = pCap->low_5ghz_chan;
124 *high = pCap->high_5ghz_chan;
125 return true;
126 }
127 if ((flags & CHANNEL_2GHZ)) {
128 *low = pCap->low_2ghz_chan;
129 *high = pCap->high_2ghz_chan;
130 return true;
131 }
132 return false;
133}
134
Sujithcbe61d82009-02-09 13:27:12 +0530135u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400136 const struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530137 u32 frameLen, u16 rateix,
138 bool shortPreamble)
139{
140 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
141 u32 kbps;
142
Sujithe63835b2008-11-18 09:07:53 +0530143 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530144
145 if (kbps == 0)
146 return 0;
147
148 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530149 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530150 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530151 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530152 phyTime >>= 1;
153 numBits = frameLen << 3;
154 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
155 break;
Sujith46d14a52008-11-18 09:08:13 +0530156 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530157 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530158 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
159 numBits = OFDM_PLCP_BITS + (frameLen << 3);
160 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
161 txTime = OFDM_SIFS_TIME_QUARTER
162 + OFDM_PREAMBLE_TIME_QUARTER
163 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530164 } else if (ah->curchan &&
165 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530166 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
167 numBits = OFDM_PLCP_BITS + (frameLen << 3);
168 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
169 txTime = OFDM_SIFS_TIME_HALF +
170 OFDM_PREAMBLE_TIME_HALF
171 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
172 } else {
173 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
174 numBits = OFDM_PLCP_BITS + (frameLen << 3);
175 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
176 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
177 + (numSymbols * OFDM_SYMBOL_TIME);
178 }
179 break;
180 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700181 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
182 "Unknown phy %u (rate ix %u)\n",
183 rates->info[rateix].phy, rateix);
Sujithf1dc5602008-10-29 10:16:30 +0530184 txTime = 0;
185 break;
186 }
187
188 return txTime;
189}
190
Sujithcbe61d82009-02-09 13:27:12 +0530191void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530192 struct ath9k_channel *chan,
193 struct chan_centers *centers)
194{
195 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530196
197 if (!IS_CHAN_HT40(chan)) {
198 centers->ctl_center = centers->ext_center =
199 centers->synth_center = chan->channel;
200 return;
201 }
202
203 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
204 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
205 centers->synth_center =
206 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
207 extoff = 1;
208 } else {
209 centers->synth_center =
210 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
211 extoff = -1;
212 }
213
214 centers->ctl_center =
215 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700216 /* 25 MHz spacing is supported by hw but not on upper layers */
Sujithf1dc5602008-10-29 10:16:30 +0530217 centers->ext_center =
Luis R. Rodriguez64200142009-09-13 22:05:04 -0700218 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
Sujithf1dc5602008-10-29 10:16:30 +0530219}
220
221/******************/
222/* Chip Revisions */
223/******************/
224
Sujithcbe61d82009-02-09 13:27:12 +0530225static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530226{
227 u32 val;
228
229 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
230
231 if (val == 0xFF) {
232 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530233 ah->hw_version.macVersion =
234 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
235 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530236 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530237 } else {
238 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530239 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530240
Sujithd535a422009-02-09 13:27:06 +0530241 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530242
Sujithd535a422009-02-09 13:27:06 +0530243 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530244 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530245 }
246}
247
Sujithcbe61d82009-02-09 13:27:12 +0530248static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530249{
250 u32 val;
251 int i;
252
253 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
254
255 for (i = 0; i < 8; i++)
256 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
257 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
258 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
259
260 return ath9k_hw_reverse_bits(val, 8);
261}
262
263/************************************/
264/* HW Attach, Detach, Init Routines */
265/************************************/
266
Sujithcbe61d82009-02-09 13:27:12 +0530267static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530268{
Sujithfeed0292009-01-29 11:37:35 +0530269 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530270 return;
271
272 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
273 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
274 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
275 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
276 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
277 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
278 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
279 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
280 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
281
282 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
283}
284
Sujithcbe61d82009-02-09 13:27:12 +0530285static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530286{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700287 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530288 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
289 u32 regHold[2];
290 u32 patternData[4] = { 0x55555555,
291 0xaaaaaaaa,
292 0x66666666,
293 0x99999999 };
294 int i, j;
295
296 for (i = 0; i < 2; i++) {
297 u32 addr = regAddr[i];
298 u32 wrData, rdData;
299
300 regHold[i] = REG_READ(ah, addr);
301 for (j = 0; j < 0x100; j++) {
302 wrData = (j << 16) | j;
303 REG_WRITE(ah, addr, wrData);
304 rdData = REG_READ(ah, addr);
305 if (rdData != wrData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700306 ath_print(common, ATH_DBG_FATAL,
307 "address test failed "
308 "addr: 0x%08x - wr:0x%08x != "
309 "rd:0x%08x\n",
310 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530311 return false;
312 }
313 }
314 for (j = 0; j < 4; j++) {
315 wrData = patternData[j];
316 REG_WRITE(ah, addr, wrData);
317 rdData = REG_READ(ah, addr);
318 if (wrData != rdData) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700319 ath_print(common, ATH_DBG_FATAL,
320 "address test failed "
321 "addr: 0x%08x - wr:0x%08x != "
322 "rd:0x%08x\n",
323 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530324 return false;
325 }
326 }
327 REG_WRITE(ah, regAddr[i], regHold[i]);
328 }
329 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530330
Sujithf1dc5602008-10-29 10:16:30 +0530331 return true;
332}
333
334static const char *ath9k_hw_devname(u16 devid)
335{
336 switch (devid) {
337 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530338 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100339 case AR5416_DEVID_PCIE:
340 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530341 case AR9160_DEVID_PCI:
342 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100343 case AR5416_AR9100_DEVID:
344 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530345 case AR9280_DEVID_PCI:
346 case AR9280_DEVID_PCIE:
347 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530348 case AR9285_DEVID_PCIE:
349 return "Atheros 9285";
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530350 case AR5416_DEVID_AR9287_PCI:
351 case AR5416_DEVID_AR9287_PCIE:
352 return "Atheros 9287";
Sujithf1dc5602008-10-29 10:16:30 +0530353 }
354
355 return NULL;
356}
357
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700358static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700359{
360 int i;
361
Sujith2660b812009-02-09 13:27:26 +0530362 ah->config.dma_beacon_response_time = 2;
363 ah->config.sw_beacon_response_time = 10;
364 ah->config.additional_swba_backoff = 0;
365 ah->config.ack_6mb = 0x0;
366 ah->config.cwm_ignore_extcca = 0;
367 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530368 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530369 ah->config.pcie_waen = 0;
370 ah->config.analog_shiftreg = 1;
371 ah->config.ht_enable = 1;
372 ah->config.ofdm_trig_low = 200;
373 ah->config.ofdm_trig_high = 500;
374 ah->config.cck_trig_high = 200;
375 ah->config.cck_trig_low = 100;
376 ah->config.enable_ani = 1;
Sujith1cf68732009-08-13 09:34:32 +0530377 ah->config.diversity_control = ATH9K_ANT_VARIABLE;
Sujith2660b812009-02-09 13:27:26 +0530378 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700379
380 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530381 ah->config.spurchans[i][0] = AR_NO_SPUR;
382 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700383 }
384
Sujith0ef1f162009-03-30 15:28:35 +0530385 ah->config.intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400386
387 /*
388 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
389 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
390 * This means we use it for all AR5416 devices, and the few
391 * minor PCI AR9280 devices out there.
392 *
393 * Serialization is required because these devices do not handle
394 * well the case of two concurrent reads/writes due to the latency
395 * involved. During one read/write another read/write can be issued
396 * on another CPU while the previous read/write may still be working
397 * on our hardware, if we hit this case the hardware poops in a loop.
398 * We prevent this by serializing reads and writes.
399 *
400 * This issue is not present on PCI-Express devices or pre-AR5416
401 * devices (legacy, 802.11abg).
402 */
403 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700404 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700405}
406
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700407static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700408{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700409 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
410
411 regulatory->country_code = CTRY_DEFAULT;
412 regulatory->power_limit = MAX_RATE_POWER;
413 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
414
Sujithd535a422009-02-09 13:27:06 +0530415 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530416 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700417
418 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700419 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530420 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700421 if (!AR_SREV_9100(ah))
422 ah->ah_flags = AH_USE_EEPROM;
423
Sujith2660b812009-02-09 13:27:26 +0530424 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530425 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
426 ah->beacon_interval = 100;
427 ah->enable_32kHz_clock = DONT_USE_32KHZ;
428 ah->slottime = (u32) -1;
429 ah->acktimeout = (u32) -1;
430 ah->ctstimeout = (u32) -1;
431 ah->globaltxtimeout = (u32) -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700432
Sujith2660b812009-02-09 13:27:26 +0530433 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700434
Gabor Juhoscbdec972009-07-24 17:27:22 +0200435 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436}
437
Sujithcbe61d82009-02-09 13:27:12 +0530438static int ath9k_hw_rfattach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700439{
440 bool rfStatus = false;
441 int ecode = 0;
442
443 rfStatus = ath9k_hw_init_rf(ah, &ecode);
444 if (!rfStatus) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700445 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
446 "RF setup failed, status: %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700447 return ecode;
448 }
449
450 return 0;
451}
452
Sujithcbe61d82009-02-09 13:27:12 +0530453static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700454{
455 u32 val;
456
457 REG_WRITE(ah, AR_PHY(0), 0x00000007);
458
459 val = ath9k_hw_get_radiorev(ah);
460 switch (val & AR_RADIO_SREV_MAJOR) {
461 case 0:
462 val = AR_RAD5133_SREV_MAJOR;
463 break;
464 case AR_RAD5133_SREV_MAJOR:
465 case AR_RAD5122_SREV_MAJOR:
466 case AR_RAD2133_SREV_MAJOR:
467 case AR_RAD2122_SREV_MAJOR:
468 break;
469 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700470 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
471 "Radio Chip Rev 0x%02X not supported\n",
472 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700473 return -EOPNOTSUPP;
474 }
475
Sujithd535a422009-02-09 13:27:06 +0530476 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700477
478 return 0;
479}
480
Sujithcbe61d82009-02-09 13:27:12 +0530481static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700482{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700483 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530484 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700485 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530486 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700487
Sujithf1dc5602008-10-29 10:16:30 +0530488 sum = 0;
489 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530490 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530491 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700492 common->macaddr[2 * i] = eeval >> 8;
493 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700494 }
Sujithd8baa932009-03-30 15:28:25 +0530495 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530496 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700497
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700498 return 0;
499}
500
Sujithcbe61d82009-02-09 13:27:12 +0530501static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530502{
503 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530504
Sujithf74df6f2009-02-09 13:27:24 +0530505 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
506 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530507
508 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530509 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530510 ar9280Modes_backoff_13db_rxgain_9280_2,
511 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
512 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530513 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530514 ar9280Modes_backoff_23db_rxgain_9280_2,
515 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
516 else
Sujith2660b812009-02-09 13:27:26 +0530517 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530518 ar9280Modes_original_rxgain_9280_2,
519 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530520 } else {
Sujith2660b812009-02-09 13:27:26 +0530521 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530522 ar9280Modes_original_rxgain_9280_2,
523 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530524 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530525}
526
Sujithcbe61d82009-02-09 13:27:12 +0530527static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530528{
529 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530530
Sujithf74df6f2009-02-09 13:27:24 +0530531 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
532 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530533
534 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530535 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530536 ar9280Modes_high_power_tx_gain_9280_2,
537 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
538 else
Sujith2660b812009-02-09 13:27:26 +0530539 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530540 ar9280Modes_original_tx_gain_9280_2,
541 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530542 } else {
Sujith2660b812009-02-09 13:27:26 +0530543 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530544 ar9280Modes_original_tx_gain_9280_2,
545 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530546 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530547}
548
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700549static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700550{
551 int ecode;
552
Sujithd8baa932009-03-30 15:28:25 +0530553 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700554 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700555
556 ecode = ath9k_hw_rf_claim(ah);
557 if (ecode != 0)
558 return ecode;
559
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700560 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700561 if (ecode != 0)
562 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530563
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700564 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
565 "Eeprom VER: %d, REV: %d\n",
566 ah->eep_ops->get_eeprom_ver(ah),
567 ah->eep_ops->get_eeprom_rev(ah));
Sujith7d01b222009-03-13 08:55:55 +0530568
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700569 ecode = ath9k_hw_rfattach(ah);
570 if (ecode != 0)
571 return ecode;
572
573 if (!AR_SREV_9100(ah)) {
574 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700575 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700576 }
Sujithf1dc5602008-10-29 10:16:30 +0530577
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700578 return 0;
579}
580
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700581static bool ath9k_hw_devid_supported(u16 devid)
582{
583 switch (devid) {
584 case AR5416_DEVID_PCI:
585 case AR5416_DEVID_PCIE:
586 case AR5416_AR9100_DEVID:
587 case AR9160_DEVID_PCI:
588 case AR9280_DEVID_PCI:
589 case AR9280_DEVID_PCIE:
590 case AR9285_DEVID_PCIE:
591 case AR5416_DEVID_AR9287_PCI:
592 case AR5416_DEVID_AR9287_PCIE:
593 return true;
594 default:
595 break;
596 }
597 return false;
598}
599
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700600static bool ath9k_hw_macversion_supported(u32 macversion)
601{
602 switch (macversion) {
603 case AR_SREV_VERSION_5416_PCI:
604 case AR_SREV_VERSION_5416_PCIE:
605 case AR_SREV_VERSION_9160:
606 case AR_SREV_VERSION_9100:
607 case AR_SREV_VERSION_9280:
608 case AR_SREV_VERSION_9285:
609 case AR_SREV_VERSION_9287:
610 return true;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400611 /* Not yet */
612 case AR_SREV_VERSION_9271:
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700613 default:
614 break;
615 }
616 return false;
617}
618
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700619static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700620{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700621 if (AR_SREV_9160_10_OR_LATER(ah)) {
622 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530623 ah->iq_caldata.calData = &iq_cal_single_sample;
624 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700625 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530626 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700627 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530628 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700629 &adc_init_dc_cal;
630 } else {
Sujith2660b812009-02-09 13:27:26 +0530631 ah->iq_caldata.calData = &iq_cal_multi_sample;
632 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700633 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530634 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700635 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530636 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700637 &adc_init_dc_cal;
638 }
Sujith2660b812009-02-09 13:27:26 +0530639 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700640 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700641}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700642
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700643static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
644{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400645 if (AR_SREV_9271(ah)) {
646 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0,
647 ARRAY_SIZE(ar9271Modes_9271_1_0), 6);
648 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0,
649 ARRAY_SIZE(ar9271Common_9271_1_0), 2);
650 return;
651 }
652
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530653 if (AR_SREV_9287_11_OR_LATER(ah)) {
654 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
655 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
656 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
657 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
658 if (ah->config.pcie_clock_req)
659 INIT_INI_ARRAY(&ah->iniPcieSerdes,
660 ar9287PciePhy_clkreq_off_L1_9287_1_1,
661 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
662 else
663 INIT_INI_ARRAY(&ah->iniPcieSerdes,
664 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
665 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
666 2);
667 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
668 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
669 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
670 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
671 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700672
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530673 if (ah->config.pcie_clock_req)
674 INIT_INI_ARRAY(&ah->iniPcieSerdes,
675 ar9287PciePhy_clkreq_off_L1_9287_1_0,
676 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
677 else
678 INIT_INI_ARRAY(&ah->iniPcieSerdes,
679 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
680 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
681 2);
682 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
683
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530684
Sujith2660b812009-02-09 13:27:26 +0530685 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530686 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530687 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530688 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
689
Sujith2660b812009-02-09 13:27:26 +0530690 if (ah->config.pcie_clock_req) {
691 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530692 ar9285PciePhy_clkreq_off_L1_9285_1_2,
693 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
694 } else {
Sujith2660b812009-02-09 13:27:26 +0530695 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530696 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
697 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
698 2);
699 }
700 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530701 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530702 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530703 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530704 ARRAY_SIZE(ar9285Common_9285), 2);
705
Sujith2660b812009-02-09 13:27:26 +0530706 if (ah->config.pcie_clock_req) {
707 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530708 ar9285PciePhy_clkreq_off_L1_9285,
709 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
710 } else {
Sujith2660b812009-02-09 13:27:26 +0530711 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530712 ar9285PciePhy_clkreq_always_on_L1_9285,
713 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
714 }
715 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530716 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700717 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530718 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700719 ARRAY_SIZE(ar9280Common_9280_2), 2);
720
Sujith2660b812009-02-09 13:27:26 +0530721 if (ah->config.pcie_clock_req) {
722 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530723 ar9280PciePhy_clkreq_off_L1_9280,
724 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700725 } else {
Sujith2660b812009-02-09 13:27:26 +0530726 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530727 ar9280PciePhy_clkreq_always_on_L1_9280,
728 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700729 }
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700731 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530732 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700733 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530734 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530736 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700737 ARRAY_SIZE(ar9280Common_9280), 2);
738 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530739 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700740 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530741 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700742 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530743 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530747 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530751 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530755 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530757 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700758 ARRAY_SIZE(ar5416Bank7_9160), 2);
759 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530760 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 ar5416Addac_91601_1,
762 ARRAY_SIZE(ar5416Addac_91601_1), 2);
763 } else {
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ARRAY_SIZE(ar5416Addac_9160), 2);
766 }
767 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530784 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700785 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530786 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530788 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700789 ARRAY_SIZE(ar5416Addac_9100), 2);
790 } else {
Sujith2660b812009-02-09 13:27:26 +0530791 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530793 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530807 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700808 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530809 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700810 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530811 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700812 ARRAY_SIZE(ar5416Addac), 2);
813 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700814}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700815
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700816static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
817{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530818 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530819 INIT_INI_ARRAY(&ah->iniModesRxGain,
820 ar9287Modes_rx_gain_9287_1_1,
821 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
822 else if (AR_SREV_9287_10(ah))
823 INIT_INI_ARRAY(&ah->iniModesRxGain,
824 ar9287Modes_rx_gain_9287_1_0,
825 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
826 else if (AR_SREV_9280_20(ah))
827 ath9k_hw_init_rxgain_ini(ah);
828
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530829 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530830 INIT_INI_ARRAY(&ah->iniModesTxGain,
831 ar9287Modes_tx_gain_9287_1_1,
832 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
833 } else if (AR_SREV_9287_10(ah)) {
834 INIT_INI_ARRAY(&ah->iniModesTxGain,
835 ar9287Modes_tx_gain_9287_1_0,
836 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
837 } else if (AR_SREV_9280_20(ah)) {
838 ath9k_hw_init_txgain_ini(ah);
839 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530840 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
841
842 /* txgain table */
843 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
844 INIT_INI_ARRAY(&ah->iniModesTxGain,
845 ar9285Modes_high_power_tx_gain_9285_1_2,
846 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
847 } else {
848 INIT_INI_ARRAY(&ah->iniModesTxGain,
849 ar9285Modes_original_tx_gain_9285_1_2,
850 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
851 }
852
853 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700854}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530855
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700856static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
857{
858 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530859
860 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
861 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
862
863 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530864 for (i = 0; i < ah->iniModes.ia_rows; i++) {
865 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700866
Sujith2660b812009-02-09 13:27:26 +0530867 for (j = 1; j < ah->iniModes.ia_columns; j++) {
868 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700869
Sujith2660b812009-02-09 13:27:26 +0530870 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530871 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530872 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700873 reg, val);
874 }
875 }
876 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700877}
878
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700879int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700880{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700881 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700882 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700883
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700884 if (!ath9k_hw_devid_supported(ah->hw_version.devid))
885 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700886
887 ath9k_hw_init_defaults(ah);
888 ath9k_hw_init_config(ah);
889
890 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700891 ath_print(common, ATH_DBG_FATAL,
892 "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700893 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700894 }
895
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700896 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700897 ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700898 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700899 }
900
901 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
902 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
903 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
904 ah->config.serialize_regmode =
905 SER_REG_MODE_ON;
906 } else {
907 ah->config.serialize_regmode =
908 SER_REG_MODE_OFF;
909 }
910 }
911
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700912 ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700913 ah->config.serialize_regmode);
914
915 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700916 ath_print(common, ATH_DBG_FATAL,
917 "Mac Chip Rev 0x%02x.%x is not supported by "
918 "this driver\n", ah->hw_version.macVersion,
919 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700920 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700921 }
922
923 if (AR_SREV_9100(ah)) {
924 ah->iq_caldata.calData = &iq_cal_multi_sample;
925 ah->supp_cals = IQ_MISMATCH_CAL;
926 ah->is_pciexpress = false;
927 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400928
929 if (AR_SREV_9271(ah))
930 ah->is_pciexpress = false;
931
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700932 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
933
934 ath9k_hw_init_cal_settings(ah);
935
936 ah->ani_function = ATH9K_ANI_ALL;
937 if (AR_SREV_9280_10_OR_LATER(ah))
938 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
939
940 ath9k_hw_init_mode_regs(ah);
941
942 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530943 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700944 else
945 ath9k_hw_disablepcie(ah);
946
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700947 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700948 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700949 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700950
951 ath9k_hw_init_mode_gain_regs(ah);
952 ath9k_hw_fill_cap_info(ah);
953 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530954
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700955 r = ath9k_hw_init_macaddr(ah);
956 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700957 ath_print(common, ATH_DBG_FATAL,
958 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700959 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700960 }
961
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400962 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530963 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700964 else
Sujith2660b812009-02-09 13:27:26 +0530965 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700966
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700967 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700968
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700969 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700970}
971
Sujithcbe61d82009-02-09 13:27:12 +0530972static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530973 struct ath9k_channel *chan)
974{
975 u32 synthDelay;
976
977 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +0530978 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +0530979 synthDelay = (4 * synthDelay) / 22;
980 else
981 synthDelay /= 10;
982
983 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
984
985 udelay(synthDelay + BASE_ACTIVATE_DELAY);
986}
987
Sujithcbe61d82009-02-09 13:27:12 +0530988static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530989{
990 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
991 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
992
993 REG_WRITE(ah, AR_QOS_NO_ACK,
994 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
995 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
996 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
997
998 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
999 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1000 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1001 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1002 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1003}
1004
Sujithcbe61d82009-02-09 13:27:12 +05301005static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301006 struct ath9k_channel *chan)
1007{
1008 u32 pll;
1009
1010 if (AR_SREV_9100(ah)) {
1011 if (chan && IS_CHAN_5GHZ(chan))
1012 pll = 0x1450;
1013 else
1014 pll = 0x1458;
1015 } else {
1016 if (AR_SREV_9280_10_OR_LATER(ah)) {
1017 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1018
1019 if (chan && IS_CHAN_HALF_RATE(chan))
1020 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1021 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1022 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1023
1024 if (chan && IS_CHAN_5GHZ(chan)) {
1025 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1026
1027
1028 if (AR_SREV_9280_20(ah)) {
1029 if (((chan->channel % 20) == 0)
1030 || ((chan->channel % 10) == 0))
1031 pll = 0x2850;
1032 else
1033 pll = 0x142c;
1034 }
1035 } else {
1036 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1037 }
1038
1039 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1040
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(0x50, AR_RTC_9160_PLL_DIV);
1050 else
1051 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1052 } else {
1053 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1054
1055 if (chan && IS_CHAN_HALF_RATE(chan))
1056 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1057 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1058 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1059
1060 if (chan && IS_CHAN_5GHZ(chan))
1061 pll |= SM(0xa, AR_RTC_PLL_DIV);
1062 else
1063 pll |= SM(0xb, AR_RTC_PLL_DIV);
1064 }
1065 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001066 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301067
1068 udelay(RTC_PLL_SETTLE_DELAY);
1069
1070 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1071}
1072
Sujithcbe61d82009-02-09 13:27:12 +05301073static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301074{
Sujithf1dc5602008-10-29 10:16:30 +05301075 int rx_chainmask, tx_chainmask;
1076
Sujith2660b812009-02-09 13:27:26 +05301077 rx_chainmask = ah->rxchainmask;
1078 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301079
1080 switch (rx_chainmask) {
1081 case 0x5:
1082 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1083 AR_PHY_SWAP_ALT_CHAIN);
1084 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301085 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301086 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1087 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1088 break;
1089 }
1090 case 0x1:
1091 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301092 case 0x7:
1093 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1094 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1095 break;
1096 default:
1097 break;
1098 }
1099
1100 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1101 if (tx_chainmask == 0x5) {
1102 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1103 AR_PHY_SWAP_ALT_CHAIN);
1104 }
1105 if (AR_SREV_9100(ah))
1106 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1107 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1108}
1109
Sujithcbe61d82009-02-09 13:27:12 +05301110static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001111 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301112{
Sujith2660b812009-02-09 13:27:26 +05301113 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301114 AR_IMR_TXURN |
1115 AR_IMR_RXERR |
1116 AR_IMR_RXORN |
1117 AR_IMR_BCNMISC;
1118
Sujith0ef1f162009-03-30 15:28:35 +05301119 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301120 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301121 else
Sujith2660b812009-02-09 13:27:26 +05301122 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301123
Sujith2660b812009-02-09 13:27:26 +05301124 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301125
Colin McCabed97809d2008-12-01 13:38:55 -08001126 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301127 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301128
Sujith2660b812009-02-09 13:27:26 +05301129 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301130 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1131
1132 if (!AR_SREV_9100(ah)) {
1133 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1134 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1135 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1136 }
1137}
1138
Sujithcbe61d82009-02-09 13:27:12 +05301139static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301140{
Sujithf1dc5602008-10-29 10:16:30 +05301141 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001142 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1143 "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301144 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301145 return false;
1146 } else {
1147 REG_RMW_FIELD(ah, AR_TIME_OUT,
1148 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301149 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301150 return true;
1151 }
1152}
1153
Sujithcbe61d82009-02-09 13:27:12 +05301154static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301155{
Sujithf1dc5602008-10-29 10:16:30 +05301156 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001157 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1158 "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301159 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301160 return false;
1161 } else {
1162 REG_RMW_FIELD(ah, AR_TIME_OUT,
1163 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301164 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301165 return true;
1166 }
1167}
1168
Sujithcbe61d82009-02-09 13:27:12 +05301169static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301170{
Sujithf1dc5602008-10-29 10:16:30 +05301171 if (tu > 0xFFFF) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001172 ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
1173 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301174 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301175 return false;
1176 } else {
1177 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301178 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301179 return true;
1180 }
1181}
1182
Sujithcbe61d82009-02-09 13:27:12 +05301183static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301184{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001185 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1186 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301187
Sujith2660b812009-02-09 13:27:26 +05301188 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301189 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301190 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1191 if (ah->slottime != (u32) -1)
1192 ath9k_hw_setslottime(ah, ah->slottime);
1193 if (ah->acktimeout != (u32) -1)
1194 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1195 if (ah->ctstimeout != (u32) -1)
1196 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1197 if (ah->globaltxtimeout != (u32) -1)
1198 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301199}
1200
1201const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1202{
1203 return vendorid == ATHEROS_VENDOR_ID ?
1204 ath9k_hw_devname(devid) : NULL;
1205}
1206
Sujithcbe61d82009-02-09 13:27:12 +05301207void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001208{
1209 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001210 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001211
Luis R. Rodriguez081b35a2009-08-03 12:24:50 -07001212 ath9k_hw_rf_free(ah);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001213 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001214 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001215 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001216}
1217
Sujithf1dc5602008-10-29 10:16:30 +05301218/*******/
1219/* INI */
1220/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001221
Sujithcbe61d82009-02-09 13:27:12 +05301222static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301223 struct ath9k_channel *chan)
1224{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001225 u32 val;
1226
1227 if (AR_SREV_9271(ah)) {
1228 /*
1229 * Enable spectral scan to solution for issues with stuck
1230 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1231 * AR9271 1.1
1232 */
1233 if (AR_SREV_9271_10(ah)) {
1234 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE;
1235 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1236 }
1237 else if (AR_SREV_9271_11(ah))
1238 /*
1239 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1240 * present on AR9271 1.1
1241 */
1242 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1243 return;
1244 }
1245
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301246 /*
1247 * Set the RX_ABORT and RX_DIS and clear if off only after
1248 * RXE is set for MAC. This prevents frames with corrupted
1249 * descriptor status.
1250 */
1251 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1252
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301253 if (AR_SREV_9280_10_OR_LATER(ah)) {
1254 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1255 (~AR_PCU_MISC_MODE2_HWWAR1);
1256
1257 if (AR_SREV_9287_10_OR_LATER(ah))
1258 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1259
1260 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1261 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301262
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001263 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301264 AR_SREV_9280_10_OR_LATER(ah))
1265 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001266 /*
1267 * Disable BB clock gating
1268 * Necessary to avoid issues on AR5416 2.0
1269 */
Sujithf1dc5602008-10-29 10:16:30 +05301270 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1271}
1272
Sujithcbe61d82009-02-09 13:27:12 +05301273static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301274 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301275 u32 reg, u32 value)
1276{
1277 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001278 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301279
Sujithd535a422009-02-09 13:27:06 +05301280 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301281 case AR9280_DEVID_PCI:
1282 if (reg == 0x7894) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001283 ath_print(common, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301284 "ini VAL: %x EEPROM: %x\n", value,
1285 (pBase->version & 0xff));
1286
1287 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001288 ath_print(common, ATH_DBG_EEPROM,
1289 "PWDCLKIND: %d\n",
1290 pBase->pwdclkind);
Sujithf1dc5602008-10-29 10:16:30 +05301291 value &= ~AR_AN_TOP2_PWDCLKIND;
1292 value |= AR_AN_TOP2_PWDCLKIND &
1293 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1294 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001295 ath_print(common, ATH_DBG_EEPROM,
1296 "PWDCLKIND Earlier Rev\n");
Sujithf1dc5602008-10-29 10:16:30 +05301297 }
1298
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001299 ath_print(common, ATH_DBG_EEPROM,
1300 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001301 }
Sujithf1dc5602008-10-29 10:16:30 +05301302 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001303 }
1304
Sujithf1dc5602008-10-29 10:16:30 +05301305 return value;
1306}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001307
Sujithcbe61d82009-02-09 13:27:12 +05301308static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301309 struct ar5416_eeprom_def *pEepData,
1310 u32 reg, u32 value)
1311{
Sujith2660b812009-02-09 13:27:26 +05301312 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301313 return value;
1314 else
1315 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1316}
1317
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301318static void ath9k_olc_init(struct ath_hw *ah)
1319{
1320 u32 i;
1321
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301322 if (OLC_FOR_AR9287_10_LATER) {
1323 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1324 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1325 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1326 AR9287_AN_TXPC0_TXPCMODE,
1327 AR9287_AN_TXPC0_TXPCMODE_S,
1328 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1329 udelay(100);
1330 } else {
1331 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1332 ah->originalGain[i] =
1333 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1334 AR_PHY_TX_GAIN);
1335 ah->PDADCdelta = 0;
1336 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301337}
1338
Bob Copeland3a702e42009-03-30 22:30:29 -04001339static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1340 struct ath9k_channel *chan)
1341{
1342 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1343
1344 if (IS_CHAN_B(chan))
1345 ctl |= CTL_11B;
1346 else if (IS_CHAN_G(chan))
1347 ctl |= CTL_11G;
1348 else
1349 ctl |= CTL_11A;
1350
1351 return ctl;
1352}
1353
Sujithcbe61d82009-02-09 13:27:12 +05301354static int ath9k_hw_process_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301355 struct ath9k_channel *chan,
1356 enum ath9k_ht_macmode macmode)
1357{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001358 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301359 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001360 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301361 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001362
Sujithf1dc5602008-10-29 10:16:30 +05301363 switch (chan->chanmode) {
1364 case CHANNEL_A:
1365 case CHANNEL_A_HT20:
1366 modesIndex = 1;
1367 freqIndex = 1;
1368 break;
1369 case CHANNEL_A_HT40PLUS:
1370 case CHANNEL_A_HT40MINUS:
1371 modesIndex = 2;
1372 freqIndex = 1;
1373 break;
1374 case CHANNEL_G:
1375 case CHANNEL_G_HT20:
1376 case CHANNEL_B:
1377 modesIndex = 4;
1378 freqIndex = 2;
1379 break;
1380 case CHANNEL_G_HT40PLUS:
1381 case CHANNEL_G_HT40MINUS:
1382 modesIndex = 3;
1383 freqIndex = 2;
1384 break;
1385
1386 default:
1387 return -EINVAL;
1388 }
1389
1390 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301391 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301392 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301393
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001394 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301395 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301396 } else {
1397 struct ar5416IniArray temp;
1398 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301399 sizeof(u32) * ah->iniAddac.ia_rows *
1400 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301401
Sujith2660b812009-02-09 13:27:26 +05301402 memcpy(ah->addac5416_21,
1403 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301404
Sujith2660b812009-02-09 13:27:26 +05301405 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301406
Sujith2660b812009-02-09 13:27:26 +05301407 temp.ia_array = ah->addac5416_21;
1408 temp.ia_columns = ah->iniAddac.ia_columns;
1409 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301410 REG_WRITE_ARRAY(&temp, 1, regWrites);
1411 }
1412
1413 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1414
Sujith2660b812009-02-09 13:27:26 +05301415 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1416 u32 reg = INI_RA(&ah->iniModes, i, 0);
1417 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301418
Sujithf1dc5602008-10-29 10:16:30 +05301419 REG_WRITE(ah, reg, val);
1420
1421 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301422 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301423 udelay(100);
1424 }
1425
1426 DO_DELAY(regWrites);
1427 }
1428
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301429 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301430 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301431
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301432 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1433 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301434 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301435
Sujith2660b812009-02-09 13:27:26 +05301436 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1437 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1438 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301439
1440 REG_WRITE(ah, reg, val);
1441
1442 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301443 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301444 udelay(100);
1445 }
1446
1447 DO_DELAY(regWrites);
1448 }
1449
1450 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1451
1452 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301453 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301454 regWrites);
1455 }
1456
1457 ath9k_hw_override_ini(ah, chan);
1458 ath9k_hw_set_regs(ah, chan, macmode);
1459 ath9k_hw_init_chain_masks(ah);
1460
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301461 if (OLC_FOR_AR9280_20_LATER)
1462 ath9k_olc_init(ah);
1463
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001464 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001465 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001466 channel->max_antenna_gain * 2,
1467 channel->max_power * 2,
1468 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001469 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001470
Sujithf1dc5602008-10-29 10:16:30 +05301471 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001472 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
1473 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001474 return -EIO;
1475 }
1476
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001477 return 0;
1478}
1479
Sujithf1dc5602008-10-29 10:16:30 +05301480/****************************************/
1481/* Reset and Channel Switching Routines */
1482/****************************************/
1483
Sujithcbe61d82009-02-09 13:27:12 +05301484static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301485{
1486 u32 rfMode = 0;
1487
1488 if (chan == NULL)
1489 return;
1490
1491 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1492 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1493
1494 if (!AR_SREV_9280_10_OR_LATER(ah))
1495 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1496 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1497
1498 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1499 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1500
1501 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1502}
1503
Sujithcbe61d82009-02-09 13:27:12 +05301504static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301505{
1506 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1507}
1508
Sujithcbe61d82009-02-09 13:27:12 +05301509static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301510{
1511 u32 regval;
1512
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001513 /*
1514 * set AHB_MODE not to do cacheline prefetches
1515 */
Sujithf1dc5602008-10-29 10:16:30 +05301516 regval = REG_READ(ah, AR_AHB_MODE);
1517 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1518
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001519 /*
1520 * let mac dma reads be in 128 byte chunks
1521 */
Sujithf1dc5602008-10-29 10:16:30 +05301522 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1523 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1524
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001525 /*
1526 * Restore TX Trigger Level to its pre-reset value.
1527 * The initial value depends on whether aggregation is enabled, and is
1528 * adjusted whenever underruns are detected.
1529 */
Sujith2660b812009-02-09 13:27:26 +05301530 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301531
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001532 /*
1533 * let mac dma writes be in 128 byte chunks
1534 */
Sujithf1dc5602008-10-29 10:16:30 +05301535 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1536 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1537
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001538 /*
1539 * Setup receive FIFO threshold to hold off TX activities
1540 */
Sujithf1dc5602008-10-29 10:16:30 +05301541 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1542
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001543 /*
1544 * reduce the number of usable entries in PCU TXBUF to avoid
1545 * wrap around issues.
1546 */
Sujithf1dc5602008-10-29 10:16:30 +05301547 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001548 /* For AR9285 the number of Fifos are reduced to half.
1549 * So set the usable tx buf size also to half to
1550 * avoid data/delimiter underruns
1551 */
Sujithf1dc5602008-10-29 10:16:30 +05301552 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1553 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001554 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301555 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1556 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1557 }
1558}
1559
Sujithcbe61d82009-02-09 13:27:12 +05301560static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301561{
1562 u32 val;
1563
1564 val = REG_READ(ah, AR_STA_ID1);
1565 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1566 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001567 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301568 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1569 | AR_STA_ID1_KSRCH_MODE);
1570 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1571 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001572 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001573 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301574 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1575 | AR_STA_ID1_KSRCH_MODE);
1576 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1577 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001578 case NL80211_IFTYPE_STATION:
1579 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301580 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1581 break;
1582 }
1583}
1584
Sujithcbe61d82009-02-09 13:27:12 +05301585static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001586 u32 coef_scaled,
1587 u32 *coef_mantissa,
1588 u32 *coef_exponent)
1589{
1590 u32 coef_exp, coef_man;
1591
1592 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1593 if ((coef_scaled >> coef_exp) & 0x1)
1594 break;
1595
1596 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1597
1598 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1599
1600 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1601 *coef_exponent = coef_exp - 16;
1602}
1603
Sujithcbe61d82009-02-09 13:27:12 +05301604static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301605 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001606{
1607 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1608 u32 clockMhzScaled = 0x64000000;
1609 struct chan_centers centers;
1610
1611 if (IS_CHAN_HALF_RATE(chan))
1612 clockMhzScaled = clockMhzScaled >> 1;
1613 else if (IS_CHAN_QUARTER_RATE(chan))
1614 clockMhzScaled = clockMhzScaled >> 2;
1615
1616 ath9k_hw_get_channel_centers(ah, chan, &centers);
1617 coef_scaled = clockMhzScaled / centers.synth_center;
1618
1619 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1620 &ds_coef_exp);
1621
1622 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1623 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1624 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1625 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1626
1627 coef_scaled = (9 * coef_scaled) / 10;
1628
1629 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1630 &ds_coef_exp);
1631
1632 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1633 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1634 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1635 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1636}
1637
Sujithcbe61d82009-02-09 13:27:12 +05301638static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301639{
1640 u32 rst_flags;
1641 u32 tmpReg;
1642
Sujith70768492009-02-16 13:23:12 +05301643 if (AR_SREV_9100(ah)) {
1644 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1645 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1646 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1647 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1648 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1649 }
1650
Sujithf1dc5602008-10-29 10:16:30 +05301651 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1652 AR_RTC_FORCE_WAKE_ON_INT);
1653
1654 if (AR_SREV_9100(ah)) {
1655 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1656 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1657 } else {
1658 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1659 if (tmpReg &
1660 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1661 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1662 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1663 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1664 } else {
1665 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1666 }
1667
1668 rst_flags = AR_RTC_RC_MAC_WARM;
1669 if (type == ATH9K_RESET_COLD)
1670 rst_flags |= AR_RTC_RC_MAC_COLD;
1671 }
1672
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001673 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301674 udelay(50);
1675
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001676 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301677 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001678 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1679 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301680 return false;
1681 }
1682
1683 if (!AR_SREV_9100(ah))
1684 REG_WRITE(ah, AR_RC, 0);
1685
1686 ath9k_hw_init_pll(ah, NULL);
1687
1688 if (AR_SREV_9100(ah))
1689 udelay(50);
1690
1691 return true;
1692}
1693
Sujithcbe61d82009-02-09 13:27:12 +05301694static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301695{
1696 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1697 AR_RTC_FORCE_WAKE_ON_INT);
1698
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301699 if (!AR_SREV_9100(ah))
1700 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1701
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001702 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301703 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301704
1705 if (!AR_SREV_9100(ah))
1706 REG_WRITE(ah, AR_RC, 0);
1707
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001708 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301709
1710 if (!ath9k_hw_wait(ah,
1711 AR_RTC_STATUS,
1712 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301713 AR_RTC_STATUS_ON,
1714 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001715 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
1716 "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301717 return false;
1718 }
1719
1720 ath9k_hw_read_revisions(ah);
1721
1722 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1723}
1724
Sujithcbe61d82009-02-09 13:27:12 +05301725static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301726{
1727 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1728 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1729
1730 switch (type) {
1731 case ATH9K_RESET_POWER_ON:
1732 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301733 case ATH9K_RESET_WARM:
1734 case ATH9K_RESET_COLD:
1735 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301736 default:
1737 return false;
1738 }
1739}
1740
Sujithcbe61d82009-02-09 13:27:12 +05301741static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +05301742 enum ath9k_ht_macmode macmode)
1743{
1744 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301745 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301746
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301747 if (AR_SREV_9285_10_OR_LATER(ah))
1748 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1749 AR_PHY_FC_ENABLE_DAC_FIFO);
1750
Sujithf1dc5602008-10-29 10:16:30 +05301751 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301752 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301753
1754 if (IS_CHAN_HT40(chan)) {
1755 phymode |= AR_PHY_FC_DYN2040_EN;
1756
1757 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1758 (chan->chanmode == CHANNEL_G_HT40PLUS))
1759 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1760
Sujithf1dc5602008-10-29 10:16:30 +05301761 }
1762 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1763
1764 ath9k_hw_set11nmac2040(ah, macmode);
1765
1766 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1767 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1768}
1769
Sujithcbe61d82009-02-09 13:27:12 +05301770static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301771 struct ath9k_channel *chan)
1772{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301773 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301774 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1775 return false;
1776 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301777 return false;
1778
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001779 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301780 return false;
1781
Sujith2660b812009-02-09 13:27:26 +05301782 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301783 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301784 ath9k_hw_set_rfmode(ah, chan);
1785
1786 return true;
1787}
1788
Sujithcbe61d82009-02-09 13:27:12 +05301789static bool ath9k_hw_channel_change(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301790 struct ath9k_channel *chan,
1791 enum ath9k_ht_macmode macmode)
1792{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001793 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001794 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001795 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301796 u32 synthDelay, qnum;
1797
1798 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1799 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001800 ath_print(common, ATH_DBG_QUEUE,
1801 "Transmit frames pending on "
1802 "queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301803 return false;
1804 }
1805 }
1806
1807 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1808 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301809 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001810 ath_print(common, ATH_DBG_FATAL,
1811 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301812 return false;
1813 }
1814
1815 ath9k_hw_set_regs(ah, chan, macmode);
1816
1817 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001818 ath9k_hw_ar9280_set_channel(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301819 } else {
1820 if (!(ath9k_hw_set_channel(ah, chan))) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001821 ath_print(common, ATH_DBG_FATAL,
1822 "Failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301823 return false;
1824 }
1825 }
1826
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001827 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001828 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301829 channel->max_antenna_gain * 2,
1830 channel->max_power * 2,
1831 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001832 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301833
1834 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301835 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301836 synthDelay = (4 * synthDelay) / 22;
1837 else
1838 synthDelay /= 10;
1839
1840 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1841
1842 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1843
1844 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1845 ath9k_hw_set_delta_slope(ah, chan);
1846
1847 if (AR_SREV_9280_10_OR_LATER(ah))
1848 ath9k_hw_9280_spur_mitigate(ah, chan);
1849 else
1850 ath9k_hw_spur_mitigate(ah, chan);
1851
1852 if (!chan->oneTimeCalsDone)
1853 chan->oneTimeCalsDone = true;
1854
1855 return true;
1856}
1857
Sujithcbe61d82009-02-09 13:27:12 +05301858static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001859{
1860 int bb_spur = AR_NO_SPUR;
1861 int freq;
1862 int bin, cur_bin;
1863 int bb_spur_off, spur_subchannel_sd;
1864 int spur_freq_sd;
1865 int spur_delta_phase;
1866 int denominator;
1867 int upper, lower, cur_vit_mask;
1868 int tmp, newVal;
1869 int i;
1870 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1871 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1872 };
1873 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1874 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1875 };
1876 int inc[4] = { 0, 100, 0, 0 };
1877 struct chan_centers centers;
1878
1879 int8_t mask_m[123];
1880 int8_t mask_p[123];
1881 int8_t mask_amt;
1882 int tmp_mask;
1883 int cur_bb_spur;
1884 bool is2GHz = IS_CHAN_2GHZ(chan);
1885
1886 memset(&mask_m, 0, sizeof(int8_t) * 123);
1887 memset(&mask_p, 0, sizeof(int8_t) * 123);
1888
1889 ath9k_hw_get_channel_centers(ah, chan, &centers);
1890 freq = centers.synth_center;
1891
Sujith2660b812009-02-09 13:27:26 +05301892 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001893 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301894 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001895
1896 if (is2GHz)
1897 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1898 else
1899 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1900
1901 if (AR_NO_SPUR == cur_bb_spur)
1902 break;
1903 cur_bb_spur = cur_bb_spur - freq;
1904
1905 if (IS_CHAN_HT40(chan)) {
1906 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1907 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1908 bb_spur = cur_bb_spur;
1909 break;
1910 }
1911 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1912 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1913 bb_spur = cur_bb_spur;
1914 break;
1915 }
1916 }
1917
1918 if (AR_NO_SPUR == bb_spur) {
1919 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1920 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1921 return;
1922 } else {
1923 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1924 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1925 }
1926
1927 bin = bb_spur * 320;
1928
1929 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1930
1931 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1932 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1933 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1934 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1935 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1936
1937 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1938 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1939 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1940 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1941 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1942 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1943
1944 if (IS_CHAN_HT40(chan)) {
1945 if (bb_spur < 0) {
1946 spur_subchannel_sd = 1;
1947 bb_spur_off = bb_spur + 10;
1948 } else {
1949 spur_subchannel_sd = 0;
1950 bb_spur_off = bb_spur - 10;
1951 }
1952 } else {
1953 spur_subchannel_sd = 0;
1954 bb_spur_off = bb_spur;
1955 }
1956
1957 if (IS_CHAN_HT40(chan))
1958 spur_delta_phase =
1959 ((bb_spur * 262144) /
1960 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1961 else
1962 spur_delta_phase =
1963 ((bb_spur * 524288) /
1964 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1965
1966 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1967 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1968
1969 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1970 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1971 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1972 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1973
1974 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
1975 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
1976
1977 cur_bin = -6000;
1978 upper = bin + 100;
1979 lower = bin - 100;
1980
1981 for (i = 0; i < 4; i++) {
1982 int pilot_mask = 0;
1983 int chan_mask = 0;
1984 int bp = 0;
1985 for (bp = 0; bp < 30; bp++) {
1986 if ((cur_bin > lower) && (cur_bin < upper)) {
1987 pilot_mask = pilot_mask | 0x1 << bp;
1988 chan_mask = chan_mask | 0x1 << bp;
1989 }
1990 cur_bin += 100;
1991 }
1992 cur_bin += inc[i];
1993 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
1994 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
1995 }
1996
1997 cur_vit_mask = 6100;
1998 upper = bin + 120;
1999 lower = bin - 120;
2000
2001 for (i = 0; i < 123; i++) {
2002 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002003
2004 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002005 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002006
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002007 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002008 mask_amt = 1;
2009 else
2010 mask_amt = 0;
2011 if (cur_vit_mask < 0)
2012 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2013 else
2014 mask_p[cur_vit_mask / 100] = mask_amt;
2015 }
2016 cur_vit_mask -= 100;
2017 }
2018
2019 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2020 | (mask_m[48] << 26) | (mask_m[49] << 24)
2021 | (mask_m[50] << 22) | (mask_m[51] << 20)
2022 | (mask_m[52] << 18) | (mask_m[53] << 16)
2023 | (mask_m[54] << 14) | (mask_m[55] << 12)
2024 | (mask_m[56] << 10) | (mask_m[57] << 8)
2025 | (mask_m[58] << 6) | (mask_m[59] << 4)
2026 | (mask_m[60] << 2) | (mask_m[61] << 0);
2027 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2028 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2029
2030 tmp_mask = (mask_m[31] << 28)
2031 | (mask_m[32] << 26) | (mask_m[33] << 24)
2032 | (mask_m[34] << 22) | (mask_m[35] << 20)
2033 | (mask_m[36] << 18) | (mask_m[37] << 16)
2034 | (mask_m[48] << 14) | (mask_m[39] << 12)
2035 | (mask_m[40] << 10) | (mask_m[41] << 8)
2036 | (mask_m[42] << 6) | (mask_m[43] << 4)
2037 | (mask_m[44] << 2) | (mask_m[45] << 0);
2038 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2039 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2040
2041 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2042 | (mask_m[18] << 26) | (mask_m[18] << 24)
2043 | (mask_m[20] << 22) | (mask_m[20] << 20)
2044 | (mask_m[22] << 18) | (mask_m[22] << 16)
2045 | (mask_m[24] << 14) | (mask_m[24] << 12)
2046 | (mask_m[25] << 10) | (mask_m[26] << 8)
2047 | (mask_m[27] << 6) | (mask_m[28] << 4)
2048 | (mask_m[29] << 2) | (mask_m[30] << 0);
2049 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2050 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2051
2052 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2053 | (mask_m[2] << 26) | (mask_m[3] << 24)
2054 | (mask_m[4] << 22) | (mask_m[5] << 20)
2055 | (mask_m[6] << 18) | (mask_m[7] << 16)
2056 | (mask_m[8] << 14) | (mask_m[9] << 12)
2057 | (mask_m[10] << 10) | (mask_m[11] << 8)
2058 | (mask_m[12] << 6) | (mask_m[13] << 4)
2059 | (mask_m[14] << 2) | (mask_m[15] << 0);
2060 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2061 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2062
2063 tmp_mask = (mask_p[15] << 28)
2064 | (mask_p[14] << 26) | (mask_p[13] << 24)
2065 | (mask_p[12] << 22) | (mask_p[11] << 20)
2066 | (mask_p[10] << 18) | (mask_p[9] << 16)
2067 | (mask_p[8] << 14) | (mask_p[7] << 12)
2068 | (mask_p[6] << 10) | (mask_p[5] << 8)
2069 | (mask_p[4] << 6) | (mask_p[3] << 4)
2070 | (mask_p[2] << 2) | (mask_p[1] << 0);
2071 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2072 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2073
2074 tmp_mask = (mask_p[30] << 28)
2075 | (mask_p[29] << 26) | (mask_p[28] << 24)
2076 | (mask_p[27] << 22) | (mask_p[26] << 20)
2077 | (mask_p[25] << 18) | (mask_p[24] << 16)
2078 | (mask_p[23] << 14) | (mask_p[22] << 12)
2079 | (mask_p[21] << 10) | (mask_p[20] << 8)
2080 | (mask_p[19] << 6) | (mask_p[18] << 4)
2081 | (mask_p[17] << 2) | (mask_p[16] << 0);
2082 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2083 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2084
2085 tmp_mask = (mask_p[45] << 28)
2086 | (mask_p[44] << 26) | (mask_p[43] << 24)
2087 | (mask_p[42] << 22) | (mask_p[41] << 20)
2088 | (mask_p[40] << 18) | (mask_p[39] << 16)
2089 | (mask_p[38] << 14) | (mask_p[37] << 12)
2090 | (mask_p[36] << 10) | (mask_p[35] << 8)
2091 | (mask_p[34] << 6) | (mask_p[33] << 4)
2092 | (mask_p[32] << 2) | (mask_p[31] << 0);
2093 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2094 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2095
2096 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2097 | (mask_p[59] << 26) | (mask_p[58] << 24)
2098 | (mask_p[57] << 22) | (mask_p[56] << 20)
2099 | (mask_p[55] << 18) | (mask_p[54] << 16)
2100 | (mask_p[53] << 14) | (mask_p[52] << 12)
2101 | (mask_p[51] << 10) | (mask_p[50] << 8)
2102 | (mask_p[49] << 6) | (mask_p[48] << 4)
2103 | (mask_p[47] << 2) | (mask_p[46] << 0);
2104 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2105 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2106}
2107
Sujithcbe61d82009-02-09 13:27:12 +05302108static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002109{
2110 int bb_spur = AR_NO_SPUR;
2111 int bin, cur_bin;
2112 int spur_freq_sd;
2113 int spur_delta_phase;
2114 int denominator;
2115 int upper, lower, cur_vit_mask;
2116 int tmp, new;
2117 int i;
2118 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2119 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2120 };
2121 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2122 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2123 };
2124 int inc[4] = { 0, 100, 0, 0 };
2125
2126 int8_t mask_m[123];
2127 int8_t mask_p[123];
2128 int8_t mask_amt;
2129 int tmp_mask;
2130 int cur_bb_spur;
2131 bool is2GHz = IS_CHAN_2GHZ(chan);
2132
2133 memset(&mask_m, 0, sizeof(int8_t) * 123);
2134 memset(&mask_p, 0, sizeof(int8_t) * 123);
2135
2136 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05302137 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002138 if (AR_NO_SPUR == cur_bb_spur)
2139 break;
2140 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2141 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2142 bb_spur = cur_bb_spur;
2143 break;
2144 }
2145 }
2146
2147 if (AR_NO_SPUR == bb_spur)
2148 return;
2149
2150 bin = bb_spur * 32;
2151
2152 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2153 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2154 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2155 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2156 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2157
2158 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2159
2160 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2161 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2162 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2163 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2164 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2165 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2166
2167 spur_delta_phase = ((bb_spur * 524288) / 100) &
2168 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2169
2170 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2171 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2172
2173 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2174 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2175 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2176 REG_WRITE(ah, AR_PHY_TIMING11, new);
2177
2178 cur_bin = -6000;
2179 upper = bin + 100;
2180 lower = bin - 100;
2181
2182 for (i = 0; i < 4; i++) {
2183 int pilot_mask = 0;
2184 int chan_mask = 0;
2185 int bp = 0;
2186 for (bp = 0; bp < 30; bp++) {
2187 if ((cur_bin > lower) && (cur_bin < upper)) {
2188 pilot_mask = pilot_mask | 0x1 << bp;
2189 chan_mask = chan_mask | 0x1 << bp;
2190 }
2191 cur_bin += 100;
2192 }
2193 cur_bin += inc[i];
2194 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2195 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2196 }
2197
2198 cur_vit_mask = 6100;
2199 upper = bin + 120;
2200 lower = bin - 120;
2201
2202 for (i = 0; i < 123; i++) {
2203 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002204
2205 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002206 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002207
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002208 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002209 mask_amt = 1;
2210 else
2211 mask_amt = 0;
2212 if (cur_vit_mask < 0)
2213 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2214 else
2215 mask_p[cur_vit_mask / 100] = mask_amt;
2216 }
2217 cur_vit_mask -= 100;
2218 }
2219
2220 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2221 | (mask_m[48] << 26) | (mask_m[49] << 24)
2222 | (mask_m[50] << 22) | (mask_m[51] << 20)
2223 | (mask_m[52] << 18) | (mask_m[53] << 16)
2224 | (mask_m[54] << 14) | (mask_m[55] << 12)
2225 | (mask_m[56] << 10) | (mask_m[57] << 8)
2226 | (mask_m[58] << 6) | (mask_m[59] << 4)
2227 | (mask_m[60] << 2) | (mask_m[61] << 0);
2228 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2229 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2230
2231 tmp_mask = (mask_m[31] << 28)
2232 | (mask_m[32] << 26) | (mask_m[33] << 24)
2233 | (mask_m[34] << 22) | (mask_m[35] << 20)
2234 | (mask_m[36] << 18) | (mask_m[37] << 16)
2235 | (mask_m[48] << 14) | (mask_m[39] << 12)
2236 | (mask_m[40] << 10) | (mask_m[41] << 8)
2237 | (mask_m[42] << 6) | (mask_m[43] << 4)
2238 | (mask_m[44] << 2) | (mask_m[45] << 0);
2239 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2240 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2241
2242 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2243 | (mask_m[18] << 26) | (mask_m[18] << 24)
2244 | (mask_m[20] << 22) | (mask_m[20] << 20)
2245 | (mask_m[22] << 18) | (mask_m[22] << 16)
2246 | (mask_m[24] << 14) | (mask_m[24] << 12)
2247 | (mask_m[25] << 10) | (mask_m[26] << 8)
2248 | (mask_m[27] << 6) | (mask_m[28] << 4)
2249 | (mask_m[29] << 2) | (mask_m[30] << 0);
2250 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2251 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2252
2253 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2254 | (mask_m[2] << 26) | (mask_m[3] << 24)
2255 | (mask_m[4] << 22) | (mask_m[5] << 20)
2256 | (mask_m[6] << 18) | (mask_m[7] << 16)
2257 | (mask_m[8] << 14) | (mask_m[9] << 12)
2258 | (mask_m[10] << 10) | (mask_m[11] << 8)
2259 | (mask_m[12] << 6) | (mask_m[13] << 4)
2260 | (mask_m[14] << 2) | (mask_m[15] << 0);
2261 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2262 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2263
2264 tmp_mask = (mask_p[15] << 28)
2265 | (mask_p[14] << 26) | (mask_p[13] << 24)
2266 | (mask_p[12] << 22) | (mask_p[11] << 20)
2267 | (mask_p[10] << 18) | (mask_p[9] << 16)
2268 | (mask_p[8] << 14) | (mask_p[7] << 12)
2269 | (mask_p[6] << 10) | (mask_p[5] << 8)
2270 | (mask_p[4] << 6) | (mask_p[3] << 4)
2271 | (mask_p[2] << 2) | (mask_p[1] << 0);
2272 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2273 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2274
2275 tmp_mask = (mask_p[30] << 28)
2276 | (mask_p[29] << 26) | (mask_p[28] << 24)
2277 | (mask_p[27] << 22) | (mask_p[26] << 20)
2278 | (mask_p[25] << 18) | (mask_p[24] << 16)
2279 | (mask_p[23] << 14) | (mask_p[22] << 12)
2280 | (mask_p[21] << 10) | (mask_p[20] << 8)
2281 | (mask_p[19] << 6) | (mask_p[18] << 4)
2282 | (mask_p[17] << 2) | (mask_p[16] << 0);
2283 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2284 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2285
2286 tmp_mask = (mask_p[45] << 28)
2287 | (mask_p[44] << 26) | (mask_p[43] << 24)
2288 | (mask_p[42] << 22) | (mask_p[41] << 20)
2289 | (mask_p[40] << 18) | (mask_p[39] << 16)
2290 | (mask_p[38] << 14) | (mask_p[37] << 12)
2291 | (mask_p[36] << 10) | (mask_p[35] << 8)
2292 | (mask_p[34] << 6) | (mask_p[33] << 4)
2293 | (mask_p[32] << 2) | (mask_p[31] << 0);
2294 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2295 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2296
2297 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2298 | (mask_p[59] << 26) | (mask_p[58] << 24)
2299 | (mask_p[57] << 22) | (mask_p[56] << 20)
2300 | (mask_p[55] << 18) | (mask_p[54] << 16)
2301 | (mask_p[53] << 14) | (mask_p[52] << 12)
2302 | (mask_p[51] << 10) | (mask_p[50] << 8)
2303 | (mask_p[49] << 6) | (mask_p[48] << 4)
2304 | (mask_p[47] << 2) | (mask_p[46] << 0);
2305 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2306 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2307}
2308
Johannes Berg3b319aa2009-06-13 14:50:26 +05302309static void ath9k_enable_rfkill(struct ath_hw *ah)
2310{
2311 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2312 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
2313
2314 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
2315 AR_GPIO_INPUT_MUX2_RFSILENT);
2316
2317 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
2318 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
2319}
2320
Sujithcbe61d82009-02-09 13:27:12 +05302321int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002322 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002323{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002324 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002325 u32 saveLedState;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002326 struct ath_softc *sc = ah->ah_sc;
Sujith2660b812009-02-09 13:27:26 +05302327 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002328 u32 saveDefAntenna;
2329 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05302330 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002331 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002332
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07002333 ah->txchainmask = common->tx_chainmask;
2334 ah->rxchainmask = common->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002335
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002336 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002337 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002338
Vasanthakumar Thiagarajan9ebef7992009-09-17 09:26:44 +05302339 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002340 ath9k_hw_getnf(ah, curchan);
2341
2342 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302343 (ah->chip_fullsleep != true) &&
2344 (ah->curchan != NULL) &&
2345 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002346 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302347 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05302348 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
2349 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002350
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002351 if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) {
Sujith2660b812009-02-09 13:27:26 +05302352 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002353 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002354 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002355 }
2356 }
2357
2358 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2359 if (saveDefAntenna == 0)
2360 saveDefAntenna = 1;
2361
2362 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2363
Sujith46fe7822009-09-17 09:25:25 +05302364 /* For chips on which RTC reset is done, save TSF before it gets cleared */
2365 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2366 tsf = ath9k_hw_gettsf64(ah);
2367
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002368 saveLedState = REG_READ(ah, AR_CFG_LED) &
2369 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2370 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2371
2372 ath9k_hw_mark_phy_inactive(ah);
2373
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002374 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2375 REG_WRITE(ah,
2376 AR9271_RESET_POWER_DOWN_CONTROL,
2377 AR9271_RADIO_RF_RST);
2378 udelay(50);
2379 }
2380
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002381 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002382 ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002383 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002384 }
2385
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002386 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2387 ah->htc_reset_init = false;
2388 REG_WRITE(ah,
2389 AR9271_RESET_POWER_DOWN_CONTROL,
2390 AR9271_GATE_MAC_CTL);
2391 udelay(50);
2392 }
2393
Sujith46fe7822009-09-17 09:25:25 +05302394 /* Restore TSF */
2395 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2396 ath9k_hw_settsf64(ah, tsf);
2397
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302398 if (AR_SREV_9280_10_OR_LATER(ah))
2399 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002400
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302401 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302402 /* Enable ASYNC FIFO */
2403 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2404 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2405 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2406 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2407 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2408 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2409 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2410 }
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002411 r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width);
2412 if (r)
2413 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002414
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002415 /* Setup MFP options for CCMP */
2416 if (AR_SREV_9280_20_OR_LATER(ah)) {
2417 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2418 * frames when constructing CCMP AAD. */
2419 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2420 0xc7ff);
2421 ah->sw_mgmt_crypto = false;
2422 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2423 /* Disable hardware crypto for management frames */
2424 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2425 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2426 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2427 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2428 ah->sw_mgmt_crypto = true;
2429 } else
2430 ah->sw_mgmt_crypto = true;
2431
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002432 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2433 ath9k_hw_set_delta_slope(ah, chan);
2434
2435 if (AR_SREV_9280_10_OR_LATER(ah))
2436 ath9k_hw_9280_spur_mitigate(ah, chan);
2437 else
2438 ath9k_hw_spur_mitigate(ah, chan);
2439
Sujithd6509152009-03-13 08:56:05 +05302440 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002441
2442 ath9k_hw_decrease_chain_power(ah, chan);
2443
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002444 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2445 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002446 | macStaId1
2447 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302448 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302449 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302450 | ah->sta_id1_defaults);
2451 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002452
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002453 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002454
2455 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2456
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002457 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002458
2459 REG_WRITE(ah, AR_ISR, ~0);
2460
2461 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2462
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002463 if (AR_SREV_9280_10_OR_LATER(ah))
2464 ath9k_hw_ar9280_set_channel(ah, chan);
2465 else
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002466 if (!(ath9k_hw_set_channel(ah, chan)))
2467 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002468
2469 for (i = 0; i < AR_NUM_DCU; i++)
2470 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2471
Sujith2660b812009-02-09 13:27:26 +05302472 ah->intr_txqs = 0;
2473 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002474 ath9k_hw_resettxqueue(ah, i);
2475
Sujith2660b812009-02-09 13:27:26 +05302476 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002477 ath9k_hw_init_qos(ah);
2478
Sujith2660b812009-02-09 13:27:26 +05302479 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302480 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302481
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002482 ath9k_hw_init_user_settings(ah);
2483
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302484 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302485 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2486 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2487 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2488 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2489 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2490 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2491
2492 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2493 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2494
2495 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2496 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2497 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2498 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2499 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302500 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302501 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2502 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2503 }
2504
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002505 REG_WRITE(ah, AR_STA_ID1,
2506 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2507
2508 ath9k_hw_set_dma(ah);
2509
2510 REG_WRITE(ah, AR_OBS, 8);
2511
Sujith0ef1f162009-03-30 15:28:35 +05302512 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002513 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2514 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2515 }
2516
2517 ath9k_hw_init_bb(ah, chan);
2518
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002519 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002520 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002521
Sujith2660b812009-02-09 13:27:26 +05302522 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002523 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2524 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2525 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2526 }
2527
2528 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2529
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002530 /*
2531 * For big endian systems turn on swapping for descriptors
2532 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002533 if (AR_SREV_9100(ah)) {
2534 u32 mask;
2535 mask = REG_READ(ah, AR_CFG);
2536 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002537 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302538 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002539 } else {
2540 mask =
2541 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2542 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002543 ath_print(common, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302544 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002545 }
2546 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002547 /* Configure AR9271 target WLAN */
2548 if (AR_SREV_9271(ah))
2549 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002550#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002551 else
2552 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002553#endif
2554 }
2555
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002556 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302557 ath9k_hw_btcoex_enable(ah);
2558
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002559 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002560}
2561
Sujithf1dc5602008-10-29 10:16:30 +05302562/************************/
2563/* Key Cache Management */
2564/************************/
2565
Sujithcbe61d82009-02-09 13:27:12 +05302566bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002567{
Sujithf1dc5602008-10-29 10:16:30 +05302568 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002569
Sujith2660b812009-02-09 13:27:26 +05302570 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002571 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2572 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002573 return false;
2574 }
2575
Sujithf1dc5602008-10-29 10:16:30 +05302576 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002577
Sujithf1dc5602008-10-29 10:16:30 +05302578 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2579 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2580 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2581 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2582 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2583 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2584 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2585 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2586
2587 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2588 u16 micentry = entry + 64;
2589
2590 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2591 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2592 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2593 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2594
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002595 }
2596
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002597 return true;
2598}
2599
Sujithcbe61d82009-02-09 13:27:12 +05302600bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002601{
Sujithf1dc5602008-10-29 10:16:30 +05302602 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002603
Sujith2660b812009-02-09 13:27:26 +05302604 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002605 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2606 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002607 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002608 }
2609
Sujithf1dc5602008-10-29 10:16:30 +05302610 if (mac != NULL) {
2611 macHi = (mac[5] << 8) | mac[4];
2612 macLo = (mac[3] << 24) |
2613 (mac[2] << 16) |
2614 (mac[1] << 8) |
2615 mac[0];
2616 macLo >>= 1;
2617 macLo |= (macHi & 1) << 31;
2618 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002619 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302620 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002621 }
Sujithf1dc5602008-10-29 10:16:30 +05302622 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2623 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002624
2625 return true;
2626}
2627
Sujithcbe61d82009-02-09 13:27:12 +05302628bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302629 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002630 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002631{
Sujith2660b812009-02-09 13:27:26 +05302632 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002633 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302634 u32 key0, key1, key2, key3, key4;
2635 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002636
Sujithf1dc5602008-10-29 10:16:30 +05302637 if (entry >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002638 ath_print(common, ATH_DBG_FATAL,
2639 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302640 return false;
2641 }
2642
2643 switch (k->kv_type) {
2644 case ATH9K_CIPHER_AES_OCB:
2645 keyType = AR_KEYTABLE_TYPE_AES;
2646 break;
2647 case ATH9K_CIPHER_AES_CCM:
2648 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002649 ath_print(common, ATH_DBG_ANY,
2650 "AES-CCM not supported by mac rev 0x%x\n",
2651 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002652 return false;
2653 }
Sujithf1dc5602008-10-29 10:16:30 +05302654 keyType = AR_KEYTABLE_TYPE_CCM;
2655 break;
2656 case ATH9K_CIPHER_TKIP:
2657 keyType = AR_KEYTABLE_TYPE_TKIP;
2658 if (ATH9K_IS_MIC_ENABLED(ah)
2659 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002660 ath_print(common, ATH_DBG_ANY,
2661 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002662 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002663 }
Sujithf1dc5602008-10-29 10:16:30 +05302664 break;
2665 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002666 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002667 ath_print(common, ATH_DBG_ANY,
2668 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302669 return false;
2670 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002671 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302672 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002673 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302674 keyType = AR_KEYTABLE_TYPE_104;
2675 else
2676 keyType = AR_KEYTABLE_TYPE_128;
2677 break;
2678 case ATH9K_CIPHER_CLR:
2679 keyType = AR_KEYTABLE_TYPE_CLR;
2680 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002681 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002682 ath_print(common, ATH_DBG_FATAL,
2683 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002684 return false;
2685 }
Sujithf1dc5602008-10-29 10:16:30 +05302686
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002687 key0 = get_unaligned_le32(k->kv_val + 0);
2688 key1 = get_unaligned_le16(k->kv_val + 4);
2689 key2 = get_unaligned_le32(k->kv_val + 6);
2690 key3 = get_unaligned_le16(k->kv_val + 10);
2691 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002692 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302693 key4 &= 0xff;
2694
Jouni Malinen672903b2009-03-02 15:06:31 +02002695 /*
2696 * Note: Key cache registers access special memory area that requires
2697 * two 32-bit writes to actually update the values in the internal
2698 * memory. Consequently, the exact order and pairs used here must be
2699 * maintained.
2700 */
2701
Sujithf1dc5602008-10-29 10:16:30 +05302702 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2703 u16 micentry = entry + 64;
2704
Jouni Malinen672903b2009-03-02 15:06:31 +02002705 /*
2706 * Write inverted key[47:0] first to avoid Michael MIC errors
2707 * on frames that could be sent or received at the same time.
2708 * The correct key will be written in the end once everything
2709 * else is ready.
2710 */
Sujithf1dc5602008-10-29 10:16:30 +05302711 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2712 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002713
2714 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302715 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2716 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002717
2718 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302719 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2720 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002721
2722 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302723 (void) ath9k_hw_keysetmac(ah, entry, mac);
2724
Sujith2660b812009-02-09 13:27:26 +05302725 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002726 /*
2727 * TKIP uses two key cache entries:
2728 * Michael MIC TX/RX keys in the same key cache entry
2729 * (idx = main index + 64):
2730 * key0 [31:0] = RX key [31:0]
2731 * key1 [15:0] = TX key [31:16]
2732 * key1 [31:16] = reserved
2733 * key2 [31:0] = RX key [63:32]
2734 * key3 [15:0] = TX key [15:0]
2735 * key3 [31:16] = reserved
2736 * key4 [31:0] = TX key [63:32]
2737 */
Sujithf1dc5602008-10-29 10:16:30 +05302738 u32 mic0, mic1, mic2, mic3, mic4;
2739
2740 mic0 = get_unaligned_le32(k->kv_mic + 0);
2741 mic2 = get_unaligned_le32(k->kv_mic + 4);
2742 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2743 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2744 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002745
2746 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302747 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2748 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002749
2750 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302751 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2752 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002753
2754 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302755 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2756 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2757 AR_KEYTABLE_TYPE_CLR);
2758
2759 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002760 /*
2761 * TKIP uses four key cache entries (two for group
2762 * keys):
2763 * Michael MIC TX/RX keys are in different key cache
2764 * entries (idx = main index + 64 for TX and
2765 * main index + 32 + 96 for RX):
2766 * key0 [31:0] = TX/RX MIC key [31:0]
2767 * key1 [31:0] = reserved
2768 * key2 [31:0] = TX/RX MIC key [63:32]
2769 * key3 [31:0] = reserved
2770 * key4 [31:0] = reserved
2771 *
2772 * Upper layer code will call this function separately
2773 * for TX and RX keys when these registers offsets are
2774 * used.
2775 */
Sujithf1dc5602008-10-29 10:16:30 +05302776 u32 mic0, mic2;
2777
2778 mic0 = get_unaligned_le32(k->kv_mic + 0);
2779 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002780
2781 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302782 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2783 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002784
2785 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302786 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2787 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002788
2789 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302790 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2791 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2792 AR_KEYTABLE_TYPE_CLR);
2793 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002794
2795 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302796 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2797 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002798
2799 /*
2800 * Write the correct (un-inverted) key[47:0] last to enable
2801 * TKIP now that all other registers are set with correct
2802 * values.
2803 */
Sujithf1dc5602008-10-29 10:16:30 +05302804 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2805 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2806 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002807 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302808 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2809 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002810
2811 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302812 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2813 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002814
2815 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302816 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2817 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2818
Jouni Malinen672903b2009-03-02 15:06:31 +02002819 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302820 (void) ath9k_hw_keysetmac(ah, entry, mac);
2821 }
2822
Sujithf1dc5602008-10-29 10:16:30 +05302823 return true;
2824}
2825
Sujithcbe61d82009-02-09 13:27:12 +05302826bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302827{
Sujith2660b812009-02-09 13:27:26 +05302828 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302829 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2830 if (val & AR_KEYTABLE_VALID)
2831 return true;
2832 }
2833 return false;
2834}
2835
2836/******************************/
2837/* Power Management (Chipset) */
2838/******************************/
2839
Sujithcbe61d82009-02-09 13:27:12 +05302840static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302841{
2842 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2843 if (setChip) {
2844 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2845 AR_RTC_FORCE_WAKE_EN);
2846 if (!AR_SREV_9100(ah))
2847 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2848
Gabor Juhosd03a66c2009-01-14 20:17:09 +01002849 REG_CLR_BIT(ah, (AR_RTC_RESET),
Sujithf1dc5602008-10-29 10:16:30 +05302850 AR_RTC_RESET_EN);
2851 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002852}
2853
Sujithcbe61d82009-02-09 13:27:12 +05302854static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002855{
Sujithf1dc5602008-10-29 10:16:30 +05302856 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2857 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302858 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002859
Sujithf1dc5602008-10-29 10:16:30 +05302860 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2861 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2862 AR_RTC_FORCE_WAKE_ON_INT);
2863 } else {
2864 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2865 AR_RTC_FORCE_WAKE_EN);
2866 }
2867 }
2868}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002869
Sujithcbe61d82009-02-09 13:27:12 +05302870static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302871{
2872 u32 val;
2873 int i;
2874
2875 if (setChip) {
2876 if ((REG_READ(ah, AR_RTC_STATUS) &
2877 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2878 if (ath9k_hw_set_reset_reg(ah,
2879 ATH9K_RESET_POWER_ON) != true) {
2880 return false;
2881 }
2882 }
2883 if (AR_SREV_9100(ah))
2884 REG_SET_BIT(ah, AR_RTC_RESET,
2885 AR_RTC_RESET_EN);
2886
2887 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2888 AR_RTC_FORCE_WAKE_EN);
2889 udelay(50);
2890
2891 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2892 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2893 if (val == AR_RTC_STATUS_ON)
2894 break;
2895 udelay(50);
2896 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2897 AR_RTC_FORCE_WAKE_EN);
2898 }
2899 if (i == 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002900 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
2901 "Failed to wakeup in %uus\n",
2902 POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302903 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002904 }
2905 }
2906
Sujithf1dc5602008-10-29 10:16:30 +05302907 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2908
2909 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002910}
2911
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002912bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302913{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002914 struct ath_common *common = ath9k_hw_common(ah);
Sujithcbe61d82009-02-09 13:27:12 +05302915 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302916 static const char *modes[] = {
2917 "AWAKE",
2918 "FULL-SLEEP",
2919 "NETWORK SLEEP",
2920 "UNDEFINED"
2921 };
Sujithf1dc5602008-10-29 10:16:30 +05302922
Gabor Juhoscbdec972009-07-24 17:27:22 +02002923 if (ah->power_mode == mode)
2924 return status;
2925
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002926 ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
2927 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302928
2929 switch (mode) {
2930 case ATH9K_PM_AWAKE:
2931 status = ath9k_hw_set_power_awake(ah, setChip);
2932 break;
2933 case ATH9K_PM_FULL_SLEEP:
2934 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302935 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302936 break;
2937 case ATH9K_PM_NETWORK_SLEEP:
2938 ath9k_set_power_network_sleep(ah, setChip);
2939 break;
2940 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002941 ath_print(common, ATH_DBG_FATAL,
2942 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302943 return false;
2944 }
Sujith2660b812009-02-09 13:27:26 +05302945 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302946
2947 return status;
2948}
2949
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002950/*
2951 * Helper for ASPM support.
2952 *
2953 * Disable PLL when in L0s as well as receiver clock when in L1.
2954 * This power saving option must be enabled through the SerDes.
2955 *
2956 * Programming the SerDes must go through the same 288 bit serial shift
2957 * register as the other analog registers. Hence the 9 writes.
2958 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302959void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302960{
Sujithf1dc5602008-10-29 10:16:30 +05302961 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302962 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302963
Sujith2660b812009-02-09 13:27:26 +05302964 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302965 return;
2966
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002967 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302968 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302969 return;
2970
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002971 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302972 if (!restore) {
2973 if (AR_SREV_9280_20_OR_LATER(ah)) {
2974 /*
2975 * AR9280 2.0 or later chips use SerDes values from the
2976 * initvals.h initialized depending on chipset during
2977 * ath9k_hw_init()
2978 */
2979 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2980 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2981 INI_RA(&ah->iniPcieSerdes, i, 1));
2982 }
2983 } else if (AR_SREV_9280(ah) &&
2984 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2985 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2986 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302987
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302988 /* RX shut off when elecidle is asserted */
2989 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2990 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2991 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2992
2993 /* Shut off CLKREQ active in L1 */
2994 if (ah->config.pcie_clock_req)
2995 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2996 else
2997 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2998
2999 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3000 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3001 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
3002
3003 /* Load the new settings */
3004 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
3005
3006 } else {
3007 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
3008 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
3009
3010 /* RX shut off when elecidle is asserted */
3011 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
3012 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
3013 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
3014
3015 /*
3016 * Ignore ah->ah_config.pcie_clock_req setting for
3017 * pre-AR9280 11n
3018 */
3019 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
3020
3021 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3022 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3023 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
3024
3025 /* Load the new settings */
3026 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05303027 }
Sujithf1dc5602008-10-29 10:16:30 +05303028
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303029 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05303030
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303031 /* set bit 19 to allow forcing of pcie core into L1 state */
3032 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05303033
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303034 /* Several PCIe massages to ensure proper behaviour */
3035 if (ah->config.pcie_waen) {
3036 val = ah->config.pcie_waen;
3037 if (!power_off)
3038 val &= (~AR_WA_D3_L1_DISABLE);
3039 } else {
3040 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3041 AR_SREV_9287(ah)) {
3042 val = AR9285_WA_DEFAULT;
3043 if (!power_off)
3044 val &= (~AR_WA_D3_L1_DISABLE);
3045 } else if (AR_SREV_9280(ah)) {
3046 /*
3047 * On AR9280 chips bit 22 of 0x4004 needs to be
3048 * set otherwise card may disappear.
3049 */
3050 val = AR9280_WA_DEFAULT;
3051 if (!power_off)
3052 val &= (~AR_WA_D3_L1_DISABLE);
3053 } else
3054 val = AR_WA_DEFAULT;
3055 }
Sujithf1dc5602008-10-29 10:16:30 +05303056
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303057 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05303058 }
3059
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303060 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003061 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303062 * Set PCIe workaround bits
3063 * bit 14 in WA register (disable L1) should only
3064 * be set when device enters D3 and be cleared
3065 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003066 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303067 if (ah->config.pcie_waen) {
3068 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
3069 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3070 } else {
3071 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3072 AR_SREV_9287(ah)) &&
3073 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
3074 (AR_SREV_9280(ah) &&
3075 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
3076 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3077 }
3078 }
Sujithf1dc5602008-10-29 10:16:30 +05303079 }
3080}
3081
3082/**********************/
3083/* Interrupt Handling */
3084/**********************/
3085
Sujithcbe61d82009-02-09 13:27:12 +05303086bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003087{
3088 u32 host_isr;
3089
3090 if (AR_SREV_9100(ah))
3091 return true;
3092
3093 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
3094 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
3095 return true;
3096
3097 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
3098 if ((host_isr & AR_INTR_SYNC_DEFAULT)
3099 && (host_isr != AR_INTR_SPURIOUS))
3100 return true;
3101
3102 return false;
3103}
3104
Sujithcbe61d82009-02-09 13:27:12 +05303105bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003106{
3107 u32 isr = 0;
3108 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05303109 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003110 u32 sync_cause = 0;
3111 bool fatal_int = false;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003112 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003113
3114 if (!AR_SREV_9100(ah)) {
3115 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
3116 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
3117 == AR_RTC_STATUS_ON) {
3118 isr = REG_READ(ah, AR_ISR);
3119 }
3120 }
3121
Sujithf1dc5602008-10-29 10:16:30 +05303122 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
3123 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003124
3125 *masked = 0;
3126
3127 if (!isr && !sync_cause)
3128 return false;
3129 } else {
3130 *masked = 0;
3131 isr = REG_READ(ah, AR_ISR);
3132 }
3133
3134 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003135 if (isr & AR_ISR_BCNMISC) {
3136 u32 isr2;
3137 isr2 = REG_READ(ah, AR_ISR_S2);
3138 if (isr2 & AR_ISR_S2_TIM)
3139 mask2 |= ATH9K_INT_TIM;
3140 if (isr2 & AR_ISR_S2_DTIM)
3141 mask2 |= ATH9K_INT_DTIM;
3142 if (isr2 & AR_ISR_S2_DTIMSYNC)
3143 mask2 |= ATH9K_INT_DTIMSYNC;
3144 if (isr2 & (AR_ISR_S2_CABEND))
3145 mask2 |= ATH9K_INT_CABEND;
3146 if (isr2 & AR_ISR_S2_GTT)
3147 mask2 |= ATH9K_INT_GTT;
3148 if (isr2 & AR_ISR_S2_CST)
3149 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05303150 if (isr2 & AR_ISR_S2_TSFOOR)
3151 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003152 }
3153
3154 isr = REG_READ(ah, AR_ISR_RAC);
3155 if (isr == 0xffffffff) {
3156 *masked = 0;
3157 return false;
3158 }
3159
3160 *masked = isr & ATH9K_INT_COMMON;
3161
Sujith0ef1f162009-03-30 15:28:35 +05303162 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003163 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
3164 *masked |= ATH9K_INT_RX;
3165 }
3166
3167 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
3168 *masked |= ATH9K_INT_RX;
3169 if (isr &
3170 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
3171 AR_ISR_TXEOL)) {
3172 u32 s0_s, s1_s;
3173
3174 *masked |= ATH9K_INT_TX;
3175
3176 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05303177 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
3178 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003179
3180 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05303181 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
3182 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003183 }
3184
3185 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003186 ath_print(common, ATH_DBG_INTERRUPT,
3187 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003188 }
3189
3190 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05303191 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003192 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
3193 if (isr5 & AR_ISR_S5_TIM_TIMER)
3194 *masked |= ATH9K_INT_TIM_TIMER;
3195 }
3196 }
3197
3198 *masked |= mask2;
3199 }
Sujithf1dc5602008-10-29 10:16:30 +05303200
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003201 if (AR_SREV_9100(ah))
3202 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303203
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303204 if (isr & AR_ISR_GENTMR) {
3205 u32 s5_s;
3206
3207 s5_s = REG_READ(ah, AR_ISR_S5_S);
3208 if (isr & AR_ISR_GENTMR) {
3209 ah->intr_gen_timer_trigger =
3210 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
3211
3212 ah->intr_gen_timer_thresh =
3213 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
3214
3215 if (ah->intr_gen_timer_trigger)
3216 *masked |= ATH9K_INT_GENTIMER;
3217
3218 }
3219 }
3220
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003221 if (sync_cause) {
3222 fatal_int =
3223 (sync_cause &
3224 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
3225 ? true : false;
3226
3227 if (fatal_int) {
3228 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003229 ath_print(common, ATH_DBG_ANY,
3230 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003231 }
3232 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003233 ath_print(common, ATH_DBG_ANY,
3234 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003235 }
Steven Luoa89bff92009-04-12 02:57:54 -07003236 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003237 }
3238 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003239 ath_print(common, ATH_DBG_INTERRUPT,
3240 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003241 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
3242 REG_WRITE(ah, AR_RC, 0);
3243 *masked |= ATH9K_INT_FATAL;
3244 }
3245 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003246 ath_print(common, ATH_DBG_INTERRUPT,
3247 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003248 }
3249
3250 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3251 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3252 }
Sujithf1dc5602008-10-29 10:16:30 +05303253
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003254 return true;
3255}
3256
Sujithcbe61d82009-02-09 13:27:12 +05303257enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003258{
Sujith2660b812009-02-09 13:27:26 +05303259 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003260 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303261 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003262 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003263
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003264 ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003265
3266 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003267 ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003268 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3269 (void) REG_READ(ah, AR_IER);
3270 if (!AR_SREV_9100(ah)) {
3271 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3272 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3273
3274 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3275 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3276 }
3277 }
3278
3279 mask = ints & ATH9K_INT_COMMON;
3280 mask2 = 0;
3281
3282 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05303283 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003284 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303285 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003286 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303287 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003288 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303289 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003290 mask |= AR_IMR_TXEOL;
3291 }
3292 if (ints & ATH9K_INT_RX) {
3293 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05303294 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003295 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3296 else
3297 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303298 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003299 mask |= AR_IMR_GENTMR;
3300 }
3301
3302 if (ints & (ATH9K_INT_BMISC)) {
3303 mask |= AR_IMR_BCNMISC;
3304 if (ints & ATH9K_INT_TIM)
3305 mask2 |= AR_IMR_S2_TIM;
3306 if (ints & ATH9K_INT_DTIM)
3307 mask2 |= AR_IMR_S2_DTIM;
3308 if (ints & ATH9K_INT_DTIMSYNC)
3309 mask2 |= AR_IMR_S2_DTIMSYNC;
3310 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05303311 mask2 |= AR_IMR_S2_CABEND;
3312 if (ints & ATH9K_INT_TSFOOR)
3313 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003314 }
3315
3316 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3317 mask |= AR_IMR_BCNMISC;
3318 if (ints & ATH9K_INT_GTT)
3319 mask2 |= AR_IMR_S2_GTT;
3320 if (ints & ATH9K_INT_CST)
3321 mask2 |= AR_IMR_S2_CST;
3322 }
3323
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003324 ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003325 REG_WRITE(ah, AR_IMR, mask);
3326 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3327 AR_IMR_S2_DTIM |
3328 AR_IMR_S2_DTIMSYNC |
3329 AR_IMR_S2_CABEND |
3330 AR_IMR_S2_CABTO |
3331 AR_IMR_S2_TSFOOR |
3332 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3333 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303334 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003335
Sujith60b67f52008-08-07 10:52:38 +05303336 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003337 if (ints & ATH9K_INT_TIM_TIMER)
3338 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3339 else
3340 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3341 }
3342
3343 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003344 ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003345 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3346 if (!AR_SREV_9100(ah)) {
3347 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3348 AR_INTR_MAC_IRQ);
3349 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3350
3351
3352 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3353 AR_INTR_SYNC_DEFAULT);
3354 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3355 AR_INTR_SYNC_DEFAULT);
3356 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003357 ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3358 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003359 }
3360
3361 return omask;
3362}
3363
Sujithf1dc5602008-10-29 10:16:30 +05303364/*******************/
3365/* Beacon Handling */
3366/*******************/
3367
Sujithcbe61d82009-02-09 13:27:12 +05303368void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003369{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003370 int flags = 0;
3371
Sujith2660b812009-02-09 13:27:26 +05303372 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003373
Sujith2660b812009-02-09 13:27:26 +05303374 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003375 case NL80211_IFTYPE_STATION:
3376 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003377 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3378 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3379 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3380 flags |= AR_TBTT_TIMER_EN;
3381 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003382 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003383 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003384 REG_SET_BIT(ah, AR_TXCFG,
3385 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3386 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3387 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303388 (ah->atim_window ? ah->
3389 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003390 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003391 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003392 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3393 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3394 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303395 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303396 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003397 REG_WRITE(ah, AR_NEXT_SWBA,
3398 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303399 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303400 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003401 flags |=
3402 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3403 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003404 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003405 ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
3406 "%s: unsupported opmode: %d\n",
3407 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003408 return;
3409 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003410 }
3411
3412 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3413 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3414 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3415 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3416
3417 beacon_period &= ~ATH9K_BEACON_ENA;
3418 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
3419 beacon_period &= ~ATH9K_BEACON_RESET_TSF;
3420 ath9k_hw_reset_tsf(ah);
3421 }
3422
3423 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3424}
3425
Sujithcbe61d82009-02-09 13:27:12 +05303426void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303427 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003428{
3429 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303430 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003431 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003432
3433 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3434
3435 REG_WRITE(ah, AR_BEACON_PERIOD,
3436 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3437 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3438 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3439
3440 REG_RMW_FIELD(ah, AR_RSSI_THR,
3441 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3442
3443 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3444
3445 if (bs->bs_sleepduration > beaconintval)
3446 beaconintval = bs->bs_sleepduration;
3447
3448 dtimperiod = bs->bs_dtimperiod;
3449 if (bs->bs_sleepduration > dtimperiod)
3450 dtimperiod = bs->bs_sleepduration;
3451
3452 if (beaconintval == dtimperiod)
3453 nextTbtt = bs->bs_nextdtim;
3454 else
3455 nextTbtt = bs->bs_nexttbtt;
3456
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003457 ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3458 ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3459 ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3460 ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003461
3462 REG_WRITE(ah, AR_NEXT_DTIM,
3463 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3464 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3465
3466 REG_WRITE(ah, AR_SLEEP1,
3467 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3468 | AR_SLEEP1_ASSUME_DTIM);
3469
Sujith60b67f52008-08-07 10:52:38 +05303470 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003471 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3472 else
3473 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3474
3475 REG_WRITE(ah, AR_SLEEP2,
3476 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3477
3478 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3479 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3480
3481 REG_SET_BIT(ah, AR_TIMER_MODE,
3482 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3483 AR_DTIM_TIMER_EN);
3484
Sujith4af9cf42009-02-12 10:06:47 +05303485 /* TSF Out of Range Threshold */
3486 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003487}
3488
Sujithf1dc5602008-10-29 10:16:30 +05303489/*******************/
3490/* HW Capabilities */
3491/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003492
Sujitheef7a572009-03-30 15:28:28 +05303493void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003494{
Sujith2660b812009-02-09 13:27:26 +05303495 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003496 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003497 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003498 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003499
Sujithf1dc5602008-10-29 10:16:30 +05303500 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003501
Sujithf74df6f2009-02-09 13:27:24 +05303502 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003503 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303504
Sujithf74df6f2009-02-09 13:27:24 +05303505 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303506 if (AR_SREV_9285_10_OR_LATER(ah))
3507 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003508 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303509
Sujithf74df6f2009-02-09 13:27:24 +05303510 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303511
Sujith2660b812009-02-09 13:27:26 +05303512 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303513 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003514 if (regulatory->current_rd == 0x64 ||
3515 regulatory->current_rd == 0x65)
3516 regulatory->current_rd += 5;
3517 else if (regulatory->current_rd == 0x41)
3518 regulatory->current_rd = 0x43;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003519 ath_print(common, ATH_DBG_REGULATORY,
3520 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003521 }
Sujithdc2222a2008-08-14 13:26:55 +05303522
Sujithf74df6f2009-02-09 13:27:24 +05303523 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303524 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003525
Sujithf1dc5602008-10-29 10:16:30 +05303526 if (eeval & AR5416_OPFLAGS_11A) {
3527 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303528 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303529 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3530 set_bit(ATH9K_MODE_11NA_HT20,
3531 pCap->wireless_modes);
3532 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3533 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3534 pCap->wireless_modes);
3535 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3536 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003537 }
3538 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003539 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003540
Sujithf1dc5602008-10-29 10:16:30 +05303541 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303542 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303543 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303544 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3545 set_bit(ATH9K_MODE_11NG_HT20,
3546 pCap->wireless_modes);
3547 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3548 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3549 pCap->wireless_modes);
3550 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3551 pCap->wireless_modes);
3552 }
3553 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003554 }
Sujithf1dc5602008-10-29 10:16:30 +05303555
Sujithf74df6f2009-02-09 13:27:24 +05303556 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003557 /*
3558 * For AR9271 we will temporarilly uses the rx chainmax as read from
3559 * the EEPROM.
3560 */
Sujith8147f5d2009-02-20 15:13:23 +05303561 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003562 !(eeval & AR5416_OPFLAGS_11A) &&
3563 !(AR_SREV_9271(ah)))
3564 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303565 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3566 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003567 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303568 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303569
Sujithd535a422009-02-09 13:27:06 +05303570 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303571 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303572
3573 pCap->low_2ghz_chan = 2312;
3574 pCap->high_2ghz_chan = 2732;
3575
3576 pCap->low_5ghz_chan = 4920;
3577 pCap->high_5ghz_chan = 6100;
3578
3579 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3580 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3581 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3582
3583 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3584 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3585 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3586
Sujith2660b812009-02-09 13:27:26 +05303587 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303588 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3589 else
3590 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3591
3592 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3593 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3594 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3595 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3596
3597 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3598 pCap->total_queues =
3599 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3600 else
3601 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3602
3603 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3604 pCap->keycache_size =
3605 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3606 else
3607 pCap->keycache_size = AR_KEYTABLE_SIZE;
3608
3609 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303610 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3611
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303612 if (AR_SREV_9285_10_OR_LATER(ah))
3613 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3614 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303615 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3616 else
3617 pCap->num_gpio_pins = AR_NUM_GPIO;
3618
Sujithf1dc5602008-10-29 10:16:30 +05303619 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3620 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3621 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3622 } else {
3623 pCap->rts_aggr_limit = (8 * 1024);
3624 }
3625
3626 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3627
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303628#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303629 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3630 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3631 ah->rfkill_gpio =
3632 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3633 ah->rfkill_polarity =
3634 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303635
3636 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3637 }
3638#endif
3639
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303640 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303641
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303642 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303643 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3644 else
3645 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3646
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003647 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303648 pCap->reg_cap =
3649 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3650 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3651 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3652 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3653 } else {
3654 pCap->reg_cap =
3655 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3656 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3657 }
3658
3659 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3660
3661 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303662 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303663 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303664 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303665
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303666 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003667 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003668 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3669 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303670
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303671 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003672 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3673 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303674 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003675 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303676 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303677 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003678 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303679 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003680}
3681
Sujithcbe61d82009-02-09 13:27:12 +05303682bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303683 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003684{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003685 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303686 switch (type) {
3687 case ATH9K_CAP_CIPHER:
3688 switch (capability) {
3689 case ATH9K_CIPHER_AES_CCM:
3690 case ATH9K_CIPHER_AES_OCB:
3691 case ATH9K_CIPHER_TKIP:
3692 case ATH9K_CIPHER_WEP:
3693 case ATH9K_CIPHER_MIC:
3694 case ATH9K_CIPHER_CLR:
3695 return true;
3696 default:
3697 return false;
3698 }
3699 case ATH9K_CAP_TKIP_MIC:
3700 switch (capability) {
3701 case 0:
3702 return true;
3703 case 1:
Sujith2660b812009-02-09 13:27:26 +05303704 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303705 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3706 false;
3707 }
3708 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303709 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303710 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303711 case ATH9K_CAP_DIVERSITY:
3712 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3713 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3714 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303715 case ATH9K_CAP_MCAST_KEYSRCH:
3716 switch (capability) {
3717 case 0:
3718 return true;
3719 case 1:
3720 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3721 return false;
3722 } else {
Sujith2660b812009-02-09 13:27:26 +05303723 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303724 AR_STA_ID1_MCAST_KSRCH) ? true :
3725 false;
3726 }
3727 }
3728 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303729 case ATH9K_CAP_TXPOW:
3730 switch (capability) {
3731 case 0:
3732 return 0;
3733 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003734 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303735 return 0;
3736 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003737 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303738 return 0;
3739 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003740 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303741 return 0;
3742 }
3743 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303744 case ATH9K_CAP_DS:
3745 return (AR_SREV_9280_20_OR_LATER(ah) &&
3746 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3747 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303748 default:
3749 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003750 }
Sujithf1dc5602008-10-29 10:16:30 +05303751}
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003752
Sujithcbe61d82009-02-09 13:27:12 +05303753bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303754 u32 capability, u32 setting, int *status)
3755{
Sujithf1dc5602008-10-29 10:16:30 +05303756 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003757
Sujithf1dc5602008-10-29 10:16:30 +05303758 switch (type) {
3759 case ATH9K_CAP_TKIP_MIC:
3760 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303761 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303762 AR_STA_ID1_CRPT_MIC_ENABLE;
3763 else
Sujith2660b812009-02-09 13:27:26 +05303764 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303765 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3766 return true;
3767 case ATH9K_CAP_DIVERSITY:
3768 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3769 if (setting)
3770 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3771 else
3772 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3773 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3774 return true;
3775 case ATH9K_CAP_MCAST_KEYSRCH:
3776 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303777 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303778 else
Sujith2660b812009-02-09 13:27:26 +05303779 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303780 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303781 default:
3782 return false;
3783 }
3784}
3785
3786/****************************/
3787/* GPIO / RFKILL / Antennae */
3788/****************************/
3789
Sujithcbe61d82009-02-09 13:27:12 +05303790static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303791 u32 gpio, u32 type)
3792{
3793 int addr;
3794 u32 gpio_shift, tmp;
3795
3796 if (gpio > 11)
3797 addr = AR_GPIO_OUTPUT_MUX3;
3798 else if (gpio > 5)
3799 addr = AR_GPIO_OUTPUT_MUX2;
3800 else
3801 addr = AR_GPIO_OUTPUT_MUX1;
3802
3803 gpio_shift = (gpio % 6) * 5;
3804
3805 if (AR_SREV_9280_20_OR_LATER(ah)
3806 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3807 REG_RMW(ah, addr, (type << gpio_shift),
3808 (0x1f << gpio_shift));
3809 } else {
3810 tmp = REG_READ(ah, addr);
3811 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3812 tmp &= ~(0x1f << gpio_shift);
3813 tmp |= (type << gpio_shift);
3814 REG_WRITE(ah, addr, tmp);
3815 }
3816}
3817
Sujithcbe61d82009-02-09 13:27:12 +05303818void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303819{
3820 u32 gpio_shift;
3821
Sujith2660b812009-02-09 13:27:26 +05303822 ASSERT(gpio < ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303823
3824 gpio_shift = gpio << 1;
3825
3826 REG_RMW(ah,
3827 AR_GPIO_OE_OUT,
3828 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3829 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3830}
3831
Sujithcbe61d82009-02-09 13:27:12 +05303832u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303833{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303834#define MS_REG_READ(x, y) \
3835 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3836
Sujith2660b812009-02-09 13:27:26 +05303837 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303838 return 0xffffffff;
3839
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303840 if (AR_SREV_9287_10_OR_LATER(ah))
3841 return MS_REG_READ(AR9287, gpio) != 0;
3842 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303843 return MS_REG_READ(AR9285, gpio) != 0;
3844 else if (AR_SREV_9280_10_OR_LATER(ah))
3845 return MS_REG_READ(AR928X, gpio) != 0;
3846 else
3847 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303848}
3849
Sujithcbe61d82009-02-09 13:27:12 +05303850void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303851 u32 ah_signal_type)
3852{
3853 u32 gpio_shift;
3854
3855 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3856
3857 gpio_shift = 2 * gpio;
3858
3859 REG_RMW(ah,
3860 AR_GPIO_OE_OUT,
3861 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3862 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3863}
3864
Sujithcbe61d82009-02-09 13:27:12 +05303865void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303866{
3867 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3868 AR_GPIO_BIT(gpio));
3869}
3870
Sujithcbe61d82009-02-09 13:27:12 +05303871u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303872{
3873 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3874}
3875
Sujithcbe61d82009-02-09 13:27:12 +05303876void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303877{
3878 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3879}
3880
Sujithcbe61d82009-02-09 13:27:12 +05303881bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303882 enum ath9k_ant_setting settings,
3883 struct ath9k_channel *chan,
3884 u8 *tx_chainmask,
3885 u8 *rx_chainmask,
3886 u8 *antenna_cfgd)
3887{
Sujithf1dc5602008-10-29 10:16:30 +05303888 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3889
3890 if (AR_SREV_9280(ah)) {
3891 if (!tx_chainmask_cfg) {
3892
3893 tx_chainmask_cfg = *tx_chainmask;
3894 rx_chainmask_cfg = *rx_chainmask;
3895 }
3896
3897 switch (settings) {
3898 case ATH9K_ANT_FIXED_A:
3899 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3900 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3901 *antenna_cfgd = true;
3902 break;
3903 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303904 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303905 ATH9K_ANTENNA1_CHAINMASK) {
3906 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3907 }
3908 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3909 *antenna_cfgd = true;
3910 break;
3911 case ATH9K_ANT_VARIABLE:
3912 *tx_chainmask = tx_chainmask_cfg;
3913 *rx_chainmask = rx_chainmask_cfg;
3914 *antenna_cfgd = true;
3915 break;
3916 default:
3917 break;
3918 }
3919 } else {
Sujith1cf68732009-08-13 09:34:32 +05303920 ah->config.diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303921 }
3922
3923 return true;
3924}
3925
3926/*********************/
3927/* General Operation */
3928/*********************/
3929
Sujithcbe61d82009-02-09 13:27:12 +05303930u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303931{
3932 u32 bits = REG_READ(ah, AR_RX_FILTER);
3933 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3934
3935 if (phybits & AR_PHY_ERR_RADAR)
3936 bits |= ATH9K_RX_FILTER_PHYRADAR;
3937 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3938 bits |= ATH9K_RX_FILTER_PHYERR;
3939
3940 return bits;
3941}
3942
Sujithcbe61d82009-02-09 13:27:12 +05303943void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303944{
3945 u32 phybits;
3946
Sujith7ea310b2009-09-03 12:08:43 +05303947 REG_WRITE(ah, AR_RX_FILTER, bits);
3948
Sujithf1dc5602008-10-29 10:16:30 +05303949 phybits = 0;
3950 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3951 phybits |= AR_PHY_ERR_RADAR;
3952 if (bits & ATH9K_RX_FILTER_PHYERR)
3953 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3954 REG_WRITE(ah, AR_PHY_ERR, phybits);
3955
3956 if (phybits)
3957 REG_WRITE(ah, AR_RXCFG,
3958 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3959 else
3960 REG_WRITE(ah, AR_RXCFG,
3961 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3962}
3963
Sujithcbe61d82009-02-09 13:27:12 +05303964bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303965{
3966 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
3967}
3968
Sujithcbe61d82009-02-09 13:27:12 +05303969bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303970{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003971 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303972 return false;
3973
3974 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
3975}
3976
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003977void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303978{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003979 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303980 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003981 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303982
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003983 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303984
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003985 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003986 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003987 channel->max_antenna_gain * 2,
3988 channel->max_power * 2,
3989 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003990 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303991}
3992
Sujithcbe61d82009-02-09 13:27:12 +05303993void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303994{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003995 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303996}
3997
Sujithcbe61d82009-02-09 13:27:12 +05303998void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303999{
Sujith2660b812009-02-09 13:27:26 +05304000 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05304001}
4002
Sujithcbe61d82009-02-09 13:27:12 +05304003void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05304004{
4005 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
4006 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
4007}
4008
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07004009void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304010{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07004011 struct ath_common *common = ath9k_hw_common(ah);
4012
4013 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
4014 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
4015 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05304016}
4017
Sujithcbe61d82009-02-09 13:27:12 +05304018u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304019{
4020 u64 tsf;
4021
4022 tsf = REG_READ(ah, AR_TSF_U32);
4023 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
4024
4025 return tsf;
4026}
4027
Sujithcbe61d82009-02-09 13:27:12 +05304028void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004029{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004030 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01004031 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004032}
4033
Sujithcbe61d82009-02-09 13:27:12 +05304034void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304035{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004036 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
4037 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004038 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4039 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004040
Sujithf1dc5602008-10-29 10:16:30 +05304041 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004042}
4043
Sujith54e4cec2009-08-07 09:45:09 +05304044void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004045{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004046 if (setting)
Sujith2660b812009-02-09 13:27:26 +05304047 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004048 else
Sujith2660b812009-02-09 13:27:26 +05304049 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004050}
4051
Sujithcbe61d82009-02-09 13:27:12 +05304052bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004053{
Sujithf1dc5602008-10-29 10:16:30 +05304054 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004055 ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
4056 "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05304057 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05304058 return false;
4059 } else {
4060 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05304061 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05304062 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004063 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004064}
4065
Sujithcbe61d82009-02-09 13:27:12 +05304066void ath9k_hw_set11nmac2040(struct ath_hw *ah, enum ath9k_ht_macmode mode)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004067{
Sujithf1dc5602008-10-29 10:16:30 +05304068 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004069
Sujithf1dc5602008-10-29 10:16:30 +05304070 if (mode == ATH9K_HT_MACMODE_2040 &&
Sujith2660b812009-02-09 13:27:26 +05304071 !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05304072 macmode = AR_2040_JOINED_RX_CLEAR;
4073 else
4074 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004075
Sujithf1dc5602008-10-29 10:16:30 +05304076 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004077}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304078
4079/* HW Generic timers configuration */
4080
4081static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
4082{
4083 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4084 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4085 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4086 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4087 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4088 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4089 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4090 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4091 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
4092 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
4093 AR_NDP2_TIMER_MODE, 0x0002},
4094 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
4095 AR_NDP2_TIMER_MODE, 0x0004},
4096 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
4097 AR_NDP2_TIMER_MODE, 0x0008},
4098 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
4099 AR_NDP2_TIMER_MODE, 0x0010},
4100 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
4101 AR_NDP2_TIMER_MODE, 0x0020},
4102 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
4103 AR_NDP2_TIMER_MODE, 0x0040},
4104 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
4105 AR_NDP2_TIMER_MODE, 0x0080}
4106};
4107
4108/* HW generic timer primitives */
4109
4110/* compute and clear index of rightmost 1 */
4111static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
4112{
4113 u32 b;
4114
4115 b = *mask;
4116 b &= (0-b);
4117 *mask &= ~b;
4118 b *= debruijn32;
4119 b >>= 27;
4120
4121 return timer_table->gen_timer_index[b];
4122}
4123
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05304124u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304125{
4126 return REG_READ(ah, AR_TSF_L32);
4127}
4128
4129struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
4130 void (*trigger)(void *),
4131 void (*overflow)(void *),
4132 void *arg,
4133 u8 timer_index)
4134{
4135 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4136 struct ath_gen_timer *timer;
4137
4138 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
4139
4140 if (timer == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004141 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
4142 "Failed to allocate memory"
4143 "for hw timer[%d]\n", timer_index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304144 return NULL;
4145 }
4146
4147 /* allocate a hardware generic timer slot */
4148 timer_table->timers[timer_index] = timer;
4149 timer->index = timer_index;
4150 timer->trigger = trigger;
4151 timer->overflow = overflow;
4152 timer->arg = arg;
4153
4154 return timer;
4155}
4156
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004157void ath9k_hw_gen_timer_start(struct ath_hw *ah,
4158 struct ath_gen_timer *timer,
4159 u32 timer_next,
4160 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304161{
4162 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4163 u32 tsf;
4164
4165 BUG_ON(!timer_period);
4166
4167 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
4168
4169 tsf = ath9k_hw_gettsf32(ah);
4170
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004171 ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
4172 "curent tsf %x period %x"
4173 "timer_next %x\n", tsf, timer_period, timer_next);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304174
4175 /*
4176 * Pull timer_next forward if the current TSF already passed it
4177 * because of software latency
4178 */
4179 if (timer_next < tsf)
4180 timer_next = tsf + timer_period;
4181
4182 /*
4183 * Program generic timer registers
4184 */
4185 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
4186 timer_next);
4187 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
4188 timer_period);
4189 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4190 gen_tmr_configuration[timer->index].mode_mask);
4191
4192 /* Enable both trigger and thresh interrupt masks */
4193 REG_SET_BIT(ah, AR_IMR_S5,
4194 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4195 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304196}
4197
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004198void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304199{
4200 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4201
4202 if ((timer->index < AR_FIRST_NDP_TIMER) ||
4203 (timer->index >= ATH_MAX_GEN_TIMER)) {
4204 return;
4205 }
4206
4207 /* Clear generic timer enable bits. */
4208 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4209 gen_tmr_configuration[timer->index].mode_mask);
4210
4211 /* Disable both trigger and thresh interrupt masks */
4212 REG_CLR_BIT(ah, AR_IMR_S5,
4213 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4214 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
4215
4216 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304217}
4218
4219void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
4220{
4221 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4222
4223 /* free the hardware generic timer slot */
4224 timer_table->timers[timer->index] = NULL;
4225 kfree(timer);
4226}
4227
4228/*
4229 * Generic Timer Interrupts handling
4230 */
4231void ath_gen_timer_isr(struct ath_hw *ah)
4232{
4233 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4234 struct ath_gen_timer *timer;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004235 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304236 u32 trigger_mask, thresh_mask, index;
4237
4238 /* get hardware generic timer interrupt status */
4239 trigger_mask = ah->intr_gen_timer_trigger;
4240 thresh_mask = ah->intr_gen_timer_thresh;
4241 trigger_mask &= timer_table->timer_mask.val;
4242 thresh_mask &= timer_table->timer_mask.val;
4243
4244 trigger_mask &= ~thresh_mask;
4245
4246 while (thresh_mask) {
4247 index = rightmost_index(timer_table, &thresh_mask);
4248 timer = timer_table->timers[index];
4249 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004250 ath_print(common, ATH_DBG_HWTIMER,
4251 "TSF overflow for Gen timer %d\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304252 timer->overflow(timer->arg);
4253 }
4254
4255 while (trigger_mask) {
4256 index = rightmost_index(timer_table, &trigger_mask);
4257 timer = timer_table->timers[index];
4258 BUG_ON(!timer);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07004259 ath_print(common, ATH_DBG_HWTIMER,
4260 "Gen timer[%d] trigger\n", index);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304261 timer->trigger(timer->arg);
4262 }
4263}