Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Sujith | cee075a | 2009-03-13 09:07:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 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> |
| 18 | #include <asm/unaligned.h> |
| 19 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 20 | #include "hw.h" |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 21 | #include "ath9k.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 22 | #include "initvals.h" |
| 23 | |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 24 | #define ATH9K_CLOCK_RATE_CCK 22 |
| 25 | #define ATH9K_CLOCK_RATE_5GHZ_OFDM 40 |
| 26 | #define ATH9K_CLOCK_RATE_2GHZ_OFDM 44 |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 27 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 28 | static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type); |
| 29 | static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 30 | enum ath9k_ht_macmode macmode); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 31 | static u32 ath9k_hw_ini_fixup(struct ath_hw *ah, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 32 | struct ar5416_eeprom_def *pEepData, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 33 | u32 reg, u32 value); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 34 | static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan); |
| 35 | static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 36 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 37 | /********************/ |
| 38 | /* Helper Functions */ |
| 39 | /********************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 40 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 41 | static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 42 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 43 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 44 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 45 | if (!ah->curchan) /* should really check for CCK instead */ |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 46 | return clks / ATH9K_CLOCK_RATE_CCK; |
| 47 | if (conf->channel->band == IEEE80211_BAND_2GHZ) |
| 48 | return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 49 | |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 50 | return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 51 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 52 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 53 | static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 54 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 55 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 56 | |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 57 | if (conf_is_ht40(conf)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 58 | return ath9k_hw_mac_usec(ah, clks) / 2; |
| 59 | else |
| 60 | return ath9k_hw_mac_usec(ah, clks); |
| 61 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 62 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 63 | static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 64 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 65 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 66 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 67 | if (!ah->curchan) /* should really check for CCK instead */ |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 68 | return usecs *ATH9K_CLOCK_RATE_CCK; |
| 69 | if (conf->channel->band == IEEE80211_BAND_2GHZ) |
| 70 | return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM; |
| 71 | return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 72 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 73 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 74 | static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 75 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 76 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 77 | |
Luis R. Rodriguez | 4febf7b | 2008-12-23 15:58:48 -0800 | [diff] [blame] | 78 | if (conf_is_ht40(conf)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 79 | return ath9k_hw_mac_clks(ah, usecs) * 2; |
| 80 | else |
| 81 | return ath9k_hw_mac_clks(ah, usecs); |
| 82 | } |
| 83 | |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 84 | 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] | 85 | { |
| 86 | int i; |
| 87 | |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 88 | BUG_ON(timeout < AH_TIME_QUANTUM); |
| 89 | |
| 90 | for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 91 | if ((REG_READ(ah, reg) & mask) == val) |
| 92 | return true; |
| 93 | |
| 94 | udelay(AH_TIME_QUANTUM); |
| 95 | } |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 96 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 97 | ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, |
| 98 | "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n", |
| 99 | timeout, reg, REG_READ(ah, reg), mask, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 100 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 101 | return false; |
| 102 | } |
| 103 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 104 | u32 ath9k_hw_reverse_bits(u32 val, u32 n) |
| 105 | { |
| 106 | u32 retval; |
| 107 | int i; |
| 108 | |
| 109 | for (i = 0, retval = 0; i < n; i++) { |
| 110 | retval = (retval << 1) | (val & 1); |
| 111 | val >>= 1; |
| 112 | } |
| 113 | return retval; |
| 114 | } |
| 115 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 116 | bool ath9k_get_channel_edges(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 117 | u16 flags, u16 *low, |
| 118 | u16 *high) |
| 119 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 120 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 121 | |
| 122 | if (flags & CHANNEL_5GHZ) { |
| 123 | *low = pCap->low_5ghz_chan; |
| 124 | *high = pCap->high_5ghz_chan; |
| 125 | return true; |
| 126 | } |
| 127 | if ((flags & CHANNEL_2GHZ)) { |
| 128 | *low = pCap->low_2ghz_chan; |
| 129 | *high = pCap->high_2ghz_chan; |
| 130 | return true; |
| 131 | } |
| 132 | return false; |
| 133 | } |
| 134 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 135 | u16 ath9k_hw_computetxtime(struct ath_hw *ah, |
Luis R. Rodriguez | 4f0fc7c | 2009-05-06 02:20:00 -0400 | [diff] [blame] | 136 | const struct ath_rate_table *rates, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 137 | u32 frameLen, u16 rateix, |
| 138 | bool shortPreamble) |
| 139 | { |
| 140 | u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime; |
| 141 | u32 kbps; |
| 142 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 143 | kbps = rates->info[rateix].ratekbps; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 144 | |
| 145 | if (kbps == 0) |
| 146 | return 0; |
| 147 | |
| 148 | switch (rates->info[rateix].phy) { |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 149 | case WLAN_RC_PHY_CCK: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 150 | phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 151 | if (shortPreamble && rates->info[rateix].short_preamble) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 152 | phyTime >>= 1; |
| 153 | numBits = frameLen << 3; |
| 154 | txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps); |
| 155 | break; |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 156 | case WLAN_RC_PHY_OFDM: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 157 | if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 158 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000; |
| 159 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 160 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 161 | txTime = OFDM_SIFS_TIME_QUARTER |
| 162 | + OFDM_PREAMBLE_TIME_QUARTER |
| 163 | + (numSymbols * OFDM_SYMBOL_TIME_QUARTER); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 164 | } else if (ah->curchan && |
| 165 | IS_CHAN_HALF_RATE(ah->curchan)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 166 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000; |
| 167 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 168 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 169 | txTime = OFDM_SIFS_TIME_HALF + |
| 170 | OFDM_PREAMBLE_TIME_HALF |
| 171 | + (numSymbols * OFDM_SYMBOL_TIME_HALF); |
| 172 | } else { |
| 173 | bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000; |
| 174 | numBits = OFDM_PLCP_BITS + (frameLen << 3); |
| 175 | numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol); |
| 176 | txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME |
| 177 | + (numSymbols * OFDM_SYMBOL_TIME); |
| 178 | } |
| 179 | break; |
| 180 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 181 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 182 | "Unknown phy %u (rate ix %u)\n", |
| 183 | rates->info[rateix].phy, rateix); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 184 | txTime = 0; |
| 185 | break; |
| 186 | } |
| 187 | |
| 188 | return txTime; |
| 189 | } |
| 190 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 191 | void ath9k_hw_get_channel_centers(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 192 | struct ath9k_channel *chan, |
| 193 | struct chan_centers *centers) |
| 194 | { |
| 195 | int8_t extoff; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 196 | |
| 197 | if (!IS_CHAN_HT40(chan)) { |
| 198 | centers->ctl_center = centers->ext_center = |
| 199 | centers->synth_center = chan->channel; |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | if ((chan->chanmode == CHANNEL_A_HT40PLUS) || |
| 204 | (chan->chanmode == CHANNEL_G_HT40PLUS)) { |
| 205 | centers->synth_center = |
| 206 | chan->channel + HT40_CHANNEL_CENTER_SHIFT; |
| 207 | extoff = 1; |
| 208 | } else { |
| 209 | centers->synth_center = |
| 210 | chan->channel - HT40_CHANNEL_CENTER_SHIFT; |
| 211 | extoff = -1; |
| 212 | } |
| 213 | |
| 214 | centers->ctl_center = |
| 215 | centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT); |
Luis R. Rodriguez | 6420014 | 2009-09-13 22:05:04 -0700 | [diff] [blame^] | 216 | /* 25 MHz spacing is supported by hw but not on upper layers */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 217 | centers->ext_center = |
Luis R. Rodriguez | 6420014 | 2009-09-13 22:05:04 -0700 | [diff] [blame^] | 218 | centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /******************/ |
| 222 | /* Chip Revisions */ |
| 223 | /******************/ |
| 224 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 225 | static void ath9k_hw_read_revisions(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 226 | { |
| 227 | u32 val; |
| 228 | |
| 229 | val = REG_READ(ah, AR_SREV) & AR_SREV_ID; |
| 230 | |
| 231 | if (val == 0xFF) { |
| 232 | val = REG_READ(ah, AR_SREV); |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 233 | ah->hw_version.macVersion = |
| 234 | (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S; |
| 235 | ah->hw_version.macRev = MS(val, AR_SREV_REVISION2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 236 | ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 237 | } else { |
| 238 | if (!AR_SREV_9100(ah)) |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 239 | ah->hw_version.macVersion = MS(val, AR_SREV_VERSION); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 240 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 241 | ah->hw_version.macRev = val & AR_SREV_REVISION; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 242 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 243 | if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 244 | ah->is_pciexpress = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 248 | static int ath9k_hw_get_radiorev(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 249 | { |
| 250 | u32 val; |
| 251 | int i; |
| 252 | |
| 253 | REG_WRITE(ah, AR_PHY(0x36), 0x00007058); |
| 254 | |
| 255 | for (i = 0; i < 8; i++) |
| 256 | REG_WRITE(ah, AR_PHY(0x20), 0x00010000); |
| 257 | val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff; |
| 258 | val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4); |
| 259 | |
| 260 | return ath9k_hw_reverse_bits(val, 8); |
| 261 | } |
| 262 | |
| 263 | /************************************/ |
| 264 | /* HW Attach, Detach, Init Routines */ |
| 265 | /************************************/ |
| 266 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 267 | static void ath9k_hw_disablepcie(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 268 | { |
Sujith | feed029 | 2009-01-29 11:37:35 +0530 | [diff] [blame] | 269 | if (AR_SREV_9100(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 270 | return; |
| 271 | |
| 272 | REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00); |
| 273 | REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); |
| 274 | REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029); |
| 275 | REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824); |
| 276 | REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579); |
| 277 | REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000); |
| 278 | REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); |
| 279 | REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); |
| 280 | REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007); |
| 281 | |
| 282 | REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); |
| 283 | } |
| 284 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 285 | static bool ath9k_hw_chip_test(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 286 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 287 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 288 | u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) }; |
| 289 | u32 regHold[2]; |
| 290 | u32 patternData[4] = { 0x55555555, |
| 291 | 0xaaaaaaaa, |
| 292 | 0x66666666, |
| 293 | 0x99999999 }; |
| 294 | int i, j; |
| 295 | |
| 296 | for (i = 0; i < 2; i++) { |
| 297 | u32 addr = regAddr[i]; |
| 298 | u32 wrData, rdData; |
| 299 | |
| 300 | regHold[i] = REG_READ(ah, addr); |
| 301 | for (j = 0; j < 0x100; j++) { |
| 302 | wrData = (j << 16) | j; |
| 303 | REG_WRITE(ah, addr, wrData); |
| 304 | rdData = REG_READ(ah, addr); |
| 305 | if (rdData != wrData) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 306 | ath_print(common, ATH_DBG_FATAL, |
| 307 | "address test failed " |
| 308 | "addr: 0x%08x - wr:0x%08x != " |
| 309 | "rd:0x%08x\n", |
| 310 | addr, wrData, rdData); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 311 | return false; |
| 312 | } |
| 313 | } |
| 314 | for (j = 0; j < 4; j++) { |
| 315 | wrData = patternData[j]; |
| 316 | REG_WRITE(ah, addr, wrData); |
| 317 | rdData = REG_READ(ah, addr); |
| 318 | if (wrData != rdData) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 319 | ath_print(common, ATH_DBG_FATAL, |
| 320 | "address test failed " |
| 321 | "addr: 0x%08x - wr:0x%08x != " |
| 322 | "rd:0x%08x\n", |
| 323 | addr, wrData, rdData); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 324 | return false; |
| 325 | } |
| 326 | } |
| 327 | REG_WRITE(ah, regAddr[i], regHold[i]); |
| 328 | } |
| 329 | udelay(100); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 330 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 331 | return true; |
| 332 | } |
| 333 | |
| 334 | static const char *ath9k_hw_devname(u16 devid) |
| 335 | { |
| 336 | switch (devid) { |
| 337 | case AR5416_DEVID_PCI: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 338 | return "Atheros 5416"; |
Benoit PAPILLAULT | 392dff8 | 2008-11-06 22:26:49 +0100 | [diff] [blame] | 339 | case AR5416_DEVID_PCIE: |
| 340 | return "Atheros 5418"; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 341 | case AR9160_DEVID_PCI: |
| 342 | return "Atheros 9160"; |
Gabor Juhos | 0c1aa49 | 2009-01-14 20:17:12 +0100 | [diff] [blame] | 343 | case AR5416_AR9100_DEVID: |
| 344 | return "Atheros 9100"; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 345 | case AR9280_DEVID_PCI: |
| 346 | case AR9280_DEVID_PCIE: |
| 347 | return "Atheros 9280"; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 348 | case AR9285_DEVID_PCIE: |
| 349 | return "Atheros 9285"; |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 350 | case AR5416_DEVID_AR9287_PCI: |
| 351 | case AR5416_DEVID_AR9287_PCIE: |
| 352 | return "Atheros 9287"; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | return NULL; |
| 356 | } |
| 357 | |
Luis R. Rodriguez | b8b0f37 | 2009-08-03 12:24:43 -0700 | [diff] [blame] | 358 | static void ath9k_hw_init_config(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 359 | { |
| 360 | int i; |
| 361 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 362 | ah->config.dma_beacon_response_time = 2; |
| 363 | ah->config.sw_beacon_response_time = 10; |
| 364 | ah->config.additional_swba_backoff = 0; |
| 365 | ah->config.ack_6mb = 0x0; |
| 366 | ah->config.cwm_ignore_extcca = 0; |
| 367 | ah->config.pcie_powersave_enable = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 368 | ah->config.pcie_clock_req = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 369 | ah->config.pcie_waen = 0; |
| 370 | ah->config.analog_shiftreg = 1; |
| 371 | ah->config.ht_enable = 1; |
| 372 | ah->config.ofdm_trig_low = 200; |
| 373 | ah->config.ofdm_trig_high = 500; |
| 374 | ah->config.cck_trig_high = 200; |
| 375 | ah->config.cck_trig_low = 100; |
| 376 | ah->config.enable_ani = 1; |
Sujith | 1cf6873 | 2009-08-13 09:34:32 +0530 | [diff] [blame] | 377 | ah->config.diversity_control = ATH9K_ANT_VARIABLE; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 378 | ah->config.antenna_switch_swap = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 379 | |
| 380 | for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 381 | ah->config.spurchans[i][0] = AR_NO_SPUR; |
| 382 | ah->config.spurchans[i][1] = AR_NO_SPUR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Sujith | 0ef1f16 | 2009-03-30 15:28:35 +0530 | [diff] [blame] | 385 | ah->config.intr_mitigation = true; |
Luis R. Rodriguez | 6158425 | 2009-03-12 18:18:49 -0400 | [diff] [blame] | 386 | |
| 387 | /* |
| 388 | * We need this for PCI devices only (Cardbus, PCI, miniPCI) |
| 389 | * _and_ if on non-uniprocessor systems (Multiprocessor/HT). |
| 390 | * This means we use it for all AR5416 devices, and the few |
| 391 | * minor PCI AR9280 devices out there. |
| 392 | * |
| 393 | * Serialization is required because these devices do not handle |
| 394 | * well the case of two concurrent reads/writes due to the latency |
| 395 | * involved. During one read/write another read/write can be issued |
| 396 | * on another CPU while the previous read/write may still be working |
| 397 | * on our hardware, if we hit this case the hardware poops in a loop. |
| 398 | * We prevent this by serializing reads and writes. |
| 399 | * |
| 400 | * This issue is not present on PCI-Express devices or pre-AR5416 |
| 401 | * devices (legacy, 802.11abg). |
| 402 | */ |
| 403 | if (num_possible_cpus() > 1) |
David S. Miller | 2d6a5e9 | 2009-03-17 15:01:30 -0700 | [diff] [blame] | 404 | ah->config.serialize_regmode = SER_REG_MODE_AUTO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Luis R. Rodriguez | 50aca25 | 2009-08-03 12:24:42 -0700 | [diff] [blame] | 407 | static void ath9k_hw_init_defaults(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 408 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 409 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
| 410 | |
| 411 | regulatory->country_code = CTRY_DEFAULT; |
| 412 | regulatory->power_limit = MAX_RATE_POWER; |
| 413 | regulatory->tp_scale = ATH9K_TP_SCALE_MAX; |
| 414 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 415 | ah->hw_version.magic = AR5416_MAGIC; |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 416 | ah->hw_version.subvendorid = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 417 | |
| 418 | ah->ah_flags = 0; |
Luis R. Rodriguez | 8df5d1b | 2009-08-03 12:24:37 -0700 | [diff] [blame] | 419 | if (ah->hw_version.devid == AR5416_AR9100_DEVID) |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 420 | ah->hw_version.macVersion = AR_SREV_VERSION_9100; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 421 | if (!AR_SREV_9100(ah)) |
| 422 | ah->ah_flags = AH_USE_EEPROM; |
| 423 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 424 | ah->atim_window = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 425 | ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE; |
| 426 | ah->beacon_interval = 100; |
| 427 | ah->enable_32kHz_clock = DONT_USE_32KHZ; |
| 428 | ah->slottime = (u32) -1; |
| 429 | ah->acktimeout = (u32) -1; |
| 430 | ah->ctstimeout = (u32) -1; |
| 431 | ah->globaltxtimeout = (u32) -1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 432 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 433 | ah->gbeacon_rate = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 434 | |
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_rfattach(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 439 | { |
| 440 | bool rfStatus = false; |
| 441 | int ecode = 0; |
| 442 | |
| 443 | rfStatus = ath9k_hw_init_rf(ah, &ecode); |
| 444 | if (!rfStatus) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 445 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 446 | "RF setup failed, status: %u\n", ecode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 447 | return ecode; |
| 448 | } |
| 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 453 | static int ath9k_hw_rf_claim(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 454 | { |
| 455 | u32 val; |
| 456 | |
| 457 | REG_WRITE(ah, AR_PHY(0), 0x00000007); |
| 458 | |
| 459 | val = ath9k_hw_get_radiorev(ah); |
| 460 | switch (val & AR_RADIO_SREV_MAJOR) { |
| 461 | case 0: |
| 462 | val = AR_RAD5133_SREV_MAJOR; |
| 463 | break; |
| 464 | case AR_RAD5133_SREV_MAJOR: |
| 465 | case AR_RAD5122_SREV_MAJOR: |
| 466 | case AR_RAD2133_SREV_MAJOR: |
| 467 | case AR_RAD2122_SREV_MAJOR: |
| 468 | break; |
| 469 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 470 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 471 | "Radio Chip Rev 0x%02X not supported\n", |
| 472 | val & AR_RADIO_SREV_MAJOR); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 473 | return -EOPNOTSUPP; |
| 474 | } |
| 475 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 476 | ah->hw_version.analog5GhzRev = val; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 477 | |
| 478 | return 0; |
| 479 | } |
| 480 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 481 | static int ath9k_hw_init_macaddr(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 482 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 483 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 484 | u32 sum; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 485 | int i; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 486 | u16 eeval; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 487 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 488 | sum = 0; |
| 489 | for (i = 0; i < 3; i++) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 490 | eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 491 | sum += eeval; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 492 | common->macaddr[2 * i] = eeval >> 8; |
| 493 | common->macaddr[2 * i + 1] = eeval & 0xff; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 494 | } |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 495 | if (sum == 0 || sum == 0xffff * 3) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 496 | return -EADDRNOTAVAIL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 497 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 498 | return 0; |
| 499 | } |
| 500 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 501 | static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah) |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 502 | { |
| 503 | u32 rxgain_type; |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 504 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 505 | if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) { |
| 506 | rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE); |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 507 | |
| 508 | if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 509 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 510 | ar9280Modes_backoff_13db_rxgain_9280_2, |
| 511 | ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6); |
| 512 | else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 513 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 514 | ar9280Modes_backoff_23db_rxgain_9280_2, |
| 515 | ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6); |
| 516 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 517 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 518 | ar9280Modes_original_rxgain_9280_2, |
| 519 | ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 520 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 521 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 522 | ar9280Modes_original_rxgain_9280_2, |
| 523 | ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 524 | } |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 525 | } |
| 526 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 527 | static void ath9k_hw_init_txgain_ini(struct ath_hw *ah) |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 528 | { |
| 529 | u32 txgain_type; |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 530 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 531 | if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) { |
| 532 | txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE); |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 533 | |
| 534 | if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 535 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 536 | ar9280Modes_high_power_tx_gain_9280_2, |
| 537 | ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6); |
| 538 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 539 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 540 | ar9280Modes_original_tx_gain_9280_2, |
| 541 | ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 542 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 543 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 544 | ar9280Modes_original_tx_gain_9280_2, |
| 545 | ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 546 | } |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 547 | } |
| 548 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 549 | static int ath9k_hw_post_init(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 550 | { |
| 551 | int ecode; |
| 552 | |
Sujith | d8baa93 | 2009-03-30 15:28:25 +0530 | [diff] [blame] | 553 | if (!ath9k_hw_chip_test(ah)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 554 | return -ENODEV; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 555 | |
| 556 | ecode = ath9k_hw_rf_claim(ah); |
| 557 | if (ecode != 0) |
| 558 | return ecode; |
| 559 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 560 | ecode = ath9k_hw_eeprom_init(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 561 | if (ecode != 0) |
| 562 | return ecode; |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 563 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 564 | ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG, |
| 565 | "Eeprom VER: %d, REV: %d\n", |
| 566 | ah->eep_ops->get_eeprom_ver(ah), |
| 567 | ah->eep_ops->get_eeprom_rev(ah)); |
Sujith | 7d01b22 | 2009-03-13 08:55:55 +0530 | [diff] [blame] | 568 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 569 | ecode = ath9k_hw_rfattach(ah); |
| 570 | if (ecode != 0) |
| 571 | return ecode; |
| 572 | |
| 573 | if (!AR_SREV_9100(ah)) { |
| 574 | ath9k_hw_ani_setup(ah); |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 575 | ath9k_hw_ani_init(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 576 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 577 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 578 | return 0; |
| 579 | } |
| 580 | |
Luis R. Rodriguez | ee2bb46 | 2009-08-03 12:24:39 -0700 | [diff] [blame] | 581 | static bool ath9k_hw_devid_supported(u16 devid) |
| 582 | { |
| 583 | switch (devid) { |
| 584 | case AR5416_DEVID_PCI: |
| 585 | case AR5416_DEVID_PCIE: |
| 586 | case AR5416_AR9100_DEVID: |
| 587 | case AR9160_DEVID_PCI: |
| 588 | case AR9280_DEVID_PCI: |
| 589 | case AR9280_DEVID_PCIE: |
| 590 | case AR9285_DEVID_PCIE: |
| 591 | case AR5416_DEVID_AR9287_PCI: |
| 592 | case AR5416_DEVID_AR9287_PCIE: |
| 593 | return true; |
| 594 | default: |
| 595 | break; |
| 596 | } |
| 597 | return false; |
| 598 | } |
| 599 | |
Luis R. Rodriguez | f9d4a66 | 2009-08-03 12:24:41 -0700 | [diff] [blame] | 600 | static bool ath9k_hw_macversion_supported(u32 macversion) |
| 601 | { |
| 602 | switch (macversion) { |
| 603 | case AR_SREV_VERSION_5416_PCI: |
| 604 | case AR_SREV_VERSION_5416_PCIE: |
| 605 | case AR_SREV_VERSION_9160: |
| 606 | case AR_SREV_VERSION_9100: |
| 607 | case AR_SREV_VERSION_9280: |
| 608 | case AR_SREV_VERSION_9285: |
| 609 | case AR_SREV_VERSION_9287: |
| 610 | return true; |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 611 | /* Not yet */ |
| 612 | case AR_SREV_VERSION_9271: |
Luis R. Rodriguez | f9d4a66 | 2009-08-03 12:24:41 -0700 | [diff] [blame] | 613 | default: |
| 614 | break; |
| 615 | } |
| 616 | return false; |
| 617 | } |
| 618 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 619 | static void ath9k_hw_init_cal_settings(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 620 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 621 | if (AR_SREV_9160_10_OR_LATER(ah)) { |
| 622 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 623 | ah->iq_caldata.calData = &iq_cal_single_sample; |
| 624 | ah->adcgain_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 625 | &adc_gain_cal_single_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 626 | ah->adcdc_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 627 | &adc_dc_cal_single_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 628 | ah->adcdc_calinitdata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 629 | &adc_init_dc_cal; |
| 630 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 631 | ah->iq_caldata.calData = &iq_cal_multi_sample; |
| 632 | ah->adcgain_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 633 | &adc_gain_cal_multi_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 634 | ah->adcdc_caldata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 635 | &adc_dc_cal_multi_sample; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 636 | ah->adcdc_calinitdata.calData = |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 637 | &adc_init_dc_cal; |
| 638 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 639 | ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 640 | } |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 641 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 642 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 643 | static void ath9k_hw_init_mode_regs(struct ath_hw *ah) |
| 644 | { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 645 | if (AR_SREV_9271(ah)) { |
| 646 | INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0, |
| 647 | ARRAY_SIZE(ar9271Modes_9271_1_0), 6); |
| 648 | INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0, |
| 649 | ARRAY_SIZE(ar9271Common_9271_1_0), 2); |
| 650 | return; |
| 651 | } |
| 652 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 653 | if (AR_SREV_9287_11_OR_LATER(ah)) { |
| 654 | INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1, |
| 655 | ARRAY_SIZE(ar9287Modes_9287_1_1), 6); |
| 656 | INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1, |
| 657 | ARRAY_SIZE(ar9287Common_9287_1_1), 2); |
| 658 | if (ah->config.pcie_clock_req) |
| 659 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 660 | ar9287PciePhy_clkreq_off_L1_9287_1_1, |
| 661 | ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2); |
| 662 | else |
| 663 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 664 | ar9287PciePhy_clkreq_always_on_L1_9287_1_1, |
| 665 | ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1), |
| 666 | 2); |
| 667 | } else if (AR_SREV_9287_10_OR_LATER(ah)) { |
| 668 | INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0, |
| 669 | ARRAY_SIZE(ar9287Modes_9287_1_0), 6); |
| 670 | INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0, |
| 671 | ARRAY_SIZE(ar9287Common_9287_1_0), 2); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 672 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 673 | if (ah->config.pcie_clock_req) |
| 674 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 675 | ar9287PciePhy_clkreq_off_L1_9287_1_0, |
| 676 | ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2); |
| 677 | else |
| 678 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
| 679 | ar9287PciePhy_clkreq_always_on_L1_9287_1_0, |
| 680 | ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0), |
| 681 | 2); |
| 682 | } else if (AR_SREV_9285_12_OR_LATER(ah)) { |
| 683 | |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 684 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 685 | INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 686 | ARRAY_SIZE(ar9285Modes_9285_1_2), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 687 | INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 688 | ARRAY_SIZE(ar9285Common_9285_1_2), 2); |
| 689 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 690 | if (ah->config.pcie_clock_req) { |
| 691 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 692 | ar9285PciePhy_clkreq_off_L1_9285_1_2, |
| 693 | ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2); |
| 694 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 695 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 696 | ar9285PciePhy_clkreq_always_on_L1_9285_1_2, |
| 697 | ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2), |
| 698 | 2); |
| 699 | } |
| 700 | } else if (AR_SREV_9285_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 701 | INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 702 | ARRAY_SIZE(ar9285Modes_9285), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 703 | INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 704 | ARRAY_SIZE(ar9285Common_9285), 2); |
| 705 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 706 | if (ah->config.pcie_clock_req) { |
| 707 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 708 | ar9285PciePhy_clkreq_off_L1_9285, |
| 709 | ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2); |
| 710 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 711 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 712 | ar9285PciePhy_clkreq_always_on_L1_9285, |
| 713 | ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2); |
| 714 | } |
| 715 | } else if (AR_SREV_9280_20_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 716 | INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 717 | ARRAY_SIZE(ar9280Modes_9280_2), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 718 | INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 719 | ARRAY_SIZE(ar9280Common_9280_2), 2); |
| 720 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 721 | if (ah->config.pcie_clock_req) { |
| 722 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 723 | ar9280PciePhy_clkreq_off_L1_9280, |
| 724 | ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 725 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 726 | INIT_INI_ARRAY(&ah->iniPcieSerdes, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 727 | ar9280PciePhy_clkreq_always_on_L1_9280, |
| 728 | ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 729 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 730 | INIT_INI_ARRAY(&ah->iniModesAdditional, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 731 | ar9280Modes_fast_clock_9280_2, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 732 | ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 733 | } else if (AR_SREV_9280_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 734 | INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 735 | ARRAY_SIZE(ar9280Modes_9280), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 736 | INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 737 | ARRAY_SIZE(ar9280Common_9280), 2); |
| 738 | } else if (AR_SREV_9160_10_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 739 | INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 740 | ARRAY_SIZE(ar5416Modes_9160), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 741 | INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 742 | ARRAY_SIZE(ar5416Common_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 743 | INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 744 | ARRAY_SIZE(ar5416Bank0_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 745 | INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 746 | ARRAY_SIZE(ar5416BB_RfGain_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 747 | INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 748 | ARRAY_SIZE(ar5416Bank1_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 749 | INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 750 | ARRAY_SIZE(ar5416Bank2_9160), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 751 | INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 752 | ARRAY_SIZE(ar5416Bank3_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 753 | INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 754 | ARRAY_SIZE(ar5416Bank6_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 755 | INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 756 | ARRAY_SIZE(ar5416Bank6TPC_9160), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 757 | INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 758 | ARRAY_SIZE(ar5416Bank7_9160), 2); |
| 759 | if (AR_SREV_9160_11(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 760 | INIT_INI_ARRAY(&ah->iniAddac, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 761 | ar5416Addac_91601_1, |
| 762 | ARRAY_SIZE(ar5416Addac_91601_1), 2); |
| 763 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 764 | INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 765 | ARRAY_SIZE(ar5416Addac_9160), 2); |
| 766 | } |
| 767 | } else if (AR_SREV_9100_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 768 | INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 769 | ARRAY_SIZE(ar5416Modes_9100), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 770 | INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 771 | ARRAY_SIZE(ar5416Common_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 772 | INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 773 | ARRAY_SIZE(ar5416Bank0_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 774 | INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 775 | ARRAY_SIZE(ar5416BB_RfGain_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 776 | INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 777 | ARRAY_SIZE(ar5416Bank1_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 778 | INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 779 | ARRAY_SIZE(ar5416Bank2_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 780 | INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 781 | ARRAY_SIZE(ar5416Bank3_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 782 | INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 783 | ARRAY_SIZE(ar5416Bank6_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 784 | INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 785 | ARRAY_SIZE(ar5416Bank6TPC_9100), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 786 | INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 787 | ARRAY_SIZE(ar5416Bank7_9100), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 788 | INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 789 | ARRAY_SIZE(ar5416Addac_9100), 2); |
| 790 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 791 | INIT_INI_ARRAY(&ah->iniModes, ar5416Modes, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 792 | ARRAY_SIZE(ar5416Modes), 6); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 793 | INIT_INI_ARRAY(&ah->iniCommon, ar5416Common, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 794 | ARRAY_SIZE(ar5416Common), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 795 | INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 796 | ARRAY_SIZE(ar5416Bank0), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 797 | INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 798 | ARRAY_SIZE(ar5416BB_RfGain), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 799 | INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 800 | ARRAY_SIZE(ar5416Bank1), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 801 | INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 802 | ARRAY_SIZE(ar5416Bank2), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 803 | INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 804 | ARRAY_SIZE(ar5416Bank3), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 805 | INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 806 | ARRAY_SIZE(ar5416Bank6), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 807 | INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 808 | ARRAY_SIZE(ar5416Bank6TPC), 3); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 809 | INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 810 | ARRAY_SIZE(ar5416Bank7), 2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 811 | INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 812 | ARRAY_SIZE(ar5416Addac), 2); |
| 813 | } |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 814 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 815 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 816 | static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah) |
| 817 | { |
Vivek Natarajan | b37fa87 | 2009-09-23 16:27:27 +0530 | [diff] [blame] | 818 | if (AR_SREV_9287_11_OR_LATER(ah)) |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 819 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
| 820 | ar9287Modes_rx_gain_9287_1_1, |
| 821 | ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6); |
| 822 | else if (AR_SREV_9287_10(ah)) |
| 823 | INIT_INI_ARRAY(&ah->iniModesRxGain, |
| 824 | ar9287Modes_rx_gain_9287_1_0, |
| 825 | ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6); |
| 826 | else if (AR_SREV_9280_20(ah)) |
| 827 | ath9k_hw_init_rxgain_ini(ah); |
| 828 | |
Vivek Natarajan | b37fa87 | 2009-09-23 16:27:27 +0530 | [diff] [blame] | 829 | if (AR_SREV_9287_11_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 830 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 831 | ar9287Modes_tx_gain_9287_1_1, |
| 832 | ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6); |
| 833 | } else if (AR_SREV_9287_10(ah)) { |
| 834 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 835 | ar9287Modes_tx_gain_9287_1_0, |
| 836 | ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6); |
| 837 | } else if (AR_SREV_9280_20(ah)) { |
| 838 | ath9k_hw_init_txgain_ini(ah); |
| 839 | } else if (AR_SREV_9285_12_OR_LATER(ah)) { |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 840 | u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE); |
| 841 | |
| 842 | /* txgain table */ |
| 843 | if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) { |
| 844 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 845 | ar9285Modes_high_power_tx_gain_9285_1_2, |
| 846 | ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6); |
| 847 | } else { |
| 848 | INIT_INI_ARRAY(&ah->iniModesTxGain, |
| 849 | ar9285Modes_original_tx_gain_9285_1_2, |
| 850 | ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6); |
| 851 | } |
| 852 | |
| 853 | } |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 854 | } |
Senthil Balasubramanian | 4e84516 | 2009-03-06 11:24:10 +0530 | [diff] [blame] | 855 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 856 | static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah) |
| 857 | { |
| 858 | u32 i, j; |
Sujith | 06d0f06 | 2009-02-12 10:06:45 +0530 | [diff] [blame] | 859 | |
| 860 | if ((ah->hw_version.devid == AR9280_DEVID_PCI) && |
| 861 | test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) { |
| 862 | |
| 863 | /* EEPROM Fixup */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 864 | for (i = 0; i < ah->iniModes.ia_rows; i++) { |
| 865 | u32 reg = INI_RA(&ah->iniModes, i, 0); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 866 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 867 | for (j = 1; j < ah->iniModes.ia_columns; j++) { |
| 868 | u32 val = INI_RA(&ah->iniModes, i, j); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 869 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 870 | INI_RA(&ah->iniModes, i, j) = |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 871 | ath9k_hw_ini_fixup(ah, |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 872 | &ah->eeprom.def, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 873 | reg, val); |
| 874 | } |
| 875 | } |
| 876 | } |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 879 | int ath9k_hw_init(struct ath_hw *ah) |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 880 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 881 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 882 | int r = 0; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 883 | |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 884 | if (!ath9k_hw_devid_supported(ah->hw_version.devid)) |
| 885 | return -EOPNOTSUPP; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 886 | |
| 887 | ath9k_hw_init_defaults(ah); |
| 888 | ath9k_hw_init_config(ah); |
| 889 | |
| 890 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 891 | ath_print(common, ATH_DBG_FATAL, |
| 892 | "Couldn't reset chip\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 893 | return -EIO; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 896 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 897 | ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 898 | return -EIO; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) { |
| 902 | if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI || |
| 903 | (AR_SREV_9280(ah) && !ah->is_pciexpress)) { |
| 904 | ah->config.serialize_regmode = |
| 905 | SER_REG_MODE_ON; |
| 906 | } else { |
| 907 | ah->config.serialize_regmode = |
| 908 | SER_REG_MODE_OFF; |
| 909 | } |
| 910 | } |
| 911 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 912 | ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n", |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 913 | ah->config.serialize_regmode); |
| 914 | |
| 915 | if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 916 | ath_print(common, ATH_DBG_FATAL, |
| 917 | "Mac Chip Rev 0x%02x.%x is not supported by " |
| 918 | "this driver\n", ah->hw_version.macVersion, |
| 919 | ah->hw_version.macRev); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 920 | return -EOPNOTSUPP; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | if (AR_SREV_9100(ah)) { |
| 924 | ah->iq_caldata.calData = &iq_cal_multi_sample; |
| 925 | ah->supp_cals = IQ_MISMATCH_CAL; |
| 926 | ah->is_pciexpress = false; |
| 927 | } |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 928 | |
| 929 | if (AR_SREV_9271(ah)) |
| 930 | ah->is_pciexpress = false; |
| 931 | |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 932 | ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID); |
| 933 | |
| 934 | ath9k_hw_init_cal_settings(ah); |
| 935 | |
| 936 | ah->ani_function = ATH9K_ANI_ALL; |
| 937 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 938 | ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL; |
| 939 | |
| 940 | ath9k_hw_init_mode_regs(ah); |
| 941 | |
| 942 | if (ah->is_pciexpress) |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 943 | ath9k_hw_configpcipowersave(ah, 0, 0); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 944 | else |
| 945 | ath9k_hw_disablepcie(ah); |
| 946 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 947 | r = ath9k_hw_post_init(ah); |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 948 | if (r) |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 949 | return r; |
Luis R. Rodriguez | aa4058a | 2009-08-03 12:24:45 -0700 | [diff] [blame] | 950 | |
| 951 | ath9k_hw_init_mode_gain_regs(ah); |
| 952 | ath9k_hw_fill_cap_info(ah); |
| 953 | ath9k_hw_init_11a_eeprom_fix(ah); |
Sujith | f6688cd | 2008-12-07 21:43:10 +0530 | [diff] [blame] | 954 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 955 | r = ath9k_hw_init_macaddr(ah); |
| 956 | if (r) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 957 | ath_print(common, ATH_DBG_FATAL, |
| 958 | "Failed to initialize MAC address\n"); |
Luis R. Rodriguez | 95fafca | 2009-08-03 12:24:54 -0700 | [diff] [blame] | 959 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 962 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 963 | ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 964 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 965 | ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 966 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 967 | ath9k_init_nfcal_hist_buffer(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 968 | |
Luis R. Rodriguez | 4f3acf8 | 2009-08-03 12:24:36 -0700 | [diff] [blame] | 969 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 972 | static void ath9k_hw_init_bb(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 973 | struct ath9k_channel *chan) |
| 974 | { |
| 975 | u32 synthDelay; |
| 976 | |
| 977 | synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY; |
Sujith | 788a3d6 | 2008-11-18 09:09:54 +0530 | [diff] [blame] | 978 | if (IS_CHAN_B(chan)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 979 | synthDelay = (4 * synthDelay) / 22; |
| 980 | else |
| 981 | synthDelay /= 10; |
| 982 | |
| 983 | REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN); |
| 984 | |
| 985 | udelay(synthDelay + BASE_ACTIVATE_DELAY); |
| 986 | } |
| 987 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 988 | static void ath9k_hw_init_qos(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 989 | { |
| 990 | REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa); |
| 991 | REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210); |
| 992 | |
| 993 | REG_WRITE(ah, AR_QOS_NO_ACK, |
| 994 | SM(2, AR_QOS_NO_ACK_TWO_BIT) | |
| 995 | SM(5, AR_QOS_NO_ACK_BIT_OFF) | |
| 996 | SM(0, AR_QOS_NO_ACK_BYTE_OFF)); |
| 997 | |
| 998 | REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL); |
| 999 | REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF); |
| 1000 | REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF); |
| 1001 | REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF); |
| 1002 | REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF); |
| 1003 | } |
| 1004 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1005 | static void ath9k_hw_init_pll(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1006 | struct ath9k_channel *chan) |
| 1007 | { |
| 1008 | u32 pll; |
| 1009 | |
| 1010 | if (AR_SREV_9100(ah)) { |
| 1011 | if (chan && IS_CHAN_5GHZ(chan)) |
| 1012 | pll = 0x1450; |
| 1013 | else |
| 1014 | pll = 0x1458; |
| 1015 | } else { |
| 1016 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 1017 | pll = SM(0x5, AR_RTC_9160_PLL_REFDIV); |
| 1018 | |
| 1019 | if (chan && IS_CHAN_HALF_RATE(chan)) |
| 1020 | pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL); |
| 1021 | else if (chan && IS_CHAN_QUARTER_RATE(chan)) |
| 1022 | pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL); |
| 1023 | |
| 1024 | if (chan && IS_CHAN_5GHZ(chan)) { |
| 1025 | pll |= SM(0x28, AR_RTC_9160_PLL_DIV); |
| 1026 | |
| 1027 | |
| 1028 | if (AR_SREV_9280_20(ah)) { |
| 1029 | if (((chan->channel % 20) == 0) |
| 1030 | || ((chan->channel % 10) == 0)) |
| 1031 | pll = 0x2850; |
| 1032 | else |
| 1033 | pll = 0x142c; |
| 1034 | } |
| 1035 | } else { |
| 1036 | pll |= SM(0x2c, AR_RTC_9160_PLL_DIV); |
| 1037 | } |
| 1038 | |
| 1039 | } else if (AR_SREV_9160_10_OR_LATER(ah)) { |
| 1040 | |
| 1041 | pll = SM(0x5, AR_RTC_9160_PLL_REFDIV); |
| 1042 | |
| 1043 | if (chan && IS_CHAN_HALF_RATE(chan)) |
| 1044 | pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL); |
| 1045 | else if (chan && IS_CHAN_QUARTER_RATE(chan)) |
| 1046 | pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL); |
| 1047 | |
| 1048 | if (chan && IS_CHAN_5GHZ(chan)) |
| 1049 | pll |= SM(0x50, AR_RTC_9160_PLL_DIV); |
| 1050 | else |
| 1051 | pll |= SM(0x58, AR_RTC_9160_PLL_DIV); |
| 1052 | } else { |
| 1053 | pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2; |
| 1054 | |
| 1055 | if (chan && IS_CHAN_HALF_RATE(chan)) |
| 1056 | pll |= SM(0x1, AR_RTC_PLL_CLKSEL); |
| 1057 | else if (chan && IS_CHAN_QUARTER_RATE(chan)) |
| 1058 | pll |= SM(0x2, AR_RTC_PLL_CLKSEL); |
| 1059 | |
| 1060 | if (chan && IS_CHAN_5GHZ(chan)) |
| 1061 | pll |= SM(0xa, AR_RTC_PLL_DIV); |
| 1062 | else |
| 1063 | pll |= SM(0xb, AR_RTC_PLL_DIV); |
| 1064 | } |
| 1065 | } |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1066 | REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1067 | |
| 1068 | udelay(RTC_PLL_SETTLE_DELAY); |
| 1069 | |
| 1070 | REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK); |
| 1071 | } |
| 1072 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1073 | static void ath9k_hw_init_chain_masks(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1074 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1075 | int rx_chainmask, tx_chainmask; |
| 1076 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1077 | rx_chainmask = ah->rxchainmask; |
| 1078 | tx_chainmask = ah->txchainmask; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1079 | |
| 1080 | switch (rx_chainmask) { |
| 1081 | case 0x5: |
| 1082 | REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP, |
| 1083 | AR_PHY_SWAP_ALT_CHAIN); |
| 1084 | case 0x3: |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 1085 | if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1086 | REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7); |
| 1087 | REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7); |
| 1088 | break; |
| 1089 | } |
| 1090 | case 0x1: |
| 1091 | case 0x2: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1092 | case 0x7: |
| 1093 | REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask); |
| 1094 | REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask); |
| 1095 | break; |
| 1096 | default: |
| 1097 | break; |
| 1098 | } |
| 1099 | |
| 1100 | REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask); |
| 1101 | if (tx_chainmask == 0x5) { |
| 1102 | REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP, |
| 1103 | AR_PHY_SWAP_ALT_CHAIN); |
| 1104 | } |
| 1105 | if (AR_SREV_9100(ah)) |
| 1106 | REG_WRITE(ah, AR_PHY_ANALOG_SWAP, |
| 1107 | REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001); |
| 1108 | } |
| 1109 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1110 | static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah, |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1111 | enum nl80211_iftype opmode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1112 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1113 | ah->mask_reg = AR_IMR_TXERR | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1114 | AR_IMR_TXURN | |
| 1115 | AR_IMR_RXERR | |
| 1116 | AR_IMR_RXORN | |
| 1117 | AR_IMR_BCNMISC; |
| 1118 | |
Sujith | 0ef1f16 | 2009-03-30 15:28:35 +0530 | [diff] [blame] | 1119 | if (ah->config.intr_mitigation) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1120 | ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1121 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1122 | ah->mask_reg |= AR_IMR_RXOK; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1123 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1124 | ah->mask_reg |= AR_IMR_TXOK; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1125 | |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1126 | if (opmode == NL80211_IFTYPE_AP) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1127 | ah->mask_reg |= AR_IMR_MIB; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1128 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1129 | REG_WRITE(ah, AR_IMR, ah->mask_reg); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1130 | REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT); |
| 1131 | |
| 1132 | if (!AR_SREV_9100(ah)) { |
| 1133 | REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF); |
| 1134 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT); |
| 1135 | REG_WRITE(ah, AR_INTR_SYNC_MASK, 0); |
| 1136 | } |
| 1137 | } |
| 1138 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1139 | static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1140 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1141 | if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1142 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 1143 | "bad ack timeout %u\n", us); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1144 | ah->acktimeout = (u32) -1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1145 | return false; |
| 1146 | } else { |
| 1147 | REG_RMW_FIELD(ah, AR_TIME_OUT, |
| 1148 | AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1149 | ah->acktimeout = us; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1150 | return true; |
| 1151 | } |
| 1152 | } |
| 1153 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1154 | static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1155 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1156 | if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1157 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 1158 | "bad cts timeout %u\n", us); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1159 | ah->ctstimeout = (u32) -1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1160 | return false; |
| 1161 | } else { |
| 1162 | REG_RMW_FIELD(ah, AR_TIME_OUT, |
| 1163 | AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1164 | ah->ctstimeout = us; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1165 | return true; |
| 1166 | } |
| 1167 | } |
| 1168 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1169 | static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1170 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1171 | if (tu > 0xFFFF) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1172 | ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT, |
| 1173 | "bad global tx timeout %u\n", tu); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1174 | ah->globaltxtimeout = (u32) -1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1175 | return false; |
| 1176 | } else { |
| 1177 | REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1178 | ah->globaltxtimeout = tu; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1179 | return true; |
| 1180 | } |
| 1181 | } |
| 1182 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1183 | static void ath9k_hw_init_user_settings(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1184 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1185 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n", |
| 1186 | ah->misc_mode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1187 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1188 | if (ah->misc_mode != 0) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1189 | REG_WRITE(ah, AR_PCU_MISC, |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1190 | REG_READ(ah, AR_PCU_MISC) | ah->misc_mode); |
| 1191 | if (ah->slottime != (u32) -1) |
| 1192 | ath9k_hw_setslottime(ah, ah->slottime); |
| 1193 | if (ah->acktimeout != (u32) -1) |
| 1194 | ath9k_hw_set_ack_timeout(ah, ah->acktimeout); |
| 1195 | if (ah->ctstimeout != (u32) -1) |
| 1196 | ath9k_hw_set_cts_timeout(ah, ah->ctstimeout); |
| 1197 | if (ah->globaltxtimeout != (u32) -1) |
| 1198 | ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | const char *ath9k_hw_probe(u16 vendorid, u16 devid) |
| 1202 | { |
| 1203 | return vendorid == ATHEROS_VENDOR_ID ? |
| 1204 | ath9k_hw_devname(devid) : NULL; |
| 1205 | } |
| 1206 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1207 | void ath9k_hw_detach(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1208 | { |
| 1209 | if (!AR_SREV_9100(ah)) |
Luis R. Rodriguez | e70c0cf | 2009-08-03 12:24:51 -0700 | [diff] [blame] | 1210 | ath9k_hw_ani_disable(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1211 | |
Luis R. Rodriguez | 081b35a | 2009-08-03 12:24:50 -0700 | [diff] [blame] | 1212 | ath9k_hw_rf_free(ah); |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1213 | ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1214 | kfree(ah); |
Luis R. Rodriguez | 9db6b6a | 2009-08-03 12:24:52 -0700 | [diff] [blame] | 1215 | ah = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1218 | /*******/ |
| 1219 | /* INI */ |
| 1220 | /*******/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1221 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1222 | static void ath9k_hw_override_ini(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1223 | struct ath9k_channel *chan) |
| 1224 | { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1225 | u32 val; |
| 1226 | |
| 1227 | if (AR_SREV_9271(ah)) { |
| 1228 | /* |
| 1229 | * Enable spectral scan to solution for issues with stuck |
| 1230 | * beacons on AR9271 1.0. The beacon stuck issue is not seeon on |
| 1231 | * AR9271 1.1 |
| 1232 | */ |
| 1233 | if (AR_SREV_9271_10(ah)) { |
| 1234 | val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE; |
| 1235 | REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val); |
| 1236 | } |
| 1237 | else if (AR_SREV_9271_11(ah)) |
| 1238 | /* |
| 1239 | * change AR_PHY_RF_CTL3 setting to fix MAC issue |
| 1240 | * present on AR9271 1.1 |
| 1241 | */ |
| 1242 | REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001); |
| 1243 | return; |
| 1244 | } |
| 1245 | |
Senthil Balasubramanian | 8aa15e1 | 2008-12-08 19:43:50 +0530 | [diff] [blame] | 1246 | /* |
| 1247 | * Set the RX_ABORT and RX_DIS and clear if off only after |
| 1248 | * RXE is set for MAC. This prevents frames with corrupted |
| 1249 | * descriptor status. |
| 1250 | */ |
| 1251 | REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT)); |
| 1252 | |
Vasanthakumar Thiagarajan | 204d794 | 2009-09-17 09:26:14 +0530 | [diff] [blame] | 1253 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
| 1254 | val = REG_READ(ah, AR_PCU_MISC_MODE2) & |
| 1255 | (~AR_PCU_MISC_MODE2_HWWAR1); |
| 1256 | |
| 1257 | if (AR_SREV_9287_10_OR_LATER(ah)) |
| 1258 | val = val & (~AR_PCU_MISC_MODE2_HWWAR2); |
| 1259 | |
| 1260 | REG_WRITE(ah, AR_PCU_MISC_MODE2, val); |
| 1261 | } |
Senthil Balasubramanian | 8aa15e1 | 2008-12-08 19:43:50 +0530 | [diff] [blame] | 1262 | |
Gabor Juhos | a8c96d3 | 2009-03-06 09:08:51 +0100 | [diff] [blame] | 1263 | if (!AR_SREV_5416_20_OR_LATER(ah) || |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1264 | AR_SREV_9280_10_OR_LATER(ah)) |
| 1265 | return; |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1266 | /* |
| 1267 | * Disable BB clock gating |
| 1268 | * Necessary to avoid issues on AR5416 2.0 |
| 1269 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1270 | REG_WRITE(ah, 0x9800 + (651 << 2), 0x11); |
| 1271 | } |
| 1272 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1273 | static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1274 | struct ar5416_eeprom_def *pEepData, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1275 | u32 reg, u32 value) |
| 1276 | { |
| 1277 | struct base_eep_header *pBase = &(pEepData->baseEepHeader); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1278 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1279 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 1280 | switch (ah->hw_version.devid) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1281 | case AR9280_DEVID_PCI: |
| 1282 | if (reg == 0x7894) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1283 | ath_print(common, ATH_DBG_EEPROM, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1284 | "ini VAL: %x EEPROM: %x\n", value, |
| 1285 | (pBase->version & 0xff)); |
| 1286 | |
| 1287 | if ((pBase->version & 0xff) > 0x0a) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1288 | ath_print(common, ATH_DBG_EEPROM, |
| 1289 | "PWDCLKIND: %d\n", |
| 1290 | pBase->pwdclkind); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1291 | value &= ~AR_AN_TOP2_PWDCLKIND; |
| 1292 | value |= AR_AN_TOP2_PWDCLKIND & |
| 1293 | (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S); |
| 1294 | } else { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1295 | ath_print(common, ATH_DBG_EEPROM, |
| 1296 | "PWDCLKIND Earlier Rev\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1297 | } |
| 1298 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1299 | ath_print(common, ATH_DBG_EEPROM, |
| 1300 | "final ini VAL: %x\n", value); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1301 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1302 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1305 | return value; |
| 1306 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1307 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1308 | static u32 ath9k_hw_ini_fixup(struct ath_hw *ah, |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1309 | struct ar5416_eeprom_def *pEepData, |
| 1310 | u32 reg, u32 value) |
| 1311 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1312 | if (ah->eep_map == EEP_MAP_4KBITS) |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1313 | return value; |
| 1314 | else |
| 1315 | return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value); |
| 1316 | } |
| 1317 | |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1318 | static void ath9k_olc_init(struct ath_hw *ah) |
| 1319 | { |
| 1320 | u32 i; |
| 1321 | |
Vivek Natarajan | db91f2e | 2009-08-14 11:27:16 +0530 | [diff] [blame] | 1322 | if (OLC_FOR_AR9287_10_LATER) { |
| 1323 | REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9, |
| 1324 | AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL); |
| 1325 | ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0, |
| 1326 | AR9287_AN_TXPC0_TXPCMODE, |
| 1327 | AR9287_AN_TXPC0_TXPCMODE_S, |
| 1328 | AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE); |
| 1329 | udelay(100); |
| 1330 | } else { |
| 1331 | for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++) |
| 1332 | ah->originalGain[i] = |
| 1333 | MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4), |
| 1334 | AR_PHY_TX_GAIN); |
| 1335 | ah->PDADCdelta = 0; |
| 1336 | } |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1337 | } |
| 1338 | |
Bob Copeland | 3a702e4 | 2009-03-30 22:30:29 -0400 | [diff] [blame] | 1339 | static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, |
| 1340 | struct ath9k_channel *chan) |
| 1341 | { |
| 1342 | u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band); |
| 1343 | |
| 1344 | if (IS_CHAN_B(chan)) |
| 1345 | ctl |= CTL_11B; |
| 1346 | else if (IS_CHAN_G(chan)) |
| 1347 | ctl |= CTL_11G; |
| 1348 | else |
| 1349 | ctl |= CTL_11A; |
| 1350 | |
| 1351 | return ctl; |
| 1352 | } |
| 1353 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1354 | static int ath9k_hw_process_ini(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1355 | struct ath9k_channel *chan, |
| 1356 | enum ath9k_ht_macmode macmode) |
| 1357 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1358 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1359 | int i, regWrites = 0; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1360 | struct ieee80211_channel *channel = chan->chan; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1361 | u32 modesIndex, freqIndex; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1362 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1363 | switch (chan->chanmode) { |
| 1364 | case CHANNEL_A: |
| 1365 | case CHANNEL_A_HT20: |
| 1366 | modesIndex = 1; |
| 1367 | freqIndex = 1; |
| 1368 | break; |
| 1369 | case CHANNEL_A_HT40PLUS: |
| 1370 | case CHANNEL_A_HT40MINUS: |
| 1371 | modesIndex = 2; |
| 1372 | freqIndex = 1; |
| 1373 | break; |
| 1374 | case CHANNEL_G: |
| 1375 | case CHANNEL_G_HT20: |
| 1376 | case CHANNEL_B: |
| 1377 | modesIndex = 4; |
| 1378 | freqIndex = 2; |
| 1379 | break; |
| 1380 | case CHANNEL_G_HT40PLUS: |
| 1381 | case CHANNEL_G_HT40MINUS: |
| 1382 | modesIndex = 3; |
| 1383 | freqIndex = 2; |
| 1384 | break; |
| 1385 | |
| 1386 | default: |
| 1387 | return -EINVAL; |
| 1388 | } |
| 1389 | |
| 1390 | REG_WRITE(ah, AR_PHY(0), 0x00000007); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1391 | REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO); |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1392 | ah->eep_ops->set_addac(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1393 | |
Gabor Juhos | a8c96d3 | 2009-03-06 09:08:51 +0100 | [diff] [blame] | 1394 | if (AR_SREV_5416_22_OR_LATER(ah)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1395 | REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1396 | } else { |
| 1397 | struct ar5416IniArray temp; |
| 1398 | u32 addacSize = |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1399 | sizeof(u32) * ah->iniAddac.ia_rows * |
| 1400 | ah->iniAddac.ia_columns; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1401 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1402 | memcpy(ah->addac5416_21, |
| 1403 | ah->iniAddac.ia_array, addacSize); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1404 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1405 | (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1406 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1407 | temp.ia_array = ah->addac5416_21; |
| 1408 | temp.ia_columns = ah->iniAddac.ia_columns; |
| 1409 | temp.ia_rows = ah->iniAddac.ia_rows; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1410 | REG_WRITE_ARRAY(&temp, 1, regWrites); |
| 1411 | } |
| 1412 | |
| 1413 | REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC); |
| 1414 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1415 | for (i = 0; i < ah->iniModes.ia_rows; i++) { |
| 1416 | u32 reg = INI_RA(&ah->iniModes, i, 0); |
| 1417 | u32 val = INI_RA(&ah->iniModes, i, modesIndex); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1418 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1419 | REG_WRITE(ah, reg, val); |
| 1420 | |
| 1421 | if (reg >= 0x7800 && reg < 0x78a0 |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1422 | && ah->config.analog_shiftreg) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1423 | udelay(100); |
| 1424 | } |
| 1425 | |
| 1426 | DO_DELAY(regWrites); |
| 1427 | } |
| 1428 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 1429 | if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah)) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1430 | REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites); |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 1431 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 1432 | if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) || |
| 1433 | AR_SREV_9287_10_OR_LATER(ah)) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1434 | REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites); |
Senthil Balasubramanian | 9f80420 | 2008-11-13 17:58:41 +0530 | [diff] [blame] | 1435 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1436 | for (i = 0; i < ah->iniCommon.ia_rows; i++) { |
| 1437 | u32 reg = INI_RA(&ah->iniCommon, i, 0); |
| 1438 | u32 val = INI_RA(&ah->iniCommon, i, 1); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1439 | |
| 1440 | REG_WRITE(ah, reg, val); |
| 1441 | |
| 1442 | if (reg >= 0x7800 && reg < 0x78a0 |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1443 | && ah->config.analog_shiftreg) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1444 | udelay(100); |
| 1445 | } |
| 1446 | |
| 1447 | DO_DELAY(regWrites); |
| 1448 | } |
| 1449 | |
| 1450 | ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites); |
| 1451 | |
| 1452 | if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1453 | REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1454 | regWrites); |
| 1455 | } |
| 1456 | |
| 1457 | ath9k_hw_override_ini(ah, chan); |
| 1458 | ath9k_hw_set_regs(ah, chan, macmode); |
| 1459 | ath9k_hw_init_chain_masks(ah); |
| 1460 | |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1461 | if (OLC_FOR_AR9280_20_LATER) |
| 1462 | ath9k_olc_init(ah); |
| 1463 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1464 | ah->eep_ops->set_txpower(ah, chan, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1465 | ath9k_regd_get_ctl(regulatory, chan), |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1466 | channel->max_antenna_gain * 2, |
| 1467 | channel->max_power * 2, |
| 1468 | min((u32) MAX_RATE_POWER, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1469 | (u32) regulatory->power_limit)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1470 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1471 | if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1472 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 1473 | "ar5416SetRfRegs failed\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1474 | return -EIO; |
| 1475 | } |
| 1476 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1477 | return 0; |
| 1478 | } |
| 1479 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1480 | /****************************************/ |
| 1481 | /* Reset and Channel Switching Routines */ |
| 1482 | /****************************************/ |
| 1483 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1484 | static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1485 | { |
| 1486 | u32 rfMode = 0; |
| 1487 | |
| 1488 | if (chan == NULL) |
| 1489 | return; |
| 1490 | |
| 1491 | rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan)) |
| 1492 | ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM; |
| 1493 | |
| 1494 | if (!AR_SREV_9280_10_OR_LATER(ah)) |
| 1495 | rfMode |= (IS_CHAN_5GHZ(chan)) ? |
| 1496 | AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ; |
| 1497 | |
| 1498 | if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) |
| 1499 | rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE); |
| 1500 | |
| 1501 | REG_WRITE(ah, AR_PHY_MODE, rfMode); |
| 1502 | } |
| 1503 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1504 | static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1505 | { |
| 1506 | REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS); |
| 1507 | } |
| 1508 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1509 | static inline void ath9k_hw_set_dma(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1510 | { |
| 1511 | u32 regval; |
| 1512 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1513 | /* |
| 1514 | * set AHB_MODE not to do cacheline prefetches |
| 1515 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1516 | regval = REG_READ(ah, AR_AHB_MODE); |
| 1517 | REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN); |
| 1518 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1519 | /* |
| 1520 | * let mac dma reads be in 128 byte chunks |
| 1521 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1522 | regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK; |
| 1523 | REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B); |
| 1524 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1525 | /* |
| 1526 | * Restore TX Trigger Level to its pre-reset value. |
| 1527 | * The initial value depends on whether aggregation is enabled, and is |
| 1528 | * adjusted whenever underruns are detected. |
| 1529 | */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1530 | REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1531 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1532 | /* |
| 1533 | * let mac dma writes be in 128 byte chunks |
| 1534 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1535 | regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK; |
| 1536 | REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B); |
| 1537 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1538 | /* |
| 1539 | * Setup receive FIFO threshold to hold off TX activities |
| 1540 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1541 | REG_WRITE(ah, AR_RXFIFO_CFG, 0x200); |
| 1542 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1543 | /* |
| 1544 | * reduce the number of usable entries in PCU TXBUF to avoid |
| 1545 | * wrap around issues. |
| 1546 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1547 | if (AR_SREV_9285(ah)) { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1548 | /* For AR9285 the number of Fifos are reduced to half. |
| 1549 | * So set the usable tx buf size also to half to |
| 1550 | * avoid data/delimiter underruns |
| 1551 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1552 | REG_WRITE(ah, AR_PCU_TXBUF_CTRL, |
| 1553 | AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE); |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 1554 | } else if (!AR_SREV_9271(ah)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1555 | REG_WRITE(ah, AR_PCU_TXBUF_CTRL, |
| 1556 | AR_PCU_TXBUF_CTRL_USABLE_SIZE); |
| 1557 | } |
| 1558 | } |
| 1559 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1560 | static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1561 | { |
| 1562 | u32 val; |
| 1563 | |
| 1564 | val = REG_READ(ah, AR_STA_ID1); |
| 1565 | val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC); |
| 1566 | switch (opmode) { |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1567 | case NL80211_IFTYPE_AP: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1568 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP |
| 1569 | | AR_STA_ID1_KSRCH_MODE); |
| 1570 | REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); |
| 1571 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1572 | case NL80211_IFTYPE_ADHOC: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 1573 | case NL80211_IFTYPE_MESH_POINT: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1574 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC |
| 1575 | | AR_STA_ID1_KSRCH_MODE); |
| 1576 | REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); |
| 1577 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 1578 | case NL80211_IFTYPE_STATION: |
| 1579 | case NL80211_IFTYPE_MONITOR: |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1580 | REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE); |
| 1581 | break; |
| 1582 | } |
| 1583 | } |
| 1584 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1585 | static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1586 | u32 coef_scaled, |
| 1587 | u32 *coef_mantissa, |
| 1588 | u32 *coef_exponent) |
| 1589 | { |
| 1590 | u32 coef_exp, coef_man; |
| 1591 | |
| 1592 | for (coef_exp = 31; coef_exp > 0; coef_exp--) |
| 1593 | if ((coef_scaled >> coef_exp) & 0x1) |
| 1594 | break; |
| 1595 | |
| 1596 | coef_exp = 14 - (coef_exp - COEF_SCALE_S); |
| 1597 | |
| 1598 | coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1)); |
| 1599 | |
| 1600 | *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp); |
| 1601 | *coef_exponent = coef_exp - 16; |
| 1602 | } |
| 1603 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1604 | static void ath9k_hw_set_delta_slope(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1605 | struct ath9k_channel *chan) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1606 | { |
| 1607 | u32 coef_scaled, ds_coef_exp, ds_coef_man; |
| 1608 | u32 clockMhzScaled = 0x64000000; |
| 1609 | struct chan_centers centers; |
| 1610 | |
| 1611 | if (IS_CHAN_HALF_RATE(chan)) |
| 1612 | clockMhzScaled = clockMhzScaled >> 1; |
| 1613 | else if (IS_CHAN_QUARTER_RATE(chan)) |
| 1614 | clockMhzScaled = clockMhzScaled >> 2; |
| 1615 | |
| 1616 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 1617 | coef_scaled = clockMhzScaled / centers.synth_center; |
| 1618 | |
| 1619 | ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man, |
| 1620 | &ds_coef_exp); |
| 1621 | |
| 1622 | REG_RMW_FIELD(ah, AR_PHY_TIMING3, |
| 1623 | AR_PHY_TIMING3_DSC_MAN, ds_coef_man); |
| 1624 | REG_RMW_FIELD(ah, AR_PHY_TIMING3, |
| 1625 | AR_PHY_TIMING3_DSC_EXP, ds_coef_exp); |
| 1626 | |
| 1627 | coef_scaled = (9 * coef_scaled) / 10; |
| 1628 | |
| 1629 | ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man, |
| 1630 | &ds_coef_exp); |
| 1631 | |
| 1632 | REG_RMW_FIELD(ah, AR_PHY_HALFGI, |
| 1633 | AR_PHY_HALFGI_DSC_MAN, ds_coef_man); |
| 1634 | REG_RMW_FIELD(ah, AR_PHY_HALFGI, |
| 1635 | AR_PHY_HALFGI_DSC_EXP, ds_coef_exp); |
| 1636 | } |
| 1637 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1638 | static bool ath9k_hw_set_reset(struct ath_hw *ah, int type) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1639 | { |
| 1640 | u32 rst_flags; |
| 1641 | u32 tmpReg; |
| 1642 | |
Sujith | 7076849 | 2009-02-16 13:23:12 +0530 | [diff] [blame] | 1643 | if (AR_SREV_9100(ah)) { |
| 1644 | u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK); |
| 1645 | val &= ~AR_RTC_DERIVED_CLK_PERIOD; |
| 1646 | val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD); |
| 1647 | REG_WRITE(ah, AR_RTC_DERIVED_CLK, val); |
| 1648 | (void)REG_READ(ah, AR_RTC_DERIVED_CLK); |
| 1649 | } |
| 1650 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1651 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN | |
| 1652 | AR_RTC_FORCE_WAKE_ON_INT); |
| 1653 | |
| 1654 | if (AR_SREV_9100(ah)) { |
| 1655 | rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD | |
| 1656 | AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET; |
| 1657 | } else { |
| 1658 | tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE); |
| 1659 | if (tmpReg & |
| 1660 | (AR_INTR_SYNC_LOCAL_TIMEOUT | |
| 1661 | AR_INTR_SYNC_RADM_CPL_TIMEOUT)) { |
| 1662 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0); |
| 1663 | REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF); |
| 1664 | } else { |
| 1665 | REG_WRITE(ah, AR_RC, AR_RC_AHB); |
| 1666 | } |
| 1667 | |
| 1668 | rst_flags = AR_RTC_RC_MAC_WARM; |
| 1669 | if (type == ATH9K_RESET_COLD) |
| 1670 | rst_flags |= AR_RTC_RC_MAC_COLD; |
| 1671 | } |
| 1672 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1673 | REG_WRITE(ah, AR_RTC_RC, rst_flags); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1674 | udelay(50); |
| 1675 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1676 | REG_WRITE(ah, AR_RTC_RC, 0); |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1677 | if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1678 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 1679 | "RTC stuck in MAC reset\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1680 | return false; |
| 1681 | } |
| 1682 | |
| 1683 | if (!AR_SREV_9100(ah)) |
| 1684 | REG_WRITE(ah, AR_RC, 0); |
| 1685 | |
| 1686 | ath9k_hw_init_pll(ah, NULL); |
| 1687 | |
| 1688 | if (AR_SREV_9100(ah)) |
| 1689 | udelay(50); |
| 1690 | |
| 1691 | return true; |
| 1692 | } |
| 1693 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1694 | static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1695 | { |
| 1696 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN | |
| 1697 | AR_RTC_FORCE_WAKE_ON_INT); |
| 1698 | |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1699 | if (!AR_SREV_9100(ah)) |
| 1700 | REG_WRITE(ah, AR_RC, AR_RC_AHB); |
| 1701 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1702 | REG_WRITE(ah, AR_RTC_RESET, 0); |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 1703 | udelay(2); |
Vasanthakumar Thiagarajan | 1c29ce6 | 2009-08-31 17:48:36 +0530 | [diff] [blame] | 1704 | |
| 1705 | if (!AR_SREV_9100(ah)) |
| 1706 | REG_WRITE(ah, AR_RC, 0); |
| 1707 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 1708 | REG_WRITE(ah, AR_RTC_RESET, 1); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1709 | |
| 1710 | if (!ath9k_hw_wait(ah, |
| 1711 | AR_RTC_STATUS, |
| 1712 | AR_RTC_STATUS_M, |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1713 | AR_RTC_STATUS_ON, |
| 1714 | AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1715 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 1716 | "RTC not waking up\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1717 | return false; |
| 1718 | } |
| 1719 | |
| 1720 | ath9k_hw_read_revisions(ah); |
| 1721 | |
| 1722 | return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM); |
| 1723 | } |
| 1724 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1725 | static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1726 | { |
| 1727 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, |
| 1728 | AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT); |
| 1729 | |
| 1730 | switch (type) { |
| 1731 | case ATH9K_RESET_POWER_ON: |
| 1732 | return ath9k_hw_set_reset_power_on(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1733 | case ATH9K_RESET_WARM: |
| 1734 | case ATH9K_RESET_COLD: |
| 1735 | return ath9k_hw_set_reset(ah, type); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1736 | default: |
| 1737 | return false; |
| 1738 | } |
| 1739 | } |
| 1740 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1741 | static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1742 | enum ath9k_ht_macmode macmode) |
| 1743 | { |
| 1744 | u32 phymode; |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1745 | u32 enableDacFifo = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1746 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1747 | if (AR_SREV_9285_10_OR_LATER(ah)) |
| 1748 | enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) & |
| 1749 | AR_PHY_FC_ENABLE_DAC_FIFO); |
| 1750 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1751 | phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40 |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 1752 | | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1753 | |
| 1754 | if (IS_CHAN_HT40(chan)) { |
| 1755 | phymode |= AR_PHY_FC_DYN2040_EN; |
| 1756 | |
| 1757 | if ((chan->chanmode == CHANNEL_A_HT40PLUS) || |
| 1758 | (chan->chanmode == CHANNEL_G_HT40PLUS)) |
| 1759 | phymode |= AR_PHY_FC_DYN2040_PRI_CH; |
| 1760 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1761 | } |
| 1762 | REG_WRITE(ah, AR_PHY_TURBO, phymode); |
| 1763 | |
| 1764 | ath9k_hw_set11nmac2040(ah, macmode); |
| 1765 | |
| 1766 | REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S); |
| 1767 | REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S); |
| 1768 | } |
| 1769 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1770 | static bool ath9k_hw_chip_reset(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1771 | struct ath9k_channel *chan) |
| 1772 | { |
Vivek Natarajan | 42abfbe | 2009-09-17 09:27:59 +0530 | [diff] [blame] | 1773 | 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] | 1774 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) |
| 1775 | return false; |
| 1776 | } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1777 | return false; |
| 1778 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 1779 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1780 | return false; |
| 1781 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1782 | ah->chip_fullsleep = false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1783 | ath9k_hw_init_pll(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1784 | ath9k_hw_set_rfmode(ah, chan); |
| 1785 | |
| 1786 | return true; |
| 1787 | } |
| 1788 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1789 | static bool ath9k_hw_channel_change(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1790 | struct ath9k_channel *chan, |
| 1791 | enum ath9k_ht_macmode macmode) |
| 1792 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1793 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1794 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 1795 | struct ieee80211_channel *channel = chan->chan; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1796 | u32 synthDelay, qnum; |
| 1797 | |
| 1798 | for (qnum = 0; qnum < AR_NUM_QCU; qnum++) { |
| 1799 | if (ath9k_hw_numtxpending(ah, qnum)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1800 | ath_print(common, ATH_DBG_QUEUE, |
| 1801 | "Transmit frames pending on " |
| 1802 | "queue %d\n", qnum); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1803 | return false; |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN); |
| 1808 | if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN, |
Sujith | 0caa7b1 | 2009-02-16 13:23:20 +0530 | [diff] [blame] | 1809 | AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1810 | ath_print(common, ATH_DBG_FATAL, |
| 1811 | "Could not kill baseband RX\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1812 | return false; |
| 1813 | } |
| 1814 | |
| 1815 | ath9k_hw_set_regs(ah, chan, macmode); |
| 1816 | |
| 1817 | if (AR_SREV_9280_10_OR_LATER(ah)) { |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1818 | ath9k_hw_ar9280_set_channel(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1819 | } else { |
| 1820 | if (!(ath9k_hw_set_channel(ah, chan))) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1821 | ath_print(common, ATH_DBG_FATAL, |
| 1822 | "Failed to set channel\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1823 | return false; |
| 1824 | } |
| 1825 | } |
| 1826 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 1827 | ah->eep_ops->set_txpower(ah, chan, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1828 | ath9k_regd_get_ctl(regulatory, chan), |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1829 | channel->max_antenna_gain * 2, |
| 1830 | channel->max_power * 2, |
| 1831 | min((u32) MAX_RATE_POWER, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 1832 | (u32) regulatory->power_limit)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1833 | |
| 1834 | synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY; |
Sujith | 788a3d6 | 2008-11-18 09:09:54 +0530 | [diff] [blame] | 1835 | if (IS_CHAN_B(chan)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1836 | synthDelay = (4 * synthDelay) / 22; |
| 1837 | else |
| 1838 | synthDelay /= 10; |
| 1839 | |
| 1840 | udelay(synthDelay + BASE_ACTIVATE_DELAY); |
| 1841 | |
| 1842 | REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0); |
| 1843 | |
| 1844 | if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) |
| 1845 | ath9k_hw_set_delta_slope(ah, chan); |
| 1846 | |
| 1847 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 1848 | ath9k_hw_9280_spur_mitigate(ah, chan); |
| 1849 | else |
| 1850 | ath9k_hw_spur_mitigate(ah, chan); |
| 1851 | |
| 1852 | if (!chan->oneTimeCalsDone) |
| 1853 | chan->oneTimeCalsDone = true; |
| 1854 | |
| 1855 | return true; |
| 1856 | } |
| 1857 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1858 | static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1859 | { |
| 1860 | int bb_spur = AR_NO_SPUR; |
| 1861 | int freq; |
| 1862 | int bin, cur_bin; |
| 1863 | int bb_spur_off, spur_subchannel_sd; |
| 1864 | int spur_freq_sd; |
| 1865 | int spur_delta_phase; |
| 1866 | int denominator; |
| 1867 | int upper, lower, cur_vit_mask; |
| 1868 | int tmp, newVal; |
| 1869 | int i; |
| 1870 | int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8, |
| 1871 | AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60 |
| 1872 | }; |
| 1873 | int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10, |
| 1874 | AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60 |
| 1875 | }; |
| 1876 | int inc[4] = { 0, 100, 0, 0 }; |
| 1877 | struct chan_centers centers; |
| 1878 | |
| 1879 | int8_t mask_m[123]; |
| 1880 | int8_t mask_p[123]; |
| 1881 | int8_t mask_amt; |
| 1882 | int tmp_mask; |
| 1883 | int cur_bb_spur; |
| 1884 | bool is2GHz = IS_CHAN_2GHZ(chan); |
| 1885 | |
| 1886 | memset(&mask_m, 0, sizeof(int8_t) * 123); |
| 1887 | memset(&mask_p, 0, sizeof(int8_t) * 123); |
| 1888 | |
| 1889 | ath9k_hw_get_channel_centers(ah, chan, ¢ers); |
| 1890 | freq = centers.synth_center; |
| 1891 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1892 | ah->config.spurmode = SPUR_ENABLE_EEPROM; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1893 | for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 1894 | cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1895 | |
| 1896 | if (is2GHz) |
| 1897 | cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ; |
| 1898 | else |
| 1899 | cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ; |
| 1900 | |
| 1901 | if (AR_NO_SPUR == cur_bb_spur) |
| 1902 | break; |
| 1903 | cur_bb_spur = cur_bb_spur - freq; |
| 1904 | |
| 1905 | if (IS_CHAN_HT40(chan)) { |
| 1906 | if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) && |
| 1907 | (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) { |
| 1908 | bb_spur = cur_bb_spur; |
| 1909 | break; |
| 1910 | } |
| 1911 | } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) && |
| 1912 | (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) { |
| 1913 | bb_spur = cur_bb_spur; |
| 1914 | break; |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | if (AR_NO_SPUR == bb_spur) { |
| 1919 | REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK, |
| 1920 | AR_PHY_FORCE_CLKEN_CCK_MRC_MUX); |
| 1921 | return; |
| 1922 | } else { |
| 1923 | REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK, |
| 1924 | AR_PHY_FORCE_CLKEN_CCK_MRC_MUX); |
| 1925 | } |
| 1926 | |
| 1927 | bin = bb_spur * 320; |
| 1928 | |
| 1929 | tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0)); |
| 1930 | |
| 1931 | newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI | |
| 1932 | AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER | |
| 1933 | AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK | |
| 1934 | AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK); |
| 1935 | REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal); |
| 1936 | |
| 1937 | newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL | |
| 1938 | AR_PHY_SPUR_REG_ENABLE_MASK_PPM | |
| 1939 | AR_PHY_SPUR_REG_MASK_RATE_SELECT | |
| 1940 | AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI | |
| 1941 | SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH)); |
| 1942 | REG_WRITE(ah, AR_PHY_SPUR_REG, newVal); |
| 1943 | |
| 1944 | if (IS_CHAN_HT40(chan)) { |
| 1945 | if (bb_spur < 0) { |
| 1946 | spur_subchannel_sd = 1; |
| 1947 | bb_spur_off = bb_spur + 10; |
| 1948 | } else { |
| 1949 | spur_subchannel_sd = 0; |
| 1950 | bb_spur_off = bb_spur - 10; |
| 1951 | } |
| 1952 | } else { |
| 1953 | spur_subchannel_sd = 0; |
| 1954 | bb_spur_off = bb_spur; |
| 1955 | } |
| 1956 | |
| 1957 | if (IS_CHAN_HT40(chan)) |
| 1958 | spur_delta_phase = |
| 1959 | ((bb_spur * 262144) / |
| 1960 | 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE; |
| 1961 | else |
| 1962 | spur_delta_phase = |
| 1963 | ((bb_spur * 524288) / |
| 1964 | 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE; |
| 1965 | |
| 1966 | denominator = IS_CHAN_2GHZ(chan) ? 44 : 40; |
| 1967 | spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff; |
| 1968 | |
| 1969 | newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC | |
| 1970 | SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) | |
| 1971 | SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE)); |
| 1972 | REG_WRITE(ah, AR_PHY_TIMING11, newVal); |
| 1973 | |
| 1974 | newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S; |
| 1975 | REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal); |
| 1976 | |
| 1977 | cur_bin = -6000; |
| 1978 | upper = bin + 100; |
| 1979 | lower = bin - 100; |
| 1980 | |
| 1981 | for (i = 0; i < 4; i++) { |
| 1982 | int pilot_mask = 0; |
| 1983 | int chan_mask = 0; |
| 1984 | int bp = 0; |
| 1985 | for (bp = 0; bp < 30; bp++) { |
| 1986 | if ((cur_bin > lower) && (cur_bin < upper)) { |
| 1987 | pilot_mask = pilot_mask | 0x1 << bp; |
| 1988 | chan_mask = chan_mask | 0x1 << bp; |
| 1989 | } |
| 1990 | cur_bin += 100; |
| 1991 | } |
| 1992 | cur_bin += inc[i]; |
| 1993 | REG_WRITE(ah, pilot_mask_reg[i], pilot_mask); |
| 1994 | REG_WRITE(ah, chan_mask_reg[i], chan_mask); |
| 1995 | } |
| 1996 | |
| 1997 | cur_vit_mask = 6100; |
| 1998 | upper = bin + 120; |
| 1999 | lower = bin - 120; |
| 2000 | |
| 2001 | for (i = 0; i < 123; i++) { |
| 2002 | if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) { |
Adrian Bunk | b08cbcd | 2008-08-05 22:06:51 +0300 | [diff] [blame] | 2003 | |
| 2004 | /* workaround for gcc bug #37014 */ |
Luis R. Rodriguez | a085ff7 | 2008-12-23 15:58:51 -0800 | [diff] [blame] | 2005 | volatile int tmp_v = abs(cur_vit_mask - bin); |
Adrian Bunk | b08cbcd | 2008-08-05 22:06:51 +0300 | [diff] [blame] | 2006 | |
Luis R. Rodriguez | a085ff7 | 2008-12-23 15:58:51 -0800 | [diff] [blame] | 2007 | if (tmp_v < 75) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2008 | mask_amt = 1; |
| 2009 | else |
| 2010 | mask_amt = 0; |
| 2011 | if (cur_vit_mask < 0) |
| 2012 | mask_m[abs(cur_vit_mask / 100)] = mask_amt; |
| 2013 | else |
| 2014 | mask_p[cur_vit_mask / 100] = mask_amt; |
| 2015 | } |
| 2016 | cur_vit_mask -= 100; |
| 2017 | } |
| 2018 | |
| 2019 | tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28) |
| 2020 | | (mask_m[48] << 26) | (mask_m[49] << 24) |
| 2021 | | (mask_m[50] << 22) | (mask_m[51] << 20) |
| 2022 | | (mask_m[52] << 18) | (mask_m[53] << 16) |
| 2023 | | (mask_m[54] << 14) | (mask_m[55] << 12) |
| 2024 | | (mask_m[56] << 10) | (mask_m[57] << 8) |
| 2025 | | (mask_m[58] << 6) | (mask_m[59] << 4) |
| 2026 | | (mask_m[60] << 2) | (mask_m[61] << 0); |
| 2027 | REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask); |
| 2028 | REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask); |
| 2029 | |
| 2030 | tmp_mask = (mask_m[31] << 28) |
| 2031 | | (mask_m[32] << 26) | (mask_m[33] << 24) |
| 2032 | | (mask_m[34] << 22) | (mask_m[35] << 20) |
| 2033 | | (mask_m[36] << 18) | (mask_m[37] << 16) |
| 2034 | | (mask_m[48] << 14) | (mask_m[39] << 12) |
| 2035 | | (mask_m[40] << 10) | (mask_m[41] << 8) |
| 2036 | | (mask_m[42] << 6) | (mask_m[43] << 4) |
| 2037 | | (mask_m[44] << 2) | (mask_m[45] << 0); |
| 2038 | REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask); |
| 2039 | REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask); |
| 2040 | |
| 2041 | tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28) |
| 2042 | | (mask_m[18] << 26) | (mask_m[18] << 24) |
| 2043 | | (mask_m[20] << 22) | (mask_m[20] << 20) |
| 2044 | | (mask_m[22] << 18) | (mask_m[22] << 16) |
| 2045 | | (mask_m[24] << 14) | (mask_m[24] << 12) |
| 2046 | | (mask_m[25] << 10) | (mask_m[26] << 8) |
| 2047 | | (mask_m[27] << 6) | (mask_m[28] << 4) |
| 2048 | | (mask_m[29] << 2) | (mask_m[30] << 0); |
| 2049 | REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask); |
| 2050 | REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask); |
| 2051 | |
| 2052 | tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28) |
| 2053 | | (mask_m[2] << 26) | (mask_m[3] << 24) |
| 2054 | | (mask_m[4] << 22) | (mask_m[5] << 20) |
| 2055 | | (mask_m[6] << 18) | (mask_m[7] << 16) |
| 2056 | | (mask_m[8] << 14) | (mask_m[9] << 12) |
| 2057 | | (mask_m[10] << 10) | (mask_m[11] << 8) |
| 2058 | | (mask_m[12] << 6) | (mask_m[13] << 4) |
| 2059 | | (mask_m[14] << 2) | (mask_m[15] << 0); |
| 2060 | REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask); |
| 2061 | REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask); |
| 2062 | |
| 2063 | tmp_mask = (mask_p[15] << 28) |
| 2064 | | (mask_p[14] << 26) | (mask_p[13] << 24) |
| 2065 | | (mask_p[12] << 22) | (mask_p[11] << 20) |
| 2066 | | (mask_p[10] << 18) | (mask_p[9] << 16) |
| 2067 | | (mask_p[8] << 14) | (mask_p[7] << 12) |
| 2068 | | (mask_p[6] << 10) | (mask_p[5] << 8) |
| 2069 | | (mask_p[4] << 6) | (mask_p[3] << 4) |
| 2070 | | (mask_p[2] << 2) | (mask_p[1] << 0); |
| 2071 | REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask); |
| 2072 | REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask); |
| 2073 | |
| 2074 | tmp_mask = (mask_p[30] << 28) |
| 2075 | | (mask_p[29] << 26) | (mask_p[28] << 24) |
| 2076 | | (mask_p[27] << 22) | (mask_p[26] << 20) |
| 2077 | | (mask_p[25] << 18) | (mask_p[24] << 16) |
| 2078 | | (mask_p[23] << 14) | (mask_p[22] << 12) |
| 2079 | | (mask_p[21] << 10) | (mask_p[20] << 8) |
| 2080 | | (mask_p[19] << 6) | (mask_p[18] << 4) |
| 2081 | | (mask_p[17] << 2) | (mask_p[16] << 0); |
| 2082 | REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask); |
| 2083 | REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask); |
| 2084 | |
| 2085 | tmp_mask = (mask_p[45] << 28) |
| 2086 | | (mask_p[44] << 26) | (mask_p[43] << 24) |
| 2087 | | (mask_p[42] << 22) | (mask_p[41] << 20) |
| 2088 | | (mask_p[40] << 18) | (mask_p[39] << 16) |
| 2089 | | (mask_p[38] << 14) | (mask_p[37] << 12) |
| 2090 | | (mask_p[36] << 10) | (mask_p[35] << 8) |
| 2091 | | (mask_p[34] << 6) | (mask_p[33] << 4) |
| 2092 | | (mask_p[32] << 2) | (mask_p[31] << 0); |
| 2093 | REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask); |
| 2094 | REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask); |
| 2095 | |
| 2096 | tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28) |
| 2097 | | (mask_p[59] << 26) | (mask_p[58] << 24) |
| 2098 | | (mask_p[57] << 22) | (mask_p[56] << 20) |
| 2099 | | (mask_p[55] << 18) | (mask_p[54] << 16) |
| 2100 | | (mask_p[53] << 14) | (mask_p[52] << 12) |
| 2101 | | (mask_p[51] << 10) | (mask_p[50] << 8) |
| 2102 | | (mask_p[49] << 6) | (mask_p[48] << 4) |
| 2103 | | (mask_p[47] << 2) | (mask_p[46] << 0); |
| 2104 | REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask); |
| 2105 | REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask); |
| 2106 | } |
| 2107 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2108 | static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2109 | { |
| 2110 | int bb_spur = AR_NO_SPUR; |
| 2111 | int bin, cur_bin; |
| 2112 | int spur_freq_sd; |
| 2113 | int spur_delta_phase; |
| 2114 | int denominator; |
| 2115 | int upper, lower, cur_vit_mask; |
| 2116 | int tmp, new; |
| 2117 | int i; |
| 2118 | int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8, |
| 2119 | AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60 |
| 2120 | }; |
| 2121 | int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10, |
| 2122 | AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60 |
| 2123 | }; |
| 2124 | int inc[4] = { 0, 100, 0, 0 }; |
| 2125 | |
| 2126 | int8_t mask_m[123]; |
| 2127 | int8_t mask_p[123]; |
| 2128 | int8_t mask_amt; |
| 2129 | int tmp_mask; |
| 2130 | int cur_bb_spur; |
| 2131 | bool is2GHz = IS_CHAN_2GHZ(chan); |
| 2132 | |
| 2133 | memset(&mask_m, 0, sizeof(int8_t) * 123); |
| 2134 | memset(&mask_p, 0, sizeof(int8_t) * 123); |
| 2135 | |
| 2136 | for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 2137 | cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2138 | if (AR_NO_SPUR == cur_bb_spur) |
| 2139 | break; |
| 2140 | cur_bb_spur = cur_bb_spur - (chan->channel * 10); |
| 2141 | if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) { |
| 2142 | bb_spur = cur_bb_spur; |
| 2143 | break; |
| 2144 | } |
| 2145 | } |
| 2146 | |
| 2147 | if (AR_NO_SPUR == bb_spur) |
| 2148 | return; |
| 2149 | |
| 2150 | bin = bb_spur * 32; |
| 2151 | |
| 2152 | tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0)); |
| 2153 | new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI | |
| 2154 | AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER | |
| 2155 | AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK | |
| 2156 | AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK); |
| 2157 | |
| 2158 | REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new); |
| 2159 | |
| 2160 | new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL | |
| 2161 | AR_PHY_SPUR_REG_ENABLE_MASK_PPM | |
| 2162 | AR_PHY_SPUR_REG_MASK_RATE_SELECT | |
| 2163 | AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI | |
| 2164 | SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH)); |
| 2165 | REG_WRITE(ah, AR_PHY_SPUR_REG, new); |
| 2166 | |
| 2167 | spur_delta_phase = ((bb_spur * 524288) / 100) & |
| 2168 | AR_PHY_TIMING11_SPUR_DELTA_PHASE; |
| 2169 | |
| 2170 | denominator = IS_CHAN_2GHZ(chan) ? 440 : 400; |
| 2171 | spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff; |
| 2172 | |
| 2173 | new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC | |
| 2174 | SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) | |
| 2175 | SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE)); |
| 2176 | REG_WRITE(ah, AR_PHY_TIMING11, new); |
| 2177 | |
| 2178 | cur_bin = -6000; |
| 2179 | upper = bin + 100; |
| 2180 | lower = bin - 100; |
| 2181 | |
| 2182 | for (i = 0; i < 4; i++) { |
| 2183 | int pilot_mask = 0; |
| 2184 | int chan_mask = 0; |
| 2185 | int bp = 0; |
| 2186 | for (bp = 0; bp < 30; bp++) { |
| 2187 | if ((cur_bin > lower) && (cur_bin < upper)) { |
| 2188 | pilot_mask = pilot_mask | 0x1 << bp; |
| 2189 | chan_mask = chan_mask | 0x1 << bp; |
| 2190 | } |
| 2191 | cur_bin += 100; |
| 2192 | } |
| 2193 | cur_bin += inc[i]; |
| 2194 | REG_WRITE(ah, pilot_mask_reg[i], pilot_mask); |
| 2195 | REG_WRITE(ah, chan_mask_reg[i], chan_mask); |
| 2196 | } |
| 2197 | |
| 2198 | cur_vit_mask = 6100; |
| 2199 | upper = bin + 120; |
| 2200 | lower = bin - 120; |
| 2201 | |
| 2202 | for (i = 0; i < 123; i++) { |
| 2203 | if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) { |
Adrian Bunk | 88b9e2b | 2008-08-05 22:06:51 +0300 | [diff] [blame] | 2204 | |
| 2205 | /* workaround for gcc bug #37014 */ |
Luis R. Rodriguez | a085ff7 | 2008-12-23 15:58:51 -0800 | [diff] [blame] | 2206 | volatile int tmp_v = abs(cur_vit_mask - bin); |
Adrian Bunk | 88b9e2b | 2008-08-05 22:06:51 +0300 | [diff] [blame] | 2207 | |
Luis R. Rodriguez | a085ff7 | 2008-12-23 15:58:51 -0800 | [diff] [blame] | 2208 | if (tmp_v < 75) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2209 | mask_amt = 1; |
| 2210 | else |
| 2211 | mask_amt = 0; |
| 2212 | if (cur_vit_mask < 0) |
| 2213 | mask_m[abs(cur_vit_mask / 100)] = mask_amt; |
| 2214 | else |
| 2215 | mask_p[cur_vit_mask / 100] = mask_amt; |
| 2216 | } |
| 2217 | cur_vit_mask -= 100; |
| 2218 | } |
| 2219 | |
| 2220 | tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28) |
| 2221 | | (mask_m[48] << 26) | (mask_m[49] << 24) |
| 2222 | | (mask_m[50] << 22) | (mask_m[51] << 20) |
| 2223 | | (mask_m[52] << 18) | (mask_m[53] << 16) |
| 2224 | | (mask_m[54] << 14) | (mask_m[55] << 12) |
| 2225 | | (mask_m[56] << 10) | (mask_m[57] << 8) |
| 2226 | | (mask_m[58] << 6) | (mask_m[59] << 4) |
| 2227 | | (mask_m[60] << 2) | (mask_m[61] << 0); |
| 2228 | REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask); |
| 2229 | REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask); |
| 2230 | |
| 2231 | tmp_mask = (mask_m[31] << 28) |
| 2232 | | (mask_m[32] << 26) | (mask_m[33] << 24) |
| 2233 | | (mask_m[34] << 22) | (mask_m[35] << 20) |
| 2234 | | (mask_m[36] << 18) | (mask_m[37] << 16) |
| 2235 | | (mask_m[48] << 14) | (mask_m[39] << 12) |
| 2236 | | (mask_m[40] << 10) | (mask_m[41] << 8) |
| 2237 | | (mask_m[42] << 6) | (mask_m[43] << 4) |
| 2238 | | (mask_m[44] << 2) | (mask_m[45] << 0); |
| 2239 | REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask); |
| 2240 | REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask); |
| 2241 | |
| 2242 | tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28) |
| 2243 | | (mask_m[18] << 26) | (mask_m[18] << 24) |
| 2244 | | (mask_m[20] << 22) | (mask_m[20] << 20) |
| 2245 | | (mask_m[22] << 18) | (mask_m[22] << 16) |
| 2246 | | (mask_m[24] << 14) | (mask_m[24] << 12) |
| 2247 | | (mask_m[25] << 10) | (mask_m[26] << 8) |
| 2248 | | (mask_m[27] << 6) | (mask_m[28] << 4) |
| 2249 | | (mask_m[29] << 2) | (mask_m[30] << 0); |
| 2250 | REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask); |
| 2251 | REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask); |
| 2252 | |
| 2253 | tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28) |
| 2254 | | (mask_m[2] << 26) | (mask_m[3] << 24) |
| 2255 | | (mask_m[4] << 22) | (mask_m[5] << 20) |
| 2256 | | (mask_m[6] << 18) | (mask_m[7] << 16) |
| 2257 | | (mask_m[8] << 14) | (mask_m[9] << 12) |
| 2258 | | (mask_m[10] << 10) | (mask_m[11] << 8) |
| 2259 | | (mask_m[12] << 6) | (mask_m[13] << 4) |
| 2260 | | (mask_m[14] << 2) | (mask_m[15] << 0); |
| 2261 | REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask); |
| 2262 | REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask); |
| 2263 | |
| 2264 | tmp_mask = (mask_p[15] << 28) |
| 2265 | | (mask_p[14] << 26) | (mask_p[13] << 24) |
| 2266 | | (mask_p[12] << 22) | (mask_p[11] << 20) |
| 2267 | | (mask_p[10] << 18) | (mask_p[9] << 16) |
| 2268 | | (mask_p[8] << 14) | (mask_p[7] << 12) |
| 2269 | | (mask_p[6] << 10) | (mask_p[5] << 8) |
| 2270 | | (mask_p[4] << 6) | (mask_p[3] << 4) |
| 2271 | | (mask_p[2] << 2) | (mask_p[1] << 0); |
| 2272 | REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask); |
| 2273 | REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask); |
| 2274 | |
| 2275 | tmp_mask = (mask_p[30] << 28) |
| 2276 | | (mask_p[29] << 26) | (mask_p[28] << 24) |
| 2277 | | (mask_p[27] << 22) | (mask_p[26] << 20) |
| 2278 | | (mask_p[25] << 18) | (mask_p[24] << 16) |
| 2279 | | (mask_p[23] << 14) | (mask_p[22] << 12) |
| 2280 | | (mask_p[21] << 10) | (mask_p[20] << 8) |
| 2281 | | (mask_p[19] << 6) | (mask_p[18] << 4) |
| 2282 | | (mask_p[17] << 2) | (mask_p[16] << 0); |
| 2283 | REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask); |
| 2284 | REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask); |
| 2285 | |
| 2286 | tmp_mask = (mask_p[45] << 28) |
| 2287 | | (mask_p[44] << 26) | (mask_p[43] << 24) |
| 2288 | | (mask_p[42] << 22) | (mask_p[41] << 20) |
| 2289 | | (mask_p[40] << 18) | (mask_p[39] << 16) |
| 2290 | | (mask_p[38] << 14) | (mask_p[37] << 12) |
| 2291 | | (mask_p[36] << 10) | (mask_p[35] << 8) |
| 2292 | | (mask_p[34] << 6) | (mask_p[33] << 4) |
| 2293 | | (mask_p[32] << 2) | (mask_p[31] << 0); |
| 2294 | REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask); |
| 2295 | REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask); |
| 2296 | |
| 2297 | tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28) |
| 2298 | | (mask_p[59] << 26) | (mask_p[58] << 24) |
| 2299 | | (mask_p[57] << 22) | (mask_p[56] << 20) |
| 2300 | | (mask_p[55] << 18) | (mask_p[54] << 16) |
| 2301 | | (mask_p[53] << 14) | (mask_p[52] << 12) |
| 2302 | | (mask_p[51] << 10) | (mask_p[50] << 8) |
| 2303 | | (mask_p[49] << 6) | (mask_p[48] << 4) |
| 2304 | | (mask_p[47] << 2) | (mask_p[46] << 0); |
| 2305 | REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask); |
| 2306 | REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask); |
| 2307 | } |
| 2308 | |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 2309 | static void ath9k_enable_rfkill(struct ath_hw *ah) |
| 2310 | { |
| 2311 | REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, |
| 2312 | AR_GPIO_INPUT_EN_VAL_RFSILENT_BB); |
| 2313 | |
| 2314 | REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2, |
| 2315 | AR_GPIO_INPUT_MUX2_RFSILENT); |
| 2316 | |
| 2317 | ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio); |
| 2318 | REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB); |
| 2319 | } |
| 2320 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2321 | int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2322 | bool bChannelChange) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2323 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 2324 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2325 | u32 saveLedState; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2326 | struct ath_softc *sc = ah->ah_sc; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2327 | struct ath9k_channel *curchan = ah->curchan; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2328 | u32 saveDefAntenna; |
| 2329 | u32 macStaId1; |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 2330 | u64 tsf = 0; |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2331 | int i, rx_chainmask, r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2332 | |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 2333 | ah->txchainmask = common->tx_chainmask; |
| 2334 | ah->rxchainmask = common->rx_chainmask; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2335 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 2336 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2337 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2338 | |
Vasanthakumar Thiagarajan | 9ebef799 | 2009-09-17 09:26:44 +0530 | [diff] [blame] | 2339 | if (curchan && !ah->chip_fullsleep) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2340 | ath9k_hw_getnf(ah, curchan); |
| 2341 | |
| 2342 | if (bChannelChange && |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2343 | (ah->chip_fullsleep != true) && |
| 2344 | (ah->curchan != NULL) && |
| 2345 | (chan->channel != ah->curchan->channel) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2346 | ((chan->channelFlags & CHANNEL_ALL) == |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2347 | (ah->curchan->channelFlags & CHANNEL_ALL)) && |
Vasanthakumar Thiagarajan | 0a475cc | 2009-09-17 09:27:10 +0530 | [diff] [blame] | 2348 | !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) || |
| 2349 | IS_CHAN_A_5MHZ_SPACED(ah->curchan))) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2350 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2351 | if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2352 | ath9k_hw_loadnf(ah, ah->curchan); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2353 | ath9k_hw_start_nfcal(ah); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2354 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA); |
| 2359 | if (saveDefAntenna == 0) |
| 2360 | saveDefAntenna = 1; |
| 2361 | |
| 2362 | macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B; |
| 2363 | |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 2364 | /* For chips on which RTC reset is done, save TSF before it gets cleared */ |
| 2365 | if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) |
| 2366 | tsf = ath9k_hw_gettsf64(ah); |
| 2367 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2368 | saveLedState = REG_READ(ah, AR_CFG_LED) & |
| 2369 | (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL | |
| 2370 | AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW); |
| 2371 | |
| 2372 | ath9k_hw_mark_phy_inactive(ah); |
| 2373 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2374 | if (AR_SREV_9271(ah) && ah->htc_reset_init) { |
| 2375 | REG_WRITE(ah, |
| 2376 | AR9271_RESET_POWER_DOWN_CONTROL, |
| 2377 | AR9271_RADIO_RF_RST); |
| 2378 | udelay(50); |
| 2379 | } |
| 2380 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2381 | if (!ath9k_hw_chip_reset(ah, chan)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2382 | ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n"); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2383 | return -EINVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2384 | } |
| 2385 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2386 | if (AR_SREV_9271(ah) && ah->htc_reset_init) { |
| 2387 | ah->htc_reset_init = false; |
| 2388 | REG_WRITE(ah, |
| 2389 | AR9271_RESET_POWER_DOWN_CONTROL, |
| 2390 | AR9271_GATE_MAC_CTL); |
| 2391 | udelay(50); |
| 2392 | } |
| 2393 | |
Sujith | 46fe782 | 2009-09-17 09:25:25 +0530 | [diff] [blame] | 2394 | /* Restore TSF */ |
| 2395 | if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) |
| 2396 | ath9k_hw_settsf64(ah, tsf); |
| 2397 | |
Vasanthakumar Thiagarajan | 369391d | 2009-01-21 19:24:13 +0530 | [diff] [blame] | 2398 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 2399 | 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] | 2400 | |
Vivek Natarajan | 326bebb | 2009-08-14 11:33:36 +0530 | [diff] [blame] | 2401 | if (AR_SREV_9287_12_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2402 | /* Enable ASYNC FIFO */ |
| 2403 | REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3, |
| 2404 | AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL); |
| 2405 | REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO); |
| 2406 | REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3, |
| 2407 | AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET); |
| 2408 | REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3, |
| 2409 | AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET); |
| 2410 | } |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2411 | r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width); |
| 2412 | if (r) |
| 2413 | return r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2414 | |
Jouni Malinen | 0ced0e1 | 2009-01-08 13:32:13 +0200 | [diff] [blame] | 2415 | /* Setup MFP options for CCMP */ |
| 2416 | if (AR_SREV_9280_20_OR_LATER(ah)) { |
| 2417 | /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt |
| 2418 | * frames when constructing CCMP AAD. */ |
| 2419 | REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT, |
| 2420 | 0xc7ff); |
| 2421 | ah->sw_mgmt_crypto = false; |
| 2422 | } else if (AR_SREV_9160_10_OR_LATER(ah)) { |
| 2423 | /* Disable hardware crypto for management frames */ |
| 2424 | REG_CLR_BIT(ah, AR_PCU_MISC_MODE2, |
| 2425 | AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE); |
| 2426 | REG_SET_BIT(ah, AR_PCU_MISC_MODE2, |
| 2427 | AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT); |
| 2428 | ah->sw_mgmt_crypto = true; |
| 2429 | } else |
| 2430 | ah->sw_mgmt_crypto = true; |
| 2431 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2432 | if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan)) |
| 2433 | ath9k_hw_set_delta_slope(ah, chan); |
| 2434 | |
| 2435 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 2436 | ath9k_hw_9280_spur_mitigate(ah, chan); |
| 2437 | else |
| 2438 | ath9k_hw_spur_mitigate(ah, chan); |
| 2439 | |
Sujith | d650915 | 2009-03-13 08:56:05 +0530 | [diff] [blame] | 2440 | ah->eep_ops->set_board_values(ah, chan); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2441 | |
| 2442 | ath9k_hw_decrease_chain_power(ah, chan); |
| 2443 | |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 2444 | REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr)); |
| 2445 | REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2446 | | macStaId1 |
| 2447 | | AR_STA_ID1_RTS_USE_DEF |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2448 | | (ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 2449 | ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2450 | | ah->sta_id1_defaults); |
| 2451 | ath9k_hw_set_operating_mode(ah, ah->opmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2452 | |
Luis R. Rodriguez | 13b8155 | 2009-09-10 17:52:45 -0700 | [diff] [blame] | 2453 | ath_hw_setbssidmask(common); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2454 | |
| 2455 | REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna); |
| 2456 | |
Luis R. Rodriguez | 3453ad8 | 2009-09-10 08:57:00 -0700 | [diff] [blame] | 2457 | ath9k_hw_write_associd(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2458 | |
| 2459 | REG_WRITE(ah, AR_ISR, ~0); |
| 2460 | |
| 2461 | REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR); |
| 2462 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 2463 | if (AR_SREV_9280_10_OR_LATER(ah)) |
| 2464 | ath9k_hw_ar9280_set_channel(ah, chan); |
| 2465 | else |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2466 | if (!(ath9k_hw_set_channel(ah, chan))) |
| 2467 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2468 | |
| 2469 | for (i = 0; i < AR_NUM_DCU; i++) |
| 2470 | REG_WRITE(ah, AR_DQCUMASK(i), 1 << i); |
| 2471 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2472 | ah->intr_txqs = 0; |
| 2473 | for (i = 0; i < ah->caps.total_queues; i++) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2474 | ath9k_hw_resettxqueue(ah, i); |
| 2475 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2476 | ath9k_hw_init_interrupt_masks(ah, ah->opmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2477 | ath9k_hw_init_qos(ah); |
| 2478 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2479 | if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 2480 | ath9k_enable_rfkill(ah); |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 2481 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2482 | ath9k_hw_init_user_settings(ah); |
| 2483 | |
Vivek Natarajan | 326bebb | 2009-08-14 11:33:36 +0530 | [diff] [blame] | 2484 | if (AR_SREV_9287_12_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2485 | REG_WRITE(ah, AR_D_GBL_IFS_SIFS, |
| 2486 | AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR); |
| 2487 | REG_WRITE(ah, AR_D_GBL_IFS_SLOT, |
| 2488 | AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR); |
| 2489 | REG_WRITE(ah, AR_D_GBL_IFS_EIFS, |
| 2490 | AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR); |
| 2491 | |
| 2492 | REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR); |
| 2493 | REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR); |
| 2494 | |
| 2495 | REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER, |
| 2496 | AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768); |
| 2497 | REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN, |
| 2498 | AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL); |
| 2499 | } |
Vivek Natarajan | 326bebb | 2009-08-14 11:33:36 +0530 | [diff] [blame] | 2500 | if (AR_SREV_9287_12_OR_LATER(ah)) { |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 2501 | REG_SET_BIT(ah, AR_PCU_MISC_MODE2, |
| 2502 | AR_PCU_MISC_MODE2_ENABLE_AGGWEP); |
| 2503 | } |
| 2504 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2505 | REG_WRITE(ah, AR_STA_ID1, |
| 2506 | REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM); |
| 2507 | |
| 2508 | ath9k_hw_set_dma(ah); |
| 2509 | |
| 2510 | REG_WRITE(ah, AR_OBS, 8); |
| 2511 | |
Sujith | 0ef1f16 | 2009-03-30 15:28:35 +0530 | [diff] [blame] | 2512 | if (ah->config.intr_mitigation) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2513 | REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500); |
| 2514 | REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000); |
| 2515 | } |
| 2516 | |
| 2517 | ath9k_hw_init_bb(ah, chan); |
| 2518 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2519 | if (!ath9k_hw_init_cal(ah, chan)) |
Joe Perches | 6badaaf | 2009-06-28 09:26:32 -0700 | [diff] [blame] | 2520 | return -EIO; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2521 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2522 | rx_chainmask = ah->rxchainmask; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2523 | if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) { |
| 2524 | REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask); |
| 2525 | REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask); |
| 2526 | } |
| 2527 | |
| 2528 | REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ); |
| 2529 | |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2530 | /* |
| 2531 | * For big endian systems turn on swapping for descriptors |
| 2532 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2533 | if (AR_SREV_9100(ah)) { |
| 2534 | u32 mask; |
| 2535 | mask = REG_READ(ah, AR_CFG); |
| 2536 | if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2537 | ath_print(common, ATH_DBG_RESET, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2538 | "CFG Byte Swap Set 0x%x\n", mask); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2539 | } else { |
| 2540 | mask = |
| 2541 | INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB; |
| 2542 | REG_WRITE(ah, AR_CFG, mask); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2543 | ath_print(common, ATH_DBG_RESET, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2544 | "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2545 | } |
| 2546 | } else { |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2547 | /* Configure AR9271 target WLAN */ |
| 2548 | if (AR_SREV_9271(ah)) |
| 2549 | REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2550 | #ifdef __BIG_ENDIAN |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 2551 | else |
| 2552 | REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2553 | #endif |
| 2554 | } |
| 2555 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 2556 | if (ah->btcoex_hw.enabled) |
Vasanthakumar Thiagarajan | 42cc41e | 2009-08-26 21:08:45 +0530 | [diff] [blame] | 2557 | ath9k_hw_btcoex_enable(ah); |
| 2558 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 2559 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2562 | /************************/ |
| 2563 | /* Key Cache Management */ |
| 2564 | /************************/ |
| 2565 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2566 | bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2567 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2568 | u32 keyType; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2569 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2570 | if (entry >= ah->caps.keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2571 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 2572 | "keychache entry %u out of range\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2573 | return false; |
| 2574 | } |
| 2575 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2576 | keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2577 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2578 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0); |
| 2579 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0); |
| 2580 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0); |
| 2581 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0); |
| 2582 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0); |
| 2583 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR); |
| 2584 | REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0); |
| 2585 | REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0); |
| 2586 | |
| 2587 | if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) { |
| 2588 | u16 micentry = entry + 64; |
| 2589 | |
| 2590 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0); |
| 2591 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0); |
| 2592 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0); |
| 2593 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0); |
| 2594 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2595 | } |
| 2596 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2597 | return true; |
| 2598 | } |
| 2599 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2600 | bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2601 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2602 | u32 macHi, macLo; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2603 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2604 | if (entry >= ah->caps.keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2605 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 2606 | "keychache entry %u out of range\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2607 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2610 | if (mac != NULL) { |
| 2611 | macHi = (mac[5] << 8) | mac[4]; |
| 2612 | macLo = (mac[3] << 24) | |
| 2613 | (mac[2] << 16) | |
| 2614 | (mac[1] << 8) | |
| 2615 | mac[0]; |
| 2616 | macLo >>= 1; |
| 2617 | macLo |= (macHi & 1) << 31; |
| 2618 | macHi >>= 1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2619 | } else { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2620 | macLo = macHi = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2621 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2622 | REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo); |
| 2623 | REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2624 | |
| 2625 | return true; |
| 2626 | } |
| 2627 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2628 | bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2629 | const struct ath9k_keyval *k, |
Jouni Malinen | e0caf9e | 2009-03-02 18:15:53 +0200 | [diff] [blame] | 2630 | const u8 *mac) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2631 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2632 | const struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2633 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2634 | u32 key0, key1, key2, key3, key4; |
| 2635 | u32 keyType; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2636 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2637 | if (entry >= pCap->keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2638 | ath_print(common, ATH_DBG_FATAL, |
| 2639 | "keycache entry %u out of range\n", entry); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2640 | return false; |
| 2641 | } |
| 2642 | |
| 2643 | switch (k->kv_type) { |
| 2644 | case ATH9K_CIPHER_AES_OCB: |
| 2645 | keyType = AR_KEYTABLE_TYPE_AES; |
| 2646 | break; |
| 2647 | case ATH9K_CIPHER_AES_CCM: |
| 2648 | if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2649 | ath_print(common, ATH_DBG_ANY, |
| 2650 | "AES-CCM not supported by mac rev 0x%x\n", |
| 2651 | ah->hw_version.macRev); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2652 | return false; |
| 2653 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2654 | keyType = AR_KEYTABLE_TYPE_CCM; |
| 2655 | break; |
| 2656 | case ATH9K_CIPHER_TKIP: |
| 2657 | keyType = AR_KEYTABLE_TYPE_TKIP; |
| 2658 | if (ATH9K_IS_MIC_ENABLED(ah) |
| 2659 | && entry + 64 >= pCap->keycache_size) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2660 | ath_print(common, ATH_DBG_ANY, |
| 2661 | "entry %u inappropriate for TKIP\n", entry); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2662 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2663 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2664 | break; |
| 2665 | case ATH9K_CIPHER_WEP: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 2666 | if (k->kv_len < WLAN_KEY_LEN_WEP40) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2667 | ath_print(common, ATH_DBG_ANY, |
| 2668 | "WEP key length %u too small\n", k->kv_len); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2669 | return false; |
| 2670 | } |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 2671 | if (k->kv_len <= WLAN_KEY_LEN_WEP40) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2672 | keyType = AR_KEYTABLE_TYPE_40; |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 2673 | else if (k->kv_len <= WLAN_KEY_LEN_WEP104) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2674 | keyType = AR_KEYTABLE_TYPE_104; |
| 2675 | else |
| 2676 | keyType = AR_KEYTABLE_TYPE_128; |
| 2677 | break; |
| 2678 | case ATH9K_CIPHER_CLR: |
| 2679 | keyType = AR_KEYTABLE_TYPE_CLR; |
| 2680 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2681 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2682 | ath_print(common, ATH_DBG_FATAL, |
| 2683 | "cipher %u not supported\n", k->kv_type); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2684 | return false; |
| 2685 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2686 | |
Jouni Malinen | e0caf9e | 2009-03-02 18:15:53 +0200 | [diff] [blame] | 2687 | key0 = get_unaligned_le32(k->kv_val + 0); |
| 2688 | key1 = get_unaligned_le16(k->kv_val + 4); |
| 2689 | key2 = get_unaligned_le32(k->kv_val + 6); |
| 2690 | key3 = get_unaligned_le16(k->kv_val + 10); |
| 2691 | key4 = get_unaligned_le32(k->kv_val + 12); |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 2692 | if (k->kv_len <= WLAN_KEY_LEN_WEP104) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2693 | key4 &= 0xff; |
| 2694 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2695 | /* |
| 2696 | * Note: Key cache registers access special memory area that requires |
| 2697 | * two 32-bit writes to actually update the values in the internal |
| 2698 | * memory. Consequently, the exact order and pairs used here must be |
| 2699 | * maintained. |
| 2700 | */ |
| 2701 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2702 | if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) { |
| 2703 | u16 micentry = entry + 64; |
| 2704 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2705 | /* |
| 2706 | * Write inverted key[47:0] first to avoid Michael MIC errors |
| 2707 | * on frames that could be sent or received at the same time. |
| 2708 | * The correct key will be written in the end once everything |
| 2709 | * else is ready. |
| 2710 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2711 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0); |
| 2712 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2713 | |
| 2714 | /* Write key[95:48] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2715 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2); |
| 2716 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2717 | |
| 2718 | /* Write key[127:96] and key type */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2719 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4); |
| 2720 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2721 | |
| 2722 | /* Write MAC address for the entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2723 | (void) ath9k_hw_keysetmac(ah, entry, mac); |
| 2724 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2725 | if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2726 | /* |
| 2727 | * TKIP uses two key cache entries: |
| 2728 | * Michael MIC TX/RX keys in the same key cache entry |
| 2729 | * (idx = main index + 64): |
| 2730 | * key0 [31:0] = RX key [31:0] |
| 2731 | * key1 [15:0] = TX key [31:16] |
| 2732 | * key1 [31:16] = reserved |
| 2733 | * key2 [31:0] = RX key [63:32] |
| 2734 | * key3 [15:0] = TX key [15:0] |
| 2735 | * key3 [31:16] = reserved |
| 2736 | * key4 [31:0] = TX key [63:32] |
| 2737 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2738 | u32 mic0, mic1, mic2, mic3, mic4; |
| 2739 | |
| 2740 | mic0 = get_unaligned_le32(k->kv_mic + 0); |
| 2741 | mic2 = get_unaligned_le32(k->kv_mic + 4); |
| 2742 | mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff; |
| 2743 | mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff; |
| 2744 | mic4 = get_unaligned_le32(k->kv_txmic + 4); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2745 | |
| 2746 | /* Write RX[31:0] and TX[31:16] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2747 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0); |
| 2748 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2749 | |
| 2750 | /* Write RX[63:32] and TX[15:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2751 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2); |
| 2752 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2753 | |
| 2754 | /* Write TX[63:32] and keyType(reserved) */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2755 | REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4); |
| 2756 | REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry), |
| 2757 | AR_KEYTABLE_TYPE_CLR); |
| 2758 | |
| 2759 | } else { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2760 | /* |
| 2761 | * TKIP uses four key cache entries (two for group |
| 2762 | * keys): |
| 2763 | * Michael MIC TX/RX keys are in different key cache |
| 2764 | * entries (idx = main index + 64 for TX and |
| 2765 | * main index + 32 + 96 for RX): |
| 2766 | * key0 [31:0] = TX/RX MIC key [31:0] |
| 2767 | * key1 [31:0] = reserved |
| 2768 | * key2 [31:0] = TX/RX MIC key [63:32] |
| 2769 | * key3 [31:0] = reserved |
| 2770 | * key4 [31:0] = reserved |
| 2771 | * |
| 2772 | * Upper layer code will call this function separately |
| 2773 | * for TX and RX keys when these registers offsets are |
| 2774 | * used. |
| 2775 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2776 | u32 mic0, mic2; |
| 2777 | |
| 2778 | mic0 = get_unaligned_le32(k->kv_mic + 0); |
| 2779 | mic2 = get_unaligned_le32(k->kv_mic + 4); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2780 | |
| 2781 | /* Write MIC key[31:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2782 | REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0); |
| 2783 | REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2784 | |
| 2785 | /* Write MIC key[63:32] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2786 | REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2); |
| 2787 | REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2788 | |
| 2789 | /* Write TX[63:32] and keyType(reserved) */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2790 | REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0); |
| 2791 | REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry), |
| 2792 | AR_KEYTABLE_TYPE_CLR); |
| 2793 | } |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2794 | |
| 2795 | /* MAC address registers are reserved for the MIC entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2796 | REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0); |
| 2797 | REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2798 | |
| 2799 | /* |
| 2800 | * Write the correct (un-inverted) key[47:0] last to enable |
| 2801 | * TKIP now that all other registers are set with correct |
| 2802 | * values. |
| 2803 | */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2804 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0); |
| 2805 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1); |
| 2806 | } else { |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2807 | /* Write key[47:0] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2808 | REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0); |
| 2809 | REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2810 | |
| 2811 | /* Write key[95:48] */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2812 | REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2); |
| 2813 | REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3); |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2814 | |
| 2815 | /* Write key[127:96] and key type */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2816 | REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4); |
| 2817 | REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType); |
| 2818 | |
Jouni Malinen | 672903b | 2009-03-02 15:06:31 +0200 | [diff] [blame] | 2819 | /* Write MAC address for the entry */ |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2820 | (void) ath9k_hw_keysetmac(ah, entry, mac); |
| 2821 | } |
| 2822 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2823 | return true; |
| 2824 | } |
| 2825 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2826 | bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2827 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2828 | if (entry < ah->caps.keycache_size) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2829 | u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry)); |
| 2830 | if (val & AR_KEYTABLE_VALID) |
| 2831 | return true; |
| 2832 | } |
| 2833 | return false; |
| 2834 | } |
| 2835 | |
| 2836 | /******************************/ |
| 2837 | /* Power Management (Chipset) */ |
| 2838 | /******************************/ |
| 2839 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2840 | static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2841 | { |
| 2842 | REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 2843 | if (setChip) { |
| 2844 | REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2845 | AR_RTC_FORCE_WAKE_EN); |
| 2846 | if (!AR_SREV_9100(ah)) |
| 2847 | REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF); |
| 2848 | |
Gabor Juhos | d03a66c | 2009-01-14 20:17:09 +0100 | [diff] [blame] | 2849 | REG_CLR_BIT(ah, (AR_RTC_RESET), |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2850 | AR_RTC_RESET_EN); |
| 2851 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2854 | 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] | 2855 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2856 | REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 2857 | if (setChip) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2858 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2859 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2860 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
| 2861 | REG_WRITE(ah, AR_RTC_FORCE_WAKE, |
| 2862 | AR_RTC_FORCE_WAKE_ON_INT); |
| 2863 | } else { |
| 2864 | REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2865 | AR_RTC_FORCE_WAKE_EN); |
| 2866 | } |
| 2867 | } |
| 2868 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2869 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2870 | static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2871 | { |
| 2872 | u32 val; |
| 2873 | int i; |
| 2874 | |
| 2875 | if (setChip) { |
| 2876 | if ((REG_READ(ah, AR_RTC_STATUS) & |
| 2877 | AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) { |
| 2878 | if (ath9k_hw_set_reset_reg(ah, |
| 2879 | ATH9K_RESET_POWER_ON) != true) { |
| 2880 | return false; |
| 2881 | } |
| 2882 | } |
| 2883 | if (AR_SREV_9100(ah)) |
| 2884 | REG_SET_BIT(ah, AR_RTC_RESET, |
| 2885 | AR_RTC_RESET_EN); |
| 2886 | |
| 2887 | REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2888 | AR_RTC_FORCE_WAKE_EN); |
| 2889 | udelay(50); |
| 2890 | |
| 2891 | for (i = POWER_UP_TIME / 50; i > 0; i--) { |
| 2892 | val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M; |
| 2893 | if (val == AR_RTC_STATUS_ON) |
| 2894 | break; |
| 2895 | udelay(50); |
| 2896 | REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, |
| 2897 | AR_RTC_FORCE_WAKE_EN); |
| 2898 | } |
| 2899 | if (i == 0) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2900 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 2901 | "Failed to wakeup in %uus\n", |
| 2902 | POWER_UP_TIME / 20); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2903 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2904 | } |
| 2905 | } |
| 2906 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2907 | REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); |
| 2908 | |
| 2909 | return true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 2912 | bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2913 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2914 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2915 | int status = true, setChip = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2916 | static const char *modes[] = { |
| 2917 | "AWAKE", |
| 2918 | "FULL-SLEEP", |
| 2919 | "NETWORK SLEEP", |
| 2920 | "UNDEFINED" |
| 2921 | }; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2922 | |
Gabor Juhos | cbdec97 | 2009-07-24 17:27:22 +0200 | [diff] [blame] | 2923 | if (ah->power_mode == mode) |
| 2924 | return status; |
| 2925 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2926 | ath_print(common, ATH_DBG_RESET, "%s -> %s\n", |
| 2927 | modes[ah->power_mode], modes[mode]); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2928 | |
| 2929 | switch (mode) { |
| 2930 | case ATH9K_PM_AWAKE: |
| 2931 | status = ath9k_hw_set_power_awake(ah, setChip); |
| 2932 | break; |
| 2933 | case ATH9K_PM_FULL_SLEEP: |
| 2934 | ath9k_set_power_sleep(ah, setChip); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2935 | ah->chip_fullsleep = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2936 | break; |
| 2937 | case ATH9K_PM_NETWORK_SLEEP: |
| 2938 | ath9k_set_power_network_sleep(ah, setChip); |
| 2939 | break; |
| 2940 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2941 | ath_print(common, ATH_DBG_FATAL, |
| 2942 | "Unknown power mode %u\n", mode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2943 | return false; |
| 2944 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2945 | ah->power_mode = mode; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2946 | |
| 2947 | return status; |
| 2948 | } |
| 2949 | |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 2950 | /* |
| 2951 | * Helper for ASPM support. |
| 2952 | * |
| 2953 | * Disable PLL when in L0s as well as receiver clock when in L1. |
| 2954 | * This power saving option must be enabled through the SerDes. |
| 2955 | * |
| 2956 | * Programming the SerDes must go through the same 288 bit serial shift |
| 2957 | * register as the other analog registers. Hence the 9 writes. |
| 2958 | */ |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2959 | void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2960 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2961 | u8 i; |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2962 | u32 val; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2963 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2964 | if (ah->is_pciexpress != true) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2965 | return; |
| 2966 | |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 2967 | /* Do not touch SerDes registers */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 2968 | if (ah->config.pcie_powersave_enable == 2) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2969 | return; |
| 2970 | |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 2971 | /* Nothing to do on restore for 11N */ |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2972 | if (!restore) { |
| 2973 | if (AR_SREV_9280_20_OR_LATER(ah)) { |
| 2974 | /* |
| 2975 | * AR9280 2.0 or later chips use SerDes values from the |
| 2976 | * initvals.h initialized depending on chipset during |
| 2977 | * ath9k_hw_init() |
| 2978 | */ |
| 2979 | for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) { |
| 2980 | REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0), |
| 2981 | INI_RA(&ah->iniPcieSerdes, i, 1)); |
| 2982 | } |
| 2983 | } else if (AR_SREV_9280(ah) && |
| 2984 | (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) { |
| 2985 | REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00); |
| 2986 | REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 2987 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 2988 | /* RX shut off when elecidle is asserted */ |
| 2989 | REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019); |
| 2990 | REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820); |
| 2991 | REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560); |
| 2992 | |
| 2993 | /* Shut off CLKREQ active in L1 */ |
| 2994 | if (ah->config.pcie_clock_req) |
| 2995 | REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc); |
| 2996 | else |
| 2997 | REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd); |
| 2998 | |
| 2999 | REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); |
| 3000 | REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); |
| 3001 | REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007); |
| 3002 | |
| 3003 | /* Load the new settings */ |
| 3004 | REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); |
| 3005 | |
| 3006 | } else { |
| 3007 | REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00); |
| 3008 | REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924); |
| 3009 | |
| 3010 | /* RX shut off when elecidle is asserted */ |
| 3011 | REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039); |
| 3012 | REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824); |
| 3013 | REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579); |
| 3014 | |
| 3015 | /* |
| 3016 | * Ignore ah->ah_config.pcie_clock_req setting for |
| 3017 | * pre-AR9280 11n |
| 3018 | */ |
| 3019 | REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff); |
| 3020 | |
| 3021 | REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40); |
| 3022 | REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554); |
| 3023 | REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007); |
| 3024 | |
| 3025 | /* Load the new settings */ |
| 3026 | REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3027 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3028 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3029 | udelay(1000); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3030 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3031 | /* set bit 19 to allow forcing of pcie core into L1 state */ |
| 3032 | REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3033 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3034 | /* Several PCIe massages to ensure proper behaviour */ |
| 3035 | if (ah->config.pcie_waen) { |
| 3036 | val = ah->config.pcie_waen; |
| 3037 | if (!power_off) |
| 3038 | val &= (~AR_WA_D3_L1_DISABLE); |
| 3039 | } else { |
| 3040 | if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || |
| 3041 | AR_SREV_9287(ah)) { |
| 3042 | val = AR9285_WA_DEFAULT; |
| 3043 | if (!power_off) |
| 3044 | val &= (~AR_WA_D3_L1_DISABLE); |
| 3045 | } else if (AR_SREV_9280(ah)) { |
| 3046 | /* |
| 3047 | * On AR9280 chips bit 22 of 0x4004 needs to be |
| 3048 | * set otherwise card may disappear. |
| 3049 | */ |
| 3050 | val = AR9280_WA_DEFAULT; |
| 3051 | if (!power_off) |
| 3052 | val &= (~AR_WA_D3_L1_DISABLE); |
| 3053 | } else |
| 3054 | val = AR_WA_DEFAULT; |
| 3055 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3056 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3057 | REG_WRITE(ah, AR_WA, val); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3058 | } |
| 3059 | |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3060 | if (power_off) { |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 3061 | /* |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3062 | * Set PCIe workaround bits |
| 3063 | * bit 14 in WA register (disable L1) should only |
| 3064 | * be set when device enters D3 and be cleared |
| 3065 | * when device comes back to D0. |
Luis R. Rodriguez | 24c1a28 | 2009-02-10 15:35:22 -0800 | [diff] [blame] | 3066 | */ |
Vivek Natarajan | 93b1b37 | 2009-09-17 09:24:58 +0530 | [diff] [blame] | 3067 | if (ah->config.pcie_waen) { |
| 3068 | if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE) |
| 3069 | REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE); |
| 3070 | } else { |
| 3071 | if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) || |
| 3072 | AR_SREV_9287(ah)) && |
| 3073 | (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) || |
| 3074 | (AR_SREV_9280(ah) && |
| 3075 | (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) { |
| 3076 | REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE); |
| 3077 | } |
| 3078 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3079 | } |
| 3080 | } |
| 3081 | |
| 3082 | /**********************/ |
| 3083 | /* Interrupt Handling */ |
| 3084 | /**********************/ |
| 3085 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3086 | bool ath9k_hw_intrpend(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3087 | { |
| 3088 | u32 host_isr; |
| 3089 | |
| 3090 | if (AR_SREV_9100(ah)) |
| 3091 | return true; |
| 3092 | |
| 3093 | host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE); |
| 3094 | if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS)) |
| 3095 | return true; |
| 3096 | |
| 3097 | host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE); |
| 3098 | if ((host_isr & AR_INTR_SYNC_DEFAULT) |
| 3099 | && (host_isr != AR_INTR_SPURIOUS)) |
| 3100 | return true; |
| 3101 | |
| 3102 | return false; |
| 3103 | } |
| 3104 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3105 | bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3106 | { |
| 3107 | u32 isr = 0; |
| 3108 | u32 mask2 = 0; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3109 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3110 | u32 sync_cause = 0; |
| 3111 | bool fatal_int = false; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3112 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3113 | |
| 3114 | if (!AR_SREV_9100(ah)) { |
| 3115 | if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) { |
| 3116 | if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M) |
| 3117 | == AR_RTC_STATUS_ON) { |
| 3118 | isr = REG_READ(ah, AR_ISR); |
| 3119 | } |
| 3120 | } |
| 3121 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3122 | sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) & |
| 3123 | AR_INTR_SYNC_DEFAULT; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3124 | |
| 3125 | *masked = 0; |
| 3126 | |
| 3127 | if (!isr && !sync_cause) |
| 3128 | return false; |
| 3129 | } else { |
| 3130 | *masked = 0; |
| 3131 | isr = REG_READ(ah, AR_ISR); |
| 3132 | } |
| 3133 | |
| 3134 | if (isr) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3135 | if (isr & AR_ISR_BCNMISC) { |
| 3136 | u32 isr2; |
| 3137 | isr2 = REG_READ(ah, AR_ISR_S2); |
| 3138 | if (isr2 & AR_ISR_S2_TIM) |
| 3139 | mask2 |= ATH9K_INT_TIM; |
| 3140 | if (isr2 & AR_ISR_S2_DTIM) |
| 3141 | mask2 |= ATH9K_INT_DTIM; |
| 3142 | if (isr2 & AR_ISR_S2_DTIMSYNC) |
| 3143 | mask2 |= ATH9K_INT_DTIMSYNC; |
| 3144 | if (isr2 & (AR_ISR_S2_CABEND)) |
| 3145 | mask2 |= ATH9K_INT_CABEND; |
| 3146 | if (isr2 & AR_ISR_S2_GTT) |
| 3147 | mask2 |= ATH9K_INT_GTT; |
| 3148 | if (isr2 & AR_ISR_S2_CST) |
| 3149 | mask2 |= ATH9K_INT_CST; |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 3150 | if (isr2 & AR_ISR_S2_TSFOOR) |
| 3151 | mask2 |= ATH9K_INT_TSFOOR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | isr = REG_READ(ah, AR_ISR_RAC); |
| 3155 | if (isr == 0xffffffff) { |
| 3156 | *masked = 0; |
| 3157 | return false; |
| 3158 | } |
| 3159 | |
| 3160 | *masked = isr & ATH9K_INT_COMMON; |
| 3161 | |
Sujith | 0ef1f16 | 2009-03-30 15:28:35 +0530 | [diff] [blame] | 3162 | if (ah->config.intr_mitigation) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3163 | if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM)) |
| 3164 | *masked |= ATH9K_INT_RX; |
| 3165 | } |
| 3166 | |
| 3167 | if (isr & (AR_ISR_RXOK | AR_ISR_RXERR)) |
| 3168 | *masked |= ATH9K_INT_RX; |
| 3169 | if (isr & |
| 3170 | (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR | |
| 3171 | AR_ISR_TXEOL)) { |
| 3172 | u32 s0_s, s1_s; |
| 3173 | |
| 3174 | *masked |= ATH9K_INT_TX; |
| 3175 | |
| 3176 | s0_s = REG_READ(ah, AR_ISR_S0_S); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3177 | ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK); |
| 3178 | ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3179 | |
| 3180 | s1_s = REG_READ(ah, AR_ISR_S1_S); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3181 | ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR); |
| 3182 | ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | if (isr & AR_ISR_RXORN) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3186 | ath_print(common, ATH_DBG_INTERRUPT, |
| 3187 | "receive FIFO overrun interrupt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3188 | } |
| 3189 | |
| 3190 | if (!AR_SREV_9100(ah)) { |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3191 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3192 | u32 isr5 = REG_READ(ah, AR_ISR_S5_S); |
| 3193 | if (isr5 & AR_ISR_S5_TIM_TIMER) |
| 3194 | *masked |= ATH9K_INT_TIM_TIMER; |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | *masked |= mask2; |
| 3199 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3200 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3201 | if (AR_SREV_9100(ah)) |
| 3202 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3203 | |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 3204 | if (isr & AR_ISR_GENTMR) { |
| 3205 | u32 s5_s; |
| 3206 | |
| 3207 | s5_s = REG_READ(ah, AR_ISR_S5_S); |
| 3208 | if (isr & AR_ISR_GENTMR) { |
| 3209 | ah->intr_gen_timer_trigger = |
| 3210 | MS(s5_s, AR_ISR_S5_GENTIMER_TRIG); |
| 3211 | |
| 3212 | ah->intr_gen_timer_thresh = |
| 3213 | MS(s5_s, AR_ISR_S5_GENTIMER_THRESH); |
| 3214 | |
| 3215 | if (ah->intr_gen_timer_trigger) |
| 3216 | *masked |= ATH9K_INT_GENTIMER; |
| 3217 | |
| 3218 | } |
| 3219 | } |
| 3220 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3221 | if (sync_cause) { |
| 3222 | fatal_int = |
| 3223 | (sync_cause & |
| 3224 | (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR)) |
| 3225 | ? true : false; |
| 3226 | |
| 3227 | if (fatal_int) { |
| 3228 | if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3229 | ath_print(common, ATH_DBG_ANY, |
| 3230 | "received PCI FATAL interrupt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3231 | } |
| 3232 | if (sync_cause & AR_INTR_SYNC_HOST1_PERR) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3233 | ath_print(common, ATH_DBG_ANY, |
| 3234 | "received PCI PERR interrupt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3235 | } |
Steven Luo | a89bff9 | 2009-04-12 02:57:54 -0700 | [diff] [blame] | 3236 | *masked |= ATH9K_INT_FATAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3237 | } |
| 3238 | if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3239 | ath_print(common, ATH_DBG_INTERRUPT, |
| 3240 | "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3241 | REG_WRITE(ah, AR_RC, AR_RC_HOSTIF); |
| 3242 | REG_WRITE(ah, AR_RC, 0); |
| 3243 | *masked |= ATH9K_INT_FATAL; |
| 3244 | } |
| 3245 | if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3246 | ath_print(common, ATH_DBG_INTERRUPT, |
| 3247 | "AR_INTR_SYNC_LOCAL_TIMEOUT\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause); |
| 3251 | (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR); |
| 3252 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3253 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3254 | return true; |
| 3255 | } |
| 3256 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3257 | enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3258 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3259 | u32 omask = ah->mask_reg; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3260 | u32 mask, mask2; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3261 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3262 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3263 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3264 | ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3265 | |
| 3266 | if (omask & ATH9K_INT_GLOBAL) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3267 | ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3268 | REG_WRITE(ah, AR_IER, AR_IER_DISABLE); |
| 3269 | (void) REG_READ(ah, AR_IER); |
| 3270 | if (!AR_SREV_9100(ah)) { |
| 3271 | REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0); |
| 3272 | (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE); |
| 3273 | |
| 3274 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0); |
| 3275 | (void) REG_READ(ah, AR_INTR_SYNC_ENABLE); |
| 3276 | } |
| 3277 | } |
| 3278 | |
| 3279 | mask = ints & ATH9K_INT_COMMON; |
| 3280 | mask2 = 0; |
| 3281 | |
| 3282 | if (ints & ATH9K_INT_TX) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3283 | if (ah->txok_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3284 | mask |= AR_IMR_TXOK; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3285 | if (ah->txdesc_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3286 | mask |= AR_IMR_TXDESC; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3287 | if (ah->txerr_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3288 | mask |= AR_IMR_TXERR; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3289 | if (ah->txeol_interrupt_mask) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3290 | mask |= AR_IMR_TXEOL; |
| 3291 | } |
| 3292 | if (ints & ATH9K_INT_RX) { |
| 3293 | mask |= AR_IMR_RXERR; |
Sujith | 0ef1f16 | 2009-03-30 15:28:35 +0530 | [diff] [blame] | 3294 | if (ah->config.intr_mitigation) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3295 | mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM; |
| 3296 | else |
| 3297 | mask |= AR_IMR_RXOK | AR_IMR_RXDESC; |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3298 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3299 | mask |= AR_IMR_GENTMR; |
| 3300 | } |
| 3301 | |
| 3302 | if (ints & (ATH9K_INT_BMISC)) { |
| 3303 | mask |= AR_IMR_BCNMISC; |
| 3304 | if (ints & ATH9K_INT_TIM) |
| 3305 | mask2 |= AR_IMR_S2_TIM; |
| 3306 | if (ints & ATH9K_INT_DTIM) |
| 3307 | mask2 |= AR_IMR_S2_DTIM; |
| 3308 | if (ints & ATH9K_INT_DTIMSYNC) |
| 3309 | mask2 |= AR_IMR_S2_DTIMSYNC; |
| 3310 | if (ints & ATH9K_INT_CABEND) |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 3311 | mask2 |= AR_IMR_S2_CABEND; |
| 3312 | if (ints & ATH9K_INT_TSFOOR) |
| 3313 | mask2 |= AR_IMR_S2_TSFOOR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) { |
| 3317 | mask |= AR_IMR_BCNMISC; |
| 3318 | if (ints & ATH9K_INT_GTT) |
| 3319 | mask2 |= AR_IMR_S2_GTT; |
| 3320 | if (ints & ATH9K_INT_CST) |
| 3321 | mask2 |= AR_IMR_S2_CST; |
| 3322 | } |
| 3323 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3324 | ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3325 | REG_WRITE(ah, AR_IMR, mask); |
| 3326 | mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM | |
| 3327 | AR_IMR_S2_DTIM | |
| 3328 | AR_IMR_S2_DTIMSYNC | |
| 3329 | AR_IMR_S2_CABEND | |
| 3330 | AR_IMR_S2_CABTO | |
| 3331 | AR_IMR_S2_TSFOOR | |
| 3332 | AR_IMR_S2_GTT | AR_IMR_S2_CST); |
| 3333 | REG_WRITE(ah, AR_IMR_S2, mask | mask2); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3334 | ah->mask_reg = ints; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3335 | |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3336 | if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3337 | if (ints & ATH9K_INT_TIM_TIMER) |
| 3338 | REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER); |
| 3339 | else |
| 3340 | REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER); |
| 3341 | } |
| 3342 | |
| 3343 | if (ints & ATH9K_INT_GLOBAL) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3344 | ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3345 | REG_WRITE(ah, AR_IER, AR_IER_ENABLE); |
| 3346 | if (!AR_SREV_9100(ah)) { |
| 3347 | REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, |
| 3348 | AR_INTR_MAC_IRQ); |
| 3349 | REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ); |
| 3350 | |
| 3351 | |
| 3352 | REG_WRITE(ah, AR_INTR_SYNC_ENABLE, |
| 3353 | AR_INTR_SYNC_DEFAULT); |
| 3354 | REG_WRITE(ah, AR_INTR_SYNC_MASK, |
| 3355 | AR_INTR_SYNC_DEFAULT); |
| 3356 | } |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3357 | ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n", |
| 3358 | REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | return omask; |
| 3362 | } |
| 3363 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3364 | /*******************/ |
| 3365 | /* Beacon Handling */ |
| 3366 | /*******************/ |
| 3367 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3368 | 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] | 3369 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3370 | int flags = 0; |
| 3371 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3372 | ah->beacon_interval = beacon_period; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3373 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3374 | switch (ah->opmode) { |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 3375 | case NL80211_IFTYPE_STATION: |
| 3376 | case NL80211_IFTYPE_MONITOR: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3377 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon)); |
| 3378 | REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff); |
| 3379 | REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff); |
| 3380 | flags |= AR_TBTT_TIMER_EN; |
| 3381 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 3382 | case NL80211_IFTYPE_ADHOC: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 3383 | case NL80211_IFTYPE_MESH_POINT: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3384 | REG_SET_BIT(ah, AR_TXCFG, |
| 3385 | AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY); |
| 3386 | REG_WRITE(ah, AR_NEXT_NDP_TIMER, |
| 3387 | TU_TO_USEC(next_beacon + |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3388 | (ah->atim_window ? ah-> |
| 3389 | atim_window : 1))); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3390 | flags |= AR_NDP_TIMER_EN; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 3391 | case NL80211_IFTYPE_AP: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3392 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon)); |
| 3393 | REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, |
| 3394 | TU_TO_USEC(next_beacon - |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3395 | ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3396 | dma_beacon_response_time)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3397 | REG_WRITE(ah, AR_NEXT_SWBA, |
| 3398 | TU_TO_USEC(next_beacon - |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3399 | ah->config. |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3400 | sw_beacon_response_time)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3401 | flags |= |
| 3402 | AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN; |
| 3403 | break; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 3404 | default: |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3405 | ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON, |
| 3406 | "%s: unsupported opmode: %d\n", |
| 3407 | __func__, ah->opmode); |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 3408 | return; |
| 3409 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period)); |
| 3413 | REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period)); |
| 3414 | REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period)); |
| 3415 | REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period)); |
| 3416 | |
| 3417 | beacon_period &= ~ATH9K_BEACON_ENA; |
| 3418 | if (beacon_period & ATH9K_BEACON_RESET_TSF) { |
| 3419 | beacon_period &= ~ATH9K_BEACON_RESET_TSF; |
| 3420 | ath9k_hw_reset_tsf(ah); |
| 3421 | } |
| 3422 | |
| 3423 | REG_SET_BIT(ah, AR_TIMER_MODE, flags); |
| 3424 | } |
| 3425 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3426 | void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3427 | const struct ath9k_beacon_state *bs) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3428 | { |
| 3429 | u32 nextTbtt, beaconintval, dtimperiod, beacontimeout; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3430 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3431 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3432 | |
| 3433 | REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt)); |
| 3434 | |
| 3435 | REG_WRITE(ah, AR_BEACON_PERIOD, |
| 3436 | TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD)); |
| 3437 | REG_WRITE(ah, AR_DMA_BEACON_PERIOD, |
| 3438 | TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD)); |
| 3439 | |
| 3440 | REG_RMW_FIELD(ah, AR_RSSI_THR, |
| 3441 | AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold); |
| 3442 | |
| 3443 | beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD; |
| 3444 | |
| 3445 | if (bs->bs_sleepduration > beaconintval) |
| 3446 | beaconintval = bs->bs_sleepduration; |
| 3447 | |
| 3448 | dtimperiod = bs->bs_dtimperiod; |
| 3449 | if (bs->bs_sleepduration > dtimperiod) |
| 3450 | dtimperiod = bs->bs_sleepduration; |
| 3451 | |
| 3452 | if (beaconintval == dtimperiod) |
| 3453 | nextTbtt = bs->bs_nextdtim; |
| 3454 | else |
| 3455 | nextTbtt = bs->bs_nexttbtt; |
| 3456 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3457 | ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim); |
| 3458 | ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt); |
| 3459 | ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval); |
| 3460 | ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3461 | |
| 3462 | REG_WRITE(ah, AR_NEXT_DTIM, |
| 3463 | TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP)); |
| 3464 | REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP)); |
| 3465 | |
| 3466 | REG_WRITE(ah, AR_SLEEP1, |
| 3467 | SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT) |
| 3468 | | AR_SLEEP1_ASSUME_DTIM); |
| 3469 | |
Sujith | 60b67f5 | 2008-08-07 10:52:38 +0530 | [diff] [blame] | 3470 | if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3471 | beacontimeout = (BEACON_TIMEOUT_VAL << 3); |
| 3472 | else |
| 3473 | beacontimeout = MIN_BEACON_TIMEOUT_VAL; |
| 3474 | |
| 3475 | REG_WRITE(ah, AR_SLEEP2, |
| 3476 | SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT)); |
| 3477 | |
| 3478 | REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval)); |
| 3479 | REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod)); |
| 3480 | |
| 3481 | REG_SET_BIT(ah, AR_TIMER_MODE, |
| 3482 | AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN | |
| 3483 | AR_DTIM_TIMER_EN); |
| 3484 | |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 3485 | /* TSF Out of Range Threshold */ |
| 3486 | REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3487 | } |
| 3488 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3489 | /*******************/ |
| 3490 | /* HW Capabilities */ |
| 3491 | /*******************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3492 | |
Sujith | eef7a57 | 2009-03-30 15:28:28 +0530 | [diff] [blame] | 3493 | void ath9k_hw_fill_cap_info(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3494 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3495 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3496 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3497 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 3498 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3499 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3500 | u16 capField = 0, eeval; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3501 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3502 | eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0); |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3503 | regulatory->current_rd = eeval; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3504 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3505 | eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1); |
Sujith | fec0de1 | 2009-02-12 10:06:43 +0530 | [diff] [blame] | 3506 | if (AR_SREV_9285_10_OR_LATER(ah)) |
| 3507 | eeval |= AR9285_RDEXT_DEFAULT; |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3508 | regulatory->current_rd_ext = eeval; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3509 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3510 | capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3511 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3512 | if (ah->opmode != NL80211_IFTYPE_AP && |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 3513 | ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3514 | if (regulatory->current_rd == 0x64 || |
| 3515 | regulatory->current_rd == 0x65) |
| 3516 | regulatory->current_rd += 5; |
| 3517 | else if (regulatory->current_rd == 0x41) |
| 3518 | regulatory->current_rd = 0x43; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 3519 | ath_print(common, ATH_DBG_REGULATORY, |
| 3520 | "regdomain mapped to 0x%x\n", regulatory->current_rd); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3521 | } |
Sujith | dc2222a | 2008-08-14 13:26:55 +0530 | [diff] [blame] | 3522 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3523 | eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3524 | bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3525 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3526 | if (eeval & AR5416_OPFLAGS_11A) { |
| 3527 | set_bit(ATH9K_MODE_11A, pCap->wireless_modes); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3528 | if (ah->config.ht_enable) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3529 | if (!(eeval & AR5416_OPFLAGS_N_5G_HT20)) |
| 3530 | set_bit(ATH9K_MODE_11NA_HT20, |
| 3531 | pCap->wireless_modes); |
| 3532 | if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) { |
| 3533 | set_bit(ATH9K_MODE_11NA_HT40PLUS, |
| 3534 | pCap->wireless_modes); |
| 3535 | set_bit(ATH9K_MODE_11NA_HT40MINUS, |
| 3536 | pCap->wireless_modes); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3537 | } |
| 3538 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3539 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3540 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3541 | if (eeval & AR5416_OPFLAGS_11G) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3542 | set_bit(ATH9K_MODE_11G, pCap->wireless_modes); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3543 | if (ah->config.ht_enable) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3544 | if (!(eeval & AR5416_OPFLAGS_N_2G_HT20)) |
| 3545 | set_bit(ATH9K_MODE_11NG_HT20, |
| 3546 | pCap->wireless_modes); |
| 3547 | if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) { |
| 3548 | set_bit(ATH9K_MODE_11NG_HT40PLUS, |
| 3549 | pCap->wireless_modes); |
| 3550 | set_bit(ATH9K_MODE_11NG_HT40MINUS, |
| 3551 | pCap->wireless_modes); |
| 3552 | } |
| 3553 | } |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 3554 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3555 | |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3556 | 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] | 3557 | /* |
| 3558 | * For AR9271 we will temporarilly uses the rx chainmax as read from |
| 3559 | * the EEPROM. |
| 3560 | */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 3561 | if ((ah->hw_version.devid == AR5416_DEVID_PCI) && |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 3562 | !(eeval & AR5416_OPFLAGS_11A) && |
| 3563 | !(AR_SREV_9271(ah))) |
| 3564 | /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 3565 | pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7; |
| 3566 | else |
Luis R. Rodriguez | d7e7d22 | 2009-08-03 23:14:12 -0400 | [diff] [blame] | 3567 | /* Use rx_chainmask from EEPROM. */ |
Sujith | 8147f5d | 2009-02-20 15:13:23 +0530 | [diff] [blame] | 3568 | pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3569 | |
Sujith | d535a42 | 2009-02-09 13:27:06 +0530 | [diff] [blame] | 3570 | if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0))) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3571 | ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3572 | |
| 3573 | pCap->low_2ghz_chan = 2312; |
| 3574 | pCap->high_2ghz_chan = 2732; |
| 3575 | |
| 3576 | pCap->low_5ghz_chan = 4920; |
| 3577 | pCap->high_5ghz_chan = 6100; |
| 3578 | |
| 3579 | pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP; |
| 3580 | pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP; |
| 3581 | pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM; |
| 3582 | |
| 3583 | pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP; |
| 3584 | pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP; |
| 3585 | pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM; |
| 3586 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3587 | if (ah->config.ht_enable) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3588 | pCap->hw_caps |= ATH9K_HW_CAP_HT; |
| 3589 | else |
| 3590 | pCap->hw_caps &= ~ATH9K_HW_CAP_HT; |
| 3591 | |
| 3592 | pCap->hw_caps |= ATH9K_HW_CAP_GTT; |
| 3593 | pCap->hw_caps |= ATH9K_HW_CAP_VEOL; |
| 3594 | pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK; |
| 3595 | pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH; |
| 3596 | |
| 3597 | if (capField & AR_EEPROM_EEPCAP_MAXQCU) |
| 3598 | pCap->total_queues = |
| 3599 | MS(capField, AR_EEPROM_EEPCAP_MAXQCU); |
| 3600 | else |
| 3601 | pCap->total_queues = ATH9K_NUM_TX_QUEUES; |
| 3602 | |
| 3603 | if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES) |
| 3604 | pCap->keycache_size = |
| 3605 | 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES); |
| 3606 | else |
| 3607 | pCap->keycache_size = AR_KEYTABLE_SIZE; |
| 3608 | |
| 3609 | pCap->hw_caps |= ATH9K_HW_CAP_FASTCC; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3610 | pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD; |
| 3611 | |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 3612 | if (AR_SREV_9285_10_OR_LATER(ah)) |
| 3613 | pCap->num_gpio_pins = AR9285_NUM_GPIO; |
| 3614 | else if (AR_SREV_9280_10_OR_LATER(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3615 | pCap->num_gpio_pins = AR928X_NUM_GPIO; |
| 3616 | else |
| 3617 | pCap->num_gpio_pins = AR_NUM_GPIO; |
| 3618 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3619 | if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) { |
| 3620 | pCap->hw_caps |= ATH9K_HW_CAP_CST; |
| 3621 | pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX; |
| 3622 | } else { |
| 3623 | pCap->rts_aggr_limit = (8 * 1024); |
| 3624 | } |
| 3625 | |
| 3626 | pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM; |
| 3627 | |
Senthil Balasubramanian | e97275c | 2008-11-13 18:00:02 +0530 | [diff] [blame] | 3628 | #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3629 | ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT); |
| 3630 | if (ah->rfsilent & EEP_RFSILENT_ENABLED) { |
| 3631 | ah->rfkill_gpio = |
| 3632 | MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL); |
| 3633 | ah->rfkill_polarity = |
| 3634 | MS(ah->rfsilent, EEP_RFSILENT_POLARITY); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3635 | |
| 3636 | pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT; |
| 3637 | } |
| 3638 | #endif |
| 3639 | |
Vivek Natarajan | a3ca95fb | 2009-09-17 09:29:07 +0530 | [diff] [blame] | 3640 | pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3641 | |
Senthil Balasubramanian | e759407 | 2008-12-08 19:43:48 +0530 | [diff] [blame] | 3642 | if (AR_SREV_9280(ah) || AR_SREV_9285(ah)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3643 | pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS; |
| 3644 | else |
| 3645 | pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS; |
| 3646 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3647 | if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3648 | pCap->reg_cap = |
| 3649 | AR_EEPROM_EEREGCAP_EN_KK_NEW_11A | |
| 3650 | AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN | |
| 3651 | AR_EEPROM_EEREGCAP_EN_KK_U2 | |
| 3652 | AR_EEPROM_EEREGCAP_EN_KK_MIDBAND; |
| 3653 | } else { |
| 3654 | pCap->reg_cap = |
| 3655 | AR_EEPROM_EEREGCAP_EN_KK_NEW_11A | |
| 3656 | AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN; |
| 3657 | } |
| 3658 | |
| 3659 | pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND; |
| 3660 | |
| 3661 | pCap->num_antcfg_5ghz = |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3662 | ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3663 | pCap->num_antcfg_2ghz = |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 3664 | ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3665 | |
Vasanthakumar Thiagarajan | fe12946 | 2009-09-09 15:25:50 +0530 | [diff] [blame] | 3666 | if (AR_SREV_9280_10_OR_LATER(ah) && |
Luis R. Rodriguez | a36cfbc | 2009-09-09 16:05:32 -0700 | [diff] [blame] | 3667 | ath9k_hw_btcoex_supported(ah)) { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 3668 | btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO; |
| 3669 | btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO; |
Vasanthakumar Thiagarajan | 22f25d0 | 2009-08-26 21:08:47 +0530 | [diff] [blame] | 3670 | |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 3671 | if (AR_SREV_9285(ah)) { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 3672 | btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE; |
| 3673 | btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO; |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 3674 | } else { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 3675 | btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE; |
Vasanthakumar Thiagarajan | 8c8f9ba | 2009-09-09 15:25:52 +0530 | [diff] [blame] | 3676 | } |
Vasanthakumar Thiagarajan | 22f25d0 | 2009-08-26 21:08:47 +0530 | [diff] [blame] | 3677 | } else { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 3678 | btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE; |
Vasanthakumar Thiagarajan | c97c92d | 2009-01-02 15:35:46 +0530 | [diff] [blame] | 3679 | } |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 3680 | } |
| 3681 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3682 | bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3683 | u32 capability, u32 *result) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3684 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3685 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3686 | switch (type) { |
| 3687 | case ATH9K_CAP_CIPHER: |
| 3688 | switch (capability) { |
| 3689 | case ATH9K_CIPHER_AES_CCM: |
| 3690 | case ATH9K_CIPHER_AES_OCB: |
| 3691 | case ATH9K_CIPHER_TKIP: |
| 3692 | case ATH9K_CIPHER_WEP: |
| 3693 | case ATH9K_CIPHER_MIC: |
| 3694 | case ATH9K_CIPHER_CLR: |
| 3695 | return true; |
| 3696 | default: |
| 3697 | return false; |
| 3698 | } |
| 3699 | case ATH9K_CAP_TKIP_MIC: |
| 3700 | switch (capability) { |
| 3701 | case 0: |
| 3702 | return true; |
| 3703 | case 1: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3704 | return (ah->sta_id1_defaults & |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3705 | AR_STA_ID1_CRPT_MIC_ENABLE) ? true : |
| 3706 | false; |
| 3707 | } |
| 3708 | case ATH9K_CAP_TKIP_SPLIT: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3709 | return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ? |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3710 | false : true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3711 | case ATH9K_CAP_DIVERSITY: |
| 3712 | return (REG_READ(ah, AR_PHY_CCK_DETECT) & |
| 3713 | AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ? |
| 3714 | true : false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3715 | case ATH9K_CAP_MCAST_KEYSRCH: |
| 3716 | switch (capability) { |
| 3717 | case 0: |
| 3718 | return true; |
| 3719 | case 1: |
| 3720 | if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) { |
| 3721 | return false; |
| 3722 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3723 | return (ah->sta_id1_defaults & |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3724 | AR_STA_ID1_MCAST_KSRCH) ? true : |
| 3725 | false; |
| 3726 | } |
| 3727 | } |
| 3728 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3729 | case ATH9K_CAP_TXPOW: |
| 3730 | switch (capability) { |
| 3731 | case 0: |
| 3732 | return 0; |
| 3733 | case 1: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3734 | *result = regulatory->power_limit; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3735 | return 0; |
| 3736 | case 2: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3737 | *result = regulatory->max_power_level; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3738 | return 0; |
| 3739 | case 3: |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3740 | *result = regulatory->tp_scale; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3741 | return 0; |
| 3742 | } |
| 3743 | return false; |
Senthil Balasubramanian | 8bd1d07 | 2009-02-12 13:57:03 +0530 | [diff] [blame] | 3744 | case ATH9K_CAP_DS: |
| 3745 | return (AR_SREV_9280_20_OR_LATER(ah) && |
| 3746 | (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1)) |
| 3747 | ? false : true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3748 | default: |
| 3749 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3750 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3751 | } |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 3752 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3753 | bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3754 | u32 capability, u32 setting, int *status) |
| 3755 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3756 | u32 v; |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 3757 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3758 | switch (type) { |
| 3759 | case ATH9K_CAP_TKIP_MIC: |
| 3760 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3761 | ah->sta_id1_defaults |= |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3762 | AR_STA_ID1_CRPT_MIC_ENABLE; |
| 3763 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3764 | ah->sta_id1_defaults &= |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3765 | ~AR_STA_ID1_CRPT_MIC_ENABLE; |
| 3766 | return true; |
| 3767 | case ATH9K_CAP_DIVERSITY: |
| 3768 | v = REG_READ(ah, AR_PHY_CCK_DETECT); |
| 3769 | if (setting) |
| 3770 | v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV; |
| 3771 | else |
| 3772 | v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV; |
| 3773 | REG_WRITE(ah, AR_PHY_CCK_DETECT, v); |
| 3774 | return true; |
| 3775 | case ATH9K_CAP_MCAST_KEYSRCH: |
| 3776 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3777 | ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3778 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3779 | ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3780 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3781 | default: |
| 3782 | return false; |
| 3783 | } |
| 3784 | } |
| 3785 | |
| 3786 | /****************************/ |
| 3787 | /* GPIO / RFKILL / Antennae */ |
| 3788 | /****************************/ |
| 3789 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3790 | static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3791 | u32 gpio, u32 type) |
| 3792 | { |
| 3793 | int addr; |
| 3794 | u32 gpio_shift, tmp; |
| 3795 | |
| 3796 | if (gpio > 11) |
| 3797 | addr = AR_GPIO_OUTPUT_MUX3; |
| 3798 | else if (gpio > 5) |
| 3799 | addr = AR_GPIO_OUTPUT_MUX2; |
| 3800 | else |
| 3801 | addr = AR_GPIO_OUTPUT_MUX1; |
| 3802 | |
| 3803 | gpio_shift = (gpio % 6) * 5; |
| 3804 | |
| 3805 | if (AR_SREV_9280_20_OR_LATER(ah) |
| 3806 | || (addr != AR_GPIO_OUTPUT_MUX1)) { |
| 3807 | REG_RMW(ah, addr, (type << gpio_shift), |
| 3808 | (0x1f << gpio_shift)); |
| 3809 | } else { |
| 3810 | tmp = REG_READ(ah, addr); |
| 3811 | tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0); |
| 3812 | tmp &= ~(0x1f << gpio_shift); |
| 3813 | tmp |= (type << gpio_shift); |
| 3814 | REG_WRITE(ah, addr, tmp); |
| 3815 | } |
| 3816 | } |
| 3817 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3818 | void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3819 | { |
| 3820 | u32 gpio_shift; |
| 3821 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3822 | ASSERT(gpio < ah->caps.num_gpio_pins); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3823 | |
| 3824 | gpio_shift = gpio << 1; |
| 3825 | |
| 3826 | REG_RMW(ah, |
| 3827 | AR_GPIO_OE_OUT, |
| 3828 | (AR_GPIO_OE_OUT_DRV_NO << gpio_shift), |
| 3829 | (AR_GPIO_OE_OUT_DRV << gpio_shift)); |
| 3830 | } |
| 3831 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3832 | u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3833 | { |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 3834 | #define MS_REG_READ(x, y) \ |
| 3835 | (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y))) |
| 3836 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3837 | if (gpio >= ah->caps.num_gpio_pins) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3838 | return 0xffffffff; |
| 3839 | |
Vivek Natarajan | ac88b6e | 2009-07-23 10:59:57 +0530 | [diff] [blame] | 3840 | if (AR_SREV_9287_10_OR_LATER(ah)) |
| 3841 | return MS_REG_READ(AR9287, gpio) != 0; |
| 3842 | else if (AR_SREV_9285_10_OR_LATER(ah)) |
Senthil Balasubramanian | cb33c41 | 2008-12-24 18:03:58 +0530 | [diff] [blame] | 3843 | return MS_REG_READ(AR9285, gpio) != 0; |
| 3844 | else if (AR_SREV_9280_10_OR_LATER(ah)) |
| 3845 | return MS_REG_READ(AR928X, gpio) != 0; |
| 3846 | else |
| 3847 | return MS_REG_READ(AR, gpio) != 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3848 | } |
| 3849 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3850 | void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3851 | u32 ah_signal_type) |
| 3852 | { |
| 3853 | u32 gpio_shift; |
| 3854 | |
| 3855 | ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type); |
| 3856 | |
| 3857 | gpio_shift = 2 * gpio; |
| 3858 | |
| 3859 | REG_RMW(ah, |
| 3860 | AR_GPIO_OE_OUT, |
| 3861 | (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift), |
| 3862 | (AR_GPIO_OE_OUT_DRV << gpio_shift)); |
| 3863 | } |
| 3864 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3865 | void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3866 | { |
| 3867 | REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio), |
| 3868 | AR_GPIO_BIT(gpio)); |
| 3869 | } |
| 3870 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3871 | u32 ath9k_hw_getdefantenna(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3872 | { |
| 3873 | return REG_READ(ah, AR_DEF_ANTENNA) & 0x7; |
| 3874 | } |
| 3875 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3876 | void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3877 | { |
| 3878 | REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7)); |
| 3879 | } |
| 3880 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3881 | bool ath9k_hw_setantennaswitch(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3882 | enum ath9k_ant_setting settings, |
| 3883 | struct ath9k_channel *chan, |
| 3884 | u8 *tx_chainmask, |
| 3885 | u8 *rx_chainmask, |
| 3886 | u8 *antenna_cfgd) |
| 3887 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3888 | static u8 tx_chainmask_cfg, rx_chainmask_cfg; |
| 3889 | |
| 3890 | if (AR_SREV_9280(ah)) { |
| 3891 | if (!tx_chainmask_cfg) { |
| 3892 | |
| 3893 | tx_chainmask_cfg = *tx_chainmask; |
| 3894 | rx_chainmask_cfg = *rx_chainmask; |
| 3895 | } |
| 3896 | |
| 3897 | switch (settings) { |
| 3898 | case ATH9K_ANT_FIXED_A: |
| 3899 | *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK; |
| 3900 | *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK; |
| 3901 | *antenna_cfgd = true; |
| 3902 | break; |
| 3903 | case ATH9K_ANT_FIXED_B: |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3904 | if (ah->caps.tx_chainmask > |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3905 | ATH9K_ANTENNA1_CHAINMASK) { |
| 3906 | *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK; |
| 3907 | } |
| 3908 | *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK; |
| 3909 | *antenna_cfgd = true; |
| 3910 | break; |
| 3911 | case ATH9K_ANT_VARIABLE: |
| 3912 | *tx_chainmask = tx_chainmask_cfg; |
| 3913 | *rx_chainmask = rx_chainmask_cfg; |
| 3914 | *antenna_cfgd = true; |
| 3915 | break; |
| 3916 | default: |
| 3917 | break; |
| 3918 | } |
| 3919 | } else { |
Sujith | 1cf6873 | 2009-08-13 09:34:32 +0530 | [diff] [blame] | 3920 | ah->config.diversity_control = settings; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | return true; |
| 3924 | } |
| 3925 | |
| 3926 | /*********************/ |
| 3927 | /* General Operation */ |
| 3928 | /*********************/ |
| 3929 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3930 | u32 ath9k_hw_getrxfilter(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3931 | { |
| 3932 | u32 bits = REG_READ(ah, AR_RX_FILTER); |
| 3933 | u32 phybits = REG_READ(ah, AR_PHY_ERR); |
| 3934 | |
| 3935 | if (phybits & AR_PHY_ERR_RADAR) |
| 3936 | bits |= ATH9K_RX_FILTER_PHYRADAR; |
| 3937 | if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING)) |
| 3938 | bits |= ATH9K_RX_FILTER_PHYERR; |
| 3939 | |
| 3940 | return bits; |
| 3941 | } |
| 3942 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3943 | void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3944 | { |
| 3945 | u32 phybits; |
| 3946 | |
Sujith | 7ea310b | 2009-09-03 12:08:43 +0530 | [diff] [blame] | 3947 | REG_WRITE(ah, AR_RX_FILTER, bits); |
| 3948 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3949 | phybits = 0; |
| 3950 | if (bits & ATH9K_RX_FILTER_PHYRADAR) |
| 3951 | phybits |= AR_PHY_ERR_RADAR; |
| 3952 | if (bits & ATH9K_RX_FILTER_PHYERR) |
| 3953 | phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING; |
| 3954 | REG_WRITE(ah, AR_PHY_ERR, phybits); |
| 3955 | |
| 3956 | if (phybits) |
| 3957 | REG_WRITE(ah, AR_RXCFG, |
| 3958 | REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA); |
| 3959 | else |
| 3960 | REG_WRITE(ah, AR_RXCFG, |
| 3961 | REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA); |
| 3962 | } |
| 3963 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3964 | bool ath9k_hw_phy_disable(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3965 | { |
| 3966 | return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM); |
| 3967 | } |
| 3968 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3969 | bool ath9k_hw_disable(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3970 | { |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 3971 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3972 | return false; |
| 3973 | |
| 3974 | return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD); |
| 3975 | } |
| 3976 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 3977 | void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3978 | { |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3979 | struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 3980 | struct ath9k_channel *chan = ah->curchan; |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 3981 | struct ieee80211_channel *channel = chan->chan; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3982 | |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3983 | regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3984 | |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 3985 | ah->eep_ops->set_txpower(ah, chan, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3986 | ath9k_regd_get_ctl(regulatory, chan), |
Vasanthakumar Thiagarajan | 8fbff4b | 2009-05-08 17:54:51 -0700 | [diff] [blame] | 3987 | channel->max_antenna_gain * 2, |
| 3988 | channel->max_power * 2, |
| 3989 | min((u32) MAX_RATE_POWER, |
Luis R. Rodriguez | 608b88c | 2009-08-17 18:07:23 -0700 | [diff] [blame] | 3990 | (u32) regulatory->power_limit)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3991 | } |
| 3992 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3993 | void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3994 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 3995 | memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3996 | } |
| 3997 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 3998 | void ath9k_hw_setopmode(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 3999 | { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4000 | ath9k_hw_set_operating_mode(ah, ah->opmode); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4001 | } |
| 4002 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4003 | void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4004 | { |
| 4005 | REG_WRITE(ah, AR_MCAST_FIL0, filter0); |
| 4006 | REG_WRITE(ah, AR_MCAST_FIL1, filter1); |
| 4007 | } |
| 4008 | |
Luis R. Rodriguez | f2b2143 | 2009-09-10 08:50:20 -0700 | [diff] [blame] | 4009 | void ath9k_hw_write_associd(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4010 | { |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 4011 | struct ath_common *common = ath9k_hw_common(ah); |
| 4012 | |
| 4013 | REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid)); |
| 4014 | REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) | |
| 4015 | ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4016 | } |
| 4017 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4018 | u64 ath9k_hw_gettsf64(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4019 | { |
| 4020 | u64 tsf; |
| 4021 | |
| 4022 | tsf = REG_READ(ah, AR_TSF_U32); |
| 4023 | tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32); |
| 4024 | |
| 4025 | return tsf; |
| 4026 | } |
| 4027 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4028 | void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64) |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 4029 | { |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 4030 | REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff); |
Alina Friedrichsen | b9a1619 | 2009-03-02 23:28:38 +0100 | [diff] [blame] | 4031 | REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff); |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 4032 | } |
| 4033 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4034 | void ath9k_hw_reset_tsf(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4035 | { |
Gabor Juhos | f9b604f | 2009-06-21 00:02:15 +0200 | [diff] [blame] | 4036 | if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0, |
| 4037 | AH_TSF_WRITE_TIMEOUT)) |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 4038 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 4039 | "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n"); |
Gabor Juhos | f9b604f | 2009-06-21 00:02:15 +0200 | [diff] [blame] | 4040 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4041 | REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4042 | } |
| 4043 | |
Sujith | 54e4cec | 2009-08-07 09:45:09 +0530 | [diff] [blame] | 4044 | void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4045 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4046 | if (setting) |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4047 | ah->misc_mode |= AR_PCU_TX_ADD_TSF; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4048 | else |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4049 | ah->misc_mode &= ~AR_PCU_TX_ADD_TSF; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4050 | } |
| 4051 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4052 | bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4053 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4054 | if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 4055 | ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, |
| 4056 | "bad slot time %u\n", us); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4057 | ah->slottime = (u32) -1; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4058 | return false; |
| 4059 | } else { |
| 4060 | REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us)); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4061 | ah->slottime = us; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4062 | return true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4063 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 4066 | void ath9k_hw_set11nmac2040(struct ath_hw *ah, enum ath9k_ht_macmode mode) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4067 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4068 | u32 macmode; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4069 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4070 | if (mode == ATH9K_HT_MACMODE_2040 && |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 4071 | !ah->config.cwm_ignore_extcca) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4072 | macmode = AR_2040_JOINED_RX_CLEAR; |
| 4073 | else |
| 4074 | macmode = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4075 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 4076 | REG_WRITE(ah, AR_2040_MODE, macmode); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 4077 | } |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4078 | |
| 4079 | /* HW Generic timers configuration */ |
| 4080 | |
| 4081 | static const struct ath_gen_timer_configuration gen_tmr_configuration[] = |
| 4082 | { |
| 4083 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4084 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4085 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4086 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4087 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4088 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4089 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4090 | {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080}, |
| 4091 | {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001}, |
| 4092 | {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4, |
| 4093 | AR_NDP2_TIMER_MODE, 0x0002}, |
| 4094 | {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4, |
| 4095 | AR_NDP2_TIMER_MODE, 0x0004}, |
| 4096 | {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4, |
| 4097 | AR_NDP2_TIMER_MODE, 0x0008}, |
| 4098 | {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4, |
| 4099 | AR_NDP2_TIMER_MODE, 0x0010}, |
| 4100 | {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4, |
| 4101 | AR_NDP2_TIMER_MODE, 0x0020}, |
| 4102 | {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4, |
| 4103 | AR_NDP2_TIMER_MODE, 0x0040}, |
| 4104 | {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4, |
| 4105 | AR_NDP2_TIMER_MODE, 0x0080} |
| 4106 | }; |
| 4107 | |
| 4108 | /* HW generic timer primitives */ |
| 4109 | |
| 4110 | /* compute and clear index of rightmost 1 */ |
| 4111 | static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask) |
| 4112 | { |
| 4113 | u32 b; |
| 4114 | |
| 4115 | b = *mask; |
| 4116 | b &= (0-b); |
| 4117 | *mask &= ~b; |
| 4118 | b *= debruijn32; |
| 4119 | b >>= 27; |
| 4120 | |
| 4121 | return timer_table->gen_timer_index[b]; |
| 4122 | } |
| 4123 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 4124 | u32 ath9k_hw_gettsf32(struct ath_hw *ah) |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4125 | { |
| 4126 | return REG_READ(ah, AR_TSF_L32); |
| 4127 | } |
| 4128 | |
| 4129 | struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah, |
| 4130 | void (*trigger)(void *), |
| 4131 | void (*overflow)(void *), |
| 4132 | void *arg, |
| 4133 | u8 timer_index) |
| 4134 | { |
| 4135 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 4136 | struct ath_gen_timer *timer; |
| 4137 | |
| 4138 | timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL); |
| 4139 | |
| 4140 | if (timer == NULL) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 4141 | ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL, |
| 4142 | "Failed to allocate memory" |
| 4143 | "for hw timer[%d]\n", timer_index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4144 | return NULL; |
| 4145 | } |
| 4146 | |
| 4147 | /* allocate a hardware generic timer slot */ |
| 4148 | timer_table->timers[timer_index] = timer; |
| 4149 | timer->index = timer_index; |
| 4150 | timer->trigger = trigger; |
| 4151 | timer->overflow = overflow; |
| 4152 | timer->arg = arg; |
| 4153 | |
| 4154 | return timer; |
| 4155 | } |
| 4156 | |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 4157 | void ath9k_hw_gen_timer_start(struct ath_hw *ah, |
| 4158 | struct ath_gen_timer *timer, |
| 4159 | u32 timer_next, |
| 4160 | u32 timer_period) |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4161 | { |
| 4162 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 4163 | u32 tsf; |
| 4164 | |
| 4165 | BUG_ON(!timer_period); |
| 4166 | |
| 4167 | set_bit(timer->index, &timer_table->timer_mask.timer_bits); |
| 4168 | |
| 4169 | tsf = ath9k_hw_gettsf32(ah); |
| 4170 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 4171 | ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER, |
| 4172 | "curent tsf %x period %x" |
| 4173 | "timer_next %x\n", tsf, timer_period, timer_next); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4174 | |
| 4175 | /* |
| 4176 | * Pull timer_next forward if the current TSF already passed it |
| 4177 | * because of software latency |
| 4178 | */ |
| 4179 | if (timer_next < tsf) |
| 4180 | timer_next = tsf + timer_period; |
| 4181 | |
| 4182 | /* |
| 4183 | * Program generic timer registers |
| 4184 | */ |
| 4185 | REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr, |
| 4186 | timer_next); |
| 4187 | REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr, |
| 4188 | timer_period); |
| 4189 | REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr, |
| 4190 | gen_tmr_configuration[timer->index].mode_mask); |
| 4191 | |
| 4192 | /* Enable both trigger and thresh interrupt masks */ |
| 4193 | REG_SET_BIT(ah, AR_IMR_S5, |
| 4194 | (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) | |
| 4195 | SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG))); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4196 | } |
| 4197 | |
Luis R. Rodriguez | cd9bf68 | 2009-09-13 02:08:34 -0700 | [diff] [blame] | 4198 | 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] | 4199 | { |
| 4200 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 4201 | |
| 4202 | if ((timer->index < AR_FIRST_NDP_TIMER) || |
| 4203 | (timer->index >= ATH_MAX_GEN_TIMER)) { |
| 4204 | return; |
| 4205 | } |
| 4206 | |
| 4207 | /* Clear generic timer enable bits. */ |
| 4208 | REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr, |
| 4209 | gen_tmr_configuration[timer->index].mode_mask); |
| 4210 | |
| 4211 | /* Disable both trigger and thresh interrupt masks */ |
| 4212 | REG_CLR_BIT(ah, AR_IMR_S5, |
| 4213 | (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) | |
| 4214 | SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG))); |
| 4215 | |
| 4216 | clear_bit(timer->index, &timer_table->timer_mask.timer_bits); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4217 | } |
| 4218 | |
| 4219 | void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer) |
| 4220 | { |
| 4221 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 4222 | |
| 4223 | /* free the hardware generic timer slot */ |
| 4224 | timer_table->timers[timer->index] = NULL; |
| 4225 | kfree(timer); |
| 4226 | } |
| 4227 | |
| 4228 | /* |
| 4229 | * Generic Timer Interrupts handling |
| 4230 | */ |
| 4231 | void ath_gen_timer_isr(struct ath_hw *ah) |
| 4232 | { |
| 4233 | struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; |
| 4234 | struct ath_gen_timer *timer; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 4235 | struct ath_common *common = ath9k_hw_common(ah); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4236 | u32 trigger_mask, thresh_mask, index; |
| 4237 | |
| 4238 | /* get hardware generic timer interrupt status */ |
| 4239 | trigger_mask = ah->intr_gen_timer_trigger; |
| 4240 | thresh_mask = ah->intr_gen_timer_thresh; |
| 4241 | trigger_mask &= timer_table->timer_mask.val; |
| 4242 | thresh_mask &= timer_table->timer_mask.val; |
| 4243 | |
| 4244 | trigger_mask &= ~thresh_mask; |
| 4245 | |
| 4246 | while (thresh_mask) { |
| 4247 | index = rightmost_index(timer_table, &thresh_mask); |
| 4248 | timer = timer_table->timers[index]; |
| 4249 | BUG_ON(!timer); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 4250 | ath_print(common, ATH_DBG_HWTIMER, |
| 4251 | "TSF overflow for Gen timer %d\n", index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4252 | timer->overflow(timer->arg); |
| 4253 | } |
| 4254 | |
| 4255 | while (trigger_mask) { |
| 4256 | index = rightmost_index(timer_table, &trigger_mask); |
| 4257 | timer = timer_table->timers[index]; |
| 4258 | BUG_ON(!timer); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 4259 | ath_print(common, ATH_DBG_HWTIMER, |
| 4260 | "Gen timer[%d] trigger\n", index); |
Vasanthakumar Thiagarajan | ff155a4 | 2009-08-26 21:08:49 +0530 | [diff] [blame] | 4261 | timer->trigger(timer->arg); |
| 4262 | } |
| 4263 | } |