Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009 Atheros Communications Inc. |
| 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 "ath9k.h" |
| 18 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 19 | static const struct ath_btcoex_config ath_bt_config = { 0, true, true, |
| 20 | ATH_BT_COEX_MODE_SLOTTED, true, true, 2, 5, true }; |
| 21 | |
Vasanthakumar Thiagarajan | fe12946 | 2009-09-09 15:25:50 +0530 | [diff] [blame] | 22 | static const u16 ath_subsysid_tbl[] = { |
| 23 | AR9280_COEX2WIRE_SUBSYSID, |
| 24 | AT9285_COEX3WIRE_SA_SUBSYSID, |
| 25 | AT9285_COEX3WIRE_DA_SUBSYSID |
| 26 | }; |
| 27 | |
| 28 | /* |
| 29 | * Checks the subsystem id of the device to see if it |
| 30 | * supports btcoex |
| 31 | */ |
| 32 | bool ath_btcoex_supported(u16 subsysid) |
| 33 | { |
| 34 | int i; |
| 35 | |
| 36 | if (!subsysid) |
| 37 | return false; |
| 38 | |
| 39 | for (i = 0; i < ARRAY_SIZE(ath_subsysid_tbl); i++) |
| 40 | if (subsysid == ath_subsysid_tbl[i]) |
| 41 | return true; |
| 42 | |
| 43 | return false; |
| 44 | } |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 45 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 46 | static void ath_btcoex_set_weight(struct ath_btcoex_info *btcoex_info, |
| 47 | u32 bt_weight, |
| 48 | u32 wlan_weight) |
| 49 | { |
| 50 | btcoex_info->bt_coex_weights = SM(bt_weight, AR_BTCOEX_BT_WGHT) | |
| 51 | SM(wlan_weight, AR_BTCOEX_WL_WGHT); |
| 52 | } |
| 53 | |
| 54 | void ath9k_hw_btcoex_init_weight(struct ath_hw *ah) |
| 55 | { |
| 56 | ath_btcoex_set_weight(&ah->btcoex_info, AR_BT_COEX_WGHT, |
| 57 | AR_STOMP_LOW_WLAN_WGHT); |
| 58 | } |
| 59 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 60 | /* |
| 61 | * Detects if there is any priority bt traffic |
| 62 | */ |
| 63 | static void ath_detect_bt_priority(struct ath_softc *sc) |
| 64 | { |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 65 | struct ath_btcoex *btcoex = &sc->btcoex; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 66 | struct ath_hw *ah = sc->sc_ah; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 67 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 68 | if (ath9k_hw_gpio_get(sc->sc_ah, ah->btcoex_info.btpriority_gpio)) |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 69 | btcoex->bt_priority_cnt++; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 70 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 71 | if (time_after(jiffies, btcoex->bt_priority_time + |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 72 | msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) { |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 73 | if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) { |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 74 | DPRINTF(sc->sc_ah, ATH_DBG_BTCOEX, |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 75 | "BT priority traffic detected"); |
| 76 | sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED; |
| 77 | } else { |
| 78 | sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED; |
| 79 | } |
| 80 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 81 | btcoex->bt_priority_cnt = 0; |
| 82 | btcoex->bt_priority_time = jiffies; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * Configures appropriate weight based on stomp type. |
| 88 | */ |
| 89 | static void ath_btcoex_bt_stomp(struct ath_softc *sc, |
| 90 | struct ath_btcoex_info *btinfo, |
| 91 | int stomp_type) |
| 92 | { |
| 93 | |
| 94 | switch (stomp_type) { |
| 95 | case ATH_BTCOEX_STOMP_ALL: |
| 96 | ath_btcoex_set_weight(btinfo, AR_BT_COEX_WGHT, |
| 97 | AR_STOMP_ALL_WLAN_WGHT); |
| 98 | break; |
| 99 | case ATH_BTCOEX_STOMP_LOW: |
| 100 | ath_btcoex_set_weight(btinfo, AR_BT_COEX_WGHT, |
| 101 | AR_STOMP_LOW_WLAN_WGHT); |
| 102 | break; |
| 103 | case ATH_BTCOEX_STOMP_NONE: |
| 104 | ath_btcoex_set_weight(btinfo, AR_BT_COEX_WGHT, |
| 105 | AR_STOMP_NONE_WLAN_WGHT); |
| 106 | break; |
| 107 | default: |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 108 | DPRINTF(sc->sc_ah, ATH_DBG_BTCOEX, "Invalid Stomptype\n"); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 109 | break; |
| 110 | } |
| 111 | |
| 112 | ath9k_hw_btcoex_enable(sc->sc_ah); |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | * This is the master bt coex timer which runs for every |
| 117 | * 45ms, bt traffic will be given priority during 55% of this |
| 118 | * period while wlan gets remaining 45% |
| 119 | */ |
| 120 | |
| 121 | static void ath_btcoex_period_timer(unsigned long data) |
| 122 | { |
| 123 | struct ath_softc *sc = (struct ath_softc *) data; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 124 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 125 | struct ath_btcoex *btcoex = &sc->btcoex; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 126 | struct ath_btcoex_info *btinfo = &ah->btcoex_info; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 127 | |
| 128 | ath_detect_bt_priority(sc); |
| 129 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 130 | spin_lock_bh(&btcoex->btcoex_lock); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 131 | |
| 132 | ath_btcoex_bt_stomp(sc, btinfo, btinfo->bt_stomp_type); |
| 133 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 134 | spin_unlock_bh(&btcoex->btcoex_lock); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 135 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 136 | if (btcoex->btcoex_period != btcoex->btcoex_no_stomp) { |
| 137 | if (btcoex->hw_timer_enabled) |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 138 | ath_gen_timer_stop(ah, btinfo->no_stomp_timer); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 139 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 140 | ath_gen_timer_start(ah, |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 141 | btinfo->no_stomp_timer, |
| 142 | (ath9k_hw_gettsf32(sc->sc_ah) + |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 143 | btcoex->btcoex_no_stomp), |
| 144 | btcoex->btcoex_no_stomp * 10); |
| 145 | btcoex->hw_timer_enabled = true; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 146 | } |
| 147 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 148 | mod_timer(&btcoex->period_timer, jiffies + |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 149 | msecs_to_jiffies(ATH_BTCOEX_DEF_BT_PERIOD)); |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * Generic tsf based hw timer which configures weight |
| 154 | * registers to time slice between wlan and bt traffic |
| 155 | */ |
| 156 | |
| 157 | static void ath_btcoex_no_stomp_timer(void *arg) |
| 158 | { |
| 159 | struct ath_softc *sc = (struct ath_softc *)arg; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 160 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 161 | struct ath_btcoex *btcoex = &sc->btcoex; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 162 | struct ath_btcoex_info *btinfo = &ah->btcoex_info; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 163 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 164 | DPRINTF(ah, ATH_DBG_BTCOEX, "no stomp timer running \n"); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 165 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 166 | spin_lock_bh(&btcoex->btcoex_lock); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 167 | |
| 168 | if (btinfo->bt_stomp_type == ATH_BTCOEX_STOMP_LOW) |
| 169 | ath_btcoex_bt_stomp(sc, btinfo, ATH_BTCOEX_STOMP_NONE); |
| 170 | else if (btinfo->bt_stomp_type == ATH_BTCOEX_STOMP_ALL) |
| 171 | ath_btcoex_bt_stomp(sc, btinfo, ATH_BTCOEX_STOMP_LOW); |
| 172 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 173 | spin_unlock_bh(&btcoex->btcoex_lock); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 174 | } |
| 175 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 176 | static int ath_init_btcoex_info(struct ath_hw *ah, |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 177 | struct ath_btcoex_info *btcoex_info) |
| 178 | { |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 179 | struct ath_btcoex *btcoex = &ah->ah_sc->btcoex; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 180 | u32 i; |
| 181 | int qnum; |
| 182 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 183 | qnum = ath_tx_get_qnum(ah->ah_sc, ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 184 | |
| 185 | btcoex_info->bt_coex_mode = |
| 186 | (btcoex_info->bt_coex_mode & AR_BT_QCU_THRESH) | |
| 187 | SM(ath_bt_config.bt_time_extend, AR_BT_TIME_EXTEND) | |
| 188 | SM(ath_bt_config.bt_txstate_extend, AR_BT_TXSTATE_EXTEND) | |
| 189 | SM(ath_bt_config.bt_txframe_extend, AR_BT_TX_FRAME_EXTEND) | |
| 190 | SM(ath_bt_config.bt_mode, AR_BT_MODE) | |
| 191 | SM(ath_bt_config.bt_quiet_collision, AR_BT_QUIET) | |
| 192 | SM(ath_bt_config.bt_rxclear_polarity, AR_BT_RX_CLEAR_POLARITY) | |
| 193 | SM(ath_bt_config.bt_priority_time, AR_BT_PRIORITY_TIME) | |
| 194 | SM(ath_bt_config.bt_first_slot_time, AR_BT_FIRST_SLOT_TIME) | |
| 195 | SM(qnum, AR_BT_QCU_THRESH); |
| 196 | |
| 197 | btcoex_info->bt_coex_mode2 = |
| 198 | SM(ath_bt_config.bt_hold_rx_clear, AR_BT_HOLD_RX_CLEAR) | |
| 199 | SM(ATH_BTCOEX_BMISS_THRESH, AR_BT_BCN_MISS_THRESH) | |
| 200 | AR_BT_DISABLE_BT_ANT; |
| 201 | |
| 202 | btcoex_info->bt_stomp_type = ATH_BTCOEX_STOMP_LOW; |
| 203 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 204 | btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD * 1000; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 205 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 206 | btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) * |
| 207 | btcoex->btcoex_period / 100; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 208 | |
| 209 | for (i = 0; i < 32; i++) |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 210 | ah->hw_gen_timers.gen_timer_index[(debruijn32 << i) >> 27] = i; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 211 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 212 | setup_timer(&btcoex->period_timer, ath_btcoex_period_timer, |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 213 | (unsigned long) ah->ah_sc); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 214 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 215 | btcoex_info->no_stomp_timer = ath_gen_timer_alloc(ah, |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 216 | ath_btcoex_no_stomp_timer, |
| 217 | ath_btcoex_no_stomp_timer, |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 218 | (void *)ah->ah_sc, AR_FIRST_NDP_TIMER); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 219 | |
| 220 | if (btcoex_info->no_stomp_timer == NULL) |
| 221 | return -ENOMEM; |
| 222 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 223 | spin_lock_init(&btcoex->btcoex_lock); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame^] | 228 | static void ath9k_hw_btcoex_init_2wire(struct ath_hw *ah) |
| 229 | { |
| 230 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
| 231 | |
| 232 | /* connect bt_active to baseband */ |
| 233 | REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL, |
| 234 | (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF | |
| 235 | AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF)); |
| 236 | |
| 237 | REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, |
| 238 | AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB); |
| 239 | |
| 240 | /* Set input mux for bt_active to gpio pin */ |
| 241 | REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, |
| 242 | AR_GPIO_INPUT_MUX1_BT_ACTIVE, |
| 243 | btcoex_info->btactive_gpio); |
| 244 | |
| 245 | /* Configure the desired gpio port for input */ |
| 246 | ath9k_hw_cfg_gpio_input(ah, btcoex_info->btactive_gpio); |
| 247 | } |
| 248 | |
| 249 | static void ath9k_hw_btcoex_init_3wire(struct ath_hw *ah) |
| 250 | { |
| 251 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
| 252 | |
| 253 | /* btcoex 3-wire */ |
| 254 | REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, |
| 255 | (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB | |
| 256 | AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB)); |
| 257 | |
| 258 | /* Set input mux for bt_prority_async and |
| 259 | * bt_active_async to GPIO pins */ |
| 260 | REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, |
| 261 | AR_GPIO_INPUT_MUX1_BT_ACTIVE, |
| 262 | btcoex_info->btactive_gpio); |
| 263 | |
| 264 | REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, |
| 265 | AR_GPIO_INPUT_MUX1_BT_PRIORITY, |
| 266 | btcoex_info->btpriority_gpio); |
| 267 | |
| 268 | /* Configure the desired GPIO ports for input */ |
| 269 | |
| 270 | ath9k_hw_cfg_gpio_input(ah, btcoex_info->btactive_gpio); |
| 271 | ath9k_hw_cfg_gpio_input(ah, btcoex_info->btpriority_gpio); |
| 272 | } |
| 273 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 274 | int ath9k_hw_btcoex_init(struct ath_hw *ah) |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 275 | { |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 276 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 277 | int ret = 0; |
Vasanthakumar Thiagarajan | f14462c | 2009-08-26 21:08:46 +0530 | [diff] [blame] | 278 | |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame^] | 279 | if (btcoex_info->btcoex_scheme == ATH_BTCOEX_CFG_2WIRE) |
| 280 | ath9k_hw_btcoex_init_2wire(ah); |
| 281 | else { |
| 282 | ath9k_hw_btcoex_init_3wire(ah); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 283 | ret = ath_init_btcoex_info(ah, btcoex_info); |
| 284 | } |
| 285 | |
| 286 | return ret; |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void ath9k_hw_btcoex_enable(struct ath_hw *ah) |
| 290 | { |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 291 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
Vasanthakumar Thiagarajan | f14462c | 2009-08-26 21:08:46 +0530 | [diff] [blame] | 292 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 293 | if (btcoex_info->btcoex_scheme == ATH_BTCOEX_CFG_2WIRE) { |
| 294 | /* Configure the desired GPIO port for TX_FRAME output */ |
| 295 | ath9k_hw_cfg_output(ah, btcoex_info->wlanactive_gpio, |
| 296 | AR_GPIO_OUTPUT_MUX_AS_TX_FRAME); |
| 297 | } else { |
| 298 | /* |
| 299 | * Program coex mode and weight registers to |
| 300 | * enable coex 3-wire |
| 301 | */ |
| 302 | REG_WRITE(ah, AR_BT_COEX_MODE, btcoex_info->bt_coex_mode); |
| 303 | REG_WRITE(ah, AR_BT_COEX_WEIGHT, btcoex_info->bt_coex_weights); |
| 304 | REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex_info->bt_coex_mode2); |
| 305 | |
| 306 | REG_RMW_FIELD(ah, AR_QUIET1, |
| 307 | AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1); |
| 308 | REG_RMW_FIELD(ah, AR_PCU_MISC, |
| 309 | AR_PCU_BT_ANT_PREVENT_RX, 0); |
| 310 | |
| 311 | ath9k_hw_cfg_output(ah, btcoex_info->wlanactive_gpio, |
| 312 | AR_GPIO_OUTPUT_MUX_AS_RX_CLEAR_EXTERNAL); |
| 313 | } |
| 314 | |
| 315 | REG_RMW(ah, AR_GPIO_PDPU, |
| 316 | (0x2 << (btcoex_info->btactive_gpio * 2)), |
| 317 | (0x3 << (btcoex_info->btactive_gpio * 2))); |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 318 | |
| 319 | ah->ah_sc->sc_flags |= SC_OP_BTCOEX_ENABLED; |
| 320 | } |
| 321 | |
| 322 | void ath9k_hw_btcoex_disable(struct ath_hw *ah) |
| 323 | { |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 324 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 325 | |
Vasanthakumar Thiagarajan | f14462c | 2009-08-26 21:08:46 +0530 | [diff] [blame] | 326 | ath9k_hw_set_gpio(ah, btcoex_info->wlanactive_gpio, 0); |
| 327 | |
| 328 | ath9k_hw_cfg_output(ah, btcoex_info->wlanactive_gpio, |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 329 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
| 330 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 331 | if (btcoex_info->btcoex_scheme == ATH_BTCOEX_CFG_3WIRE) { |
| 332 | REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE); |
| 333 | REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0); |
| 334 | REG_WRITE(ah, AR_BT_COEX_MODE2, 0); |
| 335 | } |
| 336 | |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 337 | ah->ah_sc->sc_flags &= ~SC_OP_BTCOEX_ENABLED; |
| 338 | } |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 339 | |
| 340 | /* |
| 341 | * Pause btcoex timer and bt duty cycle timer |
| 342 | */ |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 343 | void ath_btcoex_timer_pause(struct ath_softc *sc) |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 344 | { |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 345 | struct ath_btcoex *btcoex = &sc->btcoex; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 346 | struct ath_hw *ah = sc->sc_ah; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 347 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 348 | del_timer_sync(&btcoex->period_timer); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 349 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 350 | if (btcoex->hw_timer_enabled) |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 351 | ath_gen_timer_stop(ah, ah->btcoex_info.no_stomp_timer); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 352 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 353 | btcoex->hw_timer_enabled = false; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /* |
| 357 | * (Re)start btcoex timers |
| 358 | */ |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 359 | void ath_btcoex_timer_resume(struct ath_softc *sc) |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 360 | { |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 361 | struct ath_btcoex *btcoex = &sc->btcoex; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 362 | struct ath_hw *ah = sc->sc_ah; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 363 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 364 | DPRINTF(ah, ATH_DBG_BTCOEX, "Starting btcoex timers"); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 365 | |
| 366 | /* make sure duty cycle timer is also stopped when resuming */ |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 367 | if (btcoex->hw_timer_enabled) |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 368 | ath_gen_timer_stop(sc->sc_ah, ah->btcoex_info.no_stomp_timer); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 369 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 370 | btcoex->bt_priority_cnt = 0; |
| 371 | btcoex->bt_priority_time = jiffies; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 372 | sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED; |
| 373 | |
Luis R. Rodriguez | 2e20250 | 2009-09-09 01:18:09 -0700 | [diff] [blame] | 374 | mod_timer(&btcoex->period_timer, jiffies); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 375 | } |