btcoex.c 8.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (c) 2009 Atheros Communications Inc.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

17
#include "hw.h"
18

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
enum ath_bt_mode {
	ATH_BT_COEX_MODE_LEGACY,        /* legacy rx_clear mode */
	ATH_BT_COEX_MODE_UNSLOTTED,     /* untimed/unslotted mode */
	ATH_BT_COEX_MODE_SLOTTED,       /* slotted mode */
	ATH_BT_COEX_MODE_DISALBED,      /* coexistence disabled */
};

struct ath_btcoex_config {
	u8 bt_time_extend;
	bool bt_txstate_extend;
	bool bt_txframe_extend;
	enum ath_bt_mode bt_mode; /* coexistence mode */
	bool bt_quiet_collision;
	bool bt_rxclear_polarity; /* invert rx_clear as WLAN_ACTIVE*/
	u8 bt_priority_time;
	u8 bt_first_slot_time;
	bool bt_hold_rx_clear;
};
37 38


39
void ath9k_hw_init_btcoex_hw(struct ath_hw *ah, int qnum)
40
{
41
	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
42 43 44 45 46 47 48 49 50 51 52
	const struct ath_btcoex_config ath_bt_config = {
		.bt_time_extend = 0,
		.bt_txstate_extend = true,
		.bt_txframe_extend = true,
		.bt_mode = ATH_BT_COEX_MODE_SLOTTED,
		.bt_quiet_collision = true,
		.bt_rxclear_polarity = true,
		.bt_priority_time = 2,
		.bt_first_slot_time = 5,
		.bt_hold_rx_clear = true,
	};
53
	u32 i;
54 55 56 57
	bool rxclear_polarity = ath_bt_config.bt_rxclear_polarity;

	if (AR_SREV_9300_20_OR_LATER(ah))
		rxclear_polarity = !ath_bt_config.bt_rxclear_polarity;
58

59 60
	btcoex_hw->bt_coex_mode =
		(btcoex_hw->bt_coex_mode & AR_BT_QCU_THRESH) |
61 62 63 64 65
		SM(ath_bt_config.bt_time_extend, AR_BT_TIME_EXTEND) |
		SM(ath_bt_config.bt_txstate_extend, AR_BT_TXSTATE_EXTEND) |
		SM(ath_bt_config.bt_txframe_extend, AR_BT_TX_FRAME_EXTEND) |
		SM(ath_bt_config.bt_mode, AR_BT_MODE) |
		SM(ath_bt_config.bt_quiet_collision, AR_BT_QUIET) |
66
		SM(rxclear_polarity, AR_BT_RX_CLEAR_POLARITY) |
67 68 69 70
		SM(ath_bt_config.bt_priority_time, AR_BT_PRIORITY_TIME) |
		SM(ath_bt_config.bt_first_slot_time, AR_BT_FIRST_SLOT_TIME) |
		SM(qnum, AR_BT_QCU_THRESH);

71
	btcoex_hw->bt_coex_mode2 =
72 73 74 75 76
		SM(ath_bt_config.bt_hold_rx_clear, AR_BT_HOLD_RX_CLEAR) |
		SM(ATH_BTCOEX_BMISS_THRESH, AR_BT_BCN_MISS_THRESH) |
		AR_BT_DISABLE_BT_ANT;

	for (i = 0; i < 32; i++)
77
		ah->hw_gen_timers.gen_timer_index[(debruijn32 << i) >> 27] = i;
78
}
79
EXPORT_SYMBOL(ath9k_hw_init_btcoex_hw);
80

81
void ath9k_hw_btcoex_init_2wire(struct ath_hw *ah)
82
{
83
	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
84

85 86 87 88
	/* connect bt_active to baseband */
	REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
		    (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
		     AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
89

90 91
	REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
		    AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
92

93 94 95
	/* Set input mux for bt_active to gpio pin */
	REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
		      AR_GPIO_INPUT_MUX1_BT_ACTIVE,
96
		      btcoex_hw->btactive_gpio);
97

98
	/* Configure the desired gpio port for input */
99
	ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
100
}
101
EXPORT_SYMBOL(ath9k_hw_btcoex_init_2wire);
102

103
void ath9k_hw_btcoex_init_3wire(struct ath_hw *ah)
104
{
105
	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
106

107 108 109 110
	/* btcoex 3-wire */
	REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
			(AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB |
			 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB));
111

112 113 114 115
	/* Set input mux for bt_prority_async and
	 *                  bt_active_async to GPIO pins */
	REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
			AR_GPIO_INPUT_MUX1_BT_ACTIVE,
116
			btcoex_hw->btactive_gpio);
117

118 119
	REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
			AR_GPIO_INPUT_MUX1_BT_PRIORITY,
120
			btcoex_hw->btpriority_gpio);
121

122 123
	/* Configure the desired GPIO ports for input */

124 125
	ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
	ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btpriority_gpio);
126
}
127
EXPORT_SYMBOL(ath9k_hw_btcoex_init_3wire);
128

129 130
static void ath9k_hw_btcoex_enable_2wire(struct ath_hw *ah)
{
131
	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
132 133

	/* Configure the desired GPIO port for TX_FRAME output */
134
	ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
135 136 137
			    AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
}

138 139 140 141 142 143 144 145 146
void ath9k_hw_btcoex_set_weight(struct ath_hw *ah,
				u32 bt_weight,
				u32 wlan_weight)
{
	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;

	btcoex_hw->bt_coex_weights = SM(bt_weight, AR_BTCOEX_BT_WGHT) |
				     SM(wlan_weight, AR_BTCOEX_WL_WGHT);
}
147
EXPORT_SYMBOL(ath9k_hw_btcoex_set_weight);
148

149

150 151
static void ath9k_hw_btcoex_enable_3wire(struct ath_hw *ah)
{
152
	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
153
	u32  val;
154 155 156 157 158

	/*
	 * Program coex mode and weight registers to
	 * enable coex 3-wire
	 */
159 160
	REG_WRITE(ah, AR_BT_COEX_MODE, btcoex_hw->bt_coex_mode);
	REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex_hw->bt_coex_mode2);
161

162 163 164 165 166 167 168 169 170 171 172 173 174 175

	if (AR_SREV_9300_20_OR_LATER(ah)) {
		REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS0, ah->bt_coex_wlan_weight[0]);
		REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS1, ah->bt_coex_wlan_weight[1]);
		REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS0, ah->bt_coex_bt_weight[0]);
		REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS1, ah->bt_coex_bt_weight[1]);
		REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS2, ah->bt_coex_bt_weight[2]);
		REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS3, ah->bt_coex_bt_weight[3]);

	} else
		REG_WRITE(ah, AR_BT_COEX_WEIGHT, btcoex_hw->bt_coex_weights);



176 177 178 179 180 181
	if (AR_SREV_9271(ah)) {
		val = REG_READ(ah, 0x50040);
		val &= 0xFFFFFEFF;
		REG_WRITE(ah, 0x50040, val);
	}

182 183 184
	REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);
	REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);

185
	ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
186 187 188
			    AR_GPIO_OUTPUT_MUX_AS_RX_CLEAR_EXTERNAL);
}

189 190
void ath9k_hw_btcoex_enable(struct ath_hw *ah)
{
191
	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
192

193
	switch (btcoex_hw->scheme) {
194 195 196 197 198 199 200 201
	case ATH_BTCOEX_CFG_NONE:
		break;
	case ATH_BTCOEX_CFG_2WIRE:
		ath9k_hw_btcoex_enable_2wire(ah);
		break;
	case ATH_BTCOEX_CFG_3WIRE:
		ath9k_hw_btcoex_enable_3wire(ah);
		break;
202 203 204
	}

	REG_RMW(ah, AR_GPIO_PDPU,
205 206
		(0x2 << (btcoex_hw->btactive_gpio * 2)),
		(0x3 << (btcoex_hw->btactive_gpio * 2)));
207

208
	ah->btcoex_hw.enabled = true;
209
}
210
EXPORT_SYMBOL(ath9k_hw_btcoex_enable);
211 212 213

void ath9k_hw_btcoex_disable(struct ath_hw *ah)
{
214
	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
215

216
	ath9k_hw_set_gpio(ah, btcoex_hw->wlanactive_gpio, 0);
217

218
	ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
219 220
			AR_GPIO_OUTPUT_MUX_AS_OUTPUT);

221
	if (btcoex_hw->scheme == ATH_BTCOEX_CFG_3WIRE) {
222 223
		REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE);
		REG_WRITE(ah, AR_BT_COEX_MODE2, 0);
224 225 226 227 228 229 230 231 232 233 234

		if (AR_SREV_9300_20_OR_LATER(ah)) {
			REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS0, 0);
			REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS1, 0);
			REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS0, 0);
			REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS1, 0);
			REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS2, 0);
			REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS3, 0);
		} else
			REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0);

235 236
	}

237
	ah->btcoex_hw.enabled = false;
238
}
239
EXPORT_SYMBOL(ath9k_hw_btcoex_disable);
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305

static void ar9003_btcoex_bt_stomp(struct ath_hw *ah,
			 enum ath_stomp_type stomp_type)
{
	ah->bt_coex_bt_weight[0] = AR9300_BT_WGHT;
	ah->bt_coex_bt_weight[1] = AR9300_BT_WGHT;
	ah->bt_coex_bt_weight[2] = AR9300_BT_WGHT;
	ah->bt_coex_bt_weight[3] = AR9300_BT_WGHT;


	switch (stomp_type) {
	case ATH_BTCOEX_STOMP_ALL:
		ah->bt_coex_wlan_weight[0] = AR9300_STOMP_ALL_WLAN_WGHT0;
		ah->bt_coex_wlan_weight[1] = AR9300_STOMP_ALL_WLAN_WGHT1;
		break;
	case ATH_BTCOEX_STOMP_LOW:
		ah->bt_coex_wlan_weight[0] = AR9300_STOMP_LOW_WLAN_WGHT0;
		ah->bt_coex_wlan_weight[1] = AR9300_STOMP_LOW_WLAN_WGHT1;
		break;
	case ATH_BTCOEX_STOMP_NONE:
		ah->bt_coex_wlan_weight[0] = AR9300_STOMP_NONE_WLAN_WGHT0;
		ah->bt_coex_wlan_weight[1] = AR9300_STOMP_NONE_WLAN_WGHT1;
		break;

	default:
		ath_dbg(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
				"Invalid Stomptype\n");
		break;
	}

	ath9k_hw_btcoex_enable(ah);
}

/*
 * Configures appropriate weight based on stomp type.
 */
void ath9k_hw_btcoex_bt_stomp(struct ath_hw *ah,
			      enum ath_stomp_type stomp_type)
{
	if (AR_SREV_9300_20_OR_LATER(ah)) {
		ar9003_btcoex_bt_stomp(ah, stomp_type);
		return;
	}

	switch (stomp_type) {
	case ATH_BTCOEX_STOMP_ALL:
		ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
				AR_STOMP_ALL_WLAN_WGHT);
		break;
	case ATH_BTCOEX_STOMP_LOW:
		ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
				AR_STOMP_LOW_WLAN_WGHT);
		break;
	case ATH_BTCOEX_STOMP_NONE:
		ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
				AR_STOMP_NONE_WLAN_WGHT);
		break;
	default:
		ath_dbg(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
				"Invalid Stomptype\n");
		break;
	}

	ath9k_hw_btcoex_enable(ah);
}
EXPORT_SYMBOL(ath9k_hw_btcoex_bt_stomp);