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