1 /******************************************************************************
3 * Copyright(c) 2012 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
26 /***************************************************************
29 * This file is for RTL8723B Co-exist mechanism
32 * 2012/11/15 Cosa first check in.
34 ***************************************************************/
36 /***************************************************************
38 ***************************************************************/
39 #include "halbt_precomp.h"
40 /***************************************************************
41 * Global variables, these are static variables
42 ***************************************************************/
43 static struct coex_dm_8723b_1ant glcoex_dm_8723b_1ant
;
44 static struct coex_dm_8723b_1ant
*coex_dm
= &glcoex_dm_8723b_1ant
;
45 static struct coex_sta_8723b_1ant glcoex_sta_8723b_1ant
;
46 static struct coex_sta_8723b_1ant
*coex_sta
= &glcoex_sta_8723b_1ant
;
48 static const char *const glbt_info_src_8723b_1ant
[] = {
51 "BT Info[bt auto report]",
54 static u32 glcoex_ver_date_8723b_1ant
= 20130918;
55 static u32 glcoex_ver_8723b_1ant
= 0x47;
57 /***************************************************************
58 * local function proto type if needed
59 ***************************************************************/
60 /***************************************************************
61 * local function start with halbtc8723b1ant_
62 ***************************************************************/
64 static void halbtc8723b1ant_updatera_mask(struct btc_coexist
*btcoexist
,
65 bool force_exec
, u32 dis_rate_mask
)
67 coex_dm
->curra_mask
= dis_rate_mask
;
69 if (force_exec
|| (coex_dm
->prera_mask
!= coex_dm
->curra_mask
))
70 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_UPDATE_RAMASK
,
71 &coex_dm
->curra_mask
);
73 coex_dm
->prera_mask
= coex_dm
->curra_mask
;
76 static void btc8723b1ant_auto_rate_fb_retry(struct btc_coexist
*btcoexist
,
77 bool force_exec
, u8 type
)
79 bool wifi_under_bmode
= false;
81 coex_dm
->cur_arfr_type
= type
;
83 if (force_exec
|| (coex_dm
->pre_arfr_type
!= coex_dm
->cur_arfr_type
)) {
84 switch (coex_dm
->cur_arfr_type
) {
85 case 0: /* normal mode */
86 btcoexist
->btc_write_4byte(btcoexist
, 0x430,
87 coex_dm
->backup_arfr_cnt1
);
88 btcoexist
->btc_write_4byte(btcoexist
, 0x434,
89 coex_dm
->backup_arfr_cnt2
);
92 btcoexist
->btc_get(btcoexist
,
93 BTC_GET_BL_WIFI_UNDER_B_MODE
,
95 if (wifi_under_bmode
) {
96 btcoexist
->btc_write_4byte(btcoexist
,
98 btcoexist
->btc_write_4byte(btcoexist
,
101 btcoexist
->btc_write_4byte(btcoexist
,
103 btcoexist
->btc_write_4byte(btcoexist
,
112 coex_dm
->pre_arfr_type
= coex_dm
->cur_arfr_type
;
115 static void halbtc8723b1ant_retry_limit(struct btc_coexist
*btcoexist
,
116 bool force_exec
, u8 type
)
118 coex_dm
->cur_retry_limit_type
= type
;
120 if (force_exec
|| (coex_dm
->pre_retry_limit_type
!=
121 coex_dm
->cur_retry_limit_type
)) {
122 switch (coex_dm
->cur_retry_limit_type
) {
123 case 0: /* normal mode */
124 btcoexist
->btc_write_2byte(btcoexist
, 0x42a,
125 coex_dm
->backup_retry_limit
);
127 case 1: /* retry limit = 8 */
128 btcoexist
->btc_write_2byte(btcoexist
, 0x42a, 0x0808);
135 coex_dm
->pre_retry_limit_type
= coex_dm
->cur_retry_limit_type
;
138 static void halbtc8723b1ant_ampdu_maxtime(struct btc_coexist
*btcoexist
,
139 bool force_exec
, u8 type
)
141 coex_dm
->cur_ampdu_time_type
= type
;
143 if (force_exec
|| (coex_dm
->pre_ampdu_time_type
!=
144 coex_dm
->cur_ampdu_time_type
)) {
145 switch (coex_dm
->cur_ampdu_time_type
) {
146 case 0: /* normal mode */
147 btcoexist
->btc_write_1byte(btcoexist
, 0x456,
148 coex_dm
->backup_ampdu_max_time
);
150 case 1: /* AMPDU timw = 0x38 * 32us */
151 btcoexist
->btc_write_1byte(btcoexist
, 0x456, 0x38);
158 coex_dm
->pre_ampdu_time_type
= coex_dm
->cur_ampdu_time_type
;
161 static void halbtc8723b1ant_limited_tx(struct btc_coexist
*btcoexist
,
162 bool force_exec
, u8 ra_masktype
,
163 u8 arfr_type
, u8 retry_limit_type
,
166 switch (ra_masktype
) {
167 case 0: /* normal mode */
168 halbtc8723b1ant_updatera_mask(btcoexist
, force_exec
, 0x0);
170 case 1: /* disable cck 1/2 */
171 halbtc8723b1ant_updatera_mask(btcoexist
, force_exec
,
174 /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
176 halbtc8723b1ant_updatera_mask(btcoexist
, force_exec
,
183 btc8723b1ant_auto_rate_fb_retry(btcoexist
, force_exec
, arfr_type
);
184 halbtc8723b1ant_retry_limit(btcoexist
, force_exec
, retry_limit_type
);
185 halbtc8723b1ant_ampdu_maxtime(btcoexist
, force_exec
, ampdu_time_type
);
188 static void halbtc8723b1ant_limited_rx(struct btc_coexist
*btcoexist
,
189 bool force_exec
, bool rej_ap_agg_pkt
,
190 bool bt_ctrl_agg_buf_size
,
193 bool reject_rx_agg
= rej_ap_agg_pkt
;
194 bool bt_ctrl_rx_agg_size
= bt_ctrl_agg_buf_size
;
195 u8 rxaggsize
= agg_buf_size
;
197 /**********************************************
198 * Rx Aggregation related setting
199 **********************************************/
200 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_TO_REJ_AP_AGG_PKT
,
202 /* decide BT control aggregation buf size or not */
203 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_CTRL_AGG_SIZE
,
204 &bt_ctrl_rx_agg_size
);
205 /* aggregation buf size, only work
206 * when BT control Rx aggregation size.
208 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_AGG_BUF_SIZE
, &rxaggsize
);
209 /* real update aggregation setting */
210 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_AGGREGATE_CTRL
, NULL
);
213 static void halbtc8723b1ant_query_bt_info(struct btc_coexist
*btcoexist
)
215 u8 h2c_parameter
[1] = {0};
217 coex_sta
->c2h_bt_info_req_sent
= true;
220 h2c_parameter
[0] |= BIT(0);
222 btcoexist
->btc_fill_h2c(btcoexist
, 0x61, 1, h2c_parameter
);
225 static void halbtc8723b1ant_monitor_bt_ctr(struct btc_coexist
*btcoexist
)
227 u32 reg_hp_txrx
, reg_lp_txrx
, u32tmp
;
228 u32 reg_hp_tx
= 0, reg_hp_rx
= 0;
229 u32 reg_lp_tx
= 0, reg_lp_rx
= 0;
230 static u32 num_of_bt_counter_chk
;
235 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_hp_txrx
);
236 reg_hp_tx
= u32tmp
& MASKLWORD
;
237 reg_hp_rx
= (u32tmp
& MASKHWORD
) >> 16;
239 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_lp_txrx
);
240 reg_lp_tx
= u32tmp
& MASKLWORD
;
241 reg_lp_rx
= (u32tmp
& MASKHWORD
) >> 16;
243 coex_sta
->high_priority_tx
= reg_hp_tx
;
244 coex_sta
->high_priority_rx
= reg_hp_rx
;
245 coex_sta
->low_priority_tx
= reg_lp_tx
;
246 coex_sta
->low_priority_rx
= reg_lp_rx
;
248 if ((coex_sta
->low_priority_tx
> 1050) &&
249 (!coex_sta
->c2h_bt_inquiry_page
))
250 coex_sta
->pop_event_cnt
++;
253 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
255 /* This part is for wifi FW and driver to update BT's status as
258 * The flow is as the following
260 * 2. if all BT Tx/Rx counter = 0, after 6 sec we query bt info
261 * 3. Because BT will not rsp from mailbox, so wifi fw will know BT is
264 * 4. FW will rsp c2h for BT that driver will know BT is disabled.
266 if ((reg_hp_tx
== 0) && (reg_hp_rx
== 0) && (reg_lp_tx
== 0) &&
268 num_of_bt_counter_chk
++;
269 if (num_of_bt_counter_chk
== 3)
270 halbtc8723b1ant_query_bt_info(btcoexist
);
272 num_of_bt_counter_chk
= 0;
276 static void halbtc8723b1ant_monitor_wifi_ctr(struct btc_coexist
*btcoexist
)
279 bool wifi_busy
= false, wifi_under_b_mode
= false;
280 static u8 cck_lock_counter
;
283 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
284 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
285 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_B_MODE
,
288 if (coex_sta
->under_ips
) {
289 coex_sta
->crc_ok_cck
= 0;
290 coex_sta
->crc_ok_11g
= 0;
291 coex_sta
->crc_ok_11n
= 0;
292 coex_sta
->crc_ok_11n_agg
= 0;
294 coex_sta
->crc_err_cck
= 0;
295 coex_sta
->crc_err_11g
= 0;
296 coex_sta
->crc_err_11n
= 0;
297 coex_sta
->crc_err_11n_agg
= 0;
299 coex_sta
->crc_ok_cck
=
300 btcoexist
->btc_read_4byte(btcoexist
, 0xf88);
301 coex_sta
->crc_ok_11g
=
302 btcoexist
->btc_read_2byte(btcoexist
, 0xf94);
303 coex_sta
->crc_ok_11n
=
304 btcoexist
->btc_read_2byte(btcoexist
, 0xf90);
305 coex_sta
->crc_ok_11n_agg
=
306 btcoexist
->btc_read_2byte(btcoexist
, 0xfb8);
308 coex_sta
->crc_err_cck
=
309 btcoexist
->btc_read_4byte(btcoexist
, 0xf84);
310 coex_sta
->crc_err_11g
=
311 btcoexist
->btc_read_2byte(btcoexist
, 0xf96);
312 coex_sta
->crc_err_11n
=
313 btcoexist
->btc_read_2byte(btcoexist
, 0xf92);
314 coex_sta
->crc_err_11n_agg
=
315 btcoexist
->btc_read_2byte(btcoexist
, 0xfba);
319 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xf16, 0x1, 0x1);
320 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xf16, 0x1, 0x0);
322 if ((wifi_busy
) && (wifi_rssi
>= 30) && (!wifi_under_b_mode
)) {
323 total_cnt
= coex_sta
->crc_ok_cck
+ coex_sta
->crc_ok_11g
+
324 coex_sta
->crc_ok_11n
+ coex_sta
->crc_ok_11n_agg
;
326 if ((coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
) ||
327 (coex_dm
->bt_status
==
328 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
) ||
329 (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_SCO_BUSY
)) {
330 if (coex_sta
->crc_ok_cck
>
331 (total_cnt
- coex_sta
->crc_ok_cck
)) {
332 if (cck_lock_counter
< 3)
335 if (cck_lock_counter
> 0)
340 if (cck_lock_counter
> 0)
344 if (cck_lock_counter
> 0)
348 if (!coex_sta
->pre_ccklock
) {
349 if (cck_lock_counter
>= 3)
350 coex_sta
->cck_lock
= true;
352 coex_sta
->cck_lock
= false;
354 if (cck_lock_counter
== 0)
355 coex_sta
->cck_lock
= false;
357 coex_sta
->cck_lock
= true;
360 if (coex_sta
->cck_lock
)
361 coex_sta
->cck_ever_lock
= true;
363 coex_sta
->pre_ccklock
= coex_sta
->cck_lock
;
366 static bool btc8723b1ant_is_wifi_status_changed(struct btc_coexist
*btcoexist
)
368 static bool pre_wifi_busy
;
369 static bool pre_under_4way
, pre_bt_hs_on
;
370 bool wifi_busy
= false, under_4way
= false, bt_hs_on
= false;
371 bool wifi_connected
= false;
373 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
375 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
376 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
377 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
380 if (wifi_connected
) {
381 if (wifi_busy
!= pre_wifi_busy
) {
382 pre_wifi_busy
= wifi_busy
;
385 if (under_4way
!= pre_under_4way
) {
386 pre_under_4way
= under_4way
;
389 if (bt_hs_on
!= pre_bt_hs_on
) {
390 pre_bt_hs_on
= bt_hs_on
;
398 static void halbtc8723b1ant_update_bt_link_info(struct btc_coexist
*btcoexist
)
400 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
401 bool bt_hs_on
= false;
403 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
405 bt_link_info
->bt_link_exist
= coex_sta
->bt_link_exist
;
406 bt_link_info
->sco_exist
= coex_sta
->sco_exist
;
407 bt_link_info
->a2dp_exist
= coex_sta
->a2dp_exist
;
408 bt_link_info
->pan_exist
= coex_sta
->pan_exist
;
409 bt_link_info
->hid_exist
= coex_sta
->hid_exist
;
410 bt_link_info
->bt_hi_pri_link_exist
= coex_sta
->bt_hi_pri_link_exist
;
412 /* work around for HS mode. */
414 bt_link_info
->pan_exist
= true;
415 bt_link_info
->bt_link_exist
= true;
418 /* check if Sco only */
419 if (bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
420 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
421 bt_link_info
->sco_only
= true;
423 bt_link_info
->sco_only
= false;
425 /* check if A2dp only */
426 if (!bt_link_info
->sco_exist
&& bt_link_info
->a2dp_exist
&&
427 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
428 bt_link_info
->a2dp_only
= true;
430 bt_link_info
->a2dp_only
= false;
432 /* check if Pan only */
433 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
434 bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
435 bt_link_info
->pan_only
= true;
437 bt_link_info
->pan_only
= false;
439 /* check if Hid only */
440 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
441 !bt_link_info
->pan_exist
&& bt_link_info
->hid_exist
)
442 bt_link_info
->hid_only
= true;
444 bt_link_info
->hid_only
= false;
447 static void halbtc8723b1ant_set_bt_auto_report(struct btc_coexist
*btcoexist
,
448 bool enable_auto_report
)
450 u8 h2c_parameter
[1] = {0};
452 h2c_parameter
[0] = 0;
454 if (enable_auto_report
)
455 h2c_parameter
[0] |= BIT(0);
457 btcoexist
->btc_fill_h2c(btcoexist
, 0x68, 1, h2c_parameter
);
460 static void halbtc8723b1ant_bt_auto_report(struct btc_coexist
*btcoexist
,
462 bool enable_auto_report
)
464 coex_dm
->cur_bt_auto_report
= enable_auto_report
;
467 if (coex_dm
->pre_bt_auto_report
== coex_dm
->cur_bt_auto_report
)
470 halbtc8723b1ant_set_bt_auto_report(btcoexist
,
471 coex_dm
->cur_bt_auto_report
);
473 coex_dm
->pre_bt_auto_report
= coex_dm
->cur_bt_auto_report
;
476 static void btc8723b1ant_set_sw_pen_tx_rate_adapt(struct btc_coexist
*btcoexist
,
479 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
480 u8 h2c_parameter
[6] = {0};
482 h2c_parameter
[0] = 0x6; /* opCode, 0x6= Retry_Penalty */
484 if (low_penalty_ra
) {
485 h2c_parameter
[1] |= BIT0
;
486 /* normal rate except MCS7/6/5, OFDM54/48/36 */
487 h2c_parameter
[2] = 0x00;
488 h2c_parameter
[3] = 0xf7; /* MCS7 or OFDM54 */
489 h2c_parameter
[4] = 0xf8; /* MCS6 or OFDM48 */
490 h2c_parameter
[5] = 0xf9; /* MCS5 or OFDM36 */
493 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
494 "[BTCoex], set WiFi Low-Penalty Retry: %s",
495 (low_penalty_ra
? "ON!!" : "OFF!!"));
497 btcoexist
->btc_fill_h2c(btcoexist
, 0x69, 6, h2c_parameter
);
500 static void halbtc8723b1ant_low_penalty_ra(struct btc_coexist
*btcoexist
,
501 bool force_exec
, bool low_penalty_ra
)
503 coex_dm
->cur_low_penalty_ra
= low_penalty_ra
;
506 if (coex_dm
->pre_low_penalty_ra
== coex_dm
->cur_low_penalty_ra
)
509 btc8723b1ant_set_sw_pen_tx_rate_adapt(btcoexist
,
510 coex_dm
->cur_low_penalty_ra
);
512 coex_dm
->pre_low_penalty_ra
= coex_dm
->cur_low_penalty_ra
;
515 static void halbtc8723b1ant_set_coex_table(struct btc_coexist
*btcoexist
,
516 u32 val0x6c0
, u32 val0x6c4
,
517 u32 val0x6c8
, u8 val0x6cc
)
519 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
521 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
522 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0
);
523 btcoexist
->btc_write_4byte(btcoexist
, 0x6c0, val0x6c0
);
525 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
526 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4
);
527 btcoexist
->btc_write_4byte(btcoexist
, 0x6c4, val0x6c4
);
529 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
530 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8
);
531 btcoexist
->btc_write_4byte(btcoexist
, 0x6c8, val0x6c8
);
533 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
534 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc
);
535 btcoexist
->btc_write_1byte(btcoexist
, 0x6cc, val0x6cc
);
538 static void halbtc8723b1ant_coex_table(struct btc_coexist
*btcoexist
,
539 bool force_exec
, u32 val0x6c0
,
540 u32 val0x6c4
, u32 val0x6c8
,
543 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
545 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
546 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6cc = 0x%x\n",
547 (force_exec
? "force to" : ""),
548 val0x6c0
, val0x6c4
, val0x6cc
);
549 coex_dm
->cur_val0x6c0
= val0x6c0
;
550 coex_dm
->cur_val0x6c4
= val0x6c4
;
551 coex_dm
->cur_val0x6c8
= val0x6c8
;
552 coex_dm
->cur_val0x6cc
= val0x6cc
;
555 if ((coex_dm
->pre_val0x6c0
== coex_dm
->cur_val0x6c0
) &&
556 (coex_dm
->pre_val0x6c4
== coex_dm
->cur_val0x6c4
) &&
557 (coex_dm
->pre_val0x6c8
== coex_dm
->cur_val0x6c8
) &&
558 (coex_dm
->pre_val0x6cc
== coex_dm
->cur_val0x6cc
))
561 halbtc8723b1ant_set_coex_table(btcoexist
, val0x6c0
, val0x6c4
,
564 coex_dm
->pre_val0x6c0
= coex_dm
->cur_val0x6c0
;
565 coex_dm
->pre_val0x6c4
= coex_dm
->cur_val0x6c4
;
566 coex_dm
->pre_val0x6c8
= coex_dm
->cur_val0x6c8
;
567 coex_dm
->pre_val0x6cc
= coex_dm
->cur_val0x6cc
;
570 static void halbtc8723b1ant_coex_table_with_type(struct btc_coexist
*btcoexist
,
571 bool force_exec
, u8 type
)
573 coex_sta
->coex_table_type
= type
;
577 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
578 0x55555555, 0xffffff, 0x3);
581 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
582 0x5a5a5a5a, 0xffffff, 0x3);
585 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x5a5a5a5a,
586 0x5a5a5a5a, 0xffffff, 0x3);
589 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
590 0xaaaaaaaa, 0xffffff, 0x3);
593 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
594 0x5aaa5aaa, 0xffffff, 0x3);
597 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x5a5a5a5a,
598 0xaaaa5a5a, 0xffffff, 0x3);
601 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
602 0xaaaa5a5a, 0xffffff, 0x3);
605 halbtc8723b1ant_coex_table(btcoexist
, force_exec
, 0xaaaaaaaa,
606 0xaaaaaaaa, 0xffffff, 0x3);
614 halbtc8723b1ant_set_fw_ignore_wlan_act(struct btc_coexist
*btcoexist
,
617 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
618 u8 h2c_parameter
[1] = {0};
621 h2c_parameter
[0] |= BIT0
; /* function enable */
623 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
624 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
627 btcoexist
->btc_fill_h2c(btcoexist
, 0x63, 1, h2c_parameter
);
630 static void halbtc8723b1ant_ignore_wlan_act(struct btc_coexist
*btcoexist
,
631 bool force_exec
, bool enable
)
633 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
635 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
636 "[BTCoex], %s turn Ignore WlanAct %s\n",
637 (force_exec
? "force to" : ""), (enable
? "ON" : "OFF"));
638 coex_dm
->cur_ignore_wlan_act
= enable
;
641 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
642 "[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
643 coex_dm
->pre_ignore_wlan_act
,
644 coex_dm
->cur_ignore_wlan_act
);
646 if (coex_dm
->pre_ignore_wlan_act
==
647 coex_dm
->cur_ignore_wlan_act
)
650 halbtc8723b1ant_set_fw_ignore_wlan_act(btcoexist
, enable
);
652 coex_dm
->pre_ignore_wlan_act
= coex_dm
->cur_ignore_wlan_act
;
655 static void halbtc8723b1ant_set_fw_ps_tdma(struct btc_coexist
*btcoexist
,
656 u8 byte1
, u8 byte2
, u8 byte3
,
659 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
660 u8 h2c_parameter
[5] = {0};
661 u8 real_byte1
= byte1
, real_byte5
= byte5
;
662 bool ap_enable
= false;
664 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
668 if ((byte1
& BIT4
) && !(byte1
& BIT5
)) {
669 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
670 "[BTCoex], FW for 1Ant AP mode\n");
679 h2c_parameter
[0] = real_byte1
;
680 h2c_parameter
[1] = byte2
;
681 h2c_parameter
[2] = byte3
;
682 h2c_parameter
[3] = byte4
;
683 h2c_parameter
[4] = real_byte5
;
685 coex_dm
->ps_tdma_para
[0] = real_byte1
;
686 coex_dm
->ps_tdma_para
[1] = byte2
;
687 coex_dm
->ps_tdma_para
[2] = byte3
;
688 coex_dm
->ps_tdma_para
[3] = byte4
;
689 coex_dm
->ps_tdma_para
[4] = real_byte5
;
691 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
692 "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
694 h2c_parameter
[1] << 24 |
695 h2c_parameter
[2] << 16 |
696 h2c_parameter
[3] << 8 |
699 btcoexist
->btc_fill_h2c(btcoexist
, 0x60, 5, h2c_parameter
);
702 static void halbtc8723b1ant_set_lps_rpwm(struct btc_coexist
*btcoexist
,
703 u8 lps_val
, u8 rpwm_val
)
708 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_LPS_VAL
, &lps
);
709 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_RPWM_VAL
, &rpwm
);
712 static void halbtc8723b1ant_lps_rpwm(struct btc_coexist
*btcoexist
,
714 u8 lps_val
, u8 rpwm_val
)
716 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
718 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
719 "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n",
720 (force_exec
? "force to" : ""), lps_val
, rpwm_val
);
721 coex_dm
->cur_lps
= lps_val
;
722 coex_dm
->cur_rpwm
= rpwm_val
;
725 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
726 "[BTCoex], LPS-RxBeaconMode = 0x%x , LPS-RPWM = 0x%x!!\n",
727 coex_dm
->cur_lps
, coex_dm
->cur_rpwm
);
729 if ((coex_dm
->pre_lps
== coex_dm
->cur_lps
) &&
730 (coex_dm
->pre_rpwm
== coex_dm
->cur_rpwm
)) {
731 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
732 "[BTCoex], LPS-RPWM_Last = 0x%x , LPS-RPWM_Now = 0x%x!!\n",
733 coex_dm
->pre_rpwm
, coex_dm
->cur_rpwm
);
738 halbtc8723b1ant_set_lps_rpwm(btcoexist
, lps_val
, rpwm_val
);
740 coex_dm
->pre_lps
= coex_dm
->cur_lps
;
741 coex_dm
->pre_rpwm
= coex_dm
->cur_rpwm
;
744 static void halbtc8723b1ant_sw_mechanism(struct btc_coexist
*btcoexist
,
747 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
749 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
750 "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra
);
752 halbtc8723b1ant_low_penalty_ra(btcoexist
, NORMAL_EXEC
, low_penalty_ra
);
755 static void halbtc8723b1ant_set_ant_path(struct btc_coexist
*btcoexist
,
756 u8 ant_pos_type
, bool force_exec
,
757 bool init_hw_cfg
, bool wifi_off
)
759 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
760 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
761 u32 fw_ver
= 0, u32tmp
= 0, cnt_bt_cal_chk
= 0;
762 bool pg_ext_switch
= false;
763 bool use_ext_switch
= false;
764 bool is_in_mp_mode
= false;
765 u8 h2c_parameter
[2] = {0}, u8tmp
= 0;
767 coex_dm
->cur_ant_pos_type
= ant_pos_type
;
769 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_EXT_SWITCH
, &pg_ext_switch
);
770 /* [31:16] = fw ver, [15:0] = fw sub ver */
771 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
773 if ((fw_ver
< 0xc0000) || pg_ext_switch
)
774 use_ext_switch
= true;
777 /* WiFi TRx Mask on */
778 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff,
780 /* remove due to interrupt is disabled that polling c2h will
781 * fail and delay 100ms.
784 if (fw_ver
>= 0x180000) {
785 /* Use H2C to set GNT_BT to HIGH */
786 h2c_parameter
[0] = 1;
787 btcoexist
->btc_fill_h2c(btcoexist
, 0x6E, 1,
790 /* set grant_bt to high */
791 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x18);
793 /* set wlan_act control by PTA */
794 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
796 /* BT select s0/s1 is controlled by BT */
797 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67, 0x20, 0x0);
798 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x39, 0x8, 0x1);
799 btcoexist
->btc_write_1byte(btcoexist
, 0x974, 0xff);
800 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x944, 0x3, 0x3);
801 btcoexist
->btc_write_1byte(btcoexist
, 0x930, 0x77);
802 } else if (wifi_off
) {
803 if (fw_ver
>= 0x180000) {
804 /* Use H2C to set GNT_BT to HIGH */
805 h2c_parameter
[0] = 1;
806 btcoexist
->btc_fill_h2c(btcoexist
, 0x6E, 1,
809 /* set grant_bt to high */
810 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x18);
812 /* set wlan_act to always low */
813 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
815 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_IS_IN_MP_MODE
,
818 /* BT select s0/s1 is controlled by BT */
819 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67,
822 /* BT select s0/s1 is controlled by WiFi */
823 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67,
826 /* 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL
827 * BT Vendor 0xac=0xf002
829 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
832 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
834 /* Use H2C to set GNT_BT to LOW */
835 if (fw_ver
>= 0x180000) {
836 if (btcoexist
->btc_read_1byte(btcoexist
, 0x765) != 0) {
837 h2c_parameter
[0] = 0;
838 btcoexist
->btc_fill_h2c(btcoexist
, 0x6E, 1,
842 /* BT calibration check */
843 while (cnt_bt_cal_chk
<= 20) {
844 u8tmp
= btcoexist
->btc_read_1byte(btcoexist
,
847 if (u8tmp
& BIT(0)) {
848 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
850 "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n",
854 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
856 "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n",
862 /* set grant_bt to PTA */
863 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x0);
866 if (btcoexist
->btc_read_1byte(btcoexist
, 0x76e) != 0xc) {
867 /* set wlan_act control by PTA */
868 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
871 btcoexist
->btc_write_1byte_bitmask(
872 btcoexist
, 0x67, 0x20,
873 0x1); /* BT select s0/s1 is controlled by WiFi */
876 if (use_ext_switch
) {
878 /* 0x4c[23] = 0, 0x4c[24] = 1
879 * Antenna control by WL/BT
881 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
884 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
886 /* fixed internal switch S1->WiFi, S0->BT */
887 btcoexist
->btc_write_4byte(btcoexist
, 0x948, 0x0);
889 if (board_info
->btdm_ant_pos
==
890 BTC_ANTENNA_AT_MAIN_PORT
) {
891 /* tell firmware "no antenna inverse" */
892 h2c_parameter
[0] = 0;
893 /* ext switch type */
894 h2c_parameter
[1] = 1;
895 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
898 /* tell firmware "antenna inverse" */
899 h2c_parameter
[0] = 1;
900 /* ext switch type */
901 h2c_parameter
[1] = 1;
902 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
908 (coex_dm
->cur_ant_pos_type
!= coex_dm
->pre_ant_pos_type
)) {
909 /* ext switch setting */
910 switch (ant_pos_type
) {
911 case BTC_ANT_PATH_WIFI
:
912 if (board_info
->btdm_ant_pos
==
913 BTC_ANTENNA_AT_MAIN_PORT
)
914 btcoexist
->btc_write_1byte_bitmask(
915 btcoexist
, 0x92c, 0x3, 0x1);
917 btcoexist
->btc_write_1byte_bitmask(
918 btcoexist
, 0x92c, 0x3, 0x2);
920 case BTC_ANT_PATH_BT
:
921 if (board_info
->btdm_ant_pos
==
922 BTC_ANTENNA_AT_MAIN_PORT
)
923 btcoexist
->btc_write_1byte_bitmask(
924 btcoexist
, 0x92c, 0x3, 0x2);
926 btcoexist
->btc_write_1byte_bitmask(
927 btcoexist
, 0x92c, 0x3, 0x1);
930 case BTC_ANT_PATH_PTA
:
931 if (board_info
->btdm_ant_pos
==
932 BTC_ANTENNA_AT_MAIN_PORT
)
933 btcoexist
->btc_write_1byte_bitmask(
934 btcoexist
, 0x92c, 0x3, 0x1);
936 btcoexist
->btc_write_1byte_bitmask(
937 btcoexist
, 0x92c, 0x3, 0x2);
943 /* 0x4c[23] = 1, 0x4c[24] = 0,
944 * Antenna control by 0x64
946 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
949 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
951 /* Fix Ext switch Main->S1, Aux->S0 */
952 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x64, 0x1,
955 if (board_info
->btdm_ant_pos
==
956 BTC_ANTENNA_AT_MAIN_PORT
) {
957 /* tell firmware "no antenna inverse" */
958 h2c_parameter
[0] = 0;
959 /* internal switch type */
960 h2c_parameter
[1] = 0;
961 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
964 /* tell firmware "antenna inverse" */
965 h2c_parameter
[0] = 1;
966 /* internal switch type */
967 h2c_parameter
[1] = 0;
968 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
974 (coex_dm
->cur_ant_pos_type
!= coex_dm
->pre_ant_pos_type
)) {
975 /* internal switch setting */
976 switch (ant_pos_type
) {
977 case BTC_ANT_PATH_WIFI
:
978 if (board_info
->btdm_ant_pos
==
979 BTC_ANTENNA_AT_MAIN_PORT
)
980 btcoexist
->btc_write_4byte(btcoexist
,
983 btcoexist
->btc_write_4byte(btcoexist
,
986 case BTC_ANT_PATH_BT
:
987 if (board_info
->btdm_ant_pos
==
988 BTC_ANTENNA_AT_MAIN_PORT
)
989 btcoexist
->btc_write_4byte(btcoexist
,
992 btcoexist
->btc_write_4byte(btcoexist
,
996 case BTC_ANT_PATH_PTA
:
997 if (board_info
->btdm_ant_pos
==
998 BTC_ANTENNA_AT_MAIN_PORT
)
999 btcoexist
->btc_write_4byte(btcoexist
,
1002 btcoexist
->btc_write_4byte(btcoexist
,
1009 coex_dm
->pre_ant_pos_type
= coex_dm
->cur_ant_pos_type
;
1012 static void halbtc8723b1ant_ps_tdma(struct btc_coexist
*btcoexist
,
1013 bool force_exec
, bool turn_on
, u8 type
)
1015 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1016 bool wifi_busy
= false;
1017 u8 rssi_adjust_val
= 0;
1018 u8 ps_tdma_byte0_val
= 0x51;
1019 u8 ps_tdma_byte3_val
= 0x10;
1020 u8 ps_tdma_byte4_val
= 0x50;
1021 s8 wifi_duration_adjust
= 0x0;
1022 static bool pre_wifi_busy
;
1024 coex_dm
->cur_ps_tdma_on
= turn_on
;
1025 coex_dm
->cur_ps_tdma
= type
;
1027 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1029 if (wifi_busy
!= pre_wifi_busy
) {
1031 pre_wifi_busy
= wifi_busy
;
1035 if ((coex_dm
->pre_ps_tdma_on
== coex_dm
->cur_ps_tdma_on
) &&
1036 (coex_dm
->pre_ps_tdma
== coex_dm
->cur_ps_tdma
))
1040 if (coex_sta
->scan_ap_num
<= 5) {
1041 wifi_duration_adjust
= 5;
1043 if (coex_sta
->a2dp_bit_pool
>= 35)
1044 wifi_duration_adjust
= -10;
1045 else if (coex_sta
->a2dp_bit_pool
>= 45)
1046 wifi_duration_adjust
= -15;
1047 } else if (coex_sta
->scan_ap_num
>= 40) {
1048 wifi_duration_adjust
= -15;
1050 if (coex_sta
->a2dp_bit_pool
< 35)
1051 wifi_duration_adjust
= -5;
1052 else if (coex_sta
->a2dp_bit_pool
< 45)
1053 wifi_duration_adjust
= -10;
1054 } else if (coex_sta
->scan_ap_num
>= 20) {
1055 wifi_duration_adjust
= -10;
1057 if (coex_sta
->a2dp_bit_pool
>= 45)
1058 wifi_duration_adjust
= -15;
1060 wifi_duration_adjust
= 0;
1062 if (coex_sta
->a2dp_bit_pool
>= 35)
1063 wifi_duration_adjust
= -10;
1064 else if (coex_sta
->a2dp_bit_pool
>= 45)
1065 wifi_duration_adjust
= -15;
1068 if ((type
== 1) || (type
== 2) || (type
== 9) || (type
== 11) ||
1069 (type
== 101) || (type
== 102) || (type
== 109) || (type
== 101)) {
1070 if (!coex_sta
->force_lps_on
) {
1071 /* Native power save TDMA, only for A2DP-only case
1072 * 1/2/9/11 while wifi noisy threshold > 30
1076 ps_tdma_byte0_val
= 0x61;
1077 /* no tx-pause at BT-slot */
1078 ps_tdma_byte3_val
= 0x11;
1079 /* 0x778 = d/1 toggle, no dynamic slot */
1080 ps_tdma_byte4_val
= 0x10;
1083 ps_tdma_byte0_val
= 0x51;
1084 /* tx-pause at BT-slot */
1085 ps_tdma_byte3_val
= 0x10;
1086 /* 0x778 = d/1 toggle, dynamic slot */
1087 ps_tdma_byte4_val
= 0x50;
1089 } else if ((type
== 3) || (type
== 13) || (type
== 14) ||
1090 (type
== 103) || (type
== 113) || (type
== 114)) {
1092 ps_tdma_byte0_val
= 0x51;
1093 /* tx-pause at BT-slot */
1094 ps_tdma_byte3_val
= 0x10;
1095 /* 0x778 = d/1 toggle, no dynamic slot */
1096 ps_tdma_byte4_val
= 0x10;
1097 } else { /* native power save case */
1099 ps_tdma_byte0_val
= 0x61;
1100 /* no tx-pause at BT-slot */
1101 ps_tdma_byte3_val
= 0x11;
1102 /* 0x778 = d/1 toggle, no dynamic slot */
1103 ps_tdma_byte4_val
= 0x11;
1104 /* psTdmaByte4Va is not define for 0x778 = d/1, 1/1 case */
1107 /* if (bt_link_info->slave_role) */
1108 if ((bt_link_info
->slave_role
) && (bt_link_info
->a2dp_exist
))
1109 /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1110 ps_tdma_byte4_val
= ps_tdma_byte4_val
| 0x1;
1113 /* set antenna control by SW */
1114 ps_tdma_byte0_val
= ps_tdma_byte0_val
| 0x82;
1115 /* set antenna no toggle, control by antenna diversity */
1116 ps_tdma_byte3_val
= ps_tdma_byte3_val
| 0x60;
1122 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x1a,
1127 halbtc8723b1ant_set_fw_ps_tdma(
1128 btcoexist
, ps_tdma_byte0_val
,
1129 0x3a + wifi_duration_adjust
, 0x03,
1130 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1132 rssi_adjust_val
= 11;
1135 halbtc8723b1ant_set_fw_ps_tdma(
1136 btcoexist
, ps_tdma_byte0_val
,
1137 0x2d + wifi_duration_adjust
, 0x03,
1138 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1141 halbtc8723b1ant_set_fw_ps_tdma(
1142 btcoexist
, ps_tdma_byte0_val
, 0x30, 0x03,
1143 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1146 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x15,
1150 halbtc8723b1ant_set_fw_ps_tdma(
1151 btcoexist
, ps_tdma_byte0_val
, 0x1f, 0x3,
1152 ps_tdma_byte3_val
, 0x11);
1155 halbtc8723b1ant_set_fw_ps_tdma(
1156 btcoexist
, ps_tdma_byte0_val
, 0x20, 0x3,
1157 ps_tdma_byte3_val
, 0x11);
1160 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xc,
1164 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x25,
1168 halbtc8723b1ant_set_fw_ps_tdma(
1169 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1170 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1173 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xa,
1177 halbtc8723b1ant_set_fw_ps_tdma(
1178 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x03,
1179 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1182 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x0a,
1186 if (coex_sta
->scan_ap_num
<= 3)
1187 halbtc8723b1ant_set_fw_ps_tdma(
1188 btcoexist
, ps_tdma_byte0_val
, 0x40, 0x3,
1189 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1191 halbtc8723b1ant_set_fw_ps_tdma(
1192 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1193 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1196 if (coex_sta
->scan_ap_num
<= 3)
1197 halbtc8723b1ant_set_fw_ps_tdma(
1198 btcoexist
, 0x51, 0x30, 0x3, 0x10, 0x50);
1200 halbtc8723b1ant_set_fw_ps_tdma(
1201 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1202 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1205 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xa,
1209 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x15,
1213 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x25,
1217 halbtc8723b1ant_set_fw_ps_tdma(
1218 btcoexist
, ps_tdma_byte0_val
, 0x3f, 0x03,
1219 ps_tdma_byte3_val
, 0x10);
1222 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x25,
1226 halbtc8723b1ant_set_fw_ps_tdma(
1227 btcoexist
, ps_tdma_byte0_val
, 0x25, 0x03,
1228 ps_tdma_byte3_val
, 0x10);
1231 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1235 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x15,
1239 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1243 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1247 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1251 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x69, 0x25,
1255 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xab, 0x1a,
1259 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x30,
1263 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x1a,
1267 halbtc8723b1ant_set_fw_ps_tdma(
1268 btcoexist
, ps_tdma_byte0_val
, 0x35, 0x3,
1269 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1272 halbtc8723b1ant_set_fw_ps_tdma(
1273 btcoexist
, ps_tdma_byte0_val
, 0x35, 0x3,
1274 ps_tdma_byte3_val
, 0x10);
1277 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x53, 0x1a,
1281 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x63, 0x1a,
1285 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x12,
1289 /* SoftAP only with no sta associated,BT disable ,TDMA
1290 * mode for power saving
1292 * here softap mode screen off will cost 70-80mA for
1295 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x23, 0x18,
1300 /* for 1-Ant translate to 2-Ant */
1301 halbtc8723b1ant_set_fw_ps_tdma(
1302 btcoexist
, ps_tdma_byte0_val
,
1303 0x3a + wifi_duration_adjust
, 0x03,
1304 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1307 halbtc8723b1ant_set_fw_ps_tdma(
1308 btcoexist
, ps_tdma_byte0_val
,
1309 0x2d + wifi_duration_adjust
, 0x03,
1310 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1313 halbtc8723b1ant_set_fw_ps_tdma(
1314 btcoexist
, ps_tdma_byte0_val
, 0x3a, 0x03,
1315 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1318 halbtc8723b1ant_set_fw_ps_tdma(
1319 btcoexist
, ps_tdma_byte0_val
, 0x15, 0x3,
1320 ps_tdma_byte3_val
, 0x11);
1323 halbtc8723b1ant_set_fw_ps_tdma(
1324 btcoexist
, ps_tdma_byte0_val
, 0x20, 0x3,
1325 ps_tdma_byte3_val
, 0x11);
1328 halbtc8723b1ant_set_fw_ps_tdma(
1329 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1330 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1333 halbtc8723b1ant_set_fw_ps_tdma(
1334 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x03,
1335 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1338 halbtc8723b1ant_set_fw_ps_tdma(
1339 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1340 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1343 halbtc8723b1ant_set_fw_ps_tdma(
1344 btcoexist
, ps_tdma_byte0_val
, 0x21, 0x3,
1345 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1348 halbtc8723b1ant_set_fw_ps_tdma(
1349 btcoexist
, ps_tdma_byte0_val
, 0x3f, 0x03,
1350 ps_tdma_byte3_val
, 0x10);
1353 halbtc8723b1ant_set_fw_ps_tdma(
1354 btcoexist
, ps_tdma_byte0_val
, 0x25, 0x03,
1355 ps_tdma_byte3_val
, 0x10);
1358 halbtc8723b1ant_set_fw_ps_tdma(
1359 btcoexist
, ps_tdma_byte0_val
, 0x25, 0x03,
1360 ps_tdma_byte3_val
, ps_tdma_byte4_val
);
1363 halbtc8723b1ant_set_fw_ps_tdma(
1364 btcoexist
, ps_tdma_byte0_val
, 0x25, 0x03,
1365 ps_tdma_byte3_val
, 0x11);
1369 /* disable PS tdma */
1371 case 8: /* PTA Control */
1372 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x8, 0x0,
1374 halbtc8723b1ant_set_ant_path(btcoexist
,
1381 /* Software control, Antenna at BT side */
1382 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0,
1385 case 1: /* 2-Ant, 0x778=3, antenna control by ant diversity */
1386 halbtc8723b1ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1391 rssi_adjust_val
= 0;
1392 btcoexist
->btc_set(btcoexist
,
1393 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE
,
1396 /* update pre state */
1397 coex_dm
->pre_ps_tdma_on
= coex_dm
->cur_ps_tdma_on
;
1398 coex_dm
->pre_ps_tdma
= coex_dm
->cur_ps_tdma
;
1401 void btc8723b1ant_tdma_dur_adj_for_acl(struct btc_coexist
*btcoexist
,
1404 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1405 static s32 up
, dn
, m
, n
, wait_count
;
1406 /* 0: no change, +1: increase WiFi duration,
1407 * -1: decrease WiFi duration
1410 u8 retry_count
= 0, bt_info_ext
;
1411 bool wifi_busy
= false;
1413 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1414 "[BTCoex], TdmaDurationAdjustForAcl()\n");
1416 if (wifi_status
== BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
)
1422 BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN
) ||
1423 (wifi_status
== BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
) ||
1424 (wifi_status
== BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT
)) {
1425 if (coex_dm
->cur_ps_tdma
!= 1 && coex_dm
->cur_ps_tdma
!= 2 &&
1426 coex_dm
->cur_ps_tdma
!= 3 && coex_dm
->cur_ps_tdma
!= 9) {
1427 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1429 coex_dm
->ps_tdma_du_adj_type
= 9;
1441 if (!coex_dm
->auto_tdma_adjust
) {
1442 coex_dm
->auto_tdma_adjust
= true;
1443 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1444 "[BTCoex], first run TdmaDurationAdjust()!!\n");
1446 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 2);
1447 coex_dm
->ps_tdma_du_adj_type
= 2;
1456 /* acquire the BT TRx retry count from BT_Info byte2 */
1457 retry_count
= coex_sta
->bt_retry_cnt
;
1458 bt_info_ext
= coex_sta
->bt_info_ext
;
1460 if ((coex_sta
->low_priority_tx
) > 1050 ||
1461 (coex_sta
->low_priority_rx
) > 1250)
1466 /* no retry in the last 2-second duration */
1467 if (retry_count
== 0) {
1475 /* if retry count during continuous n*2 seconds
1476 * is 0, enlarge WiFi duration
1483 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1484 "[BTCoex], Increase wifi duration!!\n");
1486 } else if (retry_count
<= 3) {
1487 /* <=3 retry in the last 2-second duration */
1495 /* if continuous 2 retry count(every 2 seconds)
1496 * >0 and < 3, reduce WiFi duration
1498 if (wait_count
<= 2)
1499 /* avoid loop between the two levels */
1505 /* maximum of m = 20 ' will recheck if
1506 * need to adjust wifi duration in
1507 * maximum time interval 120 seconds
1516 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1517 "[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
1520 /* retry count > 3, once retry count > 3, to reduce
1523 if (wait_count
== 1)
1524 /* to avoid loop between the two levels */
1530 /* maximum of m = 20 ' will recheck if need to
1531 * adjust wifi duration in maximum time interval
1541 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1542 "[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
1546 if (coex_dm
->cur_ps_tdma
== 1) {
1547 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1549 coex_dm
->ps_tdma_du_adj_type
= 2;
1550 } else if (coex_dm
->cur_ps_tdma
== 2) {
1551 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1553 coex_dm
->ps_tdma_du_adj_type
= 9;
1554 } else if (coex_dm
->cur_ps_tdma
== 9) {
1555 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1557 coex_dm
->ps_tdma_du_adj_type
= 11;
1559 } else if (result
== 1) {
1560 if (coex_dm
->cur_ps_tdma
== 11) {
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
= 2;
1568 } else if (coex_dm
->cur_ps_tdma
== 2) {
1569 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1571 coex_dm
->ps_tdma_du_adj_type
= 1;
1575 if (coex_dm
->cur_ps_tdma
!= 1 && coex_dm
->cur_ps_tdma
!= 2 &&
1576 coex_dm
->cur_ps_tdma
!= 9 && coex_dm
->cur_ps_tdma
!= 11) {
1577 /* recover to previous adjust type */
1578 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1579 coex_dm
->ps_tdma_du_adj_type
);
1584 static void halbtc8723b1ant_ps_tdma_chk_pwr_save(struct btc_coexist
*btcoexist
,
1589 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_LPS_MODE
, &lps_mode
);
1592 /* already under LPS state */
1594 /* keep state under LPS, do nothing. */
1596 /* will leave LPS state, turn off psTdma first */
1597 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1603 /* will enter LPS state, turn off psTdma first */
1604 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1607 /* keep state under NO PS state, do nothing. */
1612 static void halbtc8723b1ant_power_save_state(struct btc_coexist
*btcoexist
,
1613 u8 ps_type
, u8 lps_val
,
1616 bool low_pwr_disable
= false;
1619 case BTC_PS_WIFI_NATIVE
:
1620 /* recover to original 32k low power setting */
1621 low_pwr_disable
= false;
1622 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1624 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_NORMAL_LPS
, NULL
);
1625 coex_sta
->force_lps_on
= false;
1628 halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist
, true);
1629 halbtc8723b1ant_lps_rpwm(btcoexist
, NORMAL_EXEC
, lps_val
,
1631 /* when coex force to enter LPS, do not enter 32k low power */
1632 low_pwr_disable
= true;
1633 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1635 /* power save must executed before psTdma */
1636 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_ENTER_LPS
, NULL
);
1637 coex_sta
->force_lps_on
= true;
1639 case BTC_PS_LPS_OFF
:
1640 halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist
, false);
1641 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_LEAVE_LPS
, NULL
);
1642 coex_sta
->force_lps_on
= false;
1649 static void halbtc8723b1ant_action_wifi_only(struct btc_coexist
*btcoexist
)
1651 halbtc8723b1ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 0);
1652 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
1653 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
1654 FORCE_EXEC
, false, false);
1657 /* check if BT is disabled */
1658 static void halbtc8723b1ant_monitor_bt_enable_disable(struct btc_coexist
1661 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1662 static u32 bt_disable_cnt
;
1663 bool bt_active
= true, bt_disabled
;
1665 if (coex_sta
->high_priority_tx
== 0 &&
1666 coex_sta
->high_priority_rx
== 0 && coex_sta
->low_priority_tx
== 0 &&
1667 coex_sta
->low_priority_rx
== 0)
1669 if (coex_sta
->high_priority_tx
== 0xffff &&
1670 coex_sta
->high_priority_rx
== 0xffff &&
1671 coex_sta
->low_priority_tx
== 0xffff &&
1672 coex_sta
->low_priority_rx
== 0xffff)
1676 bt_disabled
= false;
1679 if (bt_disable_cnt
>= 2)
1682 if (coex_sta
->bt_disabled
!= bt_disabled
) {
1683 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1684 "[BTCoex], BT is from %s to %s!!\n",
1685 (coex_sta
->bt_disabled
? "disabled" : "enabled"),
1686 (bt_disabled
? "disabled" : "enabled"));
1688 coex_sta
->bt_disabled
= bt_disabled
;
1689 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_DISABLE
,
1692 halbtc8723b1ant_action_wifi_only(btcoexist
);
1693 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_LEAVE_LPS
,
1695 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_NORMAL_LPS
,
1701 /*****************************************************
1703 * Non-Software Coex Mechanism start
1705 *****************************************************/
1707 static void halbtc8723b1ant_action_bt_whck_test(struct btc_coexist
*btcoexist
)
1709 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0,
1712 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1713 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
, NORMAL_EXEC
,
1715 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1718 static void halbtc8723b1ant_action_wifi_multiport(struct btc_coexist
*btcoexist
)
1720 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1723 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1724 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1727 static void halbtc8723b1ant_action_hs(struct btc_coexist
*btcoexist
)
1729 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 5);
1730 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1733 static void halbtc8723b1ant_action_bt_inquiry(struct btc_coexist
*btcoexist
)
1735 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1736 bool wifi_connected
= false, ap_enable
= false;
1737 bool wifi_busy
= false, bt_busy
= false;
1739 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
1741 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1743 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1744 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TRAFFIC_BUSY
, &bt_busy
);
1746 if (coex_sta
->bt_abnormal_scan
) {
1747 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 33);
1748 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
1749 } else if (!wifi_connected
&& !coex_sta
->wifi_is_high_pri_task
) {
1750 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1752 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1753 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
1754 NORMAL_EXEC
, false, false);
1755 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1756 } else if (bt_link_info
->sco_exist
|| bt_link_info
->hid_exist
||
1757 bt_link_info
->a2dp_exist
) {
1758 /* SCO/HID/A2DP busy */
1759 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1761 if (coex_sta
->c2h_bt_remote_name_req
)
1762 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1765 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1768 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1769 } else if (bt_link_info
->pan_exist
|| wifi_busy
) {
1770 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1772 if (coex_sta
->c2h_bt_remote_name_req
)
1773 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1776 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1779 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1781 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1783 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1784 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
1785 NORMAL_EXEC
, false, false);
1786 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
1790 static void btc8723b1ant_act_bt_sco_hid_only_busy(struct btc_coexist
*btcoexist
,
1793 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1794 bool wifi_connected
= false;
1796 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1799 /* tdma and coex table */
1800 if (bt_link_info
->sco_exist
) {
1801 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 5);
1802 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1805 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 6);
1806 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 5);
1810 static void halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
1811 struct btc_coexist
*btcoexist
,
1814 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1816 if ((coex_sta
->low_priority_rx
>= 950) && (!coex_sta
->under_ips
))
1817 bt_link_info
->slave_role
= true;
1819 bt_link_info
->slave_role
= false;
1821 if (bt_link_info
->hid_only
) { /* HID */
1822 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist
, wifi_status
);
1823 coex_dm
->auto_tdma_adjust
= false;
1825 } else if (bt_link_info
->a2dp_only
) { /* A2DP */
1826 if (wifi_status
== BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE
) {
1827 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1829 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1831 coex_dm
->auto_tdma_adjust
= false;
1833 btc8723b1ant_tdma_dur_adj_for_acl(btcoexist
,
1835 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1837 coex_dm
->auto_tdma_adjust
= true;
1839 } else if (bt_link_info
->hid_exist
&&
1840 bt_link_info
->a2dp_exist
) { /* HID + A2DP */
1841 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1842 coex_dm
->auto_tdma_adjust
= false;
1844 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 6);
1845 /* PAN(OPP,FTP), HID + PAN(OPP,FTP) */
1846 } else if (bt_link_info
->pan_only
||
1847 (bt_link_info
->hid_exist
&& bt_link_info
->pan_exist
)) {
1848 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
1849 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 6);
1850 coex_dm
->auto_tdma_adjust
= false;
1851 /* A2DP + PAN(OPP,FTP), HID + A2DP + PAN(OPP,FTP) */
1852 } else if ((bt_link_info
->a2dp_exist
&& bt_link_info
->pan_exist
) ||
1853 (bt_link_info
->hid_exist
&& bt_link_info
->a2dp_exist
&&
1854 bt_link_info
->pan_exist
)) {
1855 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 13);
1856 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1857 coex_dm
->auto_tdma_adjust
= false;
1859 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 11);
1860 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1861 coex_dm
->auto_tdma_adjust
= false;
1865 static void btc8723b1ant_action_wifi_not_conn(struct btc_coexist
*btcoexist
)
1867 /* power save state */
1868 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1871 /* tdma and coex table */
1872 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1873 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1877 btc8723b1ant_action_wifi_not_conn_scan(struct btc_coexist
*btcoexist
)
1879 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1881 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1884 /* tdma and coex table */
1885 if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
) {
1886 if (bt_link_info
->a2dp_exist
&& bt_link_info
->pan_exist
) {
1887 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1889 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1891 } else if (bt_link_info
->pan_only
) {
1892 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1894 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1897 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1899 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1902 } else if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_SCO_BUSY
||
1903 coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
){
1904 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist
,
1905 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
);
1907 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1908 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1913 btc8723b1ant_act_wifi_not_conn_asso_auth(struct btc_coexist
*btcoexist
)
1915 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1917 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1920 if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
== coex_dm
->bt_status
) ||
1921 (bt_link_info
->sco_exist
) || (bt_link_info
->hid_only
) ||
1922 (bt_link_info
->a2dp_only
) || (bt_link_info
->pan_only
)) {
1923 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1924 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
1926 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
1927 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1931 static void btc8723b1ant_action_wifi_conn_scan(struct btc_coexist
*btcoexist
)
1933 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1935 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1938 /* tdma and coex table */
1939 if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
) {
1940 if (bt_link_info
->a2dp_exist
&& bt_link_info
->pan_exist
) {
1941 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1943 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1945 } else if (bt_link_info
->pan_only
) {
1946 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1948 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1951 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1953 halbtc8723b1ant_coex_table_with_type(btcoexist
,
1956 } else if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_SCO_BUSY
||
1957 coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
) {
1958 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist
,
1959 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
);
1961 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1962 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1966 static void halbtc8723b1ant_action_wifi_connected_special_packet(
1967 struct btc_coexist
*btcoexist
)
1969 bool hs_connecting
= false;
1970 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1972 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_CONNECTING
, &hs_connecting
);
1974 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1977 /* tdma and coex table */
1978 if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
== coex_dm
->bt_status
) ||
1979 (bt_link_info
->sco_exist
) || (bt_link_info
->hid_only
) ||
1980 (bt_link_info
->a2dp_only
) || (bt_link_info
->pan_only
)) {
1981 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1982 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
1984 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
1985 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1989 static void halbtc8723b1ant_action_wifi_connected(struct btc_coexist
*btcoexist
)
1991 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1992 bool wifi_busy
= false;
1993 bool scan
= false, link
= false, roam
= false;
1994 bool under_4way
= false, ap_enable
= false;
1996 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1997 "[BTCoex], CoexForWifiConnect()===>\n");
1999 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
2002 halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist
);
2003 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2004 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
2008 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2009 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2010 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2012 if (scan
|| link
|| roam
) {
2014 btc8723b1ant_action_wifi_conn_scan(btcoexist
);
2016 halbtc8723b1ant_action_wifi_connected_special_packet(
2018 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2019 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
2023 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
2025 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
2026 /* power save state */
2028 coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
&&
2029 !btcoexist
->bt_link_info
.hid_only
) {
2030 if (!wifi_busy
&& btcoexist
->bt_link_info
.a2dp_only
)
2031 halbtc8723b1ant_power_save_state(btcoexist
,
2035 halbtc8723b1ant_power_save_state(btcoexist
,
2039 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2042 /* tdma and coex table */
2044 if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
) {
2045 halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
2047 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE
);
2048 } else if (coex_dm
->bt_status
==
2049 BT_8723B_1ANT_BT_STATUS_SCO_BUSY
||
2050 coex_dm
->bt_status
==
2051 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
) {
2052 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist
,
2053 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE
);
2055 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2057 halbtc8723b1ant_coex_table_with_type(btcoexist
,
2061 if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
) {
2062 halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
2064 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
);
2065 } else if (coex_dm
->bt_status
==
2066 BT_8723B_1ANT_BT_STATUS_SCO_BUSY
||
2067 coex_dm
->bt_status
==
2068 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
) {
2069 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist
,
2070 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
);
2072 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2074 halbtc8723b1ant_coex_table_with_type(btcoexist
,
2080 static void halbtc8723b1ant_run_coexist_mechanism(struct btc_coexist
*btcoexist
)
2082 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2083 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
2084 bool wifi_connected
= false, bt_hs_on
= false;
2085 bool increase_scan_dev_num
= false;
2086 bool bt_ctrl_agg_buf_size
= false;
2087 u8 agg_buf_size
= 5;
2088 u32 wifi_link_status
= 0;
2089 u32 num_of_wifi_link
= 0;
2091 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2092 "[BTCoex], RunCoexistMechanism()===>\n");
2094 if (btcoexist
->manual_control
) {
2095 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2096 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2100 if (btcoexist
->stop_coex_dm
) {
2101 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2102 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2106 if (coex_sta
->under_ips
) {
2107 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2108 "[BTCoex], wifi is under IPS !!!\n");
2112 if (coex_sta
->bt_whck_test
) {
2113 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2114 "[BTCoex], wifi is under IPS !!!\n");
2115 halbtc8723b1ant_action_bt_whck_test(btcoexist
);
2119 if (coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_BUSY
||
2120 coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_SCO_BUSY
||
2121 coex_dm
->bt_status
== BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
)
2122 increase_scan_dev_num
= true;
2124 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_INC_SCAN_DEV_NUM
,
2125 &increase_scan_dev_num
);
2127 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
2130 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2132 num_of_wifi_link
= wifi_link_status
>> 16;
2133 if (num_of_wifi_link
>= 2) {
2134 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2135 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2136 bt_ctrl_agg_buf_size
,
2138 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
2142 if (!bt_link_info
->sco_exist
&& !bt_link_info
->hid_exist
) {
2143 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2146 halbtc8723b1ant_limited_tx(btcoexist
,
2147 NORMAL_EXEC
, 1, 1, 1, 1);
2149 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
,
2153 if (bt_link_info
->sco_exist
) {
2154 bt_ctrl_agg_buf_size
= true;
2156 } else if (bt_link_info
->hid_exist
) {
2157 bt_ctrl_agg_buf_size
= true;
2159 } else if (bt_link_info
->a2dp_exist
|| bt_link_info
->pan_exist
) {
2160 bt_ctrl_agg_buf_size
= true;
2163 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2164 bt_ctrl_agg_buf_size
, agg_buf_size
);
2166 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2168 if (coex_sta
->c2h_bt_inquiry_page
) {
2169 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2171 } else if (bt_hs_on
) {
2172 halbtc8723b1ant_action_hs(btcoexist
);
2176 if (!wifi_connected
) {
2177 bool scan
= false, link
= false, roam
= false;
2179 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2180 "[BTCoex], wifi is non connected-idle !!!\n");
2182 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2183 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2184 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2186 if (scan
|| link
|| roam
) {
2188 btc8723b1ant_action_wifi_not_conn_scan(
2191 btc8723b1ant_act_wifi_not_conn_asso_auth(
2194 btc8723b1ant_action_wifi_not_conn(btcoexist
);
2196 } else { /* wifi LPS/Busy */
2197 halbtc8723b1ant_action_wifi_connected(btcoexist
);
2201 /* force coex mechanism to reset */
2202 static void halbtc8723b1ant_init_coex_dm(struct btc_coexist
*btcoexist
)
2205 halbtc8723b1ant_sw_mechanism(btcoexist
, false);
2207 coex_sta
->pop_event_cnt
= 0;
2210 static void halbtc8723b1ant_init_hw_config(struct btc_coexist
*btcoexist
,
2211 bool backup
, bool wifi_only
)
2213 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2215 u8 u8tmpa
= 0, u8tmpb
= 0;
2217 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2218 "[BTCoex], 1Ant Init HW Config!!\n");
2220 /* 0xf0[15:12] --> Chip Cut information */
2221 coex_sta
->cut_version
=
2222 (btcoexist
->btc_read_1byte(btcoexist
, 0xf1) & 0xf0) >> 4;
2223 /* enable TBTT interrupt */
2224 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x550, 0x8, 0x1);
2226 /* 0x790[5:0] = 0x5 */
2227 btcoexist
->btc_write_1byte(btcoexist
, 0x790, 0x5);
2229 /* Enable counter statistics */
2230 btcoexist
->btc_write_1byte(btcoexist
, 0x778, 0x1);
2231 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x40, 0x20, 0x1);
2233 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
2235 /* Antenna config */
2237 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_WIFI
,
2238 FORCE_EXEC
, true, false);
2240 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
,
2241 FORCE_EXEC
, true, false);
2244 halbtc8723b1ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 0);
2246 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x948);
2247 u8tmpa
= btcoexist
->btc_read_1byte(btcoexist
, 0x765);
2248 u8tmpb
= btcoexist
->btc_read_1byte(btcoexist
, 0x67);
2250 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2251 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
2252 u32tmp
, u8tmpa
, u8tmpb
);
2255 /**************************************************************
2256 * extern function start with ex_halbtc8723b1ant_
2257 **************************************************************/
2258 void ex_halbtc8723b1ant_power_on_setting(struct btc_coexist
*btcoexist
)
2260 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2261 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
2266 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2267 "xxxxxxxxxxxxxxxx Execute 8723b 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n");
2269 btcoexist
->stop_coex_dm
= true;
2271 btcoexist
->btc_write_1byte(btcoexist
, 0x67, 0x20);
2273 /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
2274 u16tmp
= btcoexist
->btc_read_2byte(btcoexist
, 0x2);
2275 btcoexist
->btc_write_2byte(btcoexist
, 0x2, u16tmp
| BIT0
| BIT1
);
2277 /* set GRAN_BT = 1 */
2278 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x18);
2279 /* set WLAN_ACT = 0 */
2280 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
2282 /* S0 or S1 setting and Local register setting(By the setting fw can get
2283 * ant number, S0/S1, ... info)
2285 * Local setting bit define
2286 * BIT0: "0" for no antenna inverse; "1" for antenna inverse
2287 * BIT1: "0" for internal switch; "1" for external switch
2288 * BIT2: "0" for one antenna; "1" for two antenna
2289 * NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and
2292 if (btcoexist
->chip_interface
== BTC_INTF_USB
) {
2293 /* fixed at S0 for USB interface */
2294 btcoexist
->btc_write_4byte(btcoexist
, 0x948, 0x0);
2296 u8tmp
|= 0x1; /* antenna inverse */
2297 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0xfe08, u8tmp
);
2299 board_info
->btdm_ant_pos
= BTC_ANTENNA_AT_AUX_PORT
;
2301 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
2302 if (board_info
->single_ant_path
== 0) {
2304 btcoexist
->btc_write_4byte(btcoexist
, 0x948, 0x280);
2305 board_info
->btdm_ant_pos
= BTC_ANTENNA_AT_MAIN_PORT
;
2307 } else if (board_info
->single_ant_path
== 1) {
2309 btcoexist
->btc_write_4byte(btcoexist
, 0x948, 0x0);
2310 u8tmp
|= 0x1; /* antenna inverse */
2311 board_info
->btdm_ant_pos
= BTC_ANTENNA_AT_AUX_PORT
;
2315 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_ANTPOSREGRISTRY_CTRL
,
2318 if (btcoexist
->chip_interface
== BTC_INTF_PCI
)
2319 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0x384,
2321 else if (btcoexist
->chip_interface
== BTC_INTF_SDIO
)
2322 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0x60,
2328 void ex_halbtc8723b1ant_init_hwconfig(struct btc_coexist
*btcoexist
,
2331 halbtc8723b1ant_init_hw_config(btcoexist
, true, wifi_only
);
2332 btcoexist
->stop_coex_dm
= false;
2335 void ex_halbtc8723b1ant_init_coex_dm(struct btc_coexist
*btcoexist
)
2337 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2339 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2340 "[BTCoex], Coex Mechanism Init!!\n");
2342 btcoexist
->stop_coex_dm
= false;
2344 halbtc8723b1ant_init_coex_dm(btcoexist
);
2346 halbtc8723b1ant_query_bt_info(btcoexist
);
2349 void ex_halbtc8723b1ant_display_coex_info(struct btc_coexist
*btcoexist
)
2351 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
2352 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
2353 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
2354 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2355 u8 u8tmp
[4], i
, bt_info_ext
, pstdmacase
= 0;
2358 bool roam
= false, scan
= false;
2359 bool link
= false, wifi_under_5g
= false;
2360 bool bt_hs_on
= false, wifi_busy
= false;
2361 s32 wifi_rssi
= 0, bt_hs_rssi
= 0;
2362 u32 wifi_bw
, wifi_traffic_dir
, fa_ofdm
, fa_cck
, wifi_link_status
;
2363 u8 wifi_dot11_chnl
, wifi_hs_chnl
;
2364 u32 fw_ver
= 0, bt_patch_ver
= 0;
2366 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2367 "\r\n ============[BT Coexist info]============");
2369 if (btcoexist
->manual_control
) {
2370 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2371 "\r\n ============[Under Manual Control]==========");
2372 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2373 "\r\n ==========================================");
2375 if (btcoexist
->stop_coex_dm
) {
2376 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2377 "\r\n ============[Coex is STOPPED]============");
2378 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2379 "\r\n ==========================================");
2382 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d/ %d",
2383 "Ant PG Num/ Ant Mech/ Ant Pos:",
2384 board_info
->pg_ant_num
, board_info
->btdm_ant_num
,
2385 board_info
->btdm_ant_pos
);
2387 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %s / %d",
2388 "BT stack/ hci ext ver",
2389 ((stack_info
->profile_notified
) ? "Yes" : "No"),
2390 stack_info
->hci_version
);
2392 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
, &bt_patch_ver
);
2393 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
2394 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2395 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
2396 "CoexVer/ FwVer/ PatchVer",
2397 glcoex_ver_date_8723b_1ant
, glcoex_ver_8723b_1ant
,
2398 fw_ver
, bt_patch_ver
, bt_patch_ver
);
2400 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2401 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_DOT11_CHNL
,
2403 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_HS_CHNL
, &wifi_hs_chnl
);
2404 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d / %d(%d)",
2405 "Dot11 channel / HsChnl(HsMode)",
2406 wifi_dot11_chnl
, wifi_hs_chnl
, bt_hs_on
);
2408 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %3ph ",
2409 "H2C Wifi inform bt chnl Info",
2410 coex_dm
->wifi_chnl_info
);
2412 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
2413 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_HS_RSSI
, &bt_hs_rssi
);
2414 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d",
2415 "Wifi rssi/ HS rssi", wifi_rssi
, bt_hs_rssi
);
2417 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2418 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2419 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2420 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d/ %d ",
2421 "Wifi link/ roam/ scan", link
, roam
, scan
);
2423 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
,
2425 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2426 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
2427 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION
,
2430 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %s / %s/ %s ",
2431 "Wifi status", (wifi_under_5g
? "5G" : "2.4G"),
2432 ((wifi_bw
== BTC_WIFI_BW_LEGACY
) ? "Legacy" :
2433 ((wifi_bw
== BTC_WIFI_BW_HT40
) ? "HT40" : "HT20")),
2434 ((!wifi_busy
) ? "idle" :
2435 ((wifi_traffic_dir
== BTC_WIFI_TRAFFIC_TX
) ?
2436 "uplink" : "downlink")));
2438 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2440 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
2441 "sta/vwifi/hs/p2pGo/p2pGc",
2442 ((wifi_link_status
& WIFI_STA_CONNECTED
) ? 1 : 0),
2443 ((wifi_link_status
& WIFI_AP_CONNECTED
) ? 1 : 0),
2444 ((wifi_link_status
& WIFI_HS_CONNECTED
) ? 1 : 0),
2445 ((wifi_link_status
& WIFI_P2P_GO_CONNECTED
) ? 1 : 0),
2446 ((wifi_link_status
& WIFI_P2P_GC_CONNECTED
) ? 1 : 0));
2448 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = [%s/ %d/ %d] ",
2449 "BT [status/ rssi/ retryCnt]",
2450 ((coex_sta
->bt_disabled
) ? ("disabled") :
2451 ((coex_sta
->c2h_bt_inquiry_page
) ? ("inquiry/page scan") :
2452 ((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE
==
2453 coex_dm
->bt_status
) ?
2454 "non-connected idle" :
2455 ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
==
2456 coex_dm
->bt_status
) ?
2457 "connected-idle" : "busy")))),
2458 coex_sta
->bt_rssi
, coex_sta
->bt_retry_cnt
);
2460 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2461 "\r\n %-35s = %d / %d / %d / %d",
2462 "SCO/HID/PAN/A2DP", bt_link_info
->sco_exist
,
2463 bt_link_info
->hid_exist
, bt_link_info
->pan_exist
,
2464 bt_link_info
->a2dp_exist
);
2465 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_BT_LINK_INFO
);
2467 bt_info_ext
= coex_sta
->bt_info_ext
;
2468 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %s",
2469 "BT Info A2DP rate",
2470 (bt_info_ext
& BIT0
) ? "Basic rate" : "EDR rate");
2472 for (i
= 0; i
< BT_INFO_SRC_8723B_1ANT_MAX
; i
++) {
2473 if (coex_sta
->bt_info_c2h_cnt
[i
]) {
2474 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2475 "\r\n %-35s = %7ph(%d)",
2476 glbt_info_src_8723b_1ant
[i
],
2477 coex_sta
->bt_info_c2h
[i
],
2478 coex_sta
->bt_info_c2h_cnt
[i
]);
2481 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2482 "\r\n %-35s = %s/%s, (0x%x/0x%x)",
2483 "PS state, IPS/LPS, (lps/rpwm)",
2484 ((coex_sta
->under_ips
? "IPS ON" : "IPS OFF")),
2485 ((coex_sta
->under_lps
? "LPS ON" : "LPS OFF")),
2486 btcoexist
->bt_info
.lps_val
,
2487 btcoexist
->bt_info
.rpwm_val
);
2488 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_FW_PWR_MODE_CMD
);
2490 if (!btcoexist
->manual_control
) {
2492 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s",
2493 "============[Sw mechanism]============");
2495 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/",
2496 "SM[LowPenaltyRA]", coex_dm
->cur_low_penalty_ra
);
2498 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %s/ %s/ %d ",
2499 "DelBA/ BtCtrlAgg/ AggSize",
2500 (btcoexist
->bt_info
.reject_agg_pkt
? "Yes" : "No"),
2501 (btcoexist
->bt_info
.bt_ctrl_buf_size
? "Yes" : "No"),
2502 btcoexist
->bt_info
.agg_buf_size
);
2504 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x ",
2505 "Rate Mask", btcoexist
->bt_info
.ra_mask
);
2508 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s",
2509 "============[Fw mechanism]============");
2511 pstdmacase
= coex_dm
->cur_ps_tdma
;
2512 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2513 "\r\n %-35s = %5ph case-%d (auto:%d)",
2514 "PS TDMA", coex_dm
->ps_tdma_para
,
2515 pstdmacase
, coex_dm
->auto_tdma_adjust
);
2517 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d ",
2518 "IgnWlanAct", coex_dm
->cur_ignore_wlan_act
);
2520 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x ",
2521 "Latest error condition(should be 0)",
2522 coex_dm
->error_condition
);
2525 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d",
2526 "Coex Table Type", coex_sta
->coex_table_type
);
2529 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s",
2530 "============[Hw setting]============");
2532 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2533 "backup ARFR1/ARFR2/RL/AMaxTime", coex_dm
->backup_arfr_cnt1
,
2534 coex_dm
->backup_arfr_cnt2
, coex_dm
->backup_retry_limit
,
2535 coex_dm
->backup_ampdu_max_time
);
2537 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x430);
2538 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x434);
2539 u16tmp
[0] = btcoexist
->btc_read_2byte(btcoexist
, 0x42a);
2540 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x456);
2541 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2542 "0x430/0x434/0x42a/0x456",
2543 u32tmp
[0], u32tmp
[1], u16tmp
[0], u8tmp
[0]);
2545 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x778);
2546 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x6cc);
2547 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x880);
2548 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2549 "0x778/0x6cc/0x880[29:25]", u8tmp
[0], u32tmp
[0],
2550 (u32tmp
[1] & 0x3e000000) >> 25);
2552 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x948);
2553 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x67);
2554 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x765);
2555 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2556 "0x948/ 0x67[5] / 0x765",
2557 u32tmp
[0], ((u8tmp
[0] & 0x20) >> 5), u8tmp
[1]);
2559 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x92c);
2560 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x930);
2561 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x944);
2562 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2563 "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
2564 u32tmp
[0] & 0x3, u32tmp
[1] & 0xff, u32tmp
[2] & 0x3);
2566 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x39);
2567 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x40);
2568 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
2569 u8tmp
[2] = btcoexist
->btc_read_1byte(btcoexist
, 0x64);
2570 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2571 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
2572 "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
2573 ((u8tmp
[0] & 0x8) >> 3), u8tmp
[1],
2574 ((u32tmp
[0] & 0x01800000) >> 23), u8tmp
[2] & 0x1);
2576 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x550);
2577 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x522);
2578 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x",
2579 "0x550(bcn ctrl)/0x522", u32tmp
[0], u8tmp
[0]);
2581 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xc50);
2582 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x49c);
2583 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x",
2584 "0xc50(dig)/0x49c(null-drop)", u32tmp
[0] & 0xff, u8tmp
[0]);
2586 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xda0);
2587 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0xda4);
2588 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0xda8);
2589 u32tmp
[3] = btcoexist
->btc_read_4byte(btcoexist
, 0xcf0);
2591 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5b);
2592 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5c);
2594 fa_ofdm
= ((u32tmp
[0] & 0xffff0000) >> 16) +
2595 ((u32tmp
[1] & 0xffff0000) >> 16) +
2596 (u32tmp
[1] & 0xffff) +
2597 (u32tmp
[2] & 0xffff) +
2598 ((u32tmp
[3] & 0xffff0000) >> 16) +
2599 (u32tmp
[3] & 0xffff);
2600 fa_cck
= (u8tmp
[0] << 8) + u8tmp
[1];
2602 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2603 "OFDM-CCA/OFDM-FA/CCK-FA",
2604 u32tmp
[0] & 0xffff, fa_ofdm
, fa_cck
);
2606 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c0);
2607 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c4);
2608 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c8);
2609 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2610 "0x6c0/0x6c4/0x6c8(coexTable)",
2611 u32tmp
[0], u32tmp
[1], u32tmp
[2]);
2613 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d",
2614 "0x770(high-pri rx/tx)", coex_sta
->high_priority_rx
,
2615 coex_sta
->high_priority_tx
);
2616 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d",
2617 "0x774(low-pri rx/tx)", coex_sta
->low_priority_rx
,
2618 coex_sta
->low_priority_tx
);
2619 if (btcoexist
->auto_report_1ant
)
2620 halbtc8723b1ant_monitor_bt_ctr(btcoexist
);
2621 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_COEX_STATISTICS
);
2624 void ex_halbtc8723b1ant_ips_notify(struct btc_coexist
*btcoexist
, u8 type
)
2626 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2628 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
)
2631 if (BTC_IPS_ENTER
== type
) {
2632 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2633 "[BTCoex], IPS ENTER notify\n");
2634 coex_sta
->under_ips
= true;
2636 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
,
2637 FORCE_EXEC
, false, true);
2638 /* set PTA control */
2639 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
2640 halbtc8723b1ant_coex_table_with_type(btcoexist
,
2642 } else if (BTC_IPS_LEAVE
== type
) {
2643 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2644 "[BTCoex], IPS LEAVE notify\n");
2645 coex_sta
->under_ips
= false;
2647 halbtc8723b1ant_init_hw_config(btcoexist
, false, false);
2648 halbtc8723b1ant_init_coex_dm(btcoexist
);
2649 halbtc8723b1ant_query_bt_info(btcoexist
);
2653 void ex_halbtc8723b1ant_lps_notify(struct btc_coexist
*btcoexist
, u8 type
)
2655 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2657 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
)
2660 if (BTC_LPS_ENABLE
== type
) {
2661 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2662 "[BTCoex], LPS ENABLE notify\n");
2663 coex_sta
->under_lps
= true;
2664 } else if (BTC_LPS_DISABLE
== type
) {
2665 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2666 "[BTCoex], LPS DISABLE notify\n");
2667 coex_sta
->under_lps
= false;
2671 void ex_halbtc8723b1ant_scan_notify(struct btc_coexist
*btcoexist
, u8 type
)
2673 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2674 bool wifi_connected
= false, bt_hs_on
= false;
2677 u32 wifi_link_status
= 0;
2678 u32 num_of_wifi_link
= 0;
2679 bool bt_ctrl_agg_buf_size
= false;
2680 u8 agg_buf_size
= 5;
2682 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
)
2685 if (type
== BTC_SCAN_START
) {
2686 coex_sta
->wifi_is_high_pri_task
= true;
2687 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2688 "[BTCoex], SCAN START notify\n");
2689 /* Force antenna setup for no scan result issue */
2690 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
2691 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
2692 FORCE_EXEC
, false, false);
2693 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x948);
2694 u8tmpa
= btcoexist
->btc_read_1byte(btcoexist
, 0x765);
2695 u8tmpb
= btcoexist
->btc_read_1byte(btcoexist
, 0x67);
2697 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2698 "[BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
2699 u32tmp
, u8tmpa
, u8tmpb
);
2701 coex_sta
->wifi_is_high_pri_task
= false;
2702 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2703 "[BTCoex], SCAN FINISH notify\n");
2705 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_AP_NUM
,
2706 &coex_sta
->scan_ap_num
);
2709 if (coex_sta
->bt_disabled
)
2712 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2713 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
2716 halbtc8723b1ant_query_bt_info(btcoexist
);
2718 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2720 num_of_wifi_link
= wifi_link_status
>> 16;
2721 if (num_of_wifi_link
>= 2) {
2722 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2723 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2724 bt_ctrl_agg_buf_size
, agg_buf_size
);
2725 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
2729 if (coex_sta
->c2h_bt_inquiry_page
) {
2730 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2732 } else if (bt_hs_on
) {
2733 halbtc8723b1ant_action_hs(btcoexist
);
2737 if (BTC_SCAN_START
== type
) {
2738 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2739 "[BTCoex], SCAN START notify\n");
2740 if (!wifi_connected
)
2741 /* non-connected scan */
2742 btc8723b1ant_action_wifi_not_conn_scan(btcoexist
);
2744 /* wifi is connected */
2745 btc8723b1ant_action_wifi_conn_scan(btcoexist
);
2746 } else if (BTC_SCAN_FINISH
== type
) {
2747 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2748 "[BTCoex], SCAN FINISH notify\n");
2749 if (!wifi_connected
)
2750 /* non-connected scan */
2751 btc8723b1ant_action_wifi_not_conn(btcoexist
);
2753 halbtc8723b1ant_action_wifi_connected(btcoexist
);
2757 void ex_halbtc8723b1ant_connect_notify(struct btc_coexist
*btcoexist
, u8 type
)
2759 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2760 bool wifi_connected
= false, bt_hs_on
= false;
2761 u32 wifi_link_status
= 0;
2762 u32 num_of_wifi_link
= 0;
2763 bool bt_ctrl_agg_buf_size
= false, under_4way
= false;
2764 u8 agg_buf_size
= 5;
2766 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
2769 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2770 coex_sta
->bt_disabled
)
2773 if (type
== BTC_ASSOCIATE_START
) {
2774 coex_sta
->wifi_is_high_pri_task
= true;
2776 /* Force antenna setup for no scan result issue */
2777 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
2778 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
2779 FORCE_EXEC
, false, false);
2780 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2781 "[BTCoex], CONNECT START notify\n");
2782 coex_dm
->arp_cnt
= 0;
2784 coex_sta
->wifi_is_high_pri_task
= false;
2785 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2786 "[BTCoex], CONNECT FINISH notify\n");
2789 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2791 num_of_wifi_link
= wifi_link_status
>>16;
2792 if (num_of_wifi_link
>= 2) {
2793 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2794 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2795 bt_ctrl_agg_buf_size
, agg_buf_size
);
2796 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
2800 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2801 if (coex_sta
->c2h_bt_inquiry_page
) {
2802 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2804 } else if (bt_hs_on
) {
2805 halbtc8723b1ant_action_hs(btcoexist
);
2809 if (BTC_ASSOCIATE_START
== type
) {
2810 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2811 "[BTCoex], CONNECT START notify\n");
2812 btc8723b1ant_act_wifi_not_conn_asso_auth(btcoexist
);
2813 } else if (BTC_ASSOCIATE_FINISH
== type
) {
2814 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2815 "[BTCoex], CONNECT FINISH notify\n");
2817 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
2819 if (!wifi_connected
)
2820 /* non-connected scan */
2821 btc8723b1ant_action_wifi_not_conn(btcoexist
);
2823 halbtc8723b1ant_action_wifi_connected(btcoexist
);
2827 void ex_halbtc8723b1ant_media_status_notify(struct btc_coexist
*btcoexist
,
2830 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2831 u8 h2c_parameter
[3] = {0};
2833 u8 wifi_central_chnl
;
2834 bool wifi_under_b_mode
= false;
2836 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2837 coex_sta
->bt_disabled
)
2840 if (type
== BTC_MEDIA_CONNECT
) {
2841 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2842 "[BTCoex], MEDIA connect notify\n");
2843 /* Force antenna setup for no scan result issue */
2844 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
2845 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
2846 FORCE_EXEC
, false, false);
2847 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_B_MODE
,
2848 &wifi_under_b_mode
);
2850 /* Set CCK Tx/Rx high Pri except 11b mode */
2851 if (wifi_under_b_mode
) {
2852 btcoexist
->btc_write_1byte(btcoexist
, 0x6cd,
2854 btcoexist
->btc_write_1byte(btcoexist
, 0x6cf,
2857 btcoexist
->btc_write_1byte(btcoexist
, 0x6cd,
2859 btcoexist
->btc_write_1byte(btcoexist
, 0x6cf,
2863 coex_dm
->backup_arfr_cnt1
=
2864 btcoexist
->btc_read_4byte(btcoexist
, 0x430);
2865 coex_dm
->backup_arfr_cnt2
=
2866 btcoexist
->btc_read_4byte(btcoexist
, 0x434);
2867 coex_dm
->backup_retry_limit
=
2868 btcoexist
->btc_read_2byte(btcoexist
, 0x42a);
2869 coex_dm
->backup_ampdu_max_time
=
2870 btcoexist
->btc_read_1byte(btcoexist
, 0x456);
2872 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2873 "[BTCoex], MEDIA disconnect notify\n");
2874 coex_dm
->arp_cnt
= 0;
2876 btcoexist
->btc_write_1byte(btcoexist
, 0x6cd, 0x0); /* CCK Tx */
2877 btcoexist
->btc_write_1byte(btcoexist
, 0x6cf, 0x0); /* CCK Rx */
2879 coex_sta
->cck_ever_lock
= false;
2882 /* only 2.4G we need to inform bt the chnl mask */
2883 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_CENTRAL_CHNL
,
2884 &wifi_central_chnl
);
2886 if (type
== BTC_MEDIA_CONNECT
&& wifi_central_chnl
<= 14) {
2887 h2c_parameter
[0] = 0x0;
2888 h2c_parameter
[1] = wifi_central_chnl
;
2889 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2890 if (BTC_WIFI_BW_HT40
== wifi_bw
)
2891 h2c_parameter
[2] = 0x30;
2893 h2c_parameter
[2] = 0x20;
2896 coex_dm
->wifi_chnl_info
[0] = h2c_parameter
[0];
2897 coex_dm
->wifi_chnl_info
[1] = h2c_parameter
[1];
2898 coex_dm
->wifi_chnl_info
[2] = h2c_parameter
[2];
2900 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2901 "[BTCoex], FW write 0x66 = 0x%x\n",
2902 h2c_parameter
[0] << 16 | h2c_parameter
[1] << 8 |
2905 btcoexist
->btc_fill_h2c(btcoexist
, 0x66, 3, h2c_parameter
);
2908 void ex_halbtc8723b1ant_special_packet_notify(struct btc_coexist
*btcoexist
,
2911 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2912 bool bt_hs_on
= false;
2913 u32 wifi_link_status
= 0;
2914 u32 num_of_wifi_link
= 0;
2915 bool bt_ctrl_agg_buf_size
= false, under_4way
= false;
2916 u8 agg_buf_size
= 5;
2918 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
2921 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2922 coex_sta
->bt_disabled
)
2925 if (type
== BTC_PACKET_DHCP
|| type
== BTC_PACKET_EAPOL
||
2926 type
== BTC_PACKET_ARP
) {
2927 if (type
== BTC_PACKET_ARP
) {
2928 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2929 "[BTCoex], special Packet ARP notify\n");
2932 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2933 "[BTCoex], ARP Packet Count = %d\n",
2936 if ((coex_dm
->arp_cnt
>= 10) && (!under_4way
))
2937 /* if APR PKT > 10 after connect, do not go to
2938 * ActionWifiConnectedSpecificPacket(btcoexist)
2940 coex_sta
->wifi_is_high_pri_task
= false;
2942 coex_sta
->wifi_is_high_pri_task
= true;
2944 coex_sta
->wifi_is_high_pri_task
= true;
2945 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2946 "[BTCoex], special Packet DHCP or EAPOL notify\n");
2949 coex_sta
->wifi_is_high_pri_task
= false;
2950 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2951 "[BTCoex], special Packet [Type = %d] notify\n",
2955 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2957 num_of_wifi_link
= wifi_link_status
>> 16;
2958 if (num_of_wifi_link
>= 2) {
2959 halbtc8723b1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2960 halbtc8723b1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2961 bt_ctrl_agg_buf_size
, agg_buf_size
);
2962 halbtc8723b1ant_action_wifi_multiport(btcoexist
);
2966 coex_sta
->special_pkt_period_cnt
= 0;
2968 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2969 if (coex_sta
->c2h_bt_inquiry_page
) {
2970 halbtc8723b1ant_action_bt_inquiry(btcoexist
);
2972 } else if (bt_hs_on
) {
2973 halbtc8723b1ant_action_hs(btcoexist
);
2977 if (BTC_PACKET_DHCP
== type
||
2978 BTC_PACKET_EAPOL
== type
) {
2979 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2980 "[BTCoex], special Packet(%d) notify\n", type
);
2981 halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist
);
2985 void ex_halbtc8723b1ant_bt_info_notify(struct btc_coexist
*btcoexist
,
2986 u8
*tmp_buf
, u8 length
)
2988 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2990 u8 i
, rsp_source
= 0;
2991 bool wifi_connected
= false;
2992 bool bt_busy
= false;
2994 coex_sta
->c2h_bt_info_req_sent
= false;
2996 rsp_source
= tmp_buf
[0] & 0xf;
2997 if (rsp_source
>= BT_INFO_SRC_8723B_1ANT_MAX
)
2998 rsp_source
= BT_INFO_SRC_8723B_1ANT_WIFI_FW
;
2999 coex_sta
->bt_info_c2h_cnt
[rsp_source
]++;
3001 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3002 "[BTCoex], Bt info[%d], length=%d, hex data = [",
3003 rsp_source
, length
);
3004 for (i
= 0; i
< length
; i
++) {
3005 coex_sta
->bt_info_c2h
[rsp_source
][i
] = tmp_buf
[i
];
3007 bt_info
= tmp_buf
[i
];
3008 if (i
== length
- 1)
3009 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3010 "0x%02x]\n", tmp_buf
[i
]);
3012 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3013 "0x%02x, ", tmp_buf
[i
]);
3016 /* if 0xff, it means BT is under WHCK test */
3017 if (bt_info
== 0xff)
3018 coex_sta
->bt_whck_test
= true;
3020 coex_sta
->bt_whck_test
= false;
3022 if (rsp_source
!= BT_INFO_SRC_8723B_1ANT_WIFI_FW
) {
3023 coex_sta
->bt_retry_cnt
= /* [3:0] */
3024 coex_sta
->bt_info_c2h
[rsp_source
][2] & 0xf;
3026 if (coex_sta
->bt_retry_cnt
>= 1)
3027 coex_sta
->pop_event_cnt
++;
3029 if (coex_sta
->bt_info_c2h
[rsp_source
][2] & 0x20)
3030 coex_sta
->c2h_bt_remote_name_req
= true;
3032 coex_sta
->c2h_bt_remote_name_req
= false;
3035 coex_sta
->bt_info_c2h
[rsp_source
][3] * 2 - 90;
3037 coex_sta
->bt_info_ext
=
3038 coex_sta
->bt_info_c2h
[rsp_source
][4];
3040 if (coex_sta
->bt_info_c2h
[rsp_source
][1] == 0x49) {
3041 coex_sta
->a2dp_bit_pool
=
3042 coex_sta
->bt_info_c2h
[rsp_source
][6];
3044 coex_sta
->a2dp_bit_pool
= 0;
3047 coex_sta
->bt_tx_rx_mask
=
3048 (coex_sta
->bt_info_c2h
[rsp_source
][2] & 0x40);
3049 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TX_RX_MASK
,
3050 &coex_sta
->bt_tx_rx_mask
);
3052 if (!coex_sta
->bt_tx_rx_mask
) {
3053 /* BT into is responded by BT FW and BT RF REG
3054 * 0x3C != 0x15 => Need to switch BT TRx Mask
3056 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3057 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
3058 btcoexist
->btc_set_bt_reg(btcoexist
, BTC_BT_REG_RF
,
3061 /* BT TRx Mask lock 0x2c[0], 0x30[0] = 0 */
3062 btcoexist
->btc_set_bt_reg(btcoexist
, BTC_BT_REG_RF
,
3064 btcoexist
->btc_set_bt_reg(btcoexist
, BTC_BT_REG_RF
,
3068 /* Here we need to resend some wifi info to BT
3069 * because bt is reset and loss of the info.
3071 if (coex_sta
->bt_info_ext
& BIT1
) {
3072 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3073 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
3074 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
3077 ex_halbtc8723b1ant_media_status_notify(btcoexist
,
3080 ex_halbtc8723b1ant_media_status_notify(btcoexist
,
3081 BTC_MEDIA_DISCONNECT
);
3084 if (coex_sta
->bt_info_ext
& BIT3
) {
3085 if (!btcoexist
->manual_control
&&
3086 !btcoexist
->stop_coex_dm
) {
3087 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3088 "[BTCoex], BT ext info bit3 check, set BT NOT ignore Wlan active!!\n");
3089 halbtc8723b1ant_ignore_wlan_act(btcoexist
,
3094 /* BT already NOT ignore Wlan active, do nothing here.*/
3096 if (!btcoexist
->auto_report_1ant
) {
3097 if (coex_sta
->bt_info_ext
& BIT4
) {
3098 /* BT auto report already enabled, do nothing */
3100 halbtc8723b1ant_bt_auto_report(btcoexist
,
3107 /* check BIT2 first ==> check if bt is under inquiry or page scan */
3108 if (bt_info
& BT_INFO_8723B_1ANT_B_INQ_PAGE
)
3109 coex_sta
->c2h_bt_inquiry_page
= true;
3111 coex_sta
->c2h_bt_inquiry_page
= false;
3113 coex_sta
->num_of_profile
= 0;
3115 /* set link exist status */
3116 if (!(bt_info
& BT_INFO_8723B_1ANT_B_CONNECTION
)) {
3117 coex_sta
->bt_link_exist
= false;
3118 coex_sta
->pan_exist
= false;
3119 coex_sta
->a2dp_exist
= false;
3120 coex_sta
->hid_exist
= false;
3121 coex_sta
->sco_exist
= false;
3123 coex_sta
->bt_hi_pri_link_exist
= false;
3125 /* connection exists */
3126 coex_sta
->bt_link_exist
= true;
3127 if (bt_info
& BT_INFO_8723B_1ANT_B_FTP
) {
3128 coex_sta
->pan_exist
= true;
3129 coex_sta
->num_of_profile
++;
3131 coex_sta
->pan_exist
= false;
3133 if (bt_info
& BT_INFO_8723B_1ANT_B_A2DP
) {
3134 coex_sta
->a2dp_exist
= true;
3135 coex_sta
->num_of_profile
++;
3137 coex_sta
->a2dp_exist
= false;
3139 if (bt_info
& BT_INFO_8723B_1ANT_B_HID
) {
3140 coex_sta
->hid_exist
= true;
3141 coex_sta
->num_of_profile
++;
3143 coex_sta
->hid_exist
= false;
3145 if (bt_info
& BT_INFO_8723B_1ANT_B_SCO_ESCO
) {
3146 coex_sta
->sco_exist
= true;
3147 coex_sta
->num_of_profile
++;
3149 coex_sta
->sco_exist
= false;
3152 if ((!coex_sta
->hid_exist
) &&
3153 (!coex_sta
->c2h_bt_inquiry_page
) &&
3154 (!coex_sta
->sco_exist
)) {
3155 if (coex_sta
->high_priority_tx
+
3156 coex_sta
->high_priority_rx
>=
3158 coex_sta
->hid_exist
= true;
3159 coex_sta
->wrong_profile_notification
++;
3160 coex_sta
->num_of_profile
++;
3161 bt_info
= bt_info
| 0x28;
3165 /* Add Hi-Pri Tx/Rx counter to avoid false detection */
3166 if (((coex_sta
->hid_exist
) || (coex_sta
->sco_exist
)) &&
3167 (coex_sta
->high_priority_tx
+ coex_sta
->high_priority_rx
>=
3169 (!coex_sta
->c2h_bt_inquiry_page
))
3170 coex_sta
->bt_hi_pri_link_exist
= true;
3172 if ((bt_info
& BT_INFO_8723B_1ANT_B_ACL_BUSY
) &&
3173 (coex_sta
->num_of_profile
== 0)) {
3174 if (coex_sta
->low_priority_tx
+
3175 coex_sta
->low_priority_rx
>=
3177 coex_sta
->pan_exist
= true;
3178 coex_sta
->num_of_profile
++;
3179 coex_sta
->wrong_profile_notification
++;
3180 bt_info
= bt_info
| 0x88;
3185 halbtc8723b1ant_update_bt_link_info(btcoexist
);
3187 /* mask profile bit for connect-ilde identification
3188 * ( for CSR case: A2DP idle --> 0x41)
3190 bt_info
= bt_info
& 0x1f;
3192 if (!(bt_info
& BT_INFO_8723B_1ANT_B_CONNECTION
)) {
3193 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE
;
3194 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3195 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!\n");
3196 /* connection exists but no busy */
3197 } else if (bt_info
== BT_INFO_8723B_1ANT_B_CONNECTION
) {
3198 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE
;
3199 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3200 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
3201 } else if ((bt_info
& BT_INFO_8723B_1ANT_B_SCO_ESCO
) ||
3202 (bt_info
& BT_INFO_8723B_1ANT_B_SCO_BUSY
)) {
3203 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_SCO_BUSY
;
3204 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3205 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
3206 } else if (bt_info
& BT_INFO_8723B_1ANT_B_ACL_BUSY
) {
3207 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY
!= coex_dm
->bt_status
)
3208 coex_dm
->auto_tdma_adjust
= false;
3210 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_ACL_BUSY
;
3211 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3212 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
3214 coex_dm
->bt_status
= BT_8723B_1ANT_BT_STATUS_MAX
;
3215 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3216 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!\n");
3219 if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) ||
3220 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY
== coex_dm
->bt_status
) ||
3221 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY
== coex_dm
->bt_status
))
3225 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TRAFFIC_BUSY
, &bt_busy
);
3227 halbtc8723b1ant_run_coexist_mechanism(btcoexist
);
3230 void ex_halbtc8723b1ant_rf_status_notify(struct btc_coexist
*btcoexist
, u8 type
)
3232 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3234 u8 u8tmpa
, u8tmpb
, u8tmpc
;
3236 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3237 "[BTCoex], RF Status notify\n");
3239 if (type
== BTC_RF_ON
) {
3240 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3241 "[BTCoex], RF is turned ON!!\n");
3242 btcoexist
->stop_coex_dm
= false;
3243 } else if (type
== BTC_RF_OFF
) {
3244 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3245 "[BTCoex], RF is turned OFF!!\n");
3247 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3249 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 0);
3250 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
,
3251 FORCE_EXEC
, false, true);
3253 halbtc8723b1ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
3254 btcoexist
->stop_coex_dm
= true;
3256 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x948);
3257 u8tmpa
= btcoexist
->btc_read_1byte(btcoexist
, 0x765);
3258 u8tmpb
= btcoexist
->btc_read_1byte(btcoexist
, 0x67);
3259 u8tmpc
= btcoexist
->btc_read_1byte(btcoexist
, 0x76e);
3261 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3262 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x, 0x76e=0x%x\n",
3263 u32tmp
, u8tmpa
, u8tmpb
, u8tmpc
);
3267 void ex_halbtc8723b1ant_halt_notify(struct btc_coexist
*btcoexist
)
3269 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3271 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
, "[BTCoex], Halt notify\n");
3273 btcoexist
->stop_coex_dm
= true;
3275 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
, FORCE_EXEC
,
3278 halbtc8723b1ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
3280 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3282 halbtc8723b1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 0);
3284 ex_halbtc8723b1ant_media_status_notify(btcoexist
, BTC_MEDIA_DISCONNECT
);
3286 btcoexist
->stop_coex_dm
= true;
3289 void ex_halbtc8723b1ant_pnp_notify(struct btc_coexist
*btcoexist
, u8 pnp_state
)
3291 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3293 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
, "[BTCoex], Pnp notify\n");
3295 if (BTC_WIFI_PNP_SLEEP
== pnp_state
) {
3296 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3297 "[BTCoex], Pnp notify to SLEEP\n");
3298 halbtc8723b1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
,
3299 FORCE_EXEC
, false, true);
3300 halbtc8723b1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3302 halbtc8723b1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
3303 halbtc8723b1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
3305 /* Driver do not leave IPS/LPS when driver is going to sleep, so
3306 * BTCoexistence think wifi is still under IPS/LPS
3308 * BT should clear UnderIPS/UnderLPS state to avoid mismatch
3309 * state after wakeup.
3311 coex_sta
->under_ips
= false;
3312 coex_sta
->under_lps
= false;
3313 btcoexist
->stop_coex_dm
= true;
3314 } else if (BTC_WIFI_PNP_WAKE_UP
== pnp_state
) {
3315 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3316 "[BTCoex], Pnp notify to WAKE UP\n");
3317 btcoexist
->stop_coex_dm
= false;
3318 halbtc8723b1ant_init_hw_config(btcoexist
, false, false);
3319 halbtc8723b1ant_init_coex_dm(btcoexist
);
3320 halbtc8723b1ant_query_bt_info(btcoexist
);
3324 void ex_halbtc8723b1ant_coex_dm_reset(struct btc_coexist
*btcoexist
)
3326 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3328 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3329 "[BTCoex], *****************Coex DM Reset****************\n");
3331 halbtc8723b1ant_init_hw_config(btcoexist
, false, false);
3332 halbtc8723b1ant_init_coex_dm(btcoexist
);
3335 void ex_halbtc8723b1ant_periodical(struct btc_coexist
*btcoexist
)
3337 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3338 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
3340 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3341 "[BTCoex], ==========================Periodical===========================\n");
3343 if (!btcoexist
->auto_report_1ant
) {
3344 halbtc8723b1ant_query_bt_info(btcoexist
);
3345 halbtc8723b1ant_monitor_bt_enable_disable(btcoexist
);
3347 halbtc8723b1ant_monitor_bt_ctr(btcoexist
);
3348 halbtc8723b1ant_monitor_wifi_ctr(btcoexist
);
3350 if ((coex_sta
->high_priority_tx
+ coex_sta
->high_priority_rx
< 50) &&
3351 bt_link_info
->hid_exist
)
3352 bt_link_info
->hid_exist
= false;
3354 if (btc8723b1ant_is_wifi_status_changed(btcoexist
) ||
3355 coex_dm
->auto_tdma_adjust
) {
3356 halbtc8723b1ant_run_coexist_mechanism(btcoexist
);
3358 coex_sta
->special_pkt_period_cnt
++;