2 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2005 Atheros Communications, Inc.
4 * Copyright (c) 2008-2010, Atheros Communications Inc.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include "ah_internal.h"
27 #include "ah_desc.h" /* NB: for HAL_PHYERR* */
30 #include "ar5416/ar5416.h"
31 #include "ar5416/ar5416reg.h"
32 #include "ar5416/ar5416phy.h"
33 #include "ar5416/ar5416desc.h" /* AR5416_CONTTXMODE */
34 #include "ar5416/ar5416_btcoex.h"
37 ar5416SetBTCoexInfo(struct ath_hal *ah, HAL_BT_COEX_INFO *btinfo)
39 struct ath_hal_5416 *ahp = AH5416(ah);
41 ahp->ah_btModule = btinfo->bt_module;
42 ahp->ah_btCoexConfigType = btinfo->bt_coex_config;
43 ahp->ah_btActiveGpioSelect = btinfo->bt_gpio_bt_active;
44 ahp->ah_btPriorityGpioSelect = btinfo->bt_gpio_bt_priority;
45 ahp->ah_wlanActiveGpioSelect = btinfo->bt_gpio_wlan_active;
46 ahp->ah_btActivePolarity = btinfo->bt_active_polarity;
47 ahp->ah_btCoexSingleAnt = btinfo->bt_single_ant;
48 ahp->ah_btWlanIsolation = btinfo->bt_isolation;
52 ar5416BTCoexConfig(struct ath_hal *ah, HAL_BT_COEX_CONFIG *btconf)
54 struct ath_hal_5416 *ahp = AH5416(ah);
55 HAL_BOOL rxClearPolarity = btconf->bt_rxclear_polarity;
58 * For Kiwi and Osprey, the polarity of rx_clear is active high.
59 * The bt_rxclear_polarity flag from ath(4) needs to be inverted.
61 if (AR_SREV_KIWI(ah)) {
62 rxClearPolarity = !btconf->bt_rxclear_polarity;
65 ahp->ah_btCoexMode = (ahp->ah_btCoexMode & AR_BT_QCU_THRESH) |
66 SM(btconf->bt_time_extend, AR_BT_TIME_EXTEND) |
67 SM(btconf->bt_txstate_extend, AR_BT_TXSTATE_EXTEND) |
68 SM(btconf->bt_txframe_extend, AR_BT_TX_FRAME_EXTEND) |
69 SM(btconf->bt_mode, AR_BT_MODE) |
70 SM(btconf->bt_quiet_collision, AR_BT_QUIET) |
71 SM(rxClearPolarity, AR_BT_RX_CLEAR_POLARITY) |
72 SM(btconf->bt_priority_time, AR_BT_PRIORITY_TIME) |
73 SM(btconf->bt_first_slot_time, AR_BT_FIRST_SLOT_TIME);
75 ahp->ah_btCoexMode2 |= SM(btconf->bt_hold_rxclear,
78 if (ahp->ah_btCoexSingleAnt == AH_FALSE) {
79 /* Enable ACK to go out even though BT has higher priority. */
80 ahp->ah_btCoexMode2 |= AR_BT_DISABLE_BT_ANT;
85 ar5416BTCoexSetQcuThresh(struct ath_hal *ah, int qnum)
87 struct ath_hal_5416 *ahp = AH5416(ah);
89 ahp->ah_btCoexMode |= SM(qnum, AR_BT_QCU_THRESH);
93 ar5416BTCoexSetWeights(struct ath_hal *ah, u_int32_t stompType)
95 struct ath_hal_5416 *ahp = AH5416(ah);
97 if (AR_SREV_KIWI_10_OR_LATER(ah)) {
98 /* TODO: TX RX seperate is not enabled. */
100 case HAL_BT_COEX_STOMP_ALL:
101 ahp->ah_btCoexBTWeight = AR5416_BT_WGHT;
102 ahp->ah_btCoexWLANWeight = AR5416_STOMP_ALL_WLAN_WGHT;
104 case HAL_BT_COEX_STOMP_LOW:
105 ahp->ah_btCoexBTWeight = AR5416_BT_WGHT;
106 ahp->ah_btCoexWLANWeight = AR5416_STOMP_LOW_WLAN_WGHT;
108 case HAL_BT_COEX_STOMP_ALL_FORCE:
109 ahp->ah_btCoexBTWeight = AR5416_BT_WGHT;
110 ahp->ah_btCoexWLANWeight =
111 AR5416_STOMP_ALL_FORCE_WLAN_WGHT;
113 case HAL_BT_COEX_STOMP_LOW_FORCE:
114 ahp->ah_btCoexBTWeight = AR5416_BT_WGHT;
115 ahp->ah_btCoexWLANWeight =
116 AR5416_STOMP_LOW_FORCE_WLAN_WGHT;
118 case HAL_BT_COEX_STOMP_NONE:
119 case HAL_BT_COEX_NO_STOMP:
120 ahp->ah_btCoexBTWeight = AR5416_BT_WGHT;
121 ahp->ah_btCoexWLANWeight = AR5416_STOMP_NONE_WLAN_WGHT;
124 /* There is a forceWeight from registry */
125 ahp->ah_btCoexBTWeight = stompType & 0xffff;
126 ahp->ah_btCoexWLANWeight = stompType >> 16;
131 case HAL_BT_COEX_STOMP_ALL:
132 ahp->ah_btCoexBTWeight = AR5416_BT_WGHT;
133 ahp->ah_btCoexWLANWeight = AR5416_STOMP_ALL_WLAN_WGHT;
135 case HAL_BT_COEX_STOMP_LOW:
136 ahp->ah_btCoexBTWeight = AR5416_BT_WGHT;
137 ahp->ah_btCoexWLANWeight = AR5416_STOMP_LOW_WLAN_WGHT;
139 case HAL_BT_COEX_STOMP_ALL_FORCE:
140 ahp->ah_btCoexBTWeight = AR5416_BT_WGHT;
141 ahp->ah_btCoexWLANWeight =
142 AR5416_STOMP_ALL_FORCE_WLAN_WGHT;
144 case HAL_BT_COEX_STOMP_LOW_FORCE:
145 ahp->ah_btCoexBTWeight = AR5416_BT_WGHT;
146 ahp->ah_btCoexWLANWeight =
147 AR5416_STOMP_LOW_FORCE_WLAN_WGHT;
149 case HAL_BT_COEX_STOMP_NONE:
150 case HAL_BT_COEX_NO_STOMP:
151 ahp->ah_btCoexBTWeight = AR5416_BT_WGHT;
152 ahp->ah_btCoexWLANWeight = AR5416_STOMP_NONE_WLAN_WGHT;
155 /* There is a forceWeight from registry */
156 ahp->ah_btCoexBTWeight = stompType & 0xffff;
157 ahp->ah_btCoexWLANWeight = stompType >> 16;
164 ar5416BTCoexSetupBmissThresh(struct ath_hal *ah, u_int32_t thresh)
166 struct ath_hal_5416 *ahp = AH5416(ah);
168 ahp->ah_btCoexMode2 |= SM(thresh, AR_BT_BCN_MISS_THRESH);
172 * There is no antenna diversity for Owl, Kiwi, etc.
174 * Kite will override this particular method.
177 ar5416BTCoexAntennaDiversity(struct ath_hal *ah)
182 ar5416BTCoexSetParameter(struct ath_hal *ah, u_int32_t type, u_int32_t value)
184 struct ath_hal_5416 *ahp = AH5416(ah);
187 case HAL_BT_COEX_SET_ACK_PWR:
189 ahp->ah_btCoexFlag |= HAL_BT_COEX_FLAG_LOW_ACK_PWR;
190 OS_REG_WRITE(ah, AR_TPC, HAL_BT_COEX_LOW_ACK_POWER);
192 ahp->ah_btCoexFlag &= ~HAL_BT_COEX_FLAG_LOW_ACK_PWR;
193 OS_REG_WRITE(ah, AR_TPC, HAL_BT_COEX_HIGH_ACK_POWER);
196 case HAL_BT_COEX_ANTENNA_DIVERSITY:
197 /* This is overridden for Kite */
200 case HAL_BT_COEX_LOWER_TX_PWR:
202 if ((ahp->ah_btCoexFlag & HAL_BT_COEX_FLAG_LOWER_TX_PWR) == 0) {
203 ahp->ah_btCoexFlag |= HAL_BT_COEX_FLAG_LOWER_TX_PWR;
204 AH_PRIVATE(ah)->ah_config.ath_hal_desc_tpc = 1;
205 ar5416SetTxPowerLimit(ah, AH_PRIVATE(ah)->ah_power_limit, AH_PRIVATE(ah)->ah_extra_txpow, 0);
209 if (ahp->ah_btCoexFlag & HAL_BT_COEX_FLAG_LOWER_TX_PWR) {
210 ahp->ah_btCoexFlag &= ~HAL_BT_COEX_FLAG_LOWER_TX_PWR;
211 AH_PRIVATE(ah)->ah_config.ath_hal_desc_tpc = 0;
212 ar5416SetTxPowerLimit(ah, AH_PRIVATE(ah)->ah_power_limit, AH_PRIVATE(ah)->ah_extra_txpow, 0);
223 ar5416BTCoexDisable(struct ath_hal *ah)
225 struct ath_hal_5416 *ahp = AH5416(ah);
227 /* Always drive rx_clear_external output as 0 */
228 ar5416GpioSet(ah, ahp->ah_wlanActiveGpioSelect, 0);
229 ar5416GpioCfgOutput(ah, ahp->ah_wlanActiveGpioSelect,
230 HAL_GPIO_OUTPUT_MUX_AS_OUTPUT);
232 if (AR_SREV_9271(ah)) {
234 * Set wlanActiveGpio to input when disabling BT-COEX to
235 * reduce power consumption
237 ar5416GpioCfgInput(ah, ahp->ah_wlanActiveGpioSelect);
240 if (ahp->ah_btCoexSingleAnt == AH_TRUE) {
241 OS_REG_RMW_FIELD(ah, AR_QUIET1, AR_QUIET1_QUIET_ACK_CTS_ENABLE,
243 OS_REG_RMW_FIELD(ah, AR_MISC_MODE, AR_PCU_BT_ANT_PREVENT_RX,
247 OS_REG_WRITE(ah, AR_BT_COEX_MODE, AR_BT_QUIET | AR_BT_MODE);
248 OS_REG_WRITE(ah, AR_BT_COEX_WEIGHT, 0);
249 if (AR_SREV_KIWI_10_OR_LATER(ah))
250 OS_REG_WRITE(ah, AR_BT_COEX_WEIGHT2, 0);
251 OS_REG_WRITE(ah, AR_BT_COEX_MODE2, 0);
253 ahp->ah_btCoexEnabled = AH_FALSE;
257 ar5416BTCoexEnable(struct ath_hal *ah)
259 struct ath_hal_5416 *ahp = AH5416(ah);
261 /* Program coex mode and weight registers to actually enable coex */
262 OS_REG_WRITE(ah, AR_BT_COEX_MODE, ahp->ah_btCoexMode);
263 OS_REG_WRITE(ah, AR_BT_COEX_WEIGHT,
264 SM(ahp->ah_btCoexWLANWeight & 0xFFFF, AR_BT_WL_WGHT) |
265 SM(ahp->ah_btCoexBTWeight & 0xFFFF, AR_BT_BT_WGHT));
266 if (AR_SREV_KIWI_10_OR_LATER(ah)) {
267 OS_REG_WRITE(ah, AR_BT_COEX_WEIGHT2,
268 SM(ahp->ah_btCoexWLANWeight >> 16, AR_BT_WL_WGHT));
270 OS_REG_WRITE(ah, AR_BT_COEX_MODE2, ahp->ah_btCoexMode2);
272 /* Added Select GPIO5~8 instaed SPI */
273 if (AR_SREV_9271(ah)) {
276 val = OS_REG_READ(ah, AR9271_CLOCK_CONTROL);
278 OS_REG_WRITE(ah, AR9271_CLOCK_CONTROL, val);
281 if (ahp->ah_btCoexFlag & HAL_BT_COEX_FLAG_LOW_ACK_PWR)
282 OS_REG_WRITE(ah, AR_TPC, HAL_BT_COEX_LOW_ACK_POWER);
284 OS_REG_WRITE(ah, AR_TPC, HAL_BT_COEX_HIGH_ACK_POWER);
286 if (ahp->ah_btCoexSingleAnt == AH_TRUE) {
287 OS_REG_RMW_FIELD(ah, AR_QUIET1,
288 AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);
289 /* XXX should update miscMode? */
290 OS_REG_RMW_FIELD(ah, AR_MISC_MODE,
291 AR_PCU_BT_ANT_PREVENT_RX, 1);
293 OS_REG_RMW_FIELD(ah, AR_QUIET1,
294 AR_QUIET1_QUIET_ACK_CTS_ENABLE, 1);
295 /* XXX should update miscMode? */
296 OS_REG_RMW_FIELD(ah, AR_MISC_MODE,
297 AR_PCU_BT_ANT_PREVENT_RX, 0);
300 if (ahp->ah_btCoexConfigType == HAL_BT_COEX_CFG_3WIRE) {
301 /* For 3-wire, configure the desired GPIO port for rx_clear */
302 ar5416GpioCfgOutput(ah, ahp->ah_wlanActiveGpioSelect,
303 HAL_GPIO_OUTPUT_MUX_AS_WLAN_ACTIVE);
306 * For 2-wire, configure the desired GPIO port
307 * for TX_FRAME output
309 ar5416GpioCfgOutput(ah, ahp->ah_wlanActiveGpioSelect,
310 HAL_GPIO_OUTPUT_MUX_AS_TX_FRAME);
314 * Enable a weak pull down on BT_ACTIVE.
315 * When BT device is disabled, BT_ACTIVE might be floating.
317 OS_REG_RMW(ah, AR_GPIO_PDPU,
318 (0x2 << (ahp->ah_btActiveGpioSelect * 2)),
319 (0x3 << (ahp->ah_btActiveGpioSelect * 2)));
321 ahp->ah_btCoexEnabled = AH_TRUE;
327 ar5416InitBTCoex(struct ath_hal *ah)
329 struct ath_hal_5416 *ahp = AH5416(ah);
331 HALDEBUG(ah, HAL_DEBUG_BT_COEX,
332 "%s: called; configType=%d\n",
334 ahp->ah_btCoexConfigType);
336 if (ahp->ah_btCoexConfigType == HAL_BT_COEX_CFG_3WIRE) {
337 OS_REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
338 (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB |
339 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB));
342 * Set input mux for bt_prority_async and
343 * bt_active_async to GPIO pins
345 OS_REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
346 AR_GPIO_INPUT_MUX1_BT_ACTIVE,
347 ahp->ah_btActiveGpioSelect);
348 OS_REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
349 AR_GPIO_INPUT_MUX1_BT_PRIORITY,
350 ahp->ah_btPriorityGpioSelect);
353 * Configure the desired GPIO ports for input
355 ar5416GpioCfgInput(ah, ahp->ah_btActiveGpioSelect);
356 ar5416GpioCfgInput(ah, ahp->ah_btPriorityGpioSelect);
359 * Configure the antenna diversity setup.
360 * It's a no-op for AR9287; AR9285 overrides this
363 AH5416(ah)->ah_btCoexSetDiversity(ah);
365 if (ahp->ah_btCoexEnabled)
366 ar5416BTCoexEnable(ah);
368 ar5416BTCoexDisable(ah);
369 } else if (ahp->ah_btCoexConfigType != HAL_BT_COEX_CFG_NONE) {
371 if (ahp->ah_btCoexEnabled) {
372 /* Connect bt_active_async to baseband */
373 OS_REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
374 (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
375 AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
376 OS_REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
377 AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
380 * Set input mux for bt_prority_async and
381 * bt_active_async to GPIO pins
383 OS_REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
384 AR_GPIO_INPUT_MUX1_BT_ACTIVE,
385 ahp->ah_btActiveGpioSelect);
387 /* Configure the desired GPIO ports for input */
388 ar5416GpioCfgInput(ah, ahp->ah_btActiveGpioSelect);
390 /* Enable coexistence on initialization */
391 ar5416BTCoexEnable(ah);