FreeBSD kernel ATH device code
ar5416_btcoex.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: ISC
3 *
4 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
5 * Copyright (c) 2002-2005 Atheros Communications, Inc.
6 * Copyright (c) 2008-2010, Atheros Communications Inc.
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *
20 * $FreeBSD$
21 */
22
23#include "opt_ah.h"
24
25#include "ah.h"
26#include "ah_internal.h"
27#include "ah_devid.h"
28#ifdef AH_DEBUG
29#include "ah_desc.h" /* NB: for HAL_PHYERR* */
30#endif
31
32#include "ar5416/ar5416.h"
33#include "ar5416/ar5416reg.h"
34#include "ar5416/ar5416phy.h"
35#include "ar5416/ar5416desc.h" /* AR5416_CONTTXMODE */
37
38void
40{
41 struct ath_hal_5416 *ahp = AH5416(ah);
42
43 ahp->ah_btModule = btinfo->bt_module;
49 ahp->ah_btCoexSingleAnt = btinfo->bt_single_ant;
50 ahp->ah_btWlanIsolation = btinfo->bt_isolation;
51}
52
53void
55{
56 struct ath_hal_5416 *ahp = AH5416(ah);
57 HAL_BOOL rxClearPolarity = btconf->bt_rxclear_polarity;
58
59 /*
60 * For Kiwi and Osprey, the polarity of rx_clear is active high.
61 * The bt_rxclear_polarity flag from ath(4) needs to be inverted.
62 */
63 if (AR_SREV_KIWI(ah)) {
64 rxClearPolarity = !btconf->bt_rxclear_polarity;
65 }
66
71 SM(btconf->bt_mode, AR_BT_MODE) |
73 SM(rxClearPolarity, AR_BT_RX_CLEAR_POLARITY) |
76
77 ahp->ah_btCoexMode2 |= SM(btconf->bt_hold_rxclear,
79
80 if (ahp->ah_btCoexSingleAnt == AH_FALSE) {
81 /* Enable ACK to go out even though BT has higher priority. */
83 }
84}
85
86void
87ar5416BTCoexSetQcuThresh(struct ath_hal *ah, int qnum)
88{
89 struct ath_hal_5416 *ahp = AH5416(ah);
90
91 ahp->ah_btCoexMode |= SM(qnum, AR_BT_QCU_THRESH);
92}
93
94void
95ar5416BTCoexSetWeights(struct ath_hal *ah, u_int32_t stompType)
96{
97 struct ath_hal_5416 *ahp = AH5416(ah);
98
100 /* TODO: TX RX separate is not enabled. */
101 switch (stompType) {
103 /* XXX TODO */
107 break;
111 break;
116 break;
121 break;
126 break;
127 default:
128 /* There is a forceWeight from registry */
129 ahp->ah_btCoexBTWeight = stompType & 0xffff;
130 ahp->ah_btCoexWLANWeight = stompType >> 16;
131 break;
132 }
133 } else {
134 switch (stompType) {
136 /* XXX TODO */
140 break;
144 break;
149 break;
154 break;
159 break;
160 default:
161 /* There is a forceWeight from registry */
162 ahp->ah_btCoexBTWeight = stompType & 0xffff;
163 ahp->ah_btCoexWLANWeight = stompType >> 16;
164 break;
165 }
166 }
167}
168
169void
170ar5416BTCoexSetupBmissThresh(struct ath_hal *ah, u_int32_t thresh)
171{
172 struct ath_hal_5416 *ahp = AH5416(ah);
173
174 ahp->ah_btCoexMode2 |= SM(thresh, AR_BT_BCN_MISS_THRESH);
175}
176
177/*
178 * There is no antenna diversity for Owl, Kiwi, etc.
179 *
180 * Kite will override this particular method.
181 */
182void
184{
185}
186
187void
188ar5416BTCoexSetParameter(struct ath_hal *ah, u_int32_t type, u_int32_t value)
189{
190 struct ath_hal_5416 *ahp = AH5416(ah);
191
192 switch (type) {
194 if (value) {
197 } else {
198 ahp->ah_btCoexFlag &= ~HAL_BT_COEX_FLAG_LOW_ACK_PWR;
200 }
201 break;
203 /* This is overridden for Kite */
204 break;
205#if 0
207 if (value) {
210 AH_PRIVATE(ah)->ah_config.ath_hal_desc_tpc = 1;
211 ar5416SetTxPowerLimit(ah, AH_PRIVATE(ah)->ah_power_limit, AH_PRIVATE(ah)->ah_extra_txpow, 0);
212 }
213 }
214 else {
216 ahp->ah_btCoexFlag &= ~HAL_BT_COEX_FLAG_LOWER_TX_PWR;
217 AH_PRIVATE(ah)->ah_config.ath_hal_desc_tpc = 0;
218 ar5416SetTxPowerLimit(ah, AH_PRIVATE(ah)->ah_power_limit, AH_PRIVATE(ah)->ah_extra_txpow, 0);
219 }
220 }
221 break;
222#endif
223 default:
224 break;
225 }
226}
227
228void
230{
231 struct ath_hal_5416 *ahp = AH5416(ah);
232
233 /* Always drive rx_clear_external output as 0 */
237
238 if (AR_SREV_9271(ah)) {
239 /*
240 * Set wlanActiveGpio to input when disabling BT-COEX to
241 * reduce power consumption
242 */
244 }
245
246 if (ahp->ah_btCoexSingleAnt == AH_TRUE) {
248 1);
250 0);
251 }
252
258
260}
261
262int
264{
265 struct ath_hal_5416 *ahp = AH5416(ah);
266
267 /* Program coex mode and weight registers to actually enable coex */
270 SM(ahp->ah_btCoexWLANWeight & 0xFFFF, AR_BT_WL_WGHT) |
271 SM(ahp->ah_btCoexBTWeight & 0xFFFF, AR_BT_BT_WGHT));
272 if (AR_SREV_KIWI_10_OR_LATER(ah)) {
275 }
277
278 /* Added Select GPIO5~8 instaed SPI */
279 if (AR_SREV_9271(ah)) {
280 uint32_t val;
281
283 val &= 0xFFFFFEFF;
285 }
286
289 else
291
292 if (ahp->ah_btCoexSingleAnt == AH_TRUE) {
295 /* XXX should update miscMode? */
298 } else {
301 /* XXX should update miscMode? */
304 }
305
307 /* For 3-wire, configure the desired GPIO port for rx_clear */
310 } else {
311 /*
312 * For 2-wire, configure the desired GPIO port
313 * for TX_FRAME output
314 */
317 }
318
319 /*
320 * Enable a weak pull down on BT_ACTIVE.
321 * When BT device is disabled, BT_ACTIVE might be floating.
322 */
324 (0x2 << (ahp->ah_btActiveGpioSelect * 2)),
325 (0x3 << (ahp->ah_btActiveGpioSelect * 2)));
326
328
329 return (0);
330}
331
332void
334{
335 struct ath_hal_5416 *ahp = AH5416(ah);
336
338 "%s: called; configType=%d\n",
339 __func__,
341
346
347 /*
348 * Set input mux for bt_prority_async and
349 * bt_active_async to GPIO pins
350 */
357
358 /*
359 * Configure the desired GPIO ports for input
360 */
363
364 /*
365 * Configure the antenna diversity setup.
366 * It's a no-op for AR9287; AR9285 overrides this
367 * as required.
368 */
369 AH5416(ah)->ah_btCoexSetDiversity(ah);
370
371 if (ahp->ah_btCoexEnabled)
373 else
375 } else if (ahp->ah_btCoexConfigType != HAL_BT_COEX_CFG_NONE) {
376 /* 2-wire */
377 if (ahp->ah_btCoexEnabled) {
378 /* Connect bt_active_async to baseband */
384
385 /*
386 * Set input mux for bt_prority_async and
387 * bt_active_async to GPIO pins
388 */
392
393 /* Configure the desired GPIO ports for input */
395
396 /* Enable coexistence on initialization */
398 }
399 }
400}
@ HAL_GPIO_OUTPUT_MUX_AS_OUTPUT
Definition: ah.h:583
@ HAL_GPIO_OUTPUT_MUX_AS_TX_FRAME
Definition: ah.h:589
@ HAL_GPIO_OUTPUT_MUX_AS_WLAN_ACTIVE
Definition: ah.h:588
HAL_BOOL
Definition: ah.h:93
@ AH_FALSE
Definition: ah.h:94
@ AH_TRUE
Definition: ah.h:95
#define HAL_BT_COEX_FLAG_LOWER_TX_PWR
Definition: ah_btcoex.h:163
@ HAL_BT_COEX_CFG_3WIRE
Definition: ah_btcoex.h:57
@ HAL_BT_COEX_CFG_NONE
Definition: ah_btcoex.h:53
#define HAL_BT_COEX_LOW_ACK_POWER
Definition: ah_btcoex.h:94
#define HAL_BT_COEX_FLAG_LOW_ACK_PWR
Definition: ah_btcoex.h:162
#define HAL_BT_COEX_HIGH_ACK_POWER
Definition: ah_btcoex.h:95
@ HAL_BT_COEX_ANTENNA_DIVERSITY
Definition: ah_btcoex.h:64
@ HAL_BT_COEX_LOWER_TX_PWR
Definition: ah_btcoex.h:63
@ HAL_BT_COEX_SET_ACK_PWR
Definition: ah_btcoex.h:62
@ HAL_BT_COEX_STOMP_ALL_FORCE
Definition: ah_btcoex.h:102
@ HAL_BT_COEX_STOMP_LOW
Definition: ah_btcoex.h:100
@ HAL_BT_COEX_STOMP_AUDIO
Definition: ah_btcoex.h:104
@ HAL_BT_COEX_STOMP_LOW_FORCE
Definition: ah_btcoex.h:103
@ HAL_BT_COEX_NO_STOMP
Definition: ah_btcoex.h:98
@ HAL_BT_COEX_STOMP_NONE
Definition: ah_btcoex.h:101
@ HAL_BT_COEX_STOMP_ALL
Definition: ah_btcoex.h:99
@ HAL_DEBUG_BT_COEX
Definition: ah_debug.h:58
#define OS_REG_SET_BIT(_a, _r, _f)
Definition: ah_internal.h:594
#define SM(_v, _f)
Definition: ah_internal.h:587
#define OS_REG_CLR_BIT(_a, _r, _f)
Definition: ah_internal.h:596
#define AH_PRIVATE(_ah)
Definition: ah_internal.h:442
#define OS_REG_RMW(_a, _r, _set, _clr)
Definition: ah_internal.h:589
#define OS_REG_RMW_FIELD(_a, _r, _f, _v)
Definition: ah_internal.h:591
#define HALDEBUG(_ah, __m,...)
Definition: ah_internal.h:658
#define OS_REG_WRITE(_ah, _reg, _val)
Definition: ah_osdep.h:139
#define OS_REG_READ(_ah, _reg)
Definition: ah_osdep.h:140
#define AR_QUIET1
Definition: ar5212reg.h:302
#define AR_TPC
Definition: ar5212reg.h:296
#define AR_MISC_MODE
Definition: ar5212reg.h:321
#define AR_QUIET1_QUIET_ACK_CTS_ENABLE
Definition: ar5212reg.h:306
#define AH5416(_ah)
Definition: ar5416.h:162
HAL_BOOL ar5416GpioCfgOutput(struct ath_hal *, uint32_t gpio, HAL_GPIO_MUX_TYPE)
Definition: ar5416_gpio.c:86
HAL_BOOL ar5416GpioSet(struct ath_hal *, uint32_t gpio, uint32_t val)
Definition: ar5416_gpio.c:163
HAL_BOOL ar5416GpioCfgInput(struct ath_hal *, uint32_t gpio)
Definition: ar5416_gpio.c:139
HAL_BOOL ar5416SetTxPowerLimit(struct ath_hal *ah, uint32_t limit)
Definition: ar5416_reset.c:915
void ar5416SetBTCoexInfo(struct ath_hal *ah, HAL_BT_COEX_INFO *btinfo)
Definition: ar5416_btcoex.c:39
void ar5416BTCoexConfig(struct ath_hal *ah, HAL_BT_COEX_CONFIG *btconf)
Definition: ar5416_btcoex.c:54
void ar5416BTCoexSetQcuThresh(struct ath_hal *ah, int qnum)
Definition: ar5416_btcoex.c:87
void ar5416BTCoexSetParameter(struct ath_hal *ah, u_int32_t type, u_int32_t value)
int ar5416BTCoexEnable(struct ath_hal *ah)
void ar5416BTCoexAntennaDiversity(struct ath_hal *ah)
void ar5416BTCoexDisable(struct ath_hal *ah)
void ar5416BTCoexSetupBmissThresh(struct ath_hal *ah, u_int32_t thresh)
void ar5416BTCoexSetWeights(struct ath_hal *ah, u_int32_t stompType)
Definition: ar5416_btcoex.c:95
void ar5416InitBTCoex(struct ath_hal *ah)
#define AR5416_STOMP_LOW_WLAN_WGHT
Definition: ar5416_btcoex.h:28
#define AR5416_BT_WGHT
Definition: ar5416_btcoex.h:26
#define AR5416_STOMP_LOW_FORCE_WLAN_WGHT
Definition: ar5416_btcoex.h:31
#define AR5416_STOMP_ALL_WLAN_WGHT
Definition: ar5416_btcoex.h:27
#define AR5416_STOMP_NONE_WLAN_WGHT
Definition: ar5416_btcoex.h:29
#define AR5416_STOMP_ALL_FORCE_WLAN_WGHT
Definition: ar5416_btcoex.h:30
#define AR_BT_WL_WGHT
Definition: ar5416phy.h:49
#define AR_BT_QCU_THRESH
Definition: ar5416phy.h:37
#define AR_BT_BCN_MISS_THRESH
Definition: ar5416phy.h:53
#define AR_BT_HOLD_RX_CLEAR
Definition: ar5416phy.h:57
#define AR_BT_COEX_MODE
Definition: ar5416phy.h:26
#define AR_BT_RX_CLEAR_POLARITY
Definition: ar5416phy.h:39
#define AR_BT_FIRST_SLOT_TIME
Definition: ar5416phy.h:43
#define AR_BT_QUIET
Definition: ar5416phy.h:35
#define AR_BT_PRIORITY_TIME
Definition: ar5416phy.h:41
#define AR_BT_COEX_WEIGHT
Definition: ar5416phy.h:46
#define AR_BT_TX_FRAME_EXTEND
Definition: ar5416phy.h:31
#define AR_BT_MODE
Definition: ar5416phy.h:33
#define AR_BT_COEX_MODE2
Definition: ar5416phy.h:52
#define AR_BT_TXSTATE_EXTEND
Definition: ar5416phy.h:29
#define AR_BT_BT_WGHT
Definition: ar5416phy.h:47
#define AR_BT_DISABLE_BT_ANT
Definition: ar5416phy.h:59
#define AR_BT_TIME_EXTEND
Definition: ar5416phy.h:27
#define AR_SREV_KIWI_10_OR_LATER(_ah)
Definition: ar5416reg.h:785
#define AR_SREV_KIWI(_ah)
Definition: ar5416reg.h:782
#define AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_BB
Definition: ar5416reg.h:62
#define AR_GPIO_INPUT_MUX1
Definition: ar5416reg.h:73
#define AR_GPIO_INPUT_EN_VAL
Definition: ar5416reg.h:53
#define AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF
Definition: ar5416reg.h:56
#define AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF
Definition: ar5416reg.h:54
#define AR_BT_COEX_WEIGHT2
Definition: ar5416reg.h:150
#define AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB
Definition: ar5416reg.h:66
#define AR_SREV_9271(_ah)
Definition: ar5416reg.h:810
#define AR_GPIO_PDPU
Definition: ar5416reg.h:103
#define AR9271_CLOCK_CONTROL
Definition: ar5416reg.h:609
#define AR_PCU_BT_ANT_PREVENT_RX
Definition: ar5416reg.h:521
#define AR_GPIO_INPUT_MUX1_BT_ACTIVE
Definition: ar5416reg.h:78
#define AR_GPIO_INPUT_MUX1_BT_PRIORITY
Definition: ar5416reg.h:74
HAL_BOOL bt_rxclear_polarity
Definition: ah_btcoex.h:137
u_int8_t bt_priority_time
Definition: ah_btcoex.h:144
u_int8_t bt_time_extend
Definition: ah_btcoex.h:109
HAL_BOOL bt_quiet_collision
Definition: ah_btcoex.h:132
u_int8_t bt_first_slot_time
Definition: ah_btcoex.h:152
HAL_BT_COEX_MODE bt_mode
Definition: ah_btcoex.h:126
HAL_BOOL bt_hold_rxclear
Definition: ah_btcoex.h:159
HAL_BOOL bt_txframe_extend
Definition: ah_btcoex.h:121
HAL_BOOL bt_txstate_extend
Definition: ah_btcoex.h:115
u_int8_t bt_coex_config
Definition: ah_btcoex.h:36
u_int8_t bt_gpio_bt_priority
Definition: ah_btcoex.h:38
HAL_BT_MODULE bt_module
Definition: ah_btcoex.h:35
u_int8_t bt_active_polarity
Definition: ah_btcoex.h:40
HAL_BOOL bt_single_ant
Definition: ah_btcoex.h:41
u_int8_t bt_gpio_bt_active
Definition: ah_btcoex.h:37
u_int8_t bt_gpio_wlan_active
Definition: ah_btcoex.h:39
u_int8_t bt_isolation
Definition: ah_btcoex.h:42
HAL_BOOL ah_btCoexEnabled
Definition: ar5416.h:155
uint8_t ah_btCoexConfigType
Definition: ar5416.h:144
uint32_t ah_btCoexMode2
Definition: ar5416.h:159
HAL_BOOL ah_btCoexSingleAnt
Definition: ar5416.h:149
uint32_t ah_btCoexFlag
Definition: ar5416.h:160
uint32_t ah_btCoexWLANWeight
Definition: ar5416.h:158
uint8_t ah_btActivePolarity
Definition: ar5416.h:148
uint8_t ah_btPriorityGpioSelect
Definition: ar5416.h:146
uint8_t ah_btActiveGpioSelect
Definition: ar5416.h:145
uint32_t ah_btCoexBTWeight
Definition: ar5416.h:157
uint32_t ah_btCoexMode
Definition: ar5416.h:156
uint8_t ah_wlanActiveGpioSelect
Definition: ar5416.h:147
HAL_BT_MODULE ah_btModule
Definition: ar5416.h:143
uint8_t ah_btWlanIsolation
Definition: ar5416.h:150
Definition: ah.h:1219