blob: e6ca3158759bde409d6c750790bd8409f20e1bc8 [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. Rodriguez4d6b2282009-09-07 04:52:26 -070097 DPRINTF(ah, ATH_DBG_ANY,
Sujith0caa7b12009-02-16 13:23:20 +053098 "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. Rodriguez4d6b2282009-09-07 04:52:26 -0700181 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +0530182 "Unknown phy %u (rate ix %u)\n",
Sujithf1dc5602008-10-29 10:16:30 +0530183 rates->info[rateix].phy, rateix);
184 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);
216 centers->ext_center =
217 centers->synth_center + (extoff *
Sujith2660b812009-02-09 13:27:26 +0530218 ((ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
Sujithf1dc5602008-10-29 10:16:30 +0530219 HT40_CHANNEL_CENTER_SHIFT : 15));
Sujithf1dc5602008-10-29 10:16:30 +0530220}
221
222/******************/
223/* Chip Revisions */
224/******************/
225
Sujithcbe61d82009-02-09 13:27:12 +0530226static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530227{
228 u32 val;
229
230 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
231
232 if (val == 0xFF) {
233 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530234 ah->hw_version.macVersion =
235 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
236 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530237 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530238 } else {
239 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530240 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530241
Sujithd535a422009-02-09 13:27:06 +0530242 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530243
Sujithd535a422009-02-09 13:27:06 +0530244 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530245 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530246 }
247}
248
Sujithcbe61d82009-02-09 13:27:12 +0530249static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530250{
251 u32 val;
252 int i;
253
254 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
255
256 for (i = 0; i < 8; i++)
257 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
258 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
259 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
260
261 return ath9k_hw_reverse_bits(val, 8);
262}
263
264/************************************/
265/* HW Attach, Detach, Init Routines */
266/************************************/
267
Sujithcbe61d82009-02-09 13:27:12 +0530268static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530269{
Sujithfeed0292009-01-29 11:37:35 +0530270 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530271 return;
272
273 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
274 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
275 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
276 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
277 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
278 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
279 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
280 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
281 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
282
283 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
284}
285
Sujithcbe61d82009-02-09 13:27:12 +0530286static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530287{
288 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. Rodriguez4d6b2282009-09-07 04:52:26 -0700306 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +0530307 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530308 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd46382008-11-28 22:18:05 +0530309 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530310 return false;
311 }
312 }
313 for (j = 0; j < 4; j++) {
314 wrData = patternData[j];
315 REG_WRITE(ah, addr, wrData);
316 rdData = REG_READ(ah, addr);
317 if (wrData != rdData) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700318 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +0530319 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530320 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd46382008-11-28 22:18:05 +0530321 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530322 return false;
323 }
324 }
325 REG_WRITE(ah, regAddr[i], regHold[i]);
326 }
327 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530328
Sujithf1dc5602008-10-29 10:16:30 +0530329 return true;
330}
331
332static const char *ath9k_hw_devname(u16 devid)
333{
334 switch (devid) {
335 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530336 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100337 case AR5416_DEVID_PCIE:
338 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530339 case AR9160_DEVID_PCI:
340 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100341 case AR5416_AR9100_DEVID:
342 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530343 case AR9280_DEVID_PCI:
344 case AR9280_DEVID_PCIE:
345 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530346 case AR9285_DEVID_PCIE:
347 return "Atheros 9285";
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530348 case AR5416_DEVID_AR9287_PCI:
349 case AR5416_DEVID_AR9287_PCIE:
350 return "Atheros 9287";
Sujithf1dc5602008-10-29 10:16:30 +0530351 }
352
353 return NULL;
354}
355
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700356static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700357{
358 int i;
359
Sujith2660b812009-02-09 13:27:26 +0530360 ah->config.dma_beacon_response_time = 2;
361 ah->config.sw_beacon_response_time = 10;
362 ah->config.additional_swba_backoff = 0;
363 ah->config.ack_6mb = 0x0;
364 ah->config.cwm_ignore_extcca = 0;
365 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530366 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530367 ah->config.pcie_waen = 0;
368 ah->config.analog_shiftreg = 1;
369 ah->config.ht_enable = 1;
370 ah->config.ofdm_trig_low = 200;
371 ah->config.ofdm_trig_high = 500;
372 ah->config.cck_trig_high = 200;
373 ah->config.cck_trig_low = 100;
374 ah->config.enable_ani = 1;
Sujith1cf68732009-08-13 09:34:32 +0530375 ah->config.diversity_control = ATH9K_ANT_VARIABLE;
Sujith2660b812009-02-09 13:27:26 +0530376 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377
378 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530379 ah->config.spurchans[i][0] = AR_NO_SPUR;
380 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700381 }
382
Sujith0ef1f162009-03-30 15:28:35 +0530383 ah->config.intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400384
385 /*
386 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
387 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
388 * This means we use it for all AR5416 devices, and the few
389 * minor PCI AR9280 devices out there.
390 *
391 * Serialization is required because these devices do not handle
392 * well the case of two concurrent reads/writes due to the latency
393 * involved. During one read/write another read/write can be issued
394 * on another CPU while the previous read/write may still be working
395 * on our hardware, if we hit this case the hardware poops in a loop.
396 * We prevent this by serializing reads and writes.
397 *
398 * This issue is not present on PCI-Express devices or pre-AR5416
399 * devices (legacy, 802.11abg).
400 */
401 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700402 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700403}
404
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700405static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700406{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700407 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
408
409 regulatory->country_code = CTRY_DEFAULT;
410 regulatory->power_limit = MAX_RATE_POWER;
411 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
412
Sujithd535a422009-02-09 13:27:06 +0530413 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530414 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700415
416 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700417 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530418 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700419 if (!AR_SREV_9100(ah))
420 ah->ah_flags = AH_USE_EEPROM;
421
Sujith2660b812009-02-09 13:27:26 +0530422 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530423 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
424 ah->beacon_interval = 100;
425 ah->enable_32kHz_clock = DONT_USE_32KHZ;
426 ah->slottime = (u32) -1;
427 ah->acktimeout = (u32) -1;
428 ah->ctstimeout = (u32) -1;
429 ah->globaltxtimeout = (u32) -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700430
Sujith2660b812009-02-09 13:27:26 +0530431 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700432
Gabor Juhoscbdec972009-07-24 17:27:22 +0200433 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700434}
435
Sujithcbe61d82009-02-09 13:27:12 +0530436static int ath9k_hw_rfattach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700437{
438 bool rfStatus = false;
439 int ecode = 0;
440
441 rfStatus = ath9k_hw_init_rf(ah, &ecode);
442 if (!rfStatus) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700443 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +0530444 "RF setup failed, status: %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445 return ecode;
446 }
447
448 return 0;
449}
450
Sujithcbe61d82009-02-09 13:27:12 +0530451static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700452{
453 u32 val;
454
455 REG_WRITE(ah, AR_PHY(0), 0x00000007);
456
457 val = ath9k_hw_get_radiorev(ah);
458 switch (val & AR_RADIO_SREV_MAJOR) {
459 case 0:
460 val = AR_RAD5133_SREV_MAJOR;
461 break;
462 case AR_RAD5133_SREV_MAJOR:
463 case AR_RAD5122_SREV_MAJOR:
464 case AR_RAD2133_SREV_MAJOR:
465 case AR_RAD2122_SREV_MAJOR:
466 break;
467 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700468 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +0530469 "Radio Chip Rev 0x%02X not supported\n",
470 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700471 return -EOPNOTSUPP;
472 }
473
Sujithd535a422009-02-09 13:27:06 +0530474 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700475
476 return 0;
477}
478
Sujithcbe61d82009-02-09 13:27:12 +0530479static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700480{
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700481 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530482 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700483 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530484 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700485
Sujithf1dc5602008-10-29 10:16:30 +0530486 sum = 0;
487 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530488 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530489 sum += eeval;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700490 common->macaddr[2 * i] = eeval >> 8;
491 common->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700492 }
Sujithd8baa932009-03-30 15:28:25 +0530493 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530494 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700495
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700496 return 0;
497}
498
Sujithcbe61d82009-02-09 13:27:12 +0530499static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530500{
501 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530502
Sujithf74df6f2009-02-09 13:27:24 +0530503 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
504 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530505
506 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530507 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530508 ar9280Modes_backoff_13db_rxgain_9280_2,
509 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
510 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530511 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530512 ar9280Modes_backoff_23db_rxgain_9280_2,
513 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
514 else
Sujith2660b812009-02-09 13:27:26 +0530515 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530516 ar9280Modes_original_rxgain_9280_2,
517 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530518 } else {
Sujith2660b812009-02-09 13:27:26 +0530519 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530520 ar9280Modes_original_rxgain_9280_2,
521 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530522 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530523}
524
Sujithcbe61d82009-02-09 13:27:12 +0530525static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530526{
527 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530528
Sujithf74df6f2009-02-09 13:27:24 +0530529 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
530 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530531
532 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530533 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530534 ar9280Modes_high_power_tx_gain_9280_2,
535 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
536 else
Sujith2660b812009-02-09 13:27:26 +0530537 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530538 ar9280Modes_original_tx_gain_9280_2,
539 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530540 } else {
Sujith2660b812009-02-09 13:27:26 +0530541 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530542 ar9280Modes_original_tx_gain_9280_2,
543 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530544 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530545}
546
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700547static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700548{
549 int ecode;
550
Sujithd8baa932009-03-30 15:28:25 +0530551 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700552 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700553
554 ecode = ath9k_hw_rf_claim(ah);
555 if (ecode != 0)
556 return ecode;
557
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700558 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700559 if (ecode != 0)
560 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530561
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700562 DPRINTF(ah, ATH_DBG_CONFIG, "Eeprom VER: %d, REV: %d\n",
Sujith7d01b222009-03-13 08:55:55 +0530563 ah->eep_ops->get_eeprom_ver(ah), ah->eep_ops->get_eeprom_rev(ah));
564
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700565 ecode = ath9k_hw_rfattach(ah);
566 if (ecode != 0)
567 return ecode;
568
569 if (!AR_SREV_9100(ah)) {
570 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700571 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700572 }
Sujithf1dc5602008-10-29 10:16:30 +0530573
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700574 return 0;
575}
576
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700577static bool ath9k_hw_devid_supported(u16 devid)
578{
579 switch (devid) {
580 case AR5416_DEVID_PCI:
581 case AR5416_DEVID_PCIE:
582 case AR5416_AR9100_DEVID:
583 case AR9160_DEVID_PCI:
584 case AR9280_DEVID_PCI:
585 case AR9280_DEVID_PCIE:
586 case AR9285_DEVID_PCIE:
587 case AR5416_DEVID_AR9287_PCI:
588 case AR5416_DEVID_AR9287_PCIE:
589 return true;
590 default:
591 break;
592 }
593 return false;
594}
595
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700596static bool ath9k_hw_macversion_supported(u32 macversion)
597{
598 switch (macversion) {
599 case AR_SREV_VERSION_5416_PCI:
600 case AR_SREV_VERSION_5416_PCIE:
601 case AR_SREV_VERSION_9160:
602 case AR_SREV_VERSION_9100:
603 case AR_SREV_VERSION_9280:
604 case AR_SREV_VERSION_9285:
605 case AR_SREV_VERSION_9287:
606 return true;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400607 /* Not yet */
608 case AR_SREV_VERSION_9271:
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700609 default:
610 break;
611 }
612 return false;
613}
614
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700615static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700616{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700617 if (AR_SREV_9160_10_OR_LATER(ah)) {
618 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530619 ah->iq_caldata.calData = &iq_cal_single_sample;
620 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700621 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530622 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700623 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530624 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700625 &adc_init_dc_cal;
626 } else {
Sujith2660b812009-02-09 13:27:26 +0530627 ah->iq_caldata.calData = &iq_cal_multi_sample;
628 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700629 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530630 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700631 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530632 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700633 &adc_init_dc_cal;
634 }
Sujith2660b812009-02-09 13:27:26 +0530635 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700636 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700637}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700638
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700639static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
640{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400641 if (AR_SREV_9271(ah)) {
642 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0,
643 ARRAY_SIZE(ar9271Modes_9271_1_0), 6);
644 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0,
645 ARRAY_SIZE(ar9271Common_9271_1_0), 2);
646 return;
647 }
648
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530649 if (AR_SREV_9287_11_OR_LATER(ah)) {
650 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
651 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
652 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
653 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
654 if (ah->config.pcie_clock_req)
655 INIT_INI_ARRAY(&ah->iniPcieSerdes,
656 ar9287PciePhy_clkreq_off_L1_9287_1_1,
657 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
658 else
659 INIT_INI_ARRAY(&ah->iniPcieSerdes,
660 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
661 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
662 2);
663 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
664 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
665 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
666 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
667 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700668
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530669 if (ah->config.pcie_clock_req)
670 INIT_INI_ARRAY(&ah->iniPcieSerdes,
671 ar9287PciePhy_clkreq_off_L1_9287_1_0,
672 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
673 else
674 INIT_INI_ARRAY(&ah->iniPcieSerdes,
675 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
676 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
677 2);
678 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
679
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530680
Sujith2660b812009-02-09 13:27:26 +0530681 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530682 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530683 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530684 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
685
Sujith2660b812009-02-09 13:27:26 +0530686 if (ah->config.pcie_clock_req) {
687 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530688 ar9285PciePhy_clkreq_off_L1_9285_1_2,
689 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
690 } else {
Sujith2660b812009-02-09 13:27:26 +0530691 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530692 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
693 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
694 2);
695 }
696 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530697 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530698 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530699 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530700 ARRAY_SIZE(ar9285Common_9285), 2);
701
Sujith2660b812009-02-09 13:27:26 +0530702 if (ah->config.pcie_clock_req) {
703 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530704 ar9285PciePhy_clkreq_off_L1_9285,
705 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
706 } else {
Sujith2660b812009-02-09 13:27:26 +0530707 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530708 ar9285PciePhy_clkreq_always_on_L1_9285,
709 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
710 }
711 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530712 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700713 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530714 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700715 ARRAY_SIZE(ar9280Common_9280_2), 2);
716
Sujith2660b812009-02-09 13:27:26 +0530717 if (ah->config.pcie_clock_req) {
718 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530719 ar9280PciePhy_clkreq_off_L1_9280,
720 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700721 } else {
Sujith2660b812009-02-09 13:27:26 +0530722 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530723 ar9280PciePhy_clkreq_always_on_L1_9280,
724 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700725 }
Sujith2660b812009-02-09 13:27:26 +0530726 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700727 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530728 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700729 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700731 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530732 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700733 ARRAY_SIZE(ar9280Common_9280), 2);
734 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530735 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700736 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530737 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700738 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530739 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700740 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530741 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700742 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530743 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530747 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530749 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530751 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700754 ARRAY_SIZE(ar5416Bank7_9160), 2);
755 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530756 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700757 ar5416Addac_91601_1,
758 ARRAY_SIZE(ar5416Addac_91601_1), 2);
759 } else {
Sujith2660b812009-02-09 13:27:26 +0530760 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 ARRAY_SIZE(ar5416Addac_9160), 2);
762 }
763 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530764 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530766 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530784 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700785 ARRAY_SIZE(ar5416Addac_9100), 2);
786 } else {
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530789 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700790 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530791 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530793 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530807 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700808 ARRAY_SIZE(ar5416Addac), 2);
809 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700810}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700811
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700812static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
813{
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530814 if (AR_SREV_9287_11_OR_LATER(ah))
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530815 INIT_INI_ARRAY(&ah->iniModesRxGain,
816 ar9287Modes_rx_gain_9287_1_1,
817 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
818 else if (AR_SREV_9287_10(ah))
819 INIT_INI_ARRAY(&ah->iniModesRxGain,
820 ar9287Modes_rx_gain_9287_1_0,
821 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
822 else if (AR_SREV_9280_20(ah))
823 ath9k_hw_init_rxgain_ini(ah);
824
Vivek Natarajanb37fa872009-09-23 16:27:27 +0530825 if (AR_SREV_9287_11_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530826 INIT_INI_ARRAY(&ah->iniModesTxGain,
827 ar9287Modes_tx_gain_9287_1_1,
828 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
829 } else if (AR_SREV_9287_10(ah)) {
830 INIT_INI_ARRAY(&ah->iniModesTxGain,
831 ar9287Modes_tx_gain_9287_1_0,
832 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
833 } else if (AR_SREV_9280_20(ah)) {
834 ath9k_hw_init_txgain_ini(ah);
835 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530836 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
837
838 /* txgain table */
839 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
840 INIT_INI_ARRAY(&ah->iniModesTxGain,
841 ar9285Modes_high_power_tx_gain_9285_1_2,
842 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
843 } else {
844 INIT_INI_ARRAY(&ah->iniModesTxGain,
845 ar9285Modes_original_tx_gain_9285_1_2,
846 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
847 }
848
849 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700850}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530851
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700852static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
853{
854 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530855
856 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
857 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
858
859 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530860 for (i = 0; i < ah->iniModes.ia_rows; i++) {
861 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700862
Sujith2660b812009-02-09 13:27:26 +0530863 for (j = 1; j < ah->iniModes.ia_columns; j++) {
864 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700865
Sujith2660b812009-02-09 13:27:26 +0530866 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530867 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530868 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700869 reg, val);
870 }
871 }
872 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700873}
874
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700875int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700876{
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700877 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700878
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700879 if (!ath9k_hw_devid_supported(ah->hw_version.devid))
880 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700881
882 ath9k_hw_init_defaults(ah);
883 ath9k_hw_init_config(ah);
884
885 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700886 DPRINTF(ah, ATH_DBG_FATAL, "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700887 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700888 }
889
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700890 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700891 DPRINTF(ah, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700892 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700893 }
894
895 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
896 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
897 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
898 ah->config.serialize_regmode =
899 SER_REG_MODE_ON;
900 } else {
901 ah->config.serialize_regmode =
902 SER_REG_MODE_OFF;
903 }
904 }
905
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700906 DPRINTF(ah, ATH_DBG_RESET, "serialize_regmode is %d\n",
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700907 ah->config.serialize_regmode);
908
909 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700910 DPRINTF(ah, ATH_DBG_FATAL,
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700911 "Mac Chip Rev 0x%02x.%x is not supported by "
912 "this driver\n", ah->hw_version.macVersion,
913 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700914 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700915 }
916
917 if (AR_SREV_9100(ah)) {
918 ah->iq_caldata.calData = &iq_cal_multi_sample;
919 ah->supp_cals = IQ_MISMATCH_CAL;
920 ah->is_pciexpress = false;
921 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400922
923 if (AR_SREV_9271(ah))
924 ah->is_pciexpress = false;
925
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700926 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
927
928 ath9k_hw_init_cal_settings(ah);
929
930 ah->ani_function = ATH9K_ANI_ALL;
931 if (AR_SREV_9280_10_OR_LATER(ah))
932 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
933
934 ath9k_hw_init_mode_regs(ah);
935
936 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530937 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700938 else
939 ath9k_hw_disablepcie(ah);
940
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700941 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700942 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700943 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700944
945 ath9k_hw_init_mode_gain_regs(ah);
946 ath9k_hw_fill_cap_info(ah);
947 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530948
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700949 r = ath9k_hw_init_macaddr(ah);
950 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700951 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +0530952 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700953 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700954 }
955
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400956 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530957 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700958 else
Sujith2660b812009-02-09 13:27:26 +0530959 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700960
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700961 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700962
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700963 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700964}
965
Sujithcbe61d82009-02-09 13:27:12 +0530966static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530967 struct ath9k_channel *chan)
968{
969 u32 synthDelay;
970
971 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +0530972 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +0530973 synthDelay = (4 * synthDelay) / 22;
974 else
975 synthDelay /= 10;
976
977 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
978
979 udelay(synthDelay + BASE_ACTIVATE_DELAY);
980}
981
Sujithcbe61d82009-02-09 13:27:12 +0530982static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530983{
984 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
985 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
986
987 REG_WRITE(ah, AR_QOS_NO_ACK,
988 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
989 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
990 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
991
992 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
993 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
994 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
995 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
996 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
997}
998
Sujithcbe61d82009-02-09 13:27:12 +0530999static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301000 struct ath9k_channel *chan)
1001{
1002 u32 pll;
1003
1004 if (AR_SREV_9100(ah)) {
1005 if (chan && IS_CHAN_5GHZ(chan))
1006 pll = 0x1450;
1007 else
1008 pll = 0x1458;
1009 } else {
1010 if (AR_SREV_9280_10_OR_LATER(ah)) {
1011 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1012
1013 if (chan && IS_CHAN_HALF_RATE(chan))
1014 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1015 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1016 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1017
1018 if (chan && IS_CHAN_5GHZ(chan)) {
1019 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1020
1021
1022 if (AR_SREV_9280_20(ah)) {
1023 if (((chan->channel % 20) == 0)
1024 || ((chan->channel % 10) == 0))
1025 pll = 0x2850;
1026 else
1027 pll = 0x142c;
1028 }
1029 } else {
1030 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1031 }
1032
1033 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1034
1035 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1036
1037 if (chan && IS_CHAN_HALF_RATE(chan))
1038 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1039 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1040 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1041
1042 if (chan && IS_CHAN_5GHZ(chan))
1043 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1044 else
1045 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1046 } else {
1047 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1048
1049 if (chan && IS_CHAN_HALF_RATE(chan))
1050 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1051 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1052 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1053
1054 if (chan && IS_CHAN_5GHZ(chan))
1055 pll |= SM(0xa, AR_RTC_PLL_DIV);
1056 else
1057 pll |= SM(0xb, AR_RTC_PLL_DIV);
1058 }
1059 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001060 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301061
1062 udelay(RTC_PLL_SETTLE_DELAY);
1063
1064 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1065}
1066
Sujithcbe61d82009-02-09 13:27:12 +05301067static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301068{
Sujithf1dc5602008-10-29 10:16:30 +05301069 int rx_chainmask, tx_chainmask;
1070
Sujith2660b812009-02-09 13:27:26 +05301071 rx_chainmask = ah->rxchainmask;
1072 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301073
1074 switch (rx_chainmask) {
1075 case 0x5:
1076 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1077 AR_PHY_SWAP_ALT_CHAIN);
1078 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301079 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301080 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1081 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1082 break;
1083 }
1084 case 0x1:
1085 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301086 case 0x7:
1087 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1088 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1089 break;
1090 default:
1091 break;
1092 }
1093
1094 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1095 if (tx_chainmask == 0x5) {
1096 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1097 AR_PHY_SWAP_ALT_CHAIN);
1098 }
1099 if (AR_SREV_9100(ah))
1100 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1101 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1102}
1103
Sujithcbe61d82009-02-09 13:27:12 +05301104static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001105 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301106{
Sujith2660b812009-02-09 13:27:26 +05301107 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301108 AR_IMR_TXURN |
1109 AR_IMR_RXERR |
1110 AR_IMR_RXORN |
1111 AR_IMR_BCNMISC;
1112
Sujith0ef1f162009-03-30 15:28:35 +05301113 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301114 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301115 else
Sujith2660b812009-02-09 13:27:26 +05301116 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301117
Sujith2660b812009-02-09 13:27:26 +05301118 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301119
Colin McCabed97809d2008-12-01 13:38:55 -08001120 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301121 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301122
Sujith2660b812009-02-09 13:27:26 +05301123 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301124 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1125
1126 if (!AR_SREV_9100(ah)) {
1127 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1128 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1129 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1130 }
1131}
1132
Sujithcbe61d82009-02-09 13:27:12 +05301133static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301134{
Sujithf1dc5602008-10-29 10:16:30 +05301135 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001136 DPRINTF(ah, ATH_DBG_RESET, "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301137 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301138 return false;
1139 } else {
1140 REG_RMW_FIELD(ah, AR_TIME_OUT,
1141 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301142 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301143 return true;
1144 }
1145}
1146
Sujithcbe61d82009-02-09 13:27:12 +05301147static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301148{
Sujithf1dc5602008-10-29 10:16:30 +05301149 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001150 DPRINTF(ah, ATH_DBG_RESET, "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301151 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301152 return false;
1153 } else {
1154 REG_RMW_FIELD(ah, AR_TIME_OUT,
1155 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301156 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301157 return true;
1158 }
1159}
1160
Sujithcbe61d82009-02-09 13:27:12 +05301161static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301162{
Sujithf1dc5602008-10-29 10:16:30 +05301163 if (tu > 0xFFFF) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001164 DPRINTF(ah, ATH_DBG_XMIT,
Sujith04bd46382008-11-28 22:18:05 +05301165 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301166 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301167 return false;
1168 } else {
1169 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301170 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301171 return true;
1172 }
1173}
1174
Sujithcbe61d82009-02-09 13:27:12 +05301175static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301176{
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001177 DPRINTF(ah, ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
Sujith2660b812009-02-09 13:27:26 +05301178 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301179
Sujith2660b812009-02-09 13:27:26 +05301180 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301181 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301182 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1183 if (ah->slottime != (u32) -1)
1184 ath9k_hw_setslottime(ah, ah->slottime);
1185 if (ah->acktimeout != (u32) -1)
1186 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1187 if (ah->ctstimeout != (u32) -1)
1188 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1189 if (ah->globaltxtimeout != (u32) -1)
1190 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301191}
1192
1193const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1194{
1195 return vendorid == ATHEROS_VENDOR_ID ?
1196 ath9k_hw_devname(devid) : NULL;
1197}
1198
Sujithcbe61d82009-02-09 13:27:12 +05301199void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001200{
1201 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001202 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001203
Luis R. Rodriguez081b35a2009-08-03 12:24:50 -07001204 ath9k_hw_rf_free(ah);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001205 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001206 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001207 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001208}
1209
Sujithf1dc5602008-10-29 10:16:30 +05301210/*******/
1211/* INI */
1212/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001213
Sujithcbe61d82009-02-09 13:27:12 +05301214static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301215 struct ath9k_channel *chan)
1216{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001217 u32 val;
1218
1219 if (AR_SREV_9271(ah)) {
1220 /*
1221 * Enable spectral scan to solution for issues with stuck
1222 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1223 * AR9271 1.1
1224 */
1225 if (AR_SREV_9271_10(ah)) {
1226 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE;
1227 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1228 }
1229 else if (AR_SREV_9271_11(ah))
1230 /*
1231 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1232 * present on AR9271 1.1
1233 */
1234 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1235 return;
1236 }
1237
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301238 /*
1239 * Set the RX_ABORT and RX_DIS and clear if off only after
1240 * RXE is set for MAC. This prevents frames with corrupted
1241 * descriptor status.
1242 */
1243 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1244
Vasanthakumar Thiagarajan204d7942009-09-17 09:26:14 +05301245 if (AR_SREV_9280_10_OR_LATER(ah)) {
1246 val = REG_READ(ah, AR_PCU_MISC_MODE2) &
1247 (~AR_PCU_MISC_MODE2_HWWAR1);
1248
1249 if (AR_SREV_9287_10_OR_LATER(ah))
1250 val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
1251
1252 REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
1253 }
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301254
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001255 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301256 AR_SREV_9280_10_OR_LATER(ah))
1257 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001258 /*
1259 * Disable BB clock gating
1260 * Necessary to avoid issues on AR5416 2.0
1261 */
Sujithf1dc5602008-10-29 10:16:30 +05301262 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1263}
1264
Sujithcbe61d82009-02-09 13:27:12 +05301265static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301266 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301267 u32 reg, u32 value)
1268{
1269 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
1270
Sujithd535a422009-02-09 13:27:06 +05301271 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301272 case AR9280_DEVID_PCI:
1273 if (reg == 0x7894) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001274 DPRINTF(ah, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301275 "ini VAL: %x EEPROM: %x\n", value,
1276 (pBase->version & 0xff));
1277
1278 if ((pBase->version & 0xff) > 0x0a) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001279 DPRINTF(ah, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301280 "PWDCLKIND: %d\n",
1281 pBase->pwdclkind);
1282 value &= ~AR_AN_TOP2_PWDCLKIND;
1283 value |= AR_AN_TOP2_PWDCLKIND &
1284 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1285 } else {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001286 DPRINTF(ah, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301287 "PWDCLKIND Earlier Rev\n");
1288 }
1289
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001290 DPRINTF(ah, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301291 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001292 }
Sujithf1dc5602008-10-29 10:16:30 +05301293 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001294 }
1295
Sujithf1dc5602008-10-29 10:16:30 +05301296 return value;
1297}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001298
Sujithcbe61d82009-02-09 13:27:12 +05301299static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301300 struct ar5416_eeprom_def *pEepData,
1301 u32 reg, u32 value)
1302{
Sujith2660b812009-02-09 13:27:26 +05301303 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301304 return value;
1305 else
1306 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1307}
1308
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301309static void ath9k_olc_init(struct ath_hw *ah)
1310{
1311 u32 i;
1312
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301313 if (OLC_FOR_AR9287_10_LATER) {
1314 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1315 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1316 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1317 AR9287_AN_TXPC0_TXPCMODE,
1318 AR9287_AN_TXPC0_TXPCMODE_S,
1319 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1320 udelay(100);
1321 } else {
1322 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1323 ah->originalGain[i] =
1324 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1325 AR_PHY_TX_GAIN);
1326 ah->PDADCdelta = 0;
1327 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301328}
1329
Bob Copeland3a702e42009-03-30 22:30:29 -04001330static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1331 struct ath9k_channel *chan)
1332{
1333 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1334
1335 if (IS_CHAN_B(chan))
1336 ctl |= CTL_11B;
1337 else if (IS_CHAN_G(chan))
1338 ctl |= CTL_11G;
1339 else
1340 ctl |= CTL_11A;
1341
1342 return ctl;
1343}
1344
Sujithcbe61d82009-02-09 13:27:12 +05301345static int ath9k_hw_process_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301346 struct ath9k_channel *chan,
1347 enum ath9k_ht_macmode macmode)
1348{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001349 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301350 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001351 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301352 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001353
Sujithf1dc5602008-10-29 10:16:30 +05301354 switch (chan->chanmode) {
1355 case CHANNEL_A:
1356 case CHANNEL_A_HT20:
1357 modesIndex = 1;
1358 freqIndex = 1;
1359 break;
1360 case CHANNEL_A_HT40PLUS:
1361 case CHANNEL_A_HT40MINUS:
1362 modesIndex = 2;
1363 freqIndex = 1;
1364 break;
1365 case CHANNEL_G:
1366 case CHANNEL_G_HT20:
1367 case CHANNEL_B:
1368 modesIndex = 4;
1369 freqIndex = 2;
1370 break;
1371 case CHANNEL_G_HT40PLUS:
1372 case CHANNEL_G_HT40MINUS:
1373 modesIndex = 3;
1374 freqIndex = 2;
1375 break;
1376
1377 default:
1378 return -EINVAL;
1379 }
1380
1381 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301382 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301383 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301384
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001385 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301386 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301387 } else {
1388 struct ar5416IniArray temp;
1389 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301390 sizeof(u32) * ah->iniAddac.ia_rows *
1391 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301392
Sujith2660b812009-02-09 13:27:26 +05301393 memcpy(ah->addac5416_21,
1394 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301395
Sujith2660b812009-02-09 13:27:26 +05301396 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301397
Sujith2660b812009-02-09 13:27:26 +05301398 temp.ia_array = ah->addac5416_21;
1399 temp.ia_columns = ah->iniAddac.ia_columns;
1400 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301401 REG_WRITE_ARRAY(&temp, 1, regWrites);
1402 }
1403
1404 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1405
Sujith2660b812009-02-09 13:27:26 +05301406 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1407 u32 reg = INI_RA(&ah->iniModes, i, 0);
1408 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301409
Sujithf1dc5602008-10-29 10:16:30 +05301410 REG_WRITE(ah, reg, val);
1411
1412 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301413 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301414 udelay(100);
1415 }
1416
1417 DO_DELAY(regWrites);
1418 }
1419
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301420 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301421 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301422
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301423 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1424 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301425 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301426
Sujith2660b812009-02-09 13:27:26 +05301427 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1428 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1429 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301430
1431 REG_WRITE(ah, reg, val);
1432
1433 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301434 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301435 udelay(100);
1436 }
1437
1438 DO_DELAY(regWrites);
1439 }
1440
1441 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1442
1443 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301444 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301445 regWrites);
1446 }
1447
1448 ath9k_hw_override_ini(ah, chan);
1449 ath9k_hw_set_regs(ah, chan, macmode);
1450 ath9k_hw_init_chain_masks(ah);
1451
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301452 if (OLC_FOR_AR9280_20_LATER)
1453 ath9k_olc_init(ah);
1454
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001455 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001456 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001457 channel->max_antenna_gain * 2,
1458 channel->max_power * 2,
1459 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001460 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001461
Sujithf1dc5602008-10-29 10:16:30 +05301462 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001463 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301464 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001465 return -EIO;
1466 }
1467
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001468 return 0;
1469}
1470
Sujithf1dc5602008-10-29 10:16:30 +05301471/****************************************/
1472/* Reset and Channel Switching Routines */
1473/****************************************/
1474
Sujithcbe61d82009-02-09 13:27:12 +05301475static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301476{
1477 u32 rfMode = 0;
1478
1479 if (chan == NULL)
1480 return;
1481
1482 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1483 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1484
1485 if (!AR_SREV_9280_10_OR_LATER(ah))
1486 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1487 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1488
1489 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1490 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1491
1492 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1493}
1494
Sujithcbe61d82009-02-09 13:27:12 +05301495static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301496{
1497 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1498}
1499
Sujithcbe61d82009-02-09 13:27:12 +05301500static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301501{
1502 u32 regval;
1503
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001504 /*
1505 * set AHB_MODE not to do cacheline prefetches
1506 */
Sujithf1dc5602008-10-29 10:16:30 +05301507 regval = REG_READ(ah, AR_AHB_MODE);
1508 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1509
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001510 /*
1511 * let mac dma reads be in 128 byte chunks
1512 */
Sujithf1dc5602008-10-29 10:16:30 +05301513 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1514 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1515
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001516 /*
1517 * Restore TX Trigger Level to its pre-reset value.
1518 * The initial value depends on whether aggregation is enabled, and is
1519 * adjusted whenever underruns are detected.
1520 */
Sujith2660b812009-02-09 13:27:26 +05301521 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301522
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001523 /*
1524 * let mac dma writes be in 128 byte chunks
1525 */
Sujithf1dc5602008-10-29 10:16:30 +05301526 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1527 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1528
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001529 /*
1530 * Setup receive FIFO threshold to hold off TX activities
1531 */
Sujithf1dc5602008-10-29 10:16:30 +05301532 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1533
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001534 /*
1535 * reduce the number of usable entries in PCU TXBUF to avoid
1536 * wrap around issues.
1537 */
Sujithf1dc5602008-10-29 10:16:30 +05301538 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001539 /* For AR9285 the number of Fifos are reduced to half.
1540 * So set the usable tx buf size also to half to
1541 * avoid data/delimiter underruns
1542 */
Sujithf1dc5602008-10-29 10:16:30 +05301543 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1544 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001545 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301546 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1547 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1548 }
1549}
1550
Sujithcbe61d82009-02-09 13:27:12 +05301551static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301552{
1553 u32 val;
1554
1555 val = REG_READ(ah, AR_STA_ID1);
1556 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1557 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001558 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301559 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1560 | AR_STA_ID1_KSRCH_MODE);
1561 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1562 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001563 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001564 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301565 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1566 | AR_STA_ID1_KSRCH_MODE);
1567 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1568 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001569 case NL80211_IFTYPE_STATION:
1570 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301571 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1572 break;
1573 }
1574}
1575
Sujithcbe61d82009-02-09 13:27:12 +05301576static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001577 u32 coef_scaled,
1578 u32 *coef_mantissa,
1579 u32 *coef_exponent)
1580{
1581 u32 coef_exp, coef_man;
1582
1583 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1584 if ((coef_scaled >> coef_exp) & 0x1)
1585 break;
1586
1587 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1588
1589 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1590
1591 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1592 *coef_exponent = coef_exp - 16;
1593}
1594
Sujithcbe61d82009-02-09 13:27:12 +05301595static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301596 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001597{
1598 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1599 u32 clockMhzScaled = 0x64000000;
1600 struct chan_centers centers;
1601
1602 if (IS_CHAN_HALF_RATE(chan))
1603 clockMhzScaled = clockMhzScaled >> 1;
1604 else if (IS_CHAN_QUARTER_RATE(chan))
1605 clockMhzScaled = clockMhzScaled >> 2;
1606
1607 ath9k_hw_get_channel_centers(ah, chan, &centers);
1608 coef_scaled = clockMhzScaled / centers.synth_center;
1609
1610 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1611 &ds_coef_exp);
1612
1613 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1614 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1615 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1616 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1617
1618 coef_scaled = (9 * coef_scaled) / 10;
1619
1620 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1621 &ds_coef_exp);
1622
1623 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1624 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1625 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1626 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1627}
1628
Sujithcbe61d82009-02-09 13:27:12 +05301629static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301630{
1631 u32 rst_flags;
1632 u32 tmpReg;
1633
Sujith70768492009-02-16 13:23:12 +05301634 if (AR_SREV_9100(ah)) {
1635 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1636 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1637 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1638 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1639 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1640 }
1641
Sujithf1dc5602008-10-29 10:16:30 +05301642 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1643 AR_RTC_FORCE_WAKE_ON_INT);
1644
1645 if (AR_SREV_9100(ah)) {
1646 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1647 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1648 } else {
1649 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1650 if (tmpReg &
1651 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1652 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1653 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1654 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1655 } else {
1656 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1657 }
1658
1659 rst_flags = AR_RTC_RC_MAC_WARM;
1660 if (type == ATH9K_RESET_COLD)
1661 rst_flags |= AR_RTC_RC_MAC_COLD;
1662 }
1663
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001664 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301665 udelay(50);
1666
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001667 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301668 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001669 DPRINTF(ah, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05301670 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301671 return false;
1672 }
1673
1674 if (!AR_SREV_9100(ah))
1675 REG_WRITE(ah, AR_RC, 0);
1676
1677 ath9k_hw_init_pll(ah, NULL);
1678
1679 if (AR_SREV_9100(ah))
1680 udelay(50);
1681
1682 return true;
1683}
1684
Sujithcbe61d82009-02-09 13:27:12 +05301685static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301686{
1687 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1688 AR_RTC_FORCE_WAKE_ON_INT);
1689
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301690 if (!AR_SREV_9100(ah))
1691 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1692
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001693 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301694 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301695
1696 if (!AR_SREV_9100(ah))
1697 REG_WRITE(ah, AR_RC, 0);
1698
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001699 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301700
1701 if (!ath9k_hw_wait(ah,
1702 AR_RTC_STATUS,
1703 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301704 AR_RTC_STATUS_ON,
1705 AH_WAIT_TIMEOUT)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001706 DPRINTF(ah, ATH_DBG_RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301707 return false;
1708 }
1709
1710 ath9k_hw_read_revisions(ah);
1711
1712 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1713}
1714
Sujithcbe61d82009-02-09 13:27:12 +05301715static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301716{
1717 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1718 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1719
1720 switch (type) {
1721 case ATH9K_RESET_POWER_ON:
1722 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301723 case ATH9K_RESET_WARM:
1724 case ATH9K_RESET_COLD:
1725 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301726 default:
1727 return false;
1728 }
1729}
1730
Sujithcbe61d82009-02-09 13:27:12 +05301731static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +05301732 enum ath9k_ht_macmode macmode)
1733{
1734 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301735 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301736
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301737 if (AR_SREV_9285_10_OR_LATER(ah))
1738 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1739 AR_PHY_FC_ENABLE_DAC_FIFO);
1740
Sujithf1dc5602008-10-29 10:16:30 +05301741 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301742 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301743
1744 if (IS_CHAN_HT40(chan)) {
1745 phymode |= AR_PHY_FC_DYN2040_EN;
1746
1747 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1748 (chan->chanmode == CHANNEL_G_HT40PLUS))
1749 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1750
Sujith2660b812009-02-09 13:27:26 +05301751 if (ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
Sujithf1dc5602008-10-29 10:16:30 +05301752 phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1753 }
1754 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1755
1756 ath9k_hw_set11nmac2040(ah, macmode);
1757
1758 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1759 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1760}
1761
Sujithcbe61d82009-02-09 13:27:12 +05301762static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301763 struct ath9k_channel *chan)
1764{
Vivek Natarajan42abfbe2009-09-17 09:27:59 +05301765 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301766 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1767 return false;
1768 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301769 return false;
1770
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001771 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05301772 return false;
1773
Sujith2660b812009-02-09 13:27:26 +05301774 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301775 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301776 ath9k_hw_set_rfmode(ah, chan);
1777
1778 return true;
1779}
1780
Sujithcbe61d82009-02-09 13:27:12 +05301781static bool ath9k_hw_channel_change(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301782 struct ath9k_channel *chan,
1783 enum ath9k_ht_macmode macmode)
1784{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001785 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001786 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301787 u32 synthDelay, qnum;
1788
1789 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1790 if (ath9k_hw_numtxpending(ah, qnum)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001791 DPRINTF(ah, ATH_DBG_QUEUE,
Sujith04bd46382008-11-28 22:18:05 +05301792 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301793 return false;
1794 }
1795 }
1796
1797 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1798 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301799 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001800 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301801 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301802 return false;
1803 }
1804
1805 ath9k_hw_set_regs(ah, chan, macmode);
1806
1807 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001808 ath9k_hw_ar9280_set_channel(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301809 } else {
1810 if (!(ath9k_hw_set_channel(ah, chan))) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001811 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +05301812 "Failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301813 return false;
1814 }
1815 }
1816
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001817 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001818 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301819 channel->max_antenna_gain * 2,
1820 channel->max_power * 2,
1821 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001822 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301823
1824 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301825 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301826 synthDelay = (4 * synthDelay) / 22;
1827 else
1828 synthDelay /= 10;
1829
1830 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1831
1832 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1833
1834 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1835 ath9k_hw_set_delta_slope(ah, chan);
1836
1837 if (AR_SREV_9280_10_OR_LATER(ah))
1838 ath9k_hw_9280_spur_mitigate(ah, chan);
1839 else
1840 ath9k_hw_spur_mitigate(ah, chan);
1841
1842 if (!chan->oneTimeCalsDone)
1843 chan->oneTimeCalsDone = true;
1844
1845 return true;
1846}
1847
Sujithcbe61d82009-02-09 13:27:12 +05301848static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001849{
1850 int bb_spur = AR_NO_SPUR;
1851 int freq;
1852 int bin, cur_bin;
1853 int bb_spur_off, spur_subchannel_sd;
1854 int spur_freq_sd;
1855 int spur_delta_phase;
1856 int denominator;
1857 int upper, lower, cur_vit_mask;
1858 int tmp, newVal;
1859 int i;
1860 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1861 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1862 };
1863 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1864 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1865 };
1866 int inc[4] = { 0, 100, 0, 0 };
1867 struct chan_centers centers;
1868
1869 int8_t mask_m[123];
1870 int8_t mask_p[123];
1871 int8_t mask_amt;
1872 int tmp_mask;
1873 int cur_bb_spur;
1874 bool is2GHz = IS_CHAN_2GHZ(chan);
1875
1876 memset(&mask_m, 0, sizeof(int8_t) * 123);
1877 memset(&mask_p, 0, sizeof(int8_t) * 123);
1878
1879 ath9k_hw_get_channel_centers(ah, chan, &centers);
1880 freq = centers.synth_center;
1881
Sujith2660b812009-02-09 13:27:26 +05301882 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001883 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301884 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001885
1886 if (is2GHz)
1887 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1888 else
1889 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1890
1891 if (AR_NO_SPUR == cur_bb_spur)
1892 break;
1893 cur_bb_spur = cur_bb_spur - freq;
1894
1895 if (IS_CHAN_HT40(chan)) {
1896 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1897 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1898 bb_spur = cur_bb_spur;
1899 break;
1900 }
1901 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1902 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1903 bb_spur = cur_bb_spur;
1904 break;
1905 }
1906 }
1907
1908 if (AR_NO_SPUR == bb_spur) {
1909 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1910 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1911 return;
1912 } else {
1913 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1914 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1915 }
1916
1917 bin = bb_spur * 320;
1918
1919 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1920
1921 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1922 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1923 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1924 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1925 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1926
1927 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1928 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1929 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1930 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1931 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1932 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1933
1934 if (IS_CHAN_HT40(chan)) {
1935 if (bb_spur < 0) {
1936 spur_subchannel_sd = 1;
1937 bb_spur_off = bb_spur + 10;
1938 } else {
1939 spur_subchannel_sd = 0;
1940 bb_spur_off = bb_spur - 10;
1941 }
1942 } else {
1943 spur_subchannel_sd = 0;
1944 bb_spur_off = bb_spur;
1945 }
1946
1947 if (IS_CHAN_HT40(chan))
1948 spur_delta_phase =
1949 ((bb_spur * 262144) /
1950 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1951 else
1952 spur_delta_phase =
1953 ((bb_spur * 524288) /
1954 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1955
1956 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1957 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1958
1959 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1960 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1961 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1962 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1963
1964 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
1965 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
1966
1967 cur_bin = -6000;
1968 upper = bin + 100;
1969 lower = bin - 100;
1970
1971 for (i = 0; i < 4; i++) {
1972 int pilot_mask = 0;
1973 int chan_mask = 0;
1974 int bp = 0;
1975 for (bp = 0; bp < 30; bp++) {
1976 if ((cur_bin > lower) && (cur_bin < upper)) {
1977 pilot_mask = pilot_mask | 0x1 << bp;
1978 chan_mask = chan_mask | 0x1 << bp;
1979 }
1980 cur_bin += 100;
1981 }
1982 cur_bin += inc[i];
1983 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
1984 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
1985 }
1986
1987 cur_vit_mask = 6100;
1988 upper = bin + 120;
1989 lower = bin - 120;
1990
1991 for (i = 0; i < 123; i++) {
1992 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03001993
1994 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08001995 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03001996
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08001997 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001998 mask_amt = 1;
1999 else
2000 mask_amt = 0;
2001 if (cur_vit_mask < 0)
2002 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2003 else
2004 mask_p[cur_vit_mask / 100] = mask_amt;
2005 }
2006 cur_vit_mask -= 100;
2007 }
2008
2009 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2010 | (mask_m[48] << 26) | (mask_m[49] << 24)
2011 | (mask_m[50] << 22) | (mask_m[51] << 20)
2012 | (mask_m[52] << 18) | (mask_m[53] << 16)
2013 | (mask_m[54] << 14) | (mask_m[55] << 12)
2014 | (mask_m[56] << 10) | (mask_m[57] << 8)
2015 | (mask_m[58] << 6) | (mask_m[59] << 4)
2016 | (mask_m[60] << 2) | (mask_m[61] << 0);
2017 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2018 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2019
2020 tmp_mask = (mask_m[31] << 28)
2021 | (mask_m[32] << 26) | (mask_m[33] << 24)
2022 | (mask_m[34] << 22) | (mask_m[35] << 20)
2023 | (mask_m[36] << 18) | (mask_m[37] << 16)
2024 | (mask_m[48] << 14) | (mask_m[39] << 12)
2025 | (mask_m[40] << 10) | (mask_m[41] << 8)
2026 | (mask_m[42] << 6) | (mask_m[43] << 4)
2027 | (mask_m[44] << 2) | (mask_m[45] << 0);
2028 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2029 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2030
2031 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2032 | (mask_m[18] << 26) | (mask_m[18] << 24)
2033 | (mask_m[20] << 22) | (mask_m[20] << 20)
2034 | (mask_m[22] << 18) | (mask_m[22] << 16)
2035 | (mask_m[24] << 14) | (mask_m[24] << 12)
2036 | (mask_m[25] << 10) | (mask_m[26] << 8)
2037 | (mask_m[27] << 6) | (mask_m[28] << 4)
2038 | (mask_m[29] << 2) | (mask_m[30] << 0);
2039 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2040 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2041
2042 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2043 | (mask_m[2] << 26) | (mask_m[3] << 24)
2044 | (mask_m[4] << 22) | (mask_m[5] << 20)
2045 | (mask_m[6] << 18) | (mask_m[7] << 16)
2046 | (mask_m[8] << 14) | (mask_m[9] << 12)
2047 | (mask_m[10] << 10) | (mask_m[11] << 8)
2048 | (mask_m[12] << 6) | (mask_m[13] << 4)
2049 | (mask_m[14] << 2) | (mask_m[15] << 0);
2050 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2051 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2052
2053 tmp_mask = (mask_p[15] << 28)
2054 | (mask_p[14] << 26) | (mask_p[13] << 24)
2055 | (mask_p[12] << 22) | (mask_p[11] << 20)
2056 | (mask_p[10] << 18) | (mask_p[9] << 16)
2057 | (mask_p[8] << 14) | (mask_p[7] << 12)
2058 | (mask_p[6] << 10) | (mask_p[5] << 8)
2059 | (mask_p[4] << 6) | (mask_p[3] << 4)
2060 | (mask_p[2] << 2) | (mask_p[1] << 0);
2061 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2062 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2063
2064 tmp_mask = (mask_p[30] << 28)
2065 | (mask_p[29] << 26) | (mask_p[28] << 24)
2066 | (mask_p[27] << 22) | (mask_p[26] << 20)
2067 | (mask_p[25] << 18) | (mask_p[24] << 16)
2068 | (mask_p[23] << 14) | (mask_p[22] << 12)
2069 | (mask_p[21] << 10) | (mask_p[20] << 8)
2070 | (mask_p[19] << 6) | (mask_p[18] << 4)
2071 | (mask_p[17] << 2) | (mask_p[16] << 0);
2072 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2073 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2074
2075 tmp_mask = (mask_p[45] << 28)
2076 | (mask_p[44] << 26) | (mask_p[43] << 24)
2077 | (mask_p[42] << 22) | (mask_p[41] << 20)
2078 | (mask_p[40] << 18) | (mask_p[39] << 16)
2079 | (mask_p[38] << 14) | (mask_p[37] << 12)
2080 | (mask_p[36] << 10) | (mask_p[35] << 8)
2081 | (mask_p[34] << 6) | (mask_p[33] << 4)
2082 | (mask_p[32] << 2) | (mask_p[31] << 0);
2083 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2084 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2085
2086 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2087 | (mask_p[59] << 26) | (mask_p[58] << 24)
2088 | (mask_p[57] << 22) | (mask_p[56] << 20)
2089 | (mask_p[55] << 18) | (mask_p[54] << 16)
2090 | (mask_p[53] << 14) | (mask_p[52] << 12)
2091 | (mask_p[51] << 10) | (mask_p[50] << 8)
2092 | (mask_p[49] << 6) | (mask_p[48] << 4)
2093 | (mask_p[47] << 2) | (mask_p[46] << 0);
2094 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2095 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2096}
2097
Sujithcbe61d82009-02-09 13:27:12 +05302098static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002099{
2100 int bb_spur = AR_NO_SPUR;
2101 int bin, cur_bin;
2102 int spur_freq_sd;
2103 int spur_delta_phase;
2104 int denominator;
2105 int upper, lower, cur_vit_mask;
2106 int tmp, new;
2107 int i;
2108 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2109 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2110 };
2111 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2112 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2113 };
2114 int inc[4] = { 0, 100, 0, 0 };
2115
2116 int8_t mask_m[123];
2117 int8_t mask_p[123];
2118 int8_t mask_amt;
2119 int tmp_mask;
2120 int cur_bb_spur;
2121 bool is2GHz = IS_CHAN_2GHZ(chan);
2122
2123 memset(&mask_m, 0, sizeof(int8_t) * 123);
2124 memset(&mask_p, 0, sizeof(int8_t) * 123);
2125
2126 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05302127 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002128 if (AR_NO_SPUR == cur_bb_spur)
2129 break;
2130 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2131 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2132 bb_spur = cur_bb_spur;
2133 break;
2134 }
2135 }
2136
2137 if (AR_NO_SPUR == bb_spur)
2138 return;
2139
2140 bin = bb_spur * 32;
2141
2142 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2143 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2144 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2145 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2146 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2147
2148 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2149
2150 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2151 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2152 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2153 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2154 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2155 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2156
2157 spur_delta_phase = ((bb_spur * 524288) / 100) &
2158 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2159
2160 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2161 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2162
2163 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2164 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2165 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2166 REG_WRITE(ah, AR_PHY_TIMING11, new);
2167
2168 cur_bin = -6000;
2169 upper = bin + 100;
2170 lower = bin - 100;
2171
2172 for (i = 0; i < 4; i++) {
2173 int pilot_mask = 0;
2174 int chan_mask = 0;
2175 int bp = 0;
2176 for (bp = 0; bp < 30; bp++) {
2177 if ((cur_bin > lower) && (cur_bin < upper)) {
2178 pilot_mask = pilot_mask | 0x1 << bp;
2179 chan_mask = chan_mask | 0x1 << bp;
2180 }
2181 cur_bin += 100;
2182 }
2183 cur_bin += inc[i];
2184 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2185 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2186 }
2187
2188 cur_vit_mask = 6100;
2189 upper = bin + 120;
2190 lower = bin - 120;
2191
2192 for (i = 0; i < 123; i++) {
2193 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002194
2195 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002196 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002197
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002198 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002199 mask_amt = 1;
2200 else
2201 mask_amt = 0;
2202 if (cur_vit_mask < 0)
2203 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2204 else
2205 mask_p[cur_vit_mask / 100] = mask_amt;
2206 }
2207 cur_vit_mask -= 100;
2208 }
2209
2210 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2211 | (mask_m[48] << 26) | (mask_m[49] << 24)
2212 | (mask_m[50] << 22) | (mask_m[51] << 20)
2213 | (mask_m[52] << 18) | (mask_m[53] << 16)
2214 | (mask_m[54] << 14) | (mask_m[55] << 12)
2215 | (mask_m[56] << 10) | (mask_m[57] << 8)
2216 | (mask_m[58] << 6) | (mask_m[59] << 4)
2217 | (mask_m[60] << 2) | (mask_m[61] << 0);
2218 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2219 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2220
2221 tmp_mask = (mask_m[31] << 28)
2222 | (mask_m[32] << 26) | (mask_m[33] << 24)
2223 | (mask_m[34] << 22) | (mask_m[35] << 20)
2224 | (mask_m[36] << 18) | (mask_m[37] << 16)
2225 | (mask_m[48] << 14) | (mask_m[39] << 12)
2226 | (mask_m[40] << 10) | (mask_m[41] << 8)
2227 | (mask_m[42] << 6) | (mask_m[43] << 4)
2228 | (mask_m[44] << 2) | (mask_m[45] << 0);
2229 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2230 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2231
2232 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2233 | (mask_m[18] << 26) | (mask_m[18] << 24)
2234 | (mask_m[20] << 22) | (mask_m[20] << 20)
2235 | (mask_m[22] << 18) | (mask_m[22] << 16)
2236 | (mask_m[24] << 14) | (mask_m[24] << 12)
2237 | (mask_m[25] << 10) | (mask_m[26] << 8)
2238 | (mask_m[27] << 6) | (mask_m[28] << 4)
2239 | (mask_m[29] << 2) | (mask_m[30] << 0);
2240 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2241 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2242
2243 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2244 | (mask_m[2] << 26) | (mask_m[3] << 24)
2245 | (mask_m[4] << 22) | (mask_m[5] << 20)
2246 | (mask_m[6] << 18) | (mask_m[7] << 16)
2247 | (mask_m[8] << 14) | (mask_m[9] << 12)
2248 | (mask_m[10] << 10) | (mask_m[11] << 8)
2249 | (mask_m[12] << 6) | (mask_m[13] << 4)
2250 | (mask_m[14] << 2) | (mask_m[15] << 0);
2251 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2252 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2253
2254 tmp_mask = (mask_p[15] << 28)
2255 | (mask_p[14] << 26) | (mask_p[13] << 24)
2256 | (mask_p[12] << 22) | (mask_p[11] << 20)
2257 | (mask_p[10] << 18) | (mask_p[9] << 16)
2258 | (mask_p[8] << 14) | (mask_p[7] << 12)
2259 | (mask_p[6] << 10) | (mask_p[5] << 8)
2260 | (mask_p[4] << 6) | (mask_p[3] << 4)
2261 | (mask_p[2] << 2) | (mask_p[1] << 0);
2262 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2263 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2264
2265 tmp_mask = (mask_p[30] << 28)
2266 | (mask_p[29] << 26) | (mask_p[28] << 24)
2267 | (mask_p[27] << 22) | (mask_p[26] << 20)
2268 | (mask_p[25] << 18) | (mask_p[24] << 16)
2269 | (mask_p[23] << 14) | (mask_p[22] << 12)
2270 | (mask_p[21] << 10) | (mask_p[20] << 8)
2271 | (mask_p[19] << 6) | (mask_p[18] << 4)
2272 | (mask_p[17] << 2) | (mask_p[16] << 0);
2273 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2274 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2275
2276 tmp_mask = (mask_p[45] << 28)
2277 | (mask_p[44] << 26) | (mask_p[43] << 24)
2278 | (mask_p[42] << 22) | (mask_p[41] << 20)
2279 | (mask_p[40] << 18) | (mask_p[39] << 16)
2280 | (mask_p[38] << 14) | (mask_p[37] << 12)
2281 | (mask_p[36] << 10) | (mask_p[35] << 8)
2282 | (mask_p[34] << 6) | (mask_p[33] << 4)
2283 | (mask_p[32] << 2) | (mask_p[31] << 0);
2284 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2285 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2286
2287 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2288 | (mask_p[59] << 26) | (mask_p[58] << 24)
2289 | (mask_p[57] << 22) | (mask_p[56] << 20)
2290 | (mask_p[55] << 18) | (mask_p[54] << 16)
2291 | (mask_p[53] << 14) | (mask_p[52] << 12)
2292 | (mask_p[51] << 10) | (mask_p[50] << 8)
2293 | (mask_p[49] << 6) | (mask_p[48] << 4)
2294 | (mask_p[47] << 2) | (mask_p[46] << 0);
2295 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2296 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2297}
2298
Johannes Berg3b319aa2009-06-13 14:50:26 +05302299static void ath9k_enable_rfkill(struct ath_hw *ah)
2300{
2301 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2302 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
2303
2304 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
2305 AR_GPIO_INPUT_MUX2_RFSILENT);
2306
2307 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
2308 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
2309}
2310
Sujithcbe61d82009-02-09 13:27:12 +05302311int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002312 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002313{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002314 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002315 u32 saveLedState;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002316 struct ath_softc *sc = ah->ah_sc;
Sujith2660b812009-02-09 13:27:26 +05302317 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002318 u32 saveDefAntenna;
2319 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05302320 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002321 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002322
Sujith2660b812009-02-09 13:27:26 +05302323 ah->extprotspacing = sc->ht_extprotspacing;
2324 ah->txchainmask = sc->tx_chainmask;
2325 ah->rxchainmask = sc->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002326
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002327 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002328 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002329
Vasanthakumar Thiagarajan9ebef7992009-09-17 09:26:44 +05302330 if (curchan && !ah->chip_fullsleep)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002331 ath9k_hw_getnf(ah, curchan);
2332
2333 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302334 (ah->chip_fullsleep != true) &&
2335 (ah->curchan != NULL) &&
2336 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002337 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302338 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Vasanthakumar Thiagarajan0a475cc2009-09-17 09:27:10 +05302339 !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
2340 IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002341
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002342 if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) {
Sujith2660b812009-02-09 13:27:26 +05302343 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002344 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002345 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002346 }
2347 }
2348
2349 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2350 if (saveDefAntenna == 0)
2351 saveDefAntenna = 1;
2352
2353 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2354
Sujith46fe7822009-09-17 09:25:25 +05302355 /* For chips on which RTC reset is done, save TSF before it gets cleared */
2356 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2357 tsf = ath9k_hw_gettsf64(ah);
2358
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002359 saveLedState = REG_READ(ah, AR_CFG_LED) &
2360 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2361 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2362
2363 ath9k_hw_mark_phy_inactive(ah);
2364
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002365 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2366 REG_WRITE(ah,
2367 AR9271_RESET_POWER_DOWN_CONTROL,
2368 AR9271_RADIO_RF_RST);
2369 udelay(50);
2370 }
2371
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002372 if (!ath9k_hw_chip_reset(ah, chan)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002373 DPRINTF(ah, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002374 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002375 }
2376
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002377 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2378 ah->htc_reset_init = false;
2379 REG_WRITE(ah,
2380 AR9271_RESET_POWER_DOWN_CONTROL,
2381 AR9271_GATE_MAC_CTL);
2382 udelay(50);
2383 }
2384
Sujith46fe7822009-09-17 09:25:25 +05302385 /* Restore TSF */
2386 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2387 ath9k_hw_settsf64(ah, tsf);
2388
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302389 if (AR_SREV_9280_10_OR_LATER(ah))
2390 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002391
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302392 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302393 /* Enable ASYNC FIFO */
2394 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2395 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2396 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2397 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2398 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2399 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2400 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2401 }
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002402 r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width);
2403 if (r)
2404 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002405
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002406 /* Setup MFP options for CCMP */
2407 if (AR_SREV_9280_20_OR_LATER(ah)) {
2408 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2409 * frames when constructing CCMP AAD. */
2410 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2411 0xc7ff);
2412 ah->sw_mgmt_crypto = false;
2413 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2414 /* Disable hardware crypto for management frames */
2415 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2416 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2417 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2418 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2419 ah->sw_mgmt_crypto = true;
2420 } else
2421 ah->sw_mgmt_crypto = true;
2422
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002423 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2424 ath9k_hw_set_delta_slope(ah, chan);
2425
2426 if (AR_SREV_9280_10_OR_LATER(ah))
2427 ath9k_hw_9280_spur_mitigate(ah, chan);
2428 else
2429 ath9k_hw_spur_mitigate(ah, chan);
2430
Sujithd6509152009-03-13 08:56:05 +05302431 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002432
2433 ath9k_hw_decrease_chain_power(ah, chan);
2434
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002435 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
2436 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002437 | macStaId1
2438 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302439 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302440 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302441 | ah->sta_id1_defaults);
2442 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002443
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07002444 ath_hw_setbssidmask(common);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002445
2446 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2447
Luis R. Rodriguez3453ad82009-09-10 08:57:00 -07002448 ath9k_hw_write_associd(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002449
2450 REG_WRITE(ah, AR_ISR, ~0);
2451
2452 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2453
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002454 if (AR_SREV_9280_10_OR_LATER(ah))
2455 ath9k_hw_ar9280_set_channel(ah, chan);
2456 else
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002457 if (!(ath9k_hw_set_channel(ah, chan)))
2458 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002459
2460 for (i = 0; i < AR_NUM_DCU; i++)
2461 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2462
Sujith2660b812009-02-09 13:27:26 +05302463 ah->intr_txqs = 0;
2464 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002465 ath9k_hw_resettxqueue(ah, i);
2466
Sujith2660b812009-02-09 13:27:26 +05302467 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002468 ath9k_hw_init_qos(ah);
2469
Sujith2660b812009-02-09 13:27:26 +05302470 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302471 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302472
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002473 ath9k_hw_init_user_settings(ah);
2474
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302475 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302476 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2477 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2478 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2479 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2480 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2481 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2482
2483 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2484 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2485
2486 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2487 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2488 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2489 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2490 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302491 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302492 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2493 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2494 }
2495
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002496 REG_WRITE(ah, AR_STA_ID1,
2497 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2498
2499 ath9k_hw_set_dma(ah);
2500
2501 REG_WRITE(ah, AR_OBS, 8);
2502
Sujith0ef1f162009-03-30 15:28:35 +05302503 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002504 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2505 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2506 }
2507
2508 ath9k_hw_init_bb(ah, chan);
2509
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002510 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002511 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002512
Sujith2660b812009-02-09 13:27:26 +05302513 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002514 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2515 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2516 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2517 }
2518
2519 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2520
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002521 /*
2522 * For big endian systems turn on swapping for descriptors
2523 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002524 if (AR_SREV_9100(ah)) {
2525 u32 mask;
2526 mask = REG_READ(ah, AR_CFG);
2527 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002528 DPRINTF(ah, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302529 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002530 } else {
2531 mask =
2532 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2533 REG_WRITE(ah, AR_CFG, mask);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002534 DPRINTF(ah, ATH_DBG_RESET,
Sujith04bd46382008-11-28 22:18:05 +05302535 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002536 }
2537 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002538 /* Configure AR9271 target WLAN */
2539 if (AR_SREV_9271(ah))
2540 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002541#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002542 else
2543 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002544#endif
2545 }
2546
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002547 if (ah->btcoex_hw.enabled)
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302548 ath9k_hw_btcoex_enable(ah);
2549
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002550 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002551}
2552
Sujithf1dc5602008-10-29 10:16:30 +05302553/************************/
2554/* Key Cache Management */
2555/************************/
2556
Sujithcbe61d82009-02-09 13:27:12 +05302557bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002558{
Sujithf1dc5602008-10-29 10:16:30 +05302559 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002560
Sujith2660b812009-02-09 13:27:26 +05302561 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002562 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +05302563 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002564 return false;
2565 }
2566
Sujithf1dc5602008-10-29 10:16:30 +05302567 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002568
Sujithf1dc5602008-10-29 10:16:30 +05302569 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2570 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2571 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2572 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2573 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2574 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2575 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2576 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2577
2578 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2579 u16 micentry = entry + 64;
2580
2581 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2582 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2583 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2584 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2585
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002586 }
2587
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002588 return true;
2589}
2590
Sujithcbe61d82009-02-09 13:27:12 +05302591bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002592{
Sujithf1dc5602008-10-29 10:16:30 +05302593 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002594
Sujith2660b812009-02-09 13:27:26 +05302595 if (entry >= ah->caps.keycache_size) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002596 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +05302597 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002598 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002599 }
2600
Sujithf1dc5602008-10-29 10:16:30 +05302601 if (mac != NULL) {
2602 macHi = (mac[5] << 8) | mac[4];
2603 macLo = (mac[3] << 24) |
2604 (mac[2] << 16) |
2605 (mac[1] << 8) |
2606 mac[0];
2607 macLo >>= 1;
2608 macLo |= (macHi & 1) << 31;
2609 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002610 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302611 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002612 }
Sujithf1dc5602008-10-29 10:16:30 +05302613 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2614 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002615
2616 return true;
2617}
2618
Sujithcbe61d82009-02-09 13:27:12 +05302619bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302620 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002621 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002622{
Sujith2660b812009-02-09 13:27:26 +05302623 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +05302624 u32 key0, key1, key2, key3, key4;
2625 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002626
Sujithf1dc5602008-10-29 10:16:30 +05302627 if (entry >= pCap->keycache_size) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002628 DPRINTF(ah, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +05302629 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302630 return false;
2631 }
2632
2633 switch (k->kv_type) {
2634 case ATH9K_CIPHER_AES_OCB:
2635 keyType = AR_KEYTABLE_TYPE_AES;
2636 break;
2637 case ATH9K_CIPHER_AES_CCM:
2638 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002639 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05302640 "AES-CCM not supported by mac rev 0x%x\n",
Sujithd535a422009-02-09 13:27:06 +05302641 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002642 return false;
2643 }
Sujithf1dc5602008-10-29 10:16:30 +05302644 keyType = AR_KEYTABLE_TYPE_CCM;
2645 break;
2646 case ATH9K_CIPHER_TKIP:
2647 keyType = AR_KEYTABLE_TYPE_TKIP;
2648 if (ATH9K_IS_MIC_ENABLED(ah)
2649 && entry + 64 >= pCap->keycache_size) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002650 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05302651 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002652 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002653 }
Sujithf1dc5602008-10-29 10:16:30 +05302654 break;
2655 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002656 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002657 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05302658 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302659 return false;
2660 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002661 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302662 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002663 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302664 keyType = AR_KEYTABLE_TYPE_104;
2665 else
2666 keyType = AR_KEYTABLE_TYPE_128;
2667 break;
2668 case ATH9K_CIPHER_CLR:
2669 keyType = AR_KEYTABLE_TYPE_CLR;
2670 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002671 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002672 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302673 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002674 return false;
2675 }
Sujithf1dc5602008-10-29 10:16:30 +05302676
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002677 key0 = get_unaligned_le32(k->kv_val + 0);
2678 key1 = get_unaligned_le16(k->kv_val + 4);
2679 key2 = get_unaligned_le32(k->kv_val + 6);
2680 key3 = get_unaligned_le16(k->kv_val + 10);
2681 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002682 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302683 key4 &= 0xff;
2684
Jouni Malinen672903b2009-03-02 15:06:31 +02002685 /*
2686 * Note: Key cache registers access special memory area that requires
2687 * two 32-bit writes to actually update the values in the internal
2688 * memory. Consequently, the exact order and pairs used here must be
2689 * maintained.
2690 */
2691
Sujithf1dc5602008-10-29 10:16:30 +05302692 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2693 u16 micentry = entry + 64;
2694
Jouni Malinen672903b2009-03-02 15:06:31 +02002695 /*
2696 * Write inverted key[47:0] first to avoid Michael MIC errors
2697 * on frames that could be sent or received at the same time.
2698 * The correct key will be written in the end once everything
2699 * else is ready.
2700 */
Sujithf1dc5602008-10-29 10:16:30 +05302701 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2702 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002703
2704 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302705 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2706 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002707
2708 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302709 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2710 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002711
2712 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302713 (void) ath9k_hw_keysetmac(ah, entry, mac);
2714
Sujith2660b812009-02-09 13:27:26 +05302715 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002716 /*
2717 * TKIP uses two key cache entries:
2718 * Michael MIC TX/RX keys in the same key cache entry
2719 * (idx = main index + 64):
2720 * key0 [31:0] = RX key [31:0]
2721 * key1 [15:0] = TX key [31:16]
2722 * key1 [31:16] = reserved
2723 * key2 [31:0] = RX key [63:32]
2724 * key3 [15:0] = TX key [15:0]
2725 * key3 [31:16] = reserved
2726 * key4 [31:0] = TX key [63:32]
2727 */
Sujithf1dc5602008-10-29 10:16:30 +05302728 u32 mic0, mic1, mic2, mic3, mic4;
2729
2730 mic0 = get_unaligned_le32(k->kv_mic + 0);
2731 mic2 = get_unaligned_le32(k->kv_mic + 4);
2732 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2733 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2734 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002735
2736 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302737 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2738 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002739
2740 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302741 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2742 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002743
2744 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302745 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2746 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2747 AR_KEYTABLE_TYPE_CLR);
2748
2749 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002750 /*
2751 * TKIP uses four key cache entries (two for group
2752 * keys):
2753 * Michael MIC TX/RX keys are in different key cache
2754 * entries (idx = main index + 64 for TX and
2755 * main index + 32 + 96 for RX):
2756 * key0 [31:0] = TX/RX MIC key [31:0]
2757 * key1 [31:0] = reserved
2758 * key2 [31:0] = TX/RX MIC key [63:32]
2759 * key3 [31:0] = reserved
2760 * key4 [31:0] = reserved
2761 *
2762 * Upper layer code will call this function separately
2763 * for TX and RX keys when these registers offsets are
2764 * used.
2765 */
Sujithf1dc5602008-10-29 10:16:30 +05302766 u32 mic0, mic2;
2767
2768 mic0 = get_unaligned_le32(k->kv_mic + 0);
2769 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002770
2771 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302772 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2773 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002774
2775 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302776 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2777 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002778
2779 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302780 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2781 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2782 AR_KEYTABLE_TYPE_CLR);
2783 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002784
2785 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302786 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2787 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002788
2789 /*
2790 * Write the correct (un-inverted) key[47:0] last to enable
2791 * TKIP now that all other registers are set with correct
2792 * values.
2793 */
Sujithf1dc5602008-10-29 10:16:30 +05302794 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2795 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2796 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002797 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302798 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2799 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002800
2801 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302802 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2803 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002804
2805 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302806 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2807 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2808
Jouni Malinen672903b2009-03-02 15:06:31 +02002809 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302810 (void) ath9k_hw_keysetmac(ah, entry, mac);
2811 }
2812
Sujithf1dc5602008-10-29 10:16:30 +05302813 return true;
2814}
2815
Sujithcbe61d82009-02-09 13:27:12 +05302816bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302817{
Sujith2660b812009-02-09 13:27:26 +05302818 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302819 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2820 if (val & AR_KEYTABLE_VALID)
2821 return true;
2822 }
2823 return false;
2824}
2825
2826/******************************/
2827/* Power Management (Chipset) */
2828/******************************/
2829
Sujithcbe61d82009-02-09 13:27:12 +05302830static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302831{
2832 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2833 if (setChip) {
2834 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2835 AR_RTC_FORCE_WAKE_EN);
2836 if (!AR_SREV_9100(ah))
2837 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2838
Gabor Juhosd03a66c2009-01-14 20:17:09 +01002839 REG_CLR_BIT(ah, (AR_RTC_RESET),
Sujithf1dc5602008-10-29 10:16:30 +05302840 AR_RTC_RESET_EN);
2841 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002842}
2843
Sujithcbe61d82009-02-09 13:27:12 +05302844static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002845{
Sujithf1dc5602008-10-29 10:16:30 +05302846 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2847 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302848 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002849
Sujithf1dc5602008-10-29 10:16:30 +05302850 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2851 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2852 AR_RTC_FORCE_WAKE_ON_INT);
2853 } else {
2854 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2855 AR_RTC_FORCE_WAKE_EN);
2856 }
2857 }
2858}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002859
Sujithcbe61d82009-02-09 13:27:12 +05302860static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302861{
2862 u32 val;
2863 int i;
2864
2865 if (setChip) {
2866 if ((REG_READ(ah, AR_RTC_STATUS) &
2867 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2868 if (ath9k_hw_set_reset_reg(ah,
2869 ATH9K_RESET_POWER_ON) != true) {
2870 return false;
2871 }
2872 }
2873 if (AR_SREV_9100(ah))
2874 REG_SET_BIT(ah, AR_RTC_RESET,
2875 AR_RTC_RESET_EN);
2876
2877 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2878 AR_RTC_FORCE_WAKE_EN);
2879 udelay(50);
2880
2881 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2882 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2883 if (val == AR_RTC_STATUS_ON)
2884 break;
2885 udelay(50);
2886 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2887 AR_RTC_FORCE_WAKE_EN);
2888 }
2889 if (i == 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002890 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302891 "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302892 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002893 }
2894 }
2895
Sujithf1dc5602008-10-29 10:16:30 +05302896 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2897
2898 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002899}
2900
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002901bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302902{
Sujithcbe61d82009-02-09 13:27:12 +05302903 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302904 static const char *modes[] = {
2905 "AWAKE",
2906 "FULL-SLEEP",
2907 "NETWORK SLEEP",
2908 "UNDEFINED"
2909 };
Sujithf1dc5602008-10-29 10:16:30 +05302910
Gabor Juhoscbdec972009-07-24 17:27:22 +02002911 if (ah->power_mode == mode)
2912 return status;
2913
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002914 DPRINTF(ah, ATH_DBG_RESET, "%s -> %s\n",
Sujithd8baa932009-03-30 15:28:25 +05302915 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302916
2917 switch (mode) {
2918 case ATH9K_PM_AWAKE:
2919 status = ath9k_hw_set_power_awake(ah, setChip);
2920 break;
2921 case ATH9K_PM_FULL_SLEEP:
2922 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302923 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302924 break;
2925 case ATH9K_PM_NETWORK_SLEEP:
2926 ath9k_set_power_network_sleep(ah, setChip);
2927 break;
2928 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002929 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302930 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302931 return false;
2932 }
Sujith2660b812009-02-09 13:27:26 +05302933 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302934
2935 return status;
2936}
2937
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002938/*
2939 * Helper for ASPM support.
2940 *
2941 * Disable PLL when in L0s as well as receiver clock when in L1.
2942 * This power saving option must be enabled through the SerDes.
2943 *
2944 * Programming the SerDes must go through the same 288 bit serial shift
2945 * register as the other analog registers. Hence the 9 writes.
2946 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302947void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05302948{
Sujithf1dc5602008-10-29 10:16:30 +05302949 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302950 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05302951
Sujith2660b812009-02-09 13:27:26 +05302952 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05302953 return;
2954
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002955 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05302956 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05302957 return;
2958
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08002959 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302960 if (!restore) {
2961 if (AR_SREV_9280_20_OR_LATER(ah)) {
2962 /*
2963 * AR9280 2.0 or later chips use SerDes values from the
2964 * initvals.h initialized depending on chipset during
2965 * ath9k_hw_init()
2966 */
2967 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
2968 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
2969 INI_RA(&ah->iniPcieSerdes, i, 1));
2970 }
2971 } else if (AR_SREV_9280(ah) &&
2972 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
2973 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
2974 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05302975
Vivek Natarajan93b1b372009-09-17 09:24:58 +05302976 /* RX shut off when elecidle is asserted */
2977 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
2978 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
2979 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
2980
2981 /* Shut off CLKREQ active in L1 */
2982 if (ah->config.pcie_clock_req)
2983 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
2984 else
2985 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
2986
2987 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
2988 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
2989 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
2990
2991 /* Load the new settings */
2992 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
2993
2994 } else {
2995 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
2996 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
2997
2998 /* RX shut off when elecidle is asserted */
2999 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
3000 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
3001 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
3002
3003 /*
3004 * Ignore ah->ah_config.pcie_clock_req setting for
3005 * pre-AR9280 11n
3006 */
3007 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
3008
3009 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3010 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3011 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
3012
3013 /* Load the new settings */
3014 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05303015 }
Sujithf1dc5602008-10-29 10:16:30 +05303016
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303017 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05303018
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303019 /* set bit 19 to allow forcing of pcie core into L1 state */
3020 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05303021
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303022 /* Several PCIe massages to ensure proper behaviour */
3023 if (ah->config.pcie_waen) {
3024 val = ah->config.pcie_waen;
3025 if (!power_off)
3026 val &= (~AR_WA_D3_L1_DISABLE);
3027 } else {
3028 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3029 AR_SREV_9287(ah)) {
3030 val = AR9285_WA_DEFAULT;
3031 if (!power_off)
3032 val &= (~AR_WA_D3_L1_DISABLE);
3033 } else if (AR_SREV_9280(ah)) {
3034 /*
3035 * On AR9280 chips bit 22 of 0x4004 needs to be
3036 * set otherwise card may disappear.
3037 */
3038 val = AR9280_WA_DEFAULT;
3039 if (!power_off)
3040 val &= (~AR_WA_D3_L1_DISABLE);
3041 } else
3042 val = AR_WA_DEFAULT;
3043 }
Sujithf1dc5602008-10-29 10:16:30 +05303044
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303045 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05303046 }
3047
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303048 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003049 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303050 * Set PCIe workaround bits
3051 * bit 14 in WA register (disable L1) should only
3052 * be set when device enters D3 and be cleared
3053 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003054 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303055 if (ah->config.pcie_waen) {
3056 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
3057 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3058 } else {
3059 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3060 AR_SREV_9287(ah)) &&
3061 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
3062 (AR_SREV_9280(ah) &&
3063 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
3064 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3065 }
3066 }
Sujithf1dc5602008-10-29 10:16:30 +05303067 }
3068}
3069
3070/**********************/
3071/* Interrupt Handling */
3072/**********************/
3073
Sujithcbe61d82009-02-09 13:27:12 +05303074bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003075{
3076 u32 host_isr;
3077
3078 if (AR_SREV_9100(ah))
3079 return true;
3080
3081 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
3082 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
3083 return true;
3084
3085 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
3086 if ((host_isr & AR_INTR_SYNC_DEFAULT)
3087 && (host_isr != AR_INTR_SPURIOUS))
3088 return true;
3089
3090 return false;
3091}
3092
Sujithcbe61d82009-02-09 13:27:12 +05303093bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003094{
3095 u32 isr = 0;
3096 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05303097 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003098 u32 sync_cause = 0;
3099 bool fatal_int = false;
3100
3101 if (!AR_SREV_9100(ah)) {
3102 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
3103 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
3104 == AR_RTC_STATUS_ON) {
3105 isr = REG_READ(ah, AR_ISR);
3106 }
3107 }
3108
Sujithf1dc5602008-10-29 10:16:30 +05303109 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
3110 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003111
3112 *masked = 0;
3113
3114 if (!isr && !sync_cause)
3115 return false;
3116 } else {
3117 *masked = 0;
3118 isr = REG_READ(ah, AR_ISR);
3119 }
3120
3121 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003122 if (isr & AR_ISR_BCNMISC) {
3123 u32 isr2;
3124 isr2 = REG_READ(ah, AR_ISR_S2);
3125 if (isr2 & AR_ISR_S2_TIM)
3126 mask2 |= ATH9K_INT_TIM;
3127 if (isr2 & AR_ISR_S2_DTIM)
3128 mask2 |= ATH9K_INT_DTIM;
3129 if (isr2 & AR_ISR_S2_DTIMSYNC)
3130 mask2 |= ATH9K_INT_DTIMSYNC;
3131 if (isr2 & (AR_ISR_S2_CABEND))
3132 mask2 |= ATH9K_INT_CABEND;
3133 if (isr2 & AR_ISR_S2_GTT)
3134 mask2 |= ATH9K_INT_GTT;
3135 if (isr2 & AR_ISR_S2_CST)
3136 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05303137 if (isr2 & AR_ISR_S2_TSFOOR)
3138 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003139 }
3140
3141 isr = REG_READ(ah, AR_ISR_RAC);
3142 if (isr == 0xffffffff) {
3143 *masked = 0;
3144 return false;
3145 }
3146
3147 *masked = isr & ATH9K_INT_COMMON;
3148
Sujith0ef1f162009-03-30 15:28:35 +05303149 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003150 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
3151 *masked |= ATH9K_INT_RX;
3152 }
3153
3154 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
3155 *masked |= ATH9K_INT_RX;
3156 if (isr &
3157 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
3158 AR_ISR_TXEOL)) {
3159 u32 s0_s, s1_s;
3160
3161 *masked |= ATH9K_INT_TX;
3162
3163 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05303164 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
3165 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003166
3167 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05303168 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
3169 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003170 }
3171
3172 if (isr & AR_ISR_RXORN) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003173 DPRINTF(ah, ATH_DBG_INTERRUPT,
Sujith04bd46382008-11-28 22:18:05 +05303174 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003175 }
3176
3177 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05303178 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003179 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
3180 if (isr5 & AR_ISR_S5_TIM_TIMER)
3181 *masked |= ATH9K_INT_TIM_TIMER;
3182 }
3183 }
3184
3185 *masked |= mask2;
3186 }
Sujithf1dc5602008-10-29 10:16:30 +05303187
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003188 if (AR_SREV_9100(ah))
3189 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303190
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303191 if (isr & AR_ISR_GENTMR) {
3192 u32 s5_s;
3193
3194 s5_s = REG_READ(ah, AR_ISR_S5_S);
3195 if (isr & AR_ISR_GENTMR) {
3196 ah->intr_gen_timer_trigger =
3197 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
3198
3199 ah->intr_gen_timer_thresh =
3200 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
3201
3202 if (ah->intr_gen_timer_trigger)
3203 *masked |= ATH9K_INT_GENTIMER;
3204
3205 }
3206 }
3207
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003208 if (sync_cause) {
3209 fatal_int =
3210 (sync_cause &
3211 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
3212 ? true : false;
3213
3214 if (fatal_int) {
3215 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003216 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05303217 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003218 }
3219 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003220 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05303221 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003222 }
Steven Luoa89bff92009-04-12 02:57:54 -07003223 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003224 }
3225 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003226 DPRINTF(ah, ATH_DBG_INTERRUPT,
Sujith04bd46382008-11-28 22:18:05 +05303227 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003228 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
3229 REG_WRITE(ah, AR_RC, 0);
3230 *masked |= ATH9K_INT_FATAL;
3231 }
3232 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003233 DPRINTF(ah, ATH_DBG_INTERRUPT,
Sujith04bd46382008-11-28 22:18:05 +05303234 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003235 }
3236
3237 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3238 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3239 }
Sujithf1dc5602008-10-29 10:16:30 +05303240
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003241 return true;
3242}
3243
Sujithcbe61d82009-02-09 13:27:12 +05303244enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003245{
Sujith2660b812009-02-09 13:27:26 +05303246 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003247 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303248 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003249
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003250 DPRINTF(ah, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003251
3252 if (omask & ATH9K_INT_GLOBAL) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003253 DPRINTF(ah, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003254 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3255 (void) REG_READ(ah, AR_IER);
3256 if (!AR_SREV_9100(ah)) {
3257 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3258 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3259
3260 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3261 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3262 }
3263 }
3264
3265 mask = ints & ATH9K_INT_COMMON;
3266 mask2 = 0;
3267
3268 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05303269 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003270 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303271 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003272 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303273 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003274 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303275 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003276 mask |= AR_IMR_TXEOL;
3277 }
3278 if (ints & ATH9K_INT_RX) {
3279 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05303280 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003281 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3282 else
3283 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303284 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003285 mask |= AR_IMR_GENTMR;
3286 }
3287
3288 if (ints & (ATH9K_INT_BMISC)) {
3289 mask |= AR_IMR_BCNMISC;
3290 if (ints & ATH9K_INT_TIM)
3291 mask2 |= AR_IMR_S2_TIM;
3292 if (ints & ATH9K_INT_DTIM)
3293 mask2 |= AR_IMR_S2_DTIM;
3294 if (ints & ATH9K_INT_DTIMSYNC)
3295 mask2 |= AR_IMR_S2_DTIMSYNC;
3296 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05303297 mask2 |= AR_IMR_S2_CABEND;
3298 if (ints & ATH9K_INT_TSFOOR)
3299 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003300 }
3301
3302 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3303 mask |= AR_IMR_BCNMISC;
3304 if (ints & ATH9K_INT_GTT)
3305 mask2 |= AR_IMR_S2_GTT;
3306 if (ints & ATH9K_INT_CST)
3307 mask2 |= AR_IMR_S2_CST;
3308 }
3309
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003310 DPRINTF(ah, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003311 REG_WRITE(ah, AR_IMR, mask);
3312 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3313 AR_IMR_S2_DTIM |
3314 AR_IMR_S2_DTIMSYNC |
3315 AR_IMR_S2_CABEND |
3316 AR_IMR_S2_CABTO |
3317 AR_IMR_S2_TSFOOR |
3318 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3319 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303320 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003321
Sujith60b67f52008-08-07 10:52:38 +05303322 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003323 if (ints & ATH9K_INT_TIM_TIMER)
3324 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3325 else
3326 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3327 }
3328
3329 if (ints & ATH9K_INT_GLOBAL) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003330 DPRINTF(ah, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003331 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3332 if (!AR_SREV_9100(ah)) {
3333 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3334 AR_INTR_MAC_IRQ);
3335 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3336
3337
3338 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3339 AR_INTR_SYNC_DEFAULT);
3340 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3341 AR_INTR_SYNC_DEFAULT);
3342 }
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003343 DPRINTF(ah, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003344 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
3345 }
3346
3347 return omask;
3348}
3349
Sujithf1dc5602008-10-29 10:16:30 +05303350/*******************/
3351/* Beacon Handling */
3352/*******************/
3353
Sujithcbe61d82009-02-09 13:27:12 +05303354void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003355{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003356 int flags = 0;
3357
Sujith2660b812009-02-09 13:27:26 +05303358 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003359
Sujith2660b812009-02-09 13:27:26 +05303360 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003361 case NL80211_IFTYPE_STATION:
3362 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003363 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3364 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3365 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3366 flags |= AR_TBTT_TIMER_EN;
3367 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003368 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003369 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003370 REG_SET_BIT(ah, AR_TXCFG,
3371 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3372 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3373 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303374 (ah->atim_window ? ah->
3375 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003376 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003377 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003378 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3379 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3380 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303381 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303382 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003383 REG_WRITE(ah, AR_NEXT_SWBA,
3384 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303385 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303386 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003387 flags |=
3388 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3389 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003390 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003391 DPRINTF(ah, ATH_DBG_BEACON,
Colin McCabed97809d2008-12-01 13:38:55 -08003392 "%s: unsupported opmode: %d\n",
Sujith2660b812009-02-09 13:27:26 +05303393 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003394 return;
3395 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003396 }
3397
3398 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3399 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3400 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3401 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3402
3403 beacon_period &= ~ATH9K_BEACON_ENA;
3404 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
3405 beacon_period &= ~ATH9K_BEACON_RESET_TSF;
3406 ath9k_hw_reset_tsf(ah);
3407 }
3408
3409 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3410}
3411
Sujithcbe61d82009-02-09 13:27:12 +05303412void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303413 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003414{
3415 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303416 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003417
3418 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3419
3420 REG_WRITE(ah, AR_BEACON_PERIOD,
3421 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3422 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3423 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3424
3425 REG_RMW_FIELD(ah, AR_RSSI_THR,
3426 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3427
3428 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3429
3430 if (bs->bs_sleepduration > beaconintval)
3431 beaconintval = bs->bs_sleepduration;
3432
3433 dtimperiod = bs->bs_dtimperiod;
3434 if (bs->bs_sleepduration > dtimperiod)
3435 dtimperiod = bs->bs_sleepduration;
3436
3437 if (beaconintval == dtimperiod)
3438 nextTbtt = bs->bs_nextdtim;
3439 else
3440 nextTbtt = bs->bs_nexttbtt;
3441
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003442 DPRINTF(ah, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3443 DPRINTF(ah, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3444 DPRINTF(ah, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3445 DPRINTF(ah, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003446
3447 REG_WRITE(ah, AR_NEXT_DTIM,
3448 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3449 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3450
3451 REG_WRITE(ah, AR_SLEEP1,
3452 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3453 | AR_SLEEP1_ASSUME_DTIM);
3454
Sujith60b67f52008-08-07 10:52:38 +05303455 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003456 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3457 else
3458 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3459
3460 REG_WRITE(ah, AR_SLEEP2,
3461 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3462
3463 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3464 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3465
3466 REG_SET_BIT(ah, AR_TIMER_MODE,
3467 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3468 AR_DTIM_TIMER_EN);
3469
Sujith4af9cf42009-02-12 10:06:47 +05303470 /* TSF Out of Range Threshold */
3471 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003472}
3473
Sujithf1dc5602008-10-29 10:16:30 +05303474/*******************/
3475/* HW Capabilities */
3476/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003477
Sujitheef7a572009-03-30 15:28:28 +05303478void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003479{
Sujith2660b812009-02-09 13:27:26 +05303480 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003481 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003482 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003483
Sujithf1dc5602008-10-29 10:16:30 +05303484 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003485
Sujithf74df6f2009-02-09 13:27:24 +05303486 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003487 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303488
Sujithf74df6f2009-02-09 13:27:24 +05303489 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303490 if (AR_SREV_9285_10_OR_LATER(ah))
3491 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003492 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303493
Sujithf74df6f2009-02-09 13:27:24 +05303494 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303495
Sujith2660b812009-02-09 13:27:26 +05303496 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303497 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003498 if (regulatory->current_rd == 0x64 ||
3499 regulatory->current_rd == 0x65)
3500 regulatory->current_rd += 5;
3501 else if (regulatory->current_rd == 0x41)
3502 regulatory->current_rd = 0x43;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003503 DPRINTF(ah, ATH_DBG_REGULATORY,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003504 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003505 }
Sujithdc2222a2008-08-14 13:26:55 +05303506
Sujithf74df6f2009-02-09 13:27:24 +05303507 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303508 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003509
Sujithf1dc5602008-10-29 10:16:30 +05303510 if (eeval & AR5416_OPFLAGS_11A) {
3511 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303512 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303513 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3514 set_bit(ATH9K_MODE_11NA_HT20,
3515 pCap->wireless_modes);
3516 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3517 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3518 pCap->wireless_modes);
3519 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3520 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003521 }
3522 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003523 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003524
Sujithf1dc5602008-10-29 10:16:30 +05303525 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303526 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303527 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303528 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3529 set_bit(ATH9K_MODE_11NG_HT20,
3530 pCap->wireless_modes);
3531 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3532 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3533 pCap->wireless_modes);
3534 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3535 pCap->wireless_modes);
3536 }
3537 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003538 }
Sujithf1dc5602008-10-29 10:16:30 +05303539
Sujithf74df6f2009-02-09 13:27:24 +05303540 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003541 /*
3542 * For AR9271 we will temporarilly uses the rx chainmax as read from
3543 * the EEPROM.
3544 */
Sujith8147f5d2009-02-20 15:13:23 +05303545 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003546 !(eeval & AR5416_OPFLAGS_11A) &&
3547 !(AR_SREV_9271(ah)))
3548 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303549 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3550 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003551 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303552 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303553
Sujithd535a422009-02-09 13:27:06 +05303554 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303555 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303556
3557 pCap->low_2ghz_chan = 2312;
3558 pCap->high_2ghz_chan = 2732;
3559
3560 pCap->low_5ghz_chan = 4920;
3561 pCap->high_5ghz_chan = 6100;
3562
3563 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3564 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3565 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3566
3567 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3568 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3569 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3570
Sujith2660b812009-02-09 13:27:26 +05303571 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303572 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3573 else
3574 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3575
3576 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3577 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3578 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3579 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3580
3581 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3582 pCap->total_queues =
3583 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3584 else
3585 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3586
3587 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3588 pCap->keycache_size =
3589 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3590 else
3591 pCap->keycache_size = AR_KEYTABLE_SIZE;
3592
3593 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303594 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3595
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303596 if (AR_SREV_9285_10_OR_LATER(ah))
3597 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3598 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303599 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3600 else
3601 pCap->num_gpio_pins = AR_NUM_GPIO;
3602
Sujithf1dc5602008-10-29 10:16:30 +05303603 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3604 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3605 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3606 } else {
3607 pCap->rts_aggr_limit = (8 * 1024);
3608 }
3609
3610 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3611
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303612#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303613 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3614 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3615 ah->rfkill_gpio =
3616 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3617 ah->rfkill_polarity =
3618 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303619
3620 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3621 }
3622#endif
3623
Vivek Natarajana3ca95fb2009-09-17 09:29:07 +05303624 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
Sujithf1dc5602008-10-29 10:16:30 +05303625
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303626 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303627 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3628 else
3629 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3630
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003631 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303632 pCap->reg_cap =
3633 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3634 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3635 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3636 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3637 } else {
3638 pCap->reg_cap =
3639 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3640 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3641 }
3642
3643 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3644
3645 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303646 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303647 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303648 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303649
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303650 if (AR_SREV_9280_10_OR_LATER(ah) &&
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -07003651 ath9k_hw_btcoex_supported(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003652 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
3653 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303654
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303655 if (AR_SREV_9285(ah)) {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003656 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
3657 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303658 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003659 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303660 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303661 } else {
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07003662 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303663 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003664}
3665
Sujithcbe61d82009-02-09 13:27:12 +05303666bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303667 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003668{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003669 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303670 switch (type) {
3671 case ATH9K_CAP_CIPHER:
3672 switch (capability) {
3673 case ATH9K_CIPHER_AES_CCM:
3674 case ATH9K_CIPHER_AES_OCB:
3675 case ATH9K_CIPHER_TKIP:
3676 case ATH9K_CIPHER_WEP:
3677 case ATH9K_CIPHER_MIC:
3678 case ATH9K_CIPHER_CLR:
3679 return true;
3680 default:
3681 return false;
3682 }
3683 case ATH9K_CAP_TKIP_MIC:
3684 switch (capability) {
3685 case 0:
3686 return true;
3687 case 1:
Sujith2660b812009-02-09 13:27:26 +05303688 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303689 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3690 false;
3691 }
3692 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303693 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303694 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303695 case ATH9K_CAP_DIVERSITY:
3696 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3697 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3698 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303699 case ATH9K_CAP_MCAST_KEYSRCH:
3700 switch (capability) {
3701 case 0:
3702 return true;
3703 case 1:
3704 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3705 return false;
3706 } else {
Sujith2660b812009-02-09 13:27:26 +05303707 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303708 AR_STA_ID1_MCAST_KSRCH) ? true :
3709 false;
3710 }
3711 }
3712 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303713 case ATH9K_CAP_TXPOW:
3714 switch (capability) {
3715 case 0:
3716 return 0;
3717 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003718 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303719 return 0;
3720 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003721 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303722 return 0;
3723 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003724 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303725 return 0;
3726 }
3727 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303728 case ATH9K_CAP_DS:
3729 return (AR_SREV_9280_20_OR_LATER(ah) &&
3730 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3731 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303732 default:
3733 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003734 }
Sujithf1dc5602008-10-29 10:16:30 +05303735}
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003736
Sujithcbe61d82009-02-09 13:27:12 +05303737bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303738 u32 capability, u32 setting, int *status)
3739{
Sujithf1dc5602008-10-29 10:16:30 +05303740 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003741
Sujithf1dc5602008-10-29 10:16:30 +05303742 switch (type) {
3743 case ATH9K_CAP_TKIP_MIC:
3744 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303745 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303746 AR_STA_ID1_CRPT_MIC_ENABLE;
3747 else
Sujith2660b812009-02-09 13:27:26 +05303748 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303749 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3750 return true;
3751 case ATH9K_CAP_DIVERSITY:
3752 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3753 if (setting)
3754 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3755 else
3756 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3757 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3758 return true;
3759 case ATH9K_CAP_MCAST_KEYSRCH:
3760 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303761 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303762 else
Sujith2660b812009-02-09 13:27:26 +05303763 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303764 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303765 default:
3766 return false;
3767 }
3768}
3769
3770/****************************/
3771/* GPIO / RFKILL / Antennae */
3772/****************************/
3773
Sujithcbe61d82009-02-09 13:27:12 +05303774static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303775 u32 gpio, u32 type)
3776{
3777 int addr;
3778 u32 gpio_shift, tmp;
3779
3780 if (gpio > 11)
3781 addr = AR_GPIO_OUTPUT_MUX3;
3782 else if (gpio > 5)
3783 addr = AR_GPIO_OUTPUT_MUX2;
3784 else
3785 addr = AR_GPIO_OUTPUT_MUX1;
3786
3787 gpio_shift = (gpio % 6) * 5;
3788
3789 if (AR_SREV_9280_20_OR_LATER(ah)
3790 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3791 REG_RMW(ah, addr, (type << gpio_shift),
3792 (0x1f << gpio_shift));
3793 } else {
3794 tmp = REG_READ(ah, addr);
3795 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3796 tmp &= ~(0x1f << gpio_shift);
3797 tmp |= (type << gpio_shift);
3798 REG_WRITE(ah, addr, tmp);
3799 }
3800}
3801
Sujithcbe61d82009-02-09 13:27:12 +05303802void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303803{
3804 u32 gpio_shift;
3805
Sujith2660b812009-02-09 13:27:26 +05303806 ASSERT(gpio < ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303807
3808 gpio_shift = gpio << 1;
3809
3810 REG_RMW(ah,
3811 AR_GPIO_OE_OUT,
3812 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3813 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3814}
3815
Sujithcbe61d82009-02-09 13:27:12 +05303816u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303817{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303818#define MS_REG_READ(x, y) \
3819 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3820
Sujith2660b812009-02-09 13:27:26 +05303821 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303822 return 0xffffffff;
3823
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303824 if (AR_SREV_9287_10_OR_LATER(ah))
3825 return MS_REG_READ(AR9287, gpio) != 0;
3826 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303827 return MS_REG_READ(AR9285, gpio) != 0;
3828 else if (AR_SREV_9280_10_OR_LATER(ah))
3829 return MS_REG_READ(AR928X, gpio) != 0;
3830 else
3831 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303832}
3833
Sujithcbe61d82009-02-09 13:27:12 +05303834void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303835 u32 ah_signal_type)
3836{
3837 u32 gpio_shift;
3838
3839 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3840
3841 gpio_shift = 2 * gpio;
3842
3843 REG_RMW(ah,
3844 AR_GPIO_OE_OUT,
3845 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3846 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3847}
3848
Sujithcbe61d82009-02-09 13:27:12 +05303849void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303850{
3851 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3852 AR_GPIO_BIT(gpio));
3853}
3854
Sujithcbe61d82009-02-09 13:27:12 +05303855u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303856{
3857 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3858}
3859
Sujithcbe61d82009-02-09 13:27:12 +05303860void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303861{
3862 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3863}
3864
Sujithcbe61d82009-02-09 13:27:12 +05303865bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303866 enum ath9k_ant_setting settings,
3867 struct ath9k_channel *chan,
3868 u8 *tx_chainmask,
3869 u8 *rx_chainmask,
3870 u8 *antenna_cfgd)
3871{
Sujithf1dc5602008-10-29 10:16:30 +05303872 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3873
3874 if (AR_SREV_9280(ah)) {
3875 if (!tx_chainmask_cfg) {
3876
3877 tx_chainmask_cfg = *tx_chainmask;
3878 rx_chainmask_cfg = *rx_chainmask;
3879 }
3880
3881 switch (settings) {
3882 case ATH9K_ANT_FIXED_A:
3883 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3884 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3885 *antenna_cfgd = true;
3886 break;
3887 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303888 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303889 ATH9K_ANTENNA1_CHAINMASK) {
3890 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3891 }
3892 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3893 *antenna_cfgd = true;
3894 break;
3895 case ATH9K_ANT_VARIABLE:
3896 *tx_chainmask = tx_chainmask_cfg;
3897 *rx_chainmask = rx_chainmask_cfg;
3898 *antenna_cfgd = true;
3899 break;
3900 default:
3901 break;
3902 }
3903 } else {
Sujith1cf68732009-08-13 09:34:32 +05303904 ah->config.diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303905 }
3906
3907 return true;
3908}
3909
3910/*********************/
3911/* General Operation */
3912/*********************/
3913
Sujithcbe61d82009-02-09 13:27:12 +05303914u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303915{
3916 u32 bits = REG_READ(ah, AR_RX_FILTER);
3917 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3918
3919 if (phybits & AR_PHY_ERR_RADAR)
3920 bits |= ATH9K_RX_FILTER_PHYRADAR;
3921 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
3922 bits |= ATH9K_RX_FILTER_PHYERR;
3923
3924 return bits;
3925}
3926
Sujithcbe61d82009-02-09 13:27:12 +05303927void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05303928{
3929 u32 phybits;
3930
Sujith7ea310b2009-09-03 12:08:43 +05303931 REG_WRITE(ah, AR_RX_FILTER, bits);
3932
Sujithf1dc5602008-10-29 10:16:30 +05303933 phybits = 0;
3934 if (bits & ATH9K_RX_FILTER_PHYRADAR)
3935 phybits |= AR_PHY_ERR_RADAR;
3936 if (bits & ATH9K_RX_FILTER_PHYERR)
3937 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
3938 REG_WRITE(ah, AR_PHY_ERR, phybits);
3939
3940 if (phybits)
3941 REG_WRITE(ah, AR_RXCFG,
3942 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
3943 else
3944 REG_WRITE(ah, AR_RXCFG,
3945 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
3946}
3947
Sujithcbe61d82009-02-09 13:27:12 +05303948bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303949{
3950 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
3951}
3952
Sujithcbe61d82009-02-09 13:27:12 +05303953bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303954{
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07003955 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
Sujithf1dc5602008-10-29 10:16:30 +05303956 return false;
3957
3958 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
3959}
3960
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003961void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05303962{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003963 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05303964 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08003965 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05303966
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003967 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05303968
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003969 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003970 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07003971 channel->max_antenna_gain * 2,
3972 channel->max_power * 2,
3973 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003974 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05303975}
3976
Sujithcbe61d82009-02-09 13:27:12 +05303977void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05303978{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003979 memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05303980}
3981
Sujithcbe61d82009-02-09 13:27:12 +05303982void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303983{
Sujith2660b812009-02-09 13:27:26 +05303984 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05303985}
3986
Sujithcbe61d82009-02-09 13:27:12 +05303987void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05303988{
3989 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
3990 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
3991}
3992
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07003993void ath9k_hw_write_associd(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303994{
Luis R. Rodriguez15107182009-09-10 09:22:37 -07003995 struct ath_common *common = ath9k_hw_common(ah);
3996
3997 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
3998 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
3999 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05304000}
4001
Sujithcbe61d82009-02-09 13:27:12 +05304002u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304003{
4004 u64 tsf;
4005
4006 tsf = REG_READ(ah, AR_TSF_U32);
4007 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
4008
4009 return tsf;
4010}
4011
Sujithcbe61d82009-02-09 13:27:12 +05304012void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004013{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004014 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01004015 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004016}
4017
Sujithcbe61d82009-02-09 13:27:12 +05304018void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304019{
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004020 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
4021 AH_TSF_WRITE_TIMEOUT))
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07004022 DPRINTF(ah, ATH_DBG_RESET,
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004023 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
4024
Sujithf1dc5602008-10-29 10:16:30 +05304025 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004026}
4027
Sujith54e4cec2009-08-07 09:45:09 +05304028void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004029{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004030 if (setting)
Sujith2660b812009-02-09 13:27:26 +05304031 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004032 else
Sujith2660b812009-02-09 13:27:26 +05304033 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004034}
4035
Sujithcbe61d82009-02-09 13:27:12 +05304036bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004037{
Sujithf1dc5602008-10-29 10:16:30 +05304038 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07004039 DPRINTF(ah, ATH_DBG_RESET, "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05304040 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05304041 return false;
4042 } else {
4043 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05304044 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05304045 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004046 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004047}
4048
Sujithcbe61d82009-02-09 13:27:12 +05304049void ath9k_hw_set11nmac2040(struct ath_hw *ah, enum ath9k_ht_macmode mode)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004050{
Sujithf1dc5602008-10-29 10:16:30 +05304051 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004052
Sujithf1dc5602008-10-29 10:16:30 +05304053 if (mode == ATH9K_HT_MACMODE_2040 &&
Sujith2660b812009-02-09 13:27:26 +05304054 !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05304055 macmode = AR_2040_JOINED_RX_CLEAR;
4056 else
4057 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004058
Sujithf1dc5602008-10-29 10:16:30 +05304059 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004060}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304061
4062/* HW Generic timers configuration */
4063
4064static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
4065{
4066 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4067 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4068 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4069 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4070 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4071 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4072 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4073 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4074 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
4075 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
4076 AR_NDP2_TIMER_MODE, 0x0002},
4077 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
4078 AR_NDP2_TIMER_MODE, 0x0004},
4079 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
4080 AR_NDP2_TIMER_MODE, 0x0008},
4081 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
4082 AR_NDP2_TIMER_MODE, 0x0010},
4083 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
4084 AR_NDP2_TIMER_MODE, 0x0020},
4085 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
4086 AR_NDP2_TIMER_MODE, 0x0040},
4087 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
4088 AR_NDP2_TIMER_MODE, 0x0080}
4089};
4090
4091/* HW generic timer primitives */
4092
4093/* compute and clear index of rightmost 1 */
4094static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
4095{
4096 u32 b;
4097
4098 b = *mask;
4099 b &= (0-b);
4100 *mask &= ~b;
4101 b *= debruijn32;
4102 b >>= 27;
4103
4104 return timer_table->gen_timer_index[b];
4105}
4106
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05304107u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304108{
4109 return REG_READ(ah, AR_TSF_L32);
4110}
4111
4112struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
4113 void (*trigger)(void *),
4114 void (*overflow)(void *),
4115 void *arg,
4116 u8 timer_index)
4117{
4118 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4119 struct ath_gen_timer *timer;
4120
4121 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
4122
4123 if (timer == NULL) {
4124 printk(KERN_DEBUG "Failed to allocate memory"
4125 "for hw timer[%d]\n", timer_index);
4126 return NULL;
4127 }
4128
4129 /* allocate a hardware generic timer slot */
4130 timer_table->timers[timer_index] = timer;
4131 timer->index = timer_index;
4132 timer->trigger = trigger;
4133 timer->overflow = overflow;
4134 timer->arg = arg;
4135
4136 return timer;
4137}
4138
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004139void ath9k_hw_gen_timer_start(struct ath_hw *ah,
4140 struct ath_gen_timer *timer,
4141 u32 timer_next,
4142 u32 timer_period)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304143{
4144 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4145 u32 tsf;
4146
4147 BUG_ON(!timer_period);
4148
4149 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
4150
4151 tsf = ath9k_hw_gettsf32(ah);
4152
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07004153 DPRINTF(ah, ATH_DBG_HWTIMER, "curent tsf %x period %x"
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304154 "timer_next %x\n", tsf, timer_period, timer_next);
4155
4156 /*
4157 * Pull timer_next forward if the current TSF already passed it
4158 * because of software latency
4159 */
4160 if (timer_next < tsf)
4161 timer_next = tsf + timer_period;
4162
4163 /*
4164 * Program generic timer registers
4165 */
4166 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
4167 timer_next);
4168 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
4169 timer_period);
4170 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4171 gen_tmr_configuration[timer->index].mode_mask);
4172
4173 /* Enable both trigger and thresh interrupt masks */
4174 REG_SET_BIT(ah, AR_IMR_S5,
4175 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4176 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304177}
4178
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07004179void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304180{
4181 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4182
4183 if ((timer->index < AR_FIRST_NDP_TIMER) ||
4184 (timer->index >= ATH_MAX_GEN_TIMER)) {
4185 return;
4186 }
4187
4188 /* Clear generic timer enable bits. */
4189 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4190 gen_tmr_configuration[timer->index].mode_mask);
4191
4192 /* Disable both trigger and thresh interrupt masks */
4193 REG_CLR_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)));
4196
4197 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304198}
4199
4200void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
4201{
4202 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4203
4204 /* free the hardware generic timer slot */
4205 timer_table->timers[timer->index] = NULL;
4206 kfree(timer);
4207}
4208
4209/*
4210 * Generic Timer Interrupts handling
4211 */
4212void ath_gen_timer_isr(struct ath_hw *ah)
4213{
4214 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4215 struct ath_gen_timer *timer;
4216 u32 trigger_mask, thresh_mask, index;
4217
4218 /* get hardware generic timer interrupt status */
4219 trigger_mask = ah->intr_gen_timer_trigger;
4220 thresh_mask = ah->intr_gen_timer_thresh;
4221 trigger_mask &= timer_table->timer_mask.val;
4222 thresh_mask &= timer_table->timer_mask.val;
4223
4224 trigger_mask &= ~thresh_mask;
4225
4226 while (thresh_mask) {
4227 index = rightmost_index(timer_table, &thresh_mask);
4228 timer = timer_table->timers[index];
4229 BUG_ON(!timer);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07004230 DPRINTF(ah, ATH_DBG_HWTIMER,
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304231 "TSF overflow for Gen timer %d\n", index);
4232 timer->overflow(timer->arg);
4233 }
4234
4235 while (trigger_mask) {
4236 index = rightmost_index(timer_table, &trigger_mask);
4237 timer = timer_table->timers[index];
4238 BUG_ON(!timer);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07004239 DPRINTF(ah, ATH_DBG_HWTIMER,
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304240 "Gen timer[%d] trigger\n", index);
4241 timer->trigger(timer->arg);
4242 }
4243}