xref: /linux/drivers/net/wireless/ath/ath9k/btcoex.c (revision e1ff147d878ab2b74621abc92a6902db94b2f6ab)
117d50d1dSVasanthakumar Thiagarajan /*
25b68138eSSujith Manoharan  * Copyright (c) 2009-2011 Atheros Communications Inc.
317d50d1dSVasanthakumar Thiagarajan  *
417d50d1dSVasanthakumar Thiagarajan  * Permission to use, copy, modify, and/or distribute this software for any
517d50d1dSVasanthakumar Thiagarajan  * purpose with or without fee is hereby granted, provided that the above
617d50d1dSVasanthakumar Thiagarajan  * copyright notice and this permission notice appear in all copies.
717d50d1dSVasanthakumar Thiagarajan  *
817d50d1dSVasanthakumar Thiagarajan  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
917d50d1dSVasanthakumar Thiagarajan  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1017d50d1dSVasanthakumar Thiagarajan  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1117d50d1dSVasanthakumar Thiagarajan  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1217d50d1dSVasanthakumar Thiagarajan  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1317d50d1dSVasanthakumar Thiagarajan  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1417d50d1dSVasanthakumar Thiagarajan  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1517d50d1dSVasanthakumar Thiagarajan  */
1617d50d1dSVasanthakumar Thiagarajan 
17ee40fa06SPaul Gortmaker #include <linux/export.h>
18cfe8cba9SLuis R. Rodriguez #include "hw.h"
1917d50d1dSVasanthakumar Thiagarajan 
208b4fc5baSLuis R. Rodriguez enum ath_bt_mode {
218b4fc5baSLuis R. Rodriguez 	ATH_BT_COEX_MODE_LEGACY,        /* legacy rx_clear mode */
228b4fc5baSLuis R. Rodriguez 	ATH_BT_COEX_MODE_UNSLOTTED,     /* untimed/unslotted mode */
238b4fc5baSLuis R. Rodriguez 	ATH_BT_COEX_MODE_SLOTTED,       /* slotted mode */
2432b1076dSMohammed Shafi Shajakhan 	ATH_BT_COEX_MODE_DISABLED,      /* coexistence disabled */
258b4fc5baSLuis R. Rodriguez };
268b4fc5baSLuis R. Rodriguez 
278b4fc5baSLuis R. Rodriguez struct ath_btcoex_config {
288b4fc5baSLuis R. Rodriguez 	u8 bt_time_extend;
298b4fc5baSLuis R. Rodriguez 	bool bt_txstate_extend;
308b4fc5baSLuis R. Rodriguez 	bool bt_txframe_extend;
318b4fc5baSLuis R. Rodriguez 	enum ath_bt_mode bt_mode; /* coexistence mode */
328b4fc5baSLuis R. Rodriguez 	bool bt_quiet_collision;
338b4fc5baSLuis R. Rodriguez 	bool bt_rxclear_polarity; /* invert rx_clear as WLAN_ACTIVE*/
348b4fc5baSLuis R. Rodriguez 	u8 bt_priority_time;
358b4fc5baSLuis R. Rodriguez 	u8 bt_first_slot_time;
368b4fc5baSLuis R. Rodriguez 	bool bt_hold_rx_clear;
378b4fc5baSLuis R. Rodriguez };
381773912bSVasanthakumar Thiagarajan 
3954f10b05SRajkumar Manoharan static const u32 ar9003_wlan_weights[ATH_BTCOEX_STOMP_MAX]
4054f10b05SRajkumar Manoharan 				    [AR9300_NUM_WLAN_WEIGHTS] = {
4154f10b05SRajkumar Manoharan 	{ 0xfffffff0, 0xfffffff0, 0xfffffff0, 0xfffffff0 }, /* STOMP_ALL */
4254f10b05SRajkumar Manoharan 	{ 0x88888880, 0x88888880, 0x88888880, 0x88888880 }, /* STOMP_LOW */
4354f10b05SRajkumar Manoharan 	{ 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, /* STOMP_NONE */
4454f10b05SRajkumar Manoharan };
451773912bSVasanthakumar Thiagarajan 
465160b46fSSujith Manoharan static const u32 mci_wlan_weights[ATH_BTCOEX_STOMP_MAX]
478227bf45SRajkumar Manoharan 				 [AR9300_NUM_WLAN_WEIGHTS] = {
488227bf45SRajkumar Manoharan 	{ 0x01017d01, 0x41414101, 0x41414101, 0x41414141 }, /* STOMP_ALL */
498227bf45SRajkumar Manoharan 	{ 0x01017d01, 0x3b3b3b01, 0x3b3b3b01, 0x3b3b3b3b }, /* STOMP_LOW */
508227bf45SRajkumar Manoharan 	{ 0x01017d01, 0x01010101, 0x01010101, 0x01010101 }, /* STOMP_NONE */
518227bf45SRajkumar Manoharan 	{ 0x01017d01, 0x013b0101, 0x3b3b0101, 0x3b3b013b }, /* STOMP_LOW_FTP */
522884561aSRajkumar Manoharan 	{ 0xffffff01, 0xffffffff, 0xffffff01, 0xffffffff }, /* STOMP_AUDIO */
538227bf45SRajkumar Manoharan };
548227bf45SRajkumar Manoharan 
55766ec4a9SLuis R. Rodriguez void ath9k_hw_init_btcoex_hw(struct ath_hw *ah, int qnum)
56af03abecSLuis R. Rodriguez {
57766ec4a9SLuis R. Rodriguez 	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
588b4fc5baSLuis R. Rodriguez 	const struct ath_btcoex_config ath_bt_config = {
598b4fc5baSLuis R. Rodriguez 		.bt_time_extend = 0,
608b4fc5baSLuis R. Rodriguez 		.bt_txstate_extend = true,
618b4fc5baSLuis R. Rodriguez 		.bt_txframe_extend = true,
628b4fc5baSLuis R. Rodriguez 		.bt_mode = ATH_BT_COEX_MODE_SLOTTED,
638b4fc5baSLuis R. Rodriguez 		.bt_quiet_collision = true,
648b4fc5baSLuis R. Rodriguez 		.bt_rxclear_polarity = true,
658b4fc5baSLuis R. Rodriguez 		.bt_priority_time = 2,
668b4fc5baSLuis R. Rodriguez 		.bt_first_slot_time = 5,
678b4fc5baSLuis R. Rodriguez 		.bt_hold_rx_clear = true,
688b4fc5baSLuis R. Rodriguez 	};
69a6ef530fSVivek Natarajan 	bool rxclear_polarity = ath_bt_config.bt_rxclear_polarity;
70a6ef530fSVivek Natarajan 
71a6ef530fSVivek Natarajan 	if (AR_SREV_9300_20_OR_LATER(ah))
72a6ef530fSVivek Natarajan 		rxclear_polarity = !ath_bt_config.bt_rxclear_polarity;
731773912bSVasanthakumar Thiagarajan 
74766ec4a9SLuis R. Rodriguez 	btcoex_hw->bt_coex_mode =
75766ec4a9SLuis R. Rodriguez 		(btcoex_hw->bt_coex_mode & AR_BT_QCU_THRESH) |
761773912bSVasanthakumar Thiagarajan 		SM(ath_bt_config.bt_time_extend, AR_BT_TIME_EXTEND) |
771773912bSVasanthakumar Thiagarajan 		SM(ath_bt_config.bt_txstate_extend, AR_BT_TXSTATE_EXTEND) |
781773912bSVasanthakumar Thiagarajan 		SM(ath_bt_config.bt_txframe_extend, AR_BT_TX_FRAME_EXTEND) |
791773912bSVasanthakumar Thiagarajan 		SM(ath_bt_config.bt_mode, AR_BT_MODE) |
801773912bSVasanthakumar Thiagarajan 		SM(ath_bt_config.bt_quiet_collision, AR_BT_QUIET) |
81a6ef530fSVivek Natarajan 		SM(rxclear_polarity, AR_BT_RX_CLEAR_POLARITY) |
821773912bSVasanthakumar Thiagarajan 		SM(ath_bt_config.bt_priority_time, AR_BT_PRIORITY_TIME) |
831773912bSVasanthakumar Thiagarajan 		SM(ath_bt_config.bt_first_slot_time, AR_BT_FIRST_SLOT_TIME) |
841773912bSVasanthakumar Thiagarajan 		SM(qnum, AR_BT_QCU_THRESH);
851773912bSVasanthakumar Thiagarajan 
86766ec4a9SLuis R. Rodriguez 	btcoex_hw->bt_coex_mode2 =
871773912bSVasanthakumar Thiagarajan 		SM(ath_bt_config.bt_hold_rx_clear, AR_BT_HOLD_RX_CLEAR) |
881773912bSVasanthakumar Thiagarajan 		SM(ATH_BTCOEX_BMISS_THRESH, AR_BT_BCN_MISS_THRESH) |
891773912bSVasanthakumar Thiagarajan 		AR_BT_DISABLE_BT_ANT;
901773912bSVasanthakumar Thiagarajan }
917322fd19SLuis R. Rodriguez EXPORT_SYMBOL(ath9k_hw_init_btcoex_hw);
921773912bSVasanthakumar Thiagarajan 
93d68475deSSujith Manoharan void ath9k_hw_btcoex_init_scheme(struct ath_hw *ah)
94d68475deSSujith Manoharan {
95d68475deSSujith Manoharan 	struct ath_common *common = ath9k_hw_common(ah);
96d68475deSSujith Manoharan 	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
97d68475deSSujith Manoharan 
98d68475deSSujith Manoharan 	/*
99d68475deSSujith Manoharan 	 * Check if BTCOEX is globally disabled.
100d68475deSSujith Manoharan 	 */
101d68475deSSujith Manoharan 	if (!common->btcoex_enabled) {
102d68475deSSujith Manoharan 		btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
103d68475deSSujith Manoharan 		return;
104d68475deSSujith Manoharan 	}
105d68475deSSujith Manoharan 
106*e1ff147dSSujith Manoharan 	if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI) {
107*e1ff147dSSujith Manoharan 		btcoex_hw->scheme = ATH_BTCOEX_CFG_MCI;
108*e1ff147dSSujith Manoharan 	} else if (AR_SREV_9300_20_OR_LATER(ah)) {
109d68475deSSujith Manoharan 		btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
110d68475deSSujith Manoharan 		btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO_9300;
111d68475deSSujith Manoharan 		btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO_9300;
112d68475deSSujith Manoharan 		btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO_9300;
113d68475deSSujith Manoharan 	} else if (AR_SREV_9280_20_OR_LATER(ah)) {
114d68475deSSujith Manoharan 		btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO_9280;
115d68475deSSujith Manoharan 		btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO_9280;
116d68475deSSujith Manoharan 
117d68475deSSujith Manoharan 		if (AR_SREV_9285(ah)) {
118d68475deSSujith Manoharan 			btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
119d68475deSSujith Manoharan 			btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO_9285;
120d68475deSSujith Manoharan 		} else {
121d68475deSSujith Manoharan 			btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
122d68475deSSujith Manoharan 		}
123d68475deSSujith Manoharan 	}
124d68475deSSujith Manoharan }
125d68475deSSujith Manoharan EXPORT_SYMBOL(ath9k_hw_btcoex_init_scheme);
126d68475deSSujith Manoharan 
12775d7839fSLuis R. Rodriguez void ath9k_hw_btcoex_init_2wire(struct ath_hw *ah)
12817d50d1dSVasanthakumar Thiagarajan {
129766ec4a9SLuis R. Rodriguez 	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
130f14462c6SVasanthakumar Thiagarajan 
13117d50d1dSVasanthakumar Thiagarajan 	/* connect bt_active to baseband */
13217d50d1dSVasanthakumar Thiagarajan 	REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
13317d50d1dSVasanthakumar Thiagarajan 		    (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
13417d50d1dSVasanthakumar Thiagarajan 		     AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
13517d50d1dSVasanthakumar Thiagarajan 
13617d50d1dSVasanthakumar Thiagarajan 	REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
13717d50d1dSVasanthakumar Thiagarajan 		    AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
13817d50d1dSVasanthakumar Thiagarajan 
13917d50d1dSVasanthakumar Thiagarajan 	/* Set input mux for bt_active to gpio pin */
14017d50d1dSVasanthakumar Thiagarajan 	REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
14117d50d1dSVasanthakumar Thiagarajan 		      AR_GPIO_INPUT_MUX1_BT_ACTIVE,
142766ec4a9SLuis R. Rodriguez 		      btcoex_hw->btactive_gpio);
14317d50d1dSVasanthakumar Thiagarajan 
14417d50d1dSVasanthakumar Thiagarajan 	/* Configure the desired gpio port for input */
145766ec4a9SLuis R. Rodriguez 	ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
1467a2f0f58SLuis R. Rodriguez }
1477322fd19SLuis R. Rodriguez EXPORT_SYMBOL(ath9k_hw_btcoex_init_2wire);
1487a2f0f58SLuis R. Rodriguez 
14975d7839fSLuis R. Rodriguez void ath9k_hw_btcoex_init_3wire(struct ath_hw *ah)
1507a2f0f58SLuis R. Rodriguez {
151766ec4a9SLuis R. Rodriguez 	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
1527a2f0f58SLuis R. Rodriguez 
1531773912bSVasanthakumar Thiagarajan 	/* btcoex 3-wire */
1541773912bSVasanthakumar Thiagarajan 	REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
1551773912bSVasanthakumar Thiagarajan 			(AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB |
1561773912bSVasanthakumar Thiagarajan 			 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB));
1571773912bSVasanthakumar Thiagarajan 
1581773912bSVasanthakumar Thiagarajan 	/* Set input mux for bt_prority_async and
1591773912bSVasanthakumar Thiagarajan 	 *                  bt_active_async to GPIO pins */
1601773912bSVasanthakumar Thiagarajan 	REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
1611773912bSVasanthakumar Thiagarajan 			AR_GPIO_INPUT_MUX1_BT_ACTIVE,
162766ec4a9SLuis R. Rodriguez 			btcoex_hw->btactive_gpio);
1631773912bSVasanthakumar Thiagarajan 
1641773912bSVasanthakumar Thiagarajan 	REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
1651773912bSVasanthakumar Thiagarajan 			AR_GPIO_INPUT_MUX1_BT_PRIORITY,
166766ec4a9SLuis R. Rodriguez 			btcoex_hw->btpriority_gpio);
1671773912bSVasanthakumar Thiagarajan 
1681773912bSVasanthakumar Thiagarajan 	/* Configure the desired GPIO ports for input */
1691773912bSVasanthakumar Thiagarajan 
170766ec4a9SLuis R. Rodriguez 	ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btactive_gpio);
171766ec4a9SLuis R. Rodriguez 	ath9k_hw_cfg_gpio_input(ah, btcoex_hw->btpriority_gpio);
1727a2f0f58SLuis R. Rodriguez }
1737322fd19SLuis R. Rodriguez EXPORT_SYMBOL(ath9k_hw_btcoex_init_3wire);
1741773912bSVasanthakumar Thiagarajan 
175d3c83ac1SSujith Manoharan void ath9k_hw_btcoex_init_mci(struct ath_hw *ah)
176d3c83ac1SSujith Manoharan {
177d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.ready = false;
178d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.bt_state = 0;
179d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.bt_ver_major = 3;
180d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.bt_ver_minor = 0;
181d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.bt_version_known = false;
182d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.update_2g5g = true;
183d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.is_2g = true;
184d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.wlan_channels_update = false;
185d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.wlan_channels[0] = 0x00000000;
186d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.wlan_channels[1] = 0xffffffff;
187d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.wlan_channels[2] = 0xffffffff;
188d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.wlan_channels[3] = 0x7fffffff;
189d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.query_bt = true;
190d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.unhalt_bt_gpm = true;
191d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.halted_bt_gpm = false;
192d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.need_flush_btinfo = false;
193d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.wlan_cal_seq = 0;
194d3c83ac1SSujith Manoharan 	ah->btcoex_hw.mci.wlan_cal_done = 0;
1953c5c9d04SRajkumar Manoharan 	ah->btcoex_hw.mci.config = (AR_SREV_9462(ah)) ? 0x2201 : 0xa4c1;
196d3c83ac1SSujith Manoharan }
197d3c83ac1SSujith Manoharan EXPORT_SYMBOL(ath9k_hw_btcoex_init_mci);
198d3c83ac1SSujith Manoharan 
199bc74bf8fSLuis R. Rodriguez static void ath9k_hw_btcoex_enable_2wire(struct ath_hw *ah)
20017d50d1dSVasanthakumar Thiagarajan {
201766ec4a9SLuis R. Rodriguez 	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
202f14462c6SVasanthakumar Thiagarajan 
20317d50d1dSVasanthakumar Thiagarajan 	/* Configure the desired GPIO port for TX_FRAME output */
204766ec4a9SLuis R. Rodriguez 	ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
20517d50d1dSVasanthakumar Thiagarajan 			    AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
206bc74bf8fSLuis R. Rodriguez }
207bc74bf8fSLuis R. Rodriguez 
2085160b46fSSujith Manoharan /*
2095160b46fSSujith Manoharan  * For AR9002, bt_weight/wlan_weight are used.
2105160b46fSSujith Manoharan  * For AR9003 and above, stomp_type is used.
2115160b46fSSujith Manoharan  */
2125e197292SLuis R. Rodriguez void ath9k_hw_btcoex_set_weight(struct ath_hw *ah,
2135e197292SLuis R. Rodriguez 				u32 bt_weight,
2145160b46fSSujith Manoharan 				u32 wlan_weight,
2155160b46fSSujith Manoharan 				enum ath_stomp_type stomp_type)
2165e197292SLuis R. Rodriguez {
2175e197292SLuis R. Rodriguez 	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
218db60428bSRajkumar Manoharan 	struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
219db60428bSRajkumar Manoharan 	u8 txprio_shift[] = { 24, 16, 16, 0 }; /* tx priority weight */
220db60428bSRajkumar Manoharan 	bool concur_tx = (mci_hw->concur_tx && btcoex_hw->tx_prio[stomp_type]);
2215160b46fSSujith Manoharan 	const u32 *weight = ar9003_wlan_weights[stomp_type];
2225160b46fSSujith Manoharan 	int i;
2235160b46fSSujith Manoharan 
224db60428bSRajkumar Manoharan 	if (!AR_SREV_9300_20_OR_LATER(ah)) {
225db60428bSRajkumar Manoharan 		btcoex_hw->bt_coex_weights =
226db60428bSRajkumar Manoharan 			SM(bt_weight, AR_BTCOEX_BT_WGHT) |
227db60428bSRajkumar Manoharan 			SM(wlan_weight, AR_BTCOEX_WL_WGHT);
228db60428bSRajkumar Manoharan 		return;
229db60428bSRajkumar Manoharan 	}
230db60428bSRajkumar Manoharan 
2315160b46fSSujith Manoharan 	if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
232db60428bSRajkumar Manoharan 		enum ath_stomp_type stype =
233db60428bSRajkumar Manoharan 			((stomp_type == ATH_BTCOEX_STOMP_LOW) &&
234db60428bSRajkumar Manoharan 			 btcoex_hw->mci.stomp_ftp) ?
235db60428bSRajkumar Manoharan 			ATH_BTCOEX_STOMP_LOW_FTP : stomp_type;
236db60428bSRajkumar Manoharan 		weight = mci_wlan_weights[stype];
2375160b46fSSujith Manoharan 	}
2385160b46fSSujith Manoharan 
2395160b46fSSujith Manoharan 	for (i = 0; i < AR9300_NUM_WLAN_WEIGHTS; i++) {
2405160b46fSSujith Manoharan 		btcoex_hw->bt_weight[i] = AR9300_BT_WGHT;
2415160b46fSSujith Manoharan 		btcoex_hw->wlan_weight[i] = weight[i];
242db60428bSRajkumar Manoharan 		if (concur_tx && i) {
243db60428bSRajkumar Manoharan 			btcoex_hw->wlan_weight[i] &=
244db60428bSRajkumar Manoharan 				~(0xff << txprio_shift[i-1]);
245db60428bSRajkumar Manoharan 			btcoex_hw->wlan_weight[i] |=
246db60428bSRajkumar Manoharan 				(btcoex_hw->tx_prio[stomp_type] <<
247db60428bSRajkumar Manoharan 				 txprio_shift[i-1]);
2485160b46fSSujith Manoharan 		}
2495e197292SLuis R. Rodriguez 	}
250db60428bSRajkumar Manoharan 	/* Last WLAN weight has to be adjusted wrt tx priority */
251db60428bSRajkumar Manoharan 	if (concur_tx) {
252db60428bSRajkumar Manoharan 		btcoex_hw->wlan_weight[i-1] &= ~(0xff << txprio_shift[i-1]);
253db60428bSRajkumar Manoharan 		btcoex_hw->wlan_weight[i-1] |= (btcoex_hw->tx_prio[stomp_type]
254db60428bSRajkumar Manoharan 						      << txprio_shift[i-1]);
255db60428bSRajkumar Manoharan 	}
256db60428bSRajkumar Manoharan 
2575160b46fSSujith Manoharan }
2587322fd19SLuis R. Rodriguez EXPORT_SYMBOL(ath9k_hw_btcoex_set_weight);
2595e197292SLuis R. Rodriguez 
260a6ef530fSVivek Natarajan 
261bc74bf8fSLuis R. Rodriguez static void ath9k_hw_btcoex_enable_3wire(struct ath_hw *ah)
262bc74bf8fSLuis R. Rodriguez {
26354f10b05SRajkumar Manoharan 	struct ath_btcoex_hw *btcoex = &ah->btcoex_hw;
26421cb9879SVivek Natarajan 	u32  val;
26554f10b05SRajkumar Manoharan 	int i;
266bc74bf8fSLuis R. Rodriguez 
2671773912bSVasanthakumar Thiagarajan 	/*
2681773912bSVasanthakumar Thiagarajan 	 * Program coex mode and weight registers to
2691773912bSVasanthakumar Thiagarajan 	 * enable coex 3-wire
2701773912bSVasanthakumar Thiagarajan 	 */
27154f10b05SRajkumar Manoharan 	REG_WRITE(ah, AR_BT_COEX_MODE, btcoex->bt_coex_mode);
27254f10b05SRajkumar Manoharan 	REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex->bt_coex_mode2);
2731773912bSVasanthakumar Thiagarajan 
274a6ef530fSVivek Natarajan 
275a6ef530fSVivek Natarajan 	if (AR_SREV_9300_20_OR_LATER(ah)) {
27654f10b05SRajkumar Manoharan 		REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS0, btcoex->wlan_weight[0]);
27754f10b05SRajkumar Manoharan 		REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS1, btcoex->wlan_weight[1]);
27854f10b05SRajkumar Manoharan 		for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++)
27954f10b05SRajkumar Manoharan 			REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS(i),
28054f10b05SRajkumar Manoharan 				  btcoex->bt_weight[i]);
281a6ef530fSVivek Natarajan 	} else
28254f10b05SRajkumar Manoharan 		REG_WRITE(ah, AR_BT_COEX_WEIGHT, btcoex->bt_coex_weights);
283a6ef530fSVivek Natarajan 
284a6ef530fSVivek Natarajan 
285a6ef530fSVivek Natarajan 
28621cb9879SVivek Natarajan 	if (AR_SREV_9271(ah)) {
28721cb9879SVivek Natarajan 		val = REG_READ(ah, 0x50040);
28821cb9879SVivek Natarajan 		val &= 0xFFFFFEFF;
28921cb9879SVivek Natarajan 		REG_WRITE(ah, 0x50040, val);
29021cb9879SVivek Natarajan 	}
29121cb9879SVivek Natarajan 
292bc74bf8fSLuis R. Rodriguez 	REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);
293bc74bf8fSLuis R. Rodriguez 	REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);
2941773912bSVasanthakumar Thiagarajan 
29554f10b05SRajkumar Manoharan 	ath9k_hw_cfg_output(ah, btcoex->wlanactive_gpio,
2961773912bSVasanthakumar Thiagarajan 			    AR_GPIO_OUTPUT_MUX_AS_RX_CLEAR_EXTERNAL);
2971773912bSVasanthakumar Thiagarajan }
2981773912bSVasanthakumar Thiagarajan 
2998227bf45SRajkumar Manoharan static void ath9k_hw_btcoex_enable_mci(struct ath_hw *ah)
3008227bf45SRajkumar Manoharan {
3018227bf45SRajkumar Manoharan 	struct ath_btcoex_hw *btcoex = &ah->btcoex_hw;
3028227bf45SRajkumar Manoharan 	int i;
3038227bf45SRajkumar Manoharan 
3048227bf45SRajkumar Manoharan 	for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++)
3058227bf45SRajkumar Manoharan 		REG_WRITE(ah, AR_MCI_COEX_WL_WEIGHTS(i),
3068227bf45SRajkumar Manoharan 			  btcoex->wlan_weight[i]);
3078227bf45SRajkumar Manoharan 
3088227bf45SRajkumar Manoharan 	REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);
3098227bf45SRajkumar Manoharan 	btcoex->enabled = true;
3108227bf45SRajkumar Manoharan }
3118227bf45SRajkumar Manoharan 
312*e1ff147dSSujith Manoharan static void ath9k_hw_btcoex_disable_mci(struct ath_hw *ah)
313*e1ff147dSSujith Manoharan {
314*e1ff147dSSujith Manoharan 	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
315*e1ff147dSSujith Manoharan 	int i;
316*e1ff147dSSujith Manoharan 
317*e1ff147dSSujith Manoharan 	ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE);
318*e1ff147dSSujith Manoharan 
319*e1ff147dSSujith Manoharan 	for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++)
320*e1ff147dSSujith Manoharan 		REG_WRITE(ah, AR_MCI_COEX_WL_WEIGHTS(i),
321*e1ff147dSSujith Manoharan 			  btcoex_hw->wlan_weight[i]);
322*e1ff147dSSujith Manoharan }
323*e1ff147dSSujith Manoharan 
324bc74bf8fSLuis R. Rodriguez void ath9k_hw_btcoex_enable(struct ath_hw *ah)
325bc74bf8fSLuis R. Rodriguez {
326766ec4a9SLuis R. Rodriguez 	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
327bc74bf8fSLuis R. Rodriguez 
3288a309305SFelix Fietkau 	switch (ath9k_hw_get_btcoex_scheme(ah)) {
329bc74bf8fSLuis R. Rodriguez 	case ATH_BTCOEX_CFG_NONE:
3308a309305SFelix Fietkau 		return;
331bc74bf8fSLuis R. Rodriguez 	case ATH_BTCOEX_CFG_2WIRE:
332bc74bf8fSLuis R. Rodriguez 		ath9k_hw_btcoex_enable_2wire(ah);
333bc74bf8fSLuis R. Rodriguez 		break;
334bc74bf8fSLuis R. Rodriguez 	case ATH_BTCOEX_CFG_3WIRE:
3350466e254SRajkumar Manoharan 		ath9k_hw_btcoex_enable_3wire(ah);
3360466e254SRajkumar Manoharan 		break;
337*e1ff147dSSujith Manoharan 	case ATH_BTCOEX_CFG_MCI:
338*e1ff147dSSujith Manoharan 		ath9k_hw_btcoex_enable_mci(ah);
339*e1ff147dSSujith Manoharan 		break;
3400466e254SRajkumar Manoharan 	}
341bc74bf8fSLuis R. Rodriguez 
342*e1ff147dSSujith Manoharan 	if (ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_MCI) {
3431773912bSVasanthakumar Thiagarajan 		REG_RMW(ah, AR_GPIO_PDPU,
344766ec4a9SLuis R. Rodriguez 			(0x2 << (btcoex_hw->btactive_gpio * 2)),
345766ec4a9SLuis R. Rodriguez 			(0x3 << (btcoex_hw->btactive_gpio * 2)));
346*e1ff147dSSujith Manoharan 	}
34717d50d1dSVasanthakumar Thiagarajan 
348766ec4a9SLuis R. Rodriguez 	ah->btcoex_hw.enabled = true;
34917d50d1dSVasanthakumar Thiagarajan }
3507322fd19SLuis R. Rodriguez EXPORT_SYMBOL(ath9k_hw_btcoex_enable);
35117d50d1dSVasanthakumar Thiagarajan 
35217d50d1dSVasanthakumar Thiagarajan void ath9k_hw_btcoex_disable(struct ath_hw *ah)
35317d50d1dSVasanthakumar Thiagarajan {
354766ec4a9SLuis R. Rodriguez 	struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
35554f10b05SRajkumar Manoharan 	int i;
35617d50d1dSVasanthakumar Thiagarajan 
3578227bf45SRajkumar Manoharan 	btcoex_hw->enabled = false;
358*e1ff147dSSujith Manoharan 
359*e1ff147dSSujith Manoharan 	if (ath9k_hw_get_btcoex_scheme(ah) == ATH_BTCOEX_CFG_MCI) {
360*e1ff147dSSujith Manoharan 		ath9k_hw_btcoex_disable_mci(ah);
3610466e254SRajkumar Manoharan 		return;
3628227bf45SRajkumar Manoharan 	}
363*e1ff147dSSujith Manoharan 
364766ec4a9SLuis R. Rodriguez 	ath9k_hw_set_gpio(ah, btcoex_hw->wlanactive_gpio, 0);
365f14462c6SVasanthakumar Thiagarajan 
366766ec4a9SLuis R. Rodriguez 	ath9k_hw_cfg_output(ah, btcoex_hw->wlanactive_gpio,
36717d50d1dSVasanthakumar Thiagarajan 			AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
36817d50d1dSVasanthakumar Thiagarajan 
369766ec4a9SLuis R. Rodriguez 	if (btcoex_hw->scheme == ATH_BTCOEX_CFG_3WIRE) {
3701773912bSVasanthakumar Thiagarajan 		REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE);
3711773912bSVasanthakumar Thiagarajan 		REG_WRITE(ah, AR_BT_COEX_MODE2, 0);
372a6ef530fSVivek Natarajan 
373a6ef530fSVivek Natarajan 		if (AR_SREV_9300_20_OR_LATER(ah)) {
374a6ef530fSVivek Natarajan 			REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS0, 0);
375a6ef530fSVivek Natarajan 			REG_WRITE(ah, AR_BT_COEX_WL_WEIGHTS1, 0);
37654f10b05SRajkumar Manoharan 			for (i = 0; i < AR9300_NUM_BT_WEIGHTS; i++)
37754f10b05SRajkumar Manoharan 				REG_WRITE(ah, AR_BT_COEX_BT_WEIGHTS(i), 0);
378a6ef530fSVivek Natarajan 		} else
379a6ef530fSVivek Natarajan 			REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0);
380a6ef530fSVivek Natarajan 
3811773912bSVasanthakumar Thiagarajan 	}
38217d50d1dSVasanthakumar Thiagarajan }
3837322fd19SLuis R. Rodriguez EXPORT_SYMBOL(ath9k_hw_btcoex_disable);
384978f78bfSVivek Natarajan 
385978f78bfSVivek Natarajan /*
386978f78bfSVivek Natarajan  * Configures appropriate weight based on stomp type.
387978f78bfSVivek Natarajan  */
388978f78bfSVivek Natarajan void ath9k_hw_btcoex_bt_stomp(struct ath_hw *ah,
389978f78bfSVivek Natarajan 			      enum ath_stomp_type stomp_type)
390978f78bfSVivek Natarajan {
391978f78bfSVivek Natarajan 	if (AR_SREV_9300_20_OR_LATER(ah)) {
3925160b46fSSujith Manoharan 		ath9k_hw_btcoex_set_weight(ah, 0, 0, stomp_type);
393978f78bfSVivek Natarajan 		return;
394978f78bfSVivek Natarajan 	}
395978f78bfSVivek Natarajan 
396978f78bfSVivek Natarajan 	switch (stomp_type) {
397978f78bfSVivek Natarajan 	case ATH_BTCOEX_STOMP_ALL:
398978f78bfSVivek Natarajan 		ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
3995160b46fSSujith Manoharan 					   AR_STOMP_ALL_WLAN_WGHT, 0);
400978f78bfSVivek Natarajan 		break;
401978f78bfSVivek Natarajan 	case ATH_BTCOEX_STOMP_LOW:
402978f78bfSVivek Natarajan 		ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
4035160b46fSSujith Manoharan 					   AR_STOMP_LOW_WLAN_WGHT, 0);
404978f78bfSVivek Natarajan 		break;
405978f78bfSVivek Natarajan 	case ATH_BTCOEX_STOMP_NONE:
406978f78bfSVivek Natarajan 		ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
4075160b46fSSujith Manoharan 					   AR_STOMP_NONE_WLAN_WGHT, 0);
408978f78bfSVivek Natarajan 		break;
409978f78bfSVivek Natarajan 	default:
410d2182b69SJoe Perches 		ath_dbg(ath9k_hw_common(ah), BTCOEX, "Invalid Stomptype\n");
411978f78bfSVivek Natarajan 		break;
412978f78bfSVivek Natarajan 	}
413978f78bfSVivek Natarajan }
414978f78bfSVivek Natarajan EXPORT_SYMBOL(ath9k_hw_btcoex_bt_stomp);
415db60428bSRajkumar Manoharan 
416db60428bSRajkumar Manoharan void ath9k_hw_btcoex_set_concur_txprio(struct ath_hw *ah, u8 *stomp_txprio)
417db60428bSRajkumar Manoharan {
418db60428bSRajkumar Manoharan 	struct ath_btcoex_hw *btcoex = &ah->btcoex_hw;
419db60428bSRajkumar Manoharan 	int i;
420db60428bSRajkumar Manoharan 
421db60428bSRajkumar Manoharan 	for (i = 0; i < ATH_BTCOEX_STOMP_MAX; i++)
422db60428bSRajkumar Manoharan 		btcoex->tx_prio[i] = stomp_txprio[i];
423db60428bSRajkumar Manoharan }
424db60428bSRajkumar Manoharan EXPORT_SYMBOL(ath9k_hw_btcoex_set_concur_txprio);
425