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 | |
Luis R. Rodriguez | cfe8cba | 2009-09-13 23:39:31 -0700 | [diff] [blame] | 17 | #include "hw.h" |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 18 | |
Luis R. Rodriguez | 8b4fc5b | 2009-09-09 15:24:02 -0700 | [diff] [blame] | 19 | enum ath_bt_mode { |
| 20 | ATH_BT_COEX_MODE_LEGACY, /* legacy rx_clear mode */ |
| 21 | ATH_BT_COEX_MODE_UNSLOTTED, /* untimed/unslotted mode */ |
| 22 | ATH_BT_COEX_MODE_SLOTTED, /* slotted mode */ |
| 23 | ATH_BT_COEX_MODE_DISALBED, /* coexistence disabled */ |
| 24 | }; |
| 25 | |
| 26 | struct ath_btcoex_config { |
| 27 | u8 bt_time_extend; |
| 28 | bool bt_txstate_extend; |
| 29 | bool bt_txframe_extend; |
| 30 | enum ath_bt_mode bt_mode; /* coexistence mode */ |
| 31 | bool bt_quiet_collision; |
| 32 | bool bt_rxclear_polarity; /* invert rx_clear as WLAN_ACTIVE*/ |
| 33 | u8 bt_priority_time; |
| 34 | u8 bt_first_slot_time; |
| 35 | bool bt_hold_rx_clear; |
| 36 | }; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 37 | |
Vasanthakumar Thiagarajan | fe12946 | 2009-09-09 15:25:50 +0530 | [diff] [blame] | 38 | static const u16 ath_subsysid_tbl[] = { |
| 39 | AR9280_COEX2WIRE_SUBSYSID, |
| 40 | AT9285_COEX3WIRE_SA_SUBSYSID, |
| 41 | AT9285_COEX3WIRE_DA_SUBSYSID |
| 42 | }; |
| 43 | |
| 44 | /* |
| 45 | * Checks the subsystem id of the device to see if it |
| 46 | * supports btcoex |
| 47 | */ |
Luis R. Rodriguez | a36cfbc | 2009-09-09 16:05:32 -0700 | [diff] [blame] | 48 | bool ath9k_hw_btcoex_supported(struct ath_hw *ah) |
Vasanthakumar Thiagarajan | fe12946 | 2009-09-09 15:25:50 +0530 | [diff] [blame] | 49 | { |
| 50 | int i; |
| 51 | |
Luis R. Rodriguez | a36cfbc | 2009-09-09 16:05:32 -0700 | [diff] [blame] | 52 | if (!ah->hw_version.subsysid) |
Vasanthakumar Thiagarajan | fe12946 | 2009-09-09 15:25:50 +0530 | [diff] [blame] | 53 | return false; |
| 54 | |
| 55 | for (i = 0; i < ARRAY_SIZE(ath_subsysid_tbl); i++) |
Luis R. Rodriguez | a36cfbc | 2009-09-09 16:05:32 -0700 | [diff] [blame] | 56 | if (ah->hw_version.subsysid == ath_subsysid_tbl[i]) |
Vasanthakumar Thiagarajan | fe12946 | 2009-09-09 15:25:50 +0530 | [diff] [blame] | 57 | return true; |
| 58 | |
| 59 | return false; |
| 60 | } |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 61 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 62 | void ath9k_hw_init_btcoex_hw(struct ath_hw *ah, int qnum) |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 63 | { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 64 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
Luis R. Rodriguez | 8b4fc5b | 2009-09-09 15:24:02 -0700 | [diff] [blame] | 65 | const struct ath_btcoex_config ath_bt_config = { |
| 66 | .bt_time_extend = 0, |
| 67 | .bt_txstate_extend = true, |
| 68 | .bt_txframe_extend = true, |
| 69 | .bt_mode = ATH_BT_COEX_MODE_SLOTTED, |
| 70 | .bt_quiet_collision = true, |
| 71 | .bt_rxclear_polarity = true, |
| 72 | .bt_priority_time = 2, |
| 73 | .bt_first_slot_time = 5, |
| 74 | .bt_hold_rx_clear = true, |
| 75 | }; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 76 | u32 i; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 77 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 78 | btcoex_hw->bt_coex_mode = |
| 79 | (btcoex_hw->bt_coex_mode & AR_BT_QCU_THRESH) | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 80 | SM(ath_bt_config.bt_time_extend, AR_BT_TIME_EXTEND) | |
| 81 | SM(ath_bt_config.bt_txstate_extend, AR_BT_TXSTATE_EXTEND) | |
| 82 | SM(ath_bt_config.bt_txframe_extend, AR_BT_TX_FRAME_EXTEND) | |
| 83 | SM(ath_bt_config.bt_mode, AR_BT_MODE) | |
| 84 | SM(ath_bt_config.bt_quiet_collision, AR_BT_QUIET) | |
| 85 | SM(ath_bt_config.bt_rxclear_polarity, AR_BT_RX_CLEAR_POLARITY) | |
| 86 | SM(ath_bt_config.bt_priority_time, AR_BT_PRIORITY_TIME) | |
| 87 | SM(ath_bt_config.bt_first_slot_time, AR_BT_FIRST_SLOT_TIME) | |
| 88 | SM(qnum, AR_BT_QCU_THRESH); |
| 89 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 90 | btcoex_hw->bt_coex_mode2 = |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 91 | SM(ath_bt_config.bt_hold_rx_clear, AR_BT_HOLD_RX_CLEAR) | |
| 92 | SM(ATH_BTCOEX_BMISS_THRESH, AR_BT_BCN_MISS_THRESH) | |
| 93 | AR_BT_DISABLE_BT_ANT; |
| 94 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 95 | for (i = 0; i < 32; i++) |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 96 | ah->hw_gen_timers.gen_timer_index[(debruijn32 << i) >> 27] = i; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 97 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 98 | EXPORT_SYMBOL(ath9k_hw_init_btcoex_hw); |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 99 | |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 100 | void ath9k_hw_btcoex_init_2wire(struct ath_hw *ah) |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 101 | { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 102 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 103 | |
| 104 | /* connect bt_active to baseband */ |
| 105 | REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL, |
| 106 | (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF | |
| 107 | AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF)); |
| 108 | |
| 109 | REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, |
| 110 | AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB); |
| 111 | |
| 112 | /* Set input mux for bt_active to gpio pin */ |
| 113 | REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, |
| 114 | AR_GPIO_INPUT_MUX1_BT_ACTIVE, |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 115 | btcoex_hw->btactive_gpio); |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 116 | |
| 117 | /* Configure the desired gpio port for input */ |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 118 | ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio); |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 119 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 120 | EXPORT_SYMBOL(ath9k_hw_btcoex_init_2wire); |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 121 | |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 122 | void ath9k_hw_btcoex_init_3wire(struct ath_hw *ah) |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 123 | { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 124 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 125 | |
| 126 | /* btcoex 3-wire */ |
| 127 | REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, |
| 128 | (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB | |
| 129 | AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB)); |
| 130 | |
| 131 | /* Set input mux for bt_prority_async and |
| 132 | * bt_active_async to GPIO pins */ |
| 133 | REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, |
| 134 | AR_GPIO_INPUT_MUX1_BT_ACTIVE, |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 135 | btcoex_hw->btactive_gpio); |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 136 | |
| 137 | REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, |
| 138 | AR_GPIO_INPUT_MUX1_BT_PRIORITY, |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 139 | btcoex_hw->btpriority_gpio); |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 140 | |
| 141 | /* Configure the desired GPIO ports for input */ |
| 142 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 143 | ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio); |
| 144 | ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btpriority_gpio); |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 145 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 146 | EXPORT_SYMBOL(ath9k_hw_btcoex_init_3wire); |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 147 | |
Luis R. Rodriguez | bc74bf8 | 2009-09-09 04:17:45 -0700 | [diff] [blame] | 148 | static void ath9k_hw_btcoex_enable_2wire(struct ath_hw *ah) |
| 149 | { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 150 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
Luis R. Rodriguez | bc74bf8 | 2009-09-09 04:17:45 -0700 | [diff] [blame] | 151 | |
| 152 | /* Configure the desired GPIO port for TX_FRAME output */ |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 153 | ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio, |
Luis R. Rodriguez | bc74bf8 | 2009-09-09 04:17:45 -0700 | [diff] [blame] | 154 | AR_GPIO_OUTPUT_MUX_AS_TX_FRAME); |
| 155 | } |
| 156 | |
Luis R. Rodriguez | 5e19729 | 2009-09-09 15:15:55 -0700 | [diff] [blame] | 157 | void ath9k_hw_btcoex_set_weight(struct ath_hw *ah, |
| 158 | u32 bt_weight, |
| 159 | u32 wlan_weight) |
| 160 | { |
| 161 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
| 162 | |
| 163 | btcoex_hw->bt_coex_weights = SM(bt_weight, AR_BTCOEX_BT_WGHT) | |
| 164 | SM(wlan_weight, AR_BTCOEX_WL_WGHT); |
| 165 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 166 | EXPORT_SYMBOL(ath9k_hw_btcoex_set_weight); |
Luis R. Rodriguez | 5e19729 | 2009-09-09 15:15:55 -0700 | [diff] [blame] | 167 | |
Luis R. Rodriguez | bc74bf8 | 2009-09-09 04:17:45 -0700 | [diff] [blame] | 168 | static void ath9k_hw_btcoex_enable_3wire(struct ath_hw *ah) |
| 169 | { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 170 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
Luis R. Rodriguez | bc74bf8 | 2009-09-09 04:17:45 -0700 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * Program coex mode and weight registers to |
| 174 | * enable coex 3-wire |
| 175 | */ |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 176 | REG_WRITE(ah, AR_BT_COEX_MODE, btcoex_hw->bt_coex_mode); |
| 177 | REG_WRITE(ah, AR_BT_COEX_WEIGHT, btcoex_hw->bt_coex_weights); |
| 178 | REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex_hw->bt_coex_mode2); |
Luis R. Rodriguez | bc74bf8 | 2009-09-09 04:17:45 -0700 | [diff] [blame] | 179 | |
| 180 | REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1); |
| 181 | REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0); |
| 182 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 183 | ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio, |
Luis R. Rodriguez | bc74bf8 | 2009-09-09 04:17:45 -0700 | [diff] [blame] | 184 | AR_GPIO_OUTPUT_MUX_AS_RX_CLEAR_EXTERNAL); |
| 185 | } |
| 186 | |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 187 | void ath9k_hw_btcoex_enable(struct ath_hw *ah) |
| 188 | { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 189 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
Vasanthakumar Thiagarajan | f14462c | 2009-08-26 21:08:46 +0530 | [diff] [blame] | 190 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 191 | switch (btcoex_hw->scheme) { |
Luis R. Rodriguez | bc74bf8 | 2009-09-09 04:17:45 -0700 | [diff] [blame] | 192 | case ATH_BTCOEX_CFG_NONE: |
| 193 | break; |
| 194 | case ATH_BTCOEX_CFG_2WIRE: |
| 195 | ath9k_hw_btcoex_enable_2wire(ah); |
| 196 | break; |
| 197 | case ATH_BTCOEX_CFG_3WIRE: |
| 198 | ath9k_hw_btcoex_enable_3wire(ah); |
| 199 | break; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | REG_RMW(ah, AR_GPIO_PDPU, |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 203 | (0x2 << (btcoex_hw->btactive_gpio * 2)), |
| 204 | (0x3 << (btcoex_hw->btactive_gpio * 2))); |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 205 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 206 | ah->btcoex_hw.enabled = true; |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 207 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 208 | EXPORT_SYMBOL(ath9k_hw_btcoex_enable); |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 209 | |
| 210 | void ath9k_hw_btcoex_disable(struct ath_hw *ah) |
| 211 | { |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 212 | struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 213 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 214 | ath9k_hw_set_gpio(ah, btcoex_hw->wlanactive_gpio, 0); |
Vasanthakumar Thiagarajan | f14462c | 2009-08-26 21:08:46 +0530 | [diff] [blame] | 215 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 216 | ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio, |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 217 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
| 218 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 219 | if (btcoex_hw->scheme == ATH_BTCOEX_CFG_3WIRE) { |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 220 | REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE); |
| 221 | REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0); |
| 222 | REG_WRITE(ah, AR_BT_COEX_MODE2, 0); |
| 223 | } |
| 224 | |
Luis R. Rodriguez | 766ec4a | 2009-09-09 14:52:02 -0700 | [diff] [blame] | 225 | ah->btcoex_hw.enabled = false; |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 226 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 227 | EXPORT_SYMBOL(ath9k_hw_btcoex_disable); |