Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Sujith Manoharan | 5b68138 | 2011-05-17 13:36:18 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2011 Atheros Communications Inc. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3 | * |
| 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Paul Gortmaker | 9d9779e | 2011-07-03 15:21:01 -0400 | [diff] [blame] | 19 | #include <linux/module.h> |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 20 | #include <asm/unaligned.h> |
| 21 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 22 | #include "hw.h" |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 23 | #include "hw-ops.h" |
Luis R. Rodriguez | cfe8cba | 2009-09-13 23:39:31 -0700 | [diff] [blame] | 24 | #include "rc.h" |
Luis R. Rodriguez | b622a72 | 2010-04-15 17:39:28 -0400 | [diff] [blame] | 25 | #include "ar9003_mac.h" |
Sujith Manoharan | f4701b5 | 2012-02-22 12:41:18 +0530 | [diff] [blame] | 26 | #include "ar9003_mci.h" |
Sujith Manoharan | 362cd03 | 2012-09-16 08:06:36 +0530 | [diff] [blame] | 27 | #include "ar9003_phy.h" |
Ben Greear | 462e58f | 2012-04-12 10:04:00 -0700 | [diff] [blame] | 28 | #include "debug.h" |
| 29 | #include "ath9k.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 30 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 31 | static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 32 | |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 33 | MODULE_AUTHOR("Atheros Communications"); |
| 34 | MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards."); |
| 35 | MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards"); |
| 36 | MODULE_LICENSE("Dual BSD/GPL"); |
| 37 | |
| 38 | static int __init ath9k_init(void) |
| 39 | { |
| 40 | return 0; |
| 41 | } |
| 42 | module_init(ath9k_init); |
| 43 | |
| 44 | static void __exit ath9k_exit(void) |
| 45 | { |
| 46 | return; |
| 47 | } |
| 48 | module_exit(ath9k_exit); |
| 49 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 50 | /* Private hardware callbacks */ |
| 51 | |
| 52 | static void ath9k_hw_init_cal_settings(struct ath_hw *ah) |
| 53 | { |
| 54 | ath9k_hw_private_ops(ah)->init_cal_settings(ah); |
| 55 | } |
| 56 | |
| 57 | static void ath9k_hw_init_mode_regs(struct ath_hw *ah) |
| 58 | { |
| 59 | ath9k_hw_private_ops(ah)->init_mode_regs(ah); |
| 60 | } |
| 61 | |
Luis R. Rodriguez | 6477396 | 2010-04-15 17:38:17 -0400 | [diff] [blame] | 62 | static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah, |
| 63 | struct ath9k_channel *chan) |
| 64 | { |
| 65 | return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan); |
| 66 | } |
| 67 | |
Luis R. Rodriguez | 991312d | 2010-04-15 17:39:05 -0400 | [diff] [blame] | 68 | static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah) |
| 69 | { |
| 70 | if (!ath9k_hw_private_ops(ah)->init_mode_gain_regs) |
| 71 | return; |
| 72 | |
| 73 | ath9k_hw_private_ops(ah)->init_mode_gain_regs(ah); |
| 74 | } |
| 75 | |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 76 | static void ath9k_hw_ani_cache_ini_regs(struct ath_hw *ah) |
| 77 | { |
| 78 | /* You will not have this callback if using the old ANI */ |
| 79 | if (!ath9k_hw_private_ops(ah)->ani_cache_ini_regs) |
| 80 | return; |
| 81 | |
| 82 | ath9k_hw_private_ops(ah)->ani_cache_ini_regs(ah); |
| 83 | } |
| 84 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 85 | /********************/ |
| 86 | /* Helper Functions */ |
| 87 | /********************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 88 | |
Ben Greear | 462e58f | 2012-04-12 10:04:00 -0700 | [diff] [blame] | 89 | #ifdef CONFIG_ATH9K_DEBUGFS |
| 90 | |
| 91 | void ath9k_debug_sync_cause(struct ath_common *common, u32 sync_cause) |
| 92 | { |
| 93 | struct ath_softc *sc = common->priv; |
| 94 | if (sync_cause) |
| 95 | sc->debug.stats.istats.sync_cause_all++; |
| 96 | if (sync_cause & AR_INTR_SYNC_RTC_IRQ) |
| 97 | sc->debug.stats.istats.sync_rtc_irq++; |
| 98 | if (sync_cause & AR_INTR_SYNC_MAC_IRQ) |
| 99 | sc->debug.stats.istats.sync_mac_irq++; |
| 100 | if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS) |
| 101 | sc->debug.stats.istats.eeprom_illegal_access++; |
| 102 | if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT) |
| 103 | sc->debug.stats.istats.apb_timeout++; |
| 104 | if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT) |
| 105 | sc->debug.stats.istats.pci_mode_conflict++; |
| 106 | if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) |
| 107 | sc->debug.stats.istats.host1_fatal++; |
| 108 | if (sync_cause & AR_INTR_SYNC_HOST1_PERR) |
| 109 | sc->debug.stats.istats.host1_perr++; |
| 110 | if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR) |
| 111 | sc->debug.stats.istats.trcv_fifo_perr++; |
| 112 | if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP) |
| 113 | sc->debug.stats.istats.radm_cpl_ep++; |
| 114 | if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT) |
| 115 | sc->debug.stats.istats.radm_cpl_dllp_abort++; |
| 116 | if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT) |
| 117 | sc->debug.stats.istats.radm_cpl_tlp_abort++; |
| 118 | if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR) |
| 119 | sc->debug.stats.istats.radm_cpl_ecrc_err++; |
| 120 | if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) |
| 121 | sc->debug.stats.istats.radm_cpl_timeout++; |
| 122 | if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) |
| 123 | sc->debug.stats.istats.local_timeout++; |
| 124 | if (sync_cause & AR_INTR_SYNC_PM_ACCESS) |
| 125 | sc->debug.stats.istats.pm_access++; |
| 126 | if (sync_cause & AR_INTR_SYNC_MAC_AWAKE) |
| 127 | sc->debug.stats.istats.mac_awake++; |
| 128 | if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP) |
| 129 | sc->debug.stats.istats.mac_asleep++; |
| 130 | if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS) |
| 131 | sc->debug.stats.istats.mac_sleep_access++; |
| 132 | } |
| 133 | #endif |
| 134 | |
| 135 | |
Felix Fietkau | dfdac8a | 2010-10-08 22:13:51 +0200 | [diff] [blame] | 136 | static void ath9k_hw_set_clockrate(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 137 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 138 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Felix Fietkau | dfdac8a | 2010-10-08 22:13:51 +0200 | [diff] [blame] | 139 | struct ath_common *common = ath9k_hw_common(ah); |
| 140 | unsigned int clockrate; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 141 | |
Felix Fietkau | 087b6ff | 2011-07-09 11:12:49 +0700 | [diff] [blame] | 142 | /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */ |
| 143 | if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) |
| 144 | clockrate = 117; |
| 145 | else if (!ah->curchan) /* should really check for CCK instead */ |
Felix Fietkau | dfdac8a | 2010-10-08 22:13:51 +0200 | [diff] [blame] | 146 | clockrate = ATH9K_CLOCK_RATE_CCK; |
| 147 | else if (conf->channel->band == IEEE80211_BAND_2GHZ) |
| 148 | clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM; |
| 149 | else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK) |
| 150 | clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM; |
Vasanthakumar Thiagarajan | e555372 | 2010-04-26 15:04:33 -0400 | [diff] [blame] | 151 | else |
Felix Fietkau | dfdac8a | 2010-10-08 22:13:51 +0200 | [diff] [blame] | 152 | clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM; |
| 153 | |
| 154 | if (conf_is_ht40(conf)) |
| 155 | clockrate *= 2; |
| 156 | |
Felix Fietkau | 906c720 | 2011-07-09 11:12:48 +0700 | [diff] [blame] | 157 | if (ah->curchan) { |
| 158 | if (IS_CHAN_HALF_RATE(ah->curchan)) |
| 159 | clockrate /= 2; |
| 160 | if (IS_CHAN_QUARTER_RATE(ah->curchan)) |
| 161 | clockrate /= 4; |
| 162 | } |
| 163 | |
Felix Fietkau | dfdac8a | 2010-10-08 22:13:51 +0200 | [diff] [blame] | 164 | common->clockrate = clockrate; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 165 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 166 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 167 | static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 168 | { |
Felix Fietkau | dfdac8a | 2010-10-08 22:13:51 +0200 | [diff] [blame] | 169 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 170 | |
Felix Fietkau | dfdac8a | 2010-10-08 22:13:51 +0200 | [diff] [blame] | 171 | return usecs * common->clockrate; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 172 | } |
| 173 | |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 174 | bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 175 | { |
| 176 | int i; |
| 177 | |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 178 | BUG_ON(timeout < AH_TIME_QUANTUM); |
| 179 | |
| 180 | for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 181 | if ((REG_READ(ah, reg) & mask) == val) |
| 182 | return true; |
| 183 | |
| 184 | udelay(AH_TIME_QUANTUM); |
| 185 | } |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 186 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 187 | ath_dbg(ath9k_hw_common(ah), ANY, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 188 | "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n", |
| 189 | timeout, reg, REG_READ(ah, reg), mask, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 190 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 191 | return false; |
| 192 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 193 | EXPORT_SYMBOL(ath9k_hw_wait); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 194 | |
Felix Fietkau | 7c5adc8 | 2012-04-19 21:18:26 +0200 | [diff] [blame] | 195 | void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan, |
| 196 | int hw_delay) |
| 197 | { |
| 198 | if (IS_CHAN_B(chan)) |
| 199 | hw_delay = (4 * hw_delay) / 22; |
| 200 | else |
| 201 | hw_delay /= 10; |
| 202 | |
| 203 | if (IS_CHAN_HALF_RATE(chan)) |
| 204 | hw_delay *= 2; |
| 205 | else if (IS_CHAN_QUARTER_RATE(chan)) |
| 206 | hw_delay *= 4; |
| 207 | |
| 208 | udelay(hw_delay + BASE_ACTIVATE_DELAY); |
| 209 | } |
| 210 | |
Felix Fietkau | a9b6b25 | 2011-03-23 20:57:27 +0100 | [diff] [blame] | 211 | void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array, |
| 212 | int column, unsigned int *writecnt) |
| 213 | { |
| 214 | int r; |
| 215 | |
| 216 | ENABLE_REGWRITE_BUFFER(ah); |
| 217 | for (r = 0; r < array->ia_rows; r++) { |
| 218 | REG_WRITE(ah, INI_RA(array, r, 0), |
| 219 | INI_RA(array, r, column)); |
| 220 | DO_DELAY(*writecnt); |
| 221 | } |
| 222 | REGWRITE_BUFFER_FLUSH(ah); |
| 223 | } |
| 224 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 225 | u32 ath9k_hw_reverse_bits(u32 val, u32 n) |
| 226 | { |
| 227 | u32 retval; |
| 228 | int i; |
| 229 | |
| 230 | for (i = 0, retval = 0; i < n; i++) { |
| 231 | retval = (retval << 1) | (val & 1); |
| 232 | val >>= 1; |
| 233 | } |
| 234 | return retval; |
| 235 | } |
| 236 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 237 | u16 ath9k_hw_computetxtime(struct ath_hw *ah, |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 238 | u8 phy, int kbps, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 239 | u32 frameLen, u16 rateix, |
| 240 | bool shortPreamble) |
| 241 | { |
| 242 | u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 243 | |
| 244 | if (kbps == 0) |
| 245 | return 0; |
| 246 | |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 247 | switch (phy) { |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 248 | case WLAN_RC_PHY_CCK: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 249 | phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS; |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 250 | if (shortPreamble) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 251 | phyTime >>= 1; |
| 252 | numBits = frameLen << 3; |
| 253 | txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps); |
| 254 | break; |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 255 | case WLAN_RC_PHY_OFDM: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 256 | if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 257 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000; |
| 258 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 259 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 260 | txTime = OFDM_SIFS_TIME_QUARTER |
| 261 | + OFDM_PREAMBLE_TIME_QUARTER |
| 262 | + (numSymbols * OFDM_SYMBOL_TIME_QUARTER); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 263 | } else if (ah->curchan && |
| 264 | IS_CHAN_HALF_RATE(ah->curchan)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 265 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000; |
| 266 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 267 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 268 | txTime = OFDM_SIFS_TIME_HALF + |
| 269 | OFDM_PREAMBLE_TIME_HALF |
| 270 | + (numSymbols * OFDM_SYMBOL_TIME_HALF); |
| 271 | } else { |
| 272 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000; |
| 273 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 274 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 275 | txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME |
| 276 | + (numSymbols * OFDM_SYMBOL_TIME); |
| 277 | } |
| 278 | break; |
| 279 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 280 | ath_err(ath9k_hw_common(ah), |
| 281 | "Unknown phy %u (rate ix %u)\n", phy, rateix); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 282 | txTime = 0; |
| 283 | break; |
| 284 | } |
| 285 | |
| 286 | return txTime; |
| 287 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 288 | EXPORT_SYMBOL(ath9k_hw_computetxtime); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 289 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 290 | void ath9k_hw_get_channel_centers(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 291 | struct ath9k_channel *chan, |
| 292 | struct chan_centers *centers) |
| 293 | { |
| 294 | int8_t extoff; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 295 | |
| 296 | if (!IS_CHAN_HT40(chan)) { |
| 297 | centers->ctl_center = centers->ext_center = |
| 298 | centers->synth_center = chan->channel; |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | if ((chan->chanmode == CHANNEL_A_HT40PLUS) || |
| 303 | (chan->chanmode == CHANNEL_G_HT40PLUS)) { |
| 304 | centers->synth_center = |
| 305 | chan->channel + HT40_CHANNEL_CENTER_SHIFT; |
| 306 | extoff = 1; |
| 307 | } else { |
| 308 | centers->synth_center = |
| 309 | chan->channel - HT40_CHANNEL_CENTER_SHIFT; |
| 310 | extoff = -1; |
| 311 | } |
| 312 | |
| 313 | centers->ctl_center = |
| 314 | centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT); |
Luis R. Rodriguez | 6420014 | 2009-09-13 22:05:04 -0700 | [diff] [blame] | 315 | /* 25 MHz spacing is supported by hw but not on upper layers */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 316 | centers->ext_center = |
Luis R. Rodriguez | 6420014 | 2009-09-13 22:05:04 -0700 | [diff] [blame] | 317 | centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /******************/ |
| 321 | /* Chip Revisions */ |
| 322 | /******************/ |
| 323 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 324 | static void ath9k_hw_read_revisions(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 325 | { |
| 326 | u32 val; |
| 327 | |
Vasanthakumar Thiagarajan | ecb1d38 | 2011-04-19 19:29:18 +0530 | [diff] [blame] | 328 | switch (ah->hw_version.devid) { |
| 329 | case AR5416_AR9100_DEVID: |
| 330 | ah->hw_version.macVersion = AR_SREV_VERSION_9100; |
| 331 | break; |
Gabor Juhos | 3762561 | 2011-06-21 11:23:23 +0200 | [diff] [blame] | 332 | case AR9300_DEVID_AR9330: |
| 333 | ah->hw_version.macVersion = AR_SREV_VERSION_9330; |
| 334 | if (ah->get_mac_revision) { |
| 335 | ah->hw_version.macRev = ah->get_mac_revision(); |
| 336 | } else { |
| 337 | val = REG_READ(ah, AR_SREV); |
| 338 | ah->hw_version.macRev = MS(val, AR_SREV_REVISION2); |
| 339 | } |
| 340 | return; |
Vasanthakumar Thiagarajan | ecb1d38 | 2011-04-19 19:29:18 +0530 | [diff] [blame] | 341 | case AR9300_DEVID_AR9340: |
| 342 | ah->hw_version.macVersion = AR_SREV_VERSION_9340; |
| 343 | val = REG_READ(ah, AR_SREV); |
| 344 | ah->hw_version.macRev = MS(val, AR_SREV_REVISION2); |
| 345 | return; |
Gabor Juhos | 813831d | 2012-07-03 19:13:17 +0200 | [diff] [blame] | 346 | case AR9300_DEVID_QCA955X: |
| 347 | ah->hw_version.macVersion = AR_SREV_VERSION_9550; |
| 348 | return; |
Vasanthakumar Thiagarajan | ecb1d38 | 2011-04-19 19:29:18 +0530 | [diff] [blame] | 349 | } |
| 350 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 351 | val = REG_READ(ah, AR_SREV) & AR_SREV_ID; |
| 352 | |
| 353 | if (val == 0xFF) { |
| 354 | val = REG_READ(ah, AR_SREV); |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 355 | ah->hw_version.macVersion = |
| 356 | (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S; |
| 357 | ah->hw_version.macRev = MS(val, AR_SREV_REVISION2); |
Mohammed Shafi Shajakhan | 76ed94b | 2011-09-30 11:31:28 +0530 | [diff] [blame] | 358 | |
Sujith Manoharan | 77fac46 | 2012-09-11 20:09:18 +0530 | [diff] [blame] | 359 | if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) |
Mohammed Shafi Shajakhan | 76ed94b | 2011-09-30 11:31:28 +0530 | [diff] [blame] | 360 | ah->is_pciexpress = true; |
| 361 | else |
| 362 | ah->is_pciexpress = (val & |
| 363 | AR_SREV_TYPE2_HOST_MODE) ? 0 : 1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 364 | } else { |
| 365 | if (!AR_SREV_9100(ah)) |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 366 | ah->hw_version.macVersion = MS(val, AR_SREV_VERSION); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 367 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 368 | ah->hw_version.macRev = val & AR_SREV_REVISION; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 369 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 370 | if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 371 | ah->is_pciexpress = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 375 | /************************************/ |
| 376 | /* HW Attach, Detach, Init Routines */ |
| 377 | /************************************/ |
| 378 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 379 | static void ath9k_hw_disablepcie(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 380 | { |
Felix Fietkau | 040b74f | 2010-12-12 00:51:07 +0100 | [diff] [blame] | 381 | if (!AR_SREV_5416(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 382 | return; |
| 383 | |
| 384 | REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00); |
| 385 | REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); |
| 386 | REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029); |
| 387 | REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824); |
| 388 | REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579); |
| 389 | REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000); |
| 390 | REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); |
| 391 | REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); |
| 392 | REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007); |
| 393 | |
| 394 | REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); |
| 395 | } |
| 396 | |
Senthil Balasubramanian | 1f3f061 | 2010-04-15 17:38:29 -0400 | [diff] [blame] | 397 | /* This should work for all families including legacy */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 398 | static bool ath9k_hw_chip_test(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 399 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 400 | struct ath_common *common = ath9k_hw_common(ah); |
Senthil Balasubramanian | 1f3f061 | 2010-04-15 17:38:29 -0400 | [diff] [blame] | 401 | u32 regAddr[2] = { AR_STA_ID0 }; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 402 | u32 regHold[2]; |
Joe Perches | 07b2fa5 | 2010-11-20 18:38:53 -0800 | [diff] [blame] | 403 | static const u32 patternData[4] = { |
| 404 | 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999 |
| 405 | }; |
Senthil Balasubramanian | 1f3f061 | 2010-04-15 17:38:29 -0400 | [diff] [blame] | 406 | int i, j, loop_max; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 407 | |
Senthil Balasubramanian | 1f3f061 | 2010-04-15 17:38:29 -0400 | [diff] [blame] | 408 | if (!AR_SREV_9300_20_OR_LATER(ah)) { |
| 409 | loop_max = 2; |
| 410 | regAddr[1] = AR_PHY_BASE + (8 << 2); |
| 411 | } else |
| 412 | loop_max = 1; |
| 413 | |
| 414 | for (i = 0; i < loop_max; i++) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 415 | u32 addr = regAddr[i]; |
| 416 | u32 wrData, rdData; |
| 417 | |
| 418 | regHold[i] = REG_READ(ah, addr); |
| 419 | for (j = 0; j < 0x100; j++) { |
| 420 | wrData = (j << 16) | j; |
| 421 | REG_WRITE(ah, addr, wrData); |
| 422 | rdData = REG_READ(ah, addr); |
| 423 | if (rdData != wrData) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 424 | ath_err(common, |
| 425 | "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n", |
| 426 | addr, wrData, rdData); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 427 | return false; |
| 428 | } |
| 429 | } |
| 430 | for (j = 0; j < 4; j++) { |
| 431 | wrData = patternData[j]; |
| 432 | REG_WRITE(ah, addr, wrData); |
| 433 | rdData = REG_READ(ah, addr); |
| 434 | if (wrData != rdData) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 435 | ath_err(common, |
| 436 | "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n", |
| 437 | addr, wrData, rdData); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 438 | return false; |
| 439 | } |
| 440 | } |
| 441 | REG_WRITE(ah, regAddr[i], regHold[i]); |
| 442 | } |
| 443 | udelay(100); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 444 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 445 | return true; |
| 446 | } |
| 447 | |
Luis R. Rodriguez | b8b0f37 | 2009-08-03 12:24:43 -0700 | [diff] [blame] | 448 | static void ath9k_hw_init_config(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 449 | { |
| 450 | int i; |
| 451 | |
Felix Fietkau | 689e756 | 2012-04-12 22:35:56 +0200 | [diff] [blame] | 452 | ah->config.dma_beacon_response_time = 1; |
| 453 | ah->config.sw_beacon_response_time = 6; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 454 | ah->config.additional_swba_backoff = 0; |
| 455 | ah->config.ack_6mb = 0x0; |
| 456 | ah->config.cwm_ignore_extcca = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 457 | ah->config.pcie_clock_req = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 458 | ah->config.pcie_waen = 0; |
| 459 | ah->config.analog_shiftreg = 1; |
Luis R. Rodriguez | 03c7251 | 2010-06-12 00:33:46 -0400 | [diff] [blame] | 460 | ah->config.enable_ani = true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 461 | |
| 462 | for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 463 | ah->config.spurchans[i][0] = AR_NO_SPUR; |
| 464 | ah->config.spurchans[i][1] = AR_NO_SPUR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Sujith | 0ce024c | 2009-12-14 14:57:00 +0530 | [diff] [blame] | 467 | ah->config.rx_intr_mitigation = true; |
Luis R. Rodriguez | 6a0ec30 | 2010-06-21 18:38:49 -0400 | [diff] [blame] | 468 | ah->config.pcieSerDesWrite = true; |
Luis R. Rodriguez | 6158425 | 2009-03-12 18:18:49 -0400 | [diff] [blame] | 469 | |
| 470 | /* |
| 471 | * We need this for PCI devices only (Cardbus, PCI, miniPCI) |
| 472 | * _and_ if on non-uniprocessor systems (Multiprocessor/HT). |
| 473 | * This means we use it for all AR5416 devices, and the few |
| 474 | * minor PCI AR9280 devices out there. |
| 475 | * |
| 476 | * Serialization is required because these devices do not handle |
| 477 | * well the case of two concurrent reads/writes due to the latency |
| 478 | * involved. During one read/write another read/write can be issued |
| 479 | * on another CPU while the previous read/write may still be working |
| 480 | * on our hardware, if we hit this case the hardware poops in a loop. |
| 481 | * We prevent this by serializing reads and writes. |
| 482 | * |
| 483 | * This issue is not present on PCI-Express devices or pre-AR5416 |
| 484 | * devices (legacy, 802.11abg). |
| 485 | */ |
| 486 | if (num_possible_cpus() > 1) |
David S. Miller | 2d6a5e9 | 2009-03-17 15:01:30 -0700 | [diff] [blame] | 487 | ah->config.serialize_regmode = SER_REG_MODE_AUTO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Luis R. Rodriguez | 50aca25 | 2009-08-03 12:24:42 -0700 | [diff] [blame] | 490 | static void ath9k_hw_init_defaults(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 491 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 492 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
| 493 | |
| 494 | regulatory->country_code = CTRY_DEFAULT; |
| 495 | regulatory->power_limit = MAX_RATE_POWER; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 496 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 497 | ah->hw_version.magic = AR5416_MAGIC; |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 498 | ah->hw_version.subvendorid = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 499 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 500 | ah->atim_window = 0; |
Felix Fietkau | 16f2411 | 2010-06-12 17:22:32 +0200 | [diff] [blame] | 501 | ah->sta_id1_defaults = |
| 502 | AR_STA_ID1_CRPT_MIC_ENABLE | |
| 503 | AR_STA_ID1_MCAST_KSRCH; |
Felix Fietkau | f171760 | 2011-03-19 13:55:41 +0100 | [diff] [blame] | 504 | if (AR_SREV_9100(ah)) |
| 505 | ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX; |
Rajkumar Manoharan | e3f2acc | 2011-08-27 11:22:59 +0530 | [diff] [blame] | 506 | ah->slottime = ATH9K_SLOT_TIME_9; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 507 | ah->globaltxtimeout = (u32) -1; |
Gabor Juhos | cbdec97 | 2009-07-24 17:27:22 +0200 | [diff] [blame] | 508 | ah->power_mode = ATH9K_PM_UNDEFINED; |
Felix Fietkau | 8efa7a8 | 2012-03-14 16:40:23 +0100 | [diff] [blame] | 509 | ah->htc_reset_init = true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 512 | static int ath9k_hw_init_macaddr(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 513 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 514 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 515 | u32 sum; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 516 | int i; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 517 | u16 eeval; |
Joe Perches | 07b2fa5 | 2010-11-20 18:38:53 -0800 | [diff] [blame] | 518 | static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW }; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 519 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 520 | sum = 0; |
| 521 | for (i = 0; i < 3; i++) { |
Luis R. Rodriguez | 4910167 | 2010-04-15 17:39:13 -0400 | [diff] [blame] | 522 | eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 523 | sum += eeval; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 524 | common->macaddr[2 * i] = eeval >> 8; |
| 525 | common->macaddr[2 * i + 1] = eeval & 0xff; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 526 | } |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 527 | if (sum == 0 || sum == 0xffff * 3) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 528 | return -EADDRNOTAVAIL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 529 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 530 | return 0; |
| 531 | } |
| 532 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 533 | static int ath9k_hw_post_init(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 534 | { |
Sujith Manoharan | 6cae913d | 2011-01-04 13:16:37 +0530 | [diff] [blame] | 535 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 536 | int ecode; |
| 537 | |
Sujith Manoharan | 6cae913d | 2011-01-04 13:16:37 +0530 | [diff] [blame] | 538 | if (common->bus_ops->ath_bus_type != ATH_USB) { |
Sujith | 527d485 | 2010-03-17 14:25:16 +0530 | [diff] [blame] | 539 | if (!ath9k_hw_chip_test(ah)) |
| 540 | return -ENODEV; |
| 541 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 542 | |
Luis R. Rodriguez | ebd5a14 | 2010-04-15 17:39:18 -0400 | [diff] [blame] | 543 | if (!AR_SREV_9300_20_OR_LATER(ah)) { |
| 544 | ecode = ar9002_hw_rf_claim(ah); |
| 545 | if (ecode != 0) |
| 546 | return ecode; |
| 547 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 548 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 549 | ecode = ath9k_hw_eeprom_init(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 550 | if (ecode != 0) |
| 551 | return ecode; |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 552 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 553 | ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n", |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 554 | ah->eep_ops->get_eeprom_ver(ah), |
| 555 | ah->eep_ops->get_eeprom_rev(ah)); |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 556 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 557 | ecode = ath9k_hw_rf_alloc_ext_banks(ah); |
| 558 | if (ecode) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 559 | ath_err(ath9k_hw_common(ah), |
| 560 | "Failed allocating banks for external radio\n"); |
Rajkumar Manoharan | 48a7c3d | 2010-11-08 20:40:53 +0530 | [diff] [blame] | 561 | ath9k_hw_rf_free_ext_banks(ah); |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 562 | return ecode; |
Luis R. Rodriguez | 574d6b1 | 2009-10-19 02:33:37 -0400 | [diff] [blame] | 563 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 564 | |
Nikolay Martynov | 4279425 | 2011-12-02 22:39:16 -0500 | [diff] [blame] | 565 | if (ah->config.enable_ani) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 566 | ath9k_hw_ani_setup(ah); |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 567 | ath9k_hw_ani_init(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 568 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 569 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 570 | return 0; |
| 571 | } |
| 572 | |
Luis R. Rodriguez | 8525f28 | 2010-04-15 17:38:19 -0400 | [diff] [blame] | 573 | static void ath9k_hw_attach_ops(struct ath_hw *ah) |
Luis R. Rodriguez | ee2bb46 | 2009-08-03 12:24:39 -0700 | [diff] [blame] | 574 | { |
Luis R. Rodriguez | 8525f28 | 2010-04-15 17:38:19 -0400 | [diff] [blame] | 575 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 576 | ar9003_hw_attach_ops(ah); |
| 577 | else |
| 578 | ar9002_hw_attach_ops(ah); |
Luis R. Rodriguez | ee2bb46 | 2009-08-03 12:24:39 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 581 | /* Called for all hardware families */ |
| 582 | static int __ath9k_hw_init(struct ath_hw *ah) |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 583 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 584 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 585 | int r = 0; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 586 | |
Senthil Balasubramanian | ac45c12 | 2010-12-22 21:14:20 +0530 | [diff] [blame] | 587 | ath9k_hw_read_revisions(ah); |
| 588 | |
Senthil Balasubramanian | 0a8d7cb | 2010-12-22 19:17:18 +0530 | [diff] [blame] | 589 | /* |
| 590 | * Read back AR_WA into a permanent copy and set bits 14 and 17. |
| 591 | * We need to do this to avoid RMW of this register. We cannot |
| 592 | * read the reg when chip is asleep. |
| 593 | */ |
| 594 | ah->WARegVal = REG_READ(ah, AR_WA); |
| 595 | ah->WARegVal |= (AR_WA_D3_L1_DISABLE | |
| 596 | AR_WA_ASPM_TIMER_BASED_DISABLE); |
| 597 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 598 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 599 | ath_err(common, "Couldn't reset chip\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 600 | return -EIO; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Rajkumar Manoharan | 423e38e | 2011-10-13 11:00:44 +0530 | [diff] [blame] | 603 | if (AR_SREV_9462(ah)) |
Rajkumar Manoharan | eec353c | 2011-10-13 10:49:13 +0530 | [diff] [blame] | 604 | ah->WARegVal &= ~AR_WA_D3_L1_DISABLE; |
| 605 | |
Sujith Manoharan | a4a2954 | 2012-09-10 09:20:03 +0530 | [diff] [blame] | 606 | if (AR_SREV_9565(ah)) { |
| 607 | ah->WARegVal |= AR_WA_BIT22; |
| 608 | REG_WRITE(ah, AR_WA, ah->WARegVal); |
| 609 | } |
| 610 | |
Luis R. Rodriguez | bab1f62 | 2010-04-15 17:38:20 -0400 | [diff] [blame] | 611 | ath9k_hw_init_defaults(ah); |
| 612 | ath9k_hw_init_config(ah); |
| 613 | |
Luis R. Rodriguez | 8525f28 | 2010-04-15 17:38:19 -0400 | [diff] [blame] | 614 | ath9k_hw_attach_ops(ah); |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 615 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 616 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 617 | ath_err(common, "Couldn't wakeup chip\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 618 | return -EIO; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Felix Fietkau | f3eef64 | 2012-03-14 16:40:25 +0100 | [diff] [blame] | 621 | if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) { |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 622 | if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI || |
Panayiotis Karabassis | 7508b65 | 2012-06-26 23:37:17 +0300 | [diff] [blame] | 623 | ((AR_SREV_9160(ah) || AR_SREV_9280(ah) || AR_SREV_9287(ah)) && |
John W. Linville | 4c85ab1 | 2010-07-28 10:06:35 -0400 | [diff] [blame] | 624 | !ah->is_pciexpress)) { |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 625 | ah->config.serialize_regmode = |
| 626 | SER_REG_MODE_ON; |
| 627 | } else { |
| 628 | ah->config.serialize_regmode = |
| 629 | SER_REG_MODE_OFF; |
| 630 | } |
| 631 | } |
| 632 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 633 | ath_dbg(common, RESET, "serialize_regmode is %d\n", |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 634 | ah->config.serialize_regmode); |
| 635 | |
Luis R. Rodriguez | f4709fd | 2009-11-24 21:37:57 -0500 | [diff] [blame] | 636 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) |
| 637 | ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1; |
| 638 | else |
| 639 | ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD; |
| 640 | |
Felix Fietkau | 6da5a72 | 2010-12-12 00:51:12 +0100 | [diff] [blame] | 641 | switch (ah->hw_version.macVersion) { |
| 642 | case AR_SREV_VERSION_5416_PCI: |
| 643 | case AR_SREV_VERSION_5416_PCIE: |
| 644 | case AR_SREV_VERSION_9160: |
| 645 | case AR_SREV_VERSION_9100: |
| 646 | case AR_SREV_VERSION_9280: |
| 647 | case AR_SREV_VERSION_9285: |
| 648 | case AR_SREV_VERSION_9287: |
| 649 | case AR_SREV_VERSION_9271: |
| 650 | case AR_SREV_VERSION_9300: |
Gabor Juhos | 2c8e593 | 2011-06-21 11:23:21 +0200 | [diff] [blame] | 651 | case AR_SREV_VERSION_9330: |
Felix Fietkau | 6da5a72 | 2010-12-12 00:51:12 +0100 | [diff] [blame] | 652 | case AR_SREV_VERSION_9485: |
Vasanthakumar Thiagarajan | bca0468 | 2011-04-19 19:29:20 +0530 | [diff] [blame] | 653 | case AR_SREV_VERSION_9340: |
Rajkumar Manoharan | 423e38e | 2011-10-13 11:00:44 +0530 | [diff] [blame] | 654 | case AR_SREV_VERSION_9462: |
Gabor Juhos | 2b943a3 | 2012-07-03 19:13:34 +0200 | [diff] [blame] | 655 | case AR_SREV_VERSION_9550: |
Sujith Manoharan | 77fac46 | 2012-09-11 20:09:18 +0530 | [diff] [blame] | 656 | case AR_SREV_VERSION_9565: |
Felix Fietkau | 6da5a72 | 2010-12-12 00:51:12 +0100 | [diff] [blame] | 657 | break; |
| 658 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 659 | ath_err(common, |
| 660 | "Mac Chip Rev 0x%02x.%x is not supported by this driver\n", |
| 661 | ah->hw_version.macVersion, ah->hw_version.macRev); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 662 | return -EOPNOTSUPP; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Gabor Juhos | 2c8e593 | 2011-06-21 11:23:21 +0200 | [diff] [blame] | 665 | if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) || |
Gabor Juhos | c95b584 | 2012-07-03 19:13:20 +0200 | [diff] [blame] | 666 | AR_SREV_9330(ah) || AR_SREV_9550(ah)) |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 667 | ah->is_pciexpress = false; |
| 668 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 669 | ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 670 | ath9k_hw_init_cal_settings(ah); |
| 671 | |
| 672 | ah->ani_function = ATH9K_ANI_ALL; |
Felix Fietkau | 7a37081 | 2010-09-22 12:34:52 +0200 | [diff] [blame] | 673 | if (AR_SREV_9280_20_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah)) |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 674 | ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 675 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 676 | ah->ani_function &= ~ATH9K_ANI_MRC_CCK; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 677 | |
| 678 | ath9k_hw_init_mode_regs(ah); |
| 679 | |
Stanislaw Gruszka | 69ce674 | 2011-08-05 13:10:34 +0200 | [diff] [blame] | 680 | if (!ah->is_pciexpress) |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 681 | ath9k_hw_disablepcie(ah); |
| 682 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 683 | r = ath9k_hw_post_init(ah); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 684 | if (r) |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 685 | return r; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 686 | |
| 687 | ath9k_hw_init_mode_gain_regs(ah); |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 688 | r = ath9k_hw_fill_cap_info(ah); |
| 689 | if (r) |
| 690 | return r; |
| 691 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 692 | r = ath9k_hw_init_macaddr(ah); |
| 693 | if (r) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 694 | ath_err(common, "Failed to initialize MAC address\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 695 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 698 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 699 | ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 700 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 701 | ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 702 | |
Gabor Juhos | 88e641d | 2011-06-21 11:23:30 +0200 | [diff] [blame] | 703 | if (AR_SREV_9330(ah)) |
| 704 | ah->bb_watchdog_timeout_ms = 85; |
| 705 | else |
| 706 | ah->bb_watchdog_timeout_ms = 25; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 707 | |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 708 | common->state = ATH_HW_INITIALIZED; |
| 709 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 710 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 713 | int ath9k_hw_init(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 714 | { |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 715 | int ret; |
| 716 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 717 | |
Sujith Manoharan | 77fac46 | 2012-09-11 20:09:18 +0530 | [diff] [blame] | 718 | /* These are all the AR5008/AR9001/AR9002/AR9003 hardware family of chipsets */ |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 719 | switch (ah->hw_version.devid) { |
| 720 | case AR5416_DEVID_PCI: |
| 721 | case AR5416_DEVID_PCIE: |
| 722 | case AR5416_AR9100_DEVID: |
| 723 | case AR9160_DEVID_PCI: |
| 724 | case AR9280_DEVID_PCI: |
| 725 | case AR9280_DEVID_PCIE: |
| 726 | case AR9285_DEVID_PCIE: |
Senthil Balasubramanian | db3cc53 | 2010-04-15 17:38:18 -0400 | [diff] [blame] | 727 | case AR9287_DEVID_PCI: |
| 728 | case AR9287_DEVID_PCIE: |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 729 | case AR2427_DEVID_PCIE: |
Senthil Balasubramanian | db3cc53 | 2010-04-15 17:38:18 -0400 | [diff] [blame] | 730 | case AR9300_DEVID_PCIE: |
Vasanthakumar Thiagarajan | 3050c91 | 2010-12-06 04:27:36 -0800 | [diff] [blame] | 731 | case AR9300_DEVID_AR9485_PCIE: |
Gabor Juhos | 999a7a8 | 2011-06-21 11:23:52 +0200 | [diff] [blame] | 732 | case AR9300_DEVID_AR9330: |
Vasanthakumar Thiagarajan | bca0468 | 2011-04-19 19:29:20 +0530 | [diff] [blame] | 733 | case AR9300_DEVID_AR9340: |
Gabor Juhos | 2b943a3 | 2012-07-03 19:13:34 +0200 | [diff] [blame] | 734 | case AR9300_DEVID_QCA955X: |
Luis R. Rodriguez | 5a63ef0 | 2011-08-24 15:36:08 -0700 | [diff] [blame] | 735 | case AR9300_DEVID_AR9580: |
Rajkumar Manoharan | 423e38e | 2011-10-13 11:00:44 +0530 | [diff] [blame] | 736 | case AR9300_DEVID_AR9462: |
Mohammed Shafi Shajakhan | d4e5979 | 2012-08-02 11:58:50 +0530 | [diff] [blame] | 737 | case AR9485_DEVID_AR1111: |
Sujith Manoharan | 77fac46 | 2012-09-11 20:09:18 +0530 | [diff] [blame] | 738 | case AR9300_DEVID_AR9565: |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 739 | break; |
| 740 | default: |
| 741 | if (common->bus_ops->ath_bus_type == ATH_USB) |
| 742 | break; |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 743 | ath_err(common, "Hardware device ID 0x%04x not supported\n", |
| 744 | ah->hw_version.devid); |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 745 | return -EOPNOTSUPP; |
| 746 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 747 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 748 | ret = __ath9k_hw_init(ah); |
| 749 | if (ret) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 750 | ath_err(common, |
| 751 | "Unable to initialize hardware; initialization status: %d\n", |
| 752 | ret); |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 753 | return ret; |
| 754 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 755 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 756 | return 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 757 | } |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 758 | EXPORT_SYMBOL(ath9k_hw_init); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 759 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 760 | static void ath9k_hw_init_qos(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 761 | { |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 762 | ENABLE_REGWRITE_BUFFER(ah); |
| 763 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 764 | REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa); |
| 765 | REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210); |
| 766 | |
| 767 | REG_WRITE(ah, AR_QOS_NO_ACK, |
| 768 | SM(2, AR_QOS_NO_ACK_TWO_BIT) | |
| 769 | SM(5, AR_QOS_NO_ACK_BIT_OFF) | |
| 770 | SM(0, AR_QOS_NO_ACK_BYTE_OFF)); |
| 771 | |
| 772 | REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL); |
| 773 | REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF); |
| 774 | REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF); |
| 775 | REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF); |
| 776 | REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 777 | |
| 778 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 779 | } |
| 780 | |
Senthil Balasubramanian | b84628e | 2011-04-22 11:32:12 +0530 | [diff] [blame] | 781 | u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah) |
Vivek Natarajan | b141581 | 2011-01-27 14:45:07 +0530 | [diff] [blame] | 782 | { |
Mohammed Shafi Shajakhan | f18e3c6 | 2012-06-18 13:13:30 +0530 | [diff] [blame] | 783 | struct ath_common *common = ath9k_hw_common(ah); |
| 784 | int i = 0; |
| 785 | |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 786 | REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK); |
| 787 | udelay(100); |
| 788 | REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK); |
| 789 | |
Mohammed Shafi Shajakhan | f18e3c6 | 2012-06-18 13:13:30 +0530 | [diff] [blame] | 790 | while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0) { |
| 791 | |
Vivek Natarajan | b141581 | 2011-01-27 14:45:07 +0530 | [diff] [blame] | 792 | udelay(100); |
Vivek Natarajan | b141581 | 2011-01-27 14:45:07 +0530 | [diff] [blame] | 793 | |
Mohammed Shafi Shajakhan | f18e3c6 | 2012-06-18 13:13:30 +0530 | [diff] [blame] | 794 | if (WARN_ON_ONCE(i >= 100)) { |
| 795 | ath_err(common, "PLL4 meaurement not done\n"); |
| 796 | break; |
| 797 | } |
| 798 | |
| 799 | i++; |
| 800 | } |
| 801 | |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 802 | return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3; |
Vivek Natarajan | b141581 | 2011-01-27 14:45:07 +0530 | [diff] [blame] | 803 | } |
| 804 | EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc); |
| 805 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 806 | static void ath9k_hw_init_pll(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 807 | struct ath9k_channel *chan) |
| 808 | { |
Vasanthakumar Thiagarajan | d09b17f | 2010-12-06 04:27:44 -0800 | [diff] [blame] | 809 | u32 pll; |
| 810 | |
Sujith Manoharan | a4a2954 | 2012-09-10 09:20:03 +0530 | [diff] [blame] | 811 | if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) { |
Vasanthakumar Thiagarajan | 3dfd7f6 | 2011-04-11 16:39:40 +0530 | [diff] [blame] | 812 | /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */ |
| 813 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, |
| 814 | AR_CH0_BB_DPLL2_PLL_PWD, 0x1); |
| 815 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, |
| 816 | AR_CH0_DPLL2_KD, 0x40); |
| 817 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, |
| 818 | AR_CH0_DPLL2_KI, 0x4); |
Vivek Natarajan | 22983c3 | 2011-01-27 14:45:09 +0530 | [diff] [blame] | 819 | |
Vasanthakumar Thiagarajan | 3dfd7f6 | 2011-04-11 16:39:40 +0530 | [diff] [blame] | 820 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1, |
| 821 | AR_CH0_BB_DPLL1_REFDIV, 0x5); |
| 822 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1, |
| 823 | AR_CH0_BB_DPLL1_NINI, 0x58); |
| 824 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1, |
| 825 | AR_CH0_BB_DPLL1_NFRAC, 0x0); |
| 826 | |
| 827 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, |
| 828 | AR_CH0_BB_DPLL2_OUTDIV, 0x1); |
| 829 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, |
| 830 | AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1); |
| 831 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, |
| 832 | AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1); |
| 833 | |
| 834 | /* program BB PLL phase_shift to 0x6 */ |
| 835 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3, |
| 836 | AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6); |
| 837 | |
| 838 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, |
| 839 | AR_CH0_BB_DPLL2_PLL_PWD, 0x0); |
Vivek Natarajan | 75e0351 | 2011-03-10 11:05:42 +0530 | [diff] [blame] | 840 | udelay(1000); |
Gabor Juhos | a5415d6 | 2011-06-21 11:23:29 +0200 | [diff] [blame] | 841 | } else if (AR_SREV_9330(ah)) { |
| 842 | u32 ddr_dpll2, pll_control2, kd; |
| 843 | |
| 844 | if (ah->is_clk_25mhz) { |
| 845 | ddr_dpll2 = 0x18e82f01; |
| 846 | pll_control2 = 0xe04a3d; |
| 847 | kd = 0x1d; |
| 848 | } else { |
| 849 | ddr_dpll2 = 0x19e82f01; |
| 850 | pll_control2 = 0x886666; |
| 851 | kd = 0x3d; |
| 852 | } |
| 853 | |
| 854 | /* program DDR PLL ki and kd value */ |
| 855 | REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2); |
| 856 | |
| 857 | /* program DDR PLL phase_shift */ |
| 858 | REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3, |
| 859 | AR_CH0_DPLL3_PHASE_SHIFT, 0x1); |
| 860 | |
| 861 | REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c); |
| 862 | udelay(1000); |
| 863 | |
| 864 | /* program refdiv, nint, frac to RTC register */ |
| 865 | REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2); |
| 866 | |
| 867 | /* program BB PLL kd and ki value */ |
| 868 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd); |
| 869 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06); |
| 870 | |
| 871 | /* program BB PLL phase_shift */ |
| 872 | REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3, |
| 873 | AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1); |
Gabor Juhos | fc05a31 | 2012-07-03 19:13:31 +0200 | [diff] [blame] | 874 | } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) { |
Vasanthakumar Thiagarajan | 0b488ac | 2011-04-20 10:26:15 +0530 | [diff] [blame] | 875 | u32 regval, pll2_divint, pll2_divfrac, refdiv; |
| 876 | |
| 877 | REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c); |
| 878 | udelay(1000); |
| 879 | |
| 880 | REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16); |
| 881 | udelay(100); |
| 882 | |
| 883 | if (ah->is_clk_25mhz) { |
| 884 | pll2_divint = 0x54; |
| 885 | pll2_divfrac = 0x1eb85; |
| 886 | refdiv = 3; |
| 887 | } else { |
Gabor Juhos | fc05a31 | 2012-07-03 19:13:31 +0200 | [diff] [blame] | 888 | if (AR_SREV_9340(ah)) { |
| 889 | pll2_divint = 88; |
| 890 | pll2_divfrac = 0; |
| 891 | refdiv = 5; |
| 892 | } else { |
| 893 | pll2_divint = 0x11; |
| 894 | pll2_divfrac = 0x26666; |
| 895 | refdiv = 1; |
| 896 | } |
Vasanthakumar Thiagarajan | 0b488ac | 2011-04-20 10:26:15 +0530 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | regval = REG_READ(ah, AR_PHY_PLL_MODE); |
| 900 | regval |= (0x1 << 16); |
| 901 | REG_WRITE(ah, AR_PHY_PLL_MODE, regval); |
| 902 | udelay(100); |
| 903 | |
| 904 | REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) | |
| 905 | (pll2_divint << 18) | pll2_divfrac); |
| 906 | udelay(100); |
| 907 | |
| 908 | regval = REG_READ(ah, AR_PHY_PLL_MODE); |
Gabor Juhos | fc05a31 | 2012-07-03 19:13:31 +0200 | [diff] [blame] | 909 | if (AR_SREV_9340(ah)) |
| 910 | regval = (regval & 0x80071fff) | (0x1 << 30) | |
| 911 | (0x1 << 13) | (0x4 << 26) | (0x18 << 19); |
| 912 | else |
| 913 | regval = (regval & 0x80071fff) | (0x3 << 30) | |
| 914 | (0x1 << 13) | (0x4 << 26) | (0x60 << 19); |
Vasanthakumar Thiagarajan | 0b488ac | 2011-04-20 10:26:15 +0530 | [diff] [blame] | 915 | REG_WRITE(ah, AR_PHY_PLL_MODE, regval); |
| 916 | REG_WRITE(ah, AR_PHY_PLL_MODE, |
| 917 | REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff); |
| 918 | udelay(1000); |
Vivek Natarajan | 22983c3 | 2011-01-27 14:45:09 +0530 | [diff] [blame] | 919 | } |
Vasanthakumar Thiagarajan | d09b17f | 2010-12-06 04:27:44 -0800 | [diff] [blame] | 920 | |
| 921 | pll = ath9k_hw_compute_pll_control(ah, chan); |
Sujith Manoharan | 8565f8b | 2012-09-10 09:20:29 +0530 | [diff] [blame] | 922 | if (AR_SREV_9565(ah)) |
| 923 | pll |= 0x40000; |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 924 | REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 925 | |
Gabor Juhos | fc05a31 | 2012-07-03 19:13:31 +0200 | [diff] [blame] | 926 | if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) || |
| 927 | AR_SREV_9550(ah)) |
Vasanthakumar Thiagarajan | 3dfd7f6 | 2011-04-11 16:39:40 +0530 | [diff] [blame] | 928 | udelay(1000); |
| 929 | |
Luis R. Rodriguez | c75724d | 2009-10-19 02:33:34 -0400 | [diff] [blame] | 930 | /* Switch the core clock for ar9271 to 117Mhz */ |
| 931 | if (AR_SREV_9271(ah)) { |
Sujith | 25e2ab1 | 2010-03-17 14:25:22 +0530 | [diff] [blame] | 932 | udelay(500); |
| 933 | REG_WRITE(ah, 0x50040, 0x304); |
Luis R. Rodriguez | c75724d | 2009-10-19 02:33:34 -0400 | [diff] [blame] | 934 | } |
| 935 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 936 | udelay(RTC_PLL_SETTLE_DELAY); |
| 937 | |
| 938 | REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK); |
Vasanthakumar Thiagarajan | 0b488ac | 2011-04-20 10:26:15 +0530 | [diff] [blame] | 939 | |
Gabor Juhos | fc05a31 | 2012-07-03 19:13:31 +0200 | [diff] [blame] | 940 | if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) { |
Vasanthakumar Thiagarajan | 0b488ac | 2011-04-20 10:26:15 +0530 | [diff] [blame] | 941 | if (ah->is_clk_25mhz) { |
| 942 | REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1); |
| 943 | REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7); |
| 944 | REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae); |
| 945 | } else { |
| 946 | REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1); |
| 947 | REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400); |
| 948 | REG_WRITE(ah, AR_SLP32_INC, 0x0001e800); |
| 949 | } |
| 950 | udelay(100); |
| 951 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 952 | } |
| 953 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 954 | static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah, |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 955 | enum nl80211_iftype opmode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 956 | { |
Vasanthakumar Thiagarajan | 79d1d2b | 2011-04-19 19:29:19 +0530 | [diff] [blame] | 957 | u32 sync_default = AR_INTR_SYNC_DEFAULT; |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 958 | u32 imr_reg = AR_IMR_TXERR | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 959 | AR_IMR_TXURN | |
| 960 | AR_IMR_RXERR | |
| 961 | AR_IMR_RXORN | |
| 962 | AR_IMR_BCNMISC; |
| 963 | |
Gabor Juhos | 3b8a057 | 2012-07-03 19:13:29 +0200 | [diff] [blame] | 964 | if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) |
Vasanthakumar Thiagarajan | 79d1d2b | 2011-04-19 19:29:19 +0530 | [diff] [blame] | 965 | sync_default &= ~AR_INTR_SYNC_HOST1_FATAL; |
| 966 | |
Vasanthakumar Thiagarajan | 6686024 | 2010-04-15 17:39:07 -0400 | [diff] [blame] | 967 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 968 | imr_reg |= AR_IMR_RXOK_HP; |
| 969 | if (ah->config.rx_intr_mitigation) |
| 970 | imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR; |
| 971 | else |
| 972 | imr_reg |= AR_IMR_RXOK_LP; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 973 | |
Vasanthakumar Thiagarajan | 6686024 | 2010-04-15 17:39:07 -0400 | [diff] [blame] | 974 | } else { |
| 975 | if (ah->config.rx_intr_mitigation) |
| 976 | imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR; |
| 977 | else |
| 978 | imr_reg |= AR_IMR_RXOK; |
| 979 | } |
| 980 | |
| 981 | if (ah->config.tx_intr_mitigation) |
| 982 | imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR; |
| 983 | else |
| 984 | imr_reg |= AR_IMR_TXOK; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 985 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 986 | ENABLE_REGWRITE_BUFFER(ah); |
| 987 | |
Pavel Roskin | 152d530 | 2010-03-31 18:05:37 -0400 | [diff] [blame] | 988 | REG_WRITE(ah, AR_IMR, imr_reg); |
Pavel Roskin | 74bad5c | 2010-02-23 18:15:27 -0500 | [diff] [blame] | 989 | ah->imrs2_reg |= AR_IMR_S2_GTT; |
| 990 | REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 991 | |
| 992 | if (!AR_SREV_9100(ah)) { |
| 993 | REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF); |
Vasanthakumar Thiagarajan | 79d1d2b | 2011-04-19 19:29:19 +0530 | [diff] [blame] | 994 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 995 | REG_WRITE(ah, AR_INTR_SYNC_MASK, 0); |
| 996 | } |
Vasanthakumar Thiagarajan | 6686024 | 2010-04-15 17:39:07 -0400 | [diff] [blame] | 997 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 998 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 999 | |
Vasanthakumar Thiagarajan | 6686024 | 2010-04-15 17:39:07 -0400 | [diff] [blame] | 1000 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 1001 | REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0); |
| 1002 | REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0); |
| 1003 | REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0); |
| 1004 | REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0); |
| 1005 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1006 | } |
| 1007 | |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1008 | static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us) |
| 1009 | { |
| 1010 | u32 val = ath9k_hw_mac_to_clks(ah, us - 2); |
| 1011 | val = min(val, (u32) 0xFFFF); |
| 1012 | REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val); |
| 1013 | } |
| 1014 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1015 | static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1016 | { |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1017 | u32 val = ath9k_hw_mac_to_clks(ah, us); |
| 1018 | val = min(val, (u32) 0xFFFF); |
| 1019 | REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1020 | } |
| 1021 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1022 | static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1023 | { |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1024 | u32 val = ath9k_hw_mac_to_clks(ah, us); |
| 1025 | val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK)); |
| 1026 | REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val); |
| 1027 | } |
| 1028 | |
| 1029 | static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us) |
| 1030 | { |
| 1031 | u32 val = ath9k_hw_mac_to_clks(ah, us); |
| 1032 | val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS)); |
| 1033 | REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1034 | } |
| 1035 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1036 | static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1037 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1038 | if (tu > 0xFFFF) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1039 | ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n", |
| 1040 | tu); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1041 | ah->globaltxtimeout = (u32) -1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1042 | return false; |
| 1043 | } else { |
| 1044 | REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1045 | ah->globaltxtimeout = tu; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1046 | return true; |
| 1047 | } |
| 1048 | } |
| 1049 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1050 | void ath9k_hw_init_global_settings(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1051 | { |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1052 | struct ath_common *common = ath9k_hw_common(ah); |
| 1053 | struct ieee80211_conf *conf = &common->hw->conf; |
| 1054 | const struct ath9k_channel *chan = ah->curchan; |
Felix Fietkau | e115b7e | 2012-04-19 21:18:23 +0200 | [diff] [blame] | 1055 | int acktimeout, ctstimeout, ack_offset = 0; |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 1056 | int slottime; |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1057 | int sifstime; |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1058 | int rx_lat = 0, tx_lat = 0, eifs = 0; |
| 1059 | u32 reg; |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1060 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1061 | ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n", |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1062 | ah->misc_mode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1063 | |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1064 | if (!chan) |
| 1065 | return; |
| 1066 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1067 | if (ah->misc_mode != 0) |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1068 | REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode); |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1069 | |
Rajkumar Manoharan | 81a91d5 | 2011-08-31 10:47:30 +0530 | [diff] [blame] | 1070 | if (IS_CHAN_A_FAST_CLOCK(ah, chan)) |
| 1071 | rx_lat = 41; |
| 1072 | else |
| 1073 | rx_lat = 37; |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1074 | tx_lat = 54; |
| 1075 | |
Felix Fietkau | e88e486 | 2012-04-19 21:18:22 +0200 | [diff] [blame] | 1076 | if (IS_CHAN_5GHZ(chan)) |
| 1077 | sifstime = 16; |
| 1078 | else |
| 1079 | sifstime = 10; |
| 1080 | |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1081 | if (IS_CHAN_HALF_RATE(chan)) { |
| 1082 | eifs = 175; |
| 1083 | rx_lat *= 2; |
| 1084 | tx_lat *= 2; |
| 1085 | if (IS_CHAN_A_FAST_CLOCK(ah, chan)) |
| 1086 | tx_lat += 11; |
| 1087 | |
Felix Fietkau | e88e486 | 2012-04-19 21:18:22 +0200 | [diff] [blame] | 1088 | sifstime *= 2; |
Felix Fietkau | e115b7e | 2012-04-19 21:18:23 +0200 | [diff] [blame] | 1089 | ack_offset = 16; |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1090 | slottime = 13; |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1091 | } else if (IS_CHAN_QUARTER_RATE(chan)) { |
| 1092 | eifs = 340; |
Rajkumar Manoharan | 81a91d5 | 2011-08-31 10:47:30 +0530 | [diff] [blame] | 1093 | rx_lat = (rx_lat * 4) - 1; |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1094 | tx_lat *= 4; |
| 1095 | if (IS_CHAN_A_FAST_CLOCK(ah, chan)) |
| 1096 | tx_lat += 22; |
| 1097 | |
Felix Fietkau | e88e486 | 2012-04-19 21:18:22 +0200 | [diff] [blame] | 1098 | sifstime *= 4; |
Felix Fietkau | e115b7e | 2012-04-19 21:18:23 +0200 | [diff] [blame] | 1099 | ack_offset = 32; |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1100 | slottime = 21; |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1101 | } else { |
Rajkumar Manoharan | a7be039 | 2011-08-27 12:13:21 +0530 | [diff] [blame] | 1102 | if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) { |
| 1103 | eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO; |
| 1104 | reg = AR_USEC_ASYNC_FIFO; |
| 1105 | } else { |
| 1106 | eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/ |
| 1107 | common->clockrate; |
| 1108 | reg = REG_READ(ah, AR_USEC); |
| 1109 | } |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1110 | rx_lat = MS(reg, AR_USEC_RX_LAT); |
| 1111 | tx_lat = MS(reg, AR_USEC_TX_LAT); |
| 1112 | |
| 1113 | slottime = ah->slottime; |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1114 | } |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1115 | |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 1116 | /* As defined by IEEE 802.11-2007 17.3.8.6 */ |
Felix Fietkau | e115b7e | 2012-04-19 21:18:23 +0200 | [diff] [blame] | 1117 | acktimeout = slottime + sifstime + 3 * ah->coverage_class + ack_offset; |
Felix Fietkau | adb5066 | 2011-08-28 01:52:10 +0200 | [diff] [blame] | 1118 | ctstimeout = acktimeout; |
Felix Fietkau | 42c4568 | 2010-02-11 18:07:19 +0100 | [diff] [blame] | 1119 | |
| 1120 | /* |
| 1121 | * Workaround for early ACK timeouts, add an offset to match the |
Felix Fietkau | 55a2bb4 | 2012-02-05 21:15:18 +0100 | [diff] [blame] | 1122 | * initval's 64us ack timeout value. Use 48us for the CTS timeout. |
Felix Fietkau | 42c4568 | 2010-02-11 18:07:19 +0100 | [diff] [blame] | 1123 | * This was initially only meant to work around an issue with delayed |
| 1124 | * BA frames in some implementations, but it has been found to fix ACK |
| 1125 | * timeout issues in other cases as well. |
| 1126 | */ |
Felix Fietkau | e115b7e | 2012-04-19 21:18:23 +0200 | [diff] [blame] | 1127 | if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ && |
| 1128 | !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) { |
Felix Fietkau | 42c4568 | 2010-02-11 18:07:19 +0100 | [diff] [blame] | 1129 | acktimeout += 64 - sifstime - ah->slottime; |
Felix Fietkau | 55a2bb4 | 2012-02-05 21:15:18 +0100 | [diff] [blame] | 1130 | ctstimeout += 48 - sifstime - ah->slottime; |
| 1131 | } |
| 1132 | |
Felix Fietkau | 42c4568 | 2010-02-11 18:07:19 +0100 | [diff] [blame] | 1133 | |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1134 | ath9k_hw_set_sifs_time(ah, sifstime); |
| 1135 | ath9k_hw_setslottime(ah, slottime); |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1136 | ath9k_hw_set_ack_timeout(ah, acktimeout); |
Felix Fietkau | adb5066 | 2011-08-28 01:52:10 +0200 | [diff] [blame] | 1137 | ath9k_hw_set_cts_timeout(ah, ctstimeout); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1138 | if (ah->globaltxtimeout != (u32) -1) |
| 1139 | ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout); |
Felix Fietkau | b6ba41b | 2011-07-09 11:12:50 +0700 | [diff] [blame] | 1140 | |
| 1141 | REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs)); |
| 1142 | REG_RMW(ah, AR_USEC, |
| 1143 | (common->clockrate - 1) | |
| 1144 | SM(rx_lat, AR_USEC_RX_LAT) | |
| 1145 | SM(tx_lat, AR_USEC_TX_LAT), |
| 1146 | AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC); |
| 1147 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1148 | } |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1149 | EXPORT_SYMBOL(ath9k_hw_init_global_settings); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1150 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1151 | void ath9k_hw_deinit(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1152 | { |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 1153 | struct ath_common *common = ath9k_hw_common(ah); |
| 1154 | |
Sujith | 736b3a2 | 2010-03-17 14:25:24 +0530 | [diff] [blame] | 1155 | if (common->state < ATH_HW_INITIALIZED) |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 1156 | goto free_hw; |
| 1157 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1158 | ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP); |
Luis R. Rodriguez | 211f585 | 2009-10-06 21:19:07 -0400 | [diff] [blame] | 1159 | |
| 1160 | free_hw: |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1161 | ath9k_hw_rf_free_ext_banks(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1162 | } |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1163 | EXPORT_SYMBOL(ath9k_hw_deinit); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1164 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1165 | /*******/ |
| 1166 | /* INI */ |
| 1167 | /*******/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1168 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1169 | u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan) |
Bob Copeland | 3a702e4 | 2009-03-30 22:30:29 -0400 | [diff] [blame] | 1170 | { |
| 1171 | u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band); |
| 1172 | |
| 1173 | if (IS_CHAN_B(chan)) |
| 1174 | ctl |= CTL_11B; |
| 1175 | else if (IS_CHAN_G(chan)) |
| 1176 | ctl |= CTL_11G; |
| 1177 | else |
| 1178 | ctl |= CTL_11A; |
| 1179 | |
| 1180 | return ctl; |
| 1181 | } |
| 1182 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1183 | /****************************************/ |
| 1184 | /* Reset and Channel Switching Routines */ |
| 1185 | /****************************************/ |
| 1186 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1187 | static inline void ath9k_hw_set_dma(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1188 | { |
Felix Fietkau | 57b3222 | 2010-04-15 17:39:22 -0400 | [diff] [blame] | 1189 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1190 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1191 | ENABLE_REGWRITE_BUFFER(ah); |
| 1192 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1193 | /* |
| 1194 | * set AHB_MODE not to do cacheline prefetches |
| 1195 | */ |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1196 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 1197 | REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1198 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1199 | /* |
| 1200 | * let mac dma reads be in 128 byte chunks |
| 1201 | */ |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1202 | REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1203 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1204 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1205 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1206 | /* |
| 1207 | * Restore TX Trigger Level to its pre-reset value. |
| 1208 | * The initial value depends on whether aggregation is enabled, and is |
| 1209 | * adjusted whenever underruns are detected. |
| 1210 | */ |
Felix Fietkau | 57b3222 | 2010-04-15 17:39:22 -0400 | [diff] [blame] | 1211 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 1212 | REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1213 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1214 | ENABLE_REGWRITE_BUFFER(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1215 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1216 | /* |
| 1217 | * let mac dma writes be in 128 byte chunks |
| 1218 | */ |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1219 | REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1220 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1221 | /* |
| 1222 | * Setup receive FIFO threshold to hold off TX activities |
| 1223 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1224 | REG_WRITE(ah, AR_RXFIFO_CFG, 0x200); |
| 1225 | |
Felix Fietkau | 57b3222 | 2010-04-15 17:39:22 -0400 | [diff] [blame] | 1226 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 1227 | REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1); |
| 1228 | REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1); |
| 1229 | |
| 1230 | ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize - |
| 1231 | ah->caps.rx_status_len); |
| 1232 | } |
| 1233 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1234 | /* |
| 1235 | * reduce the number of usable entries in PCU TXBUF to avoid |
| 1236 | * wrap around issues. |
| 1237 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1238 | if (AR_SREV_9285(ah)) { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1239 | /* For AR9285 the number of Fifos are reduced to half. |
| 1240 | * So set the usable tx buf size also to half to |
| 1241 | * avoid data/delimiter underruns |
| 1242 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1243 | REG_WRITE(ah, AR_PCU_TXBUF_CTRL, |
| 1244 | AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE); |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1245 | } else if (!AR_SREV_9271(ah)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1246 | REG_WRITE(ah, AR_PCU_TXBUF_CTRL, |
| 1247 | AR_PCU_TXBUF_CTRL_USABLE_SIZE); |
| 1248 | } |
Vasanthakumar Thiagarajan | 744d402 | 2010-04-15 17:39:27 -0400 | [diff] [blame] | 1249 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1250 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1251 | |
Vasanthakumar Thiagarajan | 744d402 | 2010-04-15 17:39:27 -0400 | [diff] [blame] | 1252 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 1253 | ath9k_hw_reset_txstatus_ring(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1254 | } |
| 1255 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1256 | static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1257 | { |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1258 | u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC; |
| 1259 | u32 set = AR_STA_ID1_KSRCH_MODE; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1260 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1261 | switch (opmode) { |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1262 | case NL80211_IFTYPE_ADHOC: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 1263 | case NL80211_IFTYPE_MESH_POINT: |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1264 | set |= AR_STA_ID1_ADHOC; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1265 | REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); |
| 1266 | break; |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1267 | case NL80211_IFTYPE_AP: |
| 1268 | set |= AR_STA_ID1_STA_AP; |
| 1269 | /* fall through */ |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1270 | case NL80211_IFTYPE_STATION: |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1271 | REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1272 | break; |
Rajkumar Manoharan | 5f841b4 | 2010-10-27 18:31:15 +0530 | [diff] [blame] | 1273 | default: |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1274 | if (!ah->is_monitoring) |
| 1275 | set = 0; |
Rajkumar Manoharan | 5f841b4 | 2010-10-27 18:31:15 +0530 | [diff] [blame] | 1276 | break; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1277 | } |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1278 | REG_RMW(ah, AR_STA_ID1, set, mask); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1279 | } |
| 1280 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1281 | void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled, |
| 1282 | u32 *coef_mantissa, u32 *coef_exponent) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1283 | { |
| 1284 | u32 coef_exp, coef_man; |
| 1285 | |
| 1286 | for (coef_exp = 31; coef_exp > 0; coef_exp--) |
| 1287 | if ((coef_scaled >> coef_exp) & 0x1) |
| 1288 | break; |
| 1289 | |
| 1290 | coef_exp = 14 - (coef_exp - COEF_SCALE_S); |
| 1291 | |
| 1292 | coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1)); |
| 1293 | |
| 1294 | *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp); |
| 1295 | *coef_exponent = coef_exp - 16; |
| 1296 | } |
| 1297 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1298 | static bool ath9k_hw_set_reset(struct ath_hw *ah, int type) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1299 | { |
| 1300 | u32 rst_flags; |
| 1301 | u32 tmpReg; |
| 1302 | |
Sujith | 7076849 | 2009-02-16 13:23:12 +0530 | [diff] [blame] | 1303 | if (AR_SREV_9100(ah)) { |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1304 | REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK, |
| 1305 | AR_RTC_DERIVED_CLK_PERIOD, 1); |
Sujith | 7076849 | 2009-02-16 13:23:12 +0530 | [diff] [blame] | 1306 | (void)REG_READ(ah, AR_RTC_DERIVED_CLK); |
| 1307 | } |
| 1308 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1309 | ENABLE_REGWRITE_BUFFER(ah); |
| 1310 | |
Luis R. Rodriguez | 9a658d2 | 2010-06-21 18:38:47 -0400 | [diff] [blame] | 1311 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 1312 | REG_WRITE(ah, AR_WA, ah->WARegVal); |
| 1313 | udelay(10); |
| 1314 | } |
| 1315 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1316 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN | |
| 1317 | AR_RTC_FORCE_WAKE_ON_INT); |
| 1318 | |
| 1319 | if (AR_SREV_9100(ah)) { |
| 1320 | rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD | |
| 1321 | AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET; |
| 1322 | } else { |
| 1323 | tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE); |
| 1324 | if (tmpReg & |
| 1325 | (AR_INTR_SYNC_LOCAL_TIMEOUT | |
| 1326 | AR_INTR_SYNC_RADM_CPL_TIMEOUT)) { |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1327 | u32 val; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1328 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0); |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1329 | |
| 1330 | val = AR_RC_HOSTIF; |
| 1331 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 1332 | val |= AR_RC_AHB; |
| 1333 | REG_WRITE(ah, AR_RC, val); |
| 1334 | |
| 1335 | } else if (!AR_SREV_9300_20_OR_LATER(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1336 | REG_WRITE(ah, AR_RC, AR_RC_AHB); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1337 | |
| 1338 | rst_flags = AR_RTC_RC_MAC_WARM; |
| 1339 | if (type == ATH9K_RESET_COLD) |
| 1340 | rst_flags |= AR_RTC_RC_MAC_COLD; |
| 1341 | } |
| 1342 | |
Gabor Juhos | 7d95847c | 2011-06-21 11:23:51 +0200 | [diff] [blame] | 1343 | if (AR_SREV_9330(ah)) { |
| 1344 | int npend = 0; |
| 1345 | int i; |
| 1346 | |
| 1347 | /* AR9330 WAR: |
| 1348 | * call external reset function to reset WMAC if: |
| 1349 | * - doing a cold reset |
| 1350 | * - we have pending frames in the TX queues |
| 1351 | */ |
| 1352 | |
| 1353 | for (i = 0; i < AR_NUM_QCU; i++) { |
| 1354 | npend = ath9k_hw_numtxpending(ah, i); |
| 1355 | if (npend) |
| 1356 | break; |
| 1357 | } |
| 1358 | |
| 1359 | if (ah->external_reset && |
| 1360 | (npend || type == ATH9K_RESET_COLD)) { |
| 1361 | int reset_err = 0; |
| 1362 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1363 | ath_dbg(ath9k_hw_common(ah), RESET, |
Gabor Juhos | 7d95847c | 2011-06-21 11:23:51 +0200 | [diff] [blame] | 1364 | "reset MAC via external reset\n"); |
| 1365 | |
| 1366 | reset_err = ah->external_reset(); |
| 1367 | if (reset_err) { |
| 1368 | ath_err(ath9k_hw_common(ah), |
| 1369 | "External reset failed, err=%d\n", |
| 1370 | reset_err); |
| 1371 | return false; |
| 1372 | } |
| 1373 | |
| 1374 | REG_WRITE(ah, AR_RTC_RESET, 1); |
| 1375 | } |
| 1376 | } |
| 1377 | |
Rajkumar Manoharan | 3863495 | 2012-06-11 12:19:32 +0530 | [diff] [blame] | 1378 | if (ath9k_hw_mci_is_enabled(ah)) |
Rajkumar Manoharan | 506847a | 2012-06-12 20:18:16 +0530 | [diff] [blame] | 1379 | ar9003_mci_check_gpm_offset(ah); |
Rajkumar Manoharan | 3863495 | 2012-06-11 12:19:32 +0530 | [diff] [blame] | 1380 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1381 | REG_WRITE(ah, AR_RTC_RC, rst_flags); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1382 | |
| 1383 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1384 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1385 | udelay(50); |
| 1386 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1387 | REG_WRITE(ah, AR_RTC_RC, 0); |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1388 | if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1389 | ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1390 | return false; |
| 1391 | } |
| 1392 | |
| 1393 | if (!AR_SREV_9100(ah)) |
| 1394 | REG_WRITE(ah, AR_RC, 0); |
| 1395 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1396 | if (AR_SREV_9100(ah)) |
| 1397 | udelay(50); |
| 1398 | |
| 1399 | return true; |
| 1400 | } |
| 1401 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1402 | static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1403 | { |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1404 | ENABLE_REGWRITE_BUFFER(ah); |
| 1405 | |
Luis R. Rodriguez | 9a658d2 | 2010-06-21 18:38:47 -0400 | [diff] [blame] | 1406 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 1407 | REG_WRITE(ah, AR_WA, ah->WARegVal); |
| 1408 | udelay(10); |
| 1409 | } |
| 1410 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1411 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN | |
| 1412 | AR_RTC_FORCE_WAKE_ON_INT); |
| 1413 | |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 1414 | if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah)) |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1415 | REG_WRITE(ah, AR_RC, AR_RC_AHB); |
| 1416 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1417 | REG_WRITE(ah, AR_RTC_RESET, 0); |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1418 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1419 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1420 | |
Senthil Balasubramanian | 84e2169 | 2010-04-15 17:38:30 -0400 | [diff] [blame] | 1421 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 1422 | udelay(2); |
| 1423 | |
| 1424 | if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah)) |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1425 | REG_WRITE(ah, AR_RC, 0); |
| 1426 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1427 | REG_WRITE(ah, AR_RTC_RESET, 1); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1428 | |
| 1429 | if (!ath9k_hw_wait(ah, |
| 1430 | AR_RTC_STATUS, |
| 1431 | AR_RTC_STATUS_M, |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1432 | AR_RTC_STATUS_ON, |
| 1433 | AH_WAIT_TIMEOUT)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1434 | ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1435 | return false; |
| 1436 | } |
| 1437 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1438 | return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM); |
| 1439 | } |
| 1440 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1441 | static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1442 | { |
Mohammed Shafi Shajakhan | 7a9233f | 2011-11-30 10:41:25 +0530 | [diff] [blame] | 1443 | bool ret = false; |
Senthil Balasubramanian | 2577c6e | 2011-09-13 22:38:18 +0530 | [diff] [blame] | 1444 | |
Luis R. Rodriguez | 9a658d2 | 2010-06-21 18:38:47 -0400 | [diff] [blame] | 1445 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 1446 | REG_WRITE(ah, AR_WA, ah->WARegVal); |
| 1447 | udelay(10); |
| 1448 | } |
| 1449 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1450 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, |
| 1451 | AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT); |
| 1452 | |
| 1453 | switch (type) { |
| 1454 | case ATH9K_RESET_POWER_ON: |
Mohammed Shafi Shajakhan | 7a9233f | 2011-11-30 10:41:25 +0530 | [diff] [blame] | 1455 | ret = ath9k_hw_set_reset_power_on(ah); |
| 1456 | break; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1457 | case ATH9K_RESET_WARM: |
| 1458 | case ATH9K_RESET_COLD: |
Mohammed Shafi Shajakhan | 7a9233f | 2011-11-30 10:41:25 +0530 | [diff] [blame] | 1459 | ret = ath9k_hw_set_reset(ah, type); |
| 1460 | break; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1461 | default: |
Mohammed Shafi Shajakhan | 7a9233f | 2011-11-30 10:41:25 +0530 | [diff] [blame] | 1462 | break; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1463 | } |
Mohammed Shafi Shajakhan | 7a9233f | 2011-11-30 10:41:25 +0530 | [diff] [blame] | 1464 | |
Mohammed Shafi Shajakhan | 7a9233f | 2011-11-30 10:41:25 +0530 | [diff] [blame] | 1465 | return ret; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1466 | } |
| 1467 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1468 | static bool ath9k_hw_chip_reset(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1469 | struct ath9k_channel *chan) |
| 1470 | { |
Felix Fietkau | 9c083af | 2012-03-03 15:17:02 +0100 | [diff] [blame] | 1471 | int reset_type = ATH9K_RESET_WARM; |
| 1472 | |
| 1473 | if (AR_SREV_9280(ah)) { |
| 1474 | if (ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) |
| 1475 | reset_type = ATH9K_RESET_POWER_ON; |
| 1476 | else |
| 1477 | reset_type = ATH9K_RESET_COLD; |
| 1478 | } |
| 1479 | |
| 1480 | if (!ath9k_hw_set_reset_reg(ah, reset_type)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1481 | return false; |
| 1482 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1483 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1484 | return false; |
| 1485 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1486 | ah->chip_fullsleep = false; |
Felix Fietkau | bfc441a | 2012-05-24 14:32:22 +0200 | [diff] [blame] | 1487 | |
| 1488 | if (AR_SREV_9330(ah)) |
| 1489 | ar9003_hw_internal_regulator_apply(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1490 | ath9k_hw_init_pll(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1491 | ath9k_hw_set_rfmode(ah, chan); |
| 1492 | |
| 1493 | return true; |
| 1494 | } |
| 1495 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1496 | static bool ath9k_hw_channel_change(struct ath_hw *ah, |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 1497 | struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1498 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1499 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1500 | u32 qnum; |
Luis R. Rodriguez | 0a3b7ba | 2009-10-19 02:33:40 -0400 | [diff] [blame] | 1501 | int r; |
Rajkumar Manoharan | 5f0c04e | 2011-10-13 11:00:35 +0530 | [diff] [blame] | 1502 | bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); |
| 1503 | bool band_switch, mode_diff; |
| 1504 | u8 ini_reloaded; |
| 1505 | |
| 1506 | band_switch = (chan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ)) != |
| 1507 | (ah->curchan->channelFlags & (CHANNEL_2GHZ | |
| 1508 | CHANNEL_5GHZ)); |
| 1509 | mode_diff = (chan->chanmode != ah->curchan->chanmode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1510 | |
| 1511 | for (qnum = 0; qnum < AR_NUM_QCU; qnum++) { |
| 1512 | if (ath9k_hw_numtxpending(ah, qnum)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1513 | ath_dbg(common, QUEUE, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1514 | "Transmit frames pending on queue %d\n", qnum); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1515 | return false; |
| 1516 | } |
| 1517 | } |
| 1518 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1519 | if (!ath9k_hw_rfbus_req(ah)) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1520 | ath_err(common, "Could not kill baseband RX\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1521 | return false; |
| 1522 | } |
| 1523 | |
Rajkumar Manoharan | 5f0c04e | 2011-10-13 11:00:35 +0530 | [diff] [blame] | 1524 | if (edma && (band_switch || mode_diff)) { |
| 1525 | ath9k_hw_mark_phy_inactive(ah); |
| 1526 | udelay(5); |
| 1527 | |
| 1528 | ath9k_hw_init_pll(ah, NULL); |
| 1529 | |
| 1530 | if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) { |
| 1531 | ath_err(common, "Failed to do fast channel change\n"); |
| 1532 | return false; |
| 1533 | } |
| 1534 | } |
| 1535 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1536 | ath9k_hw_set_channel_regs(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1537 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1538 | r = ath9k_hw_rf_set_freq(ah, chan); |
Luis R. Rodriguez | 0a3b7ba | 2009-10-19 02:33:40 -0400 | [diff] [blame] | 1539 | if (r) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1540 | ath_err(common, "Failed to set channel\n"); |
Luis R. Rodriguez | 0a3b7ba | 2009-10-19 02:33:40 -0400 | [diff] [blame] | 1541 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1542 | } |
Felix Fietkau | dfdac8a | 2010-10-08 22:13:51 +0200 | [diff] [blame] | 1543 | ath9k_hw_set_clockrate(ah); |
Gabor Juhos | 64ea57d | 2012-04-15 20:38:05 +0200 | [diff] [blame] | 1544 | ath9k_hw_apply_txpower(ah, chan, false); |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1545 | ath9k_hw_rfbus_done(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1546 | |
| 1547 | if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) |
| 1548 | ath9k_hw_set_delta_slope(ah, chan); |
| 1549 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1550 | ath9k_hw_spur_mitigate_freq(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1551 | |
Rajkumar Manoharan | 5f0c04e | 2011-10-13 11:00:35 +0530 | [diff] [blame] | 1552 | if (edma && (band_switch || mode_diff)) { |
Rajkumar Manoharan | a126ff5 | 2011-10-13 11:00:42 +0530 | [diff] [blame] | 1553 | ah->ah_flags |= AH_FASTCC; |
Rajkumar Manoharan | 5f0c04e | 2011-10-13 11:00:35 +0530 | [diff] [blame] | 1554 | if (band_switch || ini_reloaded) |
| 1555 | ah->eep_ops->set_board_values(ah, chan); |
| 1556 | |
| 1557 | ath9k_hw_init_bb(ah, chan); |
| 1558 | |
| 1559 | if (band_switch || ini_reloaded) |
| 1560 | ath9k_hw_init_cal(ah, chan); |
Rajkumar Manoharan | a126ff5 | 2011-10-13 11:00:42 +0530 | [diff] [blame] | 1561 | ah->ah_flags &= ~AH_FASTCC; |
Rajkumar Manoharan | 5f0c04e | 2011-10-13 11:00:35 +0530 | [diff] [blame] | 1562 | } |
| 1563 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1564 | return true; |
| 1565 | } |
| 1566 | |
Felix Fietkau | 691680b | 2011-03-19 13:55:38 +0100 | [diff] [blame] | 1567 | static void ath9k_hw_apply_gpio_override(struct ath_hw *ah) |
| 1568 | { |
| 1569 | u32 gpio_mask = ah->gpio_mask; |
| 1570 | int i; |
| 1571 | |
| 1572 | for (i = 0; gpio_mask; i++, gpio_mask >>= 1) { |
| 1573 | if (!(gpio_mask & 1)) |
| 1574 | continue; |
| 1575 | |
| 1576 | ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
| 1577 | ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i))); |
| 1578 | } |
| 1579 | } |
| 1580 | |
Rajkumar Manoharan | 01e1891 | 2012-03-15 05:34:27 +0530 | [diff] [blame] | 1581 | static bool ath9k_hw_check_dcs(u32 dma_dbg, u32 num_dcu_states, |
| 1582 | int *hang_state, int *hang_pos) |
| 1583 | { |
| 1584 | static u32 dcu_chain_state[] = {5, 6, 9}; /* DCU chain stuck states */ |
| 1585 | u32 chain_state, dcs_pos, i; |
| 1586 | |
| 1587 | for (dcs_pos = 0; dcs_pos < num_dcu_states; dcs_pos++) { |
| 1588 | chain_state = (dma_dbg >> (5 * dcs_pos)) & 0x1f; |
| 1589 | for (i = 0; i < 3; i++) { |
| 1590 | if (chain_state == dcu_chain_state[i]) { |
| 1591 | *hang_state = chain_state; |
| 1592 | *hang_pos = dcs_pos; |
| 1593 | return true; |
| 1594 | } |
| 1595 | } |
| 1596 | } |
| 1597 | return false; |
| 1598 | } |
| 1599 | |
| 1600 | #define DCU_COMPLETE_STATE 1 |
| 1601 | #define DCU_COMPLETE_STATE_MASK 0x3 |
| 1602 | #define NUM_STATUS_READS 50 |
| 1603 | static bool ath9k_hw_detect_mac_hang(struct ath_hw *ah) |
| 1604 | { |
| 1605 | u32 chain_state, comp_state, dcs_reg = AR_DMADBG_4; |
| 1606 | u32 i, hang_pos, hang_state, num_state = 6; |
| 1607 | |
| 1608 | comp_state = REG_READ(ah, AR_DMADBG_6); |
| 1609 | |
| 1610 | if ((comp_state & DCU_COMPLETE_STATE_MASK) != DCU_COMPLETE_STATE) { |
| 1611 | ath_dbg(ath9k_hw_common(ah), RESET, |
| 1612 | "MAC Hang signature not found at DCU complete\n"); |
| 1613 | return false; |
| 1614 | } |
| 1615 | |
| 1616 | chain_state = REG_READ(ah, dcs_reg); |
| 1617 | if (ath9k_hw_check_dcs(chain_state, num_state, &hang_state, &hang_pos)) |
| 1618 | goto hang_check_iter; |
| 1619 | |
| 1620 | dcs_reg = AR_DMADBG_5; |
| 1621 | num_state = 4; |
| 1622 | chain_state = REG_READ(ah, dcs_reg); |
| 1623 | if (ath9k_hw_check_dcs(chain_state, num_state, &hang_state, &hang_pos)) |
| 1624 | goto hang_check_iter; |
| 1625 | |
| 1626 | ath_dbg(ath9k_hw_common(ah), RESET, |
| 1627 | "MAC Hang signature 1 not found\n"); |
| 1628 | return false; |
| 1629 | |
| 1630 | hang_check_iter: |
| 1631 | ath_dbg(ath9k_hw_common(ah), RESET, |
| 1632 | "DCU registers: chain %08x complete %08x Hang: state %d pos %d\n", |
| 1633 | chain_state, comp_state, hang_state, hang_pos); |
| 1634 | |
| 1635 | for (i = 0; i < NUM_STATUS_READS; i++) { |
| 1636 | chain_state = REG_READ(ah, dcs_reg); |
| 1637 | chain_state = (chain_state >> (5 * hang_pos)) & 0x1f; |
| 1638 | comp_state = REG_READ(ah, AR_DMADBG_6); |
| 1639 | |
| 1640 | if (((comp_state & DCU_COMPLETE_STATE_MASK) != |
| 1641 | DCU_COMPLETE_STATE) || |
| 1642 | (chain_state != hang_state)) |
| 1643 | return false; |
| 1644 | } |
| 1645 | |
| 1646 | ath_dbg(ath9k_hw_common(ah), RESET, "MAC Hang signature 1 found\n"); |
| 1647 | |
| 1648 | return true; |
| 1649 | } |
| 1650 | |
Felix Fietkau | c9c99e5 | 2010-04-19 19:57:29 +0200 | [diff] [blame] | 1651 | bool ath9k_hw_check_alive(struct ath_hw *ah) |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1652 | { |
Felix Fietkau | c9c99e5 | 2010-04-19 19:57:29 +0200 | [diff] [blame] | 1653 | int count = 50; |
| 1654 | u32 reg; |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1655 | |
Rajkumar Manoharan | 01e1891 | 2012-03-15 05:34:27 +0530 | [diff] [blame] | 1656 | if (AR_SREV_9300(ah)) |
| 1657 | return !ath9k_hw_detect_mac_hang(ah); |
| 1658 | |
Felix Fietkau | e17f83e | 2010-09-22 12:34:53 +0200 | [diff] [blame] | 1659 | if (AR_SREV_9285_12_OR_LATER(ah)) |
Felix Fietkau | c9c99e5 | 2010-04-19 19:57:29 +0200 | [diff] [blame] | 1660 | return true; |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1661 | |
Felix Fietkau | c9c99e5 | 2010-04-19 19:57:29 +0200 | [diff] [blame] | 1662 | do { |
| 1663 | reg = REG_READ(ah, AR_OBS_BUS_1); |
| 1664 | |
| 1665 | if ((reg & 0x7E7FFFEF) == 0x00702400) |
| 1666 | continue; |
| 1667 | |
| 1668 | switch (reg & 0x7E000B00) { |
| 1669 | case 0x1E000000: |
| 1670 | case 0x52000B00: |
| 1671 | case 0x18000B00: |
| 1672 | continue; |
| 1673 | default: |
| 1674 | return true; |
| 1675 | } |
| 1676 | } while (count-- > 0); |
| 1677 | |
| 1678 | return false; |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1679 | } |
Felix Fietkau | c9c99e5 | 2010-04-19 19:57:29 +0200 | [diff] [blame] | 1680 | EXPORT_SYMBOL(ath9k_hw_check_alive); |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1681 | |
Sujith Manoharan | caed657 | 2012-03-14 14:40:46 +0530 | [diff] [blame] | 1682 | /* |
| 1683 | * Fast channel change: |
| 1684 | * (Change synthesizer based on channel freq without resetting chip) |
| 1685 | * |
| 1686 | * Don't do FCC when |
| 1687 | * - Flag is not set |
| 1688 | * - Chip is just coming out of full sleep |
| 1689 | * - Channel to be set is same as current channel |
| 1690 | * - Channel flags are different, (eg.,moving from 2GHz to 5GHz channel) |
| 1691 | */ |
| 1692 | static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan) |
| 1693 | { |
| 1694 | struct ath_common *common = ath9k_hw_common(ah); |
| 1695 | int ret; |
| 1696 | |
| 1697 | if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI) |
| 1698 | goto fail; |
| 1699 | |
| 1700 | if (ah->chip_fullsleep) |
| 1701 | goto fail; |
| 1702 | |
| 1703 | if (!ah->curchan) |
| 1704 | goto fail; |
| 1705 | |
| 1706 | if (chan->channel == ah->curchan->channel) |
| 1707 | goto fail; |
| 1708 | |
Felix Fietkau | feb7bc9 | 2012-04-19 21:18:28 +0200 | [diff] [blame] | 1709 | if ((ah->curchan->channelFlags | chan->channelFlags) & |
| 1710 | (CHANNEL_HALF | CHANNEL_QUARTER)) |
| 1711 | goto fail; |
| 1712 | |
Sujith Manoharan | caed657 | 2012-03-14 14:40:46 +0530 | [diff] [blame] | 1713 | if ((chan->channelFlags & CHANNEL_ALL) != |
| 1714 | (ah->curchan->channelFlags & CHANNEL_ALL)) |
| 1715 | goto fail; |
| 1716 | |
| 1717 | if (!ath9k_hw_check_alive(ah)) |
| 1718 | goto fail; |
| 1719 | |
| 1720 | /* |
| 1721 | * For AR9462, make sure that calibration data for |
| 1722 | * re-using are present. |
| 1723 | */ |
Sujith Manoharan | 8a90555 | 2012-05-04 13:23:59 +0530 | [diff] [blame] | 1724 | if (AR_SREV_9462(ah) && (ah->caldata && |
| 1725 | (!ah->caldata->done_txiqcal_once || |
| 1726 | !ah->caldata->done_txclcal_once || |
| 1727 | !ah->caldata->rtt_done))) |
Sujith Manoharan | caed657 | 2012-03-14 14:40:46 +0530 | [diff] [blame] | 1728 | goto fail; |
| 1729 | |
| 1730 | ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n", |
| 1731 | ah->curchan->channel, chan->channel); |
| 1732 | |
| 1733 | ret = ath9k_hw_channel_change(ah, chan); |
| 1734 | if (!ret) |
| 1735 | goto fail; |
| 1736 | |
Sujith Manoharan | 5955b2b | 2012-06-04 16:27:30 +0530 | [diff] [blame] | 1737 | if (ath9k_hw_mci_is_enabled(ah)) |
Rajkumar Manoharan | 1bde95fa | 2012-06-11 12:19:33 +0530 | [diff] [blame] | 1738 | ar9003_mci_2g5g_switch(ah, false); |
Sujith Manoharan | caed657 | 2012-03-14 14:40:46 +0530 | [diff] [blame] | 1739 | |
Rajkumar Manoharan | 8803331 | 2012-09-12 18:59:19 +0530 | [diff] [blame] | 1740 | ath9k_hw_loadnf(ah, ah->curchan); |
| 1741 | ath9k_hw_start_nfcal(ah, true); |
| 1742 | |
Sujith Manoharan | caed657 | 2012-03-14 14:40:46 +0530 | [diff] [blame] | 1743 | if (AR_SREV_9271(ah)) |
| 1744 | ar9002_hw_load_ani_reg(ah, chan); |
| 1745 | |
| 1746 | return 0; |
| 1747 | fail: |
| 1748 | return -EINVAL; |
| 1749 | } |
| 1750 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1751 | int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, |
Sujith Manoharan | caed657 | 2012-03-14 14:40:46 +0530 | [diff] [blame] | 1752 | struct ath9k_hw_cal_data *caldata, bool fastcc) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1753 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1754 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1755 | u32 saveLedState; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1756 | u32 saveDefAntenna; |
| 1757 | u32 macStaId1; |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 1758 | u64 tsf = 0; |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1759 | int i, r; |
Sujith Manoharan | caed657 | 2012-03-14 14:40:46 +0530 | [diff] [blame] | 1760 | bool start_mci_reset = false; |
Mohammed Shafi Shajakhan | 63d3296 | 2011-11-30 10:41:27 +0530 | [diff] [blame] | 1761 | bool save_fullsleep = ah->chip_fullsleep; |
| 1762 | |
Sujith Manoharan | 5955b2b | 2012-06-04 16:27:30 +0530 | [diff] [blame] | 1763 | if (ath9k_hw_mci_is_enabled(ah)) { |
Sujith Manoharan | 528e5d3 | 2012-02-22 12:41:12 +0530 | [diff] [blame] | 1764 | start_mci_reset = ar9003_mci_start_reset(ah, chan); |
| 1765 | if (start_mci_reset) |
| 1766 | return 0; |
Mohammed Shafi Shajakhan | 63d3296 | 2011-11-30 10:41:27 +0530 | [diff] [blame] | 1767 | } |
| 1768 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1769 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1770 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1771 | |
Sujith Manoharan | caed657 | 2012-03-14 14:40:46 +0530 | [diff] [blame] | 1772 | if (ah->curchan && !ah->chip_fullsleep) |
| 1773 | ath9k_hw_getnf(ah, ah->curchan); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1774 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 1775 | ah->caldata = caldata; |
| 1776 | if (caldata && |
| 1777 | (chan->channel != caldata->channel || |
| 1778 | (chan->channelFlags & ~CHANNEL_CW_INT) != |
| 1779 | (caldata->channelFlags & ~CHANNEL_CW_INT))) { |
| 1780 | /* Operating channel changed, reset channel calibration data */ |
| 1781 | memset(caldata, 0, sizeof(*caldata)); |
| 1782 | ath9k_init_nfcal_hist_buffer(ah, chan); |
Felix Fietkau | 51dea9b | 2012-08-27 17:00:07 +0200 | [diff] [blame] | 1783 | } else if (caldata) { |
| 1784 | caldata->paprd_packet_sent = false; |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 1785 | } |
Felix Fietkau | f23fba4 | 2011-07-28 14:08:56 +0200 | [diff] [blame] | 1786 | ah->noise = ath9k_hw_getchan_noise(ah, chan); |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 1787 | |
Sujith Manoharan | caed657 | 2012-03-14 14:40:46 +0530 | [diff] [blame] | 1788 | if (fastcc) { |
| 1789 | r = ath9k_hw_do_fastcc(ah, chan); |
| 1790 | if (!r) |
| 1791 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
Sujith Manoharan | 5955b2b | 2012-06-04 16:27:30 +0530 | [diff] [blame] | 1794 | if (ath9k_hw_mci_is_enabled(ah)) |
Sujith Manoharan | 528e5d3 | 2012-02-22 12:41:12 +0530 | [diff] [blame] | 1795 | ar9003_mci_stop_bt(ah, save_fullsleep); |
Mohammed Shafi Shajakhan | 63d3296 | 2011-11-30 10:41:27 +0530 | [diff] [blame] | 1796 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1797 | saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA); |
| 1798 | if (saveDefAntenna == 0) |
| 1799 | saveDefAntenna = 1; |
| 1800 | |
| 1801 | macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B; |
| 1802 | |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 1803 | /* For chips on which RTC reset is done, save TSF before it gets cleared */ |
Felix Fietkau | f860d52 | 2010-06-30 02:07:48 +0200 | [diff] [blame] | 1804 | if (AR_SREV_9100(ah) || |
| 1805 | (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))) |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 1806 | tsf = ath9k_hw_gettsf64(ah); |
| 1807 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1808 | saveLedState = REG_READ(ah, AR_CFG_LED) & |
| 1809 | (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL | |
| 1810 | AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW); |
| 1811 | |
| 1812 | ath9k_hw_mark_phy_inactive(ah); |
| 1813 | |
Vasanthakumar Thiagarajan | 45ef6a0 | 2010-12-15 07:30:53 -0800 | [diff] [blame] | 1814 | ah->paprd_table_write_done = false; |
| 1815 | |
Sujith | 05020d2 | 2010-03-17 14:25:23 +0530 | [diff] [blame] | 1816 | /* Only required on the first reset */ |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1817 | if (AR_SREV_9271(ah) && ah->htc_reset_init) { |
| 1818 | REG_WRITE(ah, |
| 1819 | AR9271_RESET_POWER_DOWN_CONTROL, |
| 1820 | AR9271_RADIO_RF_RST); |
| 1821 | udelay(50); |
| 1822 | } |
| 1823 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1824 | if (!ath9k_hw_chip_reset(ah, chan)) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1825 | ath_err(common, "Chip reset failed\n"); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1826 | return -EINVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
Sujith | 05020d2 | 2010-03-17 14:25:23 +0530 | [diff] [blame] | 1829 | /* Only required on the first reset */ |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1830 | if (AR_SREV_9271(ah) && ah->htc_reset_init) { |
| 1831 | ah->htc_reset_init = false; |
| 1832 | REG_WRITE(ah, |
| 1833 | AR9271_RESET_POWER_DOWN_CONTROL, |
| 1834 | AR9271_GATE_MAC_CTL); |
| 1835 | udelay(50); |
| 1836 | } |
| 1837 | |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 1838 | /* Restore TSF */ |
Felix Fietkau | f860d52 | 2010-06-30 02:07:48 +0200 | [diff] [blame] | 1839 | if (tsf) |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 1840 | ath9k_hw_settsf64(ah, tsf); |
| 1841 | |
Felix Fietkau | 7a37081 | 2010-09-22 12:34:52 +0200 | [diff] [blame] | 1842 | if (AR_SREV_9280_20_OR_LATER(ah)) |
Vasanthakumar Thiagarajan | 369391d | 2009-01-21 19:24:13 +0530 | [diff] [blame] | 1843 | REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1844 | |
Sujith | e9141f7 | 2010-06-01 15:14:10 +0530 | [diff] [blame] | 1845 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 1846 | ar9002_hw_enable_async_fifo(ah); |
| 1847 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 1848 | r = ath9k_hw_process_ini(ah, chan); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1849 | if (r) |
| 1850 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1851 | |
Sujith Manoharan | 5955b2b | 2012-06-04 16:27:30 +0530 | [diff] [blame] | 1852 | if (ath9k_hw_mci_is_enabled(ah)) |
Mohammed Shafi Shajakhan | 63d3296 | 2011-11-30 10:41:27 +0530 | [diff] [blame] | 1853 | ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep); |
| 1854 | |
Felix Fietkau | f860d52 | 2010-06-30 02:07:48 +0200 | [diff] [blame] | 1855 | /* |
| 1856 | * Some AR91xx SoC devices frequently fail to accept TSF writes |
| 1857 | * right after the chip reset. When that happens, write a new |
| 1858 | * value after the initvals have been applied, with an offset |
| 1859 | * based on measured time difference |
| 1860 | */ |
| 1861 | if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) { |
| 1862 | tsf += 1500; |
| 1863 | ath9k_hw_settsf64(ah, tsf); |
| 1864 | } |
| 1865 | |
Jouni Malinen | 0ced0e1 | 2009-01-08 13:32:13 +0200 | [diff] [blame] | 1866 | /* Setup MFP options for CCMP */ |
| 1867 | if (AR_SREV_9280_20_OR_LATER(ah)) { |
| 1868 | /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt |
| 1869 | * frames when constructing CCMP AAD. */ |
| 1870 | REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT, |
| 1871 | 0xc7ff); |
| 1872 | ah->sw_mgmt_crypto = false; |
| 1873 | } else if (AR_SREV_9160_10_OR_LATER(ah)) { |
| 1874 | /* Disable hardware crypto for management frames */ |
| 1875 | REG_CLR_BIT(ah, AR_PCU_MISC_MODE2, |
| 1876 | AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE); |
| 1877 | REG_SET_BIT(ah, AR_PCU_MISC_MODE2, |
| 1878 | AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT); |
| 1879 | ah->sw_mgmt_crypto = true; |
| 1880 | } else |
| 1881 | ah->sw_mgmt_crypto = true; |
| 1882 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1883 | if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) |
| 1884 | ath9k_hw_set_delta_slope(ah, chan); |
| 1885 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1886 | ath9k_hw_spur_mitigate_freq(ah, chan); |
Sujith | d650915 | 2009-03-13 08:56:05 +0530 | [diff] [blame] | 1887 | ah->eep_ops->set_board_values(ah, chan); |
Luis R. Rodriguez | a776582 | 2009-10-19 02:33:45 -0400 | [diff] [blame] | 1888 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1889 | ENABLE_REGWRITE_BUFFER(ah); |
| 1890 | |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1891 | REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr)); |
| 1892 | REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1893 | | macStaId1 |
| 1894 | | AR_STA_ID1_RTS_USE_DEF |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1895 | | (ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 1896 | ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1897 | | ah->sta_id1_defaults); |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 1898 | ath_hw_setbssidmask(common); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1899 | REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna); |
Luis R. Rodriguez | 3453ad8 | 2009-09-10 08:57:00 -0700 | [diff] [blame] | 1900 | ath9k_hw_write_associd(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1901 | REG_WRITE(ah, AR_ISR, ~0); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1902 | REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR); |
| 1903 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1904 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1905 | |
Sujith Manoharan | 00e0003 | 2011-01-26 21:59:05 +0530 | [diff] [blame] | 1906 | ath9k_hw_set_operating_mode(ah, ah->opmode); |
| 1907 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1908 | r = ath9k_hw_rf_set_freq(ah, chan); |
Luis R. Rodriguez | 0a3b7ba | 2009-10-19 02:33:40 -0400 | [diff] [blame] | 1909 | if (r) |
| 1910 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1911 | |
Felix Fietkau | dfdac8a | 2010-10-08 22:13:51 +0200 | [diff] [blame] | 1912 | ath9k_hw_set_clockrate(ah); |
| 1913 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1914 | ENABLE_REGWRITE_BUFFER(ah); |
| 1915 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1916 | for (i = 0; i < AR_NUM_DCU; i++) |
| 1917 | REG_WRITE(ah, AR_DQCUMASK(i), 1 << i); |
| 1918 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1919 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1920 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1921 | ah->intr_txqs = 0; |
Felix Fietkau | f4c607d | 2011-03-23 20:57:28 +0100 | [diff] [blame] | 1922 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1923 | ath9k_hw_resettxqueue(ah, i); |
| 1924 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1925 | ath9k_hw_init_interrupt_masks(ah, ah->opmode); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1926 | ath9k_hw_ani_cache_ini_regs(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1927 | ath9k_hw_init_qos(ah); |
| 1928 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1929 | if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
Felix Fietkau | 5582132 | 2010-12-17 00:57:01 +0100 | [diff] [blame] | 1930 | ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio); |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 1931 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1932 | ath9k_hw_init_global_settings(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1933 | |
Felix Fietkau | fe2b6af | 2011-07-09 11:12:51 +0700 | [diff] [blame] | 1934 | if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) { |
| 1935 | REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER, |
| 1936 | AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768); |
| 1937 | REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN, |
| 1938 | AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL); |
| 1939 | REG_SET_BIT(ah, AR_PCU_MISC_MODE2, |
| 1940 | AR_PCU_MISC_MODE2_ENABLE_AGGWEP); |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 1941 | } |
| 1942 | |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 1943 | REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1944 | |
| 1945 | ath9k_hw_set_dma(ah); |
| 1946 | |
Rajkumar Manoharan | ed6ebd8 | 2012-06-11 12:19:34 +0530 | [diff] [blame] | 1947 | if (!ath9k_hw_mci_is_enabled(ah)) |
| 1948 | REG_WRITE(ah, AR_OBS, 8); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1949 | |
Sujith | 0ce024c | 2009-12-14 14:57:00 +0530 | [diff] [blame] | 1950 | if (ah->config.rx_intr_mitigation) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1951 | REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500); |
| 1952 | REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000); |
| 1953 | } |
| 1954 | |
Vasanthakumar Thiagarajan | 7f62a13 | 2010-04-15 17:39:19 -0400 | [diff] [blame] | 1955 | if (ah->config.tx_intr_mitigation) { |
| 1956 | REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300); |
| 1957 | REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750); |
| 1958 | } |
| 1959 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1960 | ath9k_hw_init_bb(ah, chan); |
| 1961 | |
Rajkumar Manoharan | 77a5a66 | 2011-10-13 11:00:37 +0530 | [diff] [blame] | 1962 | if (caldata) { |
Rajkumar Manoharan | 5f0c04e | 2011-10-13 11:00:35 +0530 | [diff] [blame] | 1963 | caldata->done_txiqcal_once = false; |
Rajkumar Manoharan | 77a5a66 | 2011-10-13 11:00:37 +0530 | [diff] [blame] | 1964 | caldata->done_txclcal_once = false; |
| 1965 | } |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 1966 | if (!ath9k_hw_init_cal(ah, chan)) |
Joe Perches | 6badaaf | 2009-06-28 09:26:32 -0700 | [diff] [blame] | 1967 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1968 | |
Sujith Manoharan | 5955b2b | 2012-06-04 16:27:30 +0530 | [diff] [blame] | 1969 | if (ath9k_hw_mci_is_enabled(ah) && ar9003_mci_end_reset(ah, chan, caldata)) |
Sujith Manoharan | 528e5d3 | 2012-02-22 12:41:12 +0530 | [diff] [blame] | 1970 | return -EIO; |
Mohammed Shafi Shajakhan | 63d3296 | 2011-11-30 10:41:27 +0530 | [diff] [blame] | 1971 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1972 | ENABLE_REGWRITE_BUFFER(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1973 | |
Luis R. Rodriguez | 8fe6536 | 2010-04-15 17:38:14 -0400 | [diff] [blame] | 1974 | ath9k_hw_restore_chainmask(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1975 | REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ); |
| 1976 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1977 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 1978 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1979 | /* |
| 1980 | * For big endian systems turn on swapping for descriptors |
| 1981 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1982 | if (AR_SREV_9100(ah)) { |
| 1983 | u32 mask; |
| 1984 | mask = REG_READ(ah, AR_CFG); |
| 1985 | if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1986 | ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n", |
| 1987 | mask); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1988 | } else { |
| 1989 | mask = |
| 1990 | INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB; |
| 1991 | REG_WRITE(ah, AR_CFG, mask); |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1992 | ath_dbg(common, RESET, "Setting CFG 0x%x\n", |
| 1993 | REG_READ(ah, AR_CFG)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1994 | } |
| 1995 | } else { |
Sujith | cbba8cd | 2010-06-02 15:53:31 +0530 | [diff] [blame] | 1996 | if (common->bus_ops->ath_bus_type == ATH_USB) { |
| 1997 | /* Configure AR9271 target WLAN */ |
| 1998 | if (AR_SREV_9271(ah)) |
| 1999 | REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB); |
| 2000 | else |
| 2001 | REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD); |
| 2002 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2003 | #ifdef __BIG_ENDIAN |
Gabor Juhos | 2f8d10fd | 2012-07-03 19:13:21 +0200 | [diff] [blame] | 2004 | else if (AR_SREV_9330(ah) || AR_SREV_9340(ah) || |
| 2005 | AR_SREV_9550(ah)) |
Vasanthakumar Thiagarajan | 2be7bfe | 2011-04-19 19:29:14 +0530 | [diff] [blame] | 2006 | REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0); |
| 2007 | else |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2008 | REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2009 | #endif |
| 2010 | } |
| 2011 | |
Sujith Manoharan | dbccdd1 | 2012-02-22 17:55:47 +0530 | [diff] [blame] | 2012 | if (ath9k_hw_btcoex_is_enabled(ah)) |
Vasanthakumar Thiagarajan | 42cc41e | 2009-08-26 21:08:45 +0530 | [diff] [blame] | 2013 | ath9k_hw_btcoex_enable(ah); |
| 2014 | |
Sujith Manoharan | 5955b2b | 2012-06-04 16:27:30 +0530 | [diff] [blame] | 2015 | if (ath9k_hw_mci_is_enabled(ah)) |
Sujith Manoharan | 528e5d3 | 2012-02-22 12:41:12 +0530 | [diff] [blame] | 2016 | ar9003_mci_check_bt(ah); |
Mohammed Shafi Shajakhan | 63d3296 | 2011-11-30 10:41:27 +0530 | [diff] [blame] | 2017 | |
Rajkumar Manoharan | 1fe860e | 2012-07-01 19:53:51 +0530 | [diff] [blame] | 2018 | ath9k_hw_loadnf(ah, chan); |
| 2019 | ath9k_hw_start_nfcal(ah, true); |
| 2020 | |
Rajkumar Manoharan | 51ac8cb | 2011-05-20 17:52:13 +0530 | [diff] [blame] | 2021 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
Luis R. Rodriguez | aea702b | 2010-05-13 13:33:43 -0400 | [diff] [blame] | 2022 | ar9003_hw_bb_watchdog_config(ah); |
Vasanthakumar Thiagarajan | d8903a5 | 2010-04-15 17:39:25 -0400 | [diff] [blame] | 2023 | |
Rajkumar Manoharan | 51ac8cb | 2011-05-20 17:52:13 +0530 | [diff] [blame] | 2024 | ar9003_hw_disable_phy_restart(ah); |
| 2025 | } |
| 2026 | |
Felix Fietkau | 691680b | 2011-03-19 13:55:38 +0100 | [diff] [blame] | 2027 | ath9k_hw_apply_gpio_override(ah); |
| 2028 | |
Sujith Manoharan | 362cd03 | 2012-09-16 08:06:36 +0530 | [diff] [blame] | 2029 | if (AR_SREV_9565(ah) && ah->shared_chain_lnadiv) |
| 2030 | REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON); |
| 2031 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2032 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2033 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2034 | EXPORT_SYMBOL(ath9k_hw_reset); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2035 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2036 | /******************************/ |
| 2037 | /* Power Management (Chipset) */ |
| 2038 | /******************************/ |
| 2039 | |
Luis R. Rodriguez | 42d5bc3 | 2010-04-15 17:38:12 -0400 | [diff] [blame] | 2040 | /* |
| 2041 | * Notify Power Mgt is disabled in self-generated frames. |
| 2042 | * If requested, force chip to sleep. |
| 2043 | */ |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2044 | static void ath9k_set_power_sleep(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2045 | { |
| 2046 | REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
Senthil Balasubramanian | 2577c6e | 2011-09-13 22:38:18 +0530 | [diff] [blame] | 2047 | |
Sujith Manoharan | a4a2954 | 2012-09-10 09:20:03 +0530 | [diff] [blame] | 2048 | if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) { |
Rajkumar Manoharan | 153dccd | 2012-06-04 16:28:47 +0530 | [diff] [blame] | 2049 | REG_CLR_BIT(ah, AR_TIMER_MODE, 0xff); |
| 2050 | REG_CLR_BIT(ah, AR_NDP2_TIMER_MODE, 0xff); |
| 2051 | REG_CLR_BIT(ah, AR_SLP32_INC, 0xfffff); |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2052 | /* xxx Required for WLAN only case ? */ |
| 2053 | REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0); |
| 2054 | udelay(100); |
| 2055 | } |
Senthil Balasubramanian | 2577c6e | 2011-09-13 22:38:18 +0530 | [diff] [blame] | 2056 | |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2057 | /* |
| 2058 | * Clear the RTC force wake bit to allow the |
| 2059 | * mac to go to sleep. |
| 2060 | */ |
| 2061 | REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN); |
Senthil Balasubramanian | 2577c6e | 2011-09-13 22:38:18 +0530 | [diff] [blame] | 2062 | |
Rajkumar Manoharan | 153dccd | 2012-06-04 16:28:47 +0530 | [diff] [blame] | 2063 | if (ath9k_hw_mci_is_enabled(ah)) |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2064 | udelay(100); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2065 | |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2066 | if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah)) |
| 2067 | REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF); |
| 2068 | |
| 2069 | /* Shutdown chip. Active low */ |
| 2070 | if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) { |
| 2071 | REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN); |
| 2072 | udelay(2); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2073 | } |
Luis R. Rodriguez | 9a658d2 | 2010-06-21 18:38:47 -0400 | [diff] [blame] | 2074 | |
| 2075 | /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */ |
Rafael J. Wysocki | a732281 | 2011-11-26 23:37:43 +0100 | [diff] [blame] | 2076 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 2077 | REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
Luis R. Rodriguez | bbd79af | 2010-04-15 17:38:16 -0400 | [diff] [blame] | 2080 | /* |
| 2081 | * Notify Power Management is enabled in self-generating |
| 2082 | * frames. If request, set power mode of chip to |
| 2083 | * auto/normal. Duration in units of 128us (1/8 TU). |
| 2084 | */ |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2085 | static void ath9k_set_power_network_sleep(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2086 | { |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2087 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Senthil Balasubramanian | 2577c6e | 2011-09-13 22:38:18 +0530 | [diff] [blame] | 2088 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2089 | REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2090 | |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2091 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
| 2092 | /* Set WakeOnInterrupt bit; clear ForceWake bit */ |
| 2093 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, |
| 2094 | AR_RTC_FORCE_WAKE_ON_INT); |
| 2095 | } else { |
Senthil Balasubramanian | 2577c6e | 2011-09-13 22:38:18 +0530 | [diff] [blame] | 2096 | |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2097 | /* When chip goes into network sleep, it could be waken |
| 2098 | * up by MCI_INT interrupt caused by BT's HW messages |
| 2099 | * (LNA_xxx, CONT_xxx) which chould be in a very fast |
| 2100 | * rate (~100us). This will cause chip to leave and |
| 2101 | * re-enter network sleep mode frequently, which in |
| 2102 | * consequence will have WLAN MCI HW to generate lots of |
| 2103 | * SYS_WAKING and SYS_SLEEPING messages which will make |
| 2104 | * BT CPU to busy to process. |
| 2105 | */ |
Rajkumar Manoharan | 153dccd | 2012-06-04 16:28:47 +0530 | [diff] [blame] | 2106 | if (ath9k_hw_mci_is_enabled(ah)) |
| 2107 | REG_CLR_BIT(ah, AR_MCI_INTERRUPT_RX_MSG_EN, |
| 2108 | AR_MCI_INTERRUPT_RX_HW_MSG_MASK); |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2109 | /* |
| 2110 | * Clear the RTC force wake bit to allow the |
| 2111 | * mac to go to sleep. |
| 2112 | */ |
Rajkumar Manoharan | 153dccd | 2012-06-04 16:28:47 +0530 | [diff] [blame] | 2113 | REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN); |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2114 | |
Rajkumar Manoharan | 153dccd | 2012-06-04 16:28:47 +0530 | [diff] [blame] | 2115 | if (ath9k_hw_mci_is_enabled(ah)) |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2116 | udelay(30); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2117 | } |
Luis R. Rodriguez | 9a658d2 | 2010-06-21 18:38:47 -0400 | [diff] [blame] | 2118 | |
| 2119 | /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */ |
| 2120 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 2121 | REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2122 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2123 | |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2124 | static bool ath9k_hw_set_power_awake(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2125 | { |
| 2126 | u32 val; |
| 2127 | int i; |
| 2128 | |
Luis R. Rodriguez | 9a658d2 | 2010-06-21 18:38:47 -0400 | [diff] [blame] | 2129 | /* Set Bits 14 and 17 of AR_WA before powering on the chip. */ |
| 2130 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 2131 | REG_WRITE(ah, AR_WA, ah->WARegVal); |
| 2132 | udelay(10); |
| 2133 | } |
| 2134 | |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2135 | if ((REG_READ(ah, AR_RTC_STATUS) & |
| 2136 | AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) { |
| 2137 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2138 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2139 | } |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2140 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 2141 | ath9k_hw_init_pll(ah, NULL); |
| 2142 | } |
| 2143 | if (AR_SREV_9100(ah)) |
| 2144 | REG_SET_BIT(ah, AR_RTC_RESET, |
| 2145 | AR_RTC_RESET_EN); |
| 2146 | |
| 2147 | REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2148 | AR_RTC_FORCE_WAKE_EN); |
| 2149 | udelay(50); |
| 2150 | |
Rajkumar Manoharan | 9dd9b0d | 2012-06-11 12:19:31 +0530 | [diff] [blame] | 2151 | if (ath9k_hw_mci_is_enabled(ah)) |
| 2152 | ar9003_mci_set_power_awake(ah); |
| 2153 | |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2154 | for (i = POWER_UP_TIME / 50; i > 0; i--) { |
| 2155 | val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M; |
| 2156 | if (val == AR_RTC_STATUS_ON) |
| 2157 | break; |
| 2158 | udelay(50); |
| 2159 | REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2160 | AR_RTC_FORCE_WAKE_EN); |
| 2161 | } |
| 2162 | if (i == 0) { |
| 2163 | ath_err(ath9k_hw_common(ah), |
| 2164 | "Failed to wakeup in %uus\n", |
| 2165 | POWER_UP_TIME / 20); |
| 2166 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2169 | REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 2170 | |
| 2171 | return true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 2174 | bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2175 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2176 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2177 | int status = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2178 | static const char *modes[] = { |
| 2179 | "AWAKE", |
| 2180 | "FULL-SLEEP", |
| 2181 | "NETWORK SLEEP", |
| 2182 | "UNDEFINED" |
| 2183 | }; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2184 | |
Gabor Juhos | cbdec97 | 2009-07-24 17:27:22 +0200 | [diff] [blame] | 2185 | if (ah->power_mode == mode) |
| 2186 | return status; |
| 2187 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 2188 | ath_dbg(common, RESET, "%s -> %s\n", |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 2189 | modes[ah->power_mode], modes[mode]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2190 | |
| 2191 | switch (mode) { |
| 2192 | case ATH9K_PM_AWAKE: |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2193 | status = ath9k_hw_set_power_awake(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2194 | break; |
| 2195 | case ATH9K_PM_FULL_SLEEP: |
Sujith Manoharan | 5955b2b | 2012-06-04 16:27:30 +0530 | [diff] [blame] | 2196 | if (ath9k_hw_mci_is_enabled(ah)) |
Sujith Manoharan | d1ca8b8 | 2012-02-22 12:41:01 +0530 | [diff] [blame] | 2197 | ar9003_mci_set_full_sleep(ah); |
Mohammed Shafi Shajakhan | 1010911 | 2011-11-30 10:41:24 +0530 | [diff] [blame] | 2198 | |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2199 | ath9k_set_power_sleep(ah); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2200 | ah->chip_fullsleep = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2201 | break; |
| 2202 | case ATH9K_PM_NETWORK_SLEEP: |
Sujith Manoharan | 31604cf | 2012-06-04 16:27:36 +0530 | [diff] [blame] | 2203 | ath9k_set_power_network_sleep(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2204 | break; |
| 2205 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 2206 | ath_err(common, "Unknown power mode %u\n", mode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2207 | return false; |
| 2208 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2209 | ah->power_mode = mode; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2210 | |
Luis R. Rodriguez | 69f4aab | 2010-12-07 15:13:23 -0800 | [diff] [blame] | 2211 | /* |
| 2212 | * XXX: If this warning never comes up after a while then |
| 2213 | * simply keep the ATH_DBG_WARN_ON_ONCE() but make |
| 2214 | * ath9k_hw_setpower() return type void. |
| 2215 | */ |
Sujith Manoharan | 97dcec5 | 2010-12-20 08:02:42 +0530 | [diff] [blame] | 2216 | |
| 2217 | if (!(ah->ah_flags & AH_UNPLUGGED)) |
| 2218 | ATH_DBG_WARN_ON_ONCE(!status); |
Luis R. Rodriguez | 69f4aab | 2010-12-07 15:13:23 -0800 | [diff] [blame] | 2219 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2220 | return status; |
| 2221 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2222 | EXPORT_SYMBOL(ath9k_hw_setpower); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2223 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2224 | /*******************/ |
| 2225 | /* Beacon Handling */ |
| 2226 | /*******************/ |
| 2227 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2228 | void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2229 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2230 | int flags = 0; |
| 2231 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2232 | ENABLE_REGWRITE_BUFFER(ah); |
| 2233 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2234 | switch (ah->opmode) { |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 2235 | case NL80211_IFTYPE_ADHOC: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 2236 | case NL80211_IFTYPE_MESH_POINT: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2237 | REG_SET_BIT(ah, AR_TXCFG, |
| 2238 | AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY); |
Felix Fietkau | dd347f2 | 2011-03-22 21:54:17 +0100 | [diff] [blame] | 2239 | REG_WRITE(ah, AR_NEXT_NDP_TIMER, next_beacon + |
| 2240 | TU_TO_USEC(ah->atim_window ? ah->atim_window : 1)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2241 | flags |= AR_NDP_TIMER_EN; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 2242 | case NL80211_IFTYPE_AP: |
Felix Fietkau | dd347f2 | 2011-03-22 21:54:17 +0100 | [diff] [blame] | 2243 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon); |
| 2244 | REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon - |
| 2245 | TU_TO_USEC(ah->config.dma_beacon_response_time)); |
| 2246 | REG_WRITE(ah, AR_NEXT_SWBA, next_beacon - |
| 2247 | TU_TO_USEC(ah->config.sw_beacon_response_time)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2248 | flags |= |
| 2249 | AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN; |
| 2250 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 2251 | default: |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 2252 | ath_dbg(ath9k_hw_common(ah), BEACON, |
| 2253 | "%s: unsupported opmode: %d\n", __func__, ah->opmode); |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 2254 | return; |
| 2255 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
Felix Fietkau | dd347f2 | 2011-03-22 21:54:17 +0100 | [diff] [blame] | 2258 | REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period); |
| 2259 | REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period); |
| 2260 | REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period); |
| 2261 | REG_WRITE(ah, AR_NDP_PERIOD, beacon_period); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2262 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2263 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2264 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2265 | REG_SET_BIT(ah, AR_TIMER_MODE, flags); |
| 2266 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2267 | EXPORT_SYMBOL(ath9k_hw_beaconinit); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2268 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2269 | void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2270 | const struct ath9k_beacon_state *bs) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2271 | { |
| 2272 | u32 nextTbtt, beaconintval, dtimperiod, beacontimeout; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2273 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2274 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2275 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2276 | ENABLE_REGWRITE_BUFFER(ah); |
| 2277 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2278 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt)); |
| 2279 | |
| 2280 | REG_WRITE(ah, AR_BEACON_PERIOD, |
Rajkumar Manoharan | f29f5c0 | 2011-05-20 17:52:11 +0530 | [diff] [blame] | 2281 | TU_TO_USEC(bs->bs_intval)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2282 | REG_WRITE(ah, AR_DMA_BEACON_PERIOD, |
Rajkumar Manoharan | f29f5c0 | 2011-05-20 17:52:11 +0530 | [diff] [blame] | 2283 | TU_TO_USEC(bs->bs_intval)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2284 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2285 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2286 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2287 | REG_RMW_FIELD(ah, AR_RSSI_THR, |
| 2288 | AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold); |
| 2289 | |
Rajkumar Manoharan | f29f5c0 | 2011-05-20 17:52:11 +0530 | [diff] [blame] | 2290 | beaconintval = bs->bs_intval; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2291 | |
| 2292 | if (bs->bs_sleepduration > beaconintval) |
| 2293 | beaconintval = bs->bs_sleepduration; |
| 2294 | |
| 2295 | dtimperiod = bs->bs_dtimperiod; |
| 2296 | if (bs->bs_sleepduration > dtimperiod) |
| 2297 | dtimperiod = bs->bs_sleepduration; |
| 2298 | |
| 2299 | if (beaconintval == dtimperiod) |
| 2300 | nextTbtt = bs->bs_nextdtim; |
| 2301 | else |
| 2302 | nextTbtt = bs->bs_nexttbtt; |
| 2303 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 2304 | ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim); |
| 2305 | ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt); |
| 2306 | ath_dbg(common, BEACON, "beacon period %d\n", beaconintval); |
| 2307 | ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2308 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2309 | ENABLE_REGWRITE_BUFFER(ah); |
| 2310 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2311 | REG_WRITE(ah, AR_NEXT_DTIM, |
| 2312 | TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP)); |
| 2313 | REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP)); |
| 2314 | |
| 2315 | REG_WRITE(ah, AR_SLEEP1, |
| 2316 | SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT) |
| 2317 | | AR_SLEEP1_ASSUME_DTIM); |
| 2318 | |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 2319 | if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2320 | beacontimeout = (BEACON_TIMEOUT_VAL << 3); |
| 2321 | else |
| 2322 | beacontimeout = MIN_BEACON_TIMEOUT_VAL; |
| 2323 | |
| 2324 | REG_WRITE(ah, AR_SLEEP2, |
| 2325 | SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT)); |
| 2326 | |
| 2327 | REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval)); |
| 2328 | REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod)); |
| 2329 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2330 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2331 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2332 | REG_SET_BIT(ah, AR_TIMER_MODE, |
| 2333 | AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN | |
| 2334 | AR_DTIM_TIMER_EN); |
| 2335 | |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 2336 | /* TSF Out of Range Threshold */ |
| 2337 | REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2338 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2339 | EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2340 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2341 | /*******************/ |
| 2342 | /* HW Capabilities */ |
| 2343 | /*******************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2344 | |
Felix Fietkau | 6054069 | 2011-07-19 08:46:44 +0200 | [diff] [blame] | 2345 | static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask) |
| 2346 | { |
| 2347 | eeprom_chainmask &= chip_chainmask; |
| 2348 | if (eeprom_chainmask) |
| 2349 | return eeprom_chainmask; |
| 2350 | else |
| 2351 | return chip_chainmask; |
| 2352 | } |
| 2353 | |
Zefir Kurtisi | 9a66af3 | 2011-12-14 20:16:33 -0800 | [diff] [blame] | 2354 | /** |
| 2355 | * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset |
| 2356 | * @ah: the atheros hardware data structure |
| 2357 | * |
| 2358 | * We enable DFS support upstream on chipsets which have passed a series |
| 2359 | * of tests. The testing requirements are going to be documented. Desired |
| 2360 | * test requirements are documented at: |
| 2361 | * |
| 2362 | * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs |
| 2363 | * |
| 2364 | * Once a new chipset gets properly tested an individual commit can be used |
| 2365 | * to document the testing for DFS for that chipset. |
| 2366 | */ |
| 2367 | static bool ath9k_hw_dfs_tested(struct ath_hw *ah) |
| 2368 | { |
| 2369 | |
| 2370 | switch (ah->hw_version.macVersion) { |
| 2371 | /* AR9580 will likely be our first target to get testing on */ |
| 2372 | case AR_SREV_VERSION_9580: |
| 2373 | default: |
| 2374 | return false; |
| 2375 | } |
| 2376 | } |
| 2377 | |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 2378 | int ath9k_hw_fill_cap_info(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2379 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2380 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2381 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2382 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 6054069 | 2011-07-19 08:46:44 +0200 | [diff] [blame] | 2383 | unsigned int chip_chainmask; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2384 | |
Sujith Manoharan | 0ff2b5c | 2011-04-20 11:00:34 +0530 | [diff] [blame] | 2385 | u16 eeval; |
Vasanthakumar Thiagarajan | 47c80de | 2010-12-06 04:27:43 -0800 | [diff] [blame] | 2386 | u8 ant_div_ctl1, tx_chainmask, rx_chainmask; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2387 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2388 | eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0); |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2389 | regulatory->current_rd = eeval; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2390 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2391 | if (ah->opmode != NL80211_IFTYPE_AP && |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 2392 | ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 2393 | if (regulatory->current_rd == 0x64 || |
| 2394 | regulatory->current_rd == 0x65) |
| 2395 | regulatory->current_rd += 5; |
| 2396 | else if (regulatory->current_rd == 0x41) |
| 2397 | regulatory->current_rd = 0x43; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 2398 | ath_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n", |
| 2399 | regulatory->current_rd); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2400 | } |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 2401 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2402 | eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE); |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 2403 | if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 2404 | ath_err(common, |
| 2405 | "no band has been marked as supported in EEPROM\n"); |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 2406 | return -EINVAL; |
| 2407 | } |
| 2408 | |
Felix Fietkau | d465991 | 2010-10-14 16:02:39 +0200 | [diff] [blame] | 2409 | if (eeval & AR5416_OPFLAGS_11A) |
| 2410 | pCap->hw_caps |= ATH9K_HW_CAP_5GHZ; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2411 | |
Felix Fietkau | d465991 | 2010-10-14 16:02:39 +0200 | [diff] [blame] | 2412 | if (eeval & AR5416_OPFLAGS_11G) |
| 2413 | pCap->hw_caps |= ATH9K_HW_CAP_2GHZ; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2414 | |
Sujith Manoharan | e41db61 | 2012-09-10 09:20:12 +0530 | [diff] [blame] | 2415 | if (AR_SREV_9485(ah) || |
| 2416 | AR_SREV_9285(ah) || |
| 2417 | AR_SREV_9330(ah) || |
| 2418 | AR_SREV_9565(ah)) |
Felix Fietkau | 6054069 | 2011-07-19 08:46:44 +0200 | [diff] [blame] | 2419 | chip_chainmask = 1; |
Mohammed Shafi Shajakhan | ba5736a | 2011-11-30 21:10:52 +0530 | [diff] [blame] | 2420 | else if (AR_SREV_9462(ah)) |
| 2421 | chip_chainmask = 3; |
Felix Fietkau | 6054069 | 2011-07-19 08:46:44 +0200 | [diff] [blame] | 2422 | else if (!AR_SREV_9280_20_OR_LATER(ah)) |
| 2423 | chip_chainmask = 7; |
| 2424 | else if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9340(ah)) |
| 2425 | chip_chainmask = 3; |
| 2426 | else |
| 2427 | chip_chainmask = 7; |
| 2428 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2429 | pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK); |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2430 | /* |
| 2431 | * For AR9271 we will temporarilly uses the rx chainmax as read from |
| 2432 | * the EEPROM. |
| 2433 | */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 2434 | if ((ah->hw_version.devid == AR5416_DEVID_PCI) && |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2435 | !(eeval & AR5416_OPFLAGS_11A) && |
| 2436 | !(AR_SREV_9271(ah))) |
| 2437 | /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 2438 | pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7; |
Felix Fietkau | 598cdd5 | 2011-03-19 13:55:42 +0100 | [diff] [blame] | 2439 | else if (AR_SREV_9100(ah)) |
| 2440 | pCap->rx_chainmask = 0x7; |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 2441 | else |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2442 | /* Use rx_chainmask from EEPROM. */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 2443 | pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2444 | |
Felix Fietkau | 6054069 | 2011-07-19 08:46:44 +0200 | [diff] [blame] | 2445 | pCap->tx_chainmask = fixup_chainmask(chip_chainmask, pCap->tx_chainmask); |
| 2446 | pCap->rx_chainmask = fixup_chainmask(chip_chainmask, pCap->rx_chainmask); |
Felix Fietkau | 82b2d33 | 2011-09-03 01:40:23 +0200 | [diff] [blame] | 2447 | ah->txchainmask = pCap->tx_chainmask; |
| 2448 | ah->rxchainmask = pCap->rx_chainmask; |
Felix Fietkau | 6054069 | 2011-07-19 08:46:44 +0200 | [diff] [blame] | 2449 | |
Felix Fietkau | 7a37081 | 2010-09-22 12:34:52 +0200 | [diff] [blame] | 2450 | ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2451 | |
Felix Fietkau | 02d2ebb | 2010-11-22 15:39:39 +0100 | [diff] [blame] | 2452 | /* enable key search for every frame in an aggregate */ |
| 2453 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 2454 | ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH; |
| 2455 | |
Bruno Randolf | ce2220d | 2010-09-17 11:36:25 +0900 | [diff] [blame] | 2456 | common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM; |
| 2457 | |
Felix Fietkau | 0db156e | 2011-03-23 20:57:29 +0100 | [diff] [blame] | 2458 | if (ah->hw_version.devid != AR2427_DEVID_PCIE) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2459 | pCap->hw_caps |= ATH9K_HW_CAP_HT; |
| 2460 | else |
| 2461 | pCap->hw_caps &= ~ATH9K_HW_CAP_HT; |
| 2462 | |
Sujith | 5b5fa35 | 2010-03-17 14:25:15 +0530 | [diff] [blame] | 2463 | if (AR_SREV_9271(ah)) |
| 2464 | pCap->num_gpio_pins = AR9271_NUM_GPIO; |
Sujith | 88c1f4f | 2010-06-30 14:46:31 +0530 | [diff] [blame] | 2465 | else if (AR_DEVID_7010(ah)) |
| 2466 | pCap->num_gpio_pins = AR7010_NUM_GPIO; |
Mohammed Shafi Shajakhan | 6321eb0 | 2011-09-30 11:31:27 +0530 | [diff] [blame] | 2467 | else if (AR_SREV_9300_20_OR_LATER(ah)) |
| 2468 | pCap->num_gpio_pins = AR9300_NUM_GPIO; |
| 2469 | else if (AR_SREV_9287_11_OR_LATER(ah)) |
| 2470 | pCap->num_gpio_pins = AR9287_NUM_GPIO; |
Felix Fietkau | e17f83e | 2010-09-22 12:34:53 +0200 | [diff] [blame] | 2471 | else if (AR_SREV_9285_12_OR_LATER(ah)) |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 2472 | pCap->num_gpio_pins = AR9285_NUM_GPIO; |
Felix Fietkau | 7a37081 | 2010-09-22 12:34:52 +0200 | [diff] [blame] | 2473 | else if (AR_SREV_9280_20_OR_LATER(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2474 | pCap->num_gpio_pins = AR928X_NUM_GPIO; |
| 2475 | else |
| 2476 | pCap->num_gpio_pins = AR_NUM_GPIO; |
| 2477 | |
Mohammed Shafi Shajakhan | 1b2538b | 2011-12-07 16:51:39 +0530 | [diff] [blame] | 2478 | if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2479 | pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX; |
Mohammed Shafi Shajakhan | 1b2538b | 2011-12-07 16:51:39 +0530 | [diff] [blame] | 2480 | else |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2481 | pCap->rts_aggr_limit = (8 * 1024); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2482 | |
Senthil Balasubramanian | e97275c | 2008-11-13 18:00:02 +0530 | [diff] [blame] | 2483 | #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2484 | ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT); |
| 2485 | if (ah->rfsilent & EEP_RFSILENT_ENABLED) { |
| 2486 | ah->rfkill_gpio = |
| 2487 | MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL); |
| 2488 | ah->rfkill_polarity = |
| 2489 | MS(ah->rfsilent, EEP_RFSILENT_POLARITY); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2490 | |
| 2491 | pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT; |
| 2492 | } |
| 2493 | #endif |
Vasanthakumar Thiagarajan | d5d1154 | 2010-05-17 18:57:56 -0700 | [diff] [blame] | 2494 | if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah)) |
Vivek Natarajan | bde748a | 2010-04-05 14:48:05 +0530 | [diff] [blame] | 2495 | pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP; |
| 2496 | else |
| 2497 | pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2498 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 2499 | if (AR_SREV_9280(ah) || AR_SREV_9285(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2500 | pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS; |
| 2501 | else |
| 2502 | pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS; |
| 2503 | |
Vasanthakumar Thiagarajan | ceb2644 | 2010-04-15 17:38:25 -0400 | [diff] [blame] | 2504 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
Vasanthakumar Thiagarajan | 784ad50 | 2010-12-06 04:27:40 -0800 | [diff] [blame] | 2505 | pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK; |
Sujith Manoharan | a4a2954 | 2012-09-10 09:20:03 +0530 | [diff] [blame] | 2506 | if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah) && !AR_SREV_9565(ah)) |
Vasanthakumar Thiagarajan | 784ad50 | 2010-12-06 04:27:40 -0800 | [diff] [blame] | 2507 | pCap->hw_caps |= ATH9K_HW_CAP_LDPC; |
| 2508 | |
Vasanthakumar Thiagarajan | ceb2644 | 2010-04-15 17:38:25 -0400 | [diff] [blame] | 2509 | pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH; |
| 2510 | pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH; |
| 2511 | pCap->rx_status_len = sizeof(struct ar9003_rxs); |
Vasanthakumar Thiagarajan | 162c3be | 2010-04-15 17:38:41 -0400 | [diff] [blame] | 2512 | pCap->tx_desc_len = sizeof(struct ar9003_txc); |
Vasanthakumar Thiagarajan | 5088c2f | 2010-04-15 17:39:34 -0400 | [diff] [blame] | 2513 | pCap->txs_len = sizeof(struct ar9003_txs); |
Vasanthakumar Thiagarajan | 162c3be | 2010-04-15 17:38:41 -0400 | [diff] [blame] | 2514 | } else { |
| 2515 | pCap->tx_desc_len = sizeof(struct ath_desc); |
Felix Fietkau | a949b17 | 2011-07-09 11:12:47 +0700 | [diff] [blame] | 2516 | if (AR_SREV_9280_20(ah)) |
Felix Fietkau | 6b42e8d | 2010-04-26 15:04:35 -0400 | [diff] [blame] | 2517 | pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK; |
Vasanthakumar Thiagarajan | ceb2644 | 2010-04-15 17:38:25 -0400 | [diff] [blame] | 2518 | } |
Vasanthakumar Thiagarajan | 1adf02f | 2010-04-15 17:38:24 -0400 | [diff] [blame] | 2519 | |
Vasanthakumar Thiagarajan | 6c84ce0 | 2010-04-15 17:39:16 -0400 | [diff] [blame] | 2520 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 2521 | pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED; |
| 2522 | |
Senthil Balasubramanian | 6ee63f5 | 2010-11-10 05:03:16 -0800 | [diff] [blame] | 2523 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 2524 | ah->ent_mode = REG_READ(ah, AR_ENT_OTP); |
| 2525 | |
Felix Fietkau | a42acef | 2010-09-22 12:34:54 +0200 | [diff] [blame] | 2526 | if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah)) |
Vasanthakumar Thiagarajan | 6473d24 | 2010-05-13 18:42:38 -0700 | [diff] [blame] | 2527 | pCap->hw_caps |= ATH9K_HW_CAP_SGI_20; |
| 2528 | |
Vasanthakumar Thiagarajan | 754dc53 | 2010-09-02 01:34:41 -0700 | [diff] [blame] | 2529 | if (AR_SREV_9285(ah)) |
| 2530 | if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) { |
| 2531 | ant_div_ctl1 = |
| 2532 | ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1); |
| 2533 | if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1)) |
| 2534 | pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB; |
| 2535 | } |
Mohammed Shafi Shajakhan | ea066d5 | 2010-11-23 20:42:27 +0530 | [diff] [blame] | 2536 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 2537 | if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE)) |
| 2538 | pCap->hw_caps |= ATH9K_HW_CAP_APM; |
| 2539 | } |
| 2540 | |
| 2541 | |
Sujith Manoharan | 06236e5 | 2012-09-16 08:07:12 +0530 | [diff] [blame] | 2542 | if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) { |
Mohammed Shafi Shajakhan | 21d2c63 | 2011-05-13 20:29:31 +0530 | [diff] [blame] | 2543 | ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1); |
| 2544 | /* |
| 2545 | * enable the diversity-combining algorithm only when |
| 2546 | * both enable_lna_div and enable_fast_div are set |
| 2547 | * Table for Diversity |
| 2548 | * ant_div_alt_lnaconf bit 0-1 |
| 2549 | * ant_div_main_lnaconf bit 2-3 |
| 2550 | * ant_div_alt_gaintb bit 4 |
| 2551 | * ant_div_main_gaintb bit 5 |
| 2552 | * enable_ant_div_lnadiv bit 6 |
| 2553 | * enable_ant_fast_div bit 7 |
| 2554 | */ |
| 2555 | if ((ant_div_ctl1 >> 0x6) == 0x3) |
| 2556 | pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB; |
| 2557 | } |
Vasanthakumar Thiagarajan | 754dc53 | 2010-09-02 01:34:41 -0700 | [diff] [blame] | 2558 | |
Vasanthakumar Thiagarajan | 8060e16 | 2010-12-06 04:27:42 -0800 | [diff] [blame] | 2559 | if (AR_SREV_9485_10(ah)) { |
| 2560 | pCap->pcie_lcr_extsync_en = true; |
| 2561 | pCap->pcie_lcr_offset = 0x80; |
| 2562 | } |
| 2563 | |
Zefir Kurtisi | 9a66af3 | 2011-12-14 20:16:33 -0800 | [diff] [blame] | 2564 | if (ath9k_hw_dfs_tested(ah)) |
| 2565 | pCap->hw_caps |= ATH9K_HW_CAP_DFS; |
| 2566 | |
Vasanthakumar Thiagarajan | 47c80de | 2010-12-06 04:27:43 -0800 | [diff] [blame] | 2567 | tx_chainmask = pCap->tx_chainmask; |
| 2568 | rx_chainmask = pCap->rx_chainmask; |
| 2569 | while (tx_chainmask || rx_chainmask) { |
| 2570 | if (tx_chainmask & BIT(0)) |
| 2571 | pCap->max_txchains++; |
| 2572 | if (rx_chainmask & BIT(0)) |
| 2573 | pCap->max_rxchains++; |
| 2574 | |
| 2575 | tx_chainmask >>= 1; |
| 2576 | rx_chainmask >>= 1; |
| 2577 | } |
| 2578 | |
Rajkumar Manoharan | 8ad74c4 | 2011-10-13 11:00:38 +0530 | [diff] [blame] | 2579 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 2580 | ah->enabled_cals |= TX_IQ_CAL; |
Mohammed Shafi Shajakhan | 6fea593 | 2011-11-30 21:01:31 +0530 | [diff] [blame] | 2581 | if (AR_SREV_9485_OR_LATER(ah)) |
Rajkumar Manoharan | 8ad74c4 | 2011-10-13 11:00:38 +0530 | [diff] [blame] | 2582 | ah->enabled_cals |= TX_IQ_ON_AGC_CAL; |
| 2583 | } |
Mohammed Shafi Shajakhan | 3789d59 | 2012-03-09 12:01:55 +0530 | [diff] [blame] | 2584 | |
Sujith Manoharan | a4a2954 | 2012-09-10 09:20:03 +0530 | [diff] [blame] | 2585 | if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) { |
Mohammed Shafi Shajakhan | 3789d59 | 2012-03-09 12:01:55 +0530 | [diff] [blame] | 2586 | if (!(ah->ent_mode & AR_ENT_OTP_49GHZ_DISABLE)) |
| 2587 | pCap->hw_caps |= ATH9K_HW_CAP_MCI; |
| 2588 | |
| 2589 | if (AR_SREV_9462_20(ah)) |
| 2590 | pCap->hw_caps |= ATH9K_HW_CAP_RTT; |
Mohammed Shafi Shajakhan | 3789d59 | 2012-03-09 12:01:55 +0530 | [diff] [blame] | 2591 | } |
| 2592 | |
Rajkumar Manoharan | 324c74a | 2011-10-13 11:00:41 +0530 | [diff] [blame] | 2593 | |
Mohammed Shafi Shajakhan | d687809 | 2012-07-10 14:55:17 +0530 | [diff] [blame] | 2594 | if (AR_SREV_9280_20_OR_LATER(ah)) { |
| 2595 | pCap->hw_caps |= ATH9K_HW_WOW_DEVICE_CAPABLE | |
| 2596 | ATH9K_HW_WOW_PATTERN_MATCH_EXACT; |
| 2597 | |
| 2598 | if (AR_SREV_9280(ah)) |
| 2599 | pCap->hw_caps |= ATH9K_HW_WOW_PATTERN_MATCH_DWORD; |
| 2600 | } |
| 2601 | |
Gabor Juhos | a9a29ce | 2009-11-27 12:01:35 +0100 | [diff] [blame] | 2602 | return 0; |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 2603 | } |
| 2604 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2605 | /****************************/ |
| 2606 | /* GPIO / RFKILL / Antennae */ |
| 2607 | /****************************/ |
| 2608 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2609 | static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2610 | u32 gpio, u32 type) |
| 2611 | { |
| 2612 | int addr; |
| 2613 | u32 gpio_shift, tmp; |
| 2614 | |
| 2615 | if (gpio > 11) |
| 2616 | addr = AR_GPIO_OUTPUT_MUX3; |
| 2617 | else if (gpio > 5) |
| 2618 | addr = AR_GPIO_OUTPUT_MUX2; |
| 2619 | else |
| 2620 | addr = AR_GPIO_OUTPUT_MUX1; |
| 2621 | |
| 2622 | gpio_shift = (gpio % 6) * 5; |
| 2623 | |
| 2624 | if (AR_SREV_9280_20_OR_LATER(ah) |
| 2625 | || (addr != AR_GPIO_OUTPUT_MUX1)) { |
| 2626 | REG_RMW(ah, addr, (type << gpio_shift), |
| 2627 | (0x1f << gpio_shift)); |
| 2628 | } else { |
| 2629 | tmp = REG_READ(ah, addr); |
| 2630 | tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0); |
| 2631 | tmp &= ~(0x1f << gpio_shift); |
| 2632 | tmp |= (type << gpio_shift); |
| 2633 | REG_WRITE(ah, addr, tmp); |
| 2634 | } |
| 2635 | } |
| 2636 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2637 | void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2638 | { |
| 2639 | u32 gpio_shift; |
| 2640 | |
Luis R. Rodriguez | 9680e8a | 2009-09-13 23:28:00 -0700 | [diff] [blame] | 2641 | BUG_ON(gpio >= ah->caps.num_gpio_pins); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2642 | |
Sujith | 88c1f4f | 2010-06-30 14:46:31 +0530 | [diff] [blame] | 2643 | if (AR_DEVID_7010(ah)) { |
| 2644 | gpio_shift = gpio; |
| 2645 | REG_RMW(ah, AR7010_GPIO_OE, |
| 2646 | (AR7010_GPIO_OE_AS_INPUT << gpio_shift), |
| 2647 | (AR7010_GPIO_OE_MASK << gpio_shift)); |
| 2648 | return; |
| 2649 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2650 | |
Sujith | 88c1f4f | 2010-06-30 14:46:31 +0530 | [diff] [blame] | 2651 | gpio_shift = gpio << 1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2652 | REG_RMW(ah, |
| 2653 | AR_GPIO_OE_OUT, |
| 2654 | (AR_GPIO_OE_OUT_DRV_NO << gpio_shift), |
| 2655 | (AR_GPIO_OE_OUT_DRV << gpio_shift)); |
| 2656 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2657 | EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2658 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2659 | u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2660 | { |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 2661 | #define MS_REG_READ(x, y) \ |
| 2662 | (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y))) |
| 2663 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2664 | if (gpio >= ah->caps.num_gpio_pins) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2665 | return 0xffffffff; |
| 2666 | |
Sujith | 88c1f4f | 2010-06-30 14:46:31 +0530 | [diff] [blame] | 2667 | if (AR_DEVID_7010(ah)) { |
| 2668 | u32 val; |
| 2669 | val = REG_READ(ah, AR7010_GPIO_IN); |
| 2670 | return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0; |
| 2671 | } else if (AR_SREV_9300_20_OR_LATER(ah)) |
Vasanthakumar Thiagarajan | 9306990 | 2010-11-30 23:24:09 -0800 | [diff] [blame] | 2672 | return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) & |
| 2673 | AR_GPIO_BIT(gpio)) != 0; |
Felix Fietkau | 783dfca | 2010-04-15 17:38:11 -0400 | [diff] [blame] | 2674 | else if (AR_SREV_9271(ah)) |
Sujith | 5b5fa35 | 2010-03-17 14:25:15 +0530 | [diff] [blame] | 2675 | return MS_REG_READ(AR9271, gpio) != 0; |
Felix Fietkau | a42acef | 2010-09-22 12:34:54 +0200 | [diff] [blame] | 2676 | else if (AR_SREV_9287_11_OR_LATER(ah)) |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2677 | return MS_REG_READ(AR9287, gpio) != 0; |
Felix Fietkau | e17f83e | 2010-09-22 12:34:53 +0200 | [diff] [blame] | 2678 | else if (AR_SREV_9285_12_OR_LATER(ah)) |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 2679 | return MS_REG_READ(AR9285, gpio) != 0; |
Felix Fietkau | 7a37081 | 2010-09-22 12:34:52 +0200 | [diff] [blame] | 2680 | else if (AR_SREV_9280_20_OR_LATER(ah)) |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 2681 | return MS_REG_READ(AR928X, gpio) != 0; |
| 2682 | else |
| 2683 | return MS_REG_READ(AR, gpio) != 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2684 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2685 | EXPORT_SYMBOL(ath9k_hw_gpio_get); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2686 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2687 | void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2688 | u32 ah_signal_type) |
| 2689 | { |
| 2690 | u32 gpio_shift; |
| 2691 | |
Sujith | 88c1f4f | 2010-06-30 14:46:31 +0530 | [diff] [blame] | 2692 | if (AR_DEVID_7010(ah)) { |
| 2693 | gpio_shift = gpio; |
| 2694 | REG_RMW(ah, AR7010_GPIO_OE, |
| 2695 | (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift), |
| 2696 | (AR7010_GPIO_OE_MASK << gpio_shift)); |
| 2697 | return; |
| 2698 | } |
| 2699 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2700 | ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2701 | gpio_shift = 2 * gpio; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2702 | REG_RMW(ah, |
| 2703 | AR_GPIO_OE_OUT, |
| 2704 | (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift), |
| 2705 | (AR_GPIO_OE_OUT_DRV << gpio_shift)); |
| 2706 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2707 | EXPORT_SYMBOL(ath9k_hw_cfg_output); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2708 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2709 | void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2710 | { |
Sujith | 88c1f4f | 2010-06-30 14:46:31 +0530 | [diff] [blame] | 2711 | if (AR_DEVID_7010(ah)) { |
| 2712 | val = val ? 0 : 1; |
| 2713 | REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio), |
| 2714 | AR_GPIO_BIT(gpio)); |
| 2715 | return; |
| 2716 | } |
| 2717 | |
Sujith | 5b5fa35 | 2010-03-17 14:25:15 +0530 | [diff] [blame] | 2718 | if (AR_SREV_9271(ah)) |
| 2719 | val = ~val; |
| 2720 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2721 | REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio), |
| 2722 | AR_GPIO_BIT(gpio)); |
| 2723 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2724 | EXPORT_SYMBOL(ath9k_hw_set_gpio); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2725 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2726 | void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2727 | { |
| 2728 | REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7)); |
| 2729 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2730 | EXPORT_SYMBOL(ath9k_hw_setantenna); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2731 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2732 | /*********************/ |
| 2733 | /* General Operation */ |
| 2734 | /*********************/ |
| 2735 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2736 | u32 ath9k_hw_getrxfilter(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2737 | { |
| 2738 | u32 bits = REG_READ(ah, AR_RX_FILTER); |
| 2739 | u32 phybits = REG_READ(ah, AR_PHY_ERR); |
| 2740 | |
| 2741 | if (phybits & AR_PHY_ERR_RADAR) |
| 2742 | bits |= ATH9K_RX_FILTER_PHYRADAR; |
| 2743 | if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING)) |
| 2744 | bits |= ATH9K_RX_FILTER_PHYERR; |
| 2745 | |
| 2746 | return bits; |
| 2747 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2748 | EXPORT_SYMBOL(ath9k_hw_getrxfilter); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2749 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2750 | void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2751 | { |
| 2752 | u32 phybits; |
| 2753 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2754 | ENABLE_REGWRITE_BUFFER(ah); |
| 2755 | |
Sujith Manoharan | a4a2954 | 2012-09-10 09:20:03 +0530 | [diff] [blame] | 2756 | if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) |
Senthil Balasubramanian | 2577c6e | 2011-09-13 22:38:18 +0530 | [diff] [blame] | 2757 | bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER; |
| 2758 | |
Sujith | 7ea310b | 2009-09-03 12:08:43 +0530 | [diff] [blame] | 2759 | REG_WRITE(ah, AR_RX_FILTER, bits); |
| 2760 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2761 | phybits = 0; |
| 2762 | if (bits & ATH9K_RX_FILTER_PHYRADAR) |
| 2763 | phybits |= AR_PHY_ERR_RADAR; |
| 2764 | if (bits & ATH9K_RX_FILTER_PHYERR) |
| 2765 | phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING; |
| 2766 | REG_WRITE(ah, AR_PHY_ERR, phybits); |
| 2767 | |
| 2768 | if (phybits) |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 2769 | REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2770 | else |
Felix Fietkau | ca7a4de | 2011-03-23 20:57:26 +0100 | [diff] [blame] | 2771 | REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 2772 | |
| 2773 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2774 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2775 | EXPORT_SYMBOL(ath9k_hw_setrxfilter); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2776 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2777 | bool ath9k_hw_phy_disable(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2778 | { |
Rajkumar Manoharan | 99922a4 | 2012-06-04 16:28:31 +0530 | [diff] [blame] | 2779 | if (ath9k_hw_mci_is_enabled(ah)) |
| 2780 | ar9003_mci_bt_gain_ctrl(ah); |
| 2781 | |
Senthil Balasubramanian | 63a75b9 | 2009-09-18 15:07:03 +0530 | [diff] [blame] | 2782 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM)) |
| 2783 | return false; |
| 2784 | |
| 2785 | ath9k_hw_init_pll(ah, NULL); |
Felix Fietkau | 8efa7a8 | 2012-03-14 16:40:23 +0100 | [diff] [blame] | 2786 | ah->htc_reset_init = true; |
Senthil Balasubramanian | 63a75b9 | 2009-09-18 15:07:03 +0530 | [diff] [blame] | 2787 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2788 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2789 | EXPORT_SYMBOL(ath9k_hw_phy_disable); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2790 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2791 | bool ath9k_hw_disable(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2792 | { |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 2793 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2794 | return false; |
| 2795 | |
Senthil Balasubramanian | 63a75b9 | 2009-09-18 15:07:03 +0530 | [diff] [blame] | 2796 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD)) |
| 2797 | return false; |
| 2798 | |
| 2799 | ath9k_hw_init_pll(ah, NULL); |
| 2800 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2801 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2802 | EXPORT_SYMBOL(ath9k_hw_disable); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2803 | |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 2804 | static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2805 | { |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 2806 | enum eeprom_param gain_param; |
Felix Fietkau | 9c204b4 | 2011-07-27 15:01:05 +0200 | [diff] [blame] | 2807 | |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 2808 | if (IS_CHAN_2GHZ(chan)) |
| 2809 | gain_param = EEP_ANTENNA_GAIN_2G; |
| 2810 | else |
| 2811 | gain_param = EEP_ANTENNA_GAIN_5G; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2812 | |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 2813 | return ah->eep_ops->get_eeprom(ah, gain_param); |
| 2814 | } |
| 2815 | |
Gabor Juhos | 64ea57d | 2012-04-15 20:38:05 +0200 | [diff] [blame] | 2816 | void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan, |
| 2817 | bool test) |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 2818 | { |
| 2819 | struct ath_regulatory *reg = ath9k_hw_regulatory(ah); |
| 2820 | struct ieee80211_channel *channel; |
| 2821 | int chan_pwr, new_pwr, max_gain; |
| 2822 | int ant_gain, ant_reduction = 0; |
| 2823 | |
| 2824 | if (!chan) |
| 2825 | return; |
| 2826 | |
| 2827 | channel = chan->chan; |
| 2828 | chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER); |
| 2829 | new_pwr = min_t(int, chan_pwr, reg->power_limit); |
| 2830 | max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2; |
| 2831 | |
| 2832 | ant_gain = get_antenna_gain(ah, chan); |
| 2833 | if (ant_gain > max_gain) |
| 2834 | ant_reduction = ant_gain - max_gain; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2835 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2836 | ah->eep_ops->set_txpower(ah, chan, |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 2837 | ath9k_regd_get_ctl(reg, chan), |
Gabor Juhos | 64ea57d | 2012-04-15 20:38:05 +0200 | [diff] [blame] | 2838 | ant_reduction, new_pwr, test); |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test) |
| 2842 | { |
| 2843 | struct ath_regulatory *reg = ath9k_hw_regulatory(ah); |
| 2844 | struct ath9k_channel *chan = ah->curchan; |
| 2845 | struct ieee80211_channel *channel = chan->chan; |
| 2846 | |
Dan Carpenter | 48ef5c4 | 2011-10-17 10:28:23 +0300 | [diff] [blame] | 2847 | reg->power_limit = min_t(u32, limit, MAX_RATE_POWER); |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 2848 | if (test) |
| 2849 | channel->max_power = MAX_RATE_POWER / 2; |
| 2850 | |
Gabor Juhos | 64ea57d | 2012-04-15 20:38:05 +0200 | [diff] [blame] | 2851 | ath9k_hw_apply_txpower(ah, chan, test); |
Felix Fietkau | ca2c68c | 2011-10-08 20:06:20 +0200 | [diff] [blame] | 2852 | |
| 2853 | if (test) |
| 2854 | channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2855 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2856 | EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2857 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2858 | void ath9k_hw_setopmode(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2859 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2860 | ath9k_hw_set_operating_mode(ah, ah->opmode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2861 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2862 | EXPORT_SYMBOL(ath9k_hw_setopmode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2863 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2864 | void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2865 | { |
| 2866 | REG_WRITE(ah, AR_MCAST_FIL0, filter0); |
| 2867 | REG_WRITE(ah, AR_MCAST_FIL1, filter1); |
| 2868 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2869 | EXPORT_SYMBOL(ath9k_hw_setmcastfilter); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2870 | |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 2871 | void ath9k_hw_write_associd(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2872 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 2873 | struct ath_common *common = ath9k_hw_common(ah); |
| 2874 | |
| 2875 | REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid)); |
| 2876 | REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) | |
| 2877 | ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2878 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2879 | EXPORT_SYMBOL(ath9k_hw_write_associd); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2880 | |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 2881 | #define ATH9K_MAX_TSF_READ 10 |
| 2882 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2883 | u64 ath9k_hw_gettsf64(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2884 | { |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 2885 | u32 tsf_lower, tsf_upper1, tsf_upper2; |
| 2886 | int i; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2887 | |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 2888 | tsf_upper1 = REG_READ(ah, AR_TSF_U32); |
| 2889 | for (i = 0; i < ATH9K_MAX_TSF_READ; i++) { |
| 2890 | tsf_lower = REG_READ(ah, AR_TSF_L32); |
| 2891 | tsf_upper2 = REG_READ(ah, AR_TSF_U32); |
| 2892 | if (tsf_upper2 == tsf_upper1) |
| 2893 | break; |
| 2894 | tsf_upper1 = tsf_upper2; |
| 2895 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2896 | |
Benoit Papillault | 1c0fc65 | 2010-04-16 00:07:26 +0200 | [diff] [blame] | 2897 | WARN_ON( i == ATH9K_MAX_TSF_READ ); |
| 2898 | |
| 2899 | return (((u64)tsf_upper1 << 32) | tsf_lower); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2900 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2901 | EXPORT_SYMBOL(ath9k_hw_gettsf64); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2902 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2903 | void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64) |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 2904 | { |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 2905 | REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff); |
Alina Friedrichsen | b9a1619 | 2009-03-02 23:28:38 +0100 | [diff] [blame] | 2906 | REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff); |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 2907 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2908 | EXPORT_SYMBOL(ath9k_hw_settsf64); |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 2909 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2910 | void ath9k_hw_reset_tsf(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2911 | { |
Gabor Juhos | f9b604f | 2009-06-21 00:02:15 +0200 | [diff] [blame] | 2912 | if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0, |
| 2913 | AH_TSF_WRITE_TIMEOUT)) |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 2914 | ath_dbg(ath9k_hw_common(ah), RESET, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 2915 | "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n"); |
Gabor Juhos | f9b604f | 2009-06-21 00:02:15 +0200 | [diff] [blame] | 2916 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2917 | REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2918 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2919 | EXPORT_SYMBOL(ath9k_hw_reset_tsf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2920 | |
Sujith Manoharan | 60ca9f8 | 2012-07-17 17:15:37 +0530 | [diff] [blame] | 2921 | void ath9k_hw_set_tsfadjust(struct ath_hw *ah, bool set) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2922 | { |
Sujith Manoharan | 60ca9f8 | 2012-07-17 17:15:37 +0530 | [diff] [blame] | 2923 | if (set) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2924 | ah->misc_mode |= AR_PCU_TX_ADD_TSF; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2925 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2926 | ah->misc_mode &= ~AR_PCU_TX_ADD_TSF; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2927 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 2928 | EXPORT_SYMBOL(ath9k_hw_set_tsfadjust); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2929 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 2930 | void ath9k_hw_set11nmac2040(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2931 | { |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 2932 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2933 | u32 macmode; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2934 | |
Luis R. Rodriguez | 25c56ee | 2009-09-13 23:04:44 -0700 | [diff] [blame] | 2935 | if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2936 | macmode = AR_2040_JOINED_RX_CLEAR; |
| 2937 | else |
| 2938 | macmode = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2939 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2940 | REG_WRITE(ah, AR_2040_MODE, macmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2941 | } |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2942 | |
| 2943 | /* HW Generic timers configuration */ |
| 2944 | |
| 2945 | static const struct ath_gen_timer_configuration gen_tmr_configuration[] = |
| 2946 | { |
| 2947 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2948 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2949 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2950 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2951 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2952 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2953 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2954 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 2955 | {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001}, |
| 2956 | {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4, |
| 2957 | AR_NDP2_TIMER_MODE, 0x0002}, |
| 2958 | {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4, |
| 2959 | AR_NDP2_TIMER_MODE, 0x0004}, |
| 2960 | {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4, |
| 2961 | AR_NDP2_TIMER_MODE, 0x0008}, |
| 2962 | {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4, |
| 2963 | AR_NDP2_TIMER_MODE, 0x0010}, |
| 2964 | {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4, |
| 2965 | AR_NDP2_TIMER_MODE, 0x0020}, |
| 2966 | {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4, |
| 2967 | AR_NDP2_TIMER_MODE, 0x0040}, |
| 2968 | {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4, |
| 2969 | AR_NDP2_TIMER_MODE, 0x0080} |
| 2970 | }; |
| 2971 | |
| 2972 | /* HW generic timer primitives */ |
| 2973 | |
| 2974 | /* compute and clear index of rightmost 1 */ |
| 2975 | static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask) |
| 2976 | { |
| 2977 | u32 b; |
| 2978 | |
| 2979 | b = *mask; |
| 2980 | b &= (0-b); |
| 2981 | *mask &= ~b; |
| 2982 | b *= debruijn32; |
| 2983 | b >>= 27; |
| 2984 | |
| 2985 | return timer_table->gen_timer_index[b]; |
| 2986 | } |
| 2987 | |
Felix Fietkau | dd347f2 | 2011-03-22 21:54:17 +0100 | [diff] [blame] | 2988 | u32 ath9k_hw_gettsf32(struct ath_hw *ah) |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2989 | { |
| 2990 | return REG_READ(ah, AR_TSF_L32); |
| 2991 | } |
Felix Fietkau | dd347f2 | 2011-03-22 21:54:17 +0100 | [diff] [blame] | 2992 | EXPORT_SYMBOL(ath9k_hw_gettsf32); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 2993 | |
| 2994 | struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah, |
| 2995 | void (*trigger)(void *), |
| 2996 | void (*overflow)(void *), |
| 2997 | void *arg, |
| 2998 | u8 timer_index) |
| 2999 | { |
| 3000 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 3001 | struct ath_gen_timer *timer; |
| 3002 | |
| 3003 | timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL); |
| 3004 | |
| 3005 | if (timer == NULL) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 3006 | ath_err(ath9k_hw_common(ah), |
| 3007 | "Failed to allocate memory for hw timer[%d]\n", |
| 3008 | timer_index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3009 | return NULL; |
| 3010 | } |
| 3011 | |
| 3012 | /* allocate a hardware generic timer slot */ |
| 3013 | timer_table->timers[timer_index] = timer; |
| 3014 | timer->index = timer_index; |
| 3015 | timer->trigger = trigger; |
| 3016 | timer->overflow = overflow; |
| 3017 | timer->arg = arg; |
| 3018 | |
| 3019 | return timer; |
| 3020 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3021 | EXPORT_SYMBOL(ath_gen_timer_alloc); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3022 | |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 3023 | void ath9k_hw_gen_timer_start(struct ath_hw *ah, |
| 3024 | struct ath_gen_timer *timer, |
Vasanthakumar Thiagarajan | 788f687 | 2011-04-21 18:33:27 +0530 | [diff] [blame] | 3025 | u32 trig_timeout, |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 3026 | u32 timer_period) |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3027 | { |
| 3028 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
Vasanthakumar Thiagarajan | 788f687 | 2011-04-21 18:33:27 +0530 | [diff] [blame] | 3029 | u32 tsf, timer_next; |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3030 | |
| 3031 | BUG_ON(!timer_period); |
| 3032 | |
| 3033 | set_bit(timer->index, &timer_table->timer_mask.timer_bits); |
| 3034 | |
| 3035 | tsf = ath9k_hw_gettsf32(ah); |
| 3036 | |
Vasanthakumar Thiagarajan | 788f687 | 2011-04-21 18:33:27 +0530 | [diff] [blame] | 3037 | timer_next = tsf + trig_timeout; |
| 3038 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 3039 | ath_dbg(ath9k_hw_common(ah), HWTIMER, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 3040 | "current tsf %x period %x timer_next %x\n", |
| 3041 | tsf, timer_period, timer_next); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3042 | |
| 3043 | /* |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3044 | * Program generic timer registers |
| 3045 | */ |
| 3046 | REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr, |
| 3047 | timer_next); |
| 3048 | REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr, |
| 3049 | timer_period); |
| 3050 | REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr, |
| 3051 | gen_tmr_configuration[timer->index].mode_mask); |
| 3052 | |
Sujith Manoharan | a4a2954 | 2012-09-10 09:20:03 +0530 | [diff] [blame] | 3053 | if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) { |
Senthil Balasubramanian | 2577c6e | 2011-09-13 22:38:18 +0530 | [diff] [blame] | 3054 | /* |
Rajkumar Manoharan | 423e38e | 2011-10-13 11:00:44 +0530 | [diff] [blame] | 3055 | * Starting from AR9462, each generic timer can select which tsf |
Senthil Balasubramanian | 2577c6e | 2011-09-13 22:38:18 +0530 | [diff] [blame] | 3056 | * to use. But we still follow the old rule, 0 - 7 use tsf and |
| 3057 | * 8 - 15 use tsf2. |
| 3058 | */ |
| 3059 | if ((timer->index < AR_GEN_TIMER_BANK_1_LEN)) |
| 3060 | REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL, |
| 3061 | (1 << timer->index)); |
| 3062 | else |
| 3063 | REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL, |
| 3064 | (1 << timer->index)); |
| 3065 | } |
| 3066 | |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3067 | /* Enable both trigger and thresh interrupt masks */ |
| 3068 | REG_SET_BIT(ah, AR_IMR_S5, |
| 3069 | (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) | |
| 3070 | SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG))); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3071 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3072 | EXPORT_SYMBOL(ath9k_hw_gen_timer_start); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3073 | |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 3074 | void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer) |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3075 | { |
| 3076 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 3077 | |
| 3078 | if ((timer->index < AR_FIRST_NDP_TIMER) || |
| 3079 | (timer->index >= ATH_MAX_GEN_TIMER)) { |
| 3080 | return; |
| 3081 | } |
| 3082 | |
| 3083 | /* Clear generic timer enable bits. */ |
| 3084 | REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr, |
| 3085 | gen_tmr_configuration[timer->index].mode_mask); |
| 3086 | |
Sujith Manoharan | b7f5976 | 2012-09-11 10:46:24 +0530 | [diff] [blame] | 3087 | if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) { |
| 3088 | /* |
| 3089 | * Need to switch back to TSF if it was using TSF2. |
| 3090 | */ |
| 3091 | if ((timer->index >= AR_GEN_TIMER_BANK_1_LEN)) { |
| 3092 | REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL, |
| 3093 | (1 << timer->index)); |
| 3094 | } |
| 3095 | } |
| 3096 | |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3097 | /* Disable both trigger and thresh interrupt masks */ |
| 3098 | REG_CLR_BIT(ah, AR_IMR_S5, |
| 3099 | (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) | |
| 3100 | SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG))); |
| 3101 | |
| 3102 | clear_bit(timer->index, &timer_table->timer_mask.timer_bits); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3103 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3104 | EXPORT_SYMBOL(ath9k_hw_gen_timer_stop); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3105 | |
| 3106 | void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer) |
| 3107 | { |
| 3108 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 3109 | |
| 3110 | /* free the hardware generic timer slot */ |
| 3111 | timer_table->timers[timer->index] = NULL; |
| 3112 | kfree(timer); |
| 3113 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3114 | EXPORT_SYMBOL(ath_gen_timer_free); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3115 | |
| 3116 | /* |
| 3117 | * Generic Timer Interrupts handling |
| 3118 | */ |
| 3119 | void ath_gen_timer_isr(struct ath_hw *ah) |
| 3120 | { |
| 3121 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 3122 | struct ath_gen_timer *timer; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3123 | struct ath_common *common = ath9k_hw_common(ah); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3124 | u32 trigger_mask, thresh_mask, index; |
| 3125 | |
| 3126 | /* get hardware generic timer interrupt status */ |
| 3127 | trigger_mask = ah->intr_gen_timer_trigger; |
| 3128 | thresh_mask = ah->intr_gen_timer_thresh; |
| 3129 | trigger_mask &= timer_table->timer_mask.val; |
| 3130 | thresh_mask &= timer_table->timer_mask.val; |
| 3131 | |
| 3132 | trigger_mask &= ~thresh_mask; |
| 3133 | |
| 3134 | while (thresh_mask) { |
| 3135 | index = rightmost_index(timer_table, &thresh_mask); |
| 3136 | timer = timer_table->timers[index]; |
| 3137 | BUG_ON(!timer); |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 3138 | ath_dbg(common, HWTIMER, "TSF overflow for Gen timer %d\n", |
| 3139 | index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3140 | timer->overflow(timer->arg); |
| 3141 | } |
| 3142 | |
| 3143 | while (trigger_mask) { |
| 3144 | index = rightmost_index(timer_table, &trigger_mask); |
| 3145 | timer = timer_table->timers[index]; |
| 3146 | BUG_ON(!timer); |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 3147 | ath_dbg(common, HWTIMER, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 3148 | "Gen timer[%d] trigger\n", index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3149 | timer->trigger(timer->arg); |
| 3150 | } |
| 3151 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 3152 | EXPORT_SYMBOL(ath_gen_timer_isr); |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 3153 | |
Sujith | 05020d2 | 2010-03-17 14:25:23 +0530 | [diff] [blame] | 3154 | /********/ |
| 3155 | /* HTC */ |
| 3156 | /********/ |
| 3157 | |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 3158 | static struct { |
| 3159 | u32 version; |
| 3160 | const char * name; |
| 3161 | } ath_mac_bb_names[] = { |
| 3162 | /* Devices with external radios */ |
| 3163 | { AR_SREV_VERSION_5416_PCI, "5416" }, |
| 3164 | { AR_SREV_VERSION_5416_PCIE, "5418" }, |
| 3165 | { AR_SREV_VERSION_9100, "9100" }, |
| 3166 | { AR_SREV_VERSION_9160, "9160" }, |
| 3167 | /* Single-chip solutions */ |
| 3168 | { AR_SREV_VERSION_9280, "9280" }, |
| 3169 | { AR_SREV_VERSION_9285, "9285" }, |
Luis R. Rodriguez | 1115847 | 2009-10-27 12:59:35 -0400 | [diff] [blame] | 3170 | { AR_SREV_VERSION_9287, "9287" }, |
| 3171 | { AR_SREV_VERSION_9271, "9271" }, |
Luis R. Rodriguez | ec83903 | 2010-04-15 17:39:20 -0400 | [diff] [blame] | 3172 | { AR_SREV_VERSION_9300, "9300" }, |
Gabor Juhos | 2c8e593 | 2011-06-21 11:23:21 +0200 | [diff] [blame] | 3173 | { AR_SREV_VERSION_9330, "9330" }, |
Florian Fainelli | 397e5d5 | 2011-08-25 21:33:48 +0200 | [diff] [blame] | 3174 | { AR_SREV_VERSION_9340, "9340" }, |
Senthil Balasubramanian | 8f06ca2 | 2011-04-01 17:16:33 +0530 | [diff] [blame] | 3175 | { AR_SREV_VERSION_9485, "9485" }, |
Rajkumar Manoharan | 423e38e | 2011-10-13 11:00:44 +0530 | [diff] [blame] | 3176 | { AR_SREV_VERSION_9462, "9462" }, |
Gabor Juhos | 485124c | 2012-07-03 19:13:19 +0200 | [diff] [blame] | 3177 | { AR_SREV_VERSION_9550, "9550" }, |
Sujith Manoharan | 77fac46 | 2012-09-11 20:09:18 +0530 | [diff] [blame] | 3178 | { AR_SREV_VERSION_9565, "9565" }, |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 3179 | }; |
| 3180 | |
| 3181 | /* For devices with external radios */ |
| 3182 | static struct { |
| 3183 | u16 version; |
| 3184 | const char * name; |
| 3185 | } ath_rf_names[] = { |
| 3186 | { 0, "5133" }, |
| 3187 | { AR_RAD5133_SREV_MAJOR, "5133" }, |
| 3188 | { AR_RAD5122_SREV_MAJOR, "5122" }, |
| 3189 | { AR_RAD2133_SREV_MAJOR, "2133" }, |
| 3190 | { AR_RAD2122_SREV_MAJOR, "2122" } |
| 3191 | }; |
| 3192 | |
| 3193 | /* |
| 3194 | * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown. |
| 3195 | */ |
Luis R. Rodriguez | f934c4d | 2009-10-27 12:59:34 -0400 | [diff] [blame] | 3196 | static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version) |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 3197 | { |
| 3198 | int i; |
| 3199 | |
| 3200 | for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) { |
| 3201 | if (ath_mac_bb_names[i].version == mac_bb_version) { |
| 3202 | return ath_mac_bb_names[i].name; |
| 3203 | } |
| 3204 | } |
| 3205 | |
| 3206 | return "????"; |
| 3207 | } |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 3208 | |
| 3209 | /* |
| 3210 | * Return the RF name. "????" is returned if the RF is unknown. |
| 3211 | * Used for devices with external radios. |
| 3212 | */ |
Luis R. Rodriguez | f934c4d | 2009-10-27 12:59:34 -0400 | [diff] [blame] | 3213 | static const char *ath9k_hw_rf_name(u16 rf_version) |
Luis R. Rodriguez | 2da4f01 | 2009-10-27 12:59:33 -0400 | [diff] [blame] | 3214 | { |
| 3215 | int i; |
| 3216 | |
| 3217 | for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) { |
| 3218 | if (ath_rf_names[i].version == rf_version) { |
| 3219 | return ath_rf_names[i].name; |
| 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | return "????"; |
| 3224 | } |
Luis R. Rodriguez | f934c4d | 2009-10-27 12:59:34 -0400 | [diff] [blame] | 3225 | |
| 3226 | void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len) |
| 3227 | { |
| 3228 | int used; |
| 3229 | |
| 3230 | /* chipsets >= AR9280 are single-chip */ |
Felix Fietkau | 7a37081 | 2010-09-22 12:34:52 +0200 | [diff] [blame] | 3231 | if (AR_SREV_9280_20_OR_LATER(ah)) { |
Luis R. Rodriguez | f934c4d | 2009-10-27 12:59:34 -0400 | [diff] [blame] | 3232 | used = snprintf(hw_name, len, |
| 3233 | "Atheros AR%s Rev:%x", |
| 3234 | ath9k_hw_mac_bb_name(ah->hw_version.macVersion), |
| 3235 | ah->hw_version.macRev); |
| 3236 | } |
| 3237 | else { |
| 3238 | used = snprintf(hw_name, len, |
| 3239 | "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x", |
| 3240 | ath9k_hw_mac_bb_name(ah->hw_version.macVersion), |
| 3241 | ah->hw_version.macRev, |
| 3242 | ath9k_hw_rf_name((ah->hw_version.analog5GhzRev & |
| 3243 | AR_RADIO_SREV_MAJOR)), |
| 3244 | ah->hw_version.phyRev); |
| 3245 | } |
| 3246 | |
| 3247 | hw_name[used] = '\0'; |
| 3248 | } |
| 3249 | EXPORT_SYMBOL(ath9k_hw_name); |