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