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 | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 46 | void ath9k_hw_init_btcoex_hw_info(struct ath_hw *ah, int qnum) |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 47 | { |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 48 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 49 | u32 i; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 50 | |
| 51 | btcoex_info->bt_coex_mode = |
| 52 | (btcoex_info->bt_coex_mode & AR_BT_QCU_THRESH) | |
| 53 | SM(ath_bt_config.bt_time_extend, AR_BT_TIME_EXTEND) | |
| 54 | SM(ath_bt_config.bt_txstate_extend, AR_BT_TXSTATE_EXTEND) | |
| 55 | SM(ath_bt_config.bt_txframe_extend, AR_BT_TX_FRAME_EXTEND) | |
| 56 | SM(ath_bt_config.bt_mode, AR_BT_MODE) | |
| 57 | SM(ath_bt_config.bt_quiet_collision, AR_BT_QUIET) | |
| 58 | SM(ath_bt_config.bt_rxclear_polarity, AR_BT_RX_CLEAR_POLARITY) | |
| 59 | SM(ath_bt_config.bt_priority_time, AR_BT_PRIORITY_TIME) | |
| 60 | SM(ath_bt_config.bt_first_slot_time, AR_BT_FIRST_SLOT_TIME) | |
| 61 | SM(qnum, AR_BT_QCU_THRESH); |
| 62 | |
| 63 | btcoex_info->bt_coex_mode2 = |
| 64 | SM(ath_bt_config.bt_hold_rx_clear, AR_BT_HOLD_RX_CLEAR) | |
| 65 | SM(ATH_BTCOEX_BMISS_THRESH, AR_BT_BCN_MISS_THRESH) | |
| 66 | AR_BT_DISABLE_BT_ANT; |
| 67 | |
| 68 | btcoex_info->bt_stomp_type = ATH_BTCOEX_STOMP_LOW; |
| 69 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 70 | for (i = 0; i < 32; i++) |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 71 | ah->hw_gen_timers.gen_timer_index[(debruijn32 << i) >> 27] = i; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 72 | } |
| 73 | |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 74 | void ath9k_hw_btcoex_init_2wire(struct ath_hw *ah) |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 75 | { |
| 76 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
| 77 | |
| 78 | /* connect bt_active to baseband */ |
| 79 | REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL, |
| 80 | (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF | |
| 81 | AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF)); |
| 82 | |
| 83 | REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, |
| 84 | AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB); |
| 85 | |
| 86 | /* Set input mux for bt_active to gpio pin */ |
| 87 | REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, |
| 88 | AR_GPIO_INPUT_MUX1_BT_ACTIVE, |
| 89 | btcoex_info->btactive_gpio); |
| 90 | |
| 91 | /* Configure the desired gpio port for input */ |
| 92 | ath9k_hw_cfg_gpio_input(ah, btcoex_info->btactive_gpio); |
| 93 | } |
| 94 | |
Luis R. Rodriguez | 75d7839 | 2009-09-09 04:00:10 -0700 | [diff] [blame] | 95 | void ath9k_hw_btcoex_init_3wire(struct ath_hw *ah) |
Luis R. Rodriguez | 7a2f0f5 | 2009-09-09 02:54:40 -0700 | [diff] [blame] | 96 | { |
| 97 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
| 98 | |
| 99 | /* btcoex 3-wire */ |
| 100 | REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, |
| 101 | (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB | |
| 102 | AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB)); |
| 103 | |
| 104 | /* Set input mux for bt_prority_async and |
| 105 | * bt_active_async to GPIO pins */ |
| 106 | REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, |
| 107 | AR_GPIO_INPUT_MUX1_BT_ACTIVE, |
| 108 | btcoex_info->btactive_gpio); |
| 109 | |
| 110 | REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1, |
| 111 | AR_GPIO_INPUT_MUX1_BT_PRIORITY, |
| 112 | btcoex_info->btpriority_gpio); |
| 113 | |
| 114 | /* Configure the desired GPIO ports for input */ |
| 115 | |
| 116 | ath9k_hw_cfg_gpio_input(ah, btcoex_info->btactive_gpio); |
| 117 | ath9k_hw_cfg_gpio_input(ah, btcoex_info->btpriority_gpio); |
| 118 | } |
| 119 | |
Luis R. Rodriguez | bc74bf8 | 2009-09-09 04:17:45 -0700 | [diff] [blame^] | 120 | static void ath9k_hw_btcoex_enable_2wire(struct ath_hw *ah) |
| 121 | { |
| 122 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
| 123 | |
| 124 | /* Configure the desired GPIO port for TX_FRAME output */ |
| 125 | ath9k_hw_cfg_output(ah, btcoex_info->wlanactive_gpio, |
| 126 | AR_GPIO_OUTPUT_MUX_AS_TX_FRAME); |
| 127 | } |
| 128 | |
| 129 | static void ath9k_hw_btcoex_enable_3wire(struct ath_hw *ah) |
| 130 | { |
| 131 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
| 132 | |
| 133 | /* |
| 134 | * Program coex mode and weight registers to |
| 135 | * enable coex 3-wire |
| 136 | */ |
| 137 | REG_WRITE(ah, AR_BT_COEX_MODE, btcoex_info->bt_coex_mode); |
| 138 | REG_WRITE(ah, AR_BT_COEX_WEIGHT, btcoex_info->bt_coex_weights); |
| 139 | REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex_info->bt_coex_mode2); |
| 140 | |
| 141 | REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1); |
| 142 | REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0); |
| 143 | |
| 144 | ath9k_hw_cfg_output(ah, btcoex_info->wlanactive_gpio, |
| 145 | AR_GPIO_OUTPUT_MUX_AS_RX_CLEAR_EXTERNAL); |
| 146 | } |
| 147 | |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 148 | void ath9k_hw_btcoex_enable(struct ath_hw *ah) |
| 149 | { |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 150 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
Vasanthakumar Thiagarajan | f14462c | 2009-08-26 21:08:46 +0530 | [diff] [blame] | 151 | |
Luis R. Rodriguez | bc74bf8 | 2009-09-09 04:17:45 -0700 | [diff] [blame^] | 152 | switch (btcoex_info->btcoex_scheme) { |
| 153 | case ATH_BTCOEX_CFG_NONE: |
| 154 | break; |
| 155 | case ATH_BTCOEX_CFG_2WIRE: |
| 156 | ath9k_hw_btcoex_enable_2wire(ah); |
| 157 | break; |
| 158 | case ATH_BTCOEX_CFG_3WIRE: |
| 159 | ath9k_hw_btcoex_enable_3wire(ah); |
| 160 | break; |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | REG_RMW(ah, AR_GPIO_PDPU, |
| 164 | (0x2 << (btcoex_info->btactive_gpio * 2)), |
| 165 | (0x3 << (btcoex_info->btactive_gpio * 2))); |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 166 | |
| 167 | ah->ah_sc->sc_flags |= SC_OP_BTCOEX_ENABLED; |
| 168 | } |
| 169 | |
| 170 | void ath9k_hw_btcoex_disable(struct ath_hw *ah) |
| 171 | { |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 172 | struct ath_btcoex_info *btcoex_info = &ah->btcoex_info; |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 173 | |
Vasanthakumar Thiagarajan | f14462c | 2009-08-26 21:08:46 +0530 | [diff] [blame] | 174 | ath9k_hw_set_gpio(ah, btcoex_info->wlanactive_gpio, 0); |
| 175 | |
| 176 | ath9k_hw_cfg_output(ah, btcoex_info->wlanactive_gpio, |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 177 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
| 178 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 179 | if (btcoex_info->btcoex_scheme == ATH_BTCOEX_CFG_3WIRE) { |
| 180 | REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE); |
| 181 | REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0); |
| 182 | REG_WRITE(ah, AR_BT_COEX_MODE2, 0); |
| 183 | } |
| 184 | |
Vasanthakumar Thiagarajan | 17d50d1 | 2009-08-26 21:08:44 +0530 | [diff] [blame] | 185 | ah->ah_sc->sc_flags &= ~SC_OP_BTCOEX_ENABLED; |
| 186 | } |