1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2012 Realtek Corporation.*/
4 /************************************************************
7 * This file is for RTL8821A Co-exist mechanism
10 * 2012/08/22 Cosa first check in.
11 * 2012/11/14 Cosa Revise for 8821A 2Ant out sourcing.
13 ************************************************************/
15 /************************************************************
17 ************************************************************/
18 #include "halbt_precomp.h"
19 /************************************************************
20 * Global variables, these are static variables
21 ************************************************************/
22 static struct coex_dm_8821a_2ant glcoex_dm_8821a_2ant
;
23 static struct coex_dm_8821a_2ant
*coex_dm
= &glcoex_dm_8821a_2ant
;
24 static struct coex_sta_8821a_2ant glcoex_sta_8821a_2ant
;
25 static struct coex_sta_8821a_2ant
*coex_sta
= &glcoex_sta_8821a_2ant
;
27 static const char *const glbt_info_src_8821a_2ant
[] = {
30 "BT Info[bt auto report]",
33 static u32 glcoex_ver_date_8821a_2ant
= 20130618;
34 static u32 glcoex_ver_8821a_2ant
= 0x5050;
36 /************************************************************
37 * local function proto type if needed
39 * local function start with btc8821a2ant_
40 ************************************************************/
41 static u8
btc8821a2ant_bt_rssi_state(struct btc_coexist
*btcoexist
,
42 u8 level_num
, u8 rssi_thresh
,
45 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
47 u8 bt_rssi_state
= coex_sta
->pre_bt_rssi_state
;
49 bt_rssi
= coex_sta
->bt_rssi
;
52 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
53 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
55 rssi_thresh
+ BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
) {
56 bt_rssi_state
= BTC_RSSI_STATE_HIGH
;
57 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
58 "[BTCoex], BT Rssi state switch to High\n");
60 bt_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
61 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
62 "[BTCoex], BT Rssi state stay at Low\n");
65 if (bt_rssi
< rssi_thresh
) {
66 bt_rssi_state
= BTC_RSSI_STATE_LOW
;
67 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
68 "[BTCoex], BT Rssi state switch to Low\n");
70 bt_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
71 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
72 "[BTCoex], BT Rssi state stay at High\n");
75 } else if (level_num
== 3) {
76 if (rssi_thresh
> rssi_thresh1
) {
77 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
78 "[BTCoex], BT Rssi thresh error!!\n");
79 return coex_sta
->pre_bt_rssi_state
;
82 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
83 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
86 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
)) {
87 bt_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
88 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
89 "[BTCoex], BT Rssi state switch to Medium\n");
91 bt_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
92 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
93 "[BTCoex], BT Rssi state stay at Low\n");
95 } else if ((coex_sta
->pre_bt_rssi_state
==
96 BTC_RSSI_STATE_MEDIUM
) ||
97 (coex_sta
->pre_bt_rssi_state
==
98 BTC_RSSI_STATE_STAY_MEDIUM
)) {
101 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
)) {
102 bt_rssi_state
= BTC_RSSI_STATE_HIGH
;
103 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
104 "[BTCoex], BT Rssi state switch to High\n");
105 } else if (bt_rssi
< rssi_thresh
) {
106 bt_rssi_state
= BTC_RSSI_STATE_LOW
;
107 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
108 "[BTCoex], BT Rssi state switch to Low\n");
110 bt_rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
111 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
112 "[BTCoex], BT Rssi state stay at Medium\n");
115 if (bt_rssi
< rssi_thresh1
) {
116 bt_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
117 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
118 "[BTCoex], BT Rssi state switch to Medium\n");
120 bt_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
121 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
122 "[BTCoex], BT Rssi state stay at High\n");
127 coex_sta
->pre_bt_rssi_state
= bt_rssi_state
;
129 return bt_rssi_state
;
132 static u8
btc8821a2ant_wifi_rssi_state(struct btc_coexist
*btcoexist
,
133 u8 index
, u8 level_num
,
134 u8 rssi_thresh
, u8 rssi_thresh1
)
136 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
138 u8 wifi_rssi_state
= coex_sta
->pre_wifi_rssi_state
[index
];
140 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
142 if (level_num
== 2) {
143 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
144 BTC_RSSI_STATE_LOW
) ||
145 (coex_sta
->pre_wifi_rssi_state
[index
] ==
146 BTC_RSSI_STATE_STAY_LOW
)) {
148 (rssi_thresh
+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
)) {
149 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
150 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
151 "[BTCoex], wifi RSSI state switch to High\n");
153 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
154 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
155 "[BTCoex], wifi RSSI state stay at Low\n");
158 if (wifi_rssi
< rssi_thresh
) {
159 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
160 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
161 "[BTCoex], wifi RSSI state switch to Low\n");
163 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
164 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
165 "[BTCoex], wifi RSSI state stay at High\n");
168 } else if (level_num
== 3) {
169 if (rssi_thresh
> rssi_thresh1
) {
170 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
171 "[BTCoex], wifi RSSI thresh error!!\n");
172 return coex_sta
->pre_wifi_rssi_state
[index
];
175 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
176 BTC_RSSI_STATE_LOW
) ||
177 (coex_sta
->pre_wifi_rssi_state
[index
] ==
178 BTC_RSSI_STATE_STAY_LOW
)) {
181 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
)) {
182 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
183 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
184 "[BTCoex], wifi RSSI state switch to Medium\n");
186 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
187 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
188 "[BTCoex], wifi RSSI state stay at Low\n");
190 } else if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
191 BTC_RSSI_STATE_MEDIUM
) ||
192 (coex_sta
->pre_wifi_rssi_state
[index
] ==
193 BTC_RSSI_STATE_STAY_MEDIUM
)) {
194 if (wifi_rssi
>= (rssi_thresh1
+
195 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
)) {
196 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
197 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
198 "[BTCoex], wifi RSSI state switch to High\n");
199 } else if (wifi_rssi
< rssi_thresh
) {
200 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
201 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
202 "[BTCoex], wifi RSSI state switch to Low\n");
204 wifi_rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
205 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
206 "[BTCoex], wifi RSSI state stay at Medium\n");
209 if (wifi_rssi
< rssi_thresh1
) {
210 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
211 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
212 "[BTCoex], wifi RSSI state switch to Medium\n");
214 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
215 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
216 "[BTCoex], wifi RSSI state stay at High\n");
220 coex_sta
->pre_wifi_rssi_state
[index
] = wifi_rssi_state
;
222 return wifi_rssi_state
;
226 void btc8821a2ant_limited_rx(struct btc_coexist
*btcoexist
, bool force_exec
,
227 bool rej_ap_agg_pkt
, bool bt_ctrl_agg_buf_size
,
230 bool reject_rx_agg
= rej_ap_agg_pkt
;
231 bool bt_ctrl_rx_agg_size
= bt_ctrl_agg_buf_size
;
232 u8 rx_agg_size
= agg_buf_size
;
234 /* Rx Aggregation related setting */
235 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_TO_REJ_AP_AGG_PKT
,
237 /* decide BT control aggregation buf size or not */
238 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_CTRL_AGG_SIZE
,
239 &bt_ctrl_rx_agg_size
);
240 /* aggregation buf size, works when BT control Rx aggregation size */
241 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_AGG_BUF_SIZE
, &rx_agg_size
);
242 /* real update aggregation setting */
243 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_AGGREGATE_CTRL
, NULL
);
246 static void btc8821a2ant_monitor_bt_ctr(struct btc_coexist
*btcoexist
)
248 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
249 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
250 u32 reg_hp_txrx
, reg_lp_txrx
, u4tmp
;
251 u32 reg_hp_tx
= 0, reg_hp_rx
= 0, reg_lp_tx
= 0, reg_lp_rx
= 0;
256 u4tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_hp_txrx
);
257 reg_hp_tx
= u4tmp
& MASKLWORD
;
258 reg_hp_rx
= (u4tmp
& MASKHWORD
) >> 16;
260 u4tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_lp_txrx
);
261 reg_lp_tx
= u4tmp
& MASKLWORD
;
262 reg_lp_rx
= (u4tmp
& 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_rx
>= 950) &&
270 (coex_sta
->low_priority_rx
>= coex_sta
->low_priority_tx
) &&
271 (!coex_sta
->under_ips
))
272 bt_link_info
->slave_role
= true;
274 bt_link_info
->slave_role
= false;
276 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
277 "[BTCoex], High Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
278 reg_hp_txrx
, reg_hp_tx
, reg_hp_tx
, reg_hp_rx
, reg_hp_rx
);
279 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
280 "[BTCoex], Low Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
281 reg_lp_txrx
, reg_lp_tx
, reg_lp_tx
, reg_lp_rx
, reg_lp_rx
);
284 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
287 static void btc8821a2ant_monitor_wifi_ctr(struct btc_coexist
*btcoexist
)
289 if (coex_sta
->under_ips
) {
290 coex_sta
->crc_ok_cck
= 0;
291 coex_sta
->crc_ok_11g
= 0;
292 coex_sta
->crc_ok_11n
= 0;
293 coex_sta
->crc_ok_11n_agg
= 0;
295 coex_sta
->crc_err_cck
= 0;
296 coex_sta
->crc_err_11g
= 0;
297 coex_sta
->crc_err_11n
= 0;
298 coex_sta
->crc_err_11n_agg
= 0;
300 coex_sta
->crc_ok_cck
=
301 btcoexist
->btc_read_4byte(btcoexist
, 0xf88);
302 coex_sta
->crc_ok_11g
=
303 btcoexist
->btc_read_2byte(btcoexist
, 0xf94);
304 coex_sta
->crc_ok_11n
=
305 btcoexist
->btc_read_2byte(btcoexist
, 0xf90);
306 coex_sta
->crc_ok_11n_agg
=
307 btcoexist
->btc_read_2byte(btcoexist
, 0xfb8);
309 coex_sta
->crc_err_cck
=
310 btcoexist
->btc_read_4byte(btcoexist
, 0xf84);
311 coex_sta
->crc_err_11g
=
312 btcoexist
->btc_read_2byte(btcoexist
, 0xf96);
313 coex_sta
->crc_err_11n
=
314 btcoexist
->btc_read_2byte(btcoexist
, 0xf92);
315 coex_sta
->crc_err_11n_agg
=
316 btcoexist
->btc_read_2byte(btcoexist
, 0xfba);
320 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xf16, 0x1, 0x1);
321 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xf16, 0x1, 0x0);
324 static void btc8821a2ant_query_bt_info(struct btc_coexist
*btcoexist
)
326 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
327 u8 h2c_parameter
[1] = {0};
329 coex_sta
->c2h_bt_info_req_sent
= true;
331 h2c_parameter
[0] |= BIT0
; /* trigger */
333 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
334 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
337 btcoexist
->btc_fill_h2c(btcoexist
, 0x61, 1, h2c_parameter
);
340 static bool btc8821a2ant_is_wifi_status_changed(struct btc_coexist
*btcoexist
)
342 static bool pre_wifi_busy
= true;
343 static bool pre_under_4way
= true;
344 static bool pre_bt_hs_on
= true;
345 bool wifi_busy
= false, under_4way
= false, bt_hs_on
= false;
346 bool wifi_connected
= false;
347 u8 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
349 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
351 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
352 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
353 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
356 if (wifi_connected
) {
357 if (wifi_busy
!= pre_wifi_busy
) {
358 pre_wifi_busy
= wifi_busy
;
361 if (under_4way
!= pre_under_4way
) {
362 pre_under_4way
= under_4way
;
365 if (bt_hs_on
!= pre_bt_hs_on
) {
366 pre_bt_hs_on
= bt_hs_on
;
370 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 3, 2,
371 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES
, 0);
373 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
374 (wifi_rssi_state
== BTC_RSSI_STATE_LOW
))
381 static void btc8821a2ant_update_bt_link_info(struct btc_coexist
*btcoexist
)
383 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
384 bool bt_hs_on
= false;
386 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
388 bt_link_info
->bt_link_exist
= coex_sta
->bt_link_exist
;
389 bt_link_info
->sco_exist
= coex_sta
->sco_exist
;
390 bt_link_info
->a2dp_exist
= coex_sta
->a2dp_exist
;
391 bt_link_info
->pan_exist
= coex_sta
->pan_exist
;
392 bt_link_info
->hid_exist
= coex_sta
->hid_exist
;
394 /* work around for HS mode. */
396 bt_link_info
->pan_exist
= true;
397 bt_link_info
->bt_link_exist
= true;
400 /* check if Sco only */
401 if (bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
402 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
403 bt_link_info
->sco_only
= true;
405 bt_link_info
->sco_only
= false;
407 /* check if A2dp only */
408 if (!bt_link_info
->sco_exist
&& bt_link_info
->a2dp_exist
&&
409 !bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
410 bt_link_info
->a2dp_only
= true;
412 bt_link_info
->a2dp_only
= false;
414 /* check if Pan only */
415 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
416 bt_link_info
->pan_exist
&& !bt_link_info
->hid_exist
)
417 bt_link_info
->pan_only
= true;
419 bt_link_info
->pan_only
= false;
421 /* check if Hid only */
422 if (!bt_link_info
->sco_exist
&& !bt_link_info
->a2dp_exist
&&
423 !bt_link_info
->pan_exist
&& bt_link_info
->hid_exist
)
424 bt_link_info
->hid_only
= true;
426 bt_link_info
->hid_only
= false;
429 static u8
btc8821a2ant_action_algorithm(struct btc_coexist
*btcoexist
)
431 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
432 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
433 bool bt_hs_on
= false;
434 u8 algorithm
= BT_8821A_2ANT_COEX_ALGO_UNDEFINED
;
435 u8 num_of_diff_profile
= 0;
437 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
439 if (!bt_link_info
->bt_link_exist
) {
440 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
441 "[BTCoex], No BT link exists!!!\n");
445 if (bt_link_info
->sco_exist
)
446 num_of_diff_profile
++;
447 if (bt_link_info
->hid_exist
)
448 num_of_diff_profile
++;
449 if (bt_link_info
->pan_exist
)
450 num_of_diff_profile
++;
451 if (bt_link_info
->a2dp_exist
)
452 num_of_diff_profile
++;
454 if (num_of_diff_profile
== 1) {
455 if (bt_link_info
->sco_exist
) {
456 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
457 "[BTCoex], SCO only\n");
458 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
460 if (bt_link_info
->hid_exist
) {
461 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
462 "[BTCoex], HID only\n");
463 algorithm
= BT_8821A_2ANT_COEX_ALGO_HID
;
464 } else if (bt_link_info
->a2dp_exist
) {
465 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
466 "[BTCoex], A2DP only\n");
467 algorithm
= BT_8821A_2ANT_COEX_ALGO_A2DP
;
468 } else if (bt_link_info
->pan_exist
) {
470 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
472 "[BTCoex], PAN(HS) only\n");
473 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANHS
;
475 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
477 "[BTCoex], PAN(EDR) only\n");
478 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR
;
482 } else if (num_of_diff_profile
== 2) {
483 if (bt_link_info
->sco_exist
) {
484 if (bt_link_info
->hid_exist
) {
485 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
486 "[BTCoex], SCO + HID\n");
487 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
488 } else if (bt_link_info
->a2dp_exist
) {
489 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
490 "[BTCoex], SCO + A2DP ==> SCO\n");
491 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
492 } else if (bt_link_info
->pan_exist
) {
494 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
496 "[BTCoex], SCO + PAN(HS)\n");
497 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
499 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
501 "[BTCoex], SCO + PAN(EDR)\n");
502 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
506 if (bt_link_info
->hid_exist
&&
507 bt_link_info
->a2dp_exist
) {
508 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
509 "[BTCoex], HID + A2DP\n");
510 algorithm
= BT_8821A_2ANT_COEX_ALGO_HID_A2DP
;
511 } else if (bt_link_info
->hid_exist
&&
512 bt_link_info
->pan_exist
) {
514 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
516 "[BTCoex], HID + PAN(HS)\n");
517 algorithm
= BT_8821A_2ANT_COEX_ALGO_HID
;
519 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
521 "[BTCoex], HID + PAN(EDR)\n");
523 BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
;
525 } else if (bt_link_info
->pan_exist
&&
526 bt_link_info
->a2dp_exist
) {
528 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
530 "[BTCoex], A2DP + PAN(HS)\n");
532 BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS
;
534 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
536 "[BTCoex], A2DP + PAN(EDR)\n");
538 BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP
;
542 } else if (num_of_diff_profile
== 3) {
543 if (bt_link_info
->sco_exist
) {
544 if (bt_link_info
->hid_exist
&&
545 bt_link_info
->a2dp_exist
) {
546 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
547 "[BTCoex], SCO + HID + A2DP ==> HID\n");
548 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
549 } else if (bt_link_info
->hid_exist
&&
550 bt_link_info
->pan_exist
) {
552 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
554 "[BTCoex], SCO + HID + PAN(HS)\n");
555 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
557 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
559 "[BTCoex], SCO + HID + PAN(EDR)\n");
560 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
562 } else if (bt_link_info
->pan_exist
&&
563 bt_link_info
->a2dp_exist
) {
565 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
567 "[BTCoex], SCO + A2DP + PAN(HS)\n");
568 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
570 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
572 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
573 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
577 if (bt_link_info
->hid_exist
&&
578 bt_link_info
->pan_exist
&&
579 bt_link_info
->a2dp_exist
) {
581 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
583 "[BTCoex], HID + A2DP + PAN(HS)\n");
585 BT_8821A_2ANT_COEX_ALGO_HID_A2DP
;
587 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
589 "[BTCoex], HID + A2DP + PAN(EDR)\n");
591 BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR
;
595 } else if (num_of_diff_profile
>= 3) {
596 if (bt_link_info
->sco_exist
) {
597 if (bt_link_info
->hid_exist
&&
598 bt_link_info
->pan_exist
&&
599 bt_link_info
->a2dp_exist
) {
601 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
603 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
606 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
608 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
609 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
617 static void btc8821a2ant_set_fw_dac_swing_lvl(struct btc_coexist
*btcoexist
,
620 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
621 u8 h2c_parameter
[1] = {0};
623 /* There are several type of dacswing
624 * 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6
626 h2c_parameter
[0] = dac_swing_lvl
;
628 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
629 "[BTCoex], Set Dac Swing Level = 0x%x\n", dac_swing_lvl
);
630 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
631 "[BTCoex], FW write 0x64 = 0x%x\n", h2c_parameter
[0]);
633 btcoexist
->btc_fill_h2c(btcoexist
, 0x64, 1, h2c_parameter
);
636 static void btc8821a2ant_set_fw_dec_bt_pwr(struct btc_coexist
*btcoexist
,
639 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
640 u8 h2c_parameter
[1] = {0};
642 h2c_parameter
[0] = dec_bt_pwr_lvl
;
644 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
645 "[BTCoex], decrease Bt Power Level : %u, FW write 0x62 = 0x%x\n",
646 dec_bt_pwr_lvl
, h2c_parameter
[0]);
648 btcoexist
->btc_fill_h2c(btcoexist
, 0x62, 1, h2c_parameter
);
651 static void btc8821a2ant_dec_bt_pwr(struct btc_coexist
*btcoexist
,
652 bool force_exec
, u8 dec_bt_pwr_lvl
)
654 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
656 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
657 "[BTCoex], %s Dec BT power level = %u\n",
658 (force_exec
? "force to" : ""), dec_bt_pwr_lvl
);
659 coex_dm
->cur_dec_bt_pwr_lvl
= dec_bt_pwr_lvl
;
662 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
663 "[BTCoex], pre_dec_bt_pwr_lvl = %d, cur_dec_bt_pwr_lvl = %d\n",
664 coex_dm
->pre_dec_bt_pwr_lvl
,
665 coex_dm
->cur_dec_bt_pwr_lvl
);
667 if (coex_dm
->pre_dec_bt_pwr_lvl
== coex_dm
->cur_dec_bt_pwr_lvl
)
670 btc8821a2ant_set_fw_dec_bt_pwr(btcoexist
, coex_dm
->cur_dec_bt_pwr_lvl
);
672 coex_dm
->pre_dec_bt_pwr_lvl
= coex_dm
->cur_dec_bt_pwr_lvl
;
675 static void btc8821a2ant_fw_dac_swing_lvl(struct btc_coexist
*btcoexist
,
676 bool force_exec
, u8 fw_dac_swing_lvl
)
678 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
680 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
681 "[BTCoex], %s set FW Dac Swing level = %d\n",
682 (force_exec
? "force to" : ""), fw_dac_swing_lvl
);
683 coex_dm
->cur_fw_dac_swing_lvl
= fw_dac_swing_lvl
;
686 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
687 "[BTCoex], pre_fw_dac_swing_lvl = %d, cur_fw_dac_swing_lvl = %d\n",
688 coex_dm
->pre_fw_dac_swing_lvl
,
689 coex_dm
->cur_fw_dac_swing_lvl
);
691 if (coex_dm
->pre_fw_dac_swing_lvl
==
692 coex_dm
->cur_fw_dac_swing_lvl
)
696 btc8821a2ant_set_fw_dac_swing_lvl(btcoexist
,
697 coex_dm
->cur_fw_dac_swing_lvl
);
699 coex_dm
->pre_fw_dac_swing_lvl
= coex_dm
->cur_fw_dac_swing_lvl
;
702 static void btc8821a2ant_set_sw_penalty_tx_rate_adaptive(
703 struct btc_coexist
*btcoexist
, bool low_penalty_ra
)
705 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
706 u8 h2c_parameter
[6] = {0};
708 h2c_parameter
[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */
710 if (low_penalty_ra
) {
711 h2c_parameter
[1] |= BIT0
;
712 /* normal rate except MCS7/6/5, OFDM54/48/36 */
713 h2c_parameter
[2] = 0x00;
715 h2c_parameter
[3] = 0xf5;
717 h2c_parameter
[4] = 0xa0;
719 h2c_parameter
[5] = 0xa0;
722 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
723 "[BTCoex], set WiFi Low-Penalty Retry: %s",
724 (low_penalty_ra
? "ON!!" : "OFF!!"));
726 btcoexist
->btc_fill_h2c(btcoexist
, 0x69, 6, h2c_parameter
);
729 static void btc8821a2ant_low_penalty_ra(struct btc_coexist
*btcoexist
,
730 bool force_exec
, bool low_penalty_ra
)
732 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
734 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
735 "[BTCoex], %s turn LowPenaltyRA = %s\n",
736 (force_exec
? "force to" : ""),
737 ((low_penalty_ra
) ? "ON" : "OFF"));
738 coex_dm
->cur_low_penalty_ra
= low_penalty_ra
;
741 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
742 "[BTCoex], pre_low_penalty_ra = %d, cur_low_penalty_ra = %d\n",
743 coex_dm
->pre_low_penalty_ra
,
744 coex_dm
->cur_low_penalty_ra
);
746 if (coex_dm
->pre_low_penalty_ra
== coex_dm
->cur_low_penalty_ra
)
749 btc8821a2ant_set_sw_penalty_tx_rate_adaptive(btcoexist
,
750 coex_dm
->cur_low_penalty_ra
);
752 coex_dm
->pre_low_penalty_ra
= coex_dm
->cur_low_penalty_ra
;
755 static void btc8821a2ant_set_dac_swing_reg(struct btc_coexist
*btcoexist
,
758 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
761 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
762 "[BTCoex], Write SwDacSwing = 0x%x\n", level
);
763 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xc5b, 0x3e, val
);
766 static void btc8821a2ant_set_sw_full_dac_swing(struct btc_coexist
*btcoexist
,
767 bool sw_dac_swing_on
,
768 u32 sw_dac_swing_lvl
)
771 btc8821a2ant_set_dac_swing_reg(btcoexist
, sw_dac_swing_lvl
);
773 btc8821a2ant_set_dac_swing_reg(btcoexist
, 0x18);
776 static void btc8821a2ant_dac_swing(struct btc_coexist
*btcoexist
,
777 bool force_exec
, bool dac_swing_on
,
780 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
782 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
783 "[BTCoex], %s turn DacSwing = %s, dac_swing_lvl = 0x%x\n",
784 (force_exec
? "force to" : ""),
785 ((dac_swing_on
) ? "ON" : "OFF"),
787 coex_dm
->cur_dac_swing_on
= dac_swing_on
;
788 coex_dm
->cur_dac_swing_lvl
= dac_swing_lvl
;
791 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
792 "[BTCoex], pre_dac_swing_on = %d, pre_dac_swing_lvl = 0x%x, cur_dac_swing_on = %d, cur_dac_swing_lvl = 0x%x\n",
793 coex_dm
->pre_dac_swing_on
,
794 coex_dm
->pre_dac_swing_lvl
,
795 coex_dm
->cur_dac_swing_on
,
796 coex_dm
->cur_dac_swing_lvl
);
798 if ((coex_dm
->pre_dac_swing_on
== coex_dm
->cur_dac_swing_on
) &&
799 (coex_dm
->pre_dac_swing_lvl
==
800 coex_dm
->cur_dac_swing_lvl
))
804 btc8821a2ant_set_sw_full_dac_swing(btcoexist
, dac_swing_on
,
807 coex_dm
->pre_dac_swing_on
= coex_dm
->cur_dac_swing_on
;
808 coex_dm
->pre_dac_swing_lvl
= coex_dm
->cur_dac_swing_lvl
;
811 static void btc8821a2ant_set_coex_table(struct btc_coexist
*btcoexist
,
812 u32 val0x6c0
, u32 val0x6c4
,
813 u32 val0x6c8
, u8 val0x6cc
)
815 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
817 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
818 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0
);
819 btcoexist
->btc_write_4byte(btcoexist
, 0x6c0, val0x6c0
);
821 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
822 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4
);
823 btcoexist
->btc_write_4byte(btcoexist
, 0x6c4, val0x6c4
);
825 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
826 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8
);
827 btcoexist
->btc_write_4byte(btcoexist
, 0x6c8, val0x6c8
);
829 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
830 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc
);
831 btcoexist
->btc_write_1byte(btcoexist
, 0x6cc, val0x6cc
);
834 static void btc8821a2ant_coex_table(struct btc_coexist
*btcoexist
,
835 bool force_exec
, u32 val0x6c0
,
836 u32 val0x6c4
, u32 val0x6c8
, u8 val0x6cc
)
838 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
840 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
841 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
842 (force_exec
? "force to" : ""),
843 val0x6c0
, val0x6c4
, val0x6c8
, val0x6cc
);
844 coex_dm
->cur_val0x6c0
= val0x6c0
;
845 coex_dm
->cur_val0x6c4
= val0x6c4
;
846 coex_dm
->cur_val0x6c8
= val0x6c8
;
847 coex_dm
->cur_val0x6cc
= val0x6cc
;
850 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
851 "[BTCoex], pre_val0x6c0 = 0x%x, pre_val0x6c4 = 0x%x, pre_val0x6c8 = 0x%x, pre_val0x6cc = 0x%x !!\n",
852 coex_dm
->pre_val0x6c0
,
853 coex_dm
->pre_val0x6c4
,
854 coex_dm
->pre_val0x6c8
,
855 coex_dm
->pre_val0x6cc
);
856 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
857 "[BTCoex], cur_val0x6c0 = 0x%x, cur_val0x6c4 = 0x%x, cur_val0x6c8 = 0x%x, cur_val0x6cc = 0x%x !!\n",
858 coex_dm
->cur_val0x6c0
,
859 coex_dm
->cur_val0x6c4
,
860 coex_dm
->cur_val0x6c8
,
861 coex_dm
->cur_val0x6cc
);
863 if ((coex_dm
->pre_val0x6c0
== coex_dm
->cur_val0x6c0
) &&
864 (coex_dm
->pre_val0x6c4
== coex_dm
->cur_val0x6c4
) &&
865 (coex_dm
->pre_val0x6c8
== coex_dm
->cur_val0x6c8
) &&
866 (coex_dm
->pre_val0x6cc
== coex_dm
->cur_val0x6cc
))
869 btc8821a2ant_set_coex_table(btcoexist
, val0x6c0
, val0x6c4
, val0x6c8
,
872 coex_dm
->pre_val0x6c0
= coex_dm
->cur_val0x6c0
;
873 coex_dm
->pre_val0x6c4
= coex_dm
->cur_val0x6c4
;
874 coex_dm
->pre_val0x6c8
= coex_dm
->cur_val0x6c8
;
875 coex_dm
->pre_val0x6cc
= coex_dm
->cur_val0x6cc
;
878 static void btc8821a2ant_coex_table_with_type(struct btc_coexist
*btcoexist
,
879 bool force_exec
, u8 type
)
881 coex_sta
->coex_table_type
= type
;
885 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x55555555,
886 0x55555555, 0xffffff, 0x3);
889 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x55555555,
890 0x5afa5afa, 0xffffff, 0x3);
893 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x5ada5ada,
894 0x5ada5ada, 0xffffff, 0x3);
897 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0xaaaaaaaa,
898 0xaaaaaaaa, 0xffffff, 0x3);
901 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0xffffffff,
902 0xffffffff, 0xffffff, 0x3);
905 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x5fff5fff,
906 0x5fff5fff, 0xffffff, 0x3);
909 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x55ff55ff,
910 0x5a5a5a5a, 0xffffff, 0x3);
913 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
914 0x5ada5ada, 0xffffff, 0x3);
917 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
918 0x5ada5ada, 0xffffff, 0x3);
921 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
922 0x5ada5ada, 0xffffff, 0x3);
925 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
926 0x5ada5ada, 0xffffff, 0x3);
929 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
930 0x5ada5ada, 0xffffff, 0x3);
933 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
934 0x5ada5ada, 0xffffff, 0x3);
937 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x5fff5fff,
938 0xaaaaaaaa, 0xffffff, 0x3);
941 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x5fff5fff,
942 0x5ada5ada, 0xffffff, 0x3);
945 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x55dd55dd,
946 0xaaaaaaaa, 0xffffff, 0x3);
949 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0x5fdf5fdf,
950 0x5fdb5fdb, 0xffffff, 0x3);
953 btc8821a2ant_coex_table(btcoexist
, force_exec
, 0xfafafafa,
954 0xfafafafa, 0xffffff, 0x3);
961 static void btc8821a2ant_set_fw_ignore_wlan_act(struct btc_coexist
*btcoex
,
964 struct rtl_priv
*rtlpriv
= btcoex
->adapter
;
965 u8 h2c_parameter
[1] = {0};
968 h2c_parameter
[0] |= BIT0
; /* function enable */
970 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
971 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
974 btcoex
->btc_fill_h2c(btcoex
, 0x63, 1, h2c_parameter
);
977 static void btc8821a2ant_set_lps_rpwm(struct btc_coexist
*btcoexist
, u8 lps_val
,
983 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_LPS_VAL
, &lps
);
984 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_RPWM_VAL
, &rpwm
);
987 static void btc8821a2ant_lps_rpwm(struct btc_coexist
*btcoexist
,
988 bool force_exec
, u8 lps_val
, u8 rpwm_val
)
990 coex_dm
->cur_lps
= lps_val
;
991 coex_dm
->cur_rpwm
= rpwm_val
;
994 if ((coex_dm
->pre_lps
== coex_dm
->cur_lps
) &&
995 (coex_dm
->pre_rpwm
== coex_dm
->cur_rpwm
))
998 btc8821a2ant_set_lps_rpwm(btcoexist
, lps_val
, rpwm_val
);
1000 coex_dm
->pre_lps
= coex_dm
->cur_lps
;
1001 coex_dm
->pre_rpwm
= coex_dm
->cur_rpwm
;
1004 static void btc8821a2ant_ignore_wlan_act(struct btc_coexist
*btcoexist
,
1005 bool force_exec
, bool enable
)
1007 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1009 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1010 "[BTCoex], %s turn Ignore WlanAct %s\n",
1011 (force_exec
? "force to" : ""), (enable
? "ON" : "OFF"));
1012 coex_dm
->cur_ignore_wlan_act
= enable
;
1015 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1016 "[BTCoex], pre_ignore_wlan_act = %d, cur_ignore_wlan_act = %d!!\n",
1017 coex_dm
->pre_ignore_wlan_act
,
1018 coex_dm
->cur_ignore_wlan_act
);
1020 if (coex_dm
->pre_ignore_wlan_act
==
1021 coex_dm
->cur_ignore_wlan_act
)
1024 btc8821a2ant_set_fw_ignore_wlan_act(btcoexist
, enable
);
1026 coex_dm
->pre_ignore_wlan_act
= coex_dm
->cur_ignore_wlan_act
;
1029 static void btc8821a2ant_set_fw_ps_tdma(struct btc_coexist
*btcoexist
,
1030 u8 byte1
, u8 byte2
, u8 byte3
,
1033 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1034 u8 h2c_parameter
[5];
1036 h2c_parameter
[0] = byte1
;
1037 h2c_parameter
[1] = byte2
;
1038 h2c_parameter
[2] = byte3
;
1039 h2c_parameter
[3] = byte4
;
1040 h2c_parameter
[4] = byte5
;
1042 coex_dm
->ps_tdma_para
[0] = byte1
;
1043 coex_dm
->ps_tdma_para
[1] = byte2
;
1044 coex_dm
->ps_tdma_para
[2] = byte3
;
1045 coex_dm
->ps_tdma_para
[3] = byte4
;
1046 coex_dm
->ps_tdma_para
[4] = byte5
;
1048 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1049 "[BTCoex], FW write 0x60(5bytes) = 0x%x%08x\n",
1051 h2c_parameter
[1] << 24 |
1052 h2c_parameter
[2] << 16 |
1053 h2c_parameter
[3] << 8 |
1056 btcoexist
->btc_fill_h2c(btcoexist
, 0x60, 5, h2c_parameter
);
1059 static void btc8821a2ant_sw_mechanism1(struct btc_coexist
*btcoexist
,
1060 bool shrink_rx_lpf
, bool low_penalty_ra
,
1061 bool limited_dig
, bool bt_lna_constrain
)
1063 btc8821a2ant_low_penalty_ra(btcoexist
, NORMAL_EXEC
, low_penalty_ra
);
1066 static void btc8821a2ant_sw_mechanism2(struct btc_coexist
*btcoexist
,
1067 bool agc_table_shift
, bool adc_back_off
,
1068 bool sw_dac_swing
, u32 dac_swing_lvl
)
1070 btc8821a2ant_dac_swing(btcoexist
, NORMAL_EXEC
, sw_dac_swing
,
1074 static void btc8821a2ant_set_ant_path(struct btc_coexist
*btcoexist
,
1075 u8 ant_pos_type
, bool init_hw_cfg
,
1078 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
1080 u8 h2c_parameter
[2] = {0};
1083 /* 0x4c[23] = 0, 0x4c[24] = 1 Antenna control by WL/BT */
1084 u4tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
1087 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u4tmp
);
1089 btcoexist
->btc_write_4byte(btcoexist
, 0x974, 0x3ff);
1091 if (board_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
) {
1092 /* tell firmware "antenna inverse" ==> WRONG firmware
1093 * antenna control code ==>need fw to fix
1095 h2c_parameter
[0] = 1;
1096 h2c_parameter
[1] = 1;
1097 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
1100 /* tell firmware "no antenna inverse" ==> WRONG firmware
1101 * antenna control code ==>need fw to fix
1103 h2c_parameter
[0] = 0;
1104 h2c_parameter
[1] = 1;
1105 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
1110 /* ext switch setting */
1111 switch (ant_pos_type
) {
1112 case BTC_ANT_WIFI_AT_MAIN
:
1113 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xcb7, 0x30, 0x1);
1115 case BTC_ANT_WIFI_AT_AUX
:
1116 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xcb7, 0x30, 0x2);
1121 static void btc8821a2ant_ps_tdma(struct btc_coexist
*btcoexist
,
1122 bool force_exec
, bool turn_on
, u8 type
)
1124 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1126 u8 wifi_rssi_state
, bt_rssi_state
;
1128 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 1, 2,
1129 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES
, 0);
1130 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2,
1131 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 0);
1133 if (!(BTC_RSSI_HIGH(wifi_rssi_state
) &&
1134 BTC_RSSI_HIGH(bt_rssi_state
)) &&
1136 /* for WiFi RSSI low or BT RSSI low */
1140 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1141 "[BTCoex], %s turn %s PS TDMA, type = %d\n",
1142 (force_exec
? "force to" : ""), (turn_on
? "ON" : "OFF"),
1144 coex_dm
->cur_ps_tdma_on
= turn_on
;
1145 coex_dm
->cur_ps_tdma
= type
;
1148 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1149 "[BTCoex], pre_ps_tdma_on = %d, cur_ps_tdma_on = %d!!\n",
1150 coex_dm
->pre_ps_tdma_on
, coex_dm
->cur_ps_tdma_on
);
1151 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1152 "[BTCoex], pre_ps_tdma = %d, cur_ps_tdma = %d!!\n",
1153 coex_dm
->pre_ps_tdma
, coex_dm
->cur_ps_tdma
);
1155 if ((coex_dm
->pre_ps_tdma_on
== coex_dm
->cur_ps_tdma_on
) &&
1156 (coex_dm
->pre_ps_tdma
== coex_dm
->cur_ps_tdma
))
1163 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x3c,
1167 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x2d,
1171 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1c,
1175 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x10,
1179 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x3c,
1183 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x2d,
1187 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1c,
1191 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xa3, 0x10,
1195 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x3c,
1199 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x2d,
1203 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1c,
1207 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x10,
1211 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x3c,
1215 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x2d,
1219 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1c,
1223 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x10,
1227 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xa3, 0x2f,
1231 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x5, 0x5,
1235 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1239 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1243 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x15,
1247 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1e,
1252 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x3c,
1256 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x14,
1260 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x30,
1264 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x3c,
1270 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x3a,
1277 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x2d,
1284 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x1c,
1291 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x10,
1295 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x3c,
1299 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x3c,
1303 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x15,
1308 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x35,
1312 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x1c,
1316 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x14,
1320 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x30,
1325 /* disable PS tdma */
1328 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1332 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1336 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1342 /* update pre state */
1343 coex_dm
->pre_ps_tdma_on
= coex_dm
->cur_ps_tdma_on
;
1344 coex_dm
->pre_ps_tdma
= coex_dm
->cur_ps_tdma
;
1348 btc8821a2ant_ps_tdma_check_for_power_save_state(struct btc_coexist
*btcoexist
,
1353 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_LPS_MODE
, &lps_mode
);
1356 /* already under LPS state */
1358 /* keep state under LPS, do nothing */
1360 /* will leave LPS state, turn off psTdma first */
1361 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1366 /* will enter LPS state, turn off psTdma first */
1367 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1369 /* keep state under NO PS state, do nothing */
1374 static void btc8821a2ant_power_save_state(struct btc_coexist
*btcoexist
,
1375 u8 ps_type
, u8 lps_val
, u8 rpwm_val
)
1377 bool low_pwr_disable
= false;
1380 case BTC_PS_WIFI_NATIVE
:
1381 /* recover to original 32k low power setting */
1382 low_pwr_disable
= false;
1383 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1385 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_NORMAL_LPS
, NULL
);
1386 coex_sta
->force_lps_on
= false;
1389 btc8821a2ant_ps_tdma_check_for_power_save_state(btcoexist
,
1391 btc8821a2ant_lps_rpwm(btcoexist
, NORMAL_EXEC
, lps_val
,
1393 /* when coex force to enter LPS, do not enter 32k low power */
1394 low_pwr_disable
= true;
1395 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1397 /* power save must executed before psTdma */
1398 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_ENTER_LPS
, NULL
);
1399 coex_sta
->force_lps_on
= true;
1401 case BTC_PS_LPS_OFF
:
1402 btc8821a2ant_ps_tdma_check_for_power_save_state(btcoexist
,
1404 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_LEAVE_LPS
, NULL
);
1405 coex_sta
->force_lps_on
= false;
1412 static void btc8821a2ant_coex_all_off(struct btc_coexist
*btcoexist
)
1415 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1416 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1417 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1418 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1421 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false, false);
1422 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false, 0x18);
1425 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1428 static void btc8821a2ant_coex_under_5g(struct btc_coexist
*btcoexist
)
1430 btc8821a2ant_coex_all_off(btcoexist
);
1431 btc8821a2ant_ignore_wlan_act(btcoexist
, NORMAL_EXEC
, true);
1434 static void btc8821a2ant_init_coex_dm(struct btc_coexist
*btcoexist
)
1436 /* force to reset coex mechanism */
1437 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1439 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1440 btc8821a2ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 1);
1441 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, FORCE_EXEC
, 6);
1442 btc8821a2ant_dec_bt_pwr(btcoexist
, FORCE_EXEC
, 0);
1444 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false, false);
1445 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false, 0x18);
1448 static void btc8821a2ant_action_bt_inquiry(struct btc_coexist
*btcoexist
)
1450 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1451 bool wifi_connected
= false;
1452 bool low_pwr_disable
= true;
1453 bool scan
= false, link
= false, roam
= false;
1455 btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
1456 btc8821a2ant_wifi_rssi_state(btcoexist
, 1, 2,
1457 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES
, 0);
1458 btc8821a2ant_bt_rssi_state(btcoexist
,
1459 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 0);
1461 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1463 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1466 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
1467 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
1468 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
1470 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1472 if (scan
|| link
|| roam
) {
1473 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1474 "[BTCoex], Wifi link process + BT Inq/Page!!\n");
1475 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 15);
1476 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 22);
1477 } else if (wifi_connected
) {
1478 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1479 "[BTCoex], Wifi connected + BT Inq/Page!!\n");
1480 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 15);
1481 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 22);
1483 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1484 "[BTCoex], Wifi no-link + BT Inq/Page!!\n");
1485 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1486 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1489 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, FORCE_EXEC
, 6);
1490 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1492 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false, false);
1493 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false, 0x18);
1496 static void btc8821a2ant_action_wifi_link_process(struct btc_coexist
*btcoexist
)
1498 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1501 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 15);
1502 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 22);
1504 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false, false);
1505 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false, 0x18);
1507 u8tmpa
= btcoexist
->btc_read_1byte(btcoexist
, 0x765);
1508 u8tmpb
= btcoexist
->btc_read_1byte(btcoexist
, 0x76e);
1510 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1511 "[BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u8tmpa
, u8tmpb
);
1514 static bool btc8821a2ant_action_wifi_idle_process(struct btc_coexist
*btcoexist
)
1516 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1517 u8 wifi_rssi_state1
;
1520 btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
1521 wifi_rssi_state1
= btc8821a2ant_wifi_rssi_state(btcoexist
, 1, 2,
1522 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES
- 20, 0);
1523 btc8821a2ant_bt_rssi_state(btcoexist
,
1524 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 0);
1526 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_AP_NUM
, &ap_num
);
1528 /* define the office environment */
1529 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && (coex_sta
->hid_exist
) &&
1530 (coex_sta
->a2dp_exist
)) {
1531 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1532 "[BTCoex], Wifi idle process for BT HID+A2DP exist!!\n");
1534 btc8821a2ant_dac_swing(btcoexist
, NORMAL_EXEC
, true, 0x6);
1535 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1538 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false,
1540 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false,
1543 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1544 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1546 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1549 } else if (coex_sta
->pan_exist
) {
1550 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1551 "[BTCoex], Wifi idle process for BT PAN exist!!\n");
1553 btc8821a2ant_dac_swing(btcoexist
, NORMAL_EXEC
, true, 0x6);
1554 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1557 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false,
1559 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false,
1562 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1563 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1565 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1569 btc8821a2ant_dac_swing(btcoexist
, NORMAL_EXEC
, true, 0x18);
1573 static bool btc8821a2ant_is_common_action(struct btc_coexist
*btcoexist
)
1575 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1576 bool common
= false, wifi_connected
= false, wifi_busy
= false;
1577 bool low_pwr_disable
= false;
1578 bool bt_hs_on
= false;
1580 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
1581 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1583 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1585 if (!wifi_connected
) {
1586 low_pwr_disable
= false;
1587 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1589 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false,
1592 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1593 "[BTCoex], Wifi non-connected idle!!\n");
1595 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff,
1597 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1598 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1600 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1601 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1602 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1604 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false,
1606 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false,
1611 if (BT_8821A_2ANT_BT_STATUS_IDLE
==
1612 coex_dm
->bt_status
) {
1613 low_pwr_disable
= false;
1614 btcoexist
->btc_set(btcoexist
,
1615 BTC_SET_ACT_DISABLE_LOW_POWER
,
1617 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
,
1620 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1621 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1623 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1,
1625 btc8821a2ant_coex_table_with_type(btcoexist
,
1628 btc8821a2ant_power_save_state(
1629 btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1630 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1631 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
,
1633 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1635 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
1637 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1641 } else if (BT_8821A_2ANT_BT_STATUS_CON_IDLE
==
1642 coex_dm
->bt_status
) {
1643 low_pwr_disable
= true;
1644 btcoexist
->btc_set(btcoexist
,
1645 BTC_SET_ACT_DISABLE_LOW_POWER
,
1650 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1651 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1652 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
,
1655 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1,
1657 btc8821a2ant_coex_table_with_type(btcoexist
,
1660 btc8821a2ant_power_save_state(
1661 btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1662 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1663 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
,
1665 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
1667 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
1669 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1673 low_pwr_disable
= true;
1674 btcoexist
->btc_set(btcoexist
,
1675 BTC_SET_ACT_DISABLE_LOW_POWER
,
1679 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1680 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1683 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1684 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1686 btc8821a2ant_action_wifi_idle_process(
1694 static void btc8821a2ant_tdma_duration_adjust(struct btc_coexist
*btcoexist
,
1695 bool sco_hid
, bool tx_pause
,
1698 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1699 static long up
, dn
, m
, n
, wait_count
;
1701 * +1: increase WiFi duration
1702 * -1: decrease WiFi duration
1707 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1708 "[BTCoex], TdmaDurationAdjust()\n");
1710 if (coex_dm
->auto_tdma_adjust
) {
1711 coex_dm
->auto_tdma_adjust
= false;
1712 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1713 "[BTCoex], first run TdmaDurationAdjust()!!\n");
1716 if (max_interval
== 1) {
1717 btc8821a2ant_ps_tdma(btcoexist
,
1718 NORMAL_EXEC
, true, 13);
1719 coex_dm
->ps_tdma_du_adj_type
= 13;
1720 } else if (max_interval
== 2) {
1721 btc8821a2ant_ps_tdma(btcoexist
,
1722 NORMAL_EXEC
, true, 14);
1723 coex_dm
->ps_tdma_du_adj_type
= 14;
1724 } else if (max_interval
== 3) {
1725 btc8821a2ant_ps_tdma(btcoexist
,
1726 NORMAL_EXEC
, true, 15);
1727 coex_dm
->ps_tdma_du_adj_type
= 15;
1729 btc8821a2ant_ps_tdma(btcoexist
,
1730 NORMAL_EXEC
, true, 15);
1731 coex_dm
->ps_tdma_du_adj_type
= 15;
1734 if (max_interval
== 1) {
1735 btc8821a2ant_ps_tdma(btcoexist
,
1736 NORMAL_EXEC
, true, 9);
1737 coex_dm
->ps_tdma_du_adj_type
= 9;
1738 } else if (max_interval
== 2) {
1739 btc8821a2ant_ps_tdma(btcoexist
,
1740 NORMAL_EXEC
, true, 10);
1741 coex_dm
->ps_tdma_du_adj_type
= 10;
1742 } else if (max_interval
== 3) {
1743 btc8821a2ant_ps_tdma(btcoexist
,
1744 NORMAL_EXEC
, true, 11);
1745 coex_dm
->ps_tdma_du_adj_type
= 11;
1747 btc8821a2ant_ps_tdma(btcoexist
,
1748 NORMAL_EXEC
, true, 11);
1749 coex_dm
->ps_tdma_du_adj_type
= 11;
1754 if (max_interval
== 1) {
1755 btc8821a2ant_ps_tdma(btcoexist
,
1756 NORMAL_EXEC
, true, 5);
1757 coex_dm
->ps_tdma_du_adj_type
= 5;
1758 } else if (max_interval
== 2) {
1759 btc8821a2ant_ps_tdma(btcoexist
,
1760 NORMAL_EXEC
, true, 6);
1761 coex_dm
->ps_tdma_du_adj_type
= 6;
1762 } else if (max_interval
== 3) {
1763 btc8821a2ant_ps_tdma(btcoexist
,
1764 NORMAL_EXEC
, true, 7);
1765 coex_dm
->ps_tdma_du_adj_type
= 7;
1767 btc8821a2ant_ps_tdma(btcoexist
,
1768 NORMAL_EXEC
, true, 7);
1769 coex_dm
->ps_tdma_du_adj_type
= 7;
1772 if (max_interval
== 1) {
1773 btc8821a2ant_ps_tdma(btcoexist
,
1774 NORMAL_EXEC
, true, 1);
1775 coex_dm
->ps_tdma_du_adj_type
= 1;
1776 } else if (max_interval
== 2) {
1777 btc8821a2ant_ps_tdma(btcoexist
,
1778 NORMAL_EXEC
, true, 2);
1779 coex_dm
->ps_tdma_du_adj_type
= 2;
1780 } else if (max_interval
== 3) {
1781 btc8821a2ant_ps_tdma(btcoexist
,
1782 NORMAL_EXEC
, true, 3);
1783 coex_dm
->ps_tdma_du_adj_type
= 3;
1785 btc8821a2ant_ps_tdma(btcoexist
,
1786 NORMAL_EXEC
, true, 3);
1787 coex_dm
->ps_tdma_du_adj_type
= 3;
1799 /* accquire the BT TRx retry count from BT_Info byte2 */
1800 retry_count
= coex_sta
->bt_retry_cnt
;
1801 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1802 "[BTCoex], retry_count = %d\n", retry_count
);
1803 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1804 "[BTCoex], up = %d, dn = %d, m = %d, n = %d, wait_count = %d\n",
1805 (int)up
, (int)dn
, (int)m
, (int)n
, (int)wait_count
);
1809 if (retry_count
== 0) {
1810 /* no retry in the last 2-second duration */
1818 /* if (retry count == 0) for 2*n seconds,
1819 * make WiFi duration wider
1826 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1827 "[BTCoex], Increase wifi duration!!\n");
1829 } else if (retry_count
<= 3) {
1830 /* <=3 retry in the last 2-second duration */
1838 /* if retry count < 3 for 2*2 seconds,
1839 * shrink wifi duration
1841 if (wait_count
<= 2)
1842 m
++; /* avoid bounce in two levels */
1845 /* m max value is 20, max time is 120 second,
1846 * recheck if adjust WiFi duration.
1856 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1857 "[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
1860 /* retry count > 3, if retry count > 3 happens once,
1861 * shrink WiFi duration
1863 if (wait_count
== 1)
1864 m
++; /* avoid bounce in two levels */
1867 /* m max value is 20, max time is 120 second,
1868 * recheck if adjust WiFi duration.
1878 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1879 "[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
1882 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1883 "[BTCoex], max Interval = %d\n", max_interval
);
1885 if (max_interval
== 1) {
1887 if (coex_dm
->cur_ps_tdma
== 71) {
1888 btc8821a2ant_ps_tdma(btcoexist
,
1889 NORMAL_EXEC
, true, 5);
1890 coex_dm
->ps_tdma_du_adj_type
= 5;
1891 } else if (coex_dm
->cur_ps_tdma
== 1) {
1892 btc8821a2ant_ps_tdma(btcoexist
,
1893 NORMAL_EXEC
, true, 5);
1894 coex_dm
->ps_tdma_du_adj_type
= 5;
1895 } else if (coex_dm
->cur_ps_tdma
== 2) {
1896 btc8821a2ant_ps_tdma(btcoexist
,
1897 NORMAL_EXEC
, true, 6);
1898 coex_dm
->ps_tdma_du_adj_type
= 6;
1899 } else if (coex_dm
->cur_ps_tdma
== 3) {
1900 btc8821a2ant_ps_tdma(btcoexist
,
1901 NORMAL_EXEC
, true, 7);
1902 coex_dm
->ps_tdma_du_adj_type
= 7;
1903 } else if (coex_dm
->cur_ps_tdma
== 4) {
1904 btc8821a2ant_ps_tdma(btcoexist
,
1905 NORMAL_EXEC
, true, 8);
1906 coex_dm
->ps_tdma_du_adj_type
= 8;
1908 if (coex_dm
->cur_ps_tdma
== 9) {
1909 btc8821a2ant_ps_tdma(btcoexist
,
1910 NORMAL_EXEC
, true, 13);
1911 coex_dm
->ps_tdma_du_adj_type
= 13;
1912 } else if (coex_dm
->cur_ps_tdma
== 10) {
1913 btc8821a2ant_ps_tdma(btcoexist
,
1914 NORMAL_EXEC
, true, 14);
1915 coex_dm
->ps_tdma_du_adj_type
= 14;
1916 } else if (coex_dm
->cur_ps_tdma
== 11) {
1917 btc8821a2ant_ps_tdma(btcoexist
,
1918 NORMAL_EXEC
, true, 15);
1919 coex_dm
->ps_tdma_du_adj_type
= 15;
1920 } else if (coex_dm
->cur_ps_tdma
== 12) {
1921 btc8821a2ant_ps_tdma(btcoexist
,
1922 NORMAL_EXEC
, true, 16);
1923 coex_dm
->ps_tdma_du_adj_type
= 16;
1927 if (coex_dm
->cur_ps_tdma
== 5) {
1928 btc8821a2ant_ps_tdma(
1929 btcoexist
, NORMAL_EXEC
,
1931 coex_dm
->ps_tdma_du_adj_type
=
1933 } else if (coex_dm
->cur_ps_tdma
== 6) {
1934 btc8821a2ant_ps_tdma(
1935 btcoexist
, NORMAL_EXEC
,
1937 coex_dm
->ps_tdma_du_adj_type
=
1939 } else if (coex_dm
->cur_ps_tdma
== 7) {
1940 btc8821a2ant_ps_tdma(
1941 btcoexist
, NORMAL_EXEC
,
1943 coex_dm
->ps_tdma_du_adj_type
=
1945 } else if (coex_dm
->cur_ps_tdma
== 13) {
1946 btc8821a2ant_ps_tdma(
1947 btcoexist
, NORMAL_EXEC
,
1949 coex_dm
->ps_tdma_du_adj_type
=
1951 } else if (coex_dm
->cur_ps_tdma
== 14) {
1952 btc8821a2ant_ps_tdma(
1953 btcoexist
, NORMAL_EXEC
,
1955 coex_dm
->ps_tdma_du_adj_type
=
1957 } else if (coex_dm
->cur_ps_tdma
== 15) {
1958 btc8821a2ant_ps_tdma(
1959 btcoexist
, NORMAL_EXEC
,
1961 coex_dm
->ps_tdma_du_adj_type
=
1964 } else if (result
== 1) {
1965 if (coex_dm
->cur_ps_tdma
== 8) {
1966 btc8821a2ant_ps_tdma(
1967 btcoexist
, NORMAL_EXEC
,
1969 coex_dm
->ps_tdma_du_adj_type
=
1971 } else if (coex_dm
->cur_ps_tdma
== 7) {
1972 btc8821a2ant_ps_tdma(
1973 btcoexist
, NORMAL_EXEC
,
1975 coex_dm
->ps_tdma_du_adj_type
=
1977 } else if (coex_dm
->cur_ps_tdma
== 6) {
1978 btc8821a2ant_ps_tdma(
1979 btcoexist
, NORMAL_EXEC
,
1981 coex_dm
->ps_tdma_du_adj_type
=
1983 } else if (coex_dm
->cur_ps_tdma
== 16) {
1984 btc8821a2ant_ps_tdma(
1985 btcoexist
, NORMAL_EXEC
,
1987 coex_dm
->ps_tdma_du_adj_type
=
1989 } else if (coex_dm
->cur_ps_tdma
== 15) {
1990 btc8821a2ant_ps_tdma(
1991 btcoexist
, NORMAL_EXEC
,
1993 coex_dm
->ps_tdma_du_adj_type
=
1995 } else if (coex_dm
->cur_ps_tdma
== 14) {
1996 btc8821a2ant_ps_tdma(
1997 btcoexist
, NORMAL_EXEC
,
1999 coex_dm
->ps_tdma_du_adj_type
=
2004 if (coex_dm
->cur_ps_tdma
== 5) {
2005 btc8821a2ant_ps_tdma(btcoexist
,
2006 NORMAL_EXEC
, true, 71);
2007 coex_dm
->ps_tdma_du_adj_type
= 71;
2008 } else if (coex_dm
->cur_ps_tdma
== 6) {
2009 btc8821a2ant_ps_tdma(btcoexist
,
2010 NORMAL_EXEC
, true, 2);
2011 coex_dm
->ps_tdma_du_adj_type
= 2;
2012 } else if (coex_dm
->cur_ps_tdma
== 7) {
2013 btc8821a2ant_ps_tdma(btcoexist
,
2014 NORMAL_EXEC
, true, 3);
2015 coex_dm
->ps_tdma_du_adj_type
= 3;
2016 } else if (coex_dm
->cur_ps_tdma
== 8) {
2017 btc8821a2ant_ps_tdma(btcoexist
,
2018 NORMAL_EXEC
, true, 4);
2019 coex_dm
->ps_tdma_du_adj_type
= 4;
2021 if (coex_dm
->cur_ps_tdma
== 13) {
2022 btc8821a2ant_ps_tdma(btcoexist
,
2023 NORMAL_EXEC
, true, 9);
2024 coex_dm
->ps_tdma_du_adj_type
= 9;
2025 } else if (coex_dm
->cur_ps_tdma
== 14) {
2026 btc8821a2ant_ps_tdma(btcoexist
,
2027 NORMAL_EXEC
, true, 10);
2028 coex_dm
->ps_tdma_du_adj_type
= 10;
2029 } else if (coex_dm
->cur_ps_tdma
== 15) {
2030 btc8821a2ant_ps_tdma(btcoexist
,
2031 NORMAL_EXEC
, true, 11);
2032 coex_dm
->ps_tdma_du_adj_type
= 11;
2033 } else if (coex_dm
->cur_ps_tdma
== 16) {
2034 btc8821a2ant_ps_tdma(btcoexist
,
2035 NORMAL_EXEC
, true, 12);
2036 coex_dm
->ps_tdma_du_adj_type
= 12;
2040 if (coex_dm
->cur_ps_tdma
== 71) {
2041 btc8821a2ant_ps_tdma(
2042 btcoexist
, NORMAL_EXEC
,
2044 coex_dm
->ps_tdma_du_adj_type
=
2046 } else if (coex_dm
->cur_ps_tdma
== 1) {
2047 btc8821a2ant_ps_tdma(
2048 btcoexist
, NORMAL_EXEC
,
2050 coex_dm
->ps_tdma_du_adj_type
=
2052 } else if (coex_dm
->cur_ps_tdma
== 2) {
2053 btc8821a2ant_ps_tdma(
2054 btcoexist
, NORMAL_EXEC
,
2056 coex_dm
->ps_tdma_du_adj_type
=
2058 } else if (coex_dm
->cur_ps_tdma
== 3) {
2059 btc8821a2ant_ps_tdma(
2060 btcoexist
, NORMAL_EXEC
,
2062 coex_dm
->ps_tdma_du_adj_type
=
2064 } else if (coex_dm
->cur_ps_tdma
== 9) {
2065 btc8821a2ant_ps_tdma(
2066 btcoexist
, NORMAL_EXEC
,
2068 coex_dm
->ps_tdma_du_adj_type
=
2070 } else if (coex_dm
->cur_ps_tdma
== 10) {
2071 btc8821a2ant_ps_tdma(
2072 btcoexist
, NORMAL_EXEC
,
2074 coex_dm
->ps_tdma_du_adj_type
=
2076 } else if (coex_dm
->cur_ps_tdma
== 11) {
2077 btc8821a2ant_ps_tdma(
2078 btcoexist
, NORMAL_EXEC
,
2080 coex_dm
->ps_tdma_du_adj_type
=
2083 } else if (result
== 1) {
2084 if (coex_dm
->cur_ps_tdma
== 4) {
2085 btc8821a2ant_ps_tdma(
2086 btcoexist
, NORMAL_EXEC
,
2088 coex_dm
->ps_tdma_du_adj_type
=
2090 } else if (coex_dm
->cur_ps_tdma
== 3) {
2091 btc8821a2ant_ps_tdma(
2092 btcoexist
, NORMAL_EXEC
,
2094 coex_dm
->ps_tdma_du_adj_type
=
2096 } else if (coex_dm
->cur_ps_tdma
== 2) {
2097 btc8821a2ant_ps_tdma(
2098 btcoexist
, NORMAL_EXEC
,
2100 coex_dm
->ps_tdma_du_adj_type
=
2102 } else if (coex_dm
->cur_ps_tdma
== 1) {
2103 btc8821a2ant_ps_tdma(
2104 btcoexist
, NORMAL_EXEC
,
2106 coex_dm
->ps_tdma_du_adj_type
=
2108 } else if (coex_dm
->cur_ps_tdma
== 12) {
2109 btc8821a2ant_ps_tdma(
2110 btcoexist
, NORMAL_EXEC
,
2112 coex_dm
->ps_tdma_du_adj_type
=
2114 } else if (coex_dm
->cur_ps_tdma
== 11) {
2115 btc8821a2ant_ps_tdma(
2116 btcoexist
, NORMAL_EXEC
,
2118 coex_dm
->ps_tdma_du_adj_type
=
2120 } else if (coex_dm
->cur_ps_tdma
== 10) {
2121 btc8821a2ant_ps_tdma(
2122 btcoexist
, NORMAL_EXEC
,
2124 coex_dm
->ps_tdma_du_adj_type
=
2129 } else if (max_interval
== 2) {
2131 if (coex_dm
->cur_ps_tdma
== 1) {
2132 btc8821a2ant_ps_tdma(btcoexist
,
2133 NORMAL_EXEC
, true, 6);
2134 coex_dm
->ps_tdma_du_adj_type
= 6;
2135 } else if (coex_dm
->cur_ps_tdma
== 2) {
2136 btc8821a2ant_ps_tdma(btcoexist
,
2137 NORMAL_EXEC
, true, 6);
2138 coex_dm
->ps_tdma_du_adj_type
= 6;
2139 } else if (coex_dm
->cur_ps_tdma
== 3) {
2140 btc8821a2ant_ps_tdma(btcoexist
,
2141 NORMAL_EXEC
, true, 7);
2142 coex_dm
->ps_tdma_du_adj_type
= 7;
2143 } else if (coex_dm
->cur_ps_tdma
== 4) {
2144 btc8821a2ant_ps_tdma(btcoexist
,
2145 NORMAL_EXEC
, true, 8);
2146 coex_dm
->ps_tdma_du_adj_type
= 8;
2148 if (coex_dm
->cur_ps_tdma
== 9) {
2149 btc8821a2ant_ps_tdma(btcoexist
,
2150 NORMAL_EXEC
, true, 14);
2151 coex_dm
->ps_tdma_du_adj_type
= 14;
2152 } else if (coex_dm
->cur_ps_tdma
== 10) {
2153 btc8821a2ant_ps_tdma(btcoexist
,
2154 NORMAL_EXEC
, true, 14);
2155 coex_dm
->ps_tdma_du_adj_type
= 14;
2156 } else if (coex_dm
->cur_ps_tdma
== 11) {
2157 btc8821a2ant_ps_tdma(btcoexist
,
2158 NORMAL_EXEC
, true, 15);
2159 coex_dm
->ps_tdma_du_adj_type
= 15;
2160 } else if (coex_dm
->cur_ps_tdma
== 12) {
2161 btc8821a2ant_ps_tdma(btcoexist
,
2162 NORMAL_EXEC
, true, 16);
2163 coex_dm
->ps_tdma_du_adj_type
= 16;
2166 if (coex_dm
->cur_ps_tdma
== 5) {
2167 btc8821a2ant_ps_tdma(
2168 btcoexist
, NORMAL_EXEC
,
2170 coex_dm
->ps_tdma_du_adj_type
=
2172 } else if (coex_dm
->cur_ps_tdma
== 6) {
2173 btc8821a2ant_ps_tdma(
2174 btcoexist
, NORMAL_EXEC
,
2176 coex_dm
->ps_tdma_du_adj_type
=
2178 } else if (coex_dm
->cur_ps_tdma
== 7) {
2179 btc8821a2ant_ps_tdma(
2180 btcoexist
, NORMAL_EXEC
,
2182 coex_dm
->ps_tdma_du_adj_type
=
2184 } else if (coex_dm
->cur_ps_tdma
== 13) {
2185 btc8821a2ant_ps_tdma(
2186 btcoexist
, NORMAL_EXEC
,
2188 coex_dm
->ps_tdma_du_adj_type
=
2190 } else if (coex_dm
->cur_ps_tdma
== 14) {
2191 btc8821a2ant_ps_tdma(
2192 btcoexist
, NORMAL_EXEC
,
2194 coex_dm
->ps_tdma_du_adj_type
=
2196 } else if (coex_dm
->cur_ps_tdma
== 15) {
2197 btc8821a2ant_ps_tdma(
2198 btcoexist
, NORMAL_EXEC
,
2200 coex_dm
->ps_tdma_du_adj_type
=
2203 } else if (result
== 1) {
2204 if (coex_dm
->cur_ps_tdma
== 8) {
2205 btc8821a2ant_ps_tdma(
2206 btcoexist
, NORMAL_EXEC
,
2208 coex_dm
->ps_tdma_du_adj_type
=
2210 } else if (coex_dm
->cur_ps_tdma
== 7) {
2211 btc8821a2ant_ps_tdma(
2212 btcoexist
, NORMAL_EXEC
,
2214 coex_dm
->ps_tdma_du_adj_type
=
2216 } else if (coex_dm
->cur_ps_tdma
== 6) {
2217 btc8821a2ant_ps_tdma(
2218 btcoexist
, NORMAL_EXEC
,
2220 coex_dm
->ps_tdma_du_adj_type
=
2222 } else if (coex_dm
->cur_ps_tdma
== 16) {
2223 btc8821a2ant_ps_tdma(
2224 btcoexist
, NORMAL_EXEC
,
2226 coex_dm
->ps_tdma_du_adj_type
=
2228 } else if (coex_dm
->cur_ps_tdma
== 15) {
2229 btc8821a2ant_ps_tdma(
2230 btcoexist
, NORMAL_EXEC
,
2232 coex_dm
->ps_tdma_du_adj_type
=
2234 } else if (coex_dm
->cur_ps_tdma
== 14) {
2235 btc8821a2ant_ps_tdma(
2236 btcoexist
, NORMAL_EXEC
,
2238 coex_dm
->ps_tdma_du_adj_type
=
2243 if (coex_dm
->cur_ps_tdma
== 5) {
2244 btc8821a2ant_ps_tdma(btcoexist
,
2245 NORMAL_EXEC
, true, 2);
2246 coex_dm
->ps_tdma_du_adj_type
= 2;
2247 } else if (coex_dm
->cur_ps_tdma
== 6) {
2248 btc8821a2ant_ps_tdma(btcoexist
,
2249 NORMAL_EXEC
, true, 2);
2250 coex_dm
->ps_tdma_du_adj_type
= 2;
2251 } else if (coex_dm
->cur_ps_tdma
== 7) {
2252 btc8821a2ant_ps_tdma(btcoexist
,
2253 NORMAL_EXEC
, true, 3);
2254 coex_dm
->ps_tdma_du_adj_type
= 3;
2255 } else if (coex_dm
->cur_ps_tdma
== 8) {
2256 btc8821a2ant_ps_tdma(btcoexist
,
2257 NORMAL_EXEC
, true, 4);
2258 coex_dm
->ps_tdma_du_adj_type
= 4;
2260 if (coex_dm
->cur_ps_tdma
== 13) {
2261 btc8821a2ant_ps_tdma(btcoexist
,
2262 NORMAL_EXEC
, true, 10);
2263 coex_dm
->ps_tdma_du_adj_type
= 10;
2264 } else if (coex_dm
->cur_ps_tdma
== 14) {
2265 btc8821a2ant_ps_tdma(btcoexist
,
2266 NORMAL_EXEC
, true, 10);
2267 coex_dm
->ps_tdma_du_adj_type
= 10;
2268 } else if (coex_dm
->cur_ps_tdma
== 15) {
2269 btc8821a2ant_ps_tdma(btcoexist
,
2270 NORMAL_EXEC
, true, 11);
2271 coex_dm
->ps_tdma_du_adj_type
= 11;
2272 } else if (coex_dm
->cur_ps_tdma
== 16) {
2273 btc8821a2ant_ps_tdma(btcoexist
,
2274 NORMAL_EXEC
, true, 12);
2275 coex_dm
->ps_tdma_du_adj_type
= 12;
2278 if (coex_dm
->cur_ps_tdma
== 1) {
2279 btc8821a2ant_ps_tdma(
2280 btcoexist
, NORMAL_EXEC
,
2282 coex_dm
->ps_tdma_du_adj_type
=
2284 } else if (coex_dm
->cur_ps_tdma
== 2) {
2285 btc8821a2ant_ps_tdma(
2286 btcoexist
, NORMAL_EXEC
,
2288 coex_dm
->ps_tdma_du_adj_type
=
2290 } else if (coex_dm
->cur_ps_tdma
== 3) {
2291 btc8821a2ant_ps_tdma(
2292 btcoexist
, NORMAL_EXEC
,
2294 coex_dm
->ps_tdma_du_adj_type
=
2296 } else if (coex_dm
->cur_ps_tdma
== 9) {
2297 btc8821a2ant_ps_tdma(
2298 btcoexist
, NORMAL_EXEC
,
2300 coex_dm
->ps_tdma_du_adj_type
=
2302 } else if (coex_dm
->cur_ps_tdma
== 10) {
2303 btc8821a2ant_ps_tdma(
2304 btcoexist
, NORMAL_EXEC
,
2306 coex_dm
->ps_tdma_du_adj_type
=
2308 } else if (coex_dm
->cur_ps_tdma
== 11) {
2309 btc8821a2ant_ps_tdma(
2310 btcoexist
, NORMAL_EXEC
,
2312 coex_dm
->ps_tdma_du_adj_type
=
2315 } else if (result
== 1) {
2316 if (coex_dm
->cur_ps_tdma
== 4) {
2317 btc8821a2ant_ps_tdma(
2318 btcoexist
, NORMAL_EXEC
,
2320 coex_dm
->ps_tdma_du_adj_type
=
2322 } else if (coex_dm
->cur_ps_tdma
== 3) {
2323 btc8821a2ant_ps_tdma(
2324 btcoexist
, NORMAL_EXEC
,
2326 coex_dm
->ps_tdma_du_adj_type
=
2328 } else if (coex_dm
->cur_ps_tdma
== 2) {
2329 btc8821a2ant_ps_tdma(
2330 btcoexist
, NORMAL_EXEC
,
2332 coex_dm
->ps_tdma_du_adj_type
=
2334 } else if (coex_dm
->cur_ps_tdma
== 12) {
2335 btc8821a2ant_ps_tdma(
2336 btcoexist
, NORMAL_EXEC
,
2338 coex_dm
->ps_tdma_du_adj_type
=
2340 } else if (coex_dm
->cur_ps_tdma
== 11) {
2341 btc8821a2ant_ps_tdma(
2342 btcoexist
, NORMAL_EXEC
,
2344 coex_dm
->ps_tdma_du_adj_type
=
2346 } else if (coex_dm
->cur_ps_tdma
== 10) {
2347 btc8821a2ant_ps_tdma(
2348 btcoexist
, NORMAL_EXEC
,
2350 coex_dm
->ps_tdma_du_adj_type
=
2355 } else if (max_interval
== 3) {
2357 if (coex_dm
->cur_ps_tdma
== 1) {
2358 btc8821a2ant_ps_tdma(btcoexist
,
2359 NORMAL_EXEC
, true, 7);
2360 coex_dm
->ps_tdma_du_adj_type
= 7;
2361 } else if (coex_dm
->cur_ps_tdma
== 2) {
2362 btc8821a2ant_ps_tdma(btcoexist
,
2363 NORMAL_EXEC
, true, 7);
2364 coex_dm
->ps_tdma_du_adj_type
= 7;
2365 } else if (coex_dm
->cur_ps_tdma
== 3) {
2366 btc8821a2ant_ps_tdma(btcoexist
,
2367 NORMAL_EXEC
, true, 7);
2368 coex_dm
->ps_tdma_du_adj_type
= 7;
2369 } else if (coex_dm
->cur_ps_tdma
== 4) {
2370 btc8821a2ant_ps_tdma(btcoexist
,
2371 NORMAL_EXEC
, true, 8);
2372 coex_dm
->ps_tdma_du_adj_type
= 8;
2374 if (coex_dm
->cur_ps_tdma
== 9) {
2375 btc8821a2ant_ps_tdma(btcoexist
,
2376 NORMAL_EXEC
, true, 15);
2377 coex_dm
->ps_tdma_du_adj_type
= 15;
2378 } else if (coex_dm
->cur_ps_tdma
== 10) {
2379 btc8821a2ant_ps_tdma(btcoexist
,
2380 NORMAL_EXEC
, true, 15);
2381 coex_dm
->ps_tdma_du_adj_type
= 15;
2382 } else if (coex_dm
->cur_ps_tdma
== 11) {
2383 btc8821a2ant_ps_tdma(btcoexist
,
2384 NORMAL_EXEC
, true, 15);
2385 coex_dm
->ps_tdma_du_adj_type
= 15;
2386 } else if (coex_dm
->cur_ps_tdma
== 12) {
2387 btc8821a2ant_ps_tdma(btcoexist
,
2388 NORMAL_EXEC
, true, 16);
2389 coex_dm
->ps_tdma_du_adj_type
= 16;
2392 if (coex_dm
->cur_ps_tdma
== 5) {
2393 btc8821a2ant_ps_tdma(
2394 btcoexist
, NORMAL_EXEC
,
2396 coex_dm
->ps_tdma_du_adj_type
=
2398 } else if (coex_dm
->cur_ps_tdma
== 6) {
2399 btc8821a2ant_ps_tdma(
2400 btcoexist
, NORMAL_EXEC
,
2402 coex_dm
->ps_tdma_du_adj_type
=
2404 } else if (coex_dm
->cur_ps_tdma
== 7) {
2405 btc8821a2ant_ps_tdma(
2406 btcoexist
, NORMAL_EXEC
,
2408 coex_dm
->ps_tdma_du_adj_type
=
2410 } else if (coex_dm
->cur_ps_tdma
== 13) {
2411 btc8821a2ant_ps_tdma(
2412 btcoexist
, NORMAL_EXEC
,
2414 coex_dm
->ps_tdma_du_adj_type
=
2416 } else if (coex_dm
->cur_ps_tdma
== 14) {
2417 btc8821a2ant_ps_tdma(
2418 btcoexist
, NORMAL_EXEC
,
2420 coex_dm
->ps_tdma_du_adj_type
=
2422 } else if (coex_dm
->cur_ps_tdma
== 15) {
2423 btc8821a2ant_ps_tdma(
2424 btcoexist
, NORMAL_EXEC
,
2426 coex_dm
->ps_tdma_du_adj_type
=
2429 } else if (result
== 1) {
2430 if (coex_dm
->cur_ps_tdma
== 8) {
2431 btc8821a2ant_ps_tdma(
2432 btcoexist
, NORMAL_EXEC
,
2434 coex_dm
->ps_tdma_du_adj_type
=
2436 } else if (coex_dm
->cur_ps_tdma
== 7) {
2437 btc8821a2ant_ps_tdma(
2438 btcoexist
, NORMAL_EXEC
,
2440 coex_dm
->ps_tdma_du_adj_type
=
2442 } else if (coex_dm
->cur_ps_tdma
== 6) {
2443 btc8821a2ant_ps_tdma(
2444 btcoexist
, NORMAL_EXEC
,
2446 coex_dm
->ps_tdma_du_adj_type
=
2448 } else if (coex_dm
->cur_ps_tdma
== 16) {
2449 btc8821a2ant_ps_tdma(
2450 btcoexist
, NORMAL_EXEC
,
2452 coex_dm
->ps_tdma_du_adj_type
=
2454 } else if (coex_dm
->cur_ps_tdma
== 15) {
2455 btc8821a2ant_ps_tdma(
2456 btcoexist
, NORMAL_EXEC
,
2458 coex_dm
->ps_tdma_du_adj_type
=
2460 } else if (coex_dm
->cur_ps_tdma
== 14) {
2461 btc8821a2ant_ps_tdma(
2462 btcoexist
, NORMAL_EXEC
,
2464 coex_dm
->ps_tdma_du_adj_type
=
2469 if (coex_dm
->cur_ps_tdma
== 5) {
2470 btc8821a2ant_ps_tdma(btcoexist
,
2471 NORMAL_EXEC
, true, 3);
2472 coex_dm
->ps_tdma_du_adj_type
= 3;
2473 } else if (coex_dm
->cur_ps_tdma
== 6) {
2474 btc8821a2ant_ps_tdma(btcoexist
,
2475 NORMAL_EXEC
, true, 3);
2476 coex_dm
->ps_tdma_du_adj_type
= 3;
2477 } else if (coex_dm
->cur_ps_tdma
== 7) {
2478 btc8821a2ant_ps_tdma(btcoexist
,
2479 NORMAL_EXEC
, true, 3);
2480 coex_dm
->ps_tdma_du_adj_type
= 3;
2481 } else if (coex_dm
->cur_ps_tdma
== 8) {
2482 btc8821a2ant_ps_tdma(btcoexist
,
2483 NORMAL_EXEC
, true, 4);
2484 coex_dm
->ps_tdma_du_adj_type
= 4;
2486 if (coex_dm
->cur_ps_tdma
== 13) {
2487 btc8821a2ant_ps_tdma(btcoexist
,
2488 NORMAL_EXEC
, true, 11);
2489 coex_dm
->ps_tdma_du_adj_type
= 11;
2490 } else if (coex_dm
->cur_ps_tdma
== 14) {
2491 btc8821a2ant_ps_tdma(btcoexist
,
2492 NORMAL_EXEC
, true, 11);
2493 coex_dm
->ps_tdma_du_adj_type
= 11;
2494 } else if (coex_dm
->cur_ps_tdma
== 15) {
2495 btc8821a2ant_ps_tdma(btcoexist
,
2496 NORMAL_EXEC
, true, 11);
2497 coex_dm
->ps_tdma_du_adj_type
= 11;
2498 } else if (coex_dm
->cur_ps_tdma
== 16) {
2499 btc8821a2ant_ps_tdma(btcoexist
,
2500 NORMAL_EXEC
, true, 12);
2501 coex_dm
->ps_tdma_du_adj_type
= 12;
2504 if (coex_dm
->cur_ps_tdma
== 1) {
2505 btc8821a2ant_ps_tdma(
2506 btcoexist
, NORMAL_EXEC
,
2508 coex_dm
->ps_tdma_du_adj_type
=
2510 } else if (coex_dm
->cur_ps_tdma
== 2) {
2511 btc8821a2ant_ps_tdma(
2512 btcoexist
, NORMAL_EXEC
,
2514 coex_dm
->ps_tdma_du_adj_type
=
2516 } else if (coex_dm
->cur_ps_tdma
== 3) {
2517 btc8821a2ant_ps_tdma(
2518 btcoexist
, NORMAL_EXEC
,
2520 coex_dm
->ps_tdma_du_adj_type
=
2522 } else if (coex_dm
->cur_ps_tdma
== 9) {
2523 btc8821a2ant_ps_tdma(
2524 btcoexist
, NORMAL_EXEC
,
2526 coex_dm
->ps_tdma_du_adj_type
=
2528 } else if (coex_dm
->cur_ps_tdma
== 10) {
2529 btc8821a2ant_ps_tdma(
2530 btcoexist
, NORMAL_EXEC
,
2532 coex_dm
->ps_tdma_du_adj_type
=
2534 } else if (coex_dm
->cur_ps_tdma
== 11) {
2535 btc8821a2ant_ps_tdma(
2536 btcoexist
, NORMAL_EXEC
,
2538 coex_dm
->ps_tdma_du_adj_type
=
2541 } else if (result
== 1) {
2542 if (coex_dm
->cur_ps_tdma
== 4) {
2543 btc8821a2ant_ps_tdma(
2544 btcoexist
, NORMAL_EXEC
,
2546 coex_dm
->ps_tdma_du_adj_type
=
2548 } else if (coex_dm
->cur_ps_tdma
== 3) {
2549 btc8821a2ant_ps_tdma(
2550 btcoexist
, NORMAL_EXEC
,
2552 coex_dm
->ps_tdma_du_adj_type
=
2554 } else if (coex_dm
->cur_ps_tdma
== 2) {
2555 btc8821a2ant_ps_tdma(
2556 btcoexist
, NORMAL_EXEC
,
2558 coex_dm
->ps_tdma_du_adj_type
=
2560 } else if (coex_dm
->cur_ps_tdma
== 12) {
2561 btc8821a2ant_ps_tdma(
2562 btcoexist
, NORMAL_EXEC
,
2564 coex_dm
->ps_tdma_du_adj_type
=
2566 } else if (coex_dm
->cur_ps_tdma
== 11) {
2567 btc8821a2ant_ps_tdma(
2568 btcoexist
, NORMAL_EXEC
,
2570 coex_dm
->ps_tdma_du_adj_type
=
2572 } else if (coex_dm
->cur_ps_tdma
== 10) {
2573 btc8821a2ant_ps_tdma(
2574 btcoexist
, NORMAL_EXEC
,
2576 coex_dm
->ps_tdma_du_adj_type
=
2584 /* if current PsTdma not match with the recorded one
2585 * (when scan, dhcp...), then we have to adjust it back to
2586 * the previous recorded one.
2588 if (coex_dm
->cur_ps_tdma
!= coex_dm
->ps_tdma_du_adj_type
) {
2589 bool scan
= false, link
= false, roam
= false;
2591 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2592 "[BTCoex], PsTdma type mismatch!!!, cur_ps_tdma = %d, recordPsTdma = %d\n",
2593 coex_dm
->cur_ps_tdma
, coex_dm
->ps_tdma_du_adj_type
);
2595 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2596 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2597 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2599 if (!scan
&& !link
&& !roam
) {
2600 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
2601 coex_dm
->ps_tdma_du_adj_type
);
2603 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2604 "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
2609 /* SCO only or SCO+PAN(HS)*/
2610 static void btc8821a2ant_action_sco(struct btc_coexist
*btcoexist
)
2612 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
2613 u8 wifi_rssi_state
, bt_rssi_state
;
2616 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2617 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2, 35, 0);
2619 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2621 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2622 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 4);
2624 if (BTC_RSSI_HIGH(bt_rssi_state
))
2625 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2627 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2629 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2631 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
2632 /* for SCO quality at 11b/g mode */
2633 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
2635 /* for SCO quality & wifi performance balance at 11n mode */
2636 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
2637 btc8821a2ant_coex_table_with_type(btcoexist
,
2640 if (bt_link_info
->sco_only
)
2641 btc8821a2ant_coex_table_with_type(
2642 btcoexist
, NORMAL_EXEC
, 17);
2644 btc8821a2ant_coex_table_with_type(
2645 btcoexist
, NORMAL_EXEC
, 12);
2649 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
2650 /* for voice quality */
2651 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
2654 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
2655 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2656 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2657 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
2659 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2662 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
2664 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2668 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2669 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2670 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
2672 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2675 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
2677 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2683 static void btc8821a2ant_action_hid(struct btc_coexist
*btcoexist
)
2685 u8 wifi_rssi_state
, bt_rssi_state
;
2688 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2689 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
,
2690 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 0);
2692 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2694 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2695 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2697 if (BTC_RSSI_HIGH(bt_rssi_state
))
2698 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2700 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2702 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2704 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
2705 /* for HID at 11b/g mode */
2706 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
2708 /* for HID quality & wifi performance balance at 11n mode */
2709 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
2712 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
2713 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 24);
2715 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
2717 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2718 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2719 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
2721 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2724 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
2726 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2731 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2732 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2733 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
2735 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2738 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
2740 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2746 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
2747 static void btc8821a2ant_action_a2dp(struct btc_coexist
*btcoexist
)
2749 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
2753 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2754 wifi_rssi_state1
= btc8821a2ant_wifi_rssi_state(btcoexist
, 1, 2,
2755 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES
, 0);
2756 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
,
2757 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 0);
2759 if ((ap_num
>= 10) && BTC_RSSI_HIGH(wifi_rssi_state1
) &&
2760 BTC_RSSI_HIGH(bt_rssi_state
)) {
2761 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2764 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff,
2766 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false,
2768 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2769 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
2771 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
2773 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2775 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 23);
2778 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2779 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
2780 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
2782 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2785 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
2787 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2793 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2794 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2796 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2798 if (BTC_RSSI_HIGH(bt_rssi_state
))
2799 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
2801 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
2803 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
)) {
2804 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
2805 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2808 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 13);
2809 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
2813 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2814 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2815 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 23);
2817 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 23);
2821 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2822 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
2823 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2824 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2825 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
2827 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2830 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
2832 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2836 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2837 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2838 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
2840 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2843 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
2845 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2851 static void btc8821a2ant_action_a2dp_pan_hs(struct btc_coexist
*btcoexist
)
2853 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
2856 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2857 wifi_rssi_state1
= btc8821a2ant_wifi_rssi_state(btcoexist
, 1, 2,
2858 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES
, 0);
2859 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
,
2860 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 0);
2862 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2864 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2865 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2867 if (BTC_RSSI_HIGH(bt_rssi_state
))
2868 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
2870 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
2872 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
)) {
2873 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
2874 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2877 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 13);
2878 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
2882 btc8821a2ant_tdma_duration_adjust(btcoexist
, false, true, 2);
2885 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2886 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
2887 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2888 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2889 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
2891 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2894 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
2896 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2900 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2901 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2902 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
2904 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2907 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
2909 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2915 static void btc8821a2ant_action_pan_edr(struct btc_coexist
*btcoexist
)
2917 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
2920 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2921 wifi_rssi_state1
= btc8821a2ant_wifi_rssi_state(btcoexist
, 1, 2,
2922 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES
, 0);
2923 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
,
2924 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 0);
2926 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2928 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2930 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2932 if (BTC_RSSI_HIGH(bt_rssi_state
))
2933 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2935 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2937 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
)) {
2938 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 10);
2939 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2942 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 13);
2943 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
2947 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2948 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
))
2949 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 26);
2951 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 26);
2954 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2955 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
2956 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2957 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2958 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
2960 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2963 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
2965 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2969 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2970 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2971 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
2973 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2976 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
2978 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2985 static void btc8821a2ant_action_pan_hs(struct btc_coexist
*btcoexist
)
2987 u8 wifi_rssi_state
, bt_rssi_state
;
2990 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2991 btc8821a2ant_wifi_rssi_state(btcoexist
, 1, 2,
2992 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES
, 0);
2993 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
,
2994 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 0);
2996 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
2998 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2999 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3001 if (BTC_RSSI_HIGH(bt_rssi_state
))
3002 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3004 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3006 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
3007 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
3008 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
3010 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3011 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
3012 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3013 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3014 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
3016 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
3019 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
3021 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
3025 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3026 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3027 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
3029 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
3032 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
3034 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
3041 static void btc8821a2ant_action_pan_edr_a2dp(struct btc_coexist
*btcoexist
)
3043 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
3046 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
3047 wifi_rssi_state1
= btc8821a2ant_wifi_rssi_state(btcoexist
, 1, 2,
3048 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES
, 0);
3049 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
,
3050 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 0);
3052 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
3054 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
3056 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3058 if (BTC_RSSI_HIGH(bt_rssi_state
))
3059 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3061 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3063 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
))
3064 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3067 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
3070 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3072 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3073 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3074 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 12);
3076 if (wifi_bw
== BTC_WIFI_BW_HT40
)
3077 btc8821a2ant_tdma_duration_adjust(btcoexist
, false,
3080 btc8821a2ant_tdma_duration_adjust(btcoexist
, false,
3083 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 13);
3084 btc8821a2ant_tdma_duration_adjust(btcoexist
, false, true, 3);
3088 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
3089 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3090 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3091 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
3093 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
3096 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
3098 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
3102 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3103 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3104 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
3106 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
3109 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
3111 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
3117 static void btc8821a2ant_action_pan_edr_hid(struct btc_coexist
*btcoexist
)
3119 u8 wifi_rssi_state
, bt_rssi_state
;
3122 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
3123 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
,
3124 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 0);
3126 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3128 if (BTC_RSSI_HIGH(bt_rssi_state
))
3129 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
3131 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
3133 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3135 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
3136 /* for HID at 11b/g mode */
3137 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
3138 0x5a5f5a5f, 0xffff, 0x3);
3140 /* for HID quality & wifi performance balance at 11n mode */
3141 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
3142 0x5a5f5a5f, 0xffff, 0x3);
3145 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
3146 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 3);
3148 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3149 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3150 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
3153 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
3157 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3158 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3159 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
3161 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
3164 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
3166 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
3170 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3172 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3173 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3174 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 10);
3176 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
3180 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3181 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3182 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
3184 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
3187 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
3189 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
3195 /* HID+A2DP+PAN(EDR) */
3196 static void btc8821a2ant_act_hid_a2dp_pan_edr(struct btc_coexist
*btcoexist
)
3198 u8 wifi_rssi_state
, wifi_rssi_state1
, bt_rssi_state
;
3201 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
3202 wifi_rssi_state1
= btc8821a2ant_wifi_rssi_state(btcoexist
, 1, 2,
3203 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES
, 0);
3204 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
,
3205 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 0);
3207 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
3209 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
3210 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3212 if (BTC_RSSI_HIGH(bt_rssi_state
))
3213 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3215 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3217 if (BTC_RSSI_HIGH(wifi_rssi_state1
) && BTC_RSSI_HIGH(bt_rssi_state
)) {
3218 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
3219 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3222 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 14);
3223 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
3227 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3229 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3230 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3231 if (wifi_bw
== BTC_WIFI_BW_HT40
)
3232 btc8821a2ant_tdma_duration_adjust(btcoexist
, true,
3235 btc8821a2ant_tdma_duration_adjust(btcoexist
, true,
3238 btc8821a2ant_tdma_duration_adjust(btcoexist
, true, true, 3);
3242 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
3243 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3244 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3245 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
3247 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
3250 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
3252 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
3256 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3257 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3258 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
3260 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
3263 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
3265 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
3271 static void btc8821a2ant_action_hid_a2dp(struct btc_coexist
*btcoexist
)
3274 u8 wifi_rssi_state
, bt_rssi_state
;
3277 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
3278 btc8821a2ant_wifi_rssi_state(btcoexist
, 1, 2,
3279 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES
, 0);
3280 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
,
3281 3, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES
, 37);
3283 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x0);
3285 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, true, 0x5);
3286 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3288 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3289 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
3290 if (BTC_RSSI_HIGH(bt_rssi_state
))
3291 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3292 else if (BTC_RSSI_MEDIUM(bt_rssi_state
))
3293 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3295 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3297 /* only 802.11N mode we have to dec bt power to 4 degree */
3298 if (BTC_RSSI_HIGH(bt_rssi_state
)) {
3299 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_AP_NUM
,
3302 btc8821a2ant_dec_bt_pwr(btcoexist
,
3305 btc8821a2ant_dec_bt_pwr(btcoexist
,
3307 } else if (BTC_RSSI_MEDIUM(bt_rssi_state
)) {
3308 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 2);
3310 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3314 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
3315 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
3316 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
3319 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 14);
3320 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
, 0x50,
3324 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3325 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3326 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 23);
3328 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 23);
3332 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
3333 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3334 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3335 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
3337 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
3340 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
3342 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
3346 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
3347 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
3348 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
3350 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
3353 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
3355 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
3361 static void btc8821a2ant_action_wifi_multi_port(struct btc_coexist
*btcoexist
)
3363 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
3364 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, 0);
3367 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false, false);
3368 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false, 0x18);
3371 btc8821a2ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
3373 btc8821a2ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
3374 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
3377 static void btc8821a2ant_run_coexist_mechanism(struct btc_coexist
*btcoexist
)
3379 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3380 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
3381 bool wifi_under_5g
= false;
3383 u32 num_of_wifi_link
= 0;
3384 u32 wifi_link_status
= 0;
3385 bool miracast_plus_bt
= false;
3386 bool scan
= false, link
= false, roam
= false;
3388 if (btcoexist
->manual_control
) {
3389 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3390 "[BTCoex], Manual control!!!\n");
3394 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
3396 if (wifi_under_5g
) {
3397 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3398 "[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n");
3399 btc8821a2ant_coex_under_5g(btcoexist
);
3403 if (coex_sta
->under_ips
) {
3404 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3405 "[BTCoex], wifi is under IPS !!!\n");
3409 algorithm
= btc8821a2ant_action_algorithm(btcoexist
);
3410 if (coex_sta
->c2h_bt_inquiry_page
&&
3411 (BT_8821A_2ANT_COEX_ALGO_PANHS
!= algorithm
)) {
3412 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3413 "[BTCoex], BT is under inquiry/page scan !!\n");
3414 btc8821a2ant_action_bt_inquiry(btcoexist
);
3418 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
3419 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
3420 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
3422 if (scan
|| link
|| roam
) {
3423 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3424 "[BTCoex], WiFi is under Link Process !!\n");
3425 btc8821a2ant_action_wifi_link_process(btcoexist
);
3430 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
3432 num_of_wifi_link
= wifi_link_status
>> 16;
3434 if ((num_of_wifi_link
>= 2) ||
3435 (wifi_link_status
& WIFI_P2P_GO_CONNECTED
)) {
3436 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3437 "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
3438 num_of_wifi_link
, wifi_link_status
);
3440 if (bt_link_info
->bt_link_exist
)
3441 miracast_plus_bt
= true;
3443 miracast_plus_bt
= false;
3445 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_MIRACAST_PLUS_BT
,
3447 btc8821a2ant_action_wifi_multi_port(btcoexist
);
3452 miracast_plus_bt
= false;
3453 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_MIRACAST_PLUS_BT
,
3456 coex_dm
->cur_algorithm
= algorithm
;
3457 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3458 "[BTCoex], Algorithm = %d\n", coex_dm
->cur_algorithm
);
3460 if (btc8821a2ant_is_common_action(btcoexist
)) {
3461 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3462 "[BTCoex], Action 2-Ant common\n");
3463 coex_dm
->auto_tdma_adjust
= true;
3465 if (coex_dm
->cur_algorithm
!= coex_dm
->pre_algorithm
) {
3466 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3467 "[BTCoex], pre_algorithm = %d, cur_algorithm = %d\n",
3468 coex_dm
->pre_algorithm
,
3469 coex_dm
->cur_algorithm
);
3470 coex_dm
->auto_tdma_adjust
= false;
3472 switch (coex_dm
->cur_algorithm
) {
3473 case BT_8821A_2ANT_COEX_ALGO_SCO
:
3474 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3475 "[BTCoex], Action 2-Ant, algorithm = SCO\n");
3476 btc8821a2ant_action_sco(btcoexist
);
3478 case BT_8821A_2ANT_COEX_ALGO_HID
:
3479 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3480 "[BTCoex], Action 2-Ant, algorithm = HID\n");
3481 btc8821a2ant_action_hid(btcoexist
);
3483 case BT_8821A_2ANT_COEX_ALGO_A2DP
:
3484 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3485 "[BTCoex], Action 2-Ant, algorithm = A2DP\n");
3486 btc8821a2ant_action_a2dp(btcoexist
);
3488 case BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS
:
3489 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3490 "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS)\n");
3491 btc8821a2ant_action_a2dp_pan_hs(btcoexist
);
3493 case BT_8821A_2ANT_COEX_ALGO_PANEDR
:
3494 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3495 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)\n");
3496 btc8821a2ant_action_pan_edr(btcoexist
);
3498 case BT_8821A_2ANT_COEX_ALGO_PANHS
:
3499 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3500 "[BTCoex], Action 2-Ant, algorithm = HS mode\n");
3501 btc8821a2ant_action_pan_hs(btcoexist
);
3503 case BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP
:
3504 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3505 "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP\n");
3506 btc8821a2ant_action_pan_edr_a2dp(btcoexist
);
3508 case BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
:
3509 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3510 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID\n");
3511 btc8821a2ant_action_pan_edr_hid(btcoexist
);
3513 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR
:
3514 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3515 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN\n");
3516 btc8821a2ant_act_hid_a2dp_pan_edr(btcoexist
);
3518 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP
:
3519 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3520 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP\n");
3521 btc8821a2ant_action_hid_a2dp(btcoexist
);
3524 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3525 "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3526 btc8821a2ant_coex_all_off(btcoexist
);
3529 coex_dm
->pre_algorithm
= coex_dm
->cur_algorithm
;
3533 static void btc8821a2ant_wifi_off_hw_cfg(struct btc_coexist
*btcoexist
)
3535 u8 h2c_parameter
[2] = {0};
3538 /* set wlan_act to low */
3539 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
3541 /* WiFi goto standby while GNT_BT 0-->1 */
3542 btcoexist
->btc_set_rf_reg(btcoexist
, BTC_RF_A
, 0x1, 0xfffff, 0x780);
3543 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
3544 if (fw_ver
>= 0x180000) {
3545 /* Use H2C to set GNT_BT to HIGH */
3546 h2c_parameter
[0] = 1;
3547 btcoexist
->btc_fill_h2c(btcoexist
, 0x6E, 1, h2c_parameter
);
3549 btcoexist
->btc_write_1byte(btcoexist
, 0x765, 0x18);
3553 /**************************************************************
3554 * extern function start with ex_btc8821a2ant_
3555 **************************************************************/
3556 void ex_btc8821a2ant_init_hwconfig(struct btc_coexist
*btcoexist
)
3558 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3561 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3562 "[BTCoex], 2Ant Init HW Config!!\n");
3564 /* backup rf 0x1e value */
3565 coex_dm
->bt_rf0x1e_backup
=
3566 btcoexist
->btc_get_rf_reg(btcoexist
, BTC_RF_A
, 0x1e, 0xfffff);
3568 /* 0x790[5:0] = 0x5 */
3569 u1tmp
= btcoexist
->btc_read_1byte(btcoexist
, 0x790);
3572 btcoexist
->btc_write_1byte(btcoexist
, 0x790, u1tmp
);
3574 /* Antenna config */
3575 btc8821a2ant_set_ant_path(btcoexist
, BTC_ANT_WIFI_AT_MAIN
, true, false);
3576 coex_sta
->dis_ver_info_cnt
= 0;
3579 btc8821a2ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 0);
3581 /* Enable counter statistics */
3582 /* 0x76e[3] = 1, WLAN_Act control by PTA */
3583 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0x4);
3584 btcoexist
->btc_write_1byte(btcoexist
, 0x778, 0x3);
3585 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x40, 0x20, 0x1);
3588 void ex_btc8821a2ant_pre_load_firmware(struct btc_coexist
*btcoexist
)
3590 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
3591 u8 u8tmp
= 0x4; /* Set BIT2 by default since it's 2ant case */
3594 * S0 or S1 setting and Local register setting(By the setting fw can get
3595 * ant number, S0/S1, ... info)
3597 * Local setting bit define
3598 * BIT0: "0" for no antenna inverse; "1" for antenna inverse
3599 * BIT1: "0" for internal switch; "1" for external switch
3600 * BIT2: "0" for one antenna; "1" for two antenna
3601 * NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and
3604 if (btcoexist
->chip_interface
== BTC_INTF_USB
) {
3605 /* fixed at S0 for USB interface */
3606 u8tmp
|= 0x1; /* antenna inverse */
3607 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0xfe08, u8tmp
);
3609 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
3610 if (board_info
->single_ant_path
== 0) {
3611 } else if (board_info
->single_ant_path
== 1) {
3613 u8tmp
|= 0x1; /* antenna inverse */
3616 if (btcoexist
->chip_interface
== BTC_INTF_PCI
)
3617 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0x384,
3619 else if (btcoexist
->chip_interface
== BTC_INTF_SDIO
)
3620 btcoexist
->btc_write_local_reg_1byte(btcoexist
, 0x60,
3625 void ex_btc8821a2ant_init_coex_dm(struct btc_coexist
*btcoexist
)
3627 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3629 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3630 "[BTCoex], Coex Mechanism Init!!\n");
3632 btc8821a2ant_init_coex_dm(btcoexist
);
3635 void ex_btc8821a2ant_display_coex_info(struct btc_coexist
*btcoexist
,
3638 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
3639 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
3640 u8 u1tmp
[4], i
, bt_info_ext
, ps_tdma_case
= 0;
3642 bool roam
= false, scan
= false, link
= false, wifi_under_5g
= false;
3643 bool bt_hs_on
= false, wifi_busy
= false;
3644 long wifi_rssi
= 0, bt_hs_rssi
= 0;
3645 u32 wifi_bw
, wifi_traffic_dir
;
3646 u8 wifi_dot_11_chnl
, wifi_hs_chnl
;
3647 u32 fw_ver
= 0, bt_patch_ver
= 0;
3649 seq_puts(m
, "\n ============[BT Coexist info]============");
3651 seq_printf(m
, "\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:",
3652 board_info
->pg_ant_num
, board_info
->btdm_ant_num
);
3654 if (btcoexist
->manual_control
) {
3655 seq_printf(m
, "\n %-35s", "[Action Manual control]!!");
3658 seq_printf(m
, "\n %-35s = %s / %d", "BT stack/ hci ext ver",
3659 ((stack_info
->profile_notified
) ? "Yes" : "No"),
3660 stack_info
->hci_version
);
3662 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
, &bt_patch_ver
);
3663 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
3664 seq_printf(m
, "\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
3665 "CoexVer/ FwVer/ PatchVer",
3666 glcoex_ver_date_8821a_2ant
, glcoex_ver_8821a_2ant
,
3667 fw_ver
, bt_patch_ver
, bt_patch_ver
);
3669 btcoexist
->btc_get(btcoexist
,
3670 BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
3671 btcoexist
->btc_get(btcoexist
,
3672 BTC_GET_U1_WIFI_DOT11_CHNL
, &wifi_dot_11_chnl
);
3673 btcoexist
->btc_get(btcoexist
,
3674 BTC_GET_U1_WIFI_HS_CHNL
, &wifi_hs_chnl
);
3675 seq_printf(m
, "\n %-35s = %d / %d(%d)",
3676 "Dot11 channel / HsMode(HsChnl)",
3677 wifi_dot_11_chnl
, bt_hs_on
, wifi_hs_chnl
);
3679 seq_printf(m
, "\n %-35s = %3ph ",
3680 "H2C Wifi inform bt chnl Info",
3681 coex_dm
->wifi_chnl_info
);
3683 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
3684 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_HS_RSSI
, &bt_hs_rssi
);
3685 seq_printf(m
, "\n %-35s = %ld/ %ld", "Wifi rssi/ HS rssi",
3686 wifi_rssi
, bt_hs_rssi
);
3688 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
3689 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
3690 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
3691 seq_printf(m
, "\n %-35s = %d/ %d/ %d ", "Wifi link/ roam/ scan",
3694 btcoexist
->btc_get(btcoexist
,
3695 BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
3696 btcoexist
->btc_get(btcoexist
,
3697 BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3698 btcoexist
->btc_get(btcoexist
,
3699 BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
3700 btcoexist
->btc_get(btcoexist
,
3701 BTC_GET_U4_WIFI_TRAFFIC_DIRECTION
, &wifi_traffic_dir
);
3702 seq_printf(m
, "\n %-35s = %s / %s/ %s ", "Wifi status",
3703 (wifi_under_5g
? "5G" : "2.4G"),
3704 ((BTC_WIFI_BW_LEGACY
== wifi_bw
) ? "Legacy" :
3705 (((BTC_WIFI_BW_HT40
== wifi_bw
) ? "HT40" : "HT20"))),
3706 ((!wifi_busy
) ? "idle" :
3707 ((BTC_WIFI_TRAFFIC_TX
== wifi_traffic_dir
) ?
3708 "uplink" : "downlink")));
3710 if (stack_info
->profile_notified
) {
3711 seq_printf(m
, "\n %-35s = %d / %d / %d / %d",
3713 stack_info
->sco_exist
, stack_info
->hid_exist
,
3714 stack_info
->pan_exist
, stack_info
->a2dp_exist
);
3716 btcoexist
->btc_disp_dbg_msg(btcoexist
,
3717 BTC_DBG_DISP_BT_LINK_INFO
,
3721 bt_info_ext
= coex_sta
->bt_info_ext
;
3722 seq_printf(m
, "\n %-35s = %s", "BT Info A2DP rate",
3723 (bt_info_ext
&BIT0
) ? "Basic rate" : "EDR rate");
3725 for (i
= 0; i
< BT_INFO_SRC_8821A_2ANT_MAX
; i
++) {
3726 if (coex_sta
->bt_info_c2h_cnt
[i
]) {
3727 seq_printf(m
, "\n %-35s = %7ph(%d)",
3728 glbt_info_src_8821a_2ant
[i
],
3729 coex_sta
->bt_info_c2h
[i
],
3730 coex_sta
->bt_info_c2h_cnt
[i
]);
3734 seq_printf(m
, "\n %-35s = %s/%s",
3735 "PS state, IPS/LPS",
3736 ((coex_sta
->under_ips
? "IPS ON" : "IPS OFF")),
3737 ((coex_sta
->under_lps
? "LPS ON" : "LPS OFF")));
3738 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_FW_PWR_MODE_CMD
, m
);
3741 seq_printf(m
, "\n %-35s",
3742 "============[Sw mechanism]============");
3743 seq_printf(m
, "\n %-35s = %d/ %d/ %d(0x%x) ",
3744 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
3745 coex_dm
->cur_agc_table_en
, coex_dm
->cur_adc_back_off
,
3746 coex_dm
->cur_dac_swing_on
, coex_dm
->cur_dac_swing_lvl
);
3749 seq_printf(m
, "\n %-35s",
3750 "============[Fw mechanism]============");
3752 if (!btcoexist
->manual_control
) {
3753 ps_tdma_case
= coex_dm
->cur_ps_tdma
;
3754 seq_printf(m
, "\n %-35s = %5ph case-%d",
3756 coex_dm
->ps_tdma_para
, ps_tdma_case
);
3758 seq_printf(m
, "\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct",
3759 coex_dm
->cur_dec_bt_pwr_lvl
,
3760 coex_dm
->cur_ignore_wlan_act
);
3764 seq_printf(m
, "\n %-35s", "============[Hw setting]============");
3766 seq_printf(m
, "\n %-35s = 0x%x", "RF-A, 0x1e initVal",
3767 coex_dm
->bt_rf0x1e_backup
);
3769 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x778);
3770 u1tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x6cc);
3771 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x ",
3772 "0x778 (W_Act)/ 0x6cc (CoTab Sel)",
3773 u1tmp
[0], u1tmp
[1]);
3775 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x8db);
3776 u1tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0xc5b);
3777 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x",
3778 "0x8db(ADC)/0xc5b[29:25](DAC)",
3779 ((u1tmp
[0] & 0x60) >> 5), ((u1tmp
[1] & 0x3e) >> 1));
3781 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xcb4);
3782 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x",
3783 "0xcb4[7:0](ctrl)/ 0xcb4[29:28](val)",
3784 u4tmp
[0] & 0xff, ((u4tmp
[0] & 0x30000000) >> 28));
3786 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x40);
3787 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
3788 u4tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x974);
3789 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
3790 "0x40/ 0x4c[24:23]/ 0x974",
3791 u1tmp
[0], ((u4tmp
[0] & 0x01800000) >> 23), u4tmp
[1]);
3793 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x550);
3794 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x522);
3795 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x",
3796 "0x550(bcn ctrl)/0x522",
3797 u4tmp
[0], u1tmp
[0]);
3799 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xc50);
3800 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0xa0a);
3801 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x",
3802 "0xc50(DIG)/0xa0a(CCK-TH)",
3803 u4tmp
[0], u1tmp
[0]);
3805 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xf48);
3806 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5b);
3807 u1tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5c);
3808 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x",
3810 u4tmp
[0], (u1tmp
[0] << 8) + u1tmp
[1]);
3812 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c0);
3813 u4tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c4);
3814 u4tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c8);
3815 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
3816 "0x6c0/0x6c4/0x6c8",
3817 u4tmp
[0], u4tmp
[1], u4tmp
[2]);
3819 seq_printf(m
, "\n %-35s = %d/ %d",
3820 "0x770 (hi-pri Rx/Tx)",
3821 coex_sta
->high_priority_rx
, coex_sta
->high_priority_tx
);
3822 seq_printf(m
, "\n %-35s = %d/ %d",
3823 "0x774(low-pri Rx/Tx)",
3824 coex_sta
->low_priority_rx
, coex_sta
->low_priority_tx
);
3826 /* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang*/
3827 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x41b);
3828 seq_printf(m
, "\n %-35s = 0x%x",
3829 "0x41b (mgntQ hang chk == 0xf)",
3832 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_COEX_STATISTICS
, m
);
3835 void ex_btc8821a2ant_ips_notify(struct btc_coexist
*btcoexist
, u8 type
)
3837 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3839 if (BTC_IPS_ENTER
== type
) {
3840 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3841 "[BTCoex], IPS ENTER notify\n");
3842 coex_sta
->under_ips
= true;
3843 btc8821a2ant_wifi_off_hw_cfg(btcoexist
);
3844 btc8821a2ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
3845 btc8821a2ant_coex_all_off(btcoexist
);
3846 } else if (BTC_IPS_LEAVE
== type
) {
3847 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3848 "[BTCoex], IPS LEAVE notify\n");
3849 coex_sta
->under_ips
= false;
3850 ex_btc8821a2ant_init_hwconfig(btcoexist
);
3851 btc8821a2ant_init_coex_dm(btcoexist
);
3852 btc8821a2ant_query_bt_info(btcoexist
);
3856 void ex_btc8821a2ant_lps_notify(struct btc_coexist
*btcoexist
, u8 type
)
3858 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3860 if (BTC_LPS_ENABLE
== type
) {
3861 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3862 "[BTCoex], LPS ENABLE notify\n");
3863 coex_sta
->under_lps
= true;
3864 } else if (BTC_LPS_DISABLE
== type
) {
3865 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3866 "[BTCoex], LPS DISABLE notify\n");
3867 coex_sta
->under_lps
= false;
3871 void ex_btc8821a2ant_scan_notify(struct btc_coexist
*btcoexist
, u8 type
)
3873 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3875 if (BTC_SCAN_START
== type
) {
3876 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3877 "[BTCoex], SCAN START notify\n");
3878 } else if (BTC_SCAN_FINISH
== type
) {
3879 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3880 "[BTCoex], SCAN FINISH notify\n");
3884 void ex_btc8821a2ant_connect_notify(struct btc_coexist
*btcoexist
, u8 type
)
3886 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3888 if (BTC_ASSOCIATE_START
== type
) {
3889 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3890 "[BTCoex], CONNECT START notify\n");
3891 } else if (BTC_ASSOCIATE_FINISH
== type
) {
3892 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3893 "[BTCoex], CONNECT FINISH notify\n");
3897 void ex_btc8821a2ant_media_status_notify(struct btc_coexist
*btcoexist
,
3900 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3901 u8 h2c_parameter
[3] = {0};
3903 u8 wifi_central_chnl
;
3906 if (BTC_MEDIA_CONNECT
== type
) {
3907 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3908 "[BTCoex], MEDIA connect notify\n");
3910 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3911 "[BTCoex], MEDIA disconnect notify\n");
3914 /* only 2.4G we need to inform bt the chnl mask */
3915 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_CENTRAL_CHNL
,
3916 &wifi_central_chnl
);
3917 if ((BTC_MEDIA_CONNECT
== type
) &&
3918 (wifi_central_chnl
<= 14)) {
3919 h2c_parameter
[0] = 0x1;
3920 h2c_parameter
[1] = wifi_central_chnl
;
3921 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
3922 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
3923 h2c_parameter
[2] = 0x30;
3925 h2c_parameter
[2] = 0x20;
3927 h2c_parameter
[2] = 0x30;
3929 h2c_parameter
[2] = 0x20;
3933 coex_dm
->wifi_chnl_info
[0] = h2c_parameter
[0];
3934 coex_dm
->wifi_chnl_info
[1] = h2c_parameter
[1];
3935 coex_dm
->wifi_chnl_info
[2] = h2c_parameter
[2];
3937 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3938 "[BTCoex], FW write 0x66 = 0x%x\n",
3939 h2c_parameter
[0] << 16 |
3940 h2c_parameter
[1] << 8 |
3943 btcoexist
->btc_fill_h2c(btcoexist
, 0x66, 3, h2c_parameter
);
3946 void ex_btc8821a2ant_special_packet_notify(struct btc_coexist
*btcoexist
,
3949 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3951 if (type
== BTC_PACKET_DHCP
) {
3952 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3953 "[BTCoex], DHCP Packet notify\n");
3957 void ex_btc8821a2ant_bt_info_notify(struct btc_coexist
*btcoexist
,
3958 u8
*tmp_buf
, u8 length
)
3960 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
3962 u8 i
, rsp_source
= 0;
3963 bool bt_busy
= false, limited_dig
= false;
3964 bool wifi_connected
= false, wifi_under_5g
= false;
3966 coex_sta
->c2h_bt_info_req_sent
= false;
3967 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
3968 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
3971 rsp_source
= tmp_buf
[0] & 0xf;
3972 if (rsp_source
>= BT_INFO_SRC_8821A_2ANT_MAX
)
3973 rsp_source
= BT_INFO_SRC_8821A_2ANT_WIFI_FW
;
3974 coex_sta
->bt_info_c2h_cnt
[rsp_source
]++;
3976 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3977 "[BTCoex], Bt info[%d], length = %d, hex data = [",
3978 rsp_source
, length
);
3979 for (i
= 0; i
< length
; i
++) {
3980 coex_sta
->bt_info_c2h
[rsp_source
][i
] = tmp_buf
[i
];
3982 bt_info
= tmp_buf
[i
];
3983 if (i
== length
- 1) {
3984 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3985 "0x%02x]\n", tmp_buf
[i
]);
3987 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3988 "0x%02x, ", tmp_buf
[i
]);
3992 if (btcoexist
->manual_control
) {
3993 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
3994 "[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n");
3998 if (BT_INFO_SRC_8821A_2ANT_WIFI_FW
!= rsp_source
) {
4000 coex_sta
->bt_retry_cnt
=
4001 coex_sta
->bt_info_c2h
[rsp_source
][2]&0xf;
4004 coex_sta
->bt_info_c2h
[rsp_source
][3] * 2 + 10;
4006 coex_sta
->bt_info_ext
= coex_sta
->bt_info_c2h
[rsp_source
][4];
4008 coex_sta
->bt_tx_rx_mask
=
4009 (coex_sta
->bt_info_c2h
[rsp_source
][2] & 0x40);
4010 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TX_RX_MASK
,
4011 &coex_sta
->bt_tx_rx_mask
);
4012 if (coex_sta
->bt_tx_rx_mask
) {
4013 /* BT into is responded by BT FW and BT RF REG 0x3C !=
4014 * 0x01 => Need to switch BT TRx Mask
4016 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4017 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n");
4018 btcoexist
->btc_set_bt_reg(btcoexist
, BTC_BT_REG_RF
,
4022 /* Here we need to resend some wifi info to BT
4023 * because bt is reset and loss of the info
4025 if ((coex_sta
->bt_info_ext
& BIT1
)) {
4026 btcoexist
->btc_get(btcoexist
,
4027 BTC_GET_BL_WIFI_CONNECTED
, &wifi_connected
);
4028 if (wifi_connected
) {
4029 ex_btc8821a2ant_media_status_notify(btcoexist
,
4032 ex_btc8821a2ant_media_status_notify(btcoexist
,
4033 BTC_MEDIA_DISCONNECT
);
4038 if (!btcoexist
->manual_control
&& !wifi_under_5g
) {
4039 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4040 "[BTCoex], BT ext info = 0x%x!!\n",
4041 coex_sta
->bt_info_ext
);
4042 if ((coex_sta
->bt_info_ext
& BIT(3))) {
4043 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4044 "[BTCoex], BT ext info bit3=1, wifi_connected=%d\n",
4046 if (wifi_connected
) {
4047 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
4049 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
4050 btc8821a2ant_ignore_wlan_act(btcoexist
,
4055 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4056 "[BTCoex], BT ext info bit3=0, wifi_connected=%d\n",
4058 /* BT already NOT ignore Wlan active, do nothing
4061 if (!wifi_connected
) {
4062 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
,
4064 "[BTCoex], BT ext info bit3 check, set BT to ignore Wlan active!!\n");
4065 btc8821a2ant_ignore_wlan_act(
4066 btcoexist
, FORCE_EXEC
, true);
4072 /* check BIT2 first ==> check if bt is under inquiry or page scan*/
4073 if (bt_info
& BT_INFO_8821A_2ANT_B_INQ_PAGE
) {
4074 coex_sta
->c2h_bt_inquiry_page
= true;
4076 coex_sta
->c2h_bt_inquiry_page
= false;
4078 /* set link exist status */
4079 if (!(bt_info
& BT_INFO_8821A_2ANT_B_CONNECTION
)) {
4080 coex_sta
->bt_link_exist
= false;
4081 coex_sta
->pan_exist
= false;
4082 coex_sta
->a2dp_exist
= false;
4083 coex_sta
->hid_exist
= false;
4084 coex_sta
->sco_exist
= false;
4085 } else { /* connection exists */
4086 coex_sta
->bt_link_exist
= true;
4087 if (bt_info
& BT_INFO_8821A_2ANT_B_FTP
)
4088 coex_sta
->pan_exist
= true;
4090 coex_sta
->pan_exist
= false;
4091 if (bt_info
& BT_INFO_8821A_2ANT_B_A2DP
)
4092 coex_sta
->a2dp_exist
= true;
4094 coex_sta
->a2dp_exist
= false;
4095 if (bt_info
& BT_INFO_8821A_2ANT_B_HID
)
4096 coex_sta
->hid_exist
= true;
4098 coex_sta
->hid_exist
= false;
4099 if (bt_info
& BT_INFO_8821A_2ANT_B_SCO_ESCO
)
4100 coex_sta
->sco_exist
= true;
4102 coex_sta
->sco_exist
= false;
4104 if ((!coex_sta
->hid_exist
) &&
4105 (!coex_sta
->c2h_bt_inquiry_page
) &&
4106 (!coex_sta
->sco_exist
)) {
4107 if (coex_sta
->high_priority_tx
+
4108 coex_sta
->high_priority_rx
>= 160)
4109 coex_sta
->hid_exist
= true;
4113 btc8821a2ant_update_bt_link_info(btcoexist
);
4115 if (!(bt_info
& BT_INFO_8821A_2ANT_B_CONNECTION
)) {
4116 coex_dm
->bt_status
= BT_8821A_2ANT_BT_STATUS_IDLE
;
4117 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4118 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
4119 } else if (bt_info
== BT_INFO_8821A_2ANT_B_CONNECTION
) {
4120 /* connection exists but no busy */
4121 coex_dm
->bt_status
= BT_8821A_2ANT_BT_STATUS_CON_IDLE
;
4122 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4123 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
4124 } else if ((bt_info
& BT_INFO_8821A_2ANT_B_SCO_ESCO
) ||
4125 (bt_info
& BT_INFO_8821A_2ANT_B_SCO_BUSY
)) {
4126 coex_dm
->bt_status
= BT_8821A_2ANT_BT_STATUS_SCO_BUSY
;
4127 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4128 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
4129 } else if (bt_info
& BT_INFO_8821A_2ANT_B_ACL_BUSY
) {
4130 coex_dm
->bt_status
= BT_8821A_2ANT_BT_STATUS_ACL_BUSY
;
4131 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4132 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
4134 coex_dm
->bt_status
= BT_8821A_2ANT_BT_STATUS_MAX
;
4135 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4136 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
4139 if ((coex_dm
->bt_status
== BT_8821A_2ANT_BT_STATUS_ACL_BUSY
) ||
4140 (coex_dm
->bt_status
== BT_8821A_2ANT_BT_STATUS_SCO_BUSY
) ||
4141 (coex_dm
->bt_status
== BT_8821A_2ANT_BT_STATUS_ACL_SCO_BUSY
)) {
4146 limited_dig
= false;
4149 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TRAFFIC_BUSY
, &bt_busy
);
4151 coex_dm
->limited_dig
= limited_dig
;
4152 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_LIMITED_DIG
, &limited_dig
);
4154 btc8821a2ant_run_coexist_mechanism(btcoexist
);
4157 void ex_btc8821a2ant_halt_notify(struct btc_coexist
*btcoexist
)
4159 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
4161 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4162 "[BTCoex], Halt notify\n");
4164 btc8821a2ant_wifi_off_hw_cfg(btcoexist
);
4165 btc8821a2ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
4166 ex_btc8821a2ant_media_status_notify(btcoexist
, BTC_MEDIA_DISCONNECT
);
4169 void ex_btc8821a2ant_pnp_notify(struct btc_coexist
*btcoexist
, u8 pnp_state
)
4171 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
4173 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
, "[BTCoex], Pnp notify\n");
4175 if (pnp_state
== BTC_WIFI_PNP_SLEEP
) {
4176 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4177 "[BTCoex], Pnp notify to SLEEP\n");
4178 } else if (pnp_state
== BTC_WIFI_PNP_WAKE_UP
) {
4179 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4180 "[BTCoex], Pnp notify to WAKE UP\n");
4181 ex_btc8821a2ant_init_hwconfig(btcoexist
);
4182 btc8821a2ant_init_coex_dm(btcoexist
);
4183 btc8821a2ant_query_bt_info(btcoexist
);
4187 void ex_btc8821a2ant_periodical(struct btc_coexist
*btcoexist
)
4189 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
4191 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4192 "[BTCoex], ==========================Periodical===========================\n");
4194 if (coex_sta
->dis_ver_info_cnt
<= 5) {
4195 coex_sta
->dis_ver_info_cnt
+= 1;
4196 if (coex_sta
->dis_ver_info_cnt
== 3) {
4197 /* Antenna config to set 0x765 = 0x0 (GNT_BT control by
4198 * PTA) after initial
4200 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
4201 "[BTCoex], Set GNT_BT control by PTA\n");
4202 btc8821a2ant_set_ant_path(btcoexist
,
4203 BTC_ANT_WIFI_AT_MAIN
, false, false);
4207 if (btcoexist
->auto_report_2ant
) {
4208 btc8821a2ant_query_bt_info(btcoexist
);
4210 btc8821a2ant_monitor_bt_ctr(btcoexist
);
4211 btc8821a2ant_monitor_wifi_ctr(btcoexist
);
4213 if (btc8821a2ant_is_wifi_status_changed(btcoexist
) ||
4214 coex_dm
->auto_tdma_adjust
)
4215 btc8821a2ant_run_coexist_mechanism(btcoexist
);