blob: 71e9e4841fa21713162168ba542bb0556da70ba2 [file] [log] [blame]
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +05301/*
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. Rodriguezcfe8cba2009-09-13 23:39:31 -070017#include "hw.h"
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +053018
Luis R. Rodriguez8b4fc5b2009-09-09 15:24:02 -070019enum 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
26struct 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 Thiagarajan17739122009-08-26 21:08:50 +053037
38
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -070039void ath9k_hw_init_btcoex_hw(struct ath_hw *ah, int qnum)
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070040{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -070041 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez8b4fc5b2009-09-09 15:24:02 -070042 const struct ath_btcoex_config ath_bt_config = {
43 .bt_time_extend = 0,
44 .bt_txstate_extend = true,
45 .bt_txframe_extend = true,
46 .bt_mode = ATH_BT_COEX_MODE_SLOTTED,
47 .bt_quiet_collision = true,
48 .bt_rxclear_polarity = true,
49 .bt_priority_time = 2,
50 .bt_first_slot_time = 5,
51 .bt_hold_rx_clear = true,
52 };
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053053 u32 i;
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053054
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -070055 btcoex_hw->bt_coex_mode =
56 (btcoex_hw->bt_coex_mode & AR_BT_QCU_THRESH) |
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053057 SM(ath_bt_config.bt_time_extend, AR_BT_TIME_EXTEND) |
58 SM(ath_bt_config.bt_txstate_extend, AR_BT_TXSTATE_EXTEND) |
59 SM(ath_bt_config.bt_txframe_extend, AR_BT_TX_FRAME_EXTEND) |
60 SM(ath_bt_config.bt_mode, AR_BT_MODE) |
61 SM(ath_bt_config.bt_quiet_collision, AR_BT_QUIET) |
62 SM(ath_bt_config.bt_rxclear_polarity, AR_BT_RX_CLEAR_POLARITY) |
63 SM(ath_bt_config.bt_priority_time, AR_BT_PRIORITY_TIME) |
64 SM(ath_bt_config.bt_first_slot_time, AR_BT_FIRST_SLOT_TIME) |
65 SM(qnum, AR_BT_QCU_THRESH);
66
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -070067 btcoex_hw->bt_coex_mode2 =
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053068 SM(ath_bt_config.bt_hold_rx_clear, AR_BT_HOLD_RX_CLEAR) |
69 SM(ATH_BTCOEX_BMISS_THRESH, AR_BT_BCN_MISS_THRESH) |
70 AR_BT_DISABLE_BT_ANT;
71
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053072 for (i = 0; i < 32; i++)
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070073 ah->hw_gen_timers.gen_timer_index[(debruijn32 << i) >> 27] = i;
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053074}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040075EXPORT_SYMBOL(ath9k_hw_init_btcoex_hw);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053076
Luis R. Rodriguez75d78392009-09-09 04:00:10 -070077void ath9k_hw_btcoex_init_2wire(struct ath_hw *ah)
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -070078{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -070079 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -070080
81 /* connect bt_active to baseband */
82 REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
83 (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
84 AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
85
86 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
87 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
88
89 /* Set input mux for bt_active to gpio pin */
90 REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
91 AR_GPIO_INPUT_MUX1_BT_ACTIVE,
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -070092 btcoex_hw->btactive_gpio);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -070093
94 /* Configure the desired gpio port for input */
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -070095 ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -070096}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -040097EXPORT_SYMBOL(ath9k_hw_btcoex_init_2wire);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -070098
Luis R. Rodriguez75d78392009-09-09 04:00:10 -070099void ath9k_hw_btcoex_init_3wire(struct ath_hw *ah)
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700100{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700101 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700102
103 /* btcoex 3-wire */
104 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
105 (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB |
106 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB));
107
108 /* Set input mux for bt_prority_async and
109 * bt_active_async to GPIO pins */
110 REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
111 AR_GPIO_INPUT_MUX1_BT_ACTIVE,
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700112 btcoex_hw->btactive_gpio);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700113
114 REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
115 AR_GPIO_INPUT_MUX1_BT_PRIORITY,
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700116 btcoex_hw->btpriority_gpio);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700117
118 /* Configure the desired GPIO ports for input */
119
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700120 ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
121 ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btpriority_gpio);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700122}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400123EXPORT_SYMBOL(ath9k_hw_btcoex_init_3wire);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700124
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700125static void ath9k_hw_btcoex_enable_2wire(struct ath_hw *ah)
126{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700127 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700128
129 /* Configure the desired GPIO port for TX_FRAME output */
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700130 ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700131 AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
132}
133
Luis R. Rodriguez5e197292009-09-09 15:15:55 -0700134void ath9k_hw_btcoex_set_weight(struct ath_hw *ah,
135 u32 bt_weight,
136 u32 wlan_weight)
137{
138 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
139
140 btcoex_hw->bt_coex_weights = SM(bt_weight, AR_BTCOEX_BT_WGHT) |
141 SM(wlan_weight, AR_BTCOEX_WL_WGHT);
142}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400143EXPORT_SYMBOL(ath9k_hw_btcoex_set_weight);
Luis R. Rodriguez5e197292009-09-09 15:15:55 -0700144
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700145static void ath9k_hw_btcoex_enable_3wire(struct ath_hw *ah)
146{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700147 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Vivek Natarajan21cb9872010-08-18 19:57:49 +0530148 u32 val;
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700149
150 /*
151 * Program coex mode and weight registers to
152 * enable coex 3-wire
153 */
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700154 REG_WRITE(ah, AR_BT_COEX_MODE, btcoex_hw->bt_coex_mode);
155 REG_WRITE(ah, AR_BT_COEX_WEIGHT, btcoex_hw->bt_coex_weights);
156 REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex_hw->bt_coex_mode2);
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700157
Vivek Natarajan21cb9872010-08-18 19:57:49 +0530158 if (AR_SREV_9271(ah)) {
159 val = REG_READ(ah, 0x50040);
160 val &= 0xFFFFFEFF;
161 REG_WRITE(ah, 0x50040, val);
162 }
163
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700164 REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);
165 REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);
166
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700167 ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700168 AR_GPIO_OUTPUT_MUX_AS_RX_CLEAR_EXTERNAL);
169}
170
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530171void ath9k_hw_btcoex_enable(struct ath_hw *ah)
172{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700173 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Vasanthakumar Thiagarajanf14462c2009-08-26 21:08:46 +0530174
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700175 switch (btcoex_hw->scheme) {
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700176 case ATH_BTCOEX_CFG_NONE:
177 break;
178 case ATH_BTCOEX_CFG_2WIRE:
179 ath9k_hw_btcoex_enable_2wire(ah);
180 break;
181 case ATH_BTCOEX_CFG_3WIRE:
182 ath9k_hw_btcoex_enable_3wire(ah);
183 break;
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +0530184 }
185
186 REG_RMW(ah, AR_GPIO_PDPU,
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700187 (0x2 << (btcoex_hw->btactive_gpio * 2)),
188 (0x3 << (btcoex_hw->btactive_gpio * 2)));
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530189
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700190 ah->btcoex_hw.enabled = true;
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530191}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400192EXPORT_SYMBOL(ath9k_hw_btcoex_enable);
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530193
194void ath9k_hw_btcoex_disable(struct ath_hw *ah)
195{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700196 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530197
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700198 ath9k_hw_set_gpio(ah, btcoex_hw->wlanactive_gpio, 0);
Vasanthakumar Thiagarajanf14462c2009-08-26 21:08:46 +0530199
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700200 ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530201 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
202
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700203 if (btcoex_hw->scheme == ATH_BTCOEX_CFG_3WIRE) {
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +0530204 REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE);
205 REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0);
206 REG_WRITE(ah, AR_BT_COEX_MODE2, 0);
207 }
208
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700209 ah->btcoex_hw.enabled = false;
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530210}
Luis R. Rodriguez7322fd12009-09-23 23:07:00 -0400211EXPORT_SYMBOL(ath9k_hw_btcoex_disable);
Vivek Natarajan978f78b2011-04-26 10:39:52 +0530212
213static void ar9003_btcoex_bt_stomp(struct ath_hw *ah,
214 enum ath_stomp_type stomp_type)
215{
216 ah->bt_coex_bt_weight[0] = AR9300_BT_WGHT;
217 ah->bt_coex_bt_weight[1] = AR9300_BT_WGHT;
218 ah->bt_coex_bt_weight[2] = AR9300_BT_WGHT;
219 ah->bt_coex_bt_weight[3] = AR9300_BT_WGHT;
220
221
222 switch (stomp_type) {
223 case ATH_BTCOEX_STOMP_ALL:
224 ah->bt_coex_wlan_weight[0] = AR9300_STOMP_ALL_WLAN_WGHT0;
225 ah->bt_coex_wlan_weight[1] = AR9300_STOMP_ALL_WLAN_WGHT1;
226 break;
227 case ATH_BTCOEX_STOMP_LOW:
228 ah->bt_coex_wlan_weight[0] = AR9300_STOMP_LOW_WLAN_WGHT0;
229 ah->bt_coex_wlan_weight[1] = AR9300_STOMP_LOW_WLAN_WGHT1;
230 break;
231 case ATH_BTCOEX_STOMP_NONE:
232 ah->bt_coex_wlan_weight[0] = AR9300_STOMP_NONE_WLAN_WGHT0;
233 ah->bt_coex_wlan_weight[1] = AR9300_STOMP_NONE_WLAN_WGHT1;
234 break;
235
236 default:
237 ath_dbg(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
238 "Invalid Stomptype\n");
239 break;
240 }
241
242 ath9k_hw_btcoex_enable(ah);
243}
244
245/*
246 * Configures appropriate weight based on stomp type.
247 */
248void ath9k_hw_btcoex_bt_stomp(struct ath_hw *ah,
249 enum ath_stomp_type stomp_type)
250{
251 if (AR_SREV_9300_20_OR_LATER(ah)) {
252 ar9003_btcoex_bt_stomp(ah, stomp_type);
253 return;
254 }
255
256 switch (stomp_type) {
257 case ATH_BTCOEX_STOMP_ALL:
258 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
259 AR_STOMP_ALL_WLAN_WGHT);
260 break;
261 case ATH_BTCOEX_STOMP_LOW:
262 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
263 AR_STOMP_LOW_WLAN_WGHT);
264 break;
265 case ATH_BTCOEX_STOMP_NONE:
266 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
267 AR_STOMP_NONE_WLAN_WGHT);
268 break;
269 default:
270 ath_dbg(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
271 "Invalid Stomptype\n");
272 break;
273 }
274
275 ath9k_hw_btcoex_enable(ah);
276}
277EXPORT_SYMBOL(ath9k_hw_btcoex_bt_stomp);