1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2012 Realtek Corporation.*/
4 /***************************************************************
7 * This file is for RTL8723B Co-exist mechanism
10 * 2012/11/15 Cosa first check in.
12 **************************************************************/
13 /**************************************************************
15 **************************************************************/
16 #include "halbt_precomp.h"
17 /**************************************************************
18 * Global variables, these are static variables
19 **************************************************************/
20 static struct coex_dm_8723b_2ant glcoex_dm_8723b_2ant
;
21 static struct coex_dm_8723b_2ant
*coex_dm
= &glcoex_dm_8723b_2ant
;
22 static struct coex_sta_8723b_2ant glcoex_sta_8723b_2ant
;
23 static struct coex_sta_8723b_2ant
*coex_sta
= &glcoex_sta_8723b_2ant
;
25 static const char *const glbt_info_src_8723b_2ant
[] = {
28 "BT Info[bt auto report]",
31 static u32 glcoex_ver_date_8723b_2ant
= 20131113;
32 static u32 glcoex_ver_8723b_2ant
= 0x3f;
34 /**************************************************************
35 * local function proto type if needed
36 **************************************************************/
37 /**************************************************************
38 * local function start with btc8723b2ant_
39 **************************************************************/
40 static u8
btc8723b2ant_bt_rssi_state(struct btc_coexist
*btcoexist
,
41 u8 level_num
, u8 rssi_thresh
,
44 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
46 u8 bt_rssi_state
= coex_sta
->pre_bt_rssi_state
;
48 bt_rssi
= coex_sta
->bt_rssi
;
51 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
52 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
53 if (bt_rssi
>= rssi_thresh
+
54 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
55 bt_rssi_state
= BTC_RSSI_STATE_HIGH
;
56 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
57 "[BTCoex], BT Rssi state switch to High\n");
59 bt_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
60 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
61 "[BTCoex], BT Rssi state stay at Low\n");
64 if (bt_rssi
< rssi_thresh
) {
65 bt_rssi_state
= BTC_RSSI_STATE_LOW
;
66 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
67 "[BTCoex], BT Rssi state switch to Low\n");
69 bt_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
70 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
71 "[BTCoex], BT Rssi state stay at High\n");
74 } else if (level_num
== 3) {
75 if (rssi_thresh
> rssi_thresh1
) {
76 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
77 "[BTCoex], BT Rssi thresh error!!\n");
78 return coex_sta
->pre_bt_rssi_state
;
81 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
82 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
83 if (bt_rssi
>= rssi_thresh
+
84 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
85 bt_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
86 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
87 "[BTCoex], BT Rssi state switch to Medium\n");
89 bt_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
90 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
91 "[BTCoex], BT Rssi state stay at Low\n");
93 } else if ((coex_sta
->pre_bt_rssi_state
==
94 BTC_RSSI_STATE_MEDIUM
) ||
95 (coex_sta
->pre_bt_rssi_state
==
96 BTC_RSSI_STATE_STAY_MEDIUM
)) {
97 if (bt_rssi
>= rssi_thresh1
+
98 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
99 bt_rssi_state
= BTC_RSSI_STATE_HIGH
;
100 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
101 "[BTCoex], BT Rssi state switch to High\n");
102 } else if (bt_rssi
< rssi_thresh
) {
103 bt_rssi_state
= BTC_RSSI_STATE_LOW
;
104 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
105 "[BTCoex], BT Rssi state switch to Low\n");
107 bt_rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
108 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
109 "[BTCoex], BT Rssi state stay at Medium\n");
112 if (bt_rssi
< rssi_thresh1
) {
113 bt_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
114 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
115 "[BTCoex], BT Rssi state switch to Medium\n");
117 bt_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
118 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
119 "[BTCoex], BT Rssi state stay at High\n");
124 coex_sta
->pre_bt_rssi_state
= bt_rssi_state
;
126 return bt_rssi_state
;
129 static u8
btc8723b2ant_wifi_rssi_state(struct btc_coexist
*btcoexist
,
130 u8 index
, u8 level_num
,
131 u8 rssi_thresh
, u8 rssi_thresh1
)
133 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
135 u8 wifi_rssi_state
= coex_sta
->pre_wifi_rssi_state
[index
];
137 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
139 if (level_num
== 2) {
140 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
141 BTC_RSSI_STATE_LOW
) ||
142 (coex_sta
->pre_wifi_rssi_state
[index
] ==
143 BTC_RSSI_STATE_STAY_LOW
)) {
144 if (wifi_rssi
>= rssi_thresh
+
145 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
146 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
147 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
148 "[BTCoex], wifi RSSI state switch to High\n");
150 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
151 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
152 "[BTCoex], wifi RSSI state stay at Low\n");
155 if (wifi_rssi
< rssi_thresh
) {
156 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
157 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
158 "[BTCoex], wifi RSSI state switch to Low\n");
160 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
161 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
162 "[BTCoex], wifi RSSI state stay at High\n");
165 } else if (level_num
== 3) {
166 if (rssi_thresh
> rssi_thresh1
) {
167 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
168 "[BTCoex], wifi RSSI thresh error!!\n");
169 return coex_sta
->pre_wifi_rssi_state
[index
];
172 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
173 BTC_RSSI_STATE_LOW
) ||
174 (coex_sta
->pre_wifi_rssi_state
[index
] ==
175 BTC_RSSI_STATE_STAY_LOW
)) {
176 if (wifi_rssi
>= rssi_thresh
+
177 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
178 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
179 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
180 "[BTCoex], wifi RSSI state switch to Medium\n");
182 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
183 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
184 "[BTCoex], wifi RSSI state stay at Low\n");
186 } else if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
187 BTC_RSSI_STATE_MEDIUM
) ||
188 (coex_sta
->pre_wifi_rssi_state
[index
] ==
189 BTC_RSSI_STATE_STAY_MEDIUM
)) {
190 if (wifi_rssi
>= rssi_thresh1
+
191 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT
) {
192 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
193 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
194 "[BTCoex], wifi RSSI state switch to High\n");
195 } else if (wifi_rssi
< rssi_thresh
) {
196 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
197 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
198 "[BTCoex], wifi RSSI state switch to Low\n");
200 wifi_rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
201 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
202 "[BTCoex], wifi RSSI state stay at Medium\n");
205 if (wifi_rssi
< rssi_thresh1
) {
206 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
207 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
208 "[BTCoex], wifi RSSI state switch to Medium\n");
210 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
211 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
212 "[BTCoex], wifi RSSI state stay at High\n");
217 coex_sta
->pre_wifi_rssi_state
[index
] = wifi_rssi_state
;
219 return wifi_rssi_state
;
223 void btc8723b2ant_limited_rx(struct btc_coexist
*btcoexist
, bool force_exec
,
224 bool rej_ap_agg_pkt
, bool bt_ctrl_agg_buf_size
,
227 bool reject_rx_agg
= rej_ap_agg_pkt
;
228 bool bt_ctrl_rx_agg_size
= bt_ctrl_agg_buf_size
;
229 u8 rx_agg_size
= agg_buf_size
;
231 /* ============================================ */
232 /* Rx Aggregation related setting */
233 /* ============================================ */
234 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_TO_REJ_AP_AGG_PKT
,
236 /* decide BT control aggregation buf size or not */
237 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_CTRL_AGG_SIZE
,
238 &bt_ctrl_rx_agg_size
);
239 /* aggregate buf size, only work when BT control Rx aggregate size */
240 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_AGG_BUF_SIZE
, &rx_agg_size
);
241 /* real update aggregation setting */
242 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_AGGREGATE_CTRL
, NULL
);
245 static void btc8723b2ant_monitor_bt_ctr(struct btc_coexist
*btcoexist
)
247 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
248 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
249 u32 reg_hp_txrx
, reg_lp_txrx
, u32tmp
;
250 u32 reg_hp_tx
= 0, reg_hp_rx
= 0;
251 u32 reg_lp_tx
= 0, reg_lp_rx
= 0;
256 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_hp_txrx
);
257 reg_hp_tx
= u32tmp
& MASKLWORD
;
258 reg_hp_rx
= (u32tmp
& MASKHWORD
) >> 16;
260 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_lp_txrx
);
261 reg_lp_tx
= u32tmp
& MASKLWORD
;
262 reg_lp_rx
= (u32tmp
& MASKHWORD
) >> 16;
264 coex_sta
->high_priority_tx
= reg_hp_tx
;
265 coex_sta
->high_priority_rx
= reg_hp_rx
;
266 coex_sta
->low_priority_tx
= reg_lp_tx
;
267 coex_sta
->low_priority_rx
= reg_lp_rx
;
269 if ((coex_sta
->low_priority_tx
> 1050) &&
270 (!coex_sta
->c2h_bt_inquiry_page
))
271 coex_sta
->pop_event_cnt
++;
273 if ((coex_sta
->low_priority_rx
>= 950) &&
274 (coex_sta
->low_priority_rx
>= coex_sta
->low_priority_tx
) &&
275 (!coex_sta
->under_ips
))
276 bt_link_info
->slave_role
= true;
278 bt_link_info
->slave_role
= false;
280 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
281 "[BTCoex], High Priority Tx/Rx(reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
282 reg_hp_txrx
, reg_hp_tx
, reg_hp_tx
, reg_hp_rx
, reg_hp_rx
);
283 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
284 "[BTCoex], Low Priority Tx/Rx(reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
285 reg_lp_txrx
, reg_lp_tx
, reg_lp_tx
, reg_lp_rx
, reg_lp_rx
);
288 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
291 static void btc8723b2ant_monitor_wifi_ctr(struct btc_coexist
*btcoexist
)
293 if (coex_sta
->under_ips
) {
294 coex_sta
->crc_ok_cck
= 0;
295 coex_sta
->crc_ok_11g
= 0;
296 coex_sta
->crc_ok_11n
= 0;
297 coex_sta
->crc_ok_11n_agg
= 0;
299 coex_sta
->crc_err_cck
= 0;
300 coex_sta
->crc_err_11g
= 0;
301 coex_sta
->crc_err_11n
= 0;
302 coex_sta
->crc_err_11n_agg
= 0;
304 coex_sta
->crc_ok_cck
=
305 btcoexist
->btc_read_4byte(btcoexist
, 0xf88);
306 coex_sta
->crc_ok_11g
=
307 btcoexist
->btc_read_2byte(btcoexist
, 0xf94);
308 coex_sta
->crc_ok_11n
=
309 btcoexist
->btc_read_2byte(btcoexist
, 0xf90);
310 coex_sta
->crc_ok_11n_agg
=
311 btcoexist
->btc_read_2byte(btcoexist
, 0xfb8);
313 coex_sta
->crc_err_cck
=
314 btcoexist
->btc_read_4byte(btcoexist
, 0xf84);
315 coex_sta
->crc_err_11g
=
316 btcoexist
->btc_read_2byte(btcoexist
, 0xf96);
317 coex_sta
->crc_err_11n
=
318 btcoexist
->btc_read_2byte(btcoexist
, 0xf92);
319 coex_sta
->crc_err_11n_agg
=
320 btcoexist
->btc_read_2byte(btcoexist
, 0xfba);
324 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xf16, 0x1, 0x1);
325 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xf16, 0x1, 0x0);
328 static void btc8723b2ant_query_bt_info(struct btc_coexist
*btcoexist
)
330 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
331 u8 h2c_parameter
[1] = {0};
333 coex_sta
->c2h_bt_info_req_sent
= true;
335 h2c_parameter
[0] |= BIT0
; /* trigger */
337 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
338 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
341 btcoexist
->btc_fill_h2c(btcoexist
, 0x61, 1, h2c_parameter
);
344 static bool btc8723b2ant_is_wifi_status_changed(struct btc_coexist
*btcoexist
)
346 static bool pre_wifi_busy
;
347 static bool pre_under_4way
;
348 static bool pre_bt_hs_on
;
349 bool wifi_busy
= false, under_4way
= false, bt_hs_on
= false;
350 bool wifi_connected
= false;
351 u8 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
354 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
356 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
357 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
358 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
361 if (wifi_connected
) {
362 if (wifi_busy
!= pre_wifi_busy
) {
363 pre_wifi_busy
= wifi_busy
;
367 if (under_4way
!= pre_under_4way
) {
368 pre_under_4way
= under_4way
;
372 if (bt_hs_on
!= pre_bt_hs_on
) {
373 pre_bt_hs_on
= bt_hs_on
;
377 tmp
= BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES
-
378 coex_dm
->switch_thres_offset
;
380 btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, tmp
, 0);
382 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
383 (wifi_rssi_state
== BTC_RSSI_STATE_LOW
))
390 static void btc8723b2ant_update_bt_link_info(struct btc_coexist
*btcoexist
)
392 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
393 bool bt_hs_on
= false;
395 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
397 bt_link_info
->bt_link_exist
= coex_sta
->bt_link_exist
;
398 bt_link_info
->sco_exist
= coex_sta
->sco_exist
;
399 bt_link_info
->a2dp_exist
= coex_sta
->a2dp_exist
;
400 bt_link_info
->pan_exist
= coex_sta
->pan_exist
;
401 bt_link_info
->hid_exist
= coex_sta
->hid_exist
;
403 /* work around for HS mode. */
405 bt_link_info
->pan_exist
= true;
406 bt_link_info
->bt_link_exist
= true;
409 /* check if Sco only */
410 if (bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
411 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
412 bt_link_info
->sco_only
= true;
414 bt_link_info
->sco_only
= false;
416 /* check if A2dp only */
417 if (!bt_link_info
->sco_exist
&& bt_link_info
->a2dp_exist
&&
418 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
419 bt_link_info
->a2dp_only
= true;
421 bt_link_info
->a2dp_only
= false;
423 /* check if Pan only */
424 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
425 bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
426 bt_link_info
->pan_only
= true;
428 bt_link_info
->pan_only
= false;
430 /* check if Hid only */
431 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
432 !bt_link_info
->pan_exist
&& bt_link_info
->hid_exist
)
433 bt_link_info
->hid_only
= true;
435 bt_link_info
->hid_only
= false;
438 static u8
btc8723b2ant_action_algorithm(struct btc_coexist
*btcoexist
)
440 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
441 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
442 bool bt_hs_on
= false;
443 u8 algorithm
= BT_8723B_2ANT_COEX_ALGO_UNDEFINED
;
444 u8 num_of_diff_profile
= 0;
446 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
448 if (!bt_link_info
->bt_link_exist
) {
449 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
450 "[BTCoex], No BT link exists!!!\n");
454 if (bt_link_info
->sco_exist
)
455 num_of_diff_profile
++;
456 if (bt_link_info
->hid_exist
)
457 num_of_diff_profile
++;
458 if (bt_link_info
->pan_exist
)
459 num_of_diff_profile
++;
460 if (bt_link_info
->a2dp_exist
)
461 num_of_diff_profile
++;
463 if (num_of_diff_profile
== 1) {
464 if (bt_link_info
->sco_exist
) {
465 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
466 "[BTCoex], SCO only\n");
467 algorithm
= BT_8723B_2ANT_COEX_ALGO_SCO
;
469 if (bt_link_info
->hid_exist
) {
470 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
471 "[BTCoex], HID only\n");
472 algorithm
= BT_8723B_2ANT_COEX_ALGO_HID
;
473 } else if (bt_link_info
->a2dp_exist
) {
474 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
475 "[BTCoex], A2DP only\n");
476 algorithm
= BT_8723B_2ANT_COEX_ALGO_A2DP
;
477 } else if (bt_link_info
->pan_exist
) {
479 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
481 "[BTCoex], PAN(HS) only\n");
483 BT_8723B_2ANT_COEX_ALGO_PANHS
;
485 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
487 "[BTCoex], PAN(EDR) only\n");
489 BT_8723B_2ANT_COEX_ALGO_PANEDR
;
493 } else if (num_of_diff_profile
== 2) {
494 if (bt_link_info
->sco_exist
) {
495 if (bt_link_info
->hid_exist
) {
496 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
497 "[BTCoex], SCO + HID\n");
498 algorithm
= BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
499 } else if (bt_link_info
->a2dp_exist
) {
500 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
501 "[BTCoex], SCO + A2DP ==> SCO\n");
502 algorithm
= BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
503 } else if (bt_link_info
->pan_exist
) {
505 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
507 "[BTCoex], SCO + PAN(HS)\n");
508 algorithm
= BT_8723B_2ANT_COEX_ALGO_SCO
;
510 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
512 "[BTCoex], SCO + PAN(EDR)\n");
514 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
518 if (bt_link_info
->hid_exist
&&
519 bt_link_info
->a2dp_exist
) {
520 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
521 "[BTCoex], HID + A2DP\n");
522 algorithm
= BT_8723B_2ANT_COEX_ALGO_HID_A2DP
;
523 } else if (bt_link_info
->hid_exist
&&
524 bt_link_info
->pan_exist
) {
526 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
528 "[BTCoex], HID + PAN(HS)\n");
529 algorithm
= BT_8723B_2ANT_COEX_ALGO_HID
;
531 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
533 "[BTCoex], HID + PAN(EDR)\n");
535 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
537 } else if (bt_link_info
->pan_exist
&&
538 bt_link_info
->a2dp_exist
) {
540 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
542 "[BTCoex], A2DP + PAN(HS)\n");
544 BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS
;
546 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
548 "[BTCoex],A2DP + PAN(EDR)\n");
550 BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP
;
554 } else if (num_of_diff_profile
== 3) {
555 if (bt_link_info
->sco_exist
) {
556 if (bt_link_info
->hid_exist
&&
557 bt_link_info
->a2dp_exist
) {
558 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
559 "[BTCoex], SCO + HID + A2DP ==> HID\n");
560 algorithm
= BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
561 } else if (bt_link_info
->hid_exist
&&
562 bt_link_info
->pan_exist
) {
564 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
566 "[BTCoex], SCO + HID + PAN(HS)\n");
568 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
570 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
572 "[BTCoex], SCO + HID + PAN(EDR)\n");
574 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
576 } else if (bt_link_info
->pan_exist
&&
577 bt_link_info
->a2dp_exist
) {
579 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
581 "[BTCoex], SCO + A2DP + PAN(HS)\n");
583 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
585 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
587 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
589 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
593 if (bt_link_info
->hid_exist
&&
594 bt_link_info
->pan_exist
&&
595 bt_link_info
->a2dp_exist
) {
597 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
599 "[BTCoex], HID + A2DP + PAN(HS)\n");
601 BT_8723B_2ANT_COEX_ALGO_HID_A2DP
;
603 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
605 "[BTCoex], HID + A2DP + PAN(EDR)\n");
607 BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR
;
611 } else if (num_of_diff_profile
>= 3) {
612 if (bt_link_info
->sco_exist
) {
613 if (bt_link_info
->hid_exist
&&
614 bt_link_info
->pan_exist
&&
615 bt_link_info
->a2dp_exist
) {
617 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
619 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
621 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
623 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
625 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
;
633 static void btc8723b2ant_set_fw_dac_swing_level(struct btc_coexist
*btcoexist
,
636 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
637 u8 h2c_parameter
[1] = {0};
639 /* There are several type of dacswing
640 * 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6
642 h2c_parameter
[0] = dac_swing_lvl
;
644 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
645 "[BTCoex], Set Dac Swing Level=0x%x\n", dac_swing_lvl
);
646 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
647 "[BTCoex], FW write 0x64=0x%x\n", h2c_parameter
[0]);
649 btcoexist
->btc_fill_h2c(btcoexist
, 0x64, 1, h2c_parameter
);
652 static void btc8723b2ant_set_fw_dec_bt_pwr(struct btc_coexist
*btcoexist
,
655 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
656 u8 h2c_parameter
[1] = {0};
658 h2c_parameter
[0] = dec_bt_pwr_lvl
;
660 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
661 "[BTCoex], decrease Bt Power Level : %u\n", dec_bt_pwr_lvl
);
663 btcoexist
->btc_fill_h2c(btcoexist
, 0x62, 1, h2c_parameter
);
666 static void btc8723b2ant_dec_bt_pwr(struct btc_coexist
*btcoexist
,
667 bool force_exec
, u8 dec_bt_pwr_lvl
)
669 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
671 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
672 "[BTCoex], Dec BT power level = %u\n", dec_bt_pwr_lvl
);
673 coex_dm
->cur_dec_bt_pwr_lvl
= dec_bt_pwr_lvl
;
676 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
677 "[BTCoex], PreDecBtPwrLvl=%d, CurDecBtPwrLvl=%d\n",
678 coex_dm
->pre_dec_bt_pwr_lvl
,
679 coex_dm
->cur_dec_bt_pwr_lvl
);
681 if (coex_dm
->pre_dec_bt_pwr_lvl
== coex_dm
->cur_dec_bt_pwr_lvl
)
684 btc8723b2ant_set_fw_dec_bt_pwr(btcoexist
, coex_dm
->cur_dec_bt_pwr_lvl
);
686 coex_dm
->pre_dec_bt_pwr_lvl
= coex_dm
->cur_dec_bt_pwr_lvl
;
690 void halbtc8723b2ant_set_bt_auto_report(struct btc_coexist
*btcoexist
,
691 bool enable_auto_report
)
693 u8 h2c_parameter
[1] = {0};
695 h2c_parameter
[0] = 0;
697 if (enable_auto_report
)
698 h2c_parameter
[0] |= BIT(0);
700 btcoexist
->btc_fill_h2c(btcoexist
, 0x68, 1, h2c_parameter
);
704 void btc8723b2ant_bt_auto_report(struct btc_coexist
*btcoexist
,
705 bool force_exec
, bool enable_auto_report
)
707 coex_dm
->cur_bt_auto_report
= enable_auto_report
;
710 if (coex_dm
->pre_bt_auto_report
== coex_dm
->cur_bt_auto_report
)
713 halbtc8723b2ant_set_bt_auto_report(btcoexist
,
714 coex_dm
->cur_bt_auto_report
);
716 coex_dm
->pre_bt_auto_report
= coex_dm
->cur_bt_auto_report
;
719 static void btc8723b2ant_fw_dac_swing_lvl(struct btc_coexist
*btcoexist
,
720 bool force_exec
, u8 fw_dac_swing_lvl
)
722 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
724 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
725 "[BTCoex], %s set FW Dac Swing level = %d\n",
726 (force_exec
? "force to" : ""), fw_dac_swing_lvl
);
727 coex_dm
->cur_fw_dac_swing_lvl
= fw_dac_swing_lvl
;
730 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
731 "[BTCoex], preFwDacSwingLvl=%d, curFwDacSwingLvl=%d\n",
732 coex_dm
->pre_fw_dac_swing_lvl
,
733 coex_dm
->cur_fw_dac_swing_lvl
);
735 if (coex_dm
->pre_fw_dac_swing_lvl
==
736 coex_dm
->cur_fw_dac_swing_lvl
)
740 btc8723b2ant_set_fw_dac_swing_level(btcoexist
,
741 coex_dm
->cur_fw_dac_swing_lvl
);
742 coex_dm
->pre_fw_dac_swing_lvl
= coex_dm
->cur_fw_dac_swing_lvl
;
745 static void btc8723b_set_penalty_txrate(struct btc_coexist
*btcoexist
,
748 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
749 u8 h2c_parameter
[6] = {0};
751 h2c_parameter
[0] = 0x6; /* op_code, 0x6 = Retry_Penalty */
753 if (low_penalty_ra
) {
754 h2c_parameter
[1] |= BIT0
;
755 /* normal rate except MCS7/6/5, OFDM54/48/36 */
756 h2c_parameter
[2] = 0x00;
757 h2c_parameter
[3] = 0xf4; /* MCS7 or OFDM54 */
758 h2c_parameter
[4] = 0xf5; /* MCS6 or OFDM48 */
759 h2c_parameter
[5] = 0xf6; /* MCS5 or OFDM36 */
762 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
763 "[BTCoex], set WiFi Low-Penalty Retry: %s",
764 (low_penalty_ra
? "ON!!" : "OFF!!"));
766 btcoexist
->btc_fill_h2c(btcoexist
, 0x69, 6, h2c_parameter
);
769 static void btc8723b2ant_low_penalty_ra(struct btc_coexist
*btcoexist
,
770 bool force_exec
, bool low_penalty_ra
)
772 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
774 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
775 "[BTCoex], %s turn LowPenaltyRA = %s\n",
776 (force_exec
? "force to" : ""), (low_penalty_ra
?
778 coex_dm
->cur_low_penalty_ra
= low_penalty_ra
;
781 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
782 "[BTCoex], bPreLowPenaltyRa=%d, bCurLowPenaltyRa=%d\n",
783 coex_dm
->pre_low_penalty_ra
,
784 coex_dm
->cur_low_penalty_ra
);
786 if (coex_dm
->pre_low_penalty_ra
== coex_dm
->cur_low_penalty_ra
)
789 btc8723b_set_penalty_txrate(btcoexist
, coex_dm
->cur_low_penalty_ra
);
791 coex_dm
->pre_low_penalty_ra
= coex_dm
->cur_low_penalty_ra
;
794 static void btc8723b2ant_set_dac_swing_reg(struct btc_coexist
*btcoexist
,
797 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
800 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
801 "[BTCoex], Write SwDacSwing = 0x%x\n", level
);
802 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x883, 0x3e, val
);
805 static void btc8723b2ant_set_sw_fulltime_dac_swing(struct btc_coexist
*btcoex
,
806 bool sw_dac_swing_on
,
807 u32 sw_dac_swing_lvl
)
810 btc8723b2ant_set_dac_swing_reg(btcoex
, sw_dac_swing_lvl
);
812 btc8723b2ant_set_dac_swing_reg(btcoex
, 0x18);
815 static void btc8723b2ant_dac_swing(struct btc_coexist
*btcoexist
,
816 bool force_exec
, bool dac_swing_on
,
819 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
821 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
822 "[BTCoex], %s turn DacSwing=%s, dac_swing_lvl=0x%x\n",
823 (force_exec
? "force to" : ""),
824 (dac_swing_on
? "ON" : "OFF"), dac_swing_lvl
);
825 coex_dm
->cur_dac_swing_on
= dac_swing_on
;
826 coex_dm
->cur_dac_swing_lvl
= dac_swing_lvl
;
829 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
830 "[BTCoex], bPreDacSwingOn=%d, preDacSwingLvl=0x%x, bCurDacSwingOn=%d, curDacSwingLvl=0x%x\n",
831 coex_dm
->pre_dac_swing_on
,
832 coex_dm
->pre_dac_swing_lvl
,
833 coex_dm
->cur_dac_swing_on
,
834 coex_dm
->cur_dac_swing_lvl
);
836 if ((coex_dm
->pre_dac_swing_on
== coex_dm
->cur_dac_swing_on
) &&
837 (coex_dm
->pre_dac_swing_lvl
== coex_dm
->cur_dac_swing_lvl
))
841 btc8723b2ant_set_sw_fulltime_dac_swing(btcoexist
, dac_swing_on
,
844 coex_dm
->pre_dac_swing_on
= coex_dm
->cur_dac_swing_on
;
845 coex_dm
->pre_dac_swing_lvl
= coex_dm
->cur_dac_swing_lvl
;
848 static void btc8723b2ant_set_coex_table(struct btc_coexist
*btcoexist
,
849 u32 val0x6c0
, u32 val0x6c4
,
850 u32 val0x6c8
, u8 val0x6cc
)
852 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
854 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
855 "[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0
);
856 btcoexist
->btc_write_4byte(btcoexist
, 0x6c0, val0x6c0
);
858 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
859 "[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4
);
860 btcoexist
->btc_write_4byte(btcoexist
, 0x6c4, val0x6c4
);
862 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
863 "[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8
);
864 btcoexist
->btc_write_4byte(btcoexist
, 0x6c8, val0x6c8
);
866 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
867 "[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc
);
868 btcoexist
->btc_write_1byte(btcoexist
, 0x6cc, val0x6cc
);
871 static void btc8723b2ant_coex_table(struct btc_coexist
*btcoexist
,
872 bool force_exec
, u32 val0x6c0
,
873 u32 val0x6c4
, u32 val0x6c8
,
876 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
878 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
879 "[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n",
880 force_exec
? "force to" : "",
881 val0x6c0
, val0x6c4
, val0x6c8
, val0x6cc
);
882 coex_dm
->cur_val0x6c0
= val0x6c0
;
883 coex_dm
->cur_val0x6c4
= val0x6c4
;
884 coex_dm
->cur_val0x6c8
= val0x6c8
;
885 coex_dm
->cur_val0x6cc
= val0x6cc
;
888 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
889 "[BTCoex], preVal0x6c0=0x%x, preVal0x6c4=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n",
890 coex_dm
->pre_val0x6c0
, coex_dm
->pre_val0x6c4
,
891 coex_dm
->pre_val0x6c8
, coex_dm
->pre_val0x6cc
);
892 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
893 "[BTCoex], curVal0x6c0=0x%x, curVal0x6c4=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n",
894 coex_dm
->cur_val0x6c0
, coex_dm
->cur_val0x6c4
,
895 coex_dm
->cur_val0x6c8
, coex_dm
->cur_val0x6cc
);
897 if ((coex_dm
->pre_val0x6c0
== coex_dm
->cur_val0x6c0
) &&
898 (coex_dm
->pre_val0x6c4
== coex_dm
->cur_val0x6c4
) &&
899 (coex_dm
->pre_val0x6c8
== coex_dm
->cur_val0x6c8
) &&
900 (coex_dm
->pre_val0x6cc
== coex_dm
->cur_val0x6cc
))
903 btc8723b2ant_set_coex_table(btcoexist
, val0x6c0
, val0x6c4
,
906 coex_dm
->pre_val0x6c0
= coex_dm
->cur_val0x6c0
;
907 coex_dm
->pre_val0x6c4
= coex_dm
->cur_val0x6c4
;
908 coex_dm
->pre_val0x6c8
= coex_dm
->cur_val0x6c8
;
909 coex_dm
->pre_val0x6cc
= coex_dm
->cur_val0x6cc
;
912 static void btc8723b2ant_coex_table_with_type(struct btc_coexist
*btcoexist
,
913 bool force_exec
, u8 type
)
917 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55555555,
918 0x55555555, 0xffffff, 0x3);
921 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55555555,
922 0x5afa5afa, 0xffffff, 0x3);
925 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x5ada5ada,
926 0x5ada5ada, 0xffffff, 0x3);
929 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0xaaaaaaaa,
930 0xaaaaaaaa, 0xffffff, 0x3);
933 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0xffffffff,
934 0xffffffff, 0xffffff, 0x3);
937 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x5fff5fff,
938 0x5fff5fff, 0xffffff, 0x3);
941 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55ff55ff,
942 0x5a5a5a5a, 0xffffff, 0x3);
945 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
946 0x5ada5ada, 0xffffff, 0x3);
949 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
950 0x5ada5ada, 0xffffff, 0x3);
953 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
954 0x5ada5ada, 0xffffff, 0x3);
957 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
958 0x5ada5ada, 0xffffff, 0x3);
961 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
962 0x5ada5ada, 0xffffff, 0x3);
965 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
966 0x5ada5ada, 0xffffff, 0x3);
969 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x5fff5fff,
970 0xaaaaaaaa, 0xffffff, 0x3);
973 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x5fff5fff,
974 0x5ada5ada, 0xffffff, 0x3);
977 btc8723b2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
978 0xaaaaaaaa, 0xffffff, 0x3);
985 static void btc8723b2ant_set_fw_ignore_wlan_act(struct btc_coexist
*btcoexist
,
988 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
989 u8 h2c_parameter
[1] = {0};
992 h2c_parameter
[0] |= BIT0
; /* function enable */
994 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
995 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n",
998 btcoexist
->btc_fill_h2c(btcoexist
, 0x63, 1, h2c_parameter
);
1001 static void btc8723b2ant_set_lps_rpwm(struct btc_coexist
*btcoexist
,
1002 u8 lps_val
, u8 rpwm_val
)
1007 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_LPS_VAL
, &lps
);
1008 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_RPWM_VAL
, &rpwm
);
1011 static void btc8723b2ant_lps_rpwm(struct btc_coexist
*btcoexist
,
1012 bool force_exec
, u8 lps_val
, u8 rpwm_val
)
1014 coex_dm
->cur_lps
= lps_val
;
1015 coex_dm
->cur_rpwm
= rpwm_val
;
1018 if ((coex_dm
->pre_lps
== coex_dm
->cur_lps
) &&
1019 (coex_dm
->pre_rpwm
== coex_dm
->cur_rpwm
))
1022 btc8723b2ant_set_lps_rpwm(btcoexist
, lps_val
, rpwm_val
);
1024 coex_dm
->pre_lps
= coex_dm
->cur_lps
;
1025 coex_dm
->pre_rpwm
= coex_dm
->cur_rpwm
;
1028 static void btc8723b2ant_ignore_wlan_act(struct btc_coexist
*btcoexist
,
1029 bool force_exec
, bool enable
)
1031 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1033 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1034 "[BTCoex], %s turn Ignore WlanAct %s\n",
1035 (force_exec
? "force to" : ""), (enable
? "ON" : "OFF"));
1036 coex_dm
->cur_ignore_wlan_act
= enable
;
1039 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1040 "[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
1041 coex_dm
->pre_ignore_wlan_act
,
1042 coex_dm
->cur_ignore_wlan_act
);
1044 if (coex_dm
->pre_ignore_wlan_act
==
1045 coex_dm
->cur_ignore_wlan_act
)
1048 btc8723b2ant_set_fw_ignore_wlan_act(btcoexist
, enable
);
1050 coex_dm
->pre_ignore_wlan_act
= coex_dm
->cur_ignore_wlan_act
;
1053 static void btc8723b2ant_set_fw_ps_tdma(struct btc_coexist
*btcoexist
, u8 byte1
,
1054 u8 byte2
, u8 byte3
, u8 byte4
, u8 byte5
)
1056 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1057 u8 h2c_parameter
[5];
1058 if ((coex_sta
->a2dp_exist
) && (coex_sta
->hid_exist
))
1059 byte5
= byte5
| 0x1;
1061 h2c_parameter
[0] = byte1
;
1062 h2c_parameter
[1] = byte2
;
1063 h2c_parameter
[2] = byte3
;
1064 h2c_parameter
[3] = byte4
;
1065 h2c_parameter
[4] = byte5
;
1067 coex_dm
->ps_tdma_para
[0] = byte1
;
1068 coex_dm
->ps_tdma_para
[1] = byte2
;
1069 coex_dm
->ps_tdma_para
[2] = byte3
;
1070 coex_dm
->ps_tdma_para
[3] = byte4
;
1071 coex_dm
->ps_tdma_para
[4] = byte5
;
1073 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1074 "[BTCoex], FW write 0x60(5bytes)=0x%x%08x\n",
1076 h2c_parameter
[1] << 24 | h2c_parameter
[2] << 16 |
1077 h2c_parameter
[3] << 8 | h2c_parameter
[4]);
1079 btcoexist
->btc_fill_h2c(btcoexist
, 0x60, 5, h2c_parameter
);
1082 static void btc8723b2ant_sw_mechanism(struct btc_coexist
*btcoexist
,
1083 bool shrink_rx_lpf
, bool low_penalty_ra
,
1084 bool limited_dig
, bool bt_lna_constrain
)
1086 btc8723b2ant_low_penalty_ra(btcoexist
, NORMAL_EXEC
, low_penalty_ra
);
1089 static void btc8723b2ant_set_ant_path(struct btc_coexist
*btcoexist
,
1090 u8 antpos_type
, bool init_hwcfg
,
1093 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
1094 u32 fw_ver
= 0, u32tmp
= 0;
1095 bool pg_ext_switch
= false;
1096 bool use_ext_switch
= false;
1097 u8 h2c_parameter
[2] = {0};
1099 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_EXT_SWITCH
, &pg_ext_switch
);
1100 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
1102 if ((fw_ver
< 0xc0000) || pg_ext_switch
)
1103 use_ext_switch
= true;
1106 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x39, 0x8, 0x1);
1107 btcoexist
->btc_write_1byte(btcoexist
, 0x974, 0xff);
1108 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x944, 0x3, 0x3);
1109 btcoexist
->btc_write_1byte(btcoexist
, 0x930, 0x77);
1110 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67, 0x20, 0x1);
1112 if (fw_ver
>= 0x180000) {
1113 /* Use H2C to set GNT_BT to High to avoid A2DP click */
1114 h2c_parameter
[0] = 1;
1115 btcoexist
->btc_fill_h2c(btcoexist
, 0x6E, 1,
1118 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x18);
1121 btcoexist
->btc_write_4byte(btcoexist
, 0x948, 0x0);
1123 /* WiFi TRx Mask off */
1124 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
,
1127 if (board_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
) {
1128 /* tell firmware "no antenna inverse" */
1129 h2c_parameter
[0] = 0;
1131 /* tell firmware "antenna inverse" */
1132 h2c_parameter
[0] = 1;
1135 if (use_ext_switch
) {
1136 /* ext switch type */
1137 h2c_parameter
[1] = 1;
1139 /* int switch type */
1140 h2c_parameter
[1] = 0;
1142 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2, h2c_parameter
);
1144 if (fw_ver
>= 0x180000) {
1145 /* Use H2C to set GNT_BT to "Control by PTA"*/
1146 h2c_parameter
[0] = 0;
1147 btcoexist
->btc_fill_h2c(btcoexist
, 0x6E, 1,
1150 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x0);
1154 /* ext switch setting */
1155 if (use_ext_switch
) {
1157 /* 0x4c[23] = 0, 0x4c[24] = 1 Ant controlled by WL/BT */
1158 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
1161 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
1164 /* fixed internal switch S1->WiFi, S0->BT */
1165 if (board_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
1166 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x0);
1168 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x280);
1170 switch (antpos_type
) {
1171 case BTC_ANT_WIFI_AT_MAIN
:
1172 /* ext switch main at wifi */
1173 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x92c,
1176 case BTC_ANT_WIFI_AT_AUX
:
1177 /* ext switch aux at wifi */
1178 btcoexist
->btc_write_1byte_bitmask(btcoexist
,
1183 /* internal switch */
1185 /* 0x4c[23] = 0, 0x4c[24] = 1 Ant controlled by WL/BT */
1186 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
1189 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u32tmp
);
1192 /* fixed ext switch, S1->Main, S0->Aux */
1193 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x64, 0x1, 0x0);
1194 switch (antpos_type
) {
1195 case BTC_ANT_WIFI_AT_MAIN
:
1196 /* fixed internal switch S1->WiFi, S0->BT */
1197 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x0);
1199 case BTC_ANT_WIFI_AT_AUX
:
1200 /* fixed internal switch S0->WiFi, S1->BT */
1201 btcoexist
->btc_write_2byte(btcoexist
, 0x948, 0x280);
1207 static void btc8723b2ant_ps_tdma(struct btc_coexist
*btcoexist
, bool force_exec
,
1208 bool turn_on
, u8 type
)
1210 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1211 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1212 u8 wifi_rssi_state
, bt_rssi_state
;
1213 s8 wifi_duration_adjust
= 0x0;
1214 u8 tdma_byte4_modify
= 0x0;
1215 u8 tmp
= BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES
-
1216 coex_dm
->switch_thres_offset
;
1218 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, tmp
, 0);
1219 tmp
= BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
1220 coex_dm
->switch_thres_offset
;
1221 bt_rssi_state
= btc8723b2ant_bt_rssi_state(btcoexist
, 2, tmp
, 0);
1223 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1224 "[BTCoex], %s turn %s PS TDMA, type=%d\n",
1225 (force_exec
? "force to" : ""),
1226 (turn_on
? "ON" : "OFF"), type
);
1227 coex_dm
->cur_ps_tdma_on
= turn_on
;
1228 coex_dm
->cur_ps_tdma
= type
;
1230 if (!(BTC_RSSI_HIGH(wifi_rssi_state
) &&
1231 BTC_RSSI_HIGH(bt_rssi_state
)) && turn_on
) {
1232 /* for WiFi RSSI low or BT RSSI low */
1234 coex_dm
->is_switch_to_1dot5_ant
= true;
1236 coex_dm
->is_switch_to_1dot5_ant
= false;
1240 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1241 "[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n",
1242 coex_dm
->pre_ps_tdma_on
, coex_dm
->cur_ps_tdma_on
);
1243 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1244 "[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n",
1245 coex_dm
->pre_ps_tdma
, coex_dm
->cur_ps_tdma
);
1247 if ((coex_dm
->pre_ps_tdma_on
== coex_dm
->cur_ps_tdma_on
) &&
1248 (coex_dm
->pre_ps_tdma
== coex_dm
->cur_ps_tdma
))
1252 if (coex_sta
->scan_ap_num
<= 5) {
1253 if (coex_sta
->a2dp_bit_pool
>= 45)
1254 wifi_duration_adjust
= -15;
1255 else if (coex_sta
->a2dp_bit_pool
>= 35)
1256 wifi_duration_adjust
= -10;
1258 wifi_duration_adjust
= 5;
1259 } else if (coex_sta
->scan_ap_num
<= 20) {
1260 if (coex_sta
->a2dp_bit_pool
>= 45)
1261 wifi_duration_adjust
= -15;
1262 else if (coex_sta
->a2dp_bit_pool
>= 35)
1263 wifi_duration_adjust
= -10;
1265 wifi_duration_adjust
= 0;
1266 } else if (coex_sta
->scan_ap_num
<= 40) {
1267 if (coex_sta
->a2dp_bit_pool
>= 45)
1268 wifi_duration_adjust
= -15;
1269 else if (coex_sta
->a2dp_bit_pool
>= 35)
1270 wifi_duration_adjust
= -10;
1272 wifi_duration_adjust
= -5;
1274 if (coex_sta
->a2dp_bit_pool
>= 45)
1275 wifi_duration_adjust
= -15;
1276 else if (coex_sta
->a2dp_bit_pool
>= 35)
1277 wifi_duration_adjust
= -10;
1279 wifi_duration_adjust
= -10;
1282 if ((bt_link_info
->slave_role
) && (bt_link_info
->a2dp_exist
))
1283 /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1284 tdma_byte4_modify
= 0x1;
1290 btc8723b2ant_set_fw_ps_tdma(
1291 btcoexist
, 0xe3, 0x3c,
1292 0x03, 0xf1, 0x90 | tdma_byte4_modify
);
1295 btc8723b2ant_set_fw_ps_tdma(
1296 btcoexist
, 0xe3, 0x2d,
1297 0x03, 0xf1, 0x90 | tdma_byte4_modify
);
1300 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1c,
1302 0x90 | tdma_byte4_modify
);
1305 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x10,
1307 0x90 | tdma_byte4_modify
);
1310 btc8723b2ant_set_fw_ps_tdma(
1311 btcoexist
, 0xe3, 0x3c,
1312 0x3, 0x70, 0x90 | tdma_byte4_modify
);
1315 btc8723b2ant_set_fw_ps_tdma(
1316 btcoexist
, 0xe3, 0x2d,
1317 0x3, 0x70, 0x90 | tdma_byte4_modify
);
1320 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1c,
1322 0x90 | tdma_byte4_modify
);
1325 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xa3, 0x10,
1327 0x90 | tdma_byte4_modify
);
1330 btc8723b2ant_set_fw_ps_tdma(
1331 btcoexist
, 0xe3, 0x3c + wifi_duration_adjust
,
1332 0x03, 0xf1, 0x90 | tdma_byte4_modify
);
1335 btc8723b2ant_set_fw_ps_tdma(
1336 btcoexist
, 0xe3, 0x2d,
1337 0x03, 0xf1, 0x90 | tdma_byte4_modify
);
1340 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1c,
1342 0x90 | tdma_byte4_modify
);
1345 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x10,
1347 0x90 | tdma_byte4_modify
);
1350 btc8723b2ant_set_fw_ps_tdma(
1351 btcoexist
, 0xe3, 0x3c,
1352 0x3, 0x70, 0x90 | tdma_byte4_modify
);
1355 btc8723b2ant_set_fw_ps_tdma(
1356 btcoexist
, 0xe3, 0x2d,
1357 0x3, 0x70, 0x90 | tdma_byte4_modify
);
1360 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1c,
1362 0x90 | tdma_byte4_modify
);
1365 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x10,
1367 0x90 | tdma_byte4_modify
);
1370 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xa3, 0x2f,
1374 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x5, 0x5,
1378 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1382 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1386 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x15,
1392 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x35,
1396 btc8723b2ant_set_fw_ps_tdma(
1397 btcoexist
, 0xe3, 0x3c + wifi_duration_adjust
,
1404 btc8723b2ant_set_fw_ps_tdma(
1405 btcoexist
, 0xd3, 0x3a + wifi_duration_adjust
,
1406 0x03, 0x70, 0x50 | tdma_byte4_modify
);
1412 btc8723b2ant_set_fw_ps_tdma(
1413 btcoexist
, 0xd3, 0x2d + wifi_duration_adjust
,
1414 0x03, 0x70, 0x50 | tdma_byte4_modify
);
1420 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x1c,
1422 0x50 | tdma_byte4_modify
);
1428 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x10,
1430 0x50 | tdma_byte4_modify
);
1433 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x3c,
1435 0x90 | tdma_byte4_modify
);
1438 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x15,
1440 0x90 | tdma_byte4_modify
);
1444 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x35,
1449 /* disable PS tdma */
1452 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1456 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1460 btc8723b2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1466 /* update pre state */
1467 coex_dm
->pre_ps_tdma_on
= coex_dm
->cur_ps_tdma_on
;
1468 coex_dm
->pre_ps_tdma
= coex_dm
->cur_ps_tdma
;
1471 static void btc8723b2ant_ps_tdma_check_for_power_save_state(
1472 struct btc_coexist
*btcoexist
, bool new_ps_state
)
1476 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_LPS_MODE
, &lps_mode
);
1479 /* already under LPS state */
1481 /* keep state under LPS, do nothing. */
1483 /* will leave LPS state, turn off psTdma first */
1484 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1489 /* will enter LPS state, turn off psTdma first */
1490 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1492 /* keep state under NO PS state, do nothing. */
1497 static void btc8723b2ant_power_save_state(struct btc_coexist
*btcoexist
,
1498 u8 ps_type
, u8 lps_val
, u8 rpwm_val
)
1500 bool low_pwr_disable
= false;
1503 case BTC_PS_WIFI_NATIVE
:
1504 /* recover to original 32k low power setting */
1505 low_pwr_disable
= false;
1506 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1508 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_NORMAL_LPS
, NULL
);
1509 coex_sta
->force_lps_on
= false;
1512 btc8723b2ant_ps_tdma_check_for_power_save_state(btcoexist
,
1514 btc8723b2ant_lps_rpwm(btcoexist
, NORMAL_EXEC
, lps_val
,
1516 /* when coex force to enter LPS, do not enter 32k low power */
1517 low_pwr_disable
= true;
1518 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1520 /* power save must executed before psTdma */
1521 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_ENTER_LPS
, NULL
);
1522 coex_sta
->force_lps_on
= true;
1524 case BTC_PS_LPS_OFF
:
1525 btc8723b2ant_ps_tdma_check_for_power_save_state(btcoexist
,
1527 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_LEAVE_LPS
, NULL
);
1528 coex_sta
->force_lps_on
= false;
1535 static void btc8723b2ant_coex_alloff(struct btc_coexist
*btcoexist
)
1538 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1539 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1540 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1541 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1544 btc8723b2ant_sw_mechanism(btcoexist
, false, false, false, false);
1547 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
1548 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1551 static void btc8723b2ant_init_coex_dm(struct btc_coexist
*btcoexist
)
1553 /* force to reset coex mechanism*/
1554 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1555 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1557 btc8723b2ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 1);
1558 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, FORCE_EXEC
, 6);
1559 btc8723b2ant_dec_bt_pwr(btcoexist
, FORCE_EXEC
, 0);
1561 btc8723b2ant_sw_mechanism(btcoexist
, false, false, false, false);
1563 coex_sta
->pop_event_cnt
= 0;
1566 static void btc8723b2ant_action_bt_inquiry(struct btc_coexist
*btcoexist
)
1568 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1569 bool wifi_connected
= false;
1570 bool low_pwr_disable
= true;
1571 bool scan
= false, link
= false, roam
= false;
1573 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1575 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1578 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
1579 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
1580 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
1582 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1584 if (coex_sta
->bt_abnormal_scan
) {
1585 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 23);
1586 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 3);
1587 } else if (scan
|| link
|| roam
) {
1588 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1589 "[BTCoex], Wifi link process + BT Inq/Page!!\n");
1590 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 15);
1591 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 22);
1592 } else if (wifi_connected
) {
1593 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1594 "[BTCoex], Wifi connected + BT Inq/Page!!\n");
1595 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 15);
1596 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 22);
1598 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1599 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1601 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, FORCE_EXEC
, 6);
1602 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1604 btc8723b2ant_sw_mechanism(btcoexist
, false, false, false, false);
1607 static void btc8723b2ant_action_wifi_link_process(struct btc_coexist
1610 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1614 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 15);
1615 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 22);
1617 btc8723b2ant_sw_mechanism(btcoexist
, false, false, false, false);
1619 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x948);
1620 u8tmpa
= btcoexist
->btc_read_1byte(btcoexist
, 0x765);
1621 u8tmpb
= btcoexist
->btc_read_1byte(btcoexist
, 0x76e);
1623 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1624 "[BTCoex], 0x948 = 0x%x, 0x765 = 0x%x, 0x76e = 0x%x\n",
1625 u32tmp
, u8tmpa
, u8tmpb
);
1628 static bool btc8723b2ant_action_wifi_idle_process(struct btc_coexist
*btcoexist
)
1630 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1631 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
1633 u8 tmp
= BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES
-
1634 coex_dm
->switch_thres_offset
- coex_dm
->switch_thres_offset
;
1636 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
1637 wifi_rssi_state1
= btc8723b2ant_wifi_rssi_state(btcoexist
, 1, 2,
1639 tmp
= BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
1640 coex_dm
->switch_thres_offset
- coex_dm
->switch_thres_offset
;
1641 bt_rssi_state
= btc8723b2ant_bt_rssi_state(btcoexist
, 2, tmp
, 0);
1643 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_AP_NUM
, &ap_num
);
1645 /* office environment */
1646 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && (coex_sta
->hid_exist
) &&
1647 (coex_sta
->a2dp_exist
)) {
1648 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1649 "[BTCoex], Wifi idle process for BT HID+A2DP exist!!\n");
1651 btc8723b2ant_dac_swing(btcoexist
, NORMAL_EXEC
, true, 0x6);
1652 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1655 btc8723b2ant_sw_mechanism(btcoexist
, false, false, false,
1657 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1658 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1660 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1665 btc8723b2ant_dac_swing(btcoexist
, NORMAL_EXEC
, true, 0x18);
1669 static bool btc8723b2ant_is_common_action(struct btc_coexist
*btcoexist
)
1671 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1672 bool common
= false, wifi_connected
= false;
1673 bool wifi_busy
= false;
1674 bool bt_hs_on
= false, low_pwr_disable
= false;
1676 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
1677 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1679 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1681 if (!wifi_connected
) {
1682 low_pwr_disable
= false;
1683 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1685 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
,
1688 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1689 "[BTCoex], Wifi non-connected idle!!\n");
1691 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff,
1693 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1694 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1695 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1696 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1698 btc8723b2ant_sw_mechanism(btcoexist
, false, false, false,
1703 if (BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE
==
1704 coex_dm
->bt_status
) {
1705 low_pwr_disable
= false;
1706 btcoexist
->btc_set(btcoexist
,
1707 BTC_SET_ACT_DISABLE_LOW_POWER
,
1709 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
,
1712 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1713 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1715 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1,
1717 btc8723b2ant_coex_table_with_type(btcoexist
,
1719 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1720 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
,
1722 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1724 btc8723b2ant_sw_mechanism(btcoexist
, false, false,
1728 } else if (BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE
==
1729 coex_dm
->bt_status
) {
1730 low_pwr_disable
= true;
1731 btcoexist
->btc_set(btcoexist
,
1732 BTC_SET_ACT_DISABLE_LOW_POWER
,
1737 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1738 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1739 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
,
1742 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1,
1744 btc8723b2ant_coex_table_with_type(btcoexist
,
1746 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1747 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
,
1749 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1751 btc8723b2ant_sw_mechanism(btcoexist
, true, false,
1756 low_pwr_disable
= true;
1757 btcoexist
->btc_set(btcoexist
,
1758 BTC_SET_ACT_DISABLE_LOW_POWER
,
1762 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1763 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1766 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1767 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1770 btc8723b2ant_action_wifi_idle_process(
1779 static void btc8723b2ant_tdma_duration_adjust(struct btc_coexist
*btcoexist
,
1780 bool sco_hid
, bool tx_pause
,
1783 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1784 static s32 up
, dn
, m
, n
, wait_count
;
1785 /*0: no change, +1: increase WiFi duration, -1: decrease WiFi duration*/
1789 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1790 "[BTCoex], TdmaDurationAdjust()\n");
1792 if (!coex_dm
->auto_tdma_adjust
) {
1793 coex_dm
->auto_tdma_adjust
= true;
1794 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1795 "[BTCoex], first run TdmaDurationAdjust()!!\n");
1798 if (max_interval
== 1) {
1799 btc8723b2ant_ps_tdma(btcoexist
,
1802 coex_dm
->ps_tdma_du_adj_type
= 13;
1803 } else if (max_interval
== 2) {
1804 btc8723b2ant_ps_tdma(btcoexist
,
1807 coex_dm
->ps_tdma_du_adj_type
= 14;
1808 } else if (max_interval
== 3) {
1809 btc8723b2ant_ps_tdma(btcoexist
,
1812 coex_dm
->ps_tdma_du_adj_type
= 15;
1814 btc8723b2ant_ps_tdma(btcoexist
,
1817 coex_dm
->ps_tdma_du_adj_type
= 15;
1820 if (max_interval
== 1) {
1821 btc8723b2ant_ps_tdma(btcoexist
,
1824 coex_dm
->ps_tdma_du_adj_type
= 9;
1825 } else if (max_interval
== 2) {
1826 btc8723b2ant_ps_tdma(btcoexist
,
1829 coex_dm
->ps_tdma_du_adj_type
= 10;
1830 } else if (max_interval
== 3) {
1831 btc8723b2ant_ps_tdma(btcoexist
,
1834 coex_dm
->ps_tdma_du_adj_type
= 11;
1836 btc8723b2ant_ps_tdma(btcoexist
,
1839 coex_dm
->ps_tdma_du_adj_type
= 11;
1844 if (max_interval
== 1) {
1845 btc8723b2ant_ps_tdma(btcoexist
,
1848 coex_dm
->ps_tdma_du_adj_type
= 5;
1849 } else if (max_interval
== 2) {
1850 btc8723b2ant_ps_tdma(btcoexist
,
1853 coex_dm
->ps_tdma_du_adj_type
= 6;
1854 } else if (max_interval
== 3) {
1855 btc8723b2ant_ps_tdma(btcoexist
,
1858 coex_dm
->ps_tdma_du_adj_type
= 7;
1860 btc8723b2ant_ps_tdma(btcoexist
,
1863 coex_dm
->ps_tdma_du_adj_type
= 7;
1866 if (max_interval
== 1) {
1867 btc8723b2ant_ps_tdma(btcoexist
,
1870 coex_dm
->ps_tdma_du_adj_type
= 1;
1871 } else if (max_interval
== 2) {
1872 btc8723b2ant_ps_tdma(btcoexist
,
1875 coex_dm
->ps_tdma_du_adj_type
= 2;
1876 } else if (max_interval
== 3) {
1877 btc8723b2ant_ps_tdma(btcoexist
,
1880 coex_dm
->ps_tdma_du_adj_type
= 3;
1882 btc8723b2ant_ps_tdma(btcoexist
,
1885 coex_dm
->ps_tdma_du_adj_type
= 3;
1897 /*accquire the BT TRx retry count from BT_Info byte2*/
1898 retry_count
= coex_sta
->bt_retry_cnt
;
1900 if ((coex_sta
->low_priority_tx
) > 1050 ||
1901 (coex_sta
->low_priority_rx
) > 1250)
1904 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1905 "[BTCoex], retry_count = %d\n", retry_count
);
1906 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1907 "[BTCoex], up=%d, dn=%d, m=%d, n=%d, wait_count=%d\n",
1908 up
, dn
, m
, n
, wait_count
);
1911 /* no retry in the last 2-second duration*/
1912 if (retry_count
== 0) {
1920 /* if retry count during continuous n*2
1921 * seconds is 0, enlarge WiFi duration
1928 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1929 "[BTCoex], Increase wifi duration!!\n");
1930 } /* <=3 retry in the last 2-second duration*/
1931 } else if (retry_count
<= 3) {
1939 /* if continuous 2 retry count(every 2
1940 * seconds) >0 and < 3, reduce WiFi duration
1942 if (wait_count
<= 2)
1943 /* avoid loop between the two levels */
1949 /* maximum of m = 20 ' will recheck if
1950 * need to adjust wifi duration in
1951 * maximum time interval 120 seconds
1960 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1961 "[BTCoex], Decrease wifi duration for retry_counter<3!!\n");
1964 /* retry count > 3, once retry count > 3, to reduce
1967 if (wait_count
== 1)
1968 /* to avoid loop between the two levels */
1974 /* maximum of m = 20 ' will recheck if need to
1975 * adjust wifi duration in maximum time interval
1985 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1986 "[BTCoex], Decrease wifi duration for retry_counter>3!!\n");
1989 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1990 "[BTCoex], max Interval = %d\n", max_interval
);
1991 if (max_interval
== 1) {
1993 if (coex_dm
->cur_ps_tdma
== 71) {
1994 btc8723b2ant_ps_tdma(btcoexist
,
1997 coex_dm
->ps_tdma_du_adj_type
= 5;
1998 } else if (coex_dm
->cur_ps_tdma
== 1) {
1999 btc8723b2ant_ps_tdma(btcoexist
,
2002 coex_dm
->ps_tdma_du_adj_type
= 5;
2003 } else if (coex_dm
->cur_ps_tdma
== 2) {
2004 btc8723b2ant_ps_tdma(btcoexist
,
2007 coex_dm
->ps_tdma_du_adj_type
= 6;
2008 } else if (coex_dm
->cur_ps_tdma
== 3) {
2009 btc8723b2ant_ps_tdma(btcoexist
,
2012 coex_dm
->ps_tdma_du_adj_type
= 7;
2013 } else if (coex_dm
->cur_ps_tdma
== 4) {
2014 btc8723b2ant_ps_tdma(btcoexist
,
2017 coex_dm
->ps_tdma_du_adj_type
= 8;
2019 if (coex_dm
->cur_ps_tdma
== 9) {
2020 btc8723b2ant_ps_tdma(btcoexist
,
2023 coex_dm
->ps_tdma_du_adj_type
= 13;
2024 } else if (coex_dm
->cur_ps_tdma
== 10) {
2025 btc8723b2ant_ps_tdma(btcoexist
,
2028 coex_dm
->ps_tdma_du_adj_type
= 14;
2029 } else if (coex_dm
->cur_ps_tdma
== 11) {
2030 btc8723b2ant_ps_tdma(btcoexist
,
2033 coex_dm
->ps_tdma_du_adj_type
= 15;
2034 } else if (coex_dm
->cur_ps_tdma
== 12) {
2035 btc8723b2ant_ps_tdma(btcoexist
,
2038 coex_dm
->ps_tdma_du_adj_type
= 16;
2042 if (coex_dm
->cur_ps_tdma
== 5) {
2043 btc8723b2ant_ps_tdma(
2044 btcoexist
, NORMAL_EXEC
,
2046 coex_dm
->ps_tdma_du_adj_type
=
2048 } else if (coex_dm
->cur_ps_tdma
== 6) {
2049 btc8723b2ant_ps_tdma(
2050 btcoexist
, NORMAL_EXEC
,
2052 coex_dm
->ps_tdma_du_adj_type
=
2054 } else if (coex_dm
->cur_ps_tdma
== 7) {
2055 btc8723b2ant_ps_tdma(
2056 btcoexist
, NORMAL_EXEC
,
2058 coex_dm
->ps_tdma_du_adj_type
=
2060 } else if (coex_dm
->cur_ps_tdma
== 13) {
2061 btc8723b2ant_ps_tdma(
2062 btcoexist
, NORMAL_EXEC
,
2064 coex_dm
->ps_tdma_du_adj_type
=
2066 } else if (coex_dm
->cur_ps_tdma
== 14) {
2067 btc8723b2ant_ps_tdma(
2068 btcoexist
, NORMAL_EXEC
,
2070 coex_dm
->ps_tdma_du_adj_type
=
2072 } else if (coex_dm
->cur_ps_tdma
== 15) {
2073 btc8723b2ant_ps_tdma(
2074 btcoexist
, NORMAL_EXEC
,
2076 coex_dm
->ps_tdma_du_adj_type
=
2079 } else if (result
== 1) {
2080 if (coex_dm
->cur_ps_tdma
== 8) {
2081 btc8723b2ant_ps_tdma(
2082 btcoexist
, NORMAL_EXEC
,
2084 coex_dm
->ps_tdma_du_adj_type
=
2086 } else if (coex_dm
->cur_ps_tdma
== 7) {
2087 btc8723b2ant_ps_tdma(
2088 btcoexist
, NORMAL_EXEC
,
2090 coex_dm
->ps_tdma_du_adj_type
=
2092 } else if (coex_dm
->cur_ps_tdma
== 6) {
2093 btc8723b2ant_ps_tdma(
2094 btcoexist
, NORMAL_EXEC
,
2096 coex_dm
->ps_tdma_du_adj_type
=
2098 } else if (coex_dm
->cur_ps_tdma
== 16) {
2099 btc8723b2ant_ps_tdma(
2100 btcoexist
, NORMAL_EXEC
,
2102 coex_dm
->ps_tdma_du_adj_type
=
2104 } else if (coex_dm
->cur_ps_tdma
== 15) {
2105 btc8723b2ant_ps_tdma(
2106 btcoexist
, NORMAL_EXEC
,
2108 coex_dm
->ps_tdma_du_adj_type
=
2110 } else if (coex_dm
->cur_ps_tdma
== 14) {
2111 btc8723b2ant_ps_tdma(
2112 btcoexist
, NORMAL_EXEC
,
2114 coex_dm
->ps_tdma_du_adj_type
=
2119 if (coex_dm
->cur_ps_tdma
== 5) {
2120 btc8723b2ant_ps_tdma(btcoexist
,
2123 coex_dm
->ps_tdma_du_adj_type
= 71;
2124 } else if (coex_dm
->cur_ps_tdma
== 6) {
2125 btc8723b2ant_ps_tdma(btcoexist
,
2128 coex_dm
->ps_tdma_du_adj_type
= 2;
2129 } else if (coex_dm
->cur_ps_tdma
== 7) {
2130 btc8723b2ant_ps_tdma(btcoexist
,
2133 coex_dm
->ps_tdma_du_adj_type
= 3;
2134 } else if (coex_dm
->cur_ps_tdma
== 8) {
2135 btc8723b2ant_ps_tdma(btcoexist
,
2138 coex_dm
->ps_tdma_du_adj_type
= 4;
2140 if (coex_dm
->cur_ps_tdma
== 13) {
2141 btc8723b2ant_ps_tdma(btcoexist
,
2144 coex_dm
->ps_tdma_du_adj_type
= 9;
2145 } else if (coex_dm
->cur_ps_tdma
== 14) {
2146 btc8723b2ant_ps_tdma(btcoexist
,
2149 coex_dm
->ps_tdma_du_adj_type
= 10;
2150 } else if (coex_dm
->cur_ps_tdma
== 15) {
2151 btc8723b2ant_ps_tdma(btcoexist
,
2154 coex_dm
->ps_tdma_du_adj_type
= 11;
2155 } else if (coex_dm
->cur_ps_tdma
== 16) {
2156 btc8723b2ant_ps_tdma(btcoexist
,
2159 coex_dm
->ps_tdma_du_adj_type
= 12;
2163 if (coex_dm
->cur_ps_tdma
== 71) {
2164 btc8723b2ant_ps_tdma(
2165 btcoexist
, NORMAL_EXEC
,
2167 coex_dm
->ps_tdma_du_adj_type
=
2169 } else if (coex_dm
->cur_ps_tdma
== 1) {
2170 btc8723b2ant_ps_tdma(
2171 btcoexist
, NORMAL_EXEC
,
2173 coex_dm
->ps_tdma_du_adj_type
=
2175 } else if (coex_dm
->cur_ps_tdma
== 2) {
2176 btc8723b2ant_ps_tdma(
2177 btcoexist
, NORMAL_EXEC
,
2179 coex_dm
->ps_tdma_du_adj_type
=
2181 } else if (coex_dm
->cur_ps_tdma
== 3) {
2182 btc8723b2ant_ps_tdma(
2183 btcoexist
, NORMAL_EXEC
,
2185 coex_dm
->ps_tdma_du_adj_type
=
2187 } else if (coex_dm
->cur_ps_tdma
== 9) {
2188 btc8723b2ant_ps_tdma(
2189 btcoexist
, NORMAL_EXEC
,
2191 coex_dm
->ps_tdma_du_adj_type
=
2193 } else if (coex_dm
->cur_ps_tdma
== 10) {
2194 btc8723b2ant_ps_tdma(
2195 btcoexist
, NORMAL_EXEC
,
2197 coex_dm
->ps_tdma_du_adj_type
=
2199 } else if (coex_dm
->cur_ps_tdma
== 11) {
2200 btc8723b2ant_ps_tdma(
2201 btcoexist
, NORMAL_EXEC
,
2203 coex_dm
->ps_tdma_du_adj_type
=
2206 } else if (result
== 1) {
2207 if (coex_dm
->cur_ps_tdma
== 4) {
2208 btc8723b2ant_ps_tdma(
2209 btcoexist
, NORMAL_EXEC
,
2211 coex_dm
->ps_tdma_du_adj_type
=
2213 } else if (coex_dm
->cur_ps_tdma
== 3) {
2214 btc8723b2ant_ps_tdma(
2215 btcoexist
, NORMAL_EXEC
,
2217 coex_dm
->ps_tdma_du_adj_type
=
2219 } else if (coex_dm
->cur_ps_tdma
== 2) {
2220 btc8723b2ant_ps_tdma(
2221 btcoexist
, NORMAL_EXEC
,
2223 coex_dm
->ps_tdma_du_adj_type
=
2225 } else if (coex_dm
->cur_ps_tdma
== 1) {
2226 btc8723b2ant_ps_tdma(
2227 btcoexist
, NORMAL_EXEC
,
2229 coex_dm
->ps_tdma_du_adj_type
=
2231 } else if (coex_dm
->cur_ps_tdma
== 12) {
2232 btc8723b2ant_ps_tdma(
2233 btcoexist
, NORMAL_EXEC
,
2235 coex_dm
->ps_tdma_du_adj_type
=
2237 } else if (coex_dm
->cur_ps_tdma
== 11) {
2238 btc8723b2ant_ps_tdma(
2239 btcoexist
, NORMAL_EXEC
,
2241 coex_dm
->ps_tdma_du_adj_type
=
2243 } else if (coex_dm
->cur_ps_tdma
== 10) {
2244 btc8723b2ant_ps_tdma(
2245 btcoexist
, NORMAL_EXEC
,
2247 coex_dm
->ps_tdma_du_adj_type
=
2252 } else if (max_interval
== 2) {
2254 if (coex_dm
->cur_ps_tdma
== 1) {
2255 btc8723b2ant_ps_tdma(btcoexist
,
2258 coex_dm
->ps_tdma_du_adj_type
= 6;
2259 } else if (coex_dm
->cur_ps_tdma
== 2) {
2260 btc8723b2ant_ps_tdma(btcoexist
,
2263 coex_dm
->ps_tdma_du_adj_type
= 6;
2264 } else if (coex_dm
->cur_ps_tdma
== 3) {
2265 btc8723b2ant_ps_tdma(btcoexist
,
2268 coex_dm
->ps_tdma_du_adj_type
= 7;
2269 } else if (coex_dm
->cur_ps_tdma
== 4) {
2270 btc8723b2ant_ps_tdma(btcoexist
,
2273 coex_dm
->ps_tdma_du_adj_type
= 8;
2275 if (coex_dm
->cur_ps_tdma
== 9) {
2276 btc8723b2ant_ps_tdma(btcoexist
,
2279 coex_dm
->ps_tdma_du_adj_type
= 14;
2280 } else if (coex_dm
->cur_ps_tdma
== 10) {
2281 btc8723b2ant_ps_tdma(btcoexist
,
2284 coex_dm
->ps_tdma_du_adj_type
= 14;
2285 } else if (coex_dm
->cur_ps_tdma
== 11) {
2286 btc8723b2ant_ps_tdma(btcoexist
,
2289 coex_dm
->ps_tdma_du_adj_type
= 15;
2290 } else if (coex_dm
->cur_ps_tdma
== 12) {
2291 btc8723b2ant_ps_tdma(btcoexist
,
2294 coex_dm
->ps_tdma_du_adj_type
= 16;
2297 if (coex_dm
->cur_ps_tdma
== 5) {
2298 btc8723b2ant_ps_tdma(
2299 btcoexist
, NORMAL_EXEC
,
2301 coex_dm
->ps_tdma_du_adj_type
=
2303 } else if (coex_dm
->cur_ps_tdma
== 6) {
2304 btc8723b2ant_ps_tdma(
2305 btcoexist
, NORMAL_EXEC
,
2307 coex_dm
->ps_tdma_du_adj_type
=
2309 } else if (coex_dm
->cur_ps_tdma
== 7) {
2310 btc8723b2ant_ps_tdma(
2311 btcoexist
, NORMAL_EXEC
,
2313 coex_dm
->ps_tdma_du_adj_type
=
2315 } else if (coex_dm
->cur_ps_tdma
== 13) {
2316 btc8723b2ant_ps_tdma(
2317 btcoexist
, NORMAL_EXEC
,
2319 coex_dm
->ps_tdma_du_adj_type
=
2321 } else if (coex_dm
->cur_ps_tdma
== 14) {
2322 btc8723b2ant_ps_tdma(
2323 btcoexist
, NORMAL_EXEC
,
2325 coex_dm
->ps_tdma_du_adj_type
=
2327 } else if (coex_dm
->cur_ps_tdma
== 15) {
2328 btc8723b2ant_ps_tdma(
2329 btcoexist
, NORMAL_EXEC
,
2331 coex_dm
->ps_tdma_du_adj_type
=
2334 } else if (result
== 1) {
2335 if (coex_dm
->cur_ps_tdma
== 8) {
2336 btc8723b2ant_ps_tdma(
2337 btcoexist
, NORMAL_EXEC
,
2339 coex_dm
->ps_tdma_du_adj_type
=
2341 } else if (coex_dm
->cur_ps_tdma
== 7) {
2342 btc8723b2ant_ps_tdma(
2343 btcoexist
, NORMAL_EXEC
,
2345 coex_dm
->ps_tdma_du_adj_type
=
2347 } else if (coex_dm
->cur_ps_tdma
== 6) {
2348 btc8723b2ant_ps_tdma(
2349 btcoexist
, NORMAL_EXEC
,
2351 coex_dm
->ps_tdma_du_adj_type
=
2353 } else if (coex_dm
->cur_ps_tdma
== 16) {
2354 btc8723b2ant_ps_tdma(
2355 btcoexist
, NORMAL_EXEC
,
2357 coex_dm
->ps_tdma_du_adj_type
=
2359 } else if (coex_dm
->cur_ps_tdma
== 15) {
2360 btc8723b2ant_ps_tdma(
2361 btcoexist
, NORMAL_EXEC
,
2363 coex_dm
->ps_tdma_du_adj_type
=
2365 } else if (coex_dm
->cur_ps_tdma
== 14) {
2366 btc8723b2ant_ps_tdma(
2367 btcoexist
, NORMAL_EXEC
,
2369 coex_dm
->ps_tdma_du_adj_type
=
2374 if (coex_dm
->cur_ps_tdma
== 5) {
2375 btc8723b2ant_ps_tdma(btcoexist
,
2378 coex_dm
->ps_tdma_du_adj_type
= 2;
2379 } else if (coex_dm
->cur_ps_tdma
== 6) {
2380 btc8723b2ant_ps_tdma(btcoexist
,
2383 coex_dm
->ps_tdma_du_adj_type
= 2;
2384 } else if (coex_dm
->cur_ps_tdma
== 7) {
2385 btc8723b2ant_ps_tdma(btcoexist
,
2388 coex_dm
->ps_tdma_du_adj_type
= 3;
2389 } else if (coex_dm
->cur_ps_tdma
== 8) {
2390 btc8723b2ant_ps_tdma(btcoexist
,
2393 coex_dm
->ps_tdma_du_adj_type
= 4;
2395 if (coex_dm
->cur_ps_tdma
== 13) {
2396 btc8723b2ant_ps_tdma(btcoexist
,
2399 coex_dm
->ps_tdma_du_adj_type
= 10;
2400 } else if (coex_dm
->cur_ps_tdma
== 14) {
2401 btc8723b2ant_ps_tdma(btcoexist
,
2404 coex_dm
->ps_tdma_du_adj_type
= 10;
2405 } else if (coex_dm
->cur_ps_tdma
== 15) {
2406 btc8723b2ant_ps_tdma(btcoexist
,
2409 coex_dm
->ps_tdma_du_adj_type
= 11;
2410 } else if (coex_dm
->cur_ps_tdma
== 16) {
2411 btc8723b2ant_ps_tdma(btcoexist
,
2414 coex_dm
->ps_tdma_du_adj_type
= 12;
2417 if (coex_dm
->cur_ps_tdma
== 1) {
2418 btc8723b2ant_ps_tdma(
2419 btcoexist
, NORMAL_EXEC
,
2421 coex_dm
->ps_tdma_du_adj_type
=
2423 } else if (coex_dm
->cur_ps_tdma
== 2) {
2424 btc8723b2ant_ps_tdma(
2425 btcoexist
, NORMAL_EXEC
,
2427 coex_dm
->ps_tdma_du_adj_type
=
2429 } else if (coex_dm
->cur_ps_tdma
== 3) {
2430 btc8723b2ant_ps_tdma(
2431 btcoexist
, NORMAL_EXEC
,
2433 coex_dm
->ps_tdma_du_adj_type
=
2435 } else if (coex_dm
->cur_ps_tdma
== 9) {
2436 btc8723b2ant_ps_tdma(
2437 btcoexist
, NORMAL_EXEC
,
2439 coex_dm
->ps_tdma_du_adj_type
=
2441 } else if (coex_dm
->cur_ps_tdma
== 10) {
2442 btc8723b2ant_ps_tdma(
2443 btcoexist
, NORMAL_EXEC
,
2445 coex_dm
->ps_tdma_du_adj_type
=
2447 } else if (coex_dm
->cur_ps_tdma
== 11) {
2448 btc8723b2ant_ps_tdma(
2449 btcoexist
, NORMAL_EXEC
,
2451 coex_dm
->ps_tdma_du_adj_type
=
2454 } else if (result
== 1) {
2455 if (coex_dm
->cur_ps_tdma
== 4) {
2456 btc8723b2ant_ps_tdma(
2457 btcoexist
, NORMAL_EXEC
,
2459 coex_dm
->ps_tdma_du_adj_type
=
2461 } else if (coex_dm
->cur_ps_tdma
== 3) {
2462 btc8723b2ant_ps_tdma(
2463 btcoexist
, NORMAL_EXEC
,
2465 coex_dm
->ps_tdma_du_adj_type
=
2467 } else if (coex_dm
->cur_ps_tdma
== 2) {
2468 btc8723b2ant_ps_tdma(
2469 btcoexist
, NORMAL_EXEC
,
2471 coex_dm
->ps_tdma_du_adj_type
=
2473 } else if (coex_dm
->cur_ps_tdma
== 12) {
2474 btc8723b2ant_ps_tdma(
2475 btcoexist
, NORMAL_EXEC
,
2477 coex_dm
->ps_tdma_du_adj_type
=
2479 } else if (coex_dm
->cur_ps_tdma
== 11) {
2480 btc8723b2ant_ps_tdma(
2481 btcoexist
, NORMAL_EXEC
,
2483 coex_dm
->ps_tdma_du_adj_type
=
2485 } else if (coex_dm
->cur_ps_tdma
== 10) {
2486 btc8723b2ant_ps_tdma(
2487 btcoexist
, NORMAL_EXEC
,
2489 coex_dm
->ps_tdma_du_adj_type
=
2494 } else if (max_interval
== 3) {
2496 if (coex_dm
->cur_ps_tdma
== 1) {
2497 btc8723b2ant_ps_tdma(btcoexist
,
2500 coex_dm
->ps_tdma_du_adj_type
= 7;
2501 } else if (coex_dm
->cur_ps_tdma
== 2) {
2502 btc8723b2ant_ps_tdma(btcoexist
,
2505 coex_dm
->ps_tdma_du_adj_type
= 7;
2506 } else if (coex_dm
->cur_ps_tdma
== 3) {
2507 btc8723b2ant_ps_tdma(btcoexist
,
2510 coex_dm
->ps_tdma_du_adj_type
= 7;
2511 } else if (coex_dm
->cur_ps_tdma
== 4) {
2512 btc8723b2ant_ps_tdma(btcoexist
,
2515 coex_dm
->ps_tdma_du_adj_type
= 8;
2517 if (coex_dm
->cur_ps_tdma
== 9) {
2518 btc8723b2ant_ps_tdma(btcoexist
,
2521 coex_dm
->ps_tdma_du_adj_type
= 15;
2522 } else if (coex_dm
->cur_ps_tdma
== 10) {
2523 btc8723b2ant_ps_tdma(btcoexist
,
2526 coex_dm
->ps_tdma_du_adj_type
= 15;
2527 } else if (coex_dm
->cur_ps_tdma
== 11) {
2528 btc8723b2ant_ps_tdma(btcoexist
,
2531 coex_dm
->ps_tdma_du_adj_type
= 15;
2532 } else if (coex_dm
->cur_ps_tdma
== 12) {
2533 btc8723b2ant_ps_tdma(btcoexist
,
2536 coex_dm
->ps_tdma_du_adj_type
= 16;
2539 if (coex_dm
->cur_ps_tdma
== 5) {
2540 btc8723b2ant_ps_tdma(
2541 btcoexist
, NORMAL_EXEC
,
2543 coex_dm
->ps_tdma_du_adj_type
=
2545 } else if (coex_dm
->cur_ps_tdma
== 6) {
2546 btc8723b2ant_ps_tdma(
2547 btcoexist
, NORMAL_EXEC
,
2549 coex_dm
->ps_tdma_du_adj_type
=
2551 } else if (coex_dm
->cur_ps_tdma
== 7) {
2552 btc8723b2ant_ps_tdma(
2553 btcoexist
, NORMAL_EXEC
,
2555 coex_dm
->ps_tdma_du_adj_type
=
2557 } else if (coex_dm
->cur_ps_tdma
== 13) {
2558 btc8723b2ant_ps_tdma(
2559 btcoexist
, NORMAL_EXEC
,
2561 coex_dm
->ps_tdma_du_adj_type
=
2563 } else if (coex_dm
->cur_ps_tdma
== 14) {
2564 btc8723b2ant_ps_tdma(
2565 btcoexist
, NORMAL_EXEC
,
2567 coex_dm
->ps_tdma_du_adj_type
=
2569 } else if (coex_dm
->cur_ps_tdma
== 15) {
2570 btc8723b2ant_ps_tdma(
2571 btcoexist
, NORMAL_EXEC
,
2573 coex_dm
->ps_tdma_du_adj_type
=
2576 } else if (result
== 1) {
2577 if (coex_dm
->cur_ps_tdma
== 8) {
2578 btc8723b2ant_ps_tdma(
2579 btcoexist
, NORMAL_EXEC
,
2581 coex_dm
->ps_tdma_du_adj_type
=
2583 } else if (coex_dm
->cur_ps_tdma
== 7) {
2584 btc8723b2ant_ps_tdma(
2585 btcoexist
, NORMAL_EXEC
,
2587 coex_dm
->ps_tdma_du_adj_type
=
2589 } else if (coex_dm
->cur_ps_tdma
== 6) {
2590 btc8723b2ant_ps_tdma(
2591 btcoexist
, NORMAL_EXEC
,
2593 coex_dm
->ps_tdma_du_adj_type
=
2595 } else if (coex_dm
->cur_ps_tdma
== 16) {
2596 btc8723b2ant_ps_tdma(
2597 btcoexist
, NORMAL_EXEC
,
2599 coex_dm
->ps_tdma_du_adj_type
=
2601 } else if (coex_dm
->cur_ps_tdma
== 15) {
2602 btc8723b2ant_ps_tdma(
2603 btcoexist
, NORMAL_EXEC
,
2605 coex_dm
->ps_tdma_du_adj_type
=
2607 } else if (coex_dm
->cur_ps_tdma
== 14) {
2608 btc8723b2ant_ps_tdma(
2609 btcoexist
, NORMAL_EXEC
,
2611 coex_dm
->ps_tdma_du_adj_type
=
2616 if (coex_dm
->cur_ps_tdma
== 5) {
2617 btc8723b2ant_ps_tdma(btcoexist
,
2620 coex_dm
->ps_tdma_du_adj_type
= 3;
2621 } else if (coex_dm
->cur_ps_tdma
== 6) {
2622 btc8723b2ant_ps_tdma(btcoexist
,
2625 coex_dm
->ps_tdma_du_adj_type
= 3;
2626 } else if (coex_dm
->cur_ps_tdma
== 7) {
2627 btc8723b2ant_ps_tdma(btcoexist
,
2630 coex_dm
->ps_tdma_du_adj_type
= 3;
2631 } else if (coex_dm
->cur_ps_tdma
== 8) {
2632 btc8723b2ant_ps_tdma(btcoexist
,
2635 coex_dm
->ps_tdma_du_adj_type
= 4;
2637 if (coex_dm
->cur_ps_tdma
== 13) {
2638 btc8723b2ant_ps_tdma(btcoexist
,
2641 coex_dm
->ps_tdma_du_adj_type
= 11;
2642 } else if (coex_dm
->cur_ps_tdma
== 14) {
2643 btc8723b2ant_ps_tdma(btcoexist
,
2646 coex_dm
->ps_tdma_du_adj_type
= 11;
2647 } else if (coex_dm
->cur_ps_tdma
== 15) {
2648 btc8723b2ant_ps_tdma(btcoexist
,
2651 coex_dm
->ps_tdma_du_adj_type
= 11;
2652 } else if (coex_dm
->cur_ps_tdma
== 16) {
2653 btc8723b2ant_ps_tdma(btcoexist
,
2656 coex_dm
->ps_tdma_du_adj_type
= 12;
2659 if (coex_dm
->cur_ps_tdma
== 1) {
2660 btc8723b2ant_ps_tdma(
2661 btcoexist
, NORMAL_EXEC
,
2663 coex_dm
->ps_tdma_du_adj_type
=
2665 } else if (coex_dm
->cur_ps_tdma
== 2) {
2666 btc8723b2ant_ps_tdma(
2667 btcoexist
, NORMAL_EXEC
,
2669 coex_dm
->ps_tdma_du_adj_type
=
2671 } else if (coex_dm
->cur_ps_tdma
== 3) {
2672 btc8723b2ant_ps_tdma(
2673 btcoexist
, NORMAL_EXEC
,
2675 coex_dm
->ps_tdma_du_adj_type
=
2677 } else if (coex_dm
->cur_ps_tdma
== 9) {
2678 btc8723b2ant_ps_tdma(
2679 btcoexist
, NORMAL_EXEC
,
2681 coex_dm
->ps_tdma_du_adj_type
=
2683 } else if (coex_dm
->cur_ps_tdma
== 10) {
2684 btc8723b2ant_ps_tdma(
2685 btcoexist
, NORMAL_EXEC
,
2687 coex_dm
->ps_tdma_du_adj_type
=
2689 } else if (coex_dm
->cur_ps_tdma
== 11) {
2690 btc8723b2ant_ps_tdma(
2691 btcoexist
, NORMAL_EXEC
,
2693 coex_dm
->ps_tdma_du_adj_type
=
2696 } else if (result
== 1) {
2697 if (coex_dm
->cur_ps_tdma
== 4) {
2698 btc8723b2ant_ps_tdma(
2699 btcoexist
, NORMAL_EXEC
,
2701 coex_dm
->ps_tdma_du_adj_type
=
2703 } else if (coex_dm
->cur_ps_tdma
== 3) {
2704 btc8723b2ant_ps_tdma(
2705 btcoexist
, NORMAL_EXEC
,
2707 coex_dm
->ps_tdma_du_adj_type
=
2709 } else if (coex_dm
->cur_ps_tdma
== 2) {
2710 btc8723b2ant_ps_tdma(
2711 btcoexist
, NORMAL_EXEC
,
2713 coex_dm
->ps_tdma_du_adj_type
=
2715 } else if (coex_dm
->cur_ps_tdma
== 12) {
2716 btc8723b2ant_ps_tdma(
2717 btcoexist
, NORMAL_EXEC
,
2719 coex_dm
->ps_tdma_du_adj_type
=
2721 } else if (coex_dm
->cur_ps_tdma
== 11) {
2722 btc8723b2ant_ps_tdma(
2723 btcoexist
, NORMAL_EXEC
,
2725 coex_dm
->ps_tdma_du_adj_type
=
2727 } else if (coex_dm
->cur_ps_tdma
== 10) {
2728 btc8723b2ant_ps_tdma(
2729 btcoexist
, NORMAL_EXEC
,
2731 coex_dm
->ps_tdma_du_adj_type
=
2739 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2740 "[BTCoex], max Interval = %d\n", max_interval
);
2742 /* if current PsTdma not match with the recorded one (scan, dhcp, ...),
2743 * then we have to adjust it back to the previous recorded one.
2745 if (coex_dm
->cur_ps_tdma
!= coex_dm
->ps_tdma_du_adj_type
) {
2746 bool scan
= false, link
= false, roam
= false;
2747 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2748 "[BTCoex], PsTdma type mismatch!!!, curPsTdma=%d, recordPsTdma=%d\n",
2749 coex_dm
->cur_ps_tdma
, coex_dm
->ps_tdma_du_adj_type
);
2751 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2752 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2753 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2755 if (!scan
&& !link
&& !roam
)
2756 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
2757 coex_dm
->ps_tdma_du_adj_type
);
2759 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2760 "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
2764 /* SCO only or SCO+PAN(HS) */
2765 static void btc8723b2ant_action_sco(struct btc_coexist
*btcoexist
)
2767 u8 wifi_rssi_state
, bt_rssi_state
;
2770 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2771 bt_rssi_state
= btc8723b2ant_bt_rssi_state(
2772 btcoexist
, 2, BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
2773 coex_dm
->switch_thres_offset
,
2776 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2778 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2779 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 4);
2781 if (BTC_RSSI_HIGH(bt_rssi_state
))
2782 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
2784 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
2786 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2788 if (BTC_WIFI_BW_LEGACY
== wifi_bw
)
2789 /* for SCO quality at 11b/g mode */
2790 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
2792 /* for SCO quality & wifi performance balance at 11n mode */
2793 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 8);
2795 /* for voice quality */
2796 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
2799 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2800 btc8723b2ant_sw_mechanism(btcoexist
, true, true,
2803 btc8723b2ant_sw_mechanism(btcoexist
, false, true,
2808 static void btc8723b2ant_action_hid(struct btc_coexist
*btcoexist
)
2810 u8 wifi_rssi_state
, bt_rssi_state
;
2812 u8 tmp
= BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
2813 coex_dm
->switch_thres_offset
;
2815 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2816 bt_rssi_state
= btc8723b2ant_bt_rssi_state(btcoexist
, 2, tmp
, 0);
2818 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2820 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2821 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2823 if (BTC_RSSI_HIGH(bt_rssi_state
))
2824 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
2826 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
2828 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2830 if (wifi_bw
== BTC_WIFI_BW_LEGACY
)
2831 /* for HID at 11b/g mode */
2832 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
2834 /* for HID quality & wifi performance balance at 11n mode */
2835 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 9);
2837 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
2839 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2840 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
))
2841 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 9);
2843 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 13);
2846 if (wifi_bw
== BTC_WIFI_BW_HT40
)
2847 btc8723b2ant_sw_mechanism(btcoexist
, true, true, false, false);
2849 btc8723b2ant_sw_mechanism(btcoexist
, false, true, false, false);
2852 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
2853 static void btc8723b2ant_action_a2dp(struct btc_coexist
*btcoexist
)
2855 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
2858 u8 tmp
= BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
2859 coex_dm
->switch_thres_offset
;
2861 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2862 wifi_rssi_state1
= btc8723b2ant_wifi_rssi_state(btcoexist
, 1, 2, 40, 0);
2863 bt_rssi_state
= btc8723b2ant_bt_rssi_state(btcoexist
, 2, tmp
, 0);
2865 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_AP_NUM
, &ap_num
);
2867 /* define the office environment */
2868 /* driver don't know AP num in Linux, so we will never enter this if */
2869 if (ap_num
>= 10 && BTC_RSSI_HIGH(wifi_rssi_state1
)) {
2870 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff,
2872 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2873 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2874 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
2875 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
2878 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2879 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2880 btc8723b2ant_sw_mechanism(btcoexist
, true, false,
2883 btc8723b2ant_sw_mechanism(btcoexist
, false, false,
2889 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2890 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2892 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2894 if (BTC_RSSI_HIGH(bt_rssi_state
))
2895 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
2897 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
2899 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
)) {
2900 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
2901 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2904 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 13);
2905 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
2909 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2910 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
))
2911 btc8723b2ant_tdma_duration_adjust(btcoexist
, false,
2914 btc8723b2ant_tdma_duration_adjust(btcoexist
, false, true, 1);
2917 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2918 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2919 btc8723b2ant_sw_mechanism(btcoexist
, true, false,
2922 btc8723b2ant_sw_mechanism(btcoexist
, false, false,
2927 static void btc8723b2ant_action_a2dp_pan_hs(struct btc_coexist
*btcoexist
)
2929 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
2931 u8 tmp
= BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES
-
2932 coex_dm
->switch_thres_offset
;
2934 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2935 wifi_rssi_state1
= btc8723b2ant_wifi_rssi_state(btcoexist
, 1, 2,
2937 tmp
= BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
2938 coex_dm
->switch_thres_offset
;
2939 bt_rssi_state
= btc8723b2ant_bt_rssi_state(btcoexist
, 2, tmp
, 0);
2941 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2943 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2944 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2946 if (BTC_RSSI_HIGH(bt_rssi_state
))
2947 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
2949 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
2951 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
)) {
2952 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
2953 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2956 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 13);
2957 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
2961 btc8723b2ant_tdma_duration_adjust(btcoexist
, false, true, 2);
2964 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2965 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2966 btc8723b2ant_sw_mechanism(btcoexist
, true, false,
2969 btc8723b2ant_sw_mechanism(btcoexist
, false, false,
2974 static void btc8723b2ant_action_pan_edr(struct btc_coexist
*btcoexist
)
2976 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
2978 u8 tmp
= BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES
-
2979 coex_dm
->switch_thres_offset
;
2981 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2982 wifi_rssi_state1
= btc8723b2ant_wifi_rssi_state(btcoexist
, 1, 2,
2984 tmp
= BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
2985 coex_dm
->switch_thres_offset
;
2986 bt_rssi_state
= btc8723b2ant_bt_rssi_state(btcoexist
, 2, tmp
, 0);
2988 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2990 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2991 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2993 if (BTC_RSSI_HIGH(bt_rssi_state
))
2994 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
2996 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
2998 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
)) {
2999 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 10);
3000 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3003 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 13);
3004 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
3008 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3009 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
))
3010 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 1);
3012 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 5);
3015 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3016 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
3017 btc8723b2ant_sw_mechanism(btcoexist
, true, false,
3020 btc8723b2ant_sw_mechanism(btcoexist
, false, false,
3026 static void btc8723b2ant_action_pan_hs(struct btc_coexist
*btcoexist
)
3028 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
3030 u8 tmp
= BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES
-
3031 coex_dm
->switch_thres_offset
;
3033 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
3034 wifi_rssi_state1
= btc8723b2ant_wifi_rssi_state(btcoexist
, 1, 2,
3036 tmp
= BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
3037 coex_dm
->switch_thres_offset
;
3038 bt_rssi_state
= btc8723b2ant_bt_rssi_state(btcoexist
, 2, tmp
, 0);
3040 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
3042 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
3043 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3045 if (BTC_RSSI_HIGH(bt_rssi_state
))
3046 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3048 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3050 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
3051 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
3053 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3054 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
3055 btc8723b2ant_sw_mechanism(btcoexist
, true, false,
3058 btc8723b2ant_sw_mechanism(btcoexist
, false, false,
3063 /* PAN(EDR) + A2DP */
3064 static void btc8723b2ant_action_pan_edr_a2dp(struct btc_coexist
*btcoexist
)
3066 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
3068 u8 tmp
= BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES
-
3069 coex_dm
->switch_thres_offset
;
3071 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
3072 wifi_rssi_state1
= btc8723b2ant_wifi_rssi_state(btcoexist
, 1, 2,
3074 tmp
= BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
3075 coex_dm
->switch_thres_offset
;
3076 bt_rssi_state
= btc8723b2ant_bt_rssi_state(btcoexist
, 2, tmp
, 0);
3078 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
3080 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3082 if (BTC_RSSI_HIGH(bt_rssi_state
))
3083 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3085 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3087 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
))
3088 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3091 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
3093 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3095 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3096 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3097 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 12);
3098 if (BTC_WIFI_BW_HT40
== wifi_bw
)
3099 btc8723b2ant_tdma_duration_adjust(btcoexist
, false,
3102 btc8723b2ant_tdma_duration_adjust(btcoexist
, false,
3105 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
3106 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
3110 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
3111 btc8723b2ant_sw_mechanism(btcoexist
, true, false,
3114 btc8723b2ant_sw_mechanism(btcoexist
, false, false,
3119 static void btc8723b2ant_action_pan_edr_hid(struct btc_coexist
*btcoexist
)
3121 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
3123 u8 tmp
= BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES
-
3124 coex_dm
->switch_thres_offset
;
3126 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
3127 wifi_rssi_state1
= btc8723b2ant_wifi_rssi_state(btcoexist
, 1, 2,
3129 tmp
= BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
3130 coex_dm
->switch_thres_offset
;
3131 bt_rssi_state
= btc8723b2ant_bt_rssi_state(btcoexist
, 2, tmp
, 0);
3132 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3134 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
3136 if (BTC_RSSI_HIGH(bt_rssi_state
))
3137 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3139 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3141 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
)) {
3142 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
3143 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3146 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 14);
3147 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
3151 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3152 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3153 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
3154 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
,
3156 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1,
3159 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
,
3161 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1,
3164 btc8723b2ant_tdma_duration_adjust(btcoexist
, true, false, 2);
3166 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3167 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff,
3169 btc8723b2ant_tdma_duration_adjust(btcoexist
, true, true, 2);
3173 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
3174 btc8723b2ant_sw_mechanism(btcoexist
, true, true,
3177 btc8723b2ant_sw_mechanism(btcoexist
, false, true,
3182 /* HID + A2DP + PAN(EDR) */
3183 static void btc8723b2ant_action_hid_a2dp_pan_edr(struct btc_coexist
*btcoexist
)
3185 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
3187 u8 tmp
= BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES
-
3188 coex_dm
->switch_thres_offset
;
3190 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
3191 wifi_rssi_state1
= btc8723b2ant_wifi_rssi_state(btcoexist
, 1, 2,
3193 tmp
= BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
3194 coex_dm
->switch_thres_offset
;
3195 bt_rssi_state
= btc8723b2ant_bt_rssi_state(btcoexist
, 2, tmp
, 0);
3197 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
3199 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
3200 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3202 if (BTC_RSSI_HIGH(bt_rssi_state
))
3203 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3205 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3207 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
)) {
3208 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
3209 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3212 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 14);
3213 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
3217 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3220 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3221 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3222 if (BTC_WIFI_BW_HT40
== wifi_bw
)
3223 btc8723b2ant_tdma_duration_adjust(btcoexist
, true,
3226 btc8723b2ant_tdma_duration_adjust(btcoexist
, true,
3229 btc8723b2ant_tdma_duration_adjust(btcoexist
, true, true, 3);
3233 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
3234 btc8723b2ant_sw_mechanism(btcoexist
, true, true,
3237 btc8723b2ant_sw_mechanism(btcoexist
, false, true,
3242 static void btc8723b2ant_action_hid_a2dp(struct btc_coexist
*btcoexist
)
3244 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
3247 u8 tmp
= BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES
-
3248 coex_dm
->switch_thres_offset
;
3250 wifi_rssi_state
= btc8723b2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
3251 wifi_rssi_state1
= btc8723b2ant_wifi_rssi_state(btcoexist
, 1, 2,
3253 tmp
= BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES
-
3254 coex_dm
->switch_thres_offset
;
3255 bt_rssi_state
= btc8723b2ant_bt_rssi_state(btcoexist
, 3, tmp
, 37);
3257 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
3259 btc8723b2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, true, 0x5);
3260 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3262 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3264 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
3265 if (BTC_RSSI_HIGH(bt_rssi_state
))
3266 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3267 else if (BTC_RSSI_MEDIUM(bt_rssi_state
))
3268 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3270 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3272 /* only 802.11N mode we have to dec bt power to 4 degree */
3273 if (BTC_RSSI_HIGH(bt_rssi_state
)) {
3274 /* need to check ap Number of Not */
3276 btc8723b2ant_dec_bt_pwr(btcoexist
,
3279 btc8723b2ant_dec_bt_pwr(btcoexist
,
3281 } else if (BTC_RSSI_MEDIUM(bt_rssi_state
)) {
3282 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3284 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3288 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
)) {
3289 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
3290 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3293 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 14);
3294 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
3298 if (BTC_RSSI_HIGH(bt_rssi_state
)) {
3300 btc8723b2ant_tdma_duration_adjust(btcoexist
, true,
3303 btc8723b2ant_tdma_duration_adjust(btcoexist
, true,
3306 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 18);
3307 btcoexist
->btc_write_1byte(btcoexist
, 0x456, 0x38);
3308 btcoexist
->btc_write_2byte(btcoexist
, 0x42a, 0x0808);
3309 btcoexist
->btc_write_4byte(btcoexist
, 0x430, 0x0);
3310 btcoexist
->btc_write_4byte(btcoexist
, 0x434, 0x01010000);
3313 btc8723b2ant_tdma_duration_adjust(btcoexist
, true,
3316 btc8723b2ant_tdma_duration_adjust(btcoexist
, true,
3321 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
3322 btc8723b2ant_sw_mechanism(btcoexist
, true, true,
3325 btc8723b2ant_sw_mechanism(btcoexist
, false, true,
3330 static void btc8723b2ant_action_wifi_multi_port(struct btc_coexist
*btcoexist
)
3332 btc8723b2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3333 btc8723b2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3336 btc8723b2ant_sw_mechanism(btcoexist
, false, false, false, false);
3339 btc8723b2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
3341 btc8723b2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
3342 btc8723b2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
3345 static void btc8723b2ant_run_coexist_mechanism(struct btc_coexist
*btcoexist
)
3347 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3349 u32 num_of_wifi_link
= 0;
3350 u32 wifi_link_status
= 0;
3351 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
3352 bool miracast_plus_bt
= false;
3353 bool scan
= false, link
= false, roam
= false;
3355 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3356 "[BTCoex], RunCoexistMechanism()===>\n");
3358 if (btcoexist
->manual_control
) {
3359 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3360 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
3364 if (coex_sta
->under_ips
) {
3365 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3366 "[BTCoex], wifi is under IPS !!!\n");
3370 algorithm
= btc8723b2ant_action_algorithm(btcoexist
);
3371 if (coex_sta
->c2h_bt_inquiry_page
&&
3372 (BT_8723B_2ANT_COEX_ALGO_PANHS
!= algorithm
)) {
3373 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3374 "[BTCoex], BT is under inquiry/page scan !!\n");
3375 btc8723b2ant_action_bt_inquiry(btcoexist
);
3379 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
3380 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
3381 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
3383 if (scan
|| link
|| roam
) {
3384 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3385 "[BTCoex], WiFi is under Link Process !!\n");
3386 btc8723b2ant_action_wifi_link_process(btcoexist
);
3391 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
3393 num_of_wifi_link
= wifi_link_status
>> 16;
3395 if ((num_of_wifi_link
>= 2) ||
3396 (wifi_link_status
& WIFI_P2P_GO_CONNECTED
)) {
3397 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3398 "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
3399 num_of_wifi_link
, wifi_link_status
);
3401 if (bt_link_info
->bt_link_exist
)
3402 miracast_plus_bt
= true;
3404 miracast_plus_bt
= false;
3406 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_MIRACAST_PLUS_BT
,
3408 btc8723b2ant_action_wifi_multi_port(btcoexist
);
3413 miracast_plus_bt
= false;
3414 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_MIRACAST_PLUS_BT
,
3417 coex_dm
->cur_algorithm
= algorithm
;
3418 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3419 "[BTCoex], Algorithm = %d\n",
3420 coex_dm
->cur_algorithm
);
3422 if (btc8723b2ant_is_common_action(btcoexist
)) {
3423 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3424 "[BTCoex], Action 2-Ant common\n");
3425 coex_dm
->auto_tdma_adjust
= false;
3427 if (coex_dm
->cur_algorithm
!= coex_dm
->pre_algorithm
) {
3428 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3429 "[BTCoex], preAlgorithm=%d, curAlgorithm=%d\n",
3430 coex_dm
->pre_algorithm
,
3431 coex_dm
->cur_algorithm
);
3432 coex_dm
->auto_tdma_adjust
= false;
3434 switch (coex_dm
->cur_algorithm
) {
3435 case BT_8723B_2ANT_COEX_ALGO_SCO
:
3436 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3437 "[BTCoex], Action 2-Ant, algorithm = SCO\n");
3438 btc8723b2ant_action_sco(btcoexist
);
3440 case BT_8723B_2ANT_COEX_ALGO_HID
:
3441 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3442 "[BTCoex], Action 2-Ant, algorithm = HID\n");
3443 btc8723b2ant_action_hid(btcoexist
);
3445 case BT_8723B_2ANT_COEX_ALGO_A2DP
:
3446 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3447 "[BTCoex], Action 2-Ant, algorithm = A2DP\n");
3448 btc8723b2ant_action_a2dp(btcoexist
);
3450 case BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS
:
3451 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3452 "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS)\n");
3453 btc8723b2ant_action_a2dp_pan_hs(btcoexist
);
3455 case BT_8723B_2ANT_COEX_ALGO_PANEDR
:
3456 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3457 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)\n");
3458 btc8723b2ant_action_pan_edr(btcoexist
);
3460 case BT_8723B_2ANT_COEX_ALGO_PANHS
:
3461 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3462 "[BTCoex], Action 2-Ant, algorithm = HS mode\n");
3463 btc8723b2ant_action_pan_hs(btcoexist
);
3465 case BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP
:
3466 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3467 "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP\n");
3468 btc8723b2ant_action_pan_edr_a2dp(btcoexist
);
3470 case BT_8723B_2ANT_COEX_ALGO_PANEDR_HID
:
3471 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3472 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID\n");
3473 btc8723b2ant_action_pan_edr_hid(btcoexist
);
3475 case BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR
:
3476 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3477 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN\n");
3478 btc8723b2ant_action_hid_a2dp_pan_edr(btcoexist
);
3480 case BT_8723B_2ANT_COEX_ALGO_HID_A2DP
:
3481 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3482 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP\n");
3483 btc8723b2ant_action_hid_a2dp(btcoexist
);
3486 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3487 "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3488 btc8723b2ant_coex_alloff(btcoexist
);
3491 coex_dm
->pre_algorithm
= coex_dm
->cur_algorithm
;
3495 static void btc8723b2ant_wifioff_hwcfg(struct btc_coexist
*btcoexist
)
3497 bool is_in_mp_mode
= false;
3498 u8 h2c_parameter
[2] = {0};
3501 /* set wlan_act to low */
3502 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
3504 /* WiFi standby while GNT_BT 0 -> 1 */
3505 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x780);
3507 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
3508 if (fw_ver
>= 0x180000) {
3509 /* Use H2C to set GNT_BT to HIGH */
3510 h2c_parameter
[0] = 1;
3511 btcoexist
->btc_fill_h2c(btcoexist
, 0x6E, 1, h2c_parameter
);
3513 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x18);
3516 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_IS_IN_MP_MODE
,
3519 /* BT select s0/s1 is controlled by BT */
3520 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67, 0x20, 0x0);
3522 /* BT select s0/s1 is controlled by WiFi */
3523 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x67, 0x20, 0x1);
3526 /*********************************************************************
3527 * extern function start with ex_btc8723b2ant_
3528 *********************************************************************/
3529 void ex_btc8723b2ant_init_hwconfig(struct btc_coexist
*btcoexist
)
3531 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3534 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3535 "[BTCoex], 2Ant Init HW Config!!\n");
3536 coex_dm
->bt_rf0x1e_backup
=
3537 btcoexist
->btc_get_rf_reg(btcoexist
, BTC_RF_A
, 0x1e, 0xfffff);
3539 /* 0x790[5:0] = 0x5 */
3540 u8tmp
= btcoexist
->btc_read_1byte(btcoexist
, 0x790);
3543 btcoexist
->btc_write_1byte(btcoexist
, 0x790, u8tmp
);
3545 /* Antenna config */
3546 btc8723b2ant_set_ant_path(btcoexist
, BTC_ANT_WIFI_AT_MAIN
,
3548 coex_sta
->dis_ver_info_cnt
= 0;
3551 btc8723b2ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 0);
3553 /* Enable counter statistics */
3554 /* 0x76e[3] = 1, WLAN_ACT controlled by PTA */
3555 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
3556 btcoexist
->btc_write_1byte(btcoexist
, 0x778, 0x3);
3557 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x40, 0x20, 0x1);
3558 btcoexist
->auto_report_2ant
= true;
3561 void ex_btc8723b2ant_power_on_setting(struct btc_coexist
*btcoexist
)
3563 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
3567 btcoexist
->btc_write_1byte(btcoexist
, 0x67, 0x20);
3569 /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly */
3570 u16tmp
= btcoexist
->btc_read_2byte(btcoexist
, 0x2);
3571 btcoexist
->btc_write_2byte(btcoexist
, 0x2, u16tmp
| BIT0
| BIT1
);
3573 btcoexist
->btc_write_4byte(btcoexist
, 0x948, 0x0);
3575 if (btcoexist
->chip_interface
== BTC_INTF_USB
) {
3576 /* fixed at S0 for USB interface */
3577 board_info
->btdm_ant_pos
= BTC_ANTENNA_AT_AUX_PORT
;
3579 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
3580 if (board_info
->single_ant_path
== 0) {
3582 board_info
->btdm_ant_pos
= BTC_ANTENNA_AT_MAIN_PORT
;
3583 } else if (board_info
->single_ant_path
== 1) {
3585 board_info
->btdm_ant_pos
= BTC_ANTENNA_AT_AUX_PORT
;
3587 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_ANTPOSREGRISTRY_CTRL
,
3592 void ex_btc8723b2ant_pre_load_firmware(struct btc_coexist
*btcoexist
)
3594 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
3595 u8 u8tmp
= 0x4; /* Set BIT2 by default since it's 2ant case */
3598 * S0 or S1 setting and Local register setting(By this fw can get
3599 * ant number, S0/S1, ... info)
3601 * Local setting bit define
3602 * BIT0: "0" : no antenna inverse; "1" : antenna inverse
3603 * BIT1: "0" : internal switch; "1" : external switch
3604 * BIT2: "0" : one antenna; "1" : two antennas
3606 * NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and
3609 if (btcoexist
->chip_interface
== BTC_INTF_USB
) {
3610 /* fixed at S0 for USB interface */
3611 u8tmp
|= 0x1; /* antenna inverse */
3612 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0xfe08, u8tmp
);
3614 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
3615 if (board_info
->single_ant_path
== 0) {
3616 } else if (board_info
->single_ant_path
== 1) {
3618 u8tmp
|= 0x1; /* antenna inverse */
3621 if (btcoexist
->chip_interface
== BTC_INTF_PCI
)
3622 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0x384,
3624 else if (btcoexist
->chip_interface
== BTC_INTF_SDIO
)
3625 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0x60,
3630 void ex_btc8723b2ant_init_coex_dm(struct btc_coexist
*btcoexist
)
3632 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3634 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3635 "[BTCoex], Coex Mechanism Init!!\n");
3636 btc8723b2ant_init_coex_dm(btcoexist
);
3639 void ex_btc8723b2ant_display_coex_info(struct btc_coexist
*btcoexist
,
3642 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
3643 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
3644 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
3645 u8 u8tmp
[4], i
, bt_info_ext
, ps_tdma_case
= 0;
3647 bool roam
= false, scan
= false;
3648 bool link
= false, wifi_under_5g
= false;
3649 bool bt_hs_on
= false, wifi_busy
= false;
3650 s32 wifi_rssi
= 0, bt_hs_rssi
= 0;
3651 u32 wifi_bw
, wifi_traffic_dir
, fa_ofdm
, fa_cck
;
3652 u8 wifi_dot11_chnl
, wifi_hs_chnl
;
3653 u32 fw_ver
= 0, bt_patch_ver
= 0;
3656 seq_puts(m
, "\n ============[BT Coexist info]============");
3658 if (btcoexist
->manual_control
) {
3659 seq_puts(m
, "\n ==========[Under Manual Control]============");
3660 seq_puts(m
, "\n ==========================================");
3663 seq_printf(m
, "\n %-35s = %d/ %d ",
3664 "Ant PG number/ Ant mechanism:",
3665 board_info
->pg_ant_num
, board_info
->btdm_ant_num
);
3667 seq_printf(m
, "\n %-35s = %s / %d",
3668 "BT stack/ hci ext ver",
3669 ((stack_info
->profile_notified
) ? "Yes" : "No"),
3670 stack_info
->hci_version
);
3672 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
, &bt_patch_ver
);
3673 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
3674 seq_printf(m
, "\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
3675 "CoexVer/ FwVer/ PatchVer",
3676 glcoex_ver_date_8723b_2ant
, glcoex_ver_8723b_2ant
,
3677 fw_ver
, bt_patch_ver
, bt_patch_ver
);
3679 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
3680 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_DOT11_CHNL
,
3682 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_HS_CHNL
, &wifi_hs_chnl
);
3684 seq_printf(m
, "\n %-35s = %d / %d(%d)",
3685 "Dot11 channel / HsChnl(HsMode)",
3686 wifi_dot11_chnl
, wifi_hs_chnl
, bt_hs_on
);
3688 seq_printf(m
, "\n %-35s = %3ph ",
3689 "H2C Wifi inform bt chnl Info", coex_dm
->wifi_chnl_info
);
3691 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
3692 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_HS_RSSI
, &bt_hs_rssi
);
3693 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_AP_NUM
, &ap_num
);
3694 seq_printf(m
, "\n %-35s = %d/ %d/ %d",
3695 "Wifi rssi/ HS rssi/ AP#", wifi_rssi
, bt_hs_rssi
, ap_num
);
3697 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
3698 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
3699 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
3700 seq_printf(m
, "\n %-35s = %d/ %d/ %d ",
3701 "Wifi link/ roam/ scan", link
, roam
, scan
);
3703 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
3704 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3705 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
3706 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION
,
3708 seq_printf(m
, "\n %-35s = %s / %s/ %s ",
3709 "Wifi status", (wifi_under_5g
? "5G" : "2.4G"),
3710 ((wifi_bw
== BTC_WIFI_BW_LEGACY
) ? "Legacy" :
3711 (((wifi_bw
== BTC_WIFI_BW_HT40
) ? "HT40" : "HT20"))),
3712 ((!wifi_busy
) ? "idle" :
3713 ((wifi_traffic_dir
== BTC_WIFI_TRAFFIC_TX
) ?
3714 "uplink" : "downlink")));
3716 seq_printf(m
, "\n %-35s = %d / %d / %d / %d",
3718 bt_link_info
->sco_exist
, bt_link_info
->hid_exist
,
3719 bt_link_info
->pan_exist
, bt_link_info
->a2dp_exist
);
3720 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_BT_LINK_INFO
, m
);
3722 bt_info_ext
= coex_sta
->bt_info_ext
;
3723 seq_printf(m
, "\n %-35s = %s",
3724 "BT Info A2DP rate",
3725 (bt_info_ext
& BIT0
) ? "Basic rate" : "EDR rate");
3727 for (i
= 0; i
< BT_INFO_SRC_8723B_2ANT_MAX
; i
++) {
3728 if (coex_sta
->bt_info_c2h_cnt
[i
]) {
3729 seq_printf(m
, "\n %-35s = %7ph(%d)",
3730 glbt_info_src_8723b_2ant
[i
],
3731 coex_sta
->bt_info_c2h
[i
],
3732 coex_sta
->bt_info_c2h_cnt
[i
]);
3736 seq_printf(m
, "\n %-35s = %s/%s",
3737 "PS state, IPS/LPS",
3738 ((coex_sta
->under_ips
? "IPS ON" : "IPS OFF")),
3739 ((coex_sta
->under_lps
? "LPS ON" : "LPS OFF")));
3740 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_FW_PWR_MODE_CMD
, m
);
3744 "\n %-35s", "============[Sw mechanism]============");
3745 seq_printf(m
, "\n %-35s = %d/ %d/ %d ",
3746 "SM1[ShRf/ LpRA/ LimDig]", coex_dm
->cur_rf_rx_lpf_shrink
,
3747 coex_dm
->cur_low_penalty_ra
, coex_dm
->limited_dig
);
3748 seq_printf(m
, "\n %-35s = %d/ %d/ %d(0x%x) ",
3749 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
3750 coex_dm
->cur_agc_table_en
, coex_dm
->cur_adc_back_off
,
3751 coex_dm
->cur_dac_swing_on
, coex_dm
->cur_dac_swing_lvl
);
3754 seq_printf(m
, "\n %-35s",
3755 "============[Fw mechanism]============");
3757 ps_tdma_case
= coex_dm
->cur_ps_tdma
;
3758 seq_printf(m
, "\n %-35s = %5ph case-%d (auto:%d)",
3759 "PS TDMA", coex_dm
->ps_tdma_para
,
3760 ps_tdma_case
, coex_dm
->auto_tdma_adjust
);
3762 seq_printf(m
, "\n %-35s = %d/ %d ",
3763 "DecBtPwr/ IgnWlanAct", coex_dm
->cur_dec_bt_pwr_lvl
,
3764 coex_dm
->cur_ignore_wlan_act
);
3767 seq_printf(m
, "\n %-35s",
3768 "============[Hw setting]============");
3770 seq_printf(m
, "\n %-35s = 0x%x",
3771 "RF-A, 0x1e initVal", coex_dm
->bt_rf0x1e_backup
);
3773 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x778);
3774 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x880);
3775 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x",
3776 "0x778/0x880[29:25]", u8tmp
[0],
3777 (u32tmp
[0] & 0x3e000000) >> 25);
3779 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x948);
3780 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x67);
3781 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x765);
3782 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
3783 "0x948/ 0x67[5] / 0x765",
3784 u32tmp
[0], ((u8tmp
[0] & 0x20) >> 5), u8tmp
[1]);
3786 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x92c);
3787 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x930);
3788 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x944);
3789 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
3790 "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
3791 u32tmp
[0] & 0x3, u32tmp
[1] & 0xff, u32tmp
[2] & 0x3);
3793 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x39);
3794 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x40);
3795 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
3796 u8tmp
[2] = btcoexist
->btc_read_1byte(btcoexist
, 0x64);
3797 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
3798 "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
3799 ((u8tmp
[0] & 0x8) >> 3), u8tmp
[1],
3800 ((u32tmp
[0] & 0x01800000) >> 23), u8tmp
[2] & 0x1);
3802 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x550);
3803 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x522);
3804 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x",
3805 "0x550(bcn ctrl)/0x522", u32tmp
[0], u8tmp
[0]);
3807 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xc50);
3808 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x49c);
3809 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x",
3810 "0xc50(dig)/0x49c(null-drop)", u32tmp
[0] & 0xff, u8tmp
[0]);
3812 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xda0);
3813 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0xda4);
3814 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0xda8);
3815 u32tmp
[3] = btcoexist
->btc_read_4byte(btcoexist
, 0xcf0);
3817 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5b);
3818 u8tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5c);
3820 fa_ofdm
= ((u32tmp
[0]&0xffff0000) >> 16) +
3821 ((u32tmp
[1]&0xffff0000) >> 16) +
3822 (u32tmp
[1] & 0xffff) +
3823 (u32tmp
[2] & 0xffff) +
3824 ((u32tmp
[3]&0xffff0000) >> 16) +
3825 (u32tmp
[3] & 0xffff);
3826 fa_cck
= (u8tmp
[0] << 8) + u8tmp
[1];
3828 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
3829 "OFDM-CCA/OFDM-FA/CCK-FA",
3830 u32tmp
[0] & 0xffff, fa_ofdm
, fa_cck
);
3832 u32tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c0);
3833 u32tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c4);
3834 u32tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c8);
3835 u8tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x6cc);
3836 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
3837 "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
3838 u32tmp
[0], u32tmp
[1], u32tmp
[2], u8tmp
[0]);
3840 seq_printf(m
, "\n %-35s = %d/ %d",
3841 "0x770(high-pri rx/tx)",
3842 coex_sta
->high_priority_rx
, coex_sta
->high_priority_tx
);
3843 seq_printf(m
, "\n %-35s = %d/ %d",
3844 "0x774(low-pri rx/tx)", coex_sta
->low_priority_rx
,
3845 coex_sta
->low_priority_tx
);
3846 if (btcoexist
->auto_report_2ant
)
3847 btc8723b2ant_monitor_bt_ctr(btcoexist
);
3848 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_COEX_STATISTICS
, m
);
3851 void ex_btc8723b2ant_ips_notify(struct btc_coexist
*btcoexist
, u8 type
)
3853 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3855 if (BTC_IPS_ENTER
== type
) {
3856 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3857 "[BTCoex], IPS ENTER notify\n");
3858 coex_sta
->under_ips
= true;
3859 btc8723b2ant_wifioff_hwcfg(btcoexist
);
3860 btc8723b2ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
3861 btc8723b2ant_coex_alloff(btcoexist
);
3862 } else if (BTC_IPS_LEAVE
== type
) {
3863 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3864 "[BTCoex], IPS LEAVE notify\n");
3865 coex_sta
->under_ips
= false;
3866 ex_btc8723b2ant_init_hwconfig(btcoexist
);
3867 btc8723b2ant_init_coex_dm(btcoexist
);
3868 btc8723b2ant_query_bt_info(btcoexist
);
3872 void ex_btc8723b2ant_lps_notify(struct btc_coexist
*btcoexist
, u8 type
)
3874 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3876 if (BTC_LPS_ENABLE
== type
) {
3877 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3878 "[BTCoex], LPS ENABLE notify\n");
3879 coex_sta
->under_lps
= true;
3880 } else if (BTC_LPS_DISABLE
== type
) {
3881 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3882 "[BTCoex], LPS DISABLE notify\n");
3883 coex_sta
->under_lps
= false;
3887 void ex_btc8723b2ant_scan_notify(struct btc_coexist
*btcoexist
, u8 type
)
3889 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3893 u32tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x948);
3894 u8tmpa
= btcoexist
->btc_read_1byte(btcoexist
, 0x765);
3895 u8tmpb
= btcoexist
->btc_read_1byte(btcoexist
, 0x76e);
3897 if (BTC_SCAN_START
== type
)
3898 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3899 "[BTCoex], SCAN START notify\n");
3900 else if (BTC_SCAN_FINISH
== type
)
3901 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3902 "[BTCoex], SCAN FINISH notify\n");
3903 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_AP_NUM
,
3904 &coex_sta
->scan_ap_num
);
3906 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3907 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x76e=0x%x\n",
3908 u32tmp
, u8tmpa
, u8tmpb
);
3911 void ex_btc8723b2ant_connect_notify(struct btc_coexist
*btcoexist
, u8 type
)
3913 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3915 if (BTC_ASSOCIATE_START
== type
)
3916 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3917 "[BTCoex], CONNECT START notify\n");
3918 else if (BTC_ASSOCIATE_FINISH
== type
)
3919 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3920 "[BTCoex], CONNECT FINISH notify\n");
3923 void ex_btc8723b2ant_media_status_notify(struct btc_coexist
*btcoexist
,
3926 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3927 u8 h2c_parameter
[3] = {0};
3929 u8 wifi_central_chnl
;
3932 if (BTC_MEDIA_CONNECT
== type
)
3933 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3934 "[BTCoex], MEDIA connect notify\n");
3936 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3937 "[BTCoex], MEDIA disconnect notify\n");
3939 /* only 2.4G we need to inform bt the chnl mask */
3940 btcoexist
->btc_get(btcoexist
,
3941 BTC_GET_U1_WIFI_CENTRAL_CHNL
, &wifi_central_chnl
);
3942 if ((BTC_MEDIA_CONNECT
== type
) &&
3943 (wifi_central_chnl
<= 14)) {
3944 h2c_parameter
[0] = 0x1;
3945 h2c_parameter
[1] = wifi_central_chnl
;
3946 btcoexist
->btc_get(btcoexist
,
3947 BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3948 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
3949 h2c_parameter
[2] = 0x30;
3951 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_AP_NUM
,
3954 h2c_parameter
[2] = 0x30;
3956 h2c_parameter
[2] = 0x20;
3960 coex_dm
->wifi_chnl_info
[0] = h2c_parameter
[0];
3961 coex_dm
->wifi_chnl_info
[1] = h2c_parameter
[1];
3962 coex_dm
->wifi_chnl_info
[2] = h2c_parameter
[2];
3964 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3965 "[BTCoex], FW write 0x66=0x%x\n",
3966 h2c_parameter
[0] << 16 | h2c_parameter
[1] << 8 |
3969 btcoexist
->btc_fill_h2c(btcoexist
, 0x66, 3, h2c_parameter
);
3972 void ex_btc8723b2ant_special_packet_notify(struct btc_coexist
*btcoexist
,
3975 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3977 if (type
== BTC_PACKET_DHCP
)
3978 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3979 "[BTCoex], DHCP Packet notify\n");
3982 void ex_btc8723b2ant_bt_info_notify(struct btc_coexist
*btcoexist
,
3983 u8
*tmpbuf
, u8 length
)
3985 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3987 u8 i
, rsp_source
= 0;
3988 bool bt_busy
= false, limited_dig
= false;
3989 bool wifi_connected
= false;
3991 coex_sta
->c2h_bt_info_req_sent
= false;
3993 rsp_source
= tmpbuf
[0]&0xf;
3994 if (rsp_source
>= BT_INFO_SRC_8723B_2ANT_MAX
)
3995 rsp_source
= BT_INFO_SRC_8723B_2ANT_WIFI_FW
;
3996 coex_sta
->bt_info_c2h_cnt
[rsp_source
]++;
3998 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3999 "[BTCoex], Bt info[%d], length=%d, hex data=[",
4000 rsp_source
, length
);
4001 for (i
= 0; i
< length
; i
++) {
4002 coex_sta
->bt_info_c2h
[rsp_source
][i
] = tmpbuf
[i
];
4004 bt_info
= tmpbuf
[i
];
4005 if (i
== length
- 1)
4006 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4007 "0x%02x]\n", tmpbuf
[i
]);
4009 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4010 "0x%02x, ", tmpbuf
[i
]);
4013 if (btcoexist
->manual_control
) {
4014 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4015 "[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n");
4019 if (BT_INFO_SRC_8723B_2ANT_WIFI_FW
!= rsp_source
) {
4020 coex_sta
->bt_retry_cnt
=
4021 coex_sta
->bt_info_c2h
[rsp_source
][2] & 0xf;
4023 if (coex_sta
->bt_retry_cnt
>= 1)
4024 coex_sta
->pop_event_cnt
++;
4027 coex_sta
->bt_info_c2h
[rsp_source
][3] * 2 + 10;
4029 coex_sta
->bt_info_ext
= coex_sta
->bt_info_c2h
[rsp_source
][4];
4031 if (coex_sta
->bt_info_c2h
[rsp_source
][2] & 0x20)
4032 coex_sta
->c2h_bt_remote_name_req
= true;
4034 coex_sta
->c2h_bt_remote_name_req
= false;
4036 if (coex_sta
->bt_info_c2h
[rsp_source
][1] == 0x49)
4037 coex_sta
->a2dp_bit_pool
=
4038 coex_sta
->bt_info_c2h
[rsp_source
][6];
4040 coex_sta
->a2dp_bit_pool
= 0;
4042 /* Here we need to resend some wifi info to BT
4043 * because BT is reset and loss of the info.
4045 if ((coex_sta
->bt_info_ext
& BIT1
)) {
4046 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4047 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
4048 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
4051 ex_btc8723b2ant_media_status_notify(
4055 ex_btc8723b2ant_media_status_notify(
4057 BTC_MEDIA_DISCONNECT
);
4060 if ((coex_sta
->bt_info_ext
& BIT3
)) {
4061 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4062 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
4063 btc8723b2ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
,
4066 /* BT already NOT ignore Wlan active, do nothing here.*/
4068 if (!btcoexist
->auto_report_2ant
) {
4069 if (!(coex_sta
->bt_info_ext
& BIT4
))
4070 btc8723b2ant_bt_auto_report(btcoexist
,
4075 /* check BIT2 first ==> check if bt is under inquiry or page scan */
4076 if (bt_info
& BT_INFO_8723B_2ANT_B_INQ_PAGE
)
4077 coex_sta
->c2h_bt_inquiry_page
= true;
4079 coex_sta
->c2h_bt_inquiry_page
= false;
4081 if (!(bt_info
& BT_INFO_8723B_2ANT_B_CONNECTION
)) {
4082 /* set link exist status */
4083 coex_sta
->bt_link_exist
= false;
4084 coex_sta
->pan_exist
= false;
4085 coex_sta
->a2dp_exist
= false;
4086 coex_sta
->hid_exist
= false;
4087 coex_sta
->sco_exist
= false;
4089 /* connection exists */
4090 coex_sta
->bt_link_exist
= true;
4091 if (bt_info
& BT_INFO_8723B_2ANT_B_FTP
)
4092 coex_sta
->pan_exist
= true;
4094 coex_sta
->pan_exist
= false;
4095 if (bt_info
& BT_INFO_8723B_2ANT_B_A2DP
)
4096 coex_sta
->a2dp_exist
= true;
4098 coex_sta
->a2dp_exist
= false;
4099 if (bt_info
& BT_INFO_8723B_2ANT_B_HID
)
4100 coex_sta
->hid_exist
= true;
4102 coex_sta
->hid_exist
= false;
4103 if (bt_info
& BT_INFO_8723B_2ANT_B_SCO_ESCO
)
4104 coex_sta
->sco_exist
= true;
4106 coex_sta
->sco_exist
= false;
4108 if ((!coex_sta
->hid_exist
) &&
4109 (!coex_sta
->c2h_bt_inquiry_page
) &&
4110 (!coex_sta
->sco_exist
)) {
4111 if (coex_sta
->high_priority_tx
+
4112 coex_sta
->high_priority_rx
>= 160) {
4113 coex_sta
->hid_exist
= true;
4114 bt_info
= bt_info
| 0x28;
4119 btc8723b2ant_update_bt_link_info(btcoexist
);
4121 if (!(bt_info
& BT_INFO_8723B_2ANT_B_CONNECTION
)) {
4122 coex_dm
->bt_status
= BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE
;
4123 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4124 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
4125 /* connection exists but no busy */
4126 } else if (bt_info
== BT_INFO_8723B_2ANT_B_CONNECTION
) {
4127 coex_dm
->bt_status
= BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE
;
4128 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4129 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
4130 } else if ((bt_info
& BT_INFO_8723B_2ANT_B_SCO_ESCO
) ||
4131 (bt_info
& BT_INFO_8723B_2ANT_B_SCO_BUSY
)) {
4132 coex_dm
->bt_status
= BT_8723B_2ANT_BT_STATUS_SCO_BUSY
;
4133 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4134 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
4135 } else if (bt_info
&BT_INFO_8723B_2ANT_B_ACL_BUSY
) {
4136 coex_dm
->bt_status
= BT_8723B_2ANT_BT_STATUS_ACL_BUSY
;
4137 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4138 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
4140 coex_dm
->bt_status
= BT_8723B_2ANT_BT_STATUS_MAX
;
4141 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4142 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
4145 if ((BT_8723B_2ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) ||
4146 (BT_8723B_2ANT_BT_STATUS_SCO_BUSY
== coex_dm
->bt_status
) ||
4147 (BT_8723B_2ANT_BT_STATUS_ACL_SCO_BUSY
== coex_dm
->bt_status
)) {
4152 limited_dig
= false;
4155 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TRAFFIC_BUSY
, &bt_busy
);
4157 coex_dm
->limited_dig
= limited_dig
;
4158 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_LIMITED_DIG
, &limited_dig
);
4160 btc8723b2ant_run_coexist_mechanism(btcoexist
);
4163 void ex_btc8723b2ant_halt_notify(struct btc_coexist
*btcoexist
)
4165 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
4167 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
, "[BTCoex], Halt notify\n");
4169 btc8723b2ant_wifioff_hwcfg(btcoexist
);
4170 btc8723b2ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
4171 ex_btc8723b2ant_media_status_notify(btcoexist
, BTC_MEDIA_DISCONNECT
);
4174 void ex_btc8723b2ant_pnp_notify(struct btc_coexist
*btcoexist
, u8 pnp_state
)
4176 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
4178 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
, "[BTCoex], Pnp notify\n");
4180 if (pnp_state
== BTC_WIFI_PNP_SLEEP
) {
4181 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4182 "[BTCoex], Pnp notify to SLEEP\n");
4184 /* Driver do not leave IPS/LPS when driver is going to sleep, so
4185 * BTCoexistence think wifi is still under IPS/LPS
4187 * BT should clear UnderIPS/UnderLPS state to avoid mismatch
4188 * state after wakeup.
4190 coex_sta
->under_ips
= false;
4191 coex_sta
->under_lps
= false;
4192 } else if (pnp_state
== BTC_WIFI_PNP_WAKE_UP
) {
4193 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4194 "[BTCoex], Pnp notify to WAKE UP\n");
4195 ex_btc8723b2ant_init_hwconfig(btcoexist
);
4196 btc8723b2ant_init_coex_dm(btcoexist
);
4197 btc8723b2ant_query_bt_info(btcoexist
);
4201 void ex_btc8723b2ant_periodical(struct btc_coexist
*btcoexist
)
4203 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
4204 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
4206 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4207 "[BTCoex], ==========================Periodical===========================\n");
4209 if (coex_sta
->dis_ver_info_cnt
<= 5) {
4210 coex_sta
->dis_ver_info_cnt
+= 1;
4211 if (coex_sta
->dis_ver_info_cnt
== 3) {
4212 /* Antenna config to set 0x765 = 0x0 (GNT_BT control by
4213 * PTA) after initial
4215 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4216 "[BTCoex], Set GNT_BT control by PTA\n");
4217 btc8723b2ant_set_ant_path(
4218 btcoexist
, BTC_ANT_WIFI_AT_MAIN
, false, false);
4222 if (!btcoexist
->auto_report_2ant
) {
4223 btc8723b2ant_query_bt_info(btcoexist
);
4225 btc8723b2ant_monitor_bt_ctr(btcoexist
);
4226 btc8723b2ant_monitor_wifi_ctr(btcoexist
);
4228 /* for some BT speakers that High-Priority pkts appear before
4229 * playing, this will cause HID exist
4231 if ((coex_sta
->high_priority_tx
+
4232 coex_sta
->high_priority_rx
< 50) &&
4233 (bt_link_info
->hid_exist
))
4234 bt_link_info
->hid_exist
= false;
4236 if (btc8723b2ant_is_wifi_status_changed(btcoexist
) ||
4237 coex_dm
->auto_tdma_adjust
)
4238 btc8723b2ant_run_coexist_mechanism(btcoexist
);