1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2012 Realtek Corporation.*/
4 /***************************************************************
7 * This file is for RTL8723B Co-exist mechanism
10 * 2012/11/15 Cosa first check in.
12 ***************************************************************/
14 /***************************************************************
16 ***************************************************************/
17 #include "halbt_precomp.h"
18 /***************************************************************
19 * Global variables, these are static variables
20 ***************************************************************/
21 static struct coex_dm_8723b_1ant glcoex_dm_8723b_1ant
;
22 static struct coex_dm_8723b_1ant
*coex_dm
= &glcoex_dm_8723b_1ant
;
23 static struct coex_sta_8723b_1ant glcoex_sta_8723b_1ant
;
24 static struct coex_sta_8723b_1ant
*coex_sta
= &glcoex_sta_8723b_1ant
;
26 static const char *const glbt_info_src_8723b_1ant
[] = {
29 "BT Info[bt auto report]",
32 static u32 glcoex_ver_date_8723b_1ant
= 20130918;
33 static u32 glcoex_ver_8723b_1ant
= 0x47;
35 /***************************************************************
36 * local function proto type if needed
37 ***************************************************************/
38 /***************************************************************
39 * local function start with halbtc8723b1ant_
40 ***************************************************************/
42 static void halbtc8723b1ant_updatera_mask(struct btc_coexist
*btcoexist
,
43 bool force_exec
, u32 dis_rate_mask
)
45 coex_dm
->curra_mask
= dis_rate_mask
;
47 if (force_exec
|| (coex_dm
->prera_mask
!= coex_dm
->curra_mask
))
48 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_UPDATE_RAMASK
,
49 &coex_dm
->curra_mask
);
51 coex_dm
->prera_mask
= coex_dm
->curra_mask
;
54 static void btc8723b1ant_auto_rate_fb_retry(struct btc_coexist
*btcoexist
,
55 bool force_exec
, u8 type
)
57 bool wifi_under_bmode
= false;
59 coex_dm
->cur_arfr_type
= type
;
61 if (force_exec
|| (coex_dm
->pre_arfr_type
!= coex_dm
->cur_arfr_type
)) {
62 switch (coex_dm
->cur_arfr_type
) {
63 case 0: /* normal mode */
64 btcoexist
->btc_write_4byte(btcoexist
, 0x430,
65 coex_dm
->backup_arfr_cnt1
);
66 btcoexist
->btc_write_4byte(btcoexist
, 0x434,
67 coex_dm
->backup_arfr_cnt2
);
70 btcoexist
->btc_get(btcoexist
,
71 BTC_GET_BL_WIFI_UNDER_B_MODE
,
73 if (wifi_under_bmode
) {
74 btcoexist
->btc_write_4byte(btcoexist
,
76 btcoexist
->btc_write_4byte(btcoexist
,
79 btcoexist
->btc_write_4byte(btcoexist
,
81 btcoexist
->btc_write_4byte(btcoexist
,
90 coex_dm
->pre_arfr_type
= coex_dm
->cur_arfr_type
;
93 static void halbtc8723b1ant_retry_limit(struct btc_coexist
*btcoexist
,
94 bool force_exec
, u8 type
)
96 coex_dm
->cur_retry_limit_type
= type
;
98 if (force_exec
|| (coex_dm
->pre_retry_limit_type
!=
99 coex_dm
->cur_retry_limit_type
)) {
100 switch (coex_dm
->cur_retry_limit_type
) {
101 case 0: /* normal mode */
102 btcoexist
->btc_write_2byte(btcoexist
, 0x42a,
103 coex_dm
->backup_retry_limit
);
105 case 1: /* retry limit = 8 */
106 btcoexist
->btc_write_2byte(btcoexist
, 0x42a, 0x0808);
113 coex_dm
->pre_retry_limit_type
= coex_dm
->cur_retry_limit_type
;
116 static void halbtc8723b1ant_ampdu_maxtime(struct btc_coexist
*btcoexist
,
117 bool force_exec
, u8 type
)
119 coex_dm
->cur_ampdu_time_type
= type
;
121 if (force_exec
|| (coex_dm
->pre_ampdu_time_type
!=
122 coex_dm
->cur_ampdu_time_type
)) {
123 switch (coex_dm
->cur_ampdu_time_type
) {
124 case 0: /* normal mode */
125 btcoexist
->btc_write_1byte(btcoexist
, 0x456,
126 coex_dm
->backup_ampdu_max_time
);
128 case 1: /* AMPDU timw = 0x38 * 32us */
129 btcoexist
->btc_write_1byte(btcoexist
, 0x456, 0x38);
136 coex_dm
->pre_ampdu_time_type
= coex_dm
->cur_ampdu_time_type
;
139 static void halbtc8723b1ant_limited_tx(struct btc_coexist
*btcoexist
,
140 bool force_exec
, u8 ra_masktype
,
141 u8 arfr_type
, u8 retry_limit_type
,
144 switch (ra_masktype
) {
145 case 0: /* normal mode */
146 halbtc8723b1ant_updatera_mask(btcoexist
, force_exec
, 0x0);
148 case 1: /* disable cck 1/2 */
149 halbtc8723b1ant_updatera_mask(btcoexist
, force_exec
,
152 /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
154 halbtc8723b1ant_updatera_mask(btcoexist
, force_exec
,
161 btc8723b1ant_auto_rate_fb_retry(btcoexist
, force_exec
, arfr_type
);
162 halbtc8723b1ant_retry_limit(btcoexist
, force_exec
, retry_limit_type
);
163 halbtc8723b1ant_ampdu_maxtime(btcoexist
, force_exec
, ampdu_time_type
);
166 static void halbtc8723b1ant_limited_rx(struct btc_coexist
*btcoexist
,
167 bool force_exec
, bool rej_ap_agg_pkt
,
168 bool bt_ctrl_agg_buf_size
,
171 bool reject_rx_agg
= rej_ap_agg_pkt
;
172 bool bt_ctrl_rx_agg_size
= bt_ctrl_agg_buf_size
;
173 u8 rxaggsize
= agg_buf_size
;
175 /**********************************************
176 * Rx Aggregation related setting
177 **********************************************/
178 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_TO_REJ_AP_AGG_PKT
,
180 /* decide BT control aggregation buf size or not */
181 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_CTRL_AGG_SIZE
,
182 &bt_ctrl_rx_agg_size
);
183 /* aggregation buf size, only work
184 * when BT control Rx aggregation size.
186 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_AGG_BUF_SIZE
, &rxaggsize
);
187 /* real update aggregation setting */
188 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_AGGREGATE_CTRL
, NULL
);
191 static void halbtc8723b1ant_query_bt_info(struct btc_coexist
*btcoexist
)
193 u8 h2c_parameter
[1] = {0};
195 coex_sta
->c2h_bt_info_req_sent
= true;
198 h2c_parameter
[0] |= BIT(0);
200 btcoexist
->btc_fill_h2c(btcoexist
, 0x61, 1, h2c_parameter
);
203 static void halbtc8723b1ant_monitor_bt_ctr(struct btc_coexist
*btcoexist
)
205 u32 reg_hp_txrx
, reg_lp_txrx
, u32tmp
;
206 u32 reg_hp_tx
= 0, reg_hp_rx
= 0;
207 u32 reg_lp_tx
= 0, reg_lp_rx
= 0;
208 static u32 num_of_bt_counter_chk
;
213 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_hp_txrx
);
214 reg_hp_tx
= u32tmp
& MASKLWORD
;
215 reg_hp_rx
= (u32tmp
& MASKHWORD
) >> 16;
217 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_lp_txrx
);
218 reg_lp_tx
= u32tmp
& MASKLWORD
;
219 reg_lp_rx
= (u32tmp
& MASKHWORD
) >> 16;
221 coex_sta
->high_priority_tx
= reg_hp_tx
;
222 coex_sta
->high_priority_rx
= reg_hp_rx
;
223 coex_sta
->low_priority_tx
= reg_lp_tx
;
224 coex_sta
->low_priority_rx
= reg_lp_rx
;
226 if ((coex_sta
->low_priority_tx
> 1050) &&
227 (!coex_sta
->c2h_bt_inquiry_page
))
228 coex_sta
->pop_event_cnt
++;
231 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
233 /* This part is for wifi FW and driver to update BT's status as
236 * The flow is as the following
238 * 2. if all BT Tx/Rx counter = 0, after 6 sec we query bt info
239 * 3. Because BT will not rsp from mailbox, so wifi fw will know BT is
242 * 4. FW will rsp c2h for BT that driver will know BT is disabled.
244 if ((reg_hp_tx
== 0) && (reg_hp_rx
== 0) && (reg_lp_tx
== 0) &&
246 num_of_bt_counter_chk
++;
247 if (num_of_bt_counter_chk
== 3)
248 halbtc8723b1ant_query_bt_info(btcoexist
);
250 num_of_bt_counter_chk
= 0;
254 static void halbtc8723b1ant_monitor_wifi_ctr(struct btc_coexist
*btcoexist
)
257 bool wifi_busy
= false, wifi_under_b_mode
= false;
258 static u8 cck_lock_counter
;
261 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
262 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
263 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_B_MODE
,
266 if (coex_sta
->under_ips
) {
267 coex_sta
->crc_ok_cck
= 0;
268 coex_sta
->crc_ok_11g
= 0;
269 coex_sta
->crc_ok_11n
= 0;
270 coex_sta
->crc_ok_11n_agg
= 0;
272 coex_sta
->crc_err_cck
= 0;
273 coex_sta
->crc_err_11g
= 0;
274 coex_sta
->crc_err_11n
= 0;
275 coex_sta
->crc_err_11n_agg
= 0;
277 coex_sta
->crc_ok_cck
=
278 btcoexist
->btc_read_4byte(btcoexist
, 0xf88);
279 coex_sta
->crc_ok_11g
=
280 btcoexist
->btc_read_2byte(btcoexist
, 0xf94);
281 coex_sta
->crc_ok_11n
=
282 btcoexist
->btc_read_2byte(btcoexist
, 0xf90);
283 coex_sta
->crc_ok_11n_agg
=
284 btcoexist
->btc_read_2byte(btcoexist
, 0xfb8);
286 coex_sta
->crc_err_cck
=
287 btcoexist
->btc_read_4byte(btcoexist
, 0xf84);
288 coex_sta
->crc_err_11g
=
289 btcoexist
->btc_read_2byte(btcoexist
, 0xf96);
290 coex_sta
->crc_err_11n
=
291 btcoexist
->btc_read_2byte(btcoexist
, 0xf92);
292 coex_sta
->crc_err_11n_agg
=
293 btcoexist
->btc_read_2byte(btcoexist
, 0xfba);
297 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xf16, 0x1, 0x1);
298 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xf16, 0x1, 0x0);
300 if ((wifi_busy
) && (wifi_rssi
>= 30) && (!wifi_under_b_mode
)) {
301 total_cnt
= coex_sta
->crc_ok_cck
+ coex_sta
->crc_ok_11g
+
302 coex_sta
->crc_ok_11n
+ coex_sta
->crc_ok_11n_agg
;
304 if ((coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
) ||
305 (coex_dm
->bt_status
==
306 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
) ||
307 (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_SCO_BUSY
)) {
308 if (coex_sta
->crc_ok_cck
>
309 (total_cnt
- coex_sta
->crc_ok_cck
)) {
310 if (cck_lock_counter
< 3)
313 if (cck_lock_counter
> 0)
318 if (cck_lock_counter
> 0)
322 if (cck_lock_counter
> 0)
326 if (!coex_sta
->pre_ccklock
) {
327 if (cck_lock_counter
>= 3)
328 coex_sta
->cck_lock
= true;
330 coex_sta
->cck_lock
= false;
332 if (cck_lock_counter
== 0)
333 coex_sta
->cck_lock
= false;
335 coex_sta
->cck_lock
= true;
338 if (coex_sta
->cck_lock
)
339 coex_sta
->cck_ever_lock
= true;
341 coex_sta
->pre_ccklock
= coex_sta
->cck_lock
;
344 static bool btc8723b1ant_is_wifi_status_changed(struct btc_coexist
*btcoexist
)
346 static bool pre_wifi_busy
;
347 static bool pre_under_4way
, pre_bt_hs_on
;
348 bool wifi_busy
= false, under_4way
= false, bt_hs_on
= false;
349 bool wifi_connected
= false;
351 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
353 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
354 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
355 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
358 if (wifi_connected
) {
359 if (wifi_busy
!= pre_wifi_busy
) {
360 pre_wifi_busy
= wifi_busy
;
363 if (under_4way
!= pre_under_4way
) {
364 pre_under_4way
= under_4way
;
367 if (bt_hs_on
!= pre_bt_hs_on
) {
368 pre_bt_hs_on
= bt_hs_on
;
376 static void halbtc8723b1ant_update_bt_link_info(struct btc_coexist
*btcoexist
)
378 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
379 bool bt_hs_on
= false;
381 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
383 bt_link_info
->bt_link_exist
= coex_sta
->bt_link_exist
;
384 bt_link_info
->sco_exist
= coex_sta
->sco_exist
;
385 bt_link_info
->a2dp_exist
= coex_sta
->a2dp_exist
;
386 bt_link_info
->pan_exist
= coex_sta
->pan_exist
;
387 bt_link_info
->hid_exist
= coex_sta
->hid_exist
;
388 bt_link_info
->bt_hi_pri_link_exist
= coex_sta
->bt_hi_pri_link_exist
;
390 /* work around for HS mode. */
392 bt_link_info
->pan_exist
= true;
393 bt_link_info
->bt_link_exist
= true;
396 /* check if Sco only */
397 if (bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
398 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
399 bt_link_info
->sco_only
= true;
401 bt_link_info
->sco_only
= false;
403 /* check if A2dp only */
404 if (!bt_link_info
->sco_exist
&& bt_link_info
->a2dp_exist
&&
405 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
406 bt_link_info
->a2dp_only
= true;
408 bt_link_info
->a2dp_only
= false;
410 /* check if Pan only */
411 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
412 bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
413 bt_link_info
->pan_only
= true;
415 bt_link_info
->pan_only
= false;
417 /* check if Hid only */
418 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
419 !bt_link_info
->pan_exist
&& bt_link_info
->hid_exist
)
420 bt_link_info
->hid_only
= true;
422 bt_link_info
->hid_only
= false;
425 static void halbtc8723b1ant_set_bt_auto_report(struct btc_coexist
*btcoexist
,
426 bool enable_auto_report
)
428 u8 h2c_parameter
[1] = {0};
430 h2c_parameter
[0] = 0;
432 if (enable_auto_report
)
433 h2c_parameter
[0] |= BIT(0);
435 btcoexist
->btc_fill_h2c(btcoexist
, 0x68, 1, h2c_parameter
);
438 static void halbtc8723b1ant_bt_auto_report(struct btc_coexist
*btcoexist
,
440 bool enable_auto_report
)
442 coex_dm
->cur_bt_auto_report
= enable_auto_report
;
445 if (coex_dm
->pre_bt_auto_report
== coex_dm
->cur_bt_auto_report
)
448 halbtc8723b1ant_set_bt_auto_report(btcoexist
,
449 coex_dm
->cur_bt_auto_report
);
451 coex_dm
->pre_bt_auto_report
= coex_dm
->cur_bt_auto_report
;
454 static void btc8723b1ant_set_sw_pen_tx_rate_adapt(struct btc_coexist
*btcoexist
,
457 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
458 u8 h2c_parameter
[6] = {0};
460 h2c_parameter
[0] = 0x6; /* opCode, 0x6= Retry_Penalty */
462 if (low_penalty_ra
) {
463 h2c_parameter
[1] |= BIT0
;
464 /* normal rate except MCS7/6/5, OFDM54/48/36 */
465 h2c_parameter
[2] = 0x00;
466 h2c_parameter
[3] = 0xf7; /* MCS7 or OFDM54 */
467 h2c_parameter
[4] = 0xf8; /* MCS6 or OFDM48 */
468 h2c_parameter
[5] = 0xf9; /* MCS5 or OFDM36 */
471 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
472 "[BTCoex], set WiFi Low-Penalty Retry: %s",
473 (low_penalty_ra
? "ON!!" : "OFF!!"));
475 btcoexist
->btc_fill_h2c(btcoexist
, 0x69, 6, h2c_parameter
);
478 static void halbtc8723b1ant_low_penalty_ra(struct btc_coexist
*btcoexist
,
479 bool force_exec
, bool low_penalty_ra
)
481 coex_dm
->cur_low_penalty_ra
= low_penalty_ra
;
484 if (coex_dm
->pre_low_penalty_ra
== coex_dm
->cur_low_penalty_ra
)
487 btc8723b1ant_set_sw_pen_tx_rate_adapt(btcoexist
,
488 coex_dm
->cur_low_penalty_ra
);
490 coex_dm
->pre_low_penalty_ra
= coex_dm
->cur_low_penalty_ra
;
493 static void halbtc8723b1ant_set_coex_table(struct btc_coexist
*btcoexist
,
494 u32 val0x6c0
, u32 val0x6c4
,
495 u32 val0x6c8
, u8 val0x6cc
)
497 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
499 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
500 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0
);
501 btcoexist
->btc_write_4byte(btcoexist
, 0x6c0, val0x6c0
);
503 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
504 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4
);
505 btcoexist
->btc_write_4byte(btcoexist
, 0x6c4, val0x6c4
);
507 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
508 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8
);
509 btcoexist
->btc_write_4byte(btcoexist
, 0x6c8, val0x6c8
);
511 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
512 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc
);
513 btcoexist
->btc_write_1byte(btcoexist
, 0x6cc, val0x6cc
);
516 static void halbtc8723b1ant_coex_table(struct btc_coexist
*btcoexist
,
517 bool force_exec
, u32 val0x6c0
,
518 u32 val0x6c4
, u32 val0x6c8
,
521 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
523 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
524 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6cc = 0x%x\n",
525 (force_exec
? "force to" : ""),
526 val0x6c0
, val0x6c4
, val0x6cc
);
527 coex_dm
->cur_val0x6c0
= val0x6c0
;
528 coex_dm
->cur_val0x6c4
= val0x6c4
;
529 coex_dm
->cur_val0x6c8
= val0x6c8
;
530 coex_dm
->cur_val0x6cc
= val0x6cc
;
533 if ((coex_dm
->pre_val0x6c0
== coex_dm
->cur_val0x6c0
) &&
534 (coex_dm
->pre_val0x6c4
== coex_dm
->cur_val0x6c4
) &&
535 (coex_dm
->pre_val0x6c8
== coex_dm
->cur_val0x6c8
) &&
536 (coex_dm
->pre_val0x6cc
== coex_dm
->cur_val0x6cc
))
539 halbtc8723b1ant_set_coex_table(btcoexist
, val0x6c0
, val0x6c4
,
542 coex_dm
->pre_val0x6c0
= coex_dm
->cur_val0x6c0
;
543 coex_dm
->pre_val0x6c4
= coex_dm
->cur_val0x6c4
;
544 coex_dm
->pre_val0x6c8
= coex_dm
->cur_val0x6c8
;
545 coex_dm
->pre_val0x6cc
= coex_dm
->cur_val0x6cc
;
548 static void halbtc8723b1ant_coex_table_with_type(struct btc_coexist
*btcoexist
,
549 bool force_exec
, u8 type
)
551 coex_sta
->coex_table_type
= type
;
555 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
556 0x55555555, 0xffffff, 0x3);
559 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
560 0x5a5a5a5a, 0xffffff, 0x3);
563 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x5a5a5a5a,
564 0x5a5a5a5a, 0xffffff, 0x3);
567 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
568 0x5a5a5a5a, 0xffffff, 0x3);
571 if ((coex_sta
->cck_ever_lock
) && (coex_sta
->scan_ap_num
<= 5))
572 halbtc8723b1ant_coex_table(btcoexist
, force_exec
,
573 0x55555555, 0xaaaa5a5a,
576 halbtc8723b1ant_coex_table(btcoexist
, force_exec
,
577 0x55555555, 0x5a5a5a5a,
581 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x5a5a5a5a,
582 0x5aaa5a5a, 0xffffff, 0x3);
585 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
586 0xaaaaaaaa, 0xffffff, 0x3);
589 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0xaaaaaaaa,
590 0xaaaaaaaa, 0xffffff, 0x3);
593 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
594 0x5ada5ada, 0xffffff, 0x3);
597 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
598 0x5ada5ada, 0xffffff, 0x3);
601 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
602 0x5ada5ada, 0xffffff, 0x3);
605 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
606 0x5ada5ada, 0xffffff, 0x3);
609 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
610 0x5ada5ada, 0xffffff, 0x3);
613 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x5fff5fff,
614 0xaaaaaaaa, 0xffffff, 0x3);
617 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x5fff5fff,
618 0x5ada5ada, 0xffffff, 0x3);
621 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
622 0xaaaaaaaa, 0xffffff, 0x3);
630 halbtc8723b1ant_set_fw_ignore_wlan_act(struct btc_coexist
*btcoexist
,
633 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
634 u8 h2c_parameter
[1] = {0};
637 h2c_parameter
[0] |= BIT0
; /* function enable */
639 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
640 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
643 btcoexist
->btc_fill_h2c(btcoexist
, 0x63, 1, h2c_parameter
);
646 static void halbtc8723b1ant_ignore_wlan_act(struct btc_coexist
*btcoexist
,
647 bool force_exec
, bool enable
)
649 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
651 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
652 "[BTCoex], %s turn Ignore WlanAct %s\n",
653 (force_exec
? "force to" : ""), (enable
? "ON" : "OFF"));
654 coex_dm
->cur_ignore_wlan_act
= enable
;
657 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
658 "[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
659 coex_dm
->pre_ignore_wlan_act
,
660 coex_dm
->cur_ignore_wlan_act
);
662 if (coex_dm
->pre_ignore_wlan_act
==
663 coex_dm
->cur_ignore_wlan_act
)
666 halbtc8723b1ant_set_fw_ignore_wlan_act(btcoexist
, enable
);
668 coex_dm
->pre_ignore_wlan_act
= coex_dm
->cur_ignore_wlan_act
;
671 static void halbtc8723b1ant_set_fw_ps_tdma(struct btc_coexist
*btcoexist
,
672 u8 byte1
, u8 byte2
, u8 byte3
,
675 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
676 u8 h2c_parameter
[5] = {0};
677 u8 real_byte1
= byte1
, real_byte5
= byte5
;
678 bool ap_enable
= false;
680 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
684 if ((byte1
& BIT4
) && !(byte1
& BIT5
)) {
685 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
686 "[BTCoex], FW for 1Ant AP mode\n");
695 h2c_parameter
[0] = real_byte1
;
696 h2c_parameter
[1] = byte2
;
697 h2c_parameter
[2] = byte3
;
698 h2c_parameter
[3] = byte4
;
699 h2c_parameter
[4] = real_byte5
;
701 coex_dm
->ps_tdma_para
[0] = real_byte1
;
702 coex_dm
->ps_tdma_para
[1] = byte2
;
703 coex_dm
->ps_tdma_para
[2] = byte3
;
704 coex_dm
->ps_tdma_para
[3] = byte4
;
705 coex_dm
->ps_tdma_para
[4] = real_byte5
;
707 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
708 "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
710 h2c_parameter
[1] << 24 |
711 h2c_parameter
[2] << 16 |
712 h2c_parameter
[3] << 8 |
715 btcoexist
->btc_fill_h2c(btcoexist
, 0x60, 5, h2c_parameter
);
718 static void halbtc8723b1ant_set_lps_rpwm(struct btc_coexist
*btcoexist
,
719 u8 lps_val
, u8 rpwm_val
)
724 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_LPS_VAL
, &lps
);
725 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_RPWM_VAL
, &rpwm
);
728 static void halbtc8723b1ant_lps_rpwm(struct btc_coexist
*btcoexist
,
730 u8 lps_val
, u8 rpwm_val
)
732 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
734 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
735 "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n",
736 (force_exec
? "force to" : ""), lps_val
, rpwm_val
);
737 coex_dm
->cur_lps
= lps_val
;
738 coex_dm
->cur_rpwm
= rpwm_val
;
741 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
742 "[BTCoex], LPS-RxBeaconMode = 0x%x , LPS-RPWM = 0x%x!!\n",
743 coex_dm
->cur_lps
, coex_dm
->cur_rpwm
);
745 if ((coex_dm
->pre_lps
== coex_dm
->cur_lps
) &&
746 (coex_dm
->pre_rpwm
== coex_dm
->cur_rpwm
)) {
747 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
748 "[BTCoex], LPS-RPWM_Last = 0x%x , LPS-RPWM_Now = 0x%x!!\n",
749 coex_dm
->pre_rpwm
, coex_dm
->cur_rpwm
);
754 halbtc8723b1ant_set_lps_rpwm(btcoexist
, lps_val
, rpwm_val
);
756 coex_dm
->pre_lps
= coex_dm
->cur_lps
;
757 coex_dm
->pre_rpwm
= coex_dm
->cur_rpwm
;
760 static void halbtc8723b1ant_sw_mechanism(struct btc_coexist
*btcoexist
,
763 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
765 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
766 "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra
);
768 halbtc8723b1ant_low_penalty_ra(btcoexist
, NORMAL_EXEC
, low_penalty_ra
);
771 static void halbtc8723b1ant_set_ant_path(struct btc_coexist
*btcoexist
,
772 u8 ant_pos_type
, bool force_exec
,
773 bool init_hw_cfg
, bool wifi_off
)
775 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
776 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
777 u32 fw_ver
= 0, u32tmp
= 0, cnt_bt_cal_chk
= 0;
778 bool pg_ext_switch
= false;
779 bool use_ext_switch
= false;
780 bool is_in_mp_mode
= false;
781 u8 h2c_parameter
[2] = {0}, u8tmp
= 0;
783 coex_dm
->cur_ant_pos_type
= ant_pos_type
;
785 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_EXT_SWITCH
, &pg_ext_switch
);
786 /* [31:16] = fw ver, [15:0] = fw sub ver */
787 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
789 if ((fw_ver
< 0xc0000) || pg_ext_switch
)
790 use_ext_switch
= true;
793 /* WiFi TRx Mask on */
794 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff,
796 /* remove due to interrupt is disabled that polling c2h will
797 * fail and delay 100ms.
800 if (fw_ver
>= 0x180000) {
801 /* Use H2C to set GNT_BT to HIGH */
802 h2c_parameter
[0] = 1;
803 btcoexist
->btc_fill_h2c(btcoexist
, 0x6E, 1,
806 /* set grant_bt to high */
807 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x18);
809 /* set wlan_act control by PTA */
810 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
812 /* BT select s0/s1 is controlled by BT */
813 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67, 0x20, 0x0);
814 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x39, 0x8, 0x1);
815 btcoexist
->btc_write_1byte(btcoexist
, 0x974, 0xff);
816 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x944, 0x3, 0x3);
817 btcoexist
->btc_write_1byte(btcoexist
, 0x930, 0x77);
818 } else if (wifi_off
) {
819 if (fw_ver
>= 0x180000) {
820 /* Use H2C to set GNT_BT to HIGH */
821 h2c_parameter
[0] = 1;
822 btcoexist
->btc_fill_h2c(btcoexist
, 0x6E, 1,
825 /* set grant_bt to high */
826 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x18);
828 /* set wlan_act to always low */
829 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
831 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_IS_IN_MP_MODE
,
834 /* BT select s0/s1 is controlled by BT */
835 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67,
838 /* BT select s0/s1 is controlled by WiFi */
839 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67,
842 /* 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL
843 * BT Vendor 0xac=0xf002
845 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
848 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
850 /* Use H2C to set GNT_BT to LOW */
851 if (fw_ver
>= 0x180000) {
852 if (btcoexist
->btc_read_1byte(btcoexist
, 0x765) != 0) {
853 h2c_parameter
[0] = 0;
854 btcoexist
->btc_fill_h2c(btcoexist
, 0x6E, 1,
858 /* BT calibration check */
859 while (cnt_bt_cal_chk
<= 20) {
860 u8tmp
= btcoexist
->btc_read_1byte(btcoexist
,
863 if (u8tmp
& BIT(0)) {
864 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
866 "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n",
870 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
872 "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n",
878 /* set grant_bt to PTA */
879 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x0);
882 if (btcoexist
->btc_read_1byte(btcoexist
, 0x76e) != 0xc) {
883 /* set wlan_act control by PTA */
884 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
887 btcoexist
->btc_write_1byte_bitmask(
888 btcoexist
, 0x67, 0x20,
889 0x1); /* BT select s0/s1 is controlled by WiFi */
892 if (use_ext_switch
) {
894 /* 0x4c[23] = 0, 0x4c[24] = 1
895 * Antenna control by WL/BT
897 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
900 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
902 /* fixed internal switch S1->WiFi, S0->BT */
903 btcoexist
->btc_write_4byte(btcoexist
, 0x948, 0x0);
905 if (board_info
->btdm_ant_pos
==
906 BTC_ANTENNA_AT_MAIN_PORT
) {
907 /* tell firmware "no antenna inverse" */
908 h2c_parameter
[0] = 0;
909 /* ext switch type */
910 h2c_parameter
[1] = 1;
911 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
914 /* tell firmware "antenna inverse" */
915 h2c_parameter
[0] = 1;
916 /* ext switch type */
917 h2c_parameter
[1] = 1;
918 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
924 (coex_dm
->cur_ant_pos_type
!= coex_dm
->pre_ant_pos_type
)) {
925 /* ext switch setting */
926 switch (ant_pos_type
) {
927 case BTC_ANT_PATH_WIFI
:
928 if (board_info
->btdm_ant_pos
==
929 BTC_ANTENNA_AT_MAIN_PORT
)
930 btcoexist
->btc_write_1byte_bitmask(
931 btcoexist
, 0x92c, 0x3, 0x1);
933 btcoexist
->btc_write_1byte_bitmask(
934 btcoexist
, 0x92c, 0x3, 0x2);
936 case BTC_ANT_PATH_BT
:
937 if (board_info
->btdm_ant_pos
==
938 BTC_ANTENNA_AT_MAIN_PORT
)
939 btcoexist
->btc_write_1byte_bitmask(
940 btcoexist
, 0x92c, 0x3, 0x2);
942 btcoexist
->btc_write_1byte_bitmask(
943 btcoexist
, 0x92c, 0x3, 0x1);
946 case BTC_ANT_PATH_PTA
:
947 if (board_info
->btdm_ant_pos
==
948 BTC_ANTENNA_AT_MAIN_PORT
)
949 btcoexist
->btc_write_1byte_bitmask(
950 btcoexist
, 0x92c, 0x3, 0x1);
952 btcoexist
->btc_write_1byte_bitmask(
953 btcoexist
, 0x92c, 0x3, 0x2);
959 /* 0x4c[23] = 1, 0x4c[24] = 0,
960 * Antenna control by 0x64
962 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
965 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
967 /* Fix Ext switch Main->S1, Aux->S0 */
968 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x64, 0x1,
971 if (board_info
->btdm_ant_pos
==
972 BTC_ANTENNA_AT_MAIN_PORT
) {
973 /* tell firmware "no antenna inverse" */
974 h2c_parameter
[0] = 0;
975 /* internal switch type */
976 h2c_parameter
[1] = 0;
977 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
980 /* tell firmware "antenna inverse" */
981 h2c_parameter
[0] = 1;
982 /* internal switch type */
983 h2c_parameter
[1] = 0;
984 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
990 (coex_dm
->cur_ant_pos_type
!= coex_dm
->pre_ant_pos_type
)) {
991 /* internal switch setting */
992 switch (ant_pos_type
) {
993 case BTC_ANT_PATH_WIFI
:
994 if (board_info
->btdm_ant_pos
==
995 BTC_ANTENNA_AT_MAIN_PORT
)
996 btcoexist
->btc_write_4byte(btcoexist
,
999 btcoexist
->btc_write_4byte(btcoexist
,
1002 case BTC_ANT_PATH_BT
:
1003 if (board_info
->btdm_ant_pos
==
1004 BTC_ANTENNA_AT_MAIN_PORT
)
1005 btcoexist
->btc_write_4byte(btcoexist
,
1008 btcoexist
->btc_write_4byte(btcoexist
,
1012 case BTC_ANT_PATH_PTA
:
1013 if (board_info
->btdm_ant_pos
==
1014 BTC_ANTENNA_AT_MAIN_PORT
)
1015 btcoexist
->btc_write_4byte(btcoexist
,
1018 btcoexist
->btc_write_4byte(btcoexist
,
1025 coex_dm
->pre_ant_pos_type
= coex_dm
->cur_ant_pos_type
;
1028 static void halbtc8723b1ant_ps_tdma(struct btc_coexist
*btcoexist
,
1029 bool force_exec
, bool turn_on
, u8 type
)
1031 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1032 bool wifi_busy
= false;
1033 u8 rssi_adjust_val
= 0;
1034 u8 ps_tdma_byte0_val
= 0x51;
1035 u8 ps_tdma_byte3_val
= 0x10;
1036 u8 ps_tdma_byte4_val
= 0x50;
1037 s8 wifi_duration_adjust
= 0x0;
1038 static bool pre_wifi_busy
;
1040 coex_dm
->cur_ps_tdma_on
= turn_on
;
1041 coex_dm
->cur_ps_tdma
= type
;
1043 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1045 if (wifi_busy
!= pre_wifi_busy
) {
1047 pre_wifi_busy
= wifi_busy
;
1051 if ((coex_dm
->pre_ps_tdma_on
== coex_dm
->cur_ps_tdma_on
) &&
1052 (coex_dm
->pre_ps_tdma
== coex_dm
->cur_ps_tdma
))
1056 if (coex_sta
->scan_ap_num
<= 5) {
1057 wifi_duration_adjust
= 5;
1059 if (coex_sta
->a2dp_bit_pool
>= 35)
1060 wifi_duration_adjust
= -10;
1061 else if (coex_sta
->a2dp_bit_pool
>= 45)
1062 wifi_duration_adjust
= -15;
1063 } else if (coex_sta
->scan_ap_num
>= 40) {
1064 wifi_duration_adjust
= -15;
1066 if (coex_sta
->a2dp_bit_pool
< 35)
1067 wifi_duration_adjust
= -5;
1068 else if (coex_sta
->a2dp_bit_pool
< 45)
1069 wifi_duration_adjust
= -10;
1070 } else if (coex_sta
->scan_ap_num
>= 20) {
1071 wifi_duration_adjust
= -10;
1073 if (coex_sta
->a2dp_bit_pool
>= 45)
1074 wifi_duration_adjust
= -15;
1076 wifi_duration_adjust
= 0;
1078 if (coex_sta
->a2dp_bit_pool
>= 35)
1079 wifi_duration_adjust
= -10;
1080 else if (coex_sta
->a2dp_bit_pool
>= 45)
1081 wifi_duration_adjust
= -15;
1084 if ((type
== 1) || (type
== 2) || (type
== 9) || (type
== 11) ||
1085 (type
== 101) || (type
== 102) || (type
== 109) || (type
== 111)) {
1086 if (!coex_sta
->force_lps_on
) {
1087 /* Native power save TDMA, only for A2DP-only case
1088 * 1/2/9/11 while wifi noisy threshold > 30
1092 ps_tdma_byte0_val
= 0x61;
1093 /* no tx-pause at BT-slot */
1094 ps_tdma_byte3_val
= 0x11;
1095 /* 0x778 = d/1 toggle, no dynamic slot */
1096 ps_tdma_byte4_val
= 0x10;
1099 ps_tdma_byte0_val
= 0x51;
1100 /* tx-pause at BT-slot */
1101 ps_tdma_byte3_val
= 0x10;
1102 /* 0x778 = d/1 toggle, dynamic slot */
1103 ps_tdma_byte4_val
= 0x50;
1105 } else if ((type
== 3) || (type
== 13) || (type
== 14) ||
1106 (type
== 103) || (type
== 113) || (type
== 114)) {
1108 ps_tdma_byte0_val
= 0x51;
1109 /* tx-pause at BT-slot */
1110 ps_tdma_byte3_val
= 0x10;
1111 /* 0x778 = d/1 toggle, no dynamic slot */
1112 ps_tdma_byte4_val
= 0x10;
1113 } else { /* native power save case */
1115 ps_tdma_byte0_val
= 0x61;
1116 /* no tx-pause at BT-slot */
1117 ps_tdma_byte3_val
= 0x11;
1118 /* 0x778 = d/1 toggle, no dynamic slot */
1119 ps_tdma_byte4_val
= 0x11;
1120 /* psTdmaByte4Va is not define for 0x778 = d/1, 1/1 case */
1123 /* if (bt_link_info->slave_role) */
1124 if ((bt_link_info
->slave_role
) && (bt_link_info
->a2dp_exist
))
1125 /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1126 ps_tdma_byte4_val
= ps_tdma_byte4_val
| 0x1;
1129 /* set antenna control by SW */
1130 ps_tdma_byte0_val
= ps_tdma_byte0_val
| 0x82;
1131 /* set antenna no toggle, control by antenna diversity */
1132 ps_tdma_byte3_val
= ps_tdma_byte3_val
| 0x60;
1138 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x1a,
1143 halbtc8723b1ant_set_fw_ps_tdma(
1144 btcoexist
, ps_tdma_byte0_val
,
1145 0x3a + wifi_duration_adjust
, 0x03,
1146 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1148 rssi_adjust_val
= 11;
1151 halbtc8723b1ant_set_fw_ps_tdma(
1152 btcoexist
, ps_tdma_byte0_val
,
1153 0x2d + wifi_duration_adjust
, 0x03,
1154 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1157 halbtc8723b1ant_set_fw_ps_tdma(
1158 btcoexist
, ps_tdma_byte0_val
, 0x30, 0x03,
1159 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1162 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x15,
1166 halbtc8723b1ant_set_fw_ps_tdma(
1167 btcoexist
, ps_tdma_byte0_val
, 0x1f, 0x3,
1168 ps_tdma_byte3_val
, 0x11);
1171 halbtc8723b1ant_set_fw_ps_tdma(
1172 btcoexist
, ps_tdma_byte0_val
, 0x20, 0x3,
1173 ps_tdma_byte3_val
, 0x11);
1176 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xc,
1180 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x25,
1184 halbtc8723b1ant_set_fw_ps_tdma(
1185 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1186 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1189 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xa,
1193 halbtc8723b1ant_set_fw_ps_tdma(
1194 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x03,
1195 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1198 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x0a,
1202 if (coex_sta
->scan_ap_num
<= 3)
1203 halbtc8723b1ant_set_fw_ps_tdma(
1204 btcoexist
, ps_tdma_byte0_val
, 0x40, 0x3,
1205 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1207 halbtc8723b1ant_set_fw_ps_tdma(
1208 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1209 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1212 if (coex_sta
->scan_ap_num
<= 3)
1213 halbtc8723b1ant_set_fw_ps_tdma(
1214 btcoexist
, 0x51, 0x30, 0x3, 0x10, 0x50);
1216 halbtc8723b1ant_set_fw_ps_tdma(
1217 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1218 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1221 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xa,
1225 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x15,
1229 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x25,
1233 halbtc8723b1ant_set_fw_ps_tdma(
1234 btcoexist
, ps_tdma_byte0_val
, 0x3f, 0x03,
1235 ps_tdma_byte3_val
, 0x10);
1238 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x25,
1242 halbtc8723b1ant_set_fw_ps_tdma(
1243 btcoexist
, ps_tdma_byte0_val
, 0x25, 0x03,
1244 ps_tdma_byte3_val
, 0x10);
1247 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1251 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x15,
1255 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1259 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1263 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1267 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x69, 0x25,
1271 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xab, 0x1a,
1275 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x30,
1279 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x1a,
1283 halbtc8723b1ant_set_fw_ps_tdma(
1284 btcoexist
, ps_tdma_byte0_val
, 0x35, 0x3,
1285 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1288 halbtc8723b1ant_set_fw_ps_tdma(
1289 btcoexist
, ps_tdma_byte0_val
, 0x35, 0x3,
1290 ps_tdma_byte3_val
, 0x10);
1293 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x53, 0x1a,
1297 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x63, 0x1a,
1301 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x12,
1305 /* SoftAP only with no sta associated,BT disable ,TDMA
1306 * mode for power saving
1308 * here softap mode screen off will cost 70-80mA for
1311 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x23, 0x18,
1316 /* for 1-Ant translate to 2-Ant */
1317 halbtc8723b1ant_set_fw_ps_tdma(
1318 btcoexist
, ps_tdma_byte0_val
,
1319 0x3a + wifi_duration_adjust
, 0x03,
1320 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1323 halbtc8723b1ant_set_fw_ps_tdma(
1324 btcoexist
, ps_tdma_byte0_val
,
1325 0x2d + wifi_duration_adjust
, 0x03,
1326 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1329 halbtc8723b1ant_set_fw_ps_tdma(
1330 btcoexist
, ps_tdma_byte0_val
, 0x3a, 0x03,
1331 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1334 halbtc8723b1ant_set_fw_ps_tdma(
1335 btcoexist
, ps_tdma_byte0_val
, 0x15, 0x3,
1336 ps_tdma_byte3_val
, 0x11);
1339 halbtc8723b1ant_set_fw_ps_tdma(
1340 btcoexist
, ps_tdma_byte0_val
, 0x20, 0x3,
1341 ps_tdma_byte3_val
, 0x11);
1344 halbtc8723b1ant_set_fw_ps_tdma(
1345 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1346 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1349 halbtc8723b1ant_set_fw_ps_tdma(
1350 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x03,
1351 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1354 halbtc8723b1ant_set_fw_ps_tdma(
1355 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1356 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1359 halbtc8723b1ant_set_fw_ps_tdma(
1360 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1361 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1364 halbtc8723b1ant_set_fw_ps_tdma(
1365 btcoexist
, ps_tdma_byte0_val
, 0x3f, 0x03,
1366 ps_tdma_byte3_val
, 0x10);
1369 halbtc8723b1ant_set_fw_ps_tdma(
1370 btcoexist
, ps_tdma_byte0_val
, 0x25, 0x03,
1371 ps_tdma_byte3_val
, 0x10);
1374 halbtc8723b1ant_set_fw_ps_tdma(
1375 btcoexist
, ps_tdma_byte0_val
, 0x25, 0x03,
1376 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1379 halbtc8723b1ant_set_fw_ps_tdma(
1380 btcoexist
, ps_tdma_byte0_val
, 0x25, 0x03,
1381 ps_tdma_byte3_val
, 0x11);
1385 /* disable PS tdma */
1387 case 8: /* PTA Control */
1388 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x8, 0x0,
1390 halbtc8723b1ant_set_ant_path(btcoexist
,
1397 /* Software control, Antenna at BT side */
1398 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0,
1401 case 1: /* 2-Ant, 0x778=3, antenna control by ant diversity */
1402 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1407 rssi_adjust_val
= 0;
1408 btcoexist
->btc_set(btcoexist
,
1409 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE
,
1412 /* update pre state */
1413 coex_dm
->pre_ps_tdma_on
= coex_dm
->cur_ps_tdma_on
;
1414 coex_dm
->pre_ps_tdma
= coex_dm
->cur_ps_tdma
;
1418 void btc8723b1ant_tdma_dur_adj_for_acl(struct btc_coexist
*btcoexist
,
1421 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1422 static s32 up
, dn
, m
, n
, wait_count
;
1423 /* 0: no change, +1: increase WiFi duration,
1424 * -1: decrease WiFi duration
1429 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1430 "[BTCoex], TdmaDurationAdjustForAcl()\n");
1433 BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN
) ||
1434 (wifi_status
== BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
) ||
1435 (wifi_status
== BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT
)) {
1436 if (coex_dm
->cur_ps_tdma
!= 1 && coex_dm
->cur_ps_tdma
!= 2 &&
1437 coex_dm
->cur_ps_tdma
!= 3 && coex_dm
->cur_ps_tdma
!= 9) {
1438 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1440 coex_dm
->ps_tdma_du_adj_type
= 9;
1452 if (!coex_dm
->auto_tdma_adjust
) {
1453 coex_dm
->auto_tdma_adjust
= true;
1454 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1455 "[BTCoex], first run TdmaDurationAdjust()!!\n");
1457 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 2);
1458 coex_dm
->ps_tdma_du_adj_type
= 2;
1467 /* acquire the BT TRx retry count from BT_Info byte2 */
1468 retry_count
= coex_sta
->bt_retry_cnt
;
1470 if ((coex_sta
->low_priority_tx
) > 1050 ||
1471 (coex_sta
->low_priority_rx
) > 1250)
1476 /* no retry in the last 2-second duration */
1477 if (retry_count
== 0) {
1485 /* if retry count during continuous n*2 seconds
1486 * is 0, enlarge WiFi duration
1493 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1494 "[BTCoex], Increase wifi duration!!\n");
1496 } else if (retry_count
<= 3) {
1497 /* <=3 retry in the last 2-second duration */
1505 /* if continuous 2 retry count(every 2 seconds)
1506 * >0 and < 3, reduce WiFi duration
1508 if (wait_count
<= 2)
1509 /* avoid loop between the two levels */
1515 /* maximum of m = 20 ' will recheck if
1516 * need to adjust wifi duration in
1517 * maximum time interval 120 seconds
1526 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1527 "[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
1530 /* retry count > 3, once retry count > 3, to reduce
1533 if (wait_count
== 1)
1534 /* to avoid loop between the two levels */
1540 /* maximum of m = 20 ' will recheck if need to
1541 * adjust wifi duration in maximum time interval
1551 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1552 "[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
1556 if (coex_dm
->cur_ps_tdma
== 1) {
1557 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1559 coex_dm
->ps_tdma_du_adj_type
= 2;
1560 } else if (coex_dm
->cur_ps_tdma
== 2) {
1561 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1563 coex_dm
->ps_tdma_du_adj_type
= 9;
1564 } else if (coex_dm
->cur_ps_tdma
== 9) {
1565 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1567 coex_dm
->ps_tdma_du_adj_type
= 11;
1569 } else if (result
== 1) {
1570 if (coex_dm
->cur_ps_tdma
== 11) {
1571 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1573 coex_dm
->ps_tdma_du_adj_type
= 9;
1574 } else if (coex_dm
->cur_ps_tdma
== 9) {
1575 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1577 coex_dm
->ps_tdma_du_adj_type
= 2;
1578 } else if (coex_dm
->cur_ps_tdma
== 2) {
1579 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1581 coex_dm
->ps_tdma_du_adj_type
= 1;
1585 if (coex_dm
->cur_ps_tdma
!= 1 && coex_dm
->cur_ps_tdma
!= 2 &&
1586 coex_dm
->cur_ps_tdma
!= 9 && coex_dm
->cur_ps_tdma
!= 11) {
1587 /* recover to previous adjust type */
1588 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1589 coex_dm
->ps_tdma_du_adj_type
);
1594 static void halbtc8723b1ant_ps_tdma_chk_pwr_save(struct btc_coexist
*btcoexist
,
1599 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_LPS_MODE
, &lps_mode
);
1602 /* already under LPS state */
1604 /* keep state under LPS, do nothing. */
1606 /* will leave LPS state, turn off psTdma first */
1607 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1613 /* will enter LPS state, turn off psTdma first */
1614 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1617 /* keep state under NO PS state, do nothing. */
1622 static void halbtc8723b1ant_power_save_state(struct btc_coexist
*btcoexist
,
1623 u8 ps_type
, u8 lps_val
,
1626 bool low_pwr_disable
= false;
1629 case BTC_PS_WIFI_NATIVE
:
1630 /* recover to original 32k low power setting */
1631 low_pwr_disable
= false;
1632 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1634 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_NORMAL_LPS
, NULL
);
1635 coex_sta
->force_lps_on
= false;
1638 halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist
, true);
1639 halbtc8723b1ant_lps_rpwm(btcoexist
, NORMAL_EXEC
, lps_val
,
1641 /* when coex force to enter LPS, do not enter 32k low power */
1642 low_pwr_disable
= true;
1643 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1645 /* power save must executed before psTdma */
1646 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_ENTER_LPS
, NULL
);
1647 coex_sta
->force_lps_on
= true;
1649 case BTC_PS_LPS_OFF
:
1650 halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist
, false);
1651 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_LEAVE_LPS
, NULL
);
1652 coex_sta
->force_lps_on
= false;
1659 static void halbtc8723b1ant_action_wifi_only(struct btc_coexist
*btcoexist
)
1661 halbtc8723b1ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 0);
1662 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
1663 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
1664 FORCE_EXEC
, false, false);
1667 /* check if BT is disabled */
1668 static void halbtc8723b1ant_monitor_bt_enable_disable(struct btc_coexist
1671 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1672 static u32 bt_disable_cnt
;
1673 bool bt_active
= true, bt_disabled
= false;
1675 if (coex_sta
->high_priority_tx
== 0 &&
1676 coex_sta
->high_priority_rx
== 0 && coex_sta
->low_priority_tx
== 0 &&
1677 coex_sta
->low_priority_rx
== 0)
1679 if (coex_sta
->high_priority_tx
== 0xffff &&
1680 coex_sta
->high_priority_rx
== 0xffff &&
1681 coex_sta
->low_priority_tx
== 0xffff &&
1682 coex_sta
->low_priority_rx
== 0xffff)
1686 bt_disabled
= false;
1689 if (bt_disable_cnt
>= 2)
1692 if (coex_sta
->bt_disabled
!= bt_disabled
) {
1693 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1694 "[BTCoex], BT is from %s to %s!!\n",
1695 (coex_sta
->bt_disabled
? "disabled" : "enabled"),
1696 (bt_disabled
? "disabled" : "enabled"));
1698 coex_sta
->bt_disabled
= bt_disabled
;
1699 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_DISABLE
,
1702 halbtc8723b1ant_action_wifi_only(btcoexist
);
1703 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_LEAVE_LPS
,
1705 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_NORMAL_LPS
,
1711 /*****************************************************
1713 * Non-Software Coex Mechanism start
1715 *****************************************************/
1717 static void halbtc8723b1ant_action_bt_whck_test(struct btc_coexist
*btcoexist
)
1719 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0,
1722 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1723 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
, NORMAL_EXEC
,
1725 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1728 static void halbtc8723b1ant_action_wifi_multiport(struct btc_coexist
*btcoexist
)
1730 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1733 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1734 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
, NORMAL_EXEC
,
1736 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1739 static void halbtc8723b1ant_action_hs(struct btc_coexist
*btcoexist
)
1741 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 5);
1742 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1745 static void halbtc8723b1ant_action_bt_inquiry(struct btc_coexist
*btcoexist
)
1747 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1748 bool wifi_connected
= false, ap_enable
= false;
1749 bool wifi_busy
= false, bt_busy
= false;
1751 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
1753 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1755 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1756 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TRAFFIC_BUSY
, &bt_busy
);
1758 if (coex_sta
->bt_abnormal_scan
) {
1759 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 33);
1760 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
1761 } else if (!wifi_connected
&& !coex_sta
->wifi_is_high_pri_task
) {
1762 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1764 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1765 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
1766 NORMAL_EXEC
, false, false);
1767 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1768 } else if (bt_link_info
->sco_exist
|| bt_link_info
->hid_exist
||
1769 bt_link_info
->a2dp_exist
) {
1770 /* SCO/HID/A2DP busy */
1771 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1773 if (coex_sta
->c2h_bt_remote_name_req
)
1774 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1777 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1780 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1781 } else if (bt_link_info
->pan_exist
|| wifi_busy
) {
1782 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1784 if (coex_sta
->c2h_bt_remote_name_req
)
1785 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1788 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1791 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1793 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1795 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1796 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
1797 NORMAL_EXEC
, false, false);
1798 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
1802 static void btc8723b1ant_act_bt_sco_hid_only_busy(struct btc_coexist
*btcoexist
,
1805 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1806 bool wifi_connected
= false;
1808 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1811 /* tdma and coex table */
1812 if (bt_link_info
->sco_exist
) {
1813 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 5);
1814 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 5);
1817 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 6);
1818 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 5);
1822 static void halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
1823 struct btc_coexist
*btcoexist
,
1826 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1828 if ((coex_sta
->low_priority_rx
>= 950) && (!coex_sta
->under_ips
))
1829 bt_link_info
->slave_role
= true;
1831 bt_link_info
->slave_role
= false;
1833 if (bt_link_info
->hid_only
) { /* HID */
1834 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist
, wifi_status
);
1835 coex_dm
->auto_tdma_adjust
= false;
1837 } else if (bt_link_info
->a2dp_only
) { /* A2DP */
1838 if (wifi_status
== BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE
) {
1839 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1841 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1843 coex_dm
->auto_tdma_adjust
= false;
1845 btc8723b1ant_tdma_dur_adj_for_acl(btcoexist
,
1847 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1849 coex_dm
->auto_tdma_adjust
= true;
1851 } else if (((bt_link_info
->a2dp_exist
) && (bt_link_info
->pan_exist
)) ||
1852 (bt_link_info
->hid_exist
&& bt_link_info
->a2dp_exist
&&
1853 bt_link_info
->pan_exist
)) {
1854 /* A2DP + PAN(OPP,FTP), HID + A2DP + PAN(OPP,FTP) */
1855 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 13);
1856 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1857 coex_dm
->auto_tdma_adjust
= false;
1858 } else if (bt_link_info
->hid_exist
&& bt_link_info
->a2dp_exist
) {
1860 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1861 coex_dm
->auto_tdma_adjust
= false;
1863 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1864 } else if (bt_link_info
->pan_only
||
1865 (bt_link_info
->hid_exist
&& bt_link_info
->pan_exist
)) {
1866 /* PAN(OPP,FTP), HID + PAN(OPP,FTP) */
1867 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
1868 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1869 coex_dm
->auto_tdma_adjust
= false;
1871 /* BT no-profile busy (0x9) */
1872 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 33);
1873 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1874 coex_dm
->auto_tdma_adjust
= false;
1878 static void btc8723b1ant_action_wifi_not_conn(struct btc_coexist
*btcoexist
)
1880 /* power save state */
1881 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1884 /* tdma and coex table */
1885 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
1886 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
, NORMAL_EXEC
,
1888 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1892 btc8723b1ant_action_wifi_not_conn_scan(struct btc_coexist
*btcoexist
)
1894 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1896 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1899 /* tdma and coex table */
1900 if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
) {
1901 if (bt_link_info
->a2dp_exist
) {
1902 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1904 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1906 } else if (bt_link_info
->a2dp_exist
) {
1907 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1909 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1912 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1914 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1917 } else if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_SCO_BUSY
||
1918 coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
){
1919 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist
,
1920 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
);
1922 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1923 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
1924 NORMAL_EXEC
, false, false);
1925 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1930 btc8723b1ant_act_wifi_not_conn_asso_auth(struct btc_coexist
*btcoexist
)
1932 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1934 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1937 /* tdma and coex table */
1938 if ((bt_link_info
->sco_exist
) || (bt_link_info
->hid_exist
) ||
1939 (bt_link_info
->a2dp_exist
)) {
1940 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 32);
1941 halbtc8723b1ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 4);
1942 } else if (bt_link_info
->pan_exist
) {
1943 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
1944 halbtc8723b1ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 4);
1946 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1947 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
1948 NORMAL_EXEC
, false, false);
1949 halbtc8723b1ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 2);
1953 static void btc8723b1ant_action_wifi_conn_scan(struct btc_coexist
*btcoexist
)
1955 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1957 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1960 /* tdma and coex table */
1961 if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
) {
1962 if (bt_link_info
->a2dp_exist
) {
1963 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1965 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1967 } else if (bt_link_info
->a2dp_exist
&&
1968 bt_link_info
->pan_exist
) {
1969 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1971 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1974 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1976 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1979 } else if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_SCO_BUSY
||
1980 coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
) {
1981 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist
,
1982 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
);
1984 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1985 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
1986 NORMAL_EXEC
, false, false);
1987 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1991 static void halbtc8723b1ant_action_wifi_connected_special_packet(
1992 struct btc_coexist
*btcoexist
)
1994 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1995 bool wifi_busy
= false;
1997 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1999 /* no special packet process for both WiFi and BT very busy */
2001 ((bt_link_info
->pan_exist
) || (coex_sta
->num_of_profile
>= 2)))
2004 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2007 /* tdma and coex table */
2008 if ((bt_link_info
->sco_exist
) || (bt_link_info
->hid_exist
)) {
2009 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 32);
2010 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 5);
2011 } else if (bt_link_info
->a2dp_exist
) {
2012 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 32);
2013 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
2014 } else if (bt_link_info
->pan_exist
) {
2015 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
2016 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
2018 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
2019 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
2020 NORMAL_EXEC
, false, false);
2021 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
2025 static void halbtc8723b1ant_action_wifi_connected(struct btc_coexist
*btcoexist
)
2027 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2028 bool wifi_busy
= false;
2029 bool scan
= false, link
= false, roam
= false;
2030 bool under_4way
= false, ap_enable
= false;
2032 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2033 "[BTCoex], CoexForWifiConnect()===>\n");
2035 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
2038 halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist
);
2039 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2040 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
2044 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2045 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2046 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2048 if (scan
|| link
|| roam
) {
2050 btc8723b1ant_action_wifi_conn_scan(btcoexist
);
2052 halbtc8723b1ant_action_wifi_connected_special_packet(
2054 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2055 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
2059 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
2061 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
2062 /* power save state */
2064 coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
&&
2065 !btcoexist
->bt_link_info
.hid_only
) {
2066 if (btcoexist
->bt_link_info
.a2dp_only
) {
2068 halbtc8723b1ant_power_save_state(btcoexist
,
2072 if (coex_sta
->scan_ap_num
>=
2073 BT_8723B_1ANT_WIFI_NOISY_THRESH
)
2074 /* no force LPS, no PS-TDMA,
2077 halbtc8723b1ant_power_save_state(
2078 btcoexist
, BTC_PS_WIFI_NATIVE
,
2081 halbtc8723b1ant_power_save_state(
2082 btcoexist
, BTC_PS_LPS_ON
, 0x50,
2085 } else if ((!coex_sta
->pan_exist
) && (!coex_sta
->a2dp_exist
) &&
2086 (!coex_sta
->hid_exist
))
2087 halbtc8723b1ant_power_save_state(
2088 btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
2090 halbtc8723b1ant_power_save_state(btcoexist
,
2094 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2097 /* tdma and coex table */
2099 if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
) {
2100 halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
2102 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE
);
2103 } else if (coex_dm
->bt_status
==
2104 BT_8723B_1ANT_BT_STATUS_SCO_BUSY
||
2105 coex_dm
->bt_status
==
2106 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
) {
2107 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist
,
2108 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE
);
2110 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2112 halbtc8723b1ant_set_ant_path(btcoexist
,
2114 NORMAL_EXEC
, false, false);
2115 halbtc8723b1ant_coex_table_with_type(btcoexist
,
2119 if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
) {
2120 halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
2122 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
);
2123 } else if (coex_dm
->bt_status
==
2124 BT_8723B_1ANT_BT_STATUS_SCO_BUSY
||
2125 coex_dm
->bt_status
==
2126 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
) {
2127 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist
,
2128 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
);
2130 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2132 halbtc8723b1ant_set_ant_path(btcoexist
,
2134 NORMAL_EXEC
, false, false);
2135 halbtc8723b1ant_coex_table_with_type(btcoexist
,
2141 static void halbtc8723b1ant_run_coexist_mechanism(struct btc_coexist
*btcoexist
)
2143 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2144 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
2145 bool wifi_connected
= false, bt_hs_on
= false, wifi_busy
= false;
2146 bool increase_scan_dev_num
= false;
2147 bool bt_ctrl_agg_buf_size
= false;
2148 bool miracast_plus_bt
= false;
2149 u8 agg_buf_size
= 5;
2150 u8 iot_peer
= BTC_IOT_PEER_UNKNOWN
;
2151 u32 wifi_link_status
= 0;
2152 u32 num_of_wifi_link
= 0;
2155 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2156 "[BTCoex], RunCoexistMechanism()===>\n");
2158 if (btcoexist
->manual_control
) {
2159 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2160 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2164 if (btcoexist
->stop_coex_dm
) {
2165 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2166 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2170 if (coex_sta
->under_ips
) {
2171 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2172 "[BTCoex], wifi is under IPS !!!\n");
2176 if (coex_sta
->bt_whck_test
) {
2177 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2178 "[BTCoex], wifi is under IPS !!!\n");
2179 halbtc8723b1ant_action_bt_whck_test(btcoexist
);
2183 if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
||
2184 coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_SCO_BUSY
||
2185 coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
)
2186 increase_scan_dev_num
= true;
2188 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_INC_SCAN_DEV_NUM
,
2189 &increase_scan_dev_num
);
2190 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
2192 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
2194 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2196 num_of_wifi_link
= wifi_link_status
>> 16;
2198 if (num_of_wifi_link
>= 2 ||
2199 wifi_link_status
& WIFI_P2P_GO_CONNECTED
) {
2200 if (bt_link_info
->bt_link_exist
) {
2201 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 1, 1,
2203 miracast_plus_bt
= true;
2205 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0,
2207 miracast_plus_bt
= false;
2209 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_MIRACAST_PLUS_BT
,
2211 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2212 bt_ctrl_agg_buf_size
, agg_buf_size
);
2214 if ((bt_link_info
->a2dp_exist
|| wifi_busy
) &&
2215 (coex_sta
->c2h_bt_inquiry_page
))
2216 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2218 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
2223 miracast_plus_bt
= false;
2224 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_MIRACAST_PLUS_BT
,
2226 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2228 if (bt_link_info
->bt_link_exist
&& wifi_connected
) {
2229 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 1, 1, 0, 1);
2231 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_IOT_PEER
, &iot_peer
);
2233 if (iot_peer
!= BTC_IOT_PEER_CISCO
&&
2234 iot_peer
!= BTC_IOT_PEER_BROADCOM
) {
2235 bool sco_exist
= bt_link_info
->sco_exist
;
2237 halbtc8723b1ant_limited_rx(btcoexist
,
2238 NORMAL_EXEC
, sco_exist
,
2241 if (bt_link_info
->sco_exist
) {
2242 halbtc8723b1ant_limited_rx(btcoexist
,
2246 if (wifi_bw
== BTC_WIFI_BW_HT40
)
2247 halbtc8723b1ant_limited_rx(
2248 btcoexist
, NORMAL_EXEC
, false,
2251 halbtc8723b1ant_limited_rx(
2252 btcoexist
, NORMAL_EXEC
, false,
2257 halbtc8723b1ant_sw_mechanism(btcoexist
, true);
2259 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2261 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false,
2264 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
2266 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2268 if (coex_sta
->c2h_bt_inquiry_page
) {
2269 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2271 } else if (bt_hs_on
) {
2272 halbtc8723b1ant_action_hs(btcoexist
);
2276 if (!wifi_connected
) {
2277 bool scan
= false, link
= false, roam
= false;
2279 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2280 "[BTCoex], wifi is non connected-idle !!!\n");
2282 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2283 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2284 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2286 if (scan
|| link
|| roam
) {
2288 btc8723b1ant_action_wifi_not_conn_scan(
2291 btc8723b1ant_act_wifi_not_conn_asso_auth(
2294 btc8723b1ant_action_wifi_not_conn(btcoexist
);
2296 } else { /* wifi LPS/Busy */
2297 halbtc8723b1ant_action_wifi_connected(btcoexist
);
2301 /* force coex mechanism to reset */
2302 static void halbtc8723b1ant_init_coex_dm(struct btc_coexist
*btcoexist
)
2305 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
2307 coex_sta
->pop_event_cnt
= 0;
2310 static void halbtc8723b1ant_init_hw_config(struct btc_coexist
*btcoexist
,
2311 bool backup
, bool wifi_only
)
2313 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2315 u8 u8tmpa
= 0, u8tmpb
= 0;
2317 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2318 "[BTCoex], 1Ant Init HW Config!!\n");
2320 /* 0xf0[15:12] --> Chip Cut information */
2321 coex_sta
->cut_version
=
2322 (btcoexist
->btc_read_1byte(btcoexist
, 0xf1) & 0xf0) >> 4;
2323 /* enable TBTT interrupt */
2324 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x550, 0x8, 0x1);
2326 /* 0x790[5:0] = 0x5 */
2327 btcoexist
->btc_write_1byte(btcoexist
, 0x790, 0x5);
2329 /* Enable counter statistics */
2330 btcoexist
->btc_write_1byte(btcoexist
, 0x778, 0x1);
2331 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x40, 0x20, 0x1);
2333 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
2335 /* Antenna config */
2337 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_WIFI
,
2338 FORCE_EXEC
, true, false);
2340 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
,
2341 FORCE_EXEC
, true, false);
2344 halbtc8723b1ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 0);
2346 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x948);
2347 u8tmpa
= btcoexist
->btc_read_1byte(btcoexist
, 0x765);
2348 u8tmpb
= btcoexist
->btc_read_1byte(btcoexist
, 0x67);
2350 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2351 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
2352 u32tmp
, u8tmpa
, u8tmpb
);
2355 /**************************************************************
2356 * extern function start with ex_btc8723b1ant_
2357 **************************************************************/
2358 void ex_btc8723b1ant_power_on_setting(struct btc_coexist
*btcoexist
)
2360 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2361 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
2366 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2367 "xxxxxxxxxxxxxxxx Execute 8723b 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n");
2369 btcoexist
->stop_coex_dm
= true;
2371 btcoexist
->btc_write_1byte(btcoexist
, 0x67, 0x20);
2373 /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
2374 u16tmp
= btcoexist
->btc_read_2byte(btcoexist
, 0x2);
2375 btcoexist
->btc_write_2byte(btcoexist
, 0x2, u16tmp
| BIT0
| BIT1
);
2377 /* set GRAN_BT = 1 */
2378 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x18);
2379 /* set WLAN_ACT = 0 */
2380 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
2382 /* S0 or S1 setting and Local register setting(By the setting fw can get
2383 * ant number, S0/S1, ... info)
2385 * Local setting bit define
2386 * BIT0: "0" for no antenna inverse; "1" for antenna inverse
2387 * BIT1: "0" for internal switch; "1" for external switch
2388 * BIT2: "0" for one antenna; "1" for two antenna
2389 * NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and
2392 if (btcoexist
->chip_interface
== BTC_INTF_USB
) {
2393 /* fixed at S0 for USB interface */
2394 btcoexist
->btc_write_4byte(btcoexist
, 0x948, 0x0);
2396 u8tmp
|= 0x1; /* antenna inverse */
2397 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0xfe08, u8tmp
);
2399 board_info
->btdm_ant_pos
= BTC_ANTENNA_AT_AUX_PORT
;
2401 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
2402 if (board_info
->single_ant_path
== 0) {
2404 btcoexist
->btc_write_4byte(btcoexist
, 0x948, 0x280);
2405 board_info
->btdm_ant_pos
= BTC_ANTENNA_AT_MAIN_PORT
;
2407 } else if (board_info
->single_ant_path
== 1) {
2409 btcoexist
->btc_write_4byte(btcoexist
, 0x948, 0x0);
2410 u8tmp
|= 0x1; /* antenna inverse */
2411 board_info
->btdm_ant_pos
= BTC_ANTENNA_AT_AUX_PORT
;
2415 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_ANTPOSREGRISTRY_CTRL
,
2418 if (btcoexist
->chip_interface
== BTC_INTF_PCI
)
2419 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0x384,
2421 else if (btcoexist
->chip_interface
== BTC_INTF_SDIO
)
2422 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0x60,
2428 void ex_btc8723b1ant_init_hwconfig(struct btc_coexist
*btcoexist
,
2431 halbtc8723b1ant_init_hw_config(btcoexist
, true, wifi_only
);
2432 btcoexist
->stop_coex_dm
= false;
2435 void ex_btc8723b1ant_init_coex_dm(struct btc_coexist
*btcoexist
)
2437 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2439 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2440 "[BTCoex], Coex Mechanism Init!!\n");
2442 btcoexist
->stop_coex_dm
= false;
2444 halbtc8723b1ant_init_coex_dm(btcoexist
);
2446 halbtc8723b1ant_query_bt_info(btcoexist
);
2449 void ex_btc8723b1ant_display_coex_info(struct btc_coexist
*btcoexist
,
2452 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
2453 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
2454 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
2455 u8 u8tmp
[4], i
, bt_info_ext
, pstdmacase
= 0;
2458 bool roam
= false, scan
= false;
2459 bool link
= false, wifi_under_5g
= false;
2460 bool bt_hs_on
= false, wifi_busy
= false;
2461 s32 wifi_rssi
= 0, bt_hs_rssi
= 0;
2462 u32 wifi_bw
, wifi_traffic_dir
, fa_ofdm
, fa_cck
, wifi_link_status
;
2463 u8 wifi_dot11_chnl
, wifi_hs_chnl
;
2464 u32 fw_ver
= 0, bt_patch_ver
= 0;
2466 seq_puts(m
, "\n ============[BT Coexist info]============");
2468 if (btcoexist
->manual_control
) {
2469 seq_puts(m
, "\n ============[Under Manual Control]==========");
2470 seq_puts(m
, "\n ==========================================");
2472 if (btcoexist
->stop_coex_dm
) {
2473 seq_puts(m
, "\n ============[Coex is STOPPED]============");
2474 seq_puts(m
, "\n ==========================================");
2477 seq_printf(m
, "\n %-35s = %d/ %d/ %d",
2478 "Ant PG Num/ Ant Mech/ Ant Pos:",
2479 board_info
->pg_ant_num
, board_info
->btdm_ant_num
,
2480 board_info
->btdm_ant_pos
);
2482 seq_printf(m
, "\n %-35s = %s / %d",
2483 "BT stack/ hci ext ver",
2484 ((stack_info
->profile_notified
) ? "Yes" : "No"),
2485 stack_info
->hci_version
);
2487 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
, &bt_patch_ver
);
2488 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
2489 seq_printf(m
, "\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
2490 "CoexVer/ FwVer/ PatchVer",
2491 glcoex_ver_date_8723b_1ant
, glcoex_ver_8723b_1ant
,
2492 fw_ver
, bt_patch_ver
, bt_patch_ver
);
2494 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2495 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_DOT11_CHNL
,
2497 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_HS_CHNL
, &wifi_hs_chnl
);
2498 seq_printf(m
, "\n %-35s = %d / %d(%d)",
2499 "Dot11 channel / HsChnl(HsMode)",
2500 wifi_dot11_chnl
, wifi_hs_chnl
, bt_hs_on
);
2502 seq_printf(m
, "\n %-35s = %3ph ",
2503 "H2C Wifi inform bt chnl Info",
2504 coex_dm
->wifi_chnl_info
);
2506 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
2507 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_HS_RSSI
, &bt_hs_rssi
);
2508 seq_printf(m
, "\n %-35s = %d/ %d",
2509 "Wifi rssi/ HS rssi", wifi_rssi
, bt_hs_rssi
);
2511 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2512 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2513 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2514 seq_printf(m
, "\n %-35s = %d/ %d/ %d ",
2515 "Wifi link/ roam/ scan", link
, roam
, scan
);
2517 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
,
2519 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2520 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
2521 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION
,
2524 seq_printf(m
, "\n %-35s = %s / %s/ %s ",
2525 "Wifi status", (wifi_under_5g
? "5G" : "2.4G"),
2526 ((wifi_bw
== BTC_WIFI_BW_LEGACY
) ? "Legacy" :
2527 ((wifi_bw
== BTC_WIFI_BW_HT40
) ? "HT40" : "HT20")),
2528 ((!wifi_busy
) ? "idle" :
2529 ((wifi_traffic_dir
== BTC_WIFI_TRAFFIC_TX
) ?
2530 "uplink" : "downlink")));
2532 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2534 seq_printf(m
, "\n %-35s = %d/ %d/ %d/ %d/ %d",
2535 "sta/vwifi/hs/p2pGo/p2pGc",
2536 ((wifi_link_status
& WIFI_STA_CONNECTED
) ? 1 : 0),
2537 ((wifi_link_status
& WIFI_AP_CONNECTED
) ? 1 : 0),
2538 ((wifi_link_status
& WIFI_HS_CONNECTED
) ? 1 : 0),
2539 ((wifi_link_status
& WIFI_P2P_GO_CONNECTED
) ? 1 : 0),
2540 ((wifi_link_status
& WIFI_P2P_GC_CONNECTED
) ? 1 : 0));
2542 seq_printf(m
, "\n %-35s = [%s/ %d/ %d] ",
2543 "BT [status/ rssi/ retryCnt]",
2544 ((coex_sta
->bt_disabled
) ? ("disabled") :
2545 ((coex_sta
->c2h_bt_inquiry_page
) ? ("inquiry/page scan") :
2546 ((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE
==
2547 coex_dm
->bt_status
) ?
2548 "non-connected idle" :
2549 ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
==
2550 coex_dm
->bt_status
) ?
2551 "connected-idle" : "busy")))),
2552 coex_sta
->bt_rssi
, coex_sta
->bt_retry_cnt
);
2554 seq_printf(m
, "\n %-35s = %d / %d / %d / %d",
2555 "SCO/HID/PAN/A2DP", bt_link_info
->sco_exist
,
2556 bt_link_info
->hid_exist
, bt_link_info
->pan_exist
,
2557 bt_link_info
->a2dp_exist
);
2558 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_BT_LINK_INFO
, m
);
2560 bt_info_ext
= coex_sta
->bt_info_ext
;
2561 seq_printf(m
, "\n %-35s = %s",
2562 "BT Info A2DP rate",
2563 (bt_info_ext
& BIT0
) ? "Basic rate" : "EDR rate");
2565 for (i
= 0; i
< BT_INFO_SRC_8723B_1ANT_MAX
; i
++) {
2566 if (coex_sta
->bt_info_c2h_cnt
[i
]) {
2567 seq_printf(m
, "\n %-35s = %7ph(%d)",
2568 glbt_info_src_8723b_1ant
[i
],
2569 coex_sta
->bt_info_c2h
[i
],
2570 coex_sta
->bt_info_c2h_cnt
[i
]);
2573 seq_printf(m
, "\n %-35s = %s/%s, (0x%x/0x%x)",
2574 "PS state, IPS/LPS, (lps/rpwm)",
2575 ((coex_sta
->under_ips
? "IPS ON" : "IPS OFF")),
2576 ((coex_sta
->under_lps
? "LPS ON" : "LPS OFF")),
2577 btcoexist
->bt_info
.lps_val
,
2578 btcoexist
->bt_info
.rpwm_val
);
2579 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_FW_PWR_MODE_CMD
, m
);
2581 if (!btcoexist
->manual_control
) {
2583 seq_printf(m
, "\n %-35s",
2584 "============[Sw mechanism]============");
2586 seq_printf(m
, "\n %-35s = %d/",
2587 "SM[LowPenaltyRA]", coex_dm
->cur_low_penalty_ra
);
2589 seq_printf(m
, "\n %-35s = %s/ %s/ %d ",
2590 "DelBA/ BtCtrlAgg/ AggSize",
2591 (btcoexist
->bt_info
.reject_agg_pkt
? "Yes" : "No"),
2592 (btcoexist
->bt_info
.bt_ctrl_buf_size
? "Yes" : "No"),
2593 btcoexist
->bt_info
.agg_buf_size
);
2595 seq_printf(m
, "\n %-35s = 0x%x ",
2596 "Rate Mask", btcoexist
->bt_info
.ra_mask
);
2599 seq_printf(m
, "\n %-35s",
2600 "============[Fw mechanism]============");
2602 pstdmacase
= coex_dm
->cur_ps_tdma
;
2603 seq_printf(m
, "\n %-35s = %5ph case-%d (auto:%d)",
2604 "PS TDMA", coex_dm
->ps_tdma_para
,
2605 pstdmacase
, coex_dm
->auto_tdma_adjust
);
2607 seq_printf(m
, "\n %-35s = %d ",
2608 "IgnWlanAct", coex_dm
->cur_ignore_wlan_act
);
2610 seq_printf(m
, "\n %-35s = 0x%x ",
2611 "Latest error condition(should be 0)",
2612 coex_dm
->error_condition
);
2615 seq_printf(m
, "\n %-35s = %d",
2616 "Coex Table Type", coex_sta
->coex_table_type
);
2619 seq_printf(m
, "\n %-35s",
2620 "============[Hw setting]============");
2622 seq_printf(m
, "\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2623 "backup ARFR1/ARFR2/RL/AMaxTime", coex_dm
->backup_arfr_cnt1
,
2624 coex_dm
->backup_arfr_cnt2
, coex_dm
->backup_retry_limit
,
2625 coex_dm
->backup_ampdu_max_time
);
2627 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x430);
2628 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x434);
2629 u16tmp
[0] = btcoexist
->btc_read_2byte(btcoexist
, 0x42a);
2630 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x456);
2631 seq_printf(m
, "\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2632 "0x430/0x434/0x42a/0x456",
2633 u32tmp
[0], u32tmp
[1], u16tmp
[0], u8tmp
[0]);
2635 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x778);
2636 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x6cc);
2637 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x880);
2638 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
2639 "0x778/0x6cc/0x880[29:25]", u8tmp
[0], u32tmp
[0],
2640 (u32tmp
[1] & 0x3e000000) >> 25);
2642 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x948);
2643 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x67);
2644 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x765);
2645 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
2646 "0x948/ 0x67[5] / 0x765",
2647 u32tmp
[0], ((u8tmp
[0] & 0x20) >> 5), u8tmp
[1]);
2649 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x92c);
2650 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x930);
2651 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x944);
2652 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
2653 "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
2654 u32tmp
[0] & 0x3, u32tmp
[1] & 0xff, u32tmp
[2] & 0x3);
2656 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x39);
2657 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x40);
2658 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
2659 u8tmp
[2] = btcoexist
->btc_read_1byte(btcoexist
, 0x64);
2660 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
2661 "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
2662 ((u8tmp
[0] & 0x8) >> 3), u8tmp
[1],
2663 ((u32tmp
[0] & 0x01800000) >> 23), u8tmp
[2] & 0x1);
2665 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x550);
2666 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x522);
2667 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x",
2668 "0x550(bcn ctrl)/0x522", u32tmp
[0], u8tmp
[0]);
2670 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xc50);
2671 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x49c);
2672 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x",
2673 "0xc50(dig)/0x49c(null-drop)", u32tmp
[0] & 0xff, u8tmp
[0]);
2675 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xda0);
2676 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0xda4);
2677 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0xda8);
2678 u32tmp
[3] = btcoexist
->btc_read_4byte(btcoexist
, 0xcf0);
2680 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5b);
2681 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5c);
2683 fa_ofdm
= ((u32tmp
[0] & 0xffff0000) >> 16) +
2684 ((u32tmp
[1] & 0xffff0000) >> 16) +
2685 (u32tmp
[1] & 0xffff) +
2686 (u32tmp
[2] & 0xffff) +
2687 ((u32tmp
[3] & 0xffff0000) >> 16) +
2688 (u32tmp
[3] & 0xffff);
2689 fa_cck
= (u8tmp
[0] << 8) + u8tmp
[1];
2691 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
2692 "OFDM-CCA/OFDM-FA/CCK-FA",
2693 u32tmp
[0] & 0xffff, fa_ofdm
, fa_cck
);
2695 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c0);
2696 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c4);
2697 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c8);
2698 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
2699 "0x6c0/0x6c4/0x6c8(coexTable)",
2700 u32tmp
[0], u32tmp
[1], u32tmp
[2]);
2702 seq_printf(m
, "\n %-35s = %d/ %d",
2703 "0x770(high-pri rx/tx)", coex_sta
->high_priority_rx
,
2704 coex_sta
->high_priority_tx
);
2705 seq_printf(m
, "\n %-35s = %d/ %d",
2706 "0x774(low-pri rx/tx)", coex_sta
->low_priority_rx
,
2707 coex_sta
->low_priority_tx
);
2708 if (btcoexist
->auto_report_1ant
)
2709 halbtc8723b1ant_monitor_bt_ctr(btcoexist
);
2710 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_COEX_STATISTICS
, m
);
2713 void ex_btc8723b1ant_ips_notify(struct btc_coexist
*btcoexist
, u8 type
)
2715 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2717 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
)
2720 if (BTC_IPS_ENTER
== type
) {
2721 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2722 "[BTCoex], IPS ENTER notify\n");
2723 coex_sta
->under_ips
= true;
2725 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
,
2726 FORCE_EXEC
, false, true);
2727 /* set PTA control */
2728 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
2729 halbtc8723b1ant_coex_table_with_type(btcoexist
,
2731 } else if (BTC_IPS_LEAVE
== type
) {
2732 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2733 "[BTCoex], IPS LEAVE notify\n");
2734 coex_sta
->under_ips
= false;
2736 halbtc8723b1ant_init_hw_config(btcoexist
, false, false);
2737 halbtc8723b1ant_init_coex_dm(btcoexist
);
2738 halbtc8723b1ant_query_bt_info(btcoexist
);
2742 void ex_btc8723b1ant_lps_notify(struct btc_coexist
*btcoexist
, u8 type
)
2744 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2746 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
)
2749 if (BTC_LPS_ENABLE
== type
) {
2750 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2751 "[BTCoex], LPS ENABLE notify\n");
2752 coex_sta
->under_lps
= true;
2753 } else if (BTC_LPS_DISABLE
== type
) {
2754 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2755 "[BTCoex], LPS DISABLE notify\n");
2756 coex_sta
->under_lps
= false;
2760 void ex_btc8723b1ant_scan_notify(struct btc_coexist
*btcoexist
, u8 type
)
2762 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2763 bool wifi_connected
= false, bt_hs_on
= false;
2766 u32 wifi_link_status
= 0;
2767 u32 num_of_wifi_link
= 0;
2768 bool bt_ctrl_agg_buf_size
= false;
2769 u8 agg_buf_size
= 5;
2771 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
)
2774 if (type
== BTC_SCAN_START
) {
2775 coex_sta
->wifi_is_high_pri_task
= true;
2776 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2777 "[BTCoex], SCAN START notify\n");
2778 /* Force antenna setup for no scan result issue */
2779 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
2780 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
2781 FORCE_EXEC
, false, false);
2782 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x948);
2783 u8tmpa
= btcoexist
->btc_read_1byte(btcoexist
, 0x765);
2784 u8tmpb
= btcoexist
->btc_read_1byte(btcoexist
, 0x67);
2786 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2787 "[BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
2788 u32tmp
, u8tmpa
, u8tmpb
);
2790 coex_sta
->wifi_is_high_pri_task
= false;
2791 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2792 "[BTCoex], SCAN FINISH notify\n");
2794 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_AP_NUM
,
2795 &coex_sta
->scan_ap_num
);
2798 if (coex_sta
->bt_disabled
)
2801 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2802 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
2805 halbtc8723b1ant_query_bt_info(btcoexist
);
2807 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2809 num_of_wifi_link
= wifi_link_status
>> 16;
2810 if (num_of_wifi_link
>= 2) {
2811 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2812 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2813 bt_ctrl_agg_buf_size
, agg_buf_size
);
2814 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
2818 if (coex_sta
->c2h_bt_inquiry_page
) {
2819 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2821 } else if (bt_hs_on
) {
2822 halbtc8723b1ant_action_hs(btcoexist
);
2826 if (BTC_SCAN_START
== type
) {
2827 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2828 "[BTCoex], SCAN START notify\n");
2829 if (!wifi_connected
)
2830 /* non-connected scan */
2831 btc8723b1ant_action_wifi_not_conn_scan(btcoexist
);
2833 /* wifi is connected */
2834 btc8723b1ant_action_wifi_conn_scan(btcoexist
);
2835 } else if (BTC_SCAN_FINISH
== type
) {
2836 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2837 "[BTCoex], SCAN FINISH notify\n");
2838 if (!wifi_connected
)
2839 /* non-connected scan */
2840 btc8723b1ant_action_wifi_not_conn(btcoexist
);
2842 halbtc8723b1ant_action_wifi_connected(btcoexist
);
2846 void ex_btc8723b1ant_connect_notify(struct btc_coexist
*btcoexist
, u8 type
)
2848 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2849 bool wifi_connected
= false, bt_hs_on
= false;
2850 u32 wifi_link_status
= 0;
2851 u32 num_of_wifi_link
= 0;
2852 bool bt_ctrl_agg_buf_size
= false, under_4way
= false;
2853 u8 agg_buf_size
= 5;
2855 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
2858 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2859 coex_sta
->bt_disabled
)
2862 if (type
== BTC_ASSOCIATE_START
) {
2863 coex_sta
->wifi_is_high_pri_task
= true;
2865 /* Force antenna setup for no scan result issue */
2866 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
2867 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
2868 FORCE_EXEC
, false, false);
2869 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2870 "[BTCoex], CONNECT START notify\n");
2871 coex_dm
->arp_cnt
= 0;
2873 coex_sta
->wifi_is_high_pri_task
= false;
2874 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2875 "[BTCoex], CONNECT FINISH notify\n");
2878 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2880 num_of_wifi_link
= wifi_link_status
>>16;
2881 if (num_of_wifi_link
>= 2) {
2882 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2883 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2884 bt_ctrl_agg_buf_size
, agg_buf_size
);
2885 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
2889 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2890 if (coex_sta
->c2h_bt_inquiry_page
) {
2891 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2893 } else if (bt_hs_on
) {
2894 halbtc8723b1ant_action_hs(btcoexist
);
2898 if (BTC_ASSOCIATE_START
== type
) {
2899 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2900 "[BTCoex], CONNECT START notify\n");
2901 btc8723b1ant_act_wifi_not_conn_asso_auth(btcoexist
);
2902 } else if (BTC_ASSOCIATE_FINISH
== type
) {
2903 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2904 "[BTCoex], CONNECT FINISH notify\n");
2906 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
2908 if (!wifi_connected
)
2909 /* non-connected scan */
2910 btc8723b1ant_action_wifi_not_conn(btcoexist
);
2912 halbtc8723b1ant_action_wifi_connected(btcoexist
);
2916 void ex_btc8723b1ant_media_status_notify(struct btc_coexist
*btcoexist
,
2919 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2920 u8 h2c_parameter
[3] = {0};
2922 u8 wifi_central_chnl
;
2923 bool wifi_under_b_mode
= false;
2925 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2926 coex_sta
->bt_disabled
)
2929 if (type
== BTC_MEDIA_CONNECT
) {
2930 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2931 "[BTCoex], MEDIA connect notify\n");
2932 /* Force antenna setup for no scan result issue */
2933 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
2934 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
2935 FORCE_EXEC
, false, false);
2936 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_B_MODE
,
2937 &wifi_under_b_mode
);
2939 /* Set CCK Tx/Rx high Pri except 11b mode */
2940 if (wifi_under_b_mode
) {
2941 btcoexist
->btc_write_1byte(btcoexist
, 0x6cd,
2943 btcoexist
->btc_write_1byte(btcoexist
, 0x6cf,
2946 btcoexist
->btc_write_1byte(btcoexist
, 0x6cd,
2948 btcoexist
->btc_write_1byte(btcoexist
, 0x6cf,
2952 coex_dm
->backup_arfr_cnt1
=
2953 btcoexist
->btc_read_4byte(btcoexist
, 0x430);
2954 coex_dm
->backup_arfr_cnt2
=
2955 btcoexist
->btc_read_4byte(btcoexist
, 0x434);
2956 coex_dm
->backup_retry_limit
=
2957 btcoexist
->btc_read_2byte(btcoexist
, 0x42a);
2958 coex_dm
->backup_ampdu_max_time
=
2959 btcoexist
->btc_read_1byte(btcoexist
, 0x456);
2961 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2962 "[BTCoex], MEDIA disconnect notify\n");
2963 coex_dm
->arp_cnt
= 0;
2965 btcoexist
->btc_write_1byte(btcoexist
, 0x6cd, 0x0); /* CCK Tx */
2966 btcoexist
->btc_write_1byte(btcoexist
, 0x6cf, 0x0); /* CCK Rx */
2968 coex_sta
->cck_ever_lock
= false;
2971 /* only 2.4G we need to inform bt the chnl mask */
2972 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_CENTRAL_CHNL
,
2973 &wifi_central_chnl
);
2975 if (type
== BTC_MEDIA_CONNECT
&& wifi_central_chnl
<= 14) {
2976 h2c_parameter
[0] = 0x0;
2977 h2c_parameter
[1] = wifi_central_chnl
;
2978 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2979 if (BTC_WIFI_BW_HT40
== wifi_bw
)
2980 h2c_parameter
[2] = 0x30;
2982 h2c_parameter
[2] = 0x20;
2985 coex_dm
->wifi_chnl_info
[0] = h2c_parameter
[0];
2986 coex_dm
->wifi_chnl_info
[1] = h2c_parameter
[1];
2987 coex_dm
->wifi_chnl_info
[2] = h2c_parameter
[2];
2989 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2990 "[BTCoex], FW write 0x66 = 0x%x\n",
2991 h2c_parameter
[0] << 16 | h2c_parameter
[1] << 8 |
2994 btcoexist
->btc_fill_h2c(btcoexist
, 0x66, 3, h2c_parameter
);
2997 void ex_btc8723b1ant_special_packet_notify(struct btc_coexist
*btcoexist
,
3000 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3001 bool bt_hs_on
= false;
3002 u32 wifi_link_status
= 0;
3003 u32 num_of_wifi_link
= 0;
3004 bool bt_ctrl_agg_buf_size
= false, under_4way
= false;
3005 u8 agg_buf_size
= 5;
3007 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
3010 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
3011 coex_sta
->bt_disabled
)
3014 if (type
== BTC_PACKET_DHCP
|| type
== BTC_PACKET_EAPOL
||
3015 type
== BTC_PACKET_ARP
) {
3016 if (type
== BTC_PACKET_ARP
) {
3017 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3018 "[BTCoex], special Packet ARP notify\n");
3021 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3022 "[BTCoex], ARP Packet Count = %d\n",
3025 if ((coex_dm
->arp_cnt
>= 10) && (!under_4way
))
3026 /* if APR PKT > 10 after connect, do not go to
3027 * ActionWifiConnectedSpecificPacket(btcoexist)
3029 coex_sta
->wifi_is_high_pri_task
= false;
3031 coex_sta
->wifi_is_high_pri_task
= true;
3033 coex_sta
->wifi_is_high_pri_task
= true;
3034 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3035 "[BTCoex], special Packet DHCP or EAPOL notify\n");
3038 coex_sta
->wifi_is_high_pri_task
= false;
3039 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3040 "[BTCoex], special Packet [Type = %d] notify\n",
3044 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
3046 num_of_wifi_link
= wifi_link_status
>> 16;
3047 if (num_of_wifi_link
>= 2) {
3048 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
3049 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
3050 bt_ctrl_agg_buf_size
, agg_buf_size
);
3051 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
3055 coex_sta
->special_pkt_period_cnt
= 0;
3057 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
3058 if (coex_sta
->c2h_bt_inquiry_page
) {
3059 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
3061 } else if (bt_hs_on
) {
3062 halbtc8723b1ant_action_hs(btcoexist
);
3066 if (BTC_PACKET_DHCP
== type
||
3067 BTC_PACKET_EAPOL
== type
) {
3068 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3069 "[BTCoex], special Packet(%d) notify\n", type
);
3070 halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist
);
3074 void ex_btc8723b1ant_bt_info_notify(struct btc_coexist
*btcoexist
,
3075 u8
*tmp_buf
, u8 length
)
3077 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3079 u8 i
, rsp_source
= 0;
3080 bool wifi_connected
= false;
3081 bool bt_busy
= false;
3083 coex_sta
->c2h_bt_info_req_sent
= false;
3085 rsp_source
= tmp_buf
[0] & 0xf;
3086 if (rsp_source
>= BT_INFO_SRC_8723B_1ANT_MAX
)
3087 rsp_source
= BT_INFO_SRC_8723B_1ANT_WIFI_FW
;
3088 coex_sta
->bt_info_c2h_cnt
[rsp_source
]++;
3090 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3091 "[BTCoex], Bt info[%d], length=%d, hex data = [",
3092 rsp_source
, length
);
3093 for (i
= 0; i
< length
; i
++) {
3094 coex_sta
->bt_info_c2h
[rsp_source
][i
] = tmp_buf
[i
];
3096 bt_info
= tmp_buf
[i
];
3097 if (i
== length
- 1)
3098 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3099 "0x%02x]\n", tmp_buf
[i
]);
3101 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3102 "0x%02x, ", tmp_buf
[i
]);
3105 /* if 0xff, it means BT is under WHCK test */
3106 if (bt_info
== 0xff)
3107 coex_sta
->bt_whck_test
= true;
3109 coex_sta
->bt_whck_test
= false;
3111 if (rsp_source
!= BT_INFO_SRC_8723B_1ANT_WIFI_FW
) {
3112 coex_sta
->bt_retry_cnt
= /* [3:0] */
3113 coex_sta
->bt_info_c2h
[rsp_source
][2] & 0xf;
3115 if (coex_sta
->bt_retry_cnt
>= 1)
3116 coex_sta
->pop_event_cnt
++;
3118 if (coex_sta
->bt_info_c2h
[rsp_source
][2] & 0x20)
3119 coex_sta
->c2h_bt_remote_name_req
= true;
3121 coex_sta
->c2h_bt_remote_name_req
= false;
3124 coex_sta
->bt_info_c2h
[rsp_source
][3] * 2 - 90;
3126 coex_sta
->bt_info_ext
=
3127 coex_sta
->bt_info_c2h
[rsp_source
][4];
3129 if (coex_sta
->bt_info_c2h
[rsp_source
][1] == 0x49) {
3130 coex_sta
->a2dp_bit_pool
=
3131 coex_sta
->bt_info_c2h
[rsp_source
][6];
3133 coex_sta
->a2dp_bit_pool
= 0;
3136 coex_sta
->bt_tx_rx_mask
=
3137 (coex_sta
->bt_info_c2h
[rsp_source
][2] & 0x40);
3138 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TX_RX_MASK
,
3139 &coex_sta
->bt_tx_rx_mask
);
3141 if (!coex_sta
->bt_tx_rx_mask
) {
3142 /* BT into is responded by BT FW and BT RF REG
3143 * 0x3C != 0x15 => Need to switch BT TRx Mask
3145 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3146 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
3147 btcoexist
->btc_set_bt_reg(btcoexist
, BTC_BT_REG_RF
,
3150 /* BT TRx Mask lock 0x2c[0], 0x30[0] = 0 */
3151 btcoexist
->btc_set_bt_reg(btcoexist
, BTC_BT_REG_RF
,
3153 btcoexist
->btc_set_bt_reg(btcoexist
, BTC_BT_REG_RF
,
3157 /* Here we need to resend some wifi info to BT
3158 * because bt is reset and loss of the info.
3160 if (coex_sta
->bt_info_ext
& BIT1
) {
3161 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3162 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
3163 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
3166 ex_btc8723b1ant_media_status_notify(btcoexist
,
3169 ex_btc8723b1ant_media_status_notify(btcoexist
,
3170 BTC_MEDIA_DISCONNECT
);
3173 if (coex_sta
->bt_info_ext
& BIT3
) {
3174 if (!btcoexist
->manual_control
&&
3175 !btcoexist
->stop_coex_dm
) {
3176 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3177 "[BTCoex], BT ext info bit3 check, set BT NOT ignore Wlan active!!\n");
3178 halbtc8723b1ant_ignore_wlan_act(btcoexist
,
3183 /* BT already NOT ignore Wlan active, do nothing here.*/
3185 if (!btcoexist
->auto_report_1ant
) {
3186 if (coex_sta
->bt_info_ext
& BIT4
) {
3187 /* BT auto report already enabled, do nothing */
3189 halbtc8723b1ant_bt_auto_report(btcoexist
,
3196 /* check BIT2 first ==> check if bt is under inquiry or page scan */
3197 if (bt_info
& BT_INFO_8723B_1ANT_B_INQ_PAGE
)
3198 coex_sta
->c2h_bt_inquiry_page
= true;
3200 coex_sta
->c2h_bt_inquiry_page
= false;
3202 coex_sta
->num_of_profile
= 0;
3204 /* set link exist status */
3205 if (!(bt_info
& BT_INFO_8723B_1ANT_B_CONNECTION
)) {
3206 coex_sta
->bt_link_exist
= false;
3207 coex_sta
->pan_exist
= false;
3208 coex_sta
->a2dp_exist
= false;
3209 coex_sta
->hid_exist
= false;
3210 coex_sta
->sco_exist
= false;
3212 coex_sta
->bt_hi_pri_link_exist
= false;
3214 /* connection exists */
3215 coex_sta
->bt_link_exist
= true;
3216 if (bt_info
& BT_INFO_8723B_1ANT_B_FTP
) {
3217 coex_sta
->pan_exist
= true;
3218 coex_sta
->num_of_profile
++;
3220 coex_sta
->pan_exist
= false;
3222 if (bt_info
& BT_INFO_8723B_1ANT_B_A2DP
) {
3223 coex_sta
->a2dp_exist
= true;
3224 coex_sta
->num_of_profile
++;
3226 coex_sta
->a2dp_exist
= false;
3228 if (bt_info
& BT_INFO_8723B_1ANT_B_HID
) {
3229 coex_sta
->hid_exist
= true;
3230 coex_sta
->num_of_profile
++;
3232 coex_sta
->hid_exist
= false;
3234 if (bt_info
& BT_INFO_8723B_1ANT_B_SCO_ESCO
) {
3235 coex_sta
->sco_exist
= true;
3236 coex_sta
->num_of_profile
++;
3238 coex_sta
->sco_exist
= false;
3241 if ((!coex_sta
->hid_exist
) &&
3242 (!coex_sta
->c2h_bt_inquiry_page
) &&
3243 (!coex_sta
->sco_exist
)) {
3244 if (coex_sta
->high_priority_tx
+
3245 coex_sta
->high_priority_rx
>=
3247 coex_sta
->hid_exist
= true;
3248 coex_sta
->wrong_profile_notification
++;
3249 coex_sta
->num_of_profile
++;
3250 bt_info
= bt_info
| 0x28;
3254 /* Add Hi-Pri Tx/Rx counter to avoid false detection */
3255 if (((coex_sta
->hid_exist
) || (coex_sta
->sco_exist
)) &&
3256 (coex_sta
->high_priority_tx
+ coex_sta
->high_priority_rx
>=
3258 (!coex_sta
->c2h_bt_inquiry_page
))
3259 coex_sta
->bt_hi_pri_link_exist
= true;
3261 if ((bt_info
& BT_INFO_8723B_1ANT_B_ACL_BUSY
) &&
3262 (coex_sta
->num_of_profile
== 0)) {
3263 if (coex_sta
->low_priority_tx
+
3264 coex_sta
->low_priority_rx
>=
3266 coex_sta
->pan_exist
= true;
3267 coex_sta
->num_of_profile
++;
3268 coex_sta
->wrong_profile_notification
++;
3269 bt_info
= bt_info
| 0x88;
3274 halbtc8723b1ant_update_bt_link_info(btcoexist
);
3276 /* mask profile bit for connect-ilde identification
3277 * ( for CSR case: A2DP idle --> 0x41)
3279 bt_info
= bt_info
& 0x1f;
3281 if (!(bt_info
& BT_INFO_8723B_1ANT_B_CONNECTION
)) {
3282 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE
;
3283 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3284 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!\n");
3285 /* connection exists but no busy */
3286 } else if (bt_info
== BT_INFO_8723B_1ANT_B_CONNECTION
) {
3287 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
;
3288 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3289 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
3290 } else if ((bt_info
& BT_INFO_8723B_1ANT_B_SCO_ESCO
) ||
3291 (bt_info
& BT_INFO_8723B_1ANT_B_SCO_BUSY
)) {
3292 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_SCO_BUSY
;
3293 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3294 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
3295 } else if (bt_info
& BT_INFO_8723B_1ANT_B_ACL_BUSY
) {
3296 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY
!= coex_dm
->bt_status
)
3297 coex_dm
->auto_tdma_adjust
= false;
3299 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_ACL_BUSY
;
3300 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3301 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
3303 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_MAX
;
3304 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3305 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!\n");
3308 if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) ||
3309 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY
== coex_dm
->bt_status
) ||
3310 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
== coex_dm
->bt_status
))
3314 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TRAFFIC_BUSY
, &bt_busy
);
3316 halbtc8723b1ant_run_coexist_mechanism(btcoexist
);
3319 void ex_btc8723b1ant_rf_status_notify(struct btc_coexist
*btcoexist
, u8 type
)
3321 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3323 u8 u8tmpa
, u8tmpb
, u8tmpc
;
3325 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3326 "[BTCoex], RF Status notify\n");
3328 if (type
== BTC_RF_ON
) {
3329 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3330 "[BTCoex], RF is turned ON!!\n");
3331 btcoexist
->stop_coex_dm
= false;
3332 } else if (type
== BTC_RF_OFF
) {
3333 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3334 "[BTCoex], RF is turned OFF!!\n");
3336 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3338 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 0);
3339 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
,
3340 FORCE_EXEC
, false, true);
3342 halbtc8723b1ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
3343 btcoexist
->stop_coex_dm
= true;
3345 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x948);
3346 u8tmpa
= btcoexist
->btc_read_1byte(btcoexist
, 0x765);
3347 u8tmpb
= btcoexist
->btc_read_1byte(btcoexist
, 0x67);
3348 u8tmpc
= btcoexist
->btc_read_1byte(btcoexist
, 0x76e);
3350 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3351 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x, 0x76e=0x%x\n",
3352 u32tmp
, u8tmpa
, u8tmpb
, u8tmpc
);
3356 void ex_btc8723b1ant_halt_notify(struct btc_coexist
*btcoexist
)
3358 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3360 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
, "[BTCoex], Halt notify\n");
3362 btcoexist
->stop_coex_dm
= true;
3364 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
, FORCE_EXEC
,
3367 halbtc8723b1ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
3369 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3371 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 0);
3373 ex_btc8723b1ant_media_status_notify(btcoexist
, BTC_MEDIA_DISCONNECT
);
3375 btcoexist
->stop_coex_dm
= true;
3378 void ex_btc8723b1ant_pnp_notify(struct btc_coexist
*btcoexist
, u8 pnp_state
)
3380 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3382 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
, "[BTCoex], Pnp notify\n");
3384 if (BTC_WIFI_PNP_SLEEP
== pnp_state
) {
3385 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3386 "[BTCoex], Pnp notify to SLEEP\n");
3387 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
,
3388 FORCE_EXEC
, false, true);
3389 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3391 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
3392 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
3394 /* Driver do not leave IPS/LPS when driver is going to sleep, so
3395 * BTCoexistence think wifi is still under IPS/LPS
3397 * BT should clear UnderIPS/UnderLPS state to avoid mismatch
3398 * state after wakeup.
3400 coex_sta
->under_ips
= false;
3401 coex_sta
->under_lps
= false;
3402 btcoexist
->stop_coex_dm
= true;
3403 } else if (BTC_WIFI_PNP_WAKE_UP
== pnp_state
) {
3404 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3405 "[BTCoex], Pnp notify to WAKE UP\n");
3406 btcoexist
->stop_coex_dm
= false;
3407 halbtc8723b1ant_init_hw_config(btcoexist
, false, false);
3408 halbtc8723b1ant_init_coex_dm(btcoexist
);
3409 halbtc8723b1ant_query_bt_info(btcoexist
);
3413 void ex_btc8723b1ant_coex_dm_reset(struct btc_coexist
*btcoexist
)
3415 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3417 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3418 "[BTCoex], *****************Coex DM Reset****************\n");
3420 halbtc8723b1ant_init_hw_config(btcoexist
, false, false);
3421 halbtc8723b1ant_init_coex_dm(btcoexist
);
3424 void ex_btc8723b1ant_periodical(struct btc_coexist
*btcoexist
)
3426 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3427 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
3429 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3430 "[BTCoex], ==========================Periodical===========================\n");
3432 if (!btcoexist
->auto_report_1ant
) {
3433 halbtc8723b1ant_query_bt_info(btcoexist
);
3434 halbtc8723b1ant_monitor_bt_enable_disable(btcoexist
);
3436 halbtc8723b1ant_monitor_bt_ctr(btcoexist
);
3437 halbtc8723b1ant_monitor_wifi_ctr(btcoexist
);
3439 if ((coex_sta
->high_priority_tx
+ coex_sta
->high_priority_rx
< 50) &&
3440 bt_link_info
->hid_exist
)
3441 bt_link_info
->hid_exist
= false;
3443 if (btc8723b1ant_is_wifi_status_changed(btcoexist
) ||
3444 coex_dm
->auto_tdma_adjust
) {
3445 halbtc8723b1ant_run_coexist_mechanism(btcoexist
);
3447 coex_sta
->special_pkt_period_cnt
++;