blob: 0c54489ca443024e8def364afd763501156f3b6e [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
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +053038static 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. Rodrigueza36cfbc2009-09-09 16:05:32 -070048bool ath9k_hw_btcoex_supported(struct ath_hw *ah)
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +053049{
50 int i;
51
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -070052 if (!ah->hw_version.subsysid)
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +053053 return false;
54
55 for (i = 0; i < ARRAY_SIZE(ath_subsysid_tbl); i++)
Luis R. Rodrigueza36cfbc2009-09-09 16:05:32 -070056 if (ah->hw_version.subsysid == ath_subsysid_tbl[i])
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +053057 return true;
58
59 return false;
60}
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053061
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -070062void ath9k_hw_init_btcoex_hw(struct ath_hw *ah, int qnum)
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070063{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -070064 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez8b4fc5b2009-09-09 15:24:02 -070065 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 Thiagarajan17739122009-08-26 21:08:50 +053076 u32 i;
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053077
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -070078 btcoex_hw->bt_coex_mode =
79 (btcoex_hw->bt_coex_mode & AR_BT_QCU_THRESH) |
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053080 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. Rodriguez766ec4a2009-09-09 14:52:02 -070090 btcoex_hw->bt_coex_mode2 =
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053091 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 Thiagarajan17739122009-08-26 21:08:50 +053095 for (i = 0; i < 32; i++)
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070096 ah->hw_gen_timers.gen_timer_index[(debruijn32 << i) >> 27] = i;
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +053097}
98
Luis R. Rodriguez75d78392009-09-09 04:00:10 -070099void ath9k_hw_btcoex_init_2wire(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 /* connect bt_active to baseband */
104 REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
105 (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
106 AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
107
108 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
109 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
110
111 /* Set input mux for bt_active to gpio pin */
112 REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
113 AR_GPIO_INPUT_MUX1_BT_ACTIVE,
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700114 btcoex_hw->btactive_gpio);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700115
116 /* Configure the desired gpio port for input */
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700117 ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700118}
119
Luis R. Rodriguez75d78392009-09-09 04:00:10 -0700120void ath9k_hw_btcoex_init_3wire(struct ath_hw *ah)
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700121{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700122 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700123
124 /* btcoex 3-wire */
125 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
126 (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB |
127 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB));
128
129 /* Set input mux for bt_prority_async and
130 * bt_active_async to GPIO pins */
131 REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
132 AR_GPIO_INPUT_MUX1_BT_ACTIVE,
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700133 btcoex_hw->btactive_gpio);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700134
135 REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
136 AR_GPIO_INPUT_MUX1_BT_PRIORITY,
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700137 btcoex_hw->btpriority_gpio);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700138
139 /* Configure the desired GPIO ports for input */
140
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700141 ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
142 ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btpriority_gpio);
Luis R. Rodriguez7a2f0f52009-09-09 02:54:40 -0700143}
144
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700145static void ath9k_hw_btcoex_enable_2wire(struct ath_hw *ah)
146{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700147 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700148
149 /* Configure the desired GPIO port for TX_FRAME output */
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700150 ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700151 AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
152}
153
Luis R. Rodriguez5e197292009-09-09 15:15:55 -0700154void ath9k_hw_btcoex_set_weight(struct ath_hw *ah,
155 u32 bt_weight,
156 u32 wlan_weight)
157{
158 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
159
160 btcoex_hw->bt_coex_weights = SM(bt_weight, AR_BTCOEX_BT_WGHT) |
161 SM(wlan_weight, AR_BTCOEX_WL_WGHT);
162}
163
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700164static void ath9k_hw_btcoex_enable_3wire(struct ath_hw *ah)
165{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700166 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700167
168 /*
169 * Program coex mode and weight registers to
170 * enable coex 3-wire
171 */
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700172 REG_WRITE(ah, AR_BT_COEX_MODE, btcoex_hw->bt_coex_mode);
173 REG_WRITE(ah, AR_BT_COEX_WEIGHT, btcoex_hw->bt_coex_weights);
174 REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex_hw->bt_coex_mode2);
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700175
176 REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);
177 REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);
178
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700179 ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700180 AR_GPIO_OUTPUT_MUX_AS_RX_CLEAR_EXTERNAL);
181}
182
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530183void ath9k_hw_btcoex_enable(struct ath_hw *ah)
184{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700185 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Vasanthakumar Thiagarajanf14462c2009-08-26 21:08:46 +0530186
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700187 switch (btcoex_hw->scheme) {
Luis R. Rodriguezbc74bf82009-09-09 04:17:45 -0700188 case ATH_BTCOEX_CFG_NONE:
189 break;
190 case ATH_BTCOEX_CFG_2WIRE:
191 ath9k_hw_btcoex_enable_2wire(ah);
192 break;
193 case ATH_BTCOEX_CFG_3WIRE:
194 ath9k_hw_btcoex_enable_3wire(ah);
195 break;
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +0530196 }
197
198 REG_RMW(ah, AR_GPIO_PDPU,
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700199 (0x2 << (btcoex_hw->btactive_gpio * 2)),
200 (0x3 << (btcoex_hw->btactive_gpio * 2)));
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530201
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700202 ah->btcoex_hw.enabled = true;
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530203}
204
205void ath9k_hw_btcoex_disable(struct ath_hw *ah)
206{
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700207 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530208
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700209 ath9k_hw_set_gpio(ah, btcoex_hw->wlanactive_gpio, 0);
Vasanthakumar Thiagarajanf14462c2009-08-26 21:08:46 +0530210
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700211 ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530212 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
213
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700214 if (btcoex_hw->scheme == ATH_BTCOEX_CFG_3WIRE) {
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +0530215 REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE);
216 REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0);
217 REG_WRITE(ah, AR_BT_COEX_MODE2, 0);
218 }
219
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700220 ah->btcoex_hw.enabled = false;
Vasanthakumar Thiagarajan17d50d12009-08-26 21:08:44 +0530221}