2 * Copyright (c) 2008-2011 Atheros Communications Inc.
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.
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.
18 #include <linux/slab.h>
19 #include <linux/module.h>
20 #include <linux/time.h>
21 #include <linux/bitops.h>
22 #include <linux/etherdevice.h>
23 #include <linux/gpio.h>
24 #include <asm/unaligned.h>
28 #include "ar9003_mac.h"
29 #include "ar9003_mci.h"
30 #include "ar9003_phy.h"
33 static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
35 MODULE_AUTHOR("Atheros Communications");
36 MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
37 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
38 MODULE_LICENSE("Dual BSD/GPL");
40 static void ath9k_hw_set_clockrate(struct ath_hw *ah)
42 struct ath_common *common = ath9k_hw_common(ah);
43 struct ath9k_channel *chan = ah->curchan;
44 unsigned int clockrate;
46 /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
47 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
49 else if (!chan) /* should really check for CCK instead */
50 clockrate = ATH9K_CLOCK_RATE_CCK;
51 else if (IS_CHAN_2GHZ(chan))
52 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
53 else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
54 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
56 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
59 if (IS_CHAN_HT40(chan))
61 if (IS_CHAN_HALF_RATE(chan))
63 if (IS_CHAN_QUARTER_RATE(chan))
67 common->clockrate = clockrate;
70 static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
72 struct ath_common *common = ath9k_hw_common(ah);
74 return usecs * common->clockrate;
77 bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
81 BUG_ON(timeout < AH_TIME_QUANTUM);
83 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
84 if ((REG_READ(ah, reg) & mask) == val)
87 udelay(AH_TIME_QUANTUM);
90 ath_dbg(ath9k_hw_common(ah), ANY,
91 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
92 timeout, reg, REG_READ(ah, reg), mask, val);
96 EXPORT_SYMBOL(ath9k_hw_wait);
98 void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
103 if (IS_CHAN_HALF_RATE(chan))
105 else if (IS_CHAN_QUARTER_RATE(chan))
108 udelay(hw_delay + BASE_ACTIVATE_DELAY);
111 void ath9k_hw_write_array(struct ath_hw *ah, const struct ar5416IniArray *array,
112 int column, unsigned int *writecnt)
116 ENABLE_REGWRITE_BUFFER(ah);
117 for (r = 0; r < array->ia_rows; r++) {
118 REG_WRITE(ah, INI_RA(array, r, 0),
119 INI_RA(array, r, column));
122 REGWRITE_BUFFER_FLUSH(ah);
125 void ath9k_hw_read_array(struct ath_hw *ah, u32 array[][2], int size)
127 u32 *tmp_reg_list, *tmp_data;
130 tmp_reg_list = kmalloc(size * sizeof(u32), GFP_KERNEL);
132 dev_err(ah->dev, "%s: tmp_reg_list: alloc filed\n", __func__);
136 tmp_data = kmalloc(size * sizeof(u32), GFP_KERNEL);
138 dev_err(ah->dev, "%s tmp_data: alloc filed\n", __func__);
142 for (i = 0; i < size; i++)
143 tmp_reg_list[i] = array[i][0];
145 REG_READ_MULTI(ah, tmp_reg_list, tmp_data, size);
147 for (i = 0; i < size; i++)
148 array[i][1] = tmp_data[i];
155 u32 ath9k_hw_reverse_bits(u32 val, u32 n)
160 for (i = 0, retval = 0; i < n; i++) {
161 retval = (retval << 1) | (val & 1);
167 u16 ath9k_hw_computetxtime(struct ath_hw *ah,
169 u32 frameLen, u16 rateix,
172 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
178 case WLAN_RC_PHY_CCK:
179 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
182 numBits = frameLen << 3;
183 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
185 case WLAN_RC_PHY_OFDM:
186 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
187 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
188 numBits = OFDM_PLCP_BITS + (frameLen << 3);
189 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
190 txTime = OFDM_SIFS_TIME_QUARTER
191 + OFDM_PREAMBLE_TIME_QUARTER
192 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
193 } else if (ah->curchan &&
194 IS_CHAN_HALF_RATE(ah->curchan)) {
195 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
196 numBits = OFDM_PLCP_BITS + (frameLen << 3);
197 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
198 txTime = OFDM_SIFS_TIME_HALF +
199 OFDM_PREAMBLE_TIME_HALF
200 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
202 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
203 numBits = OFDM_PLCP_BITS + (frameLen << 3);
204 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
205 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
206 + (numSymbols * OFDM_SYMBOL_TIME);
210 ath_err(ath9k_hw_common(ah),
211 "Unknown phy %u (rate ix %u)\n", phy, rateix);
218 EXPORT_SYMBOL(ath9k_hw_computetxtime);
220 void ath9k_hw_get_channel_centers(struct ath_hw *ah,
221 struct ath9k_channel *chan,
222 struct chan_centers *centers)
226 if (!IS_CHAN_HT40(chan)) {
227 centers->ctl_center = centers->ext_center =
228 centers->synth_center = chan->channel;
232 if (IS_CHAN_HT40PLUS(chan)) {
233 centers->synth_center =
234 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
237 centers->synth_center =
238 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
242 centers->ctl_center =
243 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
244 /* 25 MHz spacing is supported by hw but not on upper layers */
245 centers->ext_center =
246 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
253 static bool ath9k_hw_read_revisions(struct ath_hw *ah)
258 if (ah->get_mac_revision)
259 ah->hw_version.macRev = ah->get_mac_revision();
261 switch (ah->hw_version.devid) {
262 case AR5416_AR9100_DEVID:
263 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
265 case AR9300_DEVID_AR9330:
266 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
267 if (!ah->get_mac_revision) {
268 val = REG_READ(ah, AR_SREV);
269 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
272 case AR9300_DEVID_AR9340:
273 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
275 case AR9300_DEVID_QCA955X:
276 ah->hw_version.macVersion = AR_SREV_VERSION_9550;
278 case AR9300_DEVID_AR953X:
279 ah->hw_version.macVersion = AR_SREV_VERSION_9531;
281 case AR9300_DEVID_QCA956X:
282 ah->hw_version.macVersion = AR_SREV_VERSION_9561;
286 srev = REG_READ(ah, AR_SREV);
289 ath_err(ath9k_hw_common(ah),
290 "Failed to read SREV register");
294 val = srev & AR_SREV_ID;
298 ah->hw_version.macVersion =
299 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
300 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
302 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
303 ah->is_pciexpress = true;
305 ah->is_pciexpress = (val &
306 AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
308 if (!AR_SREV_9100(ah))
309 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
311 ah->hw_version.macRev = val & AR_SREV_REVISION;
313 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
314 ah->is_pciexpress = true;
320 /************************************/
321 /* HW Attach, Detach, Init Routines */
322 /************************************/
324 static void ath9k_hw_disablepcie(struct ath_hw *ah)
326 if (!AR_SREV_5416(ah))
329 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
330 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
331 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
332 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
333 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
334 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
335 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
336 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
337 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
339 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
342 /* This should work for all families including legacy */
343 static bool ath9k_hw_chip_test(struct ath_hw *ah)
345 struct ath_common *common = ath9k_hw_common(ah);
346 u32 regAddr[2] = { AR_STA_ID0 };
348 static const u32 patternData[4] = {
349 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
353 if (!AR_SREV_9300_20_OR_LATER(ah)) {
355 regAddr[1] = AR_PHY_BASE + (8 << 2);
359 for (i = 0; i < loop_max; i++) {
360 u32 addr = regAddr[i];
363 regHold[i] = REG_READ(ah, addr);
364 for (j = 0; j < 0x100; j++) {
365 wrData = (j << 16) | j;
366 REG_WRITE(ah, addr, wrData);
367 rdData = REG_READ(ah, addr);
368 if (rdData != wrData) {
370 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
371 addr, wrData, rdData);
375 for (j = 0; j < 4; j++) {
376 wrData = patternData[j];
377 REG_WRITE(ah, addr, wrData);
378 rdData = REG_READ(ah, addr);
379 if (wrData != rdData) {
381 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
382 addr, wrData, rdData);
386 REG_WRITE(ah, regAddr[i], regHold[i]);
393 static void ath9k_hw_init_config(struct ath_hw *ah)
395 struct ath_common *common = ath9k_hw_common(ah);
397 ah->config.dma_beacon_response_time = 1;
398 ah->config.sw_beacon_response_time = 6;
399 ah->config.cwm_ignore_extcca = false;
400 ah->config.analog_shiftreg = 1;
402 ah->config.rx_intr_mitigation = true;
404 if (AR_SREV_9300_20_OR_LATER(ah)) {
405 ah->config.rimt_last = 500;
406 ah->config.rimt_first = 2000;
408 ah->config.rimt_last = 250;
409 ah->config.rimt_first = 700;
412 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
413 ah->config.pll_pwrsave = 7;
416 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
417 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
418 * This means we use it for all AR5416 devices, and the few
419 * minor PCI AR9280 devices out there.
421 * Serialization is required because these devices do not handle
422 * well the case of two concurrent reads/writes due to the latency
423 * involved. During one read/write another read/write can be issued
424 * on another CPU while the previous read/write may still be working
425 * on our hardware, if we hit this case the hardware poops in a loop.
426 * We prevent this by serializing reads and writes.
428 * This issue is not present on PCI-Express devices or pre-AR5416
429 * devices (legacy, 802.11abg).
431 if (num_possible_cpus() > 1)
432 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
434 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
435 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
436 ((AR_SREV_9160(ah) || AR_SREV_9280(ah) || AR_SREV_9287(ah)) &&
437 !ah->is_pciexpress)) {
438 ah->config.serialize_regmode = SER_REG_MODE_ON;
440 ah->config.serialize_regmode = SER_REG_MODE_OFF;
444 ath_dbg(common, RESET, "serialize_regmode is %d\n",
445 ah->config.serialize_regmode);
447 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
448 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
450 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
453 static void ath9k_hw_init_defaults(struct ath_hw *ah)
455 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
457 regulatory->country_code = CTRY_DEFAULT;
458 regulatory->power_limit = MAX_RATE_POWER;
460 ah->hw_version.magic = AR5416_MAGIC;
461 ah->hw_version.subvendorid = 0;
463 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE |
464 AR_STA_ID1_MCAST_KSRCH;
465 if (AR_SREV_9100(ah))
466 ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
468 ah->slottime = ATH9K_SLOT_TIME_9;
469 ah->globaltxtimeout = (u32) -1;
470 ah->power_mode = ATH9K_PM_UNDEFINED;
471 ah->htc_reset_init = true;
473 ah->tpc_enabled = false;
475 ah->ani_function = ATH9K_ANI_ALL;
476 if (!AR_SREV_9300_20_OR_LATER(ah))
477 ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
479 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
480 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
482 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
485 static int ath9k_hw_init_macaddr(struct ath_hw *ah)
487 struct ath_common *common = ath9k_hw_common(ah);
491 static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
494 for (i = 0; i < 3; i++) {
495 eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
497 common->macaddr[2 * i] = eeval >> 8;
498 common->macaddr[2 * i + 1] = eeval & 0xff;
500 if (!is_valid_ether_addr(common->macaddr)) {
502 "eeprom contains invalid mac address: %pM\n",
505 random_ether_addr(common->macaddr);
507 "random mac address will be used: %pM\n",
514 static int ath9k_hw_post_init(struct ath_hw *ah)
516 struct ath_common *common = ath9k_hw_common(ah);
519 if (common->bus_ops->ath_bus_type != ATH_USB) {
520 if (!ath9k_hw_chip_test(ah))
524 if (!AR_SREV_9300_20_OR_LATER(ah)) {
525 ecode = ar9002_hw_rf_claim(ah);
530 ecode = ath9k_hw_eeprom_init(ah);
534 ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n",
535 ah->eep_ops->get_eeprom_ver(ah),
536 ah->eep_ops->get_eeprom_rev(ah));
538 ath9k_hw_ani_init(ah);
541 * EEPROM needs to be initialized before we do this.
542 * This is required for regulatory compliance.
544 if (AR_SREV_9300_20_OR_LATER(ah)) {
545 u16 regdmn = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
546 if ((regdmn & 0xF0) == CTL_FCC) {
547 ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_2GHZ;
548 ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_5GHZ;
555 static int ath9k_hw_attach_ops(struct ath_hw *ah)
557 if (!AR_SREV_9300_20_OR_LATER(ah))
558 return ar9002_hw_attach_ops(ah);
560 ar9003_hw_attach_ops(ah);
564 /* Called for all hardware families */
565 static int __ath9k_hw_init(struct ath_hw *ah)
567 struct ath_common *common = ath9k_hw_common(ah);
570 if (!ath9k_hw_read_revisions(ah)) {
571 ath_err(common, "Could not read hardware revisions");
575 switch (ah->hw_version.macVersion) {
576 case AR_SREV_VERSION_5416_PCI:
577 case AR_SREV_VERSION_5416_PCIE:
578 case AR_SREV_VERSION_9160:
579 case AR_SREV_VERSION_9100:
580 case AR_SREV_VERSION_9280:
581 case AR_SREV_VERSION_9285:
582 case AR_SREV_VERSION_9287:
583 case AR_SREV_VERSION_9271:
584 case AR_SREV_VERSION_9300:
585 case AR_SREV_VERSION_9330:
586 case AR_SREV_VERSION_9485:
587 case AR_SREV_VERSION_9340:
588 case AR_SREV_VERSION_9462:
589 case AR_SREV_VERSION_9550:
590 case AR_SREV_VERSION_9565:
591 case AR_SREV_VERSION_9531:
592 case AR_SREV_VERSION_9561:
596 "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
597 ah->hw_version.macVersion, ah->hw_version.macRev);
602 * Read back AR_WA into a permanent copy and set bits 14 and 17.
603 * We need to do this to avoid RMW of this register. We cannot
604 * read the reg when chip is asleep.
606 if (AR_SREV_9300_20_OR_LATER(ah)) {
607 ah->WARegVal = REG_READ(ah, AR_WA);
608 ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
609 AR_WA_ASPM_TIMER_BASED_DISABLE);
612 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
613 ath_err(common, "Couldn't reset chip\n");
617 if (AR_SREV_9565(ah)) {
618 ah->WARegVal |= AR_WA_BIT22;
619 REG_WRITE(ah, AR_WA, ah->WARegVal);
622 ath9k_hw_init_defaults(ah);
623 ath9k_hw_init_config(ah);
625 r = ath9k_hw_attach_ops(ah);
629 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
630 ath_err(common, "Couldn't wakeup chip\n");
634 if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
635 AR_SREV_9330(ah) || AR_SREV_9550(ah))
636 ah->is_pciexpress = false;
638 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
639 ath9k_hw_init_cal_settings(ah);
641 if (!ah->is_pciexpress)
642 ath9k_hw_disablepcie(ah);
644 r = ath9k_hw_post_init(ah);
648 ath9k_hw_init_mode_gain_regs(ah);
649 r = ath9k_hw_fill_cap_info(ah);
653 r = ath9k_hw_init_macaddr(ah);
655 ath_err(common, "Failed to initialize MAC address\n");
659 ath9k_hw_init_hang_checks(ah);
661 common->state = ATH_HW_INITIALIZED;
666 int ath9k_hw_init(struct ath_hw *ah)
669 struct ath_common *common = ath9k_hw_common(ah);
671 /* These are all the AR5008/AR9001/AR9002/AR9003 hardware family of chipsets */
672 switch (ah->hw_version.devid) {
673 case AR5416_DEVID_PCI:
674 case AR5416_DEVID_PCIE:
675 case AR5416_AR9100_DEVID:
676 case AR9160_DEVID_PCI:
677 case AR9280_DEVID_PCI:
678 case AR9280_DEVID_PCIE:
679 case AR9285_DEVID_PCIE:
680 case AR9287_DEVID_PCI:
681 case AR9287_DEVID_PCIE:
682 case AR2427_DEVID_PCIE:
683 case AR9300_DEVID_PCIE:
684 case AR9300_DEVID_AR9485_PCIE:
685 case AR9300_DEVID_AR9330:
686 case AR9300_DEVID_AR9340:
687 case AR9300_DEVID_QCA955X:
688 case AR9300_DEVID_AR9580:
689 case AR9300_DEVID_AR9462:
690 case AR9485_DEVID_AR1111:
691 case AR9300_DEVID_AR9565:
692 case AR9300_DEVID_AR953X:
693 case AR9300_DEVID_QCA956X:
696 if (common->bus_ops->ath_bus_type == ATH_USB)
698 ath_err(common, "Hardware device ID 0x%04x not supported\n",
699 ah->hw_version.devid);
703 ret = __ath9k_hw_init(ah);
706 "Unable to initialize hardware; initialization status: %d\n",
715 EXPORT_SYMBOL(ath9k_hw_init);
717 static void ath9k_hw_init_qos(struct ath_hw *ah)
719 ENABLE_REGWRITE_BUFFER(ah);
721 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
722 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
724 REG_WRITE(ah, AR_QOS_NO_ACK,
725 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
726 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
727 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
729 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
730 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
731 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
732 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
733 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
735 REGWRITE_BUFFER_FLUSH(ah);
738 u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
740 struct ath_common *common = ath9k_hw_common(ah);
743 REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
745 REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
747 while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0) {
751 if (WARN_ON_ONCE(i >= 100)) {
752 ath_err(common, "PLL4 meaurement not done\n");
759 return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
761 EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
763 static void ath9k_hw_init_pll(struct ath_hw *ah,
764 struct ath9k_channel *chan)
768 pll = ath9k_hw_compute_pll_control(ah, chan);
770 if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
771 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
772 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
773 AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
774 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
775 AR_CH0_DPLL2_KD, 0x40);
776 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
777 AR_CH0_DPLL2_KI, 0x4);
779 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
780 AR_CH0_BB_DPLL1_REFDIV, 0x5);
781 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
782 AR_CH0_BB_DPLL1_NINI, 0x58);
783 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
784 AR_CH0_BB_DPLL1_NFRAC, 0x0);
786 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
787 AR_CH0_BB_DPLL2_OUTDIV, 0x1);
788 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
789 AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
790 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
791 AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
793 /* program BB PLL phase_shift to 0x6 */
794 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
795 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
797 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
798 AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
800 } else if (AR_SREV_9330(ah)) {
801 u32 ddr_dpll2, pll_control2, kd;
803 if (ah->is_clk_25mhz) {
804 ddr_dpll2 = 0x18e82f01;
805 pll_control2 = 0xe04a3d;
808 ddr_dpll2 = 0x19e82f01;
809 pll_control2 = 0x886666;
813 /* program DDR PLL ki and kd value */
814 REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
816 /* program DDR PLL phase_shift */
817 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
818 AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
820 REG_WRITE(ah, AR_RTC_PLL_CONTROL,
821 pll | AR_RTC_9300_PLL_BYPASS);
824 /* program refdiv, nint, frac to RTC register */
825 REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
827 /* program BB PLL kd and ki value */
828 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
829 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
831 /* program BB PLL phase_shift */
832 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
833 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
834 } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah) ||
836 u32 regval, pll2_divint, pll2_divfrac, refdiv;
838 REG_WRITE(ah, AR_RTC_PLL_CONTROL,
839 pll | AR_RTC_9300_SOC_PLL_BYPASS);
842 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
845 if (ah->is_clk_25mhz) {
846 if (AR_SREV_9531(ah) || AR_SREV_9561(ah)) {
848 pll2_divfrac = 0xa3d2;
852 pll2_divfrac = 0x1eb85;
856 if (AR_SREV_9340(ah)) {
862 pll2_divfrac = (AR_SREV_9531(ah) ||
869 regval = REG_READ(ah, AR_PHY_PLL_MODE);
870 if (AR_SREV_9531(ah) || AR_SREV_9561(ah))
871 regval |= (0x1 << 22);
873 regval |= (0x1 << 16);
874 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
877 REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
878 (pll2_divint << 18) | pll2_divfrac);
881 regval = REG_READ(ah, AR_PHY_PLL_MODE);
882 if (AR_SREV_9340(ah))
883 regval = (regval & 0x80071fff) |
888 else if (AR_SREV_9531(ah) || AR_SREV_9561(ah)) {
889 regval = (regval & 0x01c00fff) |
895 if (AR_SREV_9531(ah))
896 regval |= (0x6 << 12);
898 regval = (regval & 0x80071fff) |
903 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
905 if (AR_SREV_9531(ah) || AR_SREV_9561(ah))
906 REG_WRITE(ah, AR_PHY_PLL_MODE,
907 REG_READ(ah, AR_PHY_PLL_MODE) & 0xffbfffff);
909 REG_WRITE(ah, AR_PHY_PLL_MODE,
910 REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
915 if (AR_SREV_9565(ah))
917 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
919 if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
923 /* Switch the core clock for ar9271 to 117Mhz */
924 if (AR_SREV_9271(ah)) {
926 REG_WRITE(ah, 0x50040, 0x304);
929 udelay(RTC_PLL_SETTLE_DELAY);
931 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
934 static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
935 enum nl80211_iftype opmode)
937 u32 sync_default = AR_INTR_SYNC_DEFAULT;
938 u32 imr_reg = AR_IMR_TXERR |
944 if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah) ||
946 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
948 if (AR_SREV_9300_20_OR_LATER(ah)) {
949 imr_reg |= AR_IMR_RXOK_HP;
950 if (ah->config.rx_intr_mitigation)
951 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
953 imr_reg |= AR_IMR_RXOK_LP;
956 if (ah->config.rx_intr_mitigation)
957 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
959 imr_reg |= AR_IMR_RXOK;
962 if (ah->config.tx_intr_mitigation)
963 imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
965 imr_reg |= AR_IMR_TXOK;
967 ENABLE_REGWRITE_BUFFER(ah);
969 REG_WRITE(ah, AR_IMR, imr_reg);
970 ah->imrs2_reg |= AR_IMR_S2_GTT;
971 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
973 if (!AR_SREV_9100(ah)) {
974 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
975 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
976 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
979 REGWRITE_BUFFER_FLUSH(ah);
981 if (AR_SREV_9300_20_OR_LATER(ah)) {
982 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
983 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
984 REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
985 REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
989 static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us)
991 u32 val = ath9k_hw_mac_to_clks(ah, us - 2);
992 val = min(val, (u32) 0xFFFF);
993 REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val);
996 void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
998 u32 val = ath9k_hw_mac_to_clks(ah, us);
999 val = min(val, (u32) 0xFFFF);
1000 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
1003 void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
1005 u32 val = ath9k_hw_mac_to_clks(ah, us);
1006 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
1007 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
1010 void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
1012 u32 val = ath9k_hw_mac_to_clks(ah, us);
1013 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
1014 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
1017 static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
1020 ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n",
1022 ah->globaltxtimeout = (u32) -1;
1025 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
1026 ah->globaltxtimeout = tu;
1031 void ath9k_hw_init_global_settings(struct ath_hw *ah)
1033 struct ath_common *common = ath9k_hw_common(ah);
1034 const struct ath9k_channel *chan = ah->curchan;
1035 int acktimeout, ctstimeout, ack_offset = 0;
1038 int rx_lat = 0, tx_lat = 0, eifs = 0;
1041 ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n",
1047 if (ah->misc_mode != 0)
1048 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
1050 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1056 if (IS_CHAN_5GHZ(chan))
1061 if (IS_CHAN_HALF_RATE(chan)) {
1065 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1071 } else if (IS_CHAN_QUARTER_RATE(chan)) {
1073 rx_lat = (rx_lat * 4) - 1;
1075 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1082 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1083 eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
1084 reg = AR_USEC_ASYNC_FIFO;
1086 eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
1088 reg = REG_READ(ah, AR_USEC);
1090 rx_lat = MS(reg, AR_USEC_RX_LAT);
1091 tx_lat = MS(reg, AR_USEC_TX_LAT);
1093 slottime = ah->slottime;
1096 /* As defined by IEEE 802.11-2007 17.3.8.6 */
1097 slottime += 3 * ah->coverage_class;
1098 acktimeout = slottime + sifstime + ack_offset;
1099 ctstimeout = acktimeout;
1102 * Workaround for early ACK timeouts, add an offset to match the
1103 * initval's 64us ack timeout value. Use 48us for the CTS timeout.
1104 * This was initially only meant to work around an issue with delayed
1105 * BA frames in some implementations, but it has been found to fix ACK
1106 * timeout issues in other cases as well.
1108 if (IS_CHAN_2GHZ(chan) &&
1109 !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) {
1110 acktimeout += 64 - sifstime - ah->slottime;
1111 ctstimeout += 48 - sifstime - ah->slottime;
1114 if (ah->dynack.enabled) {
1115 acktimeout = ah->dynack.ackto;
1116 ctstimeout = acktimeout;
1117 slottime = (acktimeout - 3) / 2;
1119 ah->dynack.ackto = acktimeout;
1122 ath9k_hw_set_sifs_time(ah, sifstime);
1123 ath9k_hw_setslottime(ah, slottime);
1124 ath9k_hw_set_ack_timeout(ah, acktimeout);
1125 ath9k_hw_set_cts_timeout(ah, ctstimeout);
1126 if (ah->globaltxtimeout != (u32) -1)
1127 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
1129 REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
1130 REG_RMW(ah, AR_USEC,
1131 (common->clockrate - 1) |
1132 SM(rx_lat, AR_USEC_RX_LAT) |
1133 SM(tx_lat, AR_USEC_TX_LAT),
1134 AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
1137 EXPORT_SYMBOL(ath9k_hw_init_global_settings);
1139 void ath9k_hw_deinit(struct ath_hw *ah)
1141 struct ath_common *common = ath9k_hw_common(ah);
1143 if (common->state < ATH_HW_INITIALIZED)
1146 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1148 EXPORT_SYMBOL(ath9k_hw_deinit);
1154 u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
1156 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1158 if (IS_CHAN_2GHZ(chan))
1166 /****************************************/
1167 /* Reset and Channel Switching Routines */
1168 /****************************************/
1170 static inline void ath9k_hw_set_dma(struct ath_hw *ah)
1172 struct ath_common *common = ath9k_hw_common(ah);
1175 ENABLE_REGWRITE_BUFFER(ah);
1178 * set AHB_MODE not to do cacheline prefetches
1180 if (!AR_SREV_9300_20_OR_LATER(ah))
1181 REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
1184 * let mac dma reads be in 128 byte chunks
1186 REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
1188 REGWRITE_BUFFER_FLUSH(ah);
1191 * Restore TX Trigger Level to its pre-reset value.
1192 * The initial value depends on whether aggregation is enabled, and is
1193 * adjusted whenever underruns are detected.
1195 if (!AR_SREV_9300_20_OR_LATER(ah))
1196 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
1198 ENABLE_REGWRITE_BUFFER(ah);
1201 * let mac dma writes be in 128 byte chunks
1203 REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
1206 * Setup receive FIFO threshold to hold off TX activities
1208 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1210 if (AR_SREV_9300_20_OR_LATER(ah)) {
1211 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
1212 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
1214 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
1215 ah->caps.rx_status_len);
1219 * reduce the number of usable entries in PCU TXBUF to avoid
1220 * wrap around issues.
1222 if (AR_SREV_9285(ah)) {
1223 /* For AR9285 the number of Fifos are reduced to half.
1224 * So set the usable tx buf size also to half to
1225 * avoid data/delimiter underruns
1227 txbuf_size = AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE;
1228 } else if (AR_SREV_9340_13_OR_LATER(ah)) {
1229 /* Uses fewer entries for AR934x v1.3+ to prevent rx overruns */
1230 txbuf_size = AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE;
1232 txbuf_size = AR_PCU_TXBUF_CTRL_USABLE_SIZE;
1235 if (!AR_SREV_9271(ah))
1236 REG_WRITE(ah, AR_PCU_TXBUF_CTRL, txbuf_size);
1238 REGWRITE_BUFFER_FLUSH(ah);
1240 if (AR_SREV_9300_20_OR_LATER(ah))
1241 ath9k_hw_reset_txstatus_ring(ah);
1244 static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
1246 u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
1247 u32 set = AR_STA_ID1_KSRCH_MODE;
1249 ENABLE_REG_RMW_BUFFER(ah);
1251 case NL80211_IFTYPE_ADHOC:
1252 if (!AR_SREV_9340_13(ah)) {
1253 set |= AR_STA_ID1_ADHOC;
1254 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1258 case NL80211_IFTYPE_OCB:
1259 case NL80211_IFTYPE_MESH_POINT:
1260 case NL80211_IFTYPE_AP:
1261 set |= AR_STA_ID1_STA_AP;
1263 case NL80211_IFTYPE_STATION:
1264 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1267 if (!ah->is_monitoring)
1271 REG_RMW(ah, AR_STA_ID1, set, mask);
1272 REG_RMW_BUFFER_FLUSH(ah);
1275 void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1276 u32 *coef_mantissa, u32 *coef_exponent)
1278 u32 coef_exp, coef_man;
1280 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1281 if ((coef_scaled >> coef_exp) & 0x1)
1284 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1286 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1288 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1289 *coef_exponent = coef_exp - 16;
1293 * call external reset function to reset WMAC if:
1294 * - doing a cold reset
1295 * - we have pending frames in the TX queues.
1297 static bool ath9k_hw_ar9330_reset_war(struct ath_hw *ah, int type)
1301 for (i = 0; i < AR_NUM_QCU; i++) {
1302 npend = ath9k_hw_numtxpending(ah, i);
1307 if (ah->external_reset &&
1308 (npend || type == ATH9K_RESET_COLD)) {
1311 ath_dbg(ath9k_hw_common(ah), RESET,
1312 "reset MAC via external reset\n");
1314 reset_err = ah->external_reset();
1316 ath_err(ath9k_hw_common(ah),
1317 "External reset failed, err=%d\n",
1322 REG_WRITE(ah, AR_RTC_RESET, 1);
1328 static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
1333 if (AR_SREV_9100(ah)) {
1334 REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
1335 AR_RTC_DERIVED_CLK_PERIOD, 1);
1336 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1339 ENABLE_REGWRITE_BUFFER(ah);
1341 if (AR_SREV_9300_20_OR_LATER(ah)) {
1342 REG_WRITE(ah, AR_WA, ah->WARegVal);
1346 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1347 AR_RTC_FORCE_WAKE_ON_INT);
1349 if (AR_SREV_9100(ah)) {
1350 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1351 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1353 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1354 if (AR_SREV_9340(ah))
1355 tmpReg &= AR9340_INTR_SYNC_LOCAL_TIMEOUT;
1357 tmpReg &= AR_INTR_SYNC_LOCAL_TIMEOUT |
1358 AR_INTR_SYNC_RADM_CPL_TIMEOUT;
1362 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1365 if (!AR_SREV_9300_20_OR_LATER(ah))
1367 REG_WRITE(ah, AR_RC, val);
1369 } else if (!AR_SREV_9300_20_OR_LATER(ah))
1370 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1372 rst_flags = AR_RTC_RC_MAC_WARM;
1373 if (type == ATH9K_RESET_COLD)
1374 rst_flags |= AR_RTC_RC_MAC_COLD;
1377 if (AR_SREV_9330(ah)) {
1378 if (!ath9k_hw_ar9330_reset_war(ah, type))
1382 if (ath9k_hw_mci_is_enabled(ah))
1383 ar9003_mci_check_gpm_offset(ah);
1385 REG_WRITE(ah, AR_RTC_RC, rst_flags);
1387 REGWRITE_BUFFER_FLUSH(ah);
1389 if (AR_SREV_9300_20_OR_LATER(ah))
1391 else if (AR_SREV_9100(ah))
1396 REG_WRITE(ah, AR_RTC_RC, 0);
1397 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
1398 ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n");
1402 if (!AR_SREV_9100(ah))
1403 REG_WRITE(ah, AR_RC, 0);
1405 if (AR_SREV_9100(ah))
1411 static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
1413 ENABLE_REGWRITE_BUFFER(ah);
1415 if (AR_SREV_9300_20_OR_LATER(ah)) {
1416 REG_WRITE(ah, AR_WA, ah->WARegVal);
1420 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1421 AR_RTC_FORCE_WAKE_ON_INT);
1423 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
1424 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1426 REG_WRITE(ah, AR_RTC_RESET, 0);
1428 REGWRITE_BUFFER_FLUSH(ah);
1432 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
1433 REG_WRITE(ah, AR_RC, 0);
1435 REG_WRITE(ah, AR_RTC_RESET, 1);
1437 if (!ath9k_hw_wait(ah,
1442 ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n");
1446 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1449 static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
1453 if (AR_SREV_9300_20_OR_LATER(ah)) {
1454 REG_WRITE(ah, AR_WA, ah->WARegVal);
1458 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1459 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1461 if (!ah->reset_power_on)
1462 type = ATH9K_RESET_POWER_ON;
1465 case ATH9K_RESET_POWER_ON:
1466 ret = ath9k_hw_set_reset_power_on(ah);
1468 ah->reset_power_on = true;
1470 case ATH9K_RESET_WARM:
1471 case ATH9K_RESET_COLD:
1472 ret = ath9k_hw_set_reset(ah, type);
1481 static bool ath9k_hw_chip_reset(struct ath_hw *ah,
1482 struct ath9k_channel *chan)
1484 int reset_type = ATH9K_RESET_WARM;
1486 if (AR_SREV_9280(ah)) {
1487 if (ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1488 reset_type = ATH9K_RESET_POWER_ON;
1490 reset_type = ATH9K_RESET_COLD;
1491 } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) ||
1492 (REG_READ(ah, AR_CR) & AR_CR_RXE))
1493 reset_type = ATH9K_RESET_COLD;
1495 if (!ath9k_hw_set_reset_reg(ah, reset_type))
1498 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1501 ah->chip_fullsleep = false;
1503 if (AR_SREV_9330(ah))
1504 ar9003_hw_internal_regulator_apply(ah);
1505 ath9k_hw_init_pll(ah, chan);
1510 static bool ath9k_hw_channel_change(struct ath_hw *ah,
1511 struct ath9k_channel *chan)
1513 struct ath_common *common = ath9k_hw_common(ah);
1514 struct ath9k_hw_capabilities *pCap = &ah->caps;
1515 bool band_switch = false, mode_diff = false;
1516 u8 ini_reloaded = 0;
1520 if (pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) {
1521 u32 flags_diff = chan->channelFlags ^ ah->curchan->channelFlags;
1522 band_switch = !!(flags_diff & CHANNEL_5GHZ);
1523 mode_diff = !!(flags_diff & ~CHANNEL_HT);
1526 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1527 if (ath9k_hw_numtxpending(ah, qnum)) {
1528 ath_dbg(common, QUEUE,
1529 "Transmit frames pending on queue %d\n", qnum);
1534 if (!ath9k_hw_rfbus_req(ah)) {
1535 ath_err(common, "Could not kill baseband RX\n");
1539 if (band_switch || mode_diff) {
1540 ath9k_hw_mark_phy_inactive(ah);
1544 ath9k_hw_init_pll(ah, chan);
1546 if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
1547 ath_err(common, "Failed to do fast channel change\n");
1552 ath9k_hw_set_channel_regs(ah, chan);
1554 r = ath9k_hw_rf_set_freq(ah, chan);
1556 ath_err(common, "Failed to set channel\n");
1559 ath9k_hw_set_clockrate(ah);
1560 ath9k_hw_apply_txpower(ah, chan, false);
1562 ath9k_hw_set_delta_slope(ah, chan);
1563 ath9k_hw_spur_mitigate_freq(ah, chan);
1565 if (band_switch || ini_reloaded)
1566 ah->eep_ops->set_board_values(ah, chan);
1568 ath9k_hw_init_bb(ah, chan);
1569 ath9k_hw_rfbus_done(ah);
1571 if (band_switch || ini_reloaded) {
1572 ah->ah_flags |= AH_FASTCC;
1573 ath9k_hw_init_cal(ah, chan);
1574 ah->ah_flags &= ~AH_FASTCC;
1580 static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
1582 u32 gpio_mask = ah->gpio_mask;
1585 for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
1586 if (!(gpio_mask & 1))
1589 ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1590 ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
1594 void ath9k_hw_check_nav(struct ath_hw *ah)
1596 struct ath_common *common = ath9k_hw_common(ah);
1599 val = REG_READ(ah, AR_NAV);
1600 if (val != 0xdeadbeef && val > 0x7fff) {
1601 ath_dbg(common, BSTUCK, "Abnormal NAV: 0x%x\n", val);
1602 REG_WRITE(ah, AR_NAV, 0);
1605 EXPORT_SYMBOL(ath9k_hw_check_nav);
1607 bool ath9k_hw_check_alive(struct ath_hw *ah)
1612 /* Check if chip failed to wake up */
1613 if (REG_READ(ah, AR_CFG) == 0xdeadbeef)
1616 if (AR_SREV_9300(ah))
1617 return !ath9k_hw_detect_mac_hang(ah);
1619 if (AR_SREV_9285_12_OR_LATER(ah))
1622 last_val = REG_READ(ah, AR_OBS_BUS_1);
1624 reg = REG_READ(ah, AR_OBS_BUS_1);
1625 if (reg != last_val)
1630 if ((reg & 0x7E7FFFEF) == 0x00702400)
1633 switch (reg & 0x7E000B00) {
1641 } while (count-- > 0);
1645 EXPORT_SYMBOL(ath9k_hw_check_alive);
1647 static void ath9k_hw_init_mfp(struct ath_hw *ah)
1649 /* Setup MFP options for CCMP */
1650 if (AR_SREV_9280_20_OR_LATER(ah)) {
1651 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1652 * frames when constructing CCMP AAD. */
1653 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1655 if (AR_SREV_9271(ah) || AR_DEVID_7010(ah))
1656 ah->sw_mgmt_crypto_tx = true;
1658 ah->sw_mgmt_crypto_tx = false;
1659 ah->sw_mgmt_crypto_rx = false;
1660 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1661 /* Disable hardware crypto for management frames */
1662 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1663 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1664 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1665 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1666 ah->sw_mgmt_crypto_tx = true;
1667 ah->sw_mgmt_crypto_rx = true;
1669 ah->sw_mgmt_crypto_tx = true;
1670 ah->sw_mgmt_crypto_rx = true;
1674 static void ath9k_hw_reset_opmode(struct ath_hw *ah,
1675 u32 macStaId1, u32 saveDefAntenna)
1677 struct ath_common *common = ath9k_hw_common(ah);
1679 ENABLE_REGWRITE_BUFFER(ah);
1681 REG_RMW(ah, AR_STA_ID1, macStaId1
1682 | AR_STA_ID1_RTS_USE_DEF
1683 | ah->sta_id1_defaults,
1684 ~AR_STA_ID1_SADH_MASK);
1685 ath_hw_setbssidmask(common);
1686 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1687 ath9k_hw_write_associd(ah);
1688 REG_WRITE(ah, AR_ISR, ~0);
1689 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1691 REGWRITE_BUFFER_FLUSH(ah);
1693 ath9k_hw_set_operating_mode(ah, ah->opmode);
1696 static void ath9k_hw_init_queues(struct ath_hw *ah)
1700 ENABLE_REGWRITE_BUFFER(ah);
1702 for (i = 0; i < AR_NUM_DCU; i++)
1703 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1705 REGWRITE_BUFFER_FLUSH(ah);
1708 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1709 ath9k_hw_resettxqueue(ah, i);
1713 * For big endian systems turn on swapping for descriptors
1715 static void ath9k_hw_init_desc(struct ath_hw *ah)
1717 struct ath_common *common = ath9k_hw_common(ah);
1719 if (AR_SREV_9100(ah)) {
1721 mask = REG_READ(ah, AR_CFG);
1722 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
1723 ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n",
1726 mask = INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1727 REG_WRITE(ah, AR_CFG, mask);
1728 ath_dbg(common, RESET, "Setting CFG 0x%x\n",
1729 REG_READ(ah, AR_CFG));
1732 if (common->bus_ops->ath_bus_type == ATH_USB) {
1733 /* Configure AR9271 target WLAN */
1734 if (AR_SREV_9271(ah))
1735 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
1737 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1740 else if (AR_SREV_9330(ah) || AR_SREV_9340(ah) ||
1741 AR_SREV_9550(ah) || AR_SREV_9531(ah) ||
1743 REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
1745 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1751 * Fast channel change:
1752 * (Change synthesizer based on channel freq without resetting chip)
1754 static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
1756 struct ath_common *common = ath9k_hw_common(ah);
1757 struct ath9k_hw_capabilities *pCap = &ah->caps;
1760 if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
1763 if (ah->chip_fullsleep)
1769 if (chan->channel == ah->curchan->channel)
1772 if ((ah->curchan->channelFlags | chan->channelFlags) &
1773 (CHANNEL_HALF | CHANNEL_QUARTER))
1777 * If cross-band fcc is not supoprted, bail out if channelFlags differ.
1779 if (!(pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) &&
1780 ((chan->channelFlags ^ ah->curchan->channelFlags) & ~CHANNEL_HT))
1783 if (!ath9k_hw_check_alive(ah))
1787 * For AR9462, make sure that calibration data for
1788 * re-using are present.
1790 if (AR_SREV_9462(ah) && (ah->caldata &&
1791 (!test_bit(TXIQCAL_DONE, &ah->caldata->cal_flags) ||
1792 !test_bit(TXCLCAL_DONE, &ah->caldata->cal_flags) ||
1793 !test_bit(RTT_DONE, &ah->caldata->cal_flags))))
1796 ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n",
1797 ah->curchan->channel, chan->channel);
1799 ret = ath9k_hw_channel_change(ah, chan);
1803 if (ath9k_hw_mci_is_enabled(ah))
1804 ar9003_mci_2g5g_switch(ah, false);
1806 ath9k_hw_loadnf(ah, ah->curchan);
1807 ath9k_hw_start_nfcal(ah, true);
1809 if (AR_SREV_9271(ah))
1810 ar9002_hw_load_ani_reg(ah, chan);
1817 u32 ath9k_hw_get_tsf_offset(struct timespec *last, struct timespec *cur)
1823 getrawmonotonic(&ts);
1827 usec = cur->tv_sec * 1000000ULL + cur->tv_nsec / 1000;
1828 usec -= last->tv_sec * 1000000ULL + last->tv_nsec / 1000;
1832 EXPORT_SYMBOL(ath9k_hw_get_tsf_offset);
1834 int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1835 struct ath9k_hw_cal_data *caldata, bool fastcc)
1837 struct ath_common *common = ath9k_hw_common(ah);
1844 bool start_mci_reset = false;
1845 bool save_fullsleep = ah->chip_fullsleep;
1847 if (ath9k_hw_mci_is_enabled(ah)) {
1848 start_mci_reset = ar9003_mci_start_reset(ah, chan);
1849 if (start_mci_reset)
1853 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1856 if (ah->curchan && !ah->chip_fullsleep)
1857 ath9k_hw_getnf(ah, ah->curchan);
1859 ah->caldata = caldata;
1860 if (caldata && (chan->channel != caldata->channel ||
1861 chan->channelFlags != caldata->channelFlags)) {
1862 /* Operating channel changed, reset channel calibration data */
1863 memset(caldata, 0, sizeof(*caldata));
1864 ath9k_init_nfcal_hist_buffer(ah, chan);
1865 } else if (caldata) {
1866 clear_bit(PAPRD_PACKET_SENT, &caldata->cal_flags);
1868 ah->noise = ath9k_hw_getchan_noise(ah, chan, chan->noisefloor);
1871 r = ath9k_hw_do_fastcc(ah, chan);
1876 if (ath9k_hw_mci_is_enabled(ah))
1877 ar9003_mci_stop_bt(ah, save_fullsleep);
1879 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1880 if (saveDefAntenna == 0)
1883 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1885 /* Save TSF before chip reset, a cold reset clears it */
1886 tsf = ath9k_hw_gettsf64(ah);
1887 usec = ktime_to_us(ktime_get_raw());
1889 saveLedState = REG_READ(ah, AR_CFG_LED) &
1890 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1891 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1893 ath9k_hw_mark_phy_inactive(ah);
1895 ah->paprd_table_write_done = false;
1897 /* Only required on the first reset */
1898 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1900 AR9271_RESET_POWER_DOWN_CONTROL,
1901 AR9271_RADIO_RF_RST);
1905 if (!ath9k_hw_chip_reset(ah, chan)) {
1906 ath_err(common, "Chip reset failed\n");
1910 /* Only required on the first reset */
1911 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1912 ah->htc_reset_init = false;
1914 AR9271_RESET_POWER_DOWN_CONTROL,
1915 AR9271_GATE_MAC_CTL);
1920 usec = ktime_to_us(ktime_get_raw()) - usec;
1921 ath9k_hw_settsf64(ah, tsf + usec);
1923 if (AR_SREV_9280_20_OR_LATER(ah))
1924 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
1926 if (!AR_SREV_9300_20_OR_LATER(ah))
1927 ar9002_hw_enable_async_fifo(ah);
1929 r = ath9k_hw_process_ini(ah, chan);
1933 ath9k_hw_set_rfmode(ah, chan);
1935 if (ath9k_hw_mci_is_enabled(ah))
1936 ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
1939 * Some AR91xx SoC devices frequently fail to accept TSF writes
1940 * right after the chip reset. When that happens, write a new
1941 * value after the initvals have been applied, with an offset
1942 * based on measured time difference
1944 if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
1946 ath9k_hw_settsf64(ah, tsf);
1949 ath9k_hw_init_mfp(ah);
1951 ath9k_hw_set_delta_slope(ah, chan);
1952 ath9k_hw_spur_mitigate_freq(ah, chan);
1953 ah->eep_ops->set_board_values(ah, chan);
1955 ath9k_hw_reset_opmode(ah, macStaId1, saveDefAntenna);
1957 r = ath9k_hw_rf_set_freq(ah, chan);
1961 ath9k_hw_set_clockrate(ah);
1963 ath9k_hw_init_queues(ah);
1964 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
1965 ath9k_hw_ani_cache_ini_regs(ah);
1966 ath9k_hw_init_qos(ah);
1968 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1969 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
1971 ath9k_hw_init_global_settings(ah);
1973 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1974 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1975 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1976 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1977 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1978 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1979 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1982 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
1984 ath9k_hw_set_dma(ah);
1986 if (!ath9k_hw_mci_is_enabled(ah))
1987 REG_WRITE(ah, AR_OBS, 8);
1989 ENABLE_REG_RMW_BUFFER(ah);
1990 if (ah->config.rx_intr_mitigation) {
1991 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, ah->config.rimt_last);
1992 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, ah->config.rimt_first);
1995 if (ah->config.tx_intr_mitigation) {
1996 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1997 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1999 REG_RMW_BUFFER_FLUSH(ah);
2001 ath9k_hw_init_bb(ah, chan);
2004 clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
2005 clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
2007 if (!ath9k_hw_init_cal(ah, chan))
2010 if (ath9k_hw_mci_is_enabled(ah) && ar9003_mci_end_reset(ah, chan, caldata))
2013 ENABLE_REGWRITE_BUFFER(ah);
2015 ath9k_hw_restore_chainmask(ah);
2016 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2018 REGWRITE_BUFFER_FLUSH(ah);
2020 ath9k_hw_gen_timer_start_tsf2(ah);
2022 ath9k_hw_init_desc(ah);
2024 if (ath9k_hw_btcoex_is_enabled(ah))
2025 ath9k_hw_btcoex_enable(ah);
2027 if (ath9k_hw_mci_is_enabled(ah))
2028 ar9003_mci_check_bt(ah);
2030 if (AR_SREV_9300_20_OR_LATER(ah)) {
2031 ath9k_hw_loadnf(ah, chan);
2032 ath9k_hw_start_nfcal(ah, true);
2035 if (AR_SREV_9300_20_OR_LATER(ah))
2036 ar9003_hw_bb_watchdog_config(ah);
2038 if (ah->config.hw_hang_checks & HW_PHYRESTART_CLC_WAR)
2039 ar9003_hw_disable_phy_restart(ah);
2041 ath9k_hw_apply_gpio_override(ah);
2043 if (AR_SREV_9565(ah) && common->bt_ant_diversity)
2044 REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON);
2046 if (ah->hw->conf.radar_enabled) {
2047 /* set HW specific DFS configuration */
2048 ah->radar_conf.ext_channel = IS_CHAN_HT40(chan);
2049 ath9k_hw_set_radar_params(ah);
2054 EXPORT_SYMBOL(ath9k_hw_reset);
2056 /******************************/
2057 /* Power Management (Chipset) */
2058 /******************************/
2061 * Notify Power Mgt is disabled in self-generated frames.
2062 * If requested, force chip to sleep.
2064 static void ath9k_set_power_sleep(struct ath_hw *ah)
2066 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2068 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
2069 REG_CLR_BIT(ah, AR_TIMER_MODE, 0xff);
2070 REG_CLR_BIT(ah, AR_NDP2_TIMER_MODE, 0xff);
2071 REG_CLR_BIT(ah, AR_SLP32_INC, 0xfffff);
2072 /* xxx Required for WLAN only case ? */
2073 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
2078 * Clear the RTC force wake bit to allow the
2079 * mac to go to sleep.
2081 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
2083 if (ath9k_hw_mci_is_enabled(ah))
2086 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
2087 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2089 /* Shutdown chip. Active low */
2090 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
2091 REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
2095 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
2096 if (AR_SREV_9300_20_OR_LATER(ah))
2097 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
2101 * Notify Power Management is enabled in self-generating
2102 * frames. If request, set power mode of chip to
2103 * auto/normal. Duration in units of 128us (1/8 TU).
2105 static void ath9k_set_power_network_sleep(struct ath_hw *ah)
2107 struct ath9k_hw_capabilities *pCap = &ah->caps;
2109 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2111 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2112 /* Set WakeOnInterrupt bit; clear ForceWake bit */
2113 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2114 AR_RTC_FORCE_WAKE_ON_INT);
2117 /* When chip goes into network sleep, it could be waken
2118 * up by MCI_INT interrupt caused by BT's HW messages
2119 * (LNA_xxx, CONT_xxx) which chould be in a very fast
2120 * rate (~100us). This will cause chip to leave and
2121 * re-enter network sleep mode frequently, which in
2122 * consequence will have WLAN MCI HW to generate lots of
2123 * SYS_WAKING and SYS_SLEEPING messages which will make
2124 * BT CPU to busy to process.
2126 if (ath9k_hw_mci_is_enabled(ah))
2127 REG_CLR_BIT(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
2128 AR_MCI_INTERRUPT_RX_HW_MSG_MASK);
2130 * Clear the RTC force wake bit to allow the
2131 * mac to go to sleep.
2133 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
2135 if (ath9k_hw_mci_is_enabled(ah))
2139 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
2140 if (AR_SREV_9300_20_OR_LATER(ah))
2141 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
2144 static bool ath9k_hw_set_power_awake(struct ath_hw *ah)
2149 /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
2150 if (AR_SREV_9300_20_OR_LATER(ah)) {
2151 REG_WRITE(ah, AR_WA, ah->WARegVal);
2155 if ((REG_READ(ah, AR_RTC_STATUS) &
2156 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2157 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
2160 if (!AR_SREV_9300_20_OR_LATER(ah))
2161 ath9k_hw_init_pll(ah, NULL);
2163 if (AR_SREV_9100(ah))
2164 REG_SET_BIT(ah, AR_RTC_RESET,
2167 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2168 AR_RTC_FORCE_WAKE_EN);
2169 if (AR_SREV_9100(ah))
2174 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2175 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2176 if (val == AR_RTC_STATUS_ON)
2179 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2180 AR_RTC_FORCE_WAKE_EN);
2183 ath_err(ath9k_hw_common(ah),
2184 "Failed to wakeup in %uus\n",
2185 POWER_UP_TIME / 20);
2189 if (ath9k_hw_mci_is_enabled(ah))
2190 ar9003_mci_set_power_awake(ah);
2192 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2197 bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
2199 struct ath_common *common = ath9k_hw_common(ah);
2201 static const char *modes[] = {
2208 if (ah->power_mode == mode)
2211 ath_dbg(common, RESET, "%s -> %s\n",
2212 modes[ah->power_mode], modes[mode]);
2215 case ATH9K_PM_AWAKE:
2216 status = ath9k_hw_set_power_awake(ah);
2218 case ATH9K_PM_FULL_SLEEP:
2219 if (ath9k_hw_mci_is_enabled(ah))
2220 ar9003_mci_set_full_sleep(ah);
2222 ath9k_set_power_sleep(ah);
2223 ah->chip_fullsleep = true;
2225 case ATH9K_PM_NETWORK_SLEEP:
2226 ath9k_set_power_network_sleep(ah);
2229 ath_err(common, "Unknown power mode %u\n", mode);
2232 ah->power_mode = mode;
2235 * XXX: If this warning never comes up after a while then
2236 * simply keep the ATH_DBG_WARN_ON_ONCE() but make
2237 * ath9k_hw_setpower() return type void.
2240 if (!(ah->ah_flags & AH_UNPLUGGED))
2241 ATH_DBG_WARN_ON_ONCE(!status);
2245 EXPORT_SYMBOL(ath9k_hw_setpower);
2247 /*******************/
2248 /* Beacon Handling */
2249 /*******************/
2251 void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
2255 ENABLE_REGWRITE_BUFFER(ah);
2257 switch (ah->opmode) {
2258 case NL80211_IFTYPE_ADHOC:
2259 REG_SET_BIT(ah, AR_TXCFG,
2260 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2261 case NL80211_IFTYPE_MESH_POINT:
2262 case NL80211_IFTYPE_AP:
2263 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
2264 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
2265 TU_TO_USEC(ah->config.dma_beacon_response_time));
2266 REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
2267 TU_TO_USEC(ah->config.sw_beacon_response_time));
2269 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2272 ath_dbg(ath9k_hw_common(ah), BEACON,
2273 "%s: unsupported opmode: %d\n", __func__, ah->opmode);
2278 REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
2279 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
2280 REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
2282 REGWRITE_BUFFER_FLUSH(ah);
2284 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2286 EXPORT_SYMBOL(ath9k_hw_beaconinit);
2288 void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
2289 const struct ath9k_beacon_state *bs)
2291 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
2292 struct ath9k_hw_capabilities *pCap = &ah->caps;
2293 struct ath_common *common = ath9k_hw_common(ah);
2295 ENABLE_REGWRITE_BUFFER(ah);
2297 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, bs->bs_nexttbtt);
2298 REG_WRITE(ah, AR_BEACON_PERIOD, bs->bs_intval);
2299 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, bs->bs_intval);
2301 REGWRITE_BUFFER_FLUSH(ah);
2303 REG_RMW_FIELD(ah, AR_RSSI_THR,
2304 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2306 beaconintval = bs->bs_intval;
2308 if (bs->bs_sleepduration > beaconintval)
2309 beaconintval = bs->bs_sleepduration;
2311 dtimperiod = bs->bs_dtimperiod;
2312 if (bs->bs_sleepduration > dtimperiod)
2313 dtimperiod = bs->bs_sleepduration;
2315 if (beaconintval == dtimperiod)
2316 nextTbtt = bs->bs_nextdtim;
2318 nextTbtt = bs->bs_nexttbtt;
2320 ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2321 ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt);
2322 ath_dbg(common, BEACON, "beacon period %d\n", beaconintval);
2323 ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod);
2325 ENABLE_REGWRITE_BUFFER(ah);
2327 REG_WRITE(ah, AR_NEXT_DTIM, bs->bs_nextdtim - SLEEP_SLOP);
2328 REG_WRITE(ah, AR_NEXT_TIM, nextTbtt - SLEEP_SLOP);
2330 REG_WRITE(ah, AR_SLEEP1,
2331 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2332 | AR_SLEEP1_ASSUME_DTIM);
2334 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
2335 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2337 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2339 REG_WRITE(ah, AR_SLEEP2,
2340 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2342 REG_WRITE(ah, AR_TIM_PERIOD, beaconintval);
2343 REG_WRITE(ah, AR_DTIM_PERIOD, dtimperiod);
2345 REGWRITE_BUFFER_FLUSH(ah);
2347 REG_SET_BIT(ah, AR_TIMER_MODE,
2348 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2351 /* TSF Out of Range Threshold */
2352 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
2354 EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
2356 /*******************/
2357 /* HW Capabilities */
2358 /*******************/
2360 static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
2362 eeprom_chainmask &= chip_chainmask;
2363 if (eeprom_chainmask)
2364 return eeprom_chainmask;
2366 return chip_chainmask;
2370 * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset
2371 * @ah: the atheros hardware data structure
2373 * We enable DFS support upstream on chipsets which have passed a series
2374 * of tests. The testing requirements are going to be documented. Desired
2375 * test requirements are documented at:
2377 * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs
2379 * Once a new chipset gets properly tested an individual commit can be used
2380 * to document the testing for DFS for that chipset.
2382 static bool ath9k_hw_dfs_tested(struct ath_hw *ah)
2385 switch (ah->hw_version.macVersion) {
2386 /* for temporary testing DFS with 9280 */
2387 case AR_SREV_VERSION_9280:
2388 /* AR9580 will likely be our first target to get testing on */
2389 case AR_SREV_VERSION_9580:
2396 int ath9k_hw_fill_cap_info(struct ath_hw *ah)
2398 struct ath9k_hw_capabilities *pCap = &ah->caps;
2399 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
2400 struct ath_common *common = ath9k_hw_common(ah);
2403 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
2405 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
2406 regulatory->current_rd = eeval;
2408 if (ah->opmode != NL80211_IFTYPE_AP &&
2409 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
2410 if (regulatory->current_rd == 0x64 ||
2411 regulatory->current_rd == 0x65)
2412 regulatory->current_rd += 5;
2413 else if (regulatory->current_rd == 0x41)
2414 regulatory->current_rd = 0x43;
2415 ath_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n",
2416 regulatory->current_rd);
2419 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
2421 if (eeval & AR5416_OPFLAGS_11A) {
2422 if (ah->disable_5ghz)
2423 ath_warn(common, "disabling 5GHz band\n");
2425 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
2428 if (eeval & AR5416_OPFLAGS_11G) {
2429 if (ah->disable_2ghz)
2430 ath_warn(common, "disabling 2GHz band\n");
2432 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
2435 if ((pCap->hw_caps & (ATH9K_HW_CAP_2GHZ | ATH9K_HW_CAP_5GHZ)) == 0) {
2436 ath_err(common, "both bands are disabled\n");
2440 if (AR_SREV_9485(ah) ||
2444 pCap->chip_chainmask = 1;
2445 else if (!AR_SREV_9280_20_OR_LATER(ah))
2446 pCap->chip_chainmask = 7;
2447 else if (!AR_SREV_9300_20_OR_LATER(ah) ||
2451 pCap->chip_chainmask = 3;
2453 pCap->chip_chainmask = 7;
2455 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
2457 * For AR9271 we will temporarilly uses the rx chainmax as read from
2460 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
2461 !(eeval & AR5416_OPFLAGS_11A) &&
2462 !(AR_SREV_9271(ah)))
2463 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
2464 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2465 else if (AR_SREV_9100(ah))
2466 pCap->rx_chainmask = 0x7;
2468 /* Use rx_chainmask from EEPROM. */
2469 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
2471 pCap->tx_chainmask = fixup_chainmask(pCap->chip_chainmask, pCap->tx_chainmask);
2472 pCap->rx_chainmask = fixup_chainmask(pCap->chip_chainmask, pCap->rx_chainmask);
2473 ah->txchainmask = pCap->tx_chainmask;
2474 ah->rxchainmask = pCap->rx_chainmask;
2476 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
2478 /* enable key search for every frame in an aggregate */
2479 if (AR_SREV_9300_20_OR_LATER(ah))
2480 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
2482 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
2484 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
2485 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2487 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2489 if (AR_SREV_9271(ah))
2490 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2491 else if (AR_DEVID_7010(ah))
2492 pCap->num_gpio_pins = AR7010_NUM_GPIO;
2493 else if (AR_SREV_9300_20_OR_LATER(ah))
2494 pCap->num_gpio_pins = AR9300_NUM_GPIO;
2495 else if (AR_SREV_9287_11_OR_LATER(ah))
2496 pCap->num_gpio_pins = AR9287_NUM_GPIO;
2497 else if (AR_SREV_9285_12_OR_LATER(ah))
2498 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2499 else if (AR_SREV_9280_20_OR_LATER(ah))
2500 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2502 pCap->num_gpio_pins = AR_NUM_GPIO;
2504 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah))
2505 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2507 pCap->rts_aggr_limit = (8 * 1024);
2509 #ifdef CONFIG_ATH9K_RFKILL
2510 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2511 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2513 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2514 ah->rfkill_polarity =
2515 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
2517 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2520 if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
2521 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2523 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
2525 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
2526 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2528 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2530 if (AR_SREV_9300_20_OR_LATER(ah)) {
2531 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
2532 if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah) &&
2533 !AR_SREV_9561(ah) && !AR_SREV_9565(ah))
2534 pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
2536 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2537 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2538 pCap->rx_status_len = sizeof(struct ar9003_rxs);
2539 pCap->tx_desc_len = sizeof(struct ar9003_txc);
2540 pCap->txs_len = sizeof(struct ar9003_txs);
2542 pCap->tx_desc_len = sizeof(struct ath_desc);
2543 if (AR_SREV_9280_20(ah))
2544 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
2547 if (AR_SREV_9300_20_OR_LATER(ah))
2548 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2550 if (AR_SREV_9561(ah))
2551 ah->ent_mode = 0x3BDA000;
2552 else if (AR_SREV_9300_20_OR_LATER(ah))
2553 ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
2555 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
2556 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
2558 if (AR_SREV_9285(ah)) {
2559 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
2561 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2562 if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1)) {
2563 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2564 ath_info(common, "Enable LNA combining\n");
2569 if (AR_SREV_9300_20_OR_LATER(ah)) {
2570 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
2571 pCap->hw_caps |= ATH9K_HW_CAP_APM;
2574 if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
2575 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2576 if ((ant_div_ctl1 >> 0x6) == 0x3) {
2577 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2578 ath_info(common, "Enable LNA combining\n");
2582 if (ath9k_hw_dfs_tested(ah))
2583 pCap->hw_caps |= ATH9K_HW_CAP_DFS;
2585 tx_chainmask = pCap->tx_chainmask;
2586 rx_chainmask = pCap->rx_chainmask;
2587 while (tx_chainmask || rx_chainmask) {
2588 if (tx_chainmask & BIT(0))
2589 pCap->max_txchains++;
2590 if (rx_chainmask & BIT(0))
2591 pCap->max_rxchains++;
2597 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
2598 if (!(ah->ent_mode & AR_ENT_OTP_49GHZ_DISABLE))
2599 pCap->hw_caps |= ATH9K_HW_CAP_MCI;
2601 if (AR_SREV_9462_20_OR_LATER(ah))
2602 pCap->hw_caps |= ATH9K_HW_CAP_RTT;
2605 if (AR_SREV_9300_20_OR_LATER(ah) &&
2606 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
2607 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
2609 #ifdef CONFIG_ATH9K_WOW
2610 if (AR_SREV_9462_20_OR_LATER(ah) || AR_SREV_9565_11_OR_LATER(ah))
2611 ah->wow.max_patterns = MAX_NUM_PATTERN;
2613 ah->wow.max_patterns = MAX_NUM_PATTERN_LEGACY;
2619 /****************************/
2620 /* GPIO / RFKILL / Antennae */
2621 /****************************/
2623 static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
2627 u32 gpio_shift, tmp;
2630 addr = AR_GPIO_OUTPUT_MUX3;
2632 addr = AR_GPIO_OUTPUT_MUX2;
2634 addr = AR_GPIO_OUTPUT_MUX1;
2636 gpio_shift = (gpio % 6) * 5;
2638 if (AR_SREV_9280_20_OR_LATER(ah)
2639 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2640 REG_RMW(ah, addr, (type << gpio_shift),
2641 (0x1f << gpio_shift));
2643 tmp = REG_READ(ah, addr);
2644 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2645 tmp &= ~(0x1f << gpio_shift);
2646 tmp |= (type << gpio_shift);
2647 REG_WRITE(ah, addr, tmp);
2651 void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
2655 BUG_ON(gpio >= ah->caps.num_gpio_pins);
2657 if (AR_DEVID_7010(ah)) {
2659 REG_RMW(ah, AR7010_GPIO_OE,
2660 (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
2661 (AR7010_GPIO_OE_MASK << gpio_shift));
2665 gpio_shift = gpio << 1;
2668 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2669 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2671 EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
2673 u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
2675 #define MS_REG_READ(x, y) \
2676 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2678 if (gpio >= ah->caps.num_gpio_pins)
2681 if (AR_DEVID_7010(ah)) {
2683 val = REG_READ(ah, AR7010_GPIO_IN);
2684 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
2685 } else if (AR_SREV_9300_20_OR_LATER(ah))
2686 return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
2687 AR_GPIO_BIT(gpio)) != 0;
2688 else if (AR_SREV_9271(ah))
2689 return MS_REG_READ(AR9271, gpio) != 0;
2690 else if (AR_SREV_9287_11_OR_LATER(ah))
2691 return MS_REG_READ(AR9287, gpio) != 0;
2692 else if (AR_SREV_9285_12_OR_LATER(ah))
2693 return MS_REG_READ(AR9285, gpio) != 0;
2694 else if (AR_SREV_9280_20_OR_LATER(ah))
2695 return MS_REG_READ(AR928X, gpio) != 0;
2697 return MS_REG_READ(AR, gpio) != 0;
2699 EXPORT_SYMBOL(ath9k_hw_gpio_get);
2701 void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
2706 if (AR_DEVID_7010(ah)) {
2708 REG_RMW(ah, AR7010_GPIO_OE,
2709 (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
2710 (AR7010_GPIO_OE_MASK << gpio_shift));
2714 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
2715 gpio_shift = 2 * gpio;
2718 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2719 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2721 EXPORT_SYMBOL(ath9k_hw_cfg_output);
2723 void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
2725 if (AR_DEVID_7010(ah)) {
2727 REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
2732 if (AR_SREV_9271(ah))
2735 if ((1 << gpio) & AR_GPIO_OE_OUT_MASK)
2736 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2739 gpio_set_value(gpio, val & 1);
2741 EXPORT_SYMBOL(ath9k_hw_set_gpio);
2743 void ath9k_hw_request_gpio(struct ath_hw *ah, u32 gpio, const char *label)
2745 if (gpio >= ah->caps.num_gpio_pins)
2748 gpio_request_one(gpio, GPIOF_DIR_OUT | GPIOF_INIT_LOW, label);
2750 EXPORT_SYMBOL(ath9k_hw_request_gpio);
2752 void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
2754 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2756 EXPORT_SYMBOL(ath9k_hw_setantenna);
2758 /*********************/
2759 /* General Operation */
2760 /*********************/
2762 u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
2764 u32 bits = REG_READ(ah, AR_RX_FILTER);
2765 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2767 if (phybits & AR_PHY_ERR_RADAR)
2768 bits |= ATH9K_RX_FILTER_PHYRADAR;
2769 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2770 bits |= ATH9K_RX_FILTER_PHYERR;
2774 EXPORT_SYMBOL(ath9k_hw_getrxfilter);
2776 void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
2780 ENABLE_REGWRITE_BUFFER(ah);
2782 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
2783 bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
2785 REG_WRITE(ah, AR_RX_FILTER, bits);
2788 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2789 phybits |= AR_PHY_ERR_RADAR;
2790 if (bits & ATH9K_RX_FILTER_PHYERR)
2791 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2792 REG_WRITE(ah, AR_PHY_ERR, phybits);
2795 REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
2797 REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
2799 REGWRITE_BUFFER_FLUSH(ah);
2801 EXPORT_SYMBOL(ath9k_hw_setrxfilter);
2803 bool ath9k_hw_phy_disable(struct ath_hw *ah)
2805 if (ath9k_hw_mci_is_enabled(ah))
2806 ar9003_mci_bt_gain_ctrl(ah);
2808 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2811 ath9k_hw_init_pll(ah, NULL);
2812 ah->htc_reset_init = true;
2815 EXPORT_SYMBOL(ath9k_hw_phy_disable);
2817 bool ath9k_hw_disable(struct ath_hw *ah)
2819 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
2822 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2825 ath9k_hw_init_pll(ah, NULL);
2828 EXPORT_SYMBOL(ath9k_hw_disable);
2830 static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
2832 enum eeprom_param gain_param;
2834 if (IS_CHAN_2GHZ(chan))
2835 gain_param = EEP_ANTENNA_GAIN_2G;
2837 gain_param = EEP_ANTENNA_GAIN_5G;
2839 return ah->eep_ops->get_eeprom(ah, gain_param);
2842 void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
2845 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2846 struct ieee80211_channel *channel;
2847 int chan_pwr, new_pwr, max_gain;
2848 int ant_gain, ant_reduction = 0;
2853 channel = chan->chan;
2854 chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
2855 new_pwr = min_t(int, chan_pwr, reg->power_limit);
2856 max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
2858 ant_gain = get_antenna_gain(ah, chan);
2859 if (ant_gain > max_gain)
2860 ant_reduction = ant_gain - max_gain;
2862 ah->eep_ops->set_txpower(ah, chan,
2863 ath9k_regd_get_ctl(reg, chan),
2864 ant_reduction, new_pwr, test);
2867 void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
2869 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2870 struct ath9k_channel *chan = ah->curchan;
2871 struct ieee80211_channel *channel = chan->chan;
2873 reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
2875 channel->max_power = MAX_RATE_POWER / 2;
2877 ath9k_hw_apply_txpower(ah, chan, test);
2880 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
2882 EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
2884 void ath9k_hw_setopmode(struct ath_hw *ah)
2886 ath9k_hw_set_operating_mode(ah, ah->opmode);
2888 EXPORT_SYMBOL(ath9k_hw_setopmode);
2890 void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
2892 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2893 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2895 EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
2897 void ath9k_hw_write_associd(struct ath_hw *ah)
2899 struct ath_common *common = ath9k_hw_common(ah);
2901 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2902 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2903 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
2905 EXPORT_SYMBOL(ath9k_hw_write_associd);
2907 #define ATH9K_MAX_TSF_READ 10
2909 u64 ath9k_hw_gettsf64(struct ath_hw *ah)
2911 u32 tsf_lower, tsf_upper1, tsf_upper2;
2914 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2915 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2916 tsf_lower = REG_READ(ah, AR_TSF_L32);
2917 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2918 if (tsf_upper2 == tsf_upper1)
2920 tsf_upper1 = tsf_upper2;
2923 WARN_ON( i == ATH9K_MAX_TSF_READ );
2925 return (((u64)tsf_upper1 << 32) | tsf_lower);
2927 EXPORT_SYMBOL(ath9k_hw_gettsf64);
2929 void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
2931 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
2932 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
2934 EXPORT_SYMBOL(ath9k_hw_settsf64);
2936 void ath9k_hw_reset_tsf(struct ath_hw *ah)
2938 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2939 AH_TSF_WRITE_TIMEOUT))
2940 ath_dbg(ath9k_hw_common(ah), RESET,
2941 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
2943 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
2945 EXPORT_SYMBOL(ath9k_hw_reset_tsf);
2947 void ath9k_hw_set_tsfadjust(struct ath_hw *ah, bool set)
2950 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
2952 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
2954 EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
2956 void ath9k_hw_set11nmac2040(struct ath_hw *ah, struct ath9k_channel *chan)
2960 if (IS_CHAN_HT40(chan) && !ah->config.cwm_ignore_extcca)
2961 macmode = AR_2040_JOINED_RX_CLEAR;
2965 REG_WRITE(ah, AR_2040_MODE, macmode);
2968 /* HW Generic timers configuration */
2970 static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2972 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2973 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2974 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2975 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2976 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2977 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2978 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2979 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2980 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2981 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2982 AR_NDP2_TIMER_MODE, 0x0002},
2983 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2984 AR_NDP2_TIMER_MODE, 0x0004},
2985 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2986 AR_NDP2_TIMER_MODE, 0x0008},
2987 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2988 AR_NDP2_TIMER_MODE, 0x0010},
2989 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2990 AR_NDP2_TIMER_MODE, 0x0020},
2991 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2992 AR_NDP2_TIMER_MODE, 0x0040},
2993 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2994 AR_NDP2_TIMER_MODE, 0x0080}
2997 /* HW generic timer primitives */
2999 u32 ath9k_hw_gettsf32(struct ath_hw *ah)
3001 return REG_READ(ah, AR_TSF_L32);
3003 EXPORT_SYMBOL(ath9k_hw_gettsf32);
3005 void ath9k_hw_gen_timer_start_tsf2(struct ath_hw *ah)
3007 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3009 if (timer_table->tsf2_enabled) {
3010 REG_SET_BIT(ah, AR_DIRECT_CONNECT, AR_DC_AP_STA_EN);
3011 REG_SET_BIT(ah, AR_RESET_TSF, AR_RESET_TSF2_ONCE);
3015 struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
3016 void (*trigger)(void *),
3017 void (*overflow)(void *),
3021 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3022 struct ath_gen_timer *timer;
3024 if ((timer_index < AR_FIRST_NDP_TIMER) ||
3025 (timer_index >= ATH_MAX_GEN_TIMER))
3028 if ((timer_index > AR_FIRST_NDP_TIMER) &&
3029 !AR_SREV_9300_20_OR_LATER(ah))
3032 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
3036 /* allocate a hardware generic timer slot */
3037 timer_table->timers[timer_index] = timer;
3038 timer->index = timer_index;
3039 timer->trigger = trigger;
3040 timer->overflow = overflow;
3043 if ((timer_index > AR_FIRST_NDP_TIMER) && !timer_table->tsf2_enabled) {
3044 timer_table->tsf2_enabled = true;
3045 ath9k_hw_gen_timer_start_tsf2(ah);
3050 EXPORT_SYMBOL(ath_gen_timer_alloc);
3052 void ath9k_hw_gen_timer_start(struct ath_hw *ah,
3053 struct ath_gen_timer *timer,
3057 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3060 timer_table->timer_mask |= BIT(timer->index);
3063 * Program generic timer registers
3065 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
3067 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
3069 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3070 gen_tmr_configuration[timer->index].mode_mask);
3072 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
3074 * Starting from AR9462, each generic timer can select which tsf
3075 * to use. But we still follow the old rule, 0 - 7 use tsf and
3078 if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
3079 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
3080 (1 << timer->index));
3082 REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
3083 (1 << timer->index));
3087 mask |= SM(AR_GENTMR_BIT(timer->index),
3088 AR_IMR_S5_GENTIMER_TRIG);
3089 if (timer->overflow)
3090 mask |= SM(AR_GENTMR_BIT(timer->index),
3091 AR_IMR_S5_GENTIMER_THRESH);
3093 REG_SET_BIT(ah, AR_IMR_S5, mask);
3095 if ((ah->imask & ATH9K_INT_GENTIMER) == 0) {
3096 ah->imask |= ATH9K_INT_GENTIMER;
3097 ath9k_hw_set_interrupts(ah);
3100 EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
3102 void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
3104 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3106 /* Clear generic timer enable bits. */
3107 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
3108 gen_tmr_configuration[timer->index].mode_mask);
3110 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
3112 * Need to switch back to TSF if it was using TSF2.
3114 if ((timer->index >= AR_GEN_TIMER_BANK_1_LEN)) {
3115 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
3116 (1 << timer->index));
3120 /* Disable both trigger and thresh interrupt masks */
3121 REG_CLR_BIT(ah, AR_IMR_S5,
3122 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
3123 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
3125 timer_table->timer_mask &= ~BIT(timer->index);
3127 if (timer_table->timer_mask == 0) {
3128 ah->imask &= ~ATH9K_INT_GENTIMER;
3129 ath9k_hw_set_interrupts(ah);
3132 EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
3134 void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3136 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3138 /* free the hardware generic timer slot */
3139 timer_table->timers[timer->index] = NULL;
3142 EXPORT_SYMBOL(ath_gen_timer_free);
3145 * Generic Timer Interrupts handling
3147 void ath_gen_timer_isr(struct ath_hw *ah)
3149 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3150 struct ath_gen_timer *timer;
3151 unsigned long trigger_mask, thresh_mask;
3154 /* get hardware generic timer interrupt status */
3155 trigger_mask = ah->intr_gen_timer_trigger;
3156 thresh_mask = ah->intr_gen_timer_thresh;
3157 trigger_mask &= timer_table->timer_mask;
3158 thresh_mask &= timer_table->timer_mask;
3160 for_each_set_bit(index, &thresh_mask, ARRAY_SIZE(timer_table->timers)) {
3161 timer = timer_table->timers[index];
3164 if (!timer->overflow)
3167 trigger_mask &= ~BIT(index);
3168 timer->overflow(timer->arg);
3171 for_each_set_bit(index, &trigger_mask, ARRAY_SIZE(timer_table->timers)) {
3172 timer = timer_table->timers[index];
3175 if (!timer->trigger)
3177 timer->trigger(timer->arg);
3180 EXPORT_SYMBOL(ath_gen_timer_isr);
3189 } ath_mac_bb_names[] = {
3190 /* Devices with external radios */
3191 { AR_SREV_VERSION_5416_PCI, "5416" },
3192 { AR_SREV_VERSION_5416_PCIE, "5418" },
3193 { AR_SREV_VERSION_9100, "9100" },
3194 { AR_SREV_VERSION_9160, "9160" },
3195 /* Single-chip solutions */
3196 { AR_SREV_VERSION_9280, "9280" },
3197 { AR_SREV_VERSION_9285, "9285" },
3198 { AR_SREV_VERSION_9287, "9287" },
3199 { AR_SREV_VERSION_9271, "9271" },
3200 { AR_SREV_VERSION_9300, "9300" },
3201 { AR_SREV_VERSION_9330, "9330" },
3202 { AR_SREV_VERSION_9340, "9340" },
3203 { AR_SREV_VERSION_9485, "9485" },
3204 { AR_SREV_VERSION_9462, "9462" },
3205 { AR_SREV_VERSION_9550, "9550" },
3206 { AR_SREV_VERSION_9565, "9565" },
3207 { AR_SREV_VERSION_9531, "9531" },
3208 { AR_SREV_VERSION_9561, "9561" },
3211 /* For devices with external radios */
3215 } ath_rf_names[] = {
3217 { AR_RAD5133_SREV_MAJOR, "5133" },
3218 { AR_RAD5122_SREV_MAJOR, "5122" },
3219 { AR_RAD2133_SREV_MAJOR, "2133" },
3220 { AR_RAD2122_SREV_MAJOR, "2122" }
3224 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3226 static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
3230 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3231 if (ath_mac_bb_names[i].version == mac_bb_version) {
3232 return ath_mac_bb_names[i].name;
3240 * Return the RF name. "????" is returned if the RF is unknown.
3241 * Used for devices with external radios.
3243 static const char *ath9k_hw_rf_name(u16 rf_version)
3247 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3248 if (ath_rf_names[i].version == rf_version) {
3249 return ath_rf_names[i].name;
3256 void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3260 /* chipsets >= AR9280 are single-chip */
3261 if (AR_SREV_9280_20_OR_LATER(ah)) {
3262 used = scnprintf(hw_name, len,
3263 "Atheros AR%s Rev:%x",
3264 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3265 ah->hw_version.macRev);
3268 used = scnprintf(hw_name, len,
3269 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3270 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3271 ah->hw_version.macRev,
3272 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev
3273 & AR_RADIO_SREV_MAJOR)),
3274 ah->hw_version.phyRev);
3277 hw_name[used] = '\0';
3279 EXPORT_SYMBOL(ath9k_hw_name);