1 /******************************************************************************
3 * Copyright(c) 2012 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
26 /************************************************************
29 * This file is for RTL8821A Co-exist mechanism
32 * 2012/08/22 Cosa first check in.
33 * 2012/11/14 Cosa Revise for 8821A 2Ant out sourcing.
35 ************************************************************/
37 /************************************************************
39 ************************************************************/
40 #include "halbt_precomp.h"
41 /************************************************************
42 * Global variables, these are static variables
43 ************************************************************/
44 static struct coex_dm_8821a_2ant glcoex_dm_8821a_2ant
;
45 static struct coex_dm_8821a_2ant
*coex_dm
= &glcoex_dm_8821a_2ant
;
46 static struct coex_sta_8821a_2ant glcoex_sta_8821a_2ant
;
47 static struct coex_sta_8821a_2ant
*coex_sta
= &glcoex_sta_8821a_2ant
;
49 static const char *const glbt_info_src_8821a_2ant
[] = {
52 "BT Info[bt auto report]",
55 static u32 glcoex_ver_date_8821a_2ant
= 20130618;
56 static u32 glcoex_ver_8821a_2ant
= 0x5050;
58 /************************************************************
59 * local function proto type if needed
61 * local function start with btc8821a2ant_
62 ************************************************************/
63 static u8
btc8821a2ant_bt_rssi_state(struct btc_coexist
*btcoexist
,
64 u8 level_num
, u8 rssi_thresh
,
67 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
69 u8 bt_rssi_state
= coex_sta
->pre_bt_rssi_state
;
71 bt_rssi
= coex_sta
->bt_rssi
;
74 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
75 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
77 rssi_thresh
+ BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
) {
78 bt_rssi_state
= BTC_RSSI_STATE_HIGH
;
79 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
80 "[BTCoex], BT Rssi state switch to High\n");
82 bt_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
83 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
84 "[BTCoex], BT Rssi state stay at Low\n");
87 if (bt_rssi
< rssi_thresh
) {
88 bt_rssi_state
= BTC_RSSI_STATE_LOW
;
89 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
90 "[BTCoex], BT Rssi state switch to Low\n");
92 bt_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
93 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
94 "[BTCoex], BT Rssi state stay at High\n");
97 } else if (level_num
== 3) {
98 if (rssi_thresh
> rssi_thresh1
) {
99 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
100 "[BTCoex], BT Rssi thresh error!!\n");
101 return coex_sta
->pre_bt_rssi_state
;
104 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
105 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
108 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
)) {
109 bt_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
110 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
111 "[BTCoex], BT Rssi state switch to Medium\n");
113 bt_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
114 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
115 "[BTCoex], BT Rssi state stay at Low\n");
117 } else if ((coex_sta
->pre_bt_rssi_state
==
118 BTC_RSSI_STATE_MEDIUM
) ||
119 (coex_sta
->pre_bt_rssi_state
==
120 BTC_RSSI_STATE_STAY_MEDIUM
)) {
123 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
)) {
124 bt_rssi_state
= BTC_RSSI_STATE_HIGH
;
125 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
126 "[BTCoex], BT Rssi state switch to High\n");
127 } else if (bt_rssi
< rssi_thresh
) {
128 bt_rssi_state
= BTC_RSSI_STATE_LOW
;
129 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
130 "[BTCoex], BT Rssi state switch to Low\n");
132 bt_rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
133 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
134 "[BTCoex], BT Rssi state stay at Medium\n");
137 if (bt_rssi
< rssi_thresh1
) {
138 bt_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
139 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
140 "[BTCoex], BT Rssi state switch to Medium\n");
142 bt_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
143 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
144 "[BTCoex], BT Rssi state stay at High\n");
149 coex_sta
->pre_bt_rssi_state
= bt_rssi_state
;
151 return bt_rssi_state
;
154 static u8
btc8821a2ant_wifi_rssi_state(struct btc_coexist
*btcoexist
,
155 u8 index
, u8 level_num
,
156 u8 rssi_thresh
, u8 rssi_thresh1
)
158 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
160 u8 wifi_rssi_state
= coex_sta
->pre_wifi_rssi_state
[index
];
162 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
164 if (level_num
== 2) {
165 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
166 BTC_RSSI_STATE_LOW
) ||
167 (coex_sta
->pre_wifi_rssi_state
[index
] ==
168 BTC_RSSI_STATE_STAY_LOW
)) {
170 (rssi_thresh
+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
)) {
171 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
172 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
173 "[BTCoex], wifi RSSI state switch to High\n");
175 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
176 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
177 "[BTCoex], wifi RSSI state stay at Low\n");
180 if (wifi_rssi
< rssi_thresh
) {
181 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
182 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
183 "[BTCoex], wifi RSSI state switch to Low\n");
185 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
186 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
187 "[BTCoex], wifi RSSI state stay at High\n");
190 } else if (level_num
== 3) {
191 if (rssi_thresh
> rssi_thresh1
) {
192 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
193 "[BTCoex], wifi RSSI thresh error!!\n");
194 return coex_sta
->pre_wifi_rssi_state
[index
];
197 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
198 BTC_RSSI_STATE_LOW
) ||
199 (coex_sta
->pre_wifi_rssi_state
[index
] ==
200 BTC_RSSI_STATE_STAY_LOW
)) {
203 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
)) {
204 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
205 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
206 "[BTCoex], wifi RSSI state switch to Medium\n");
208 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
209 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
210 "[BTCoex], wifi RSSI state stay at Low\n");
212 } else if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
213 BTC_RSSI_STATE_MEDIUM
) ||
214 (coex_sta
->pre_wifi_rssi_state
[index
] ==
215 BTC_RSSI_STATE_STAY_MEDIUM
)) {
216 if (wifi_rssi
>= (rssi_thresh1
+
217 BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT
)) {
218 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
219 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
220 "[BTCoex], wifi RSSI state switch to High\n");
221 } else if (wifi_rssi
< rssi_thresh
) {
222 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
223 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
224 "[BTCoex], wifi RSSI state switch to Low\n");
226 wifi_rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
227 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
228 "[BTCoex], wifi RSSI state stay at Medium\n");
231 if (wifi_rssi
< rssi_thresh1
) {
232 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
233 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
234 "[BTCoex], wifi RSSI state switch to Medium\n");
236 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
237 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
238 "[BTCoex], wifi RSSI state stay at High\n");
242 coex_sta
->pre_wifi_rssi_state
[index
] = wifi_rssi_state
;
244 return wifi_rssi_state
;
248 void btc8821a2ant_limited_rx(struct btc_coexist
*btcoexist
, bool force_exec
,
249 bool rej_ap_agg_pkt
, bool bt_ctrl_agg_buf_size
,
252 bool reject_rx_agg
= rej_ap_agg_pkt
;
253 bool bt_ctrl_rx_agg_size
= bt_ctrl_agg_buf_size
;
254 u8 rx_agg_size
= agg_buf_size
;
256 /* Rx Aggregation related setting */
257 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_TO_REJ_AP_AGG_PKT
,
259 /* decide BT control aggregation buf size or not */
260 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_CTRL_AGG_SIZE
,
261 &bt_ctrl_rx_agg_size
);
262 /* aggregation buf size, works when BT control Rx aggregation size */
263 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_AGG_BUF_SIZE
, &rx_agg_size
);
264 /* real update aggregation setting */
265 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_AGGREGATE_CTRL
, NULL
);
268 static void btc8821a2ant_monitor_bt_ctr(struct btc_coexist
*btcoexist
)
270 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
271 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
272 u32 reg_hp_txrx
, reg_lp_txrx
, u4tmp
;
273 u32 reg_hp_tx
= 0, reg_hp_rx
= 0, reg_lp_tx
= 0, reg_lp_rx
= 0;
278 u4tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_hp_txrx
);
279 reg_hp_tx
= u4tmp
& MASKLWORD
;
280 reg_hp_rx
= (u4tmp
& MASKHWORD
) >> 16;
282 u4tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_lp_txrx
);
283 reg_lp_tx
= u4tmp
& MASKLWORD
;
284 reg_lp_rx
= (u4tmp
& MASKHWORD
) >> 16;
286 coex_sta
->high_priority_tx
= reg_hp_tx
;
287 coex_sta
->high_priority_rx
= reg_hp_rx
;
288 coex_sta
->low_priority_tx
= reg_lp_tx
;
289 coex_sta
->low_priority_rx
= reg_lp_rx
;
291 if ((coex_sta
->low_priority_rx
>= 950) &&
292 (coex_sta
->low_priority_rx
>= coex_sta
->low_priority_tx
) &&
293 (!coex_sta
->under_ips
))
294 bt_link_info
->slave_role
= true;
296 bt_link_info
->slave_role
= false;
298 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
299 "[BTCoex], High Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
300 reg_hp_txrx
, reg_hp_tx
, reg_hp_tx
, reg_hp_rx
, reg_hp_rx
);
301 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
302 "[BTCoex], Low Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
303 reg_lp_txrx
, reg_lp_tx
, reg_lp_tx
, reg_lp_rx
, reg_lp_rx
);
306 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
309 static void btc8821a2ant_monitor_wifi_ctr(struct btc_coexist
*btcoexist
)
311 if (coex_sta
->under_ips
) {
312 coex_sta
->crc_ok_cck
= 0;
313 coex_sta
->crc_ok_11g
= 0;
314 coex_sta
->crc_ok_11n
= 0;
315 coex_sta
->crc_ok_11n_agg
= 0;
317 coex_sta
->crc_err_cck
= 0;
318 coex_sta
->crc_err_11g
= 0;
319 coex_sta
->crc_err_11n
= 0;
320 coex_sta
->crc_err_11n_agg
= 0;
322 coex_sta
->crc_ok_cck
=
323 btcoexist
->btc_read_4byte(btcoexist
, 0xf88);
324 coex_sta
->crc_ok_11g
=
325 btcoexist
->btc_read_2byte(btcoexist
, 0xf94);
326 coex_sta
->crc_ok_11n
=
327 btcoexist
->btc_read_2byte(btcoexist
, 0xf90);
328 coex_sta
->crc_ok_11n_agg
=
329 btcoexist
->btc_read_2byte(btcoexist
, 0xfb8);
331 coex_sta
->crc_err_cck
=
332 btcoexist
->btc_read_4byte(btcoexist
, 0xf84);
333 coex_sta
->crc_err_11g
=
334 btcoexist
->btc_read_2byte(btcoexist
, 0xf96);
335 coex_sta
->crc_err_11n
=
336 btcoexist
->btc_read_2byte(btcoexist
, 0xf92);
337 coex_sta
->crc_err_11n_agg
=
338 btcoexist
->btc_read_2byte(btcoexist
, 0xfba);
342 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xf16, 0x1, 0x1);
343 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xf16, 0x1, 0x0);
346 static void btc8821a2ant_query_bt_info(struct btc_coexist
*btcoexist
)
348 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
349 u8 h2c_parameter
[1] = {0};
351 coex_sta
->c2h_bt_info_req_sent
= true;
353 h2c_parameter
[0] |= BIT0
; /* trigger */
355 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
356 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
359 btcoexist
->btc_fill_h2c(btcoexist
, 0x61, 1, h2c_parameter
);
362 static u8
btc8821a2ant_action_algorithm(struct btc_coexist
*btcoexist
)
364 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
365 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
366 bool bt_hs_on
= false;
367 u8 algorithm
= BT_8821A_2ANT_COEX_ALGO_UNDEFINED
;
368 u8 num_of_diff_profile
= 0;
370 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
372 /* sync BTInfo with BT firmware and stack */
373 if (!stack_info
->hid_exist
)
374 stack_info
->hid_exist
= coex_sta
->hid_exist
;
375 /* when stack HID report error, here we use the info from bt fw. */
376 if (!stack_info
->bt_link_exist
)
377 stack_info
->bt_link_exist
= coex_sta
->bt_link_exist
;
379 if (!coex_sta
->bt_link_exist
) {
380 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
381 "[BTCoex], No profile exists!!!\n");
385 if (coex_sta
->sco_exist
)
386 num_of_diff_profile
++;
387 if (coex_sta
->hid_exist
)
388 num_of_diff_profile
++;
389 if (coex_sta
->pan_exist
)
390 num_of_diff_profile
++;
391 if (coex_sta
->a2dp_exist
)
392 num_of_diff_profile
++;
394 if (num_of_diff_profile
== 1) {
395 if (coex_sta
->sco_exist
) {
396 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
397 "[BTCoex], SCO only\n");
398 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
400 if (coex_sta
->hid_exist
) {
401 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
402 "[BTCoex], HID only\n");
403 algorithm
= BT_8821A_2ANT_COEX_ALGO_HID
;
404 } else if (coex_sta
->a2dp_exist
) {
405 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
406 "[BTCoex], A2DP only\n");
407 algorithm
= BT_8821A_2ANT_COEX_ALGO_A2DP
;
408 } else if (coex_sta
->pan_exist
) {
410 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
412 "[BTCoex], PAN(HS) only\n");
413 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANHS
;
415 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
417 "[BTCoex], PAN(EDR) only\n");
418 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR
;
422 } else if (num_of_diff_profile
== 2) {
423 if (coex_sta
->sco_exist
) {
424 if (coex_sta
->hid_exist
) {
425 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
426 "[BTCoex], SCO + HID\n");
427 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
;
428 } else if (coex_sta
->a2dp_exist
) {
429 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
430 "[BTCoex], SCO + A2DP ==> SCO\n");
431 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
;
432 } else if (coex_sta
->pan_exist
) {
434 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
436 "[BTCoex], SCO + PAN(HS)\n");
437 algorithm
= BT_8821A_2ANT_COEX_ALGO_SCO
;
439 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
441 "[BTCoex], SCO + PAN(EDR)\n");
442 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
;
446 if (coex_sta
->hid_exist
&&
447 coex_sta
->a2dp_exist
) {
448 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
449 "[BTCoex], HID + A2DP\n");
450 algorithm
= BT_8821A_2ANT_COEX_ALGO_HID_A2DP
;
451 } else if (coex_sta
->hid_exist
&&
452 coex_sta
->pan_exist
) {
454 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
456 "[BTCoex], HID + PAN(HS)\n");
457 algorithm
= BT_8821A_2ANT_COEX_ALGO_HID
;
459 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
461 "[BTCoex], HID + PAN(EDR)\n");
462 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
;
464 } else if (coex_sta
->pan_exist
&&
465 coex_sta
->a2dp_exist
) {
467 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
469 "[BTCoex], A2DP + PAN(HS)\n");
470 algorithm
= BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS
;
472 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
474 "[BTCoex], A2DP + PAN(EDR)\n");
475 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP
;
479 } else if (num_of_diff_profile
== 3) {
480 if (coex_sta
->sco_exist
) {
481 if (coex_sta
->hid_exist
&&
482 coex_sta
->a2dp_exist
) {
483 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
484 "[BTCoex], SCO + HID + A2DP ==> HID\n");
485 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
;
486 } else if (coex_sta
->hid_exist
&&
487 coex_sta
->pan_exist
) {
489 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
491 "[BTCoex], SCO + HID + PAN(HS)\n");
492 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
;
494 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
496 "[BTCoex], SCO + HID + PAN(EDR)\n");
497 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
;
499 } else if (coex_sta
->pan_exist
&&
500 coex_sta
->a2dp_exist
) {
502 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
504 "[BTCoex], SCO + A2DP + PAN(HS)\n");
505 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
;
507 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
509 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
510 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
;
514 if (coex_sta
->hid_exist
&&
515 coex_sta
->pan_exist
&&
516 coex_sta
->a2dp_exist
) {
518 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
520 "[BTCoex], HID + A2DP + PAN(HS)\n");
521 algorithm
= BT_8821A_2ANT_COEX_ALGO_HID_A2DP
;
523 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
525 "[BTCoex], HID + A2DP + PAN(EDR)\n");
526 algorithm
= BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR
;
530 } else if (num_of_diff_profile
>= 3) {
531 if (coex_sta
->sco_exist
) {
532 if (coex_sta
->hid_exist
&&
533 coex_sta
->pan_exist
&&
534 coex_sta
->a2dp_exist
) {
536 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
538 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
541 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
543 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
544 algorithm
= BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
;
552 static void btc8821a2ant_set_fw_dac_swing_lvl(struct btc_coexist
*btcoexist
,
555 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
556 u8 h2c_parameter
[1] = {0};
558 /* There are several type of dacswing
559 * 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6
561 h2c_parameter
[0] = dac_swing_lvl
;
563 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
564 "[BTCoex], Set Dac Swing Level = 0x%x\n", dac_swing_lvl
);
565 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
566 "[BTCoex], FW write 0x64 = 0x%x\n", h2c_parameter
[0]);
568 btcoexist
->btc_fill_h2c(btcoexist
, 0x64, 1, h2c_parameter
);
571 static void btc8821a2ant_set_fw_dec_bt_pwr(struct btc_coexist
*btcoexist
,
574 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
575 u8 h2c_parameter
[1] = {0};
577 h2c_parameter
[0] = 0;
580 h2c_parameter
[0] |= BIT1
;
582 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
583 "[BTCoex], decrease Bt Power : %s, FW write 0x62 = 0x%x\n",
584 (dec_bt_pwr
? "Yes!!" : "No!!"), h2c_parameter
[0]);
586 btcoexist
->btc_fill_h2c(btcoexist
, 0x62, 1, h2c_parameter
);
589 static void btc8821a2ant_dec_bt_pwr(struct btc_coexist
*btcoexist
,
590 bool force_exec
, bool dec_bt_pwr
)
592 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
594 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
595 "[BTCoex], %s Dec BT power = %s\n",
596 (force_exec
? "force to" : ""),
597 ((dec_bt_pwr
) ? "ON" : "OFF"));
598 coex_dm
->cur_dec_bt_pwr
= dec_bt_pwr
;
601 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
602 "[BTCoex], pre_dec_bt_pwr = %d, cur_dec_bt_pwr = %d\n",
603 coex_dm
->pre_dec_bt_pwr
, coex_dm
->cur_dec_bt_pwr
);
605 if (coex_dm
->pre_dec_bt_pwr
== coex_dm
->cur_dec_bt_pwr
)
608 btc8821a2ant_set_fw_dec_bt_pwr(btcoexist
, coex_dm
->cur_dec_bt_pwr
);
610 coex_dm
->pre_dec_bt_pwr
= coex_dm
->cur_dec_bt_pwr
;
613 static void btc8821a2ant_fw_dac_swing_lvl(struct btc_coexist
*btcoexist
,
614 bool force_exec
, u8 fw_dac_swing_lvl
)
616 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
618 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
619 "[BTCoex], %s set FW Dac Swing level = %d\n",
620 (force_exec
? "force to" : ""), fw_dac_swing_lvl
);
621 coex_dm
->cur_fw_dac_swing_lvl
= fw_dac_swing_lvl
;
624 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
625 "[BTCoex], pre_fw_dac_swing_lvl = %d, cur_fw_dac_swing_lvl = %d\n",
626 coex_dm
->pre_fw_dac_swing_lvl
,
627 coex_dm
->cur_fw_dac_swing_lvl
);
629 if (coex_dm
->pre_fw_dac_swing_lvl
==
630 coex_dm
->cur_fw_dac_swing_lvl
)
634 btc8821a2ant_set_fw_dac_swing_lvl(btcoexist
,
635 coex_dm
->cur_fw_dac_swing_lvl
);
637 coex_dm
->pre_fw_dac_swing_lvl
= coex_dm
->cur_fw_dac_swing_lvl
;
640 static void btc8821a2ant_set_sw_penalty_tx_rate_adaptive(
641 struct btc_coexist
*btcoexist
, bool low_penalty_ra
)
643 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
644 u8 h2c_parameter
[6] = {0};
646 h2c_parameter
[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */
648 if (low_penalty_ra
) {
649 h2c_parameter
[1] |= BIT0
;
650 /* normal rate except MCS7/6/5, OFDM54/48/36 */
651 h2c_parameter
[2] = 0x00;
653 h2c_parameter
[3] = 0xf7;
655 h2c_parameter
[4] = 0xf8;
657 h2c_parameter
[5] = 0xf9;
660 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
661 "[BTCoex], set WiFi Low-Penalty Retry: %s",
662 (low_penalty_ra
? "ON!!" : "OFF!!"));
664 btcoexist
->btc_fill_h2c(btcoexist
, 0x69, 6, h2c_parameter
);
667 static void btc8821a2ant_low_penalty_ra(struct btc_coexist
*btcoexist
,
668 bool force_exec
, bool low_penalty_ra
)
670 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
672 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
673 "[BTCoex], %s turn LowPenaltyRA = %s\n",
674 (force_exec
? "force to" : ""),
675 ((low_penalty_ra
) ? "ON" : "OFF"));
676 coex_dm
->cur_low_penalty_ra
= low_penalty_ra
;
679 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
680 "[BTCoex], pre_low_penalty_ra = %d, cur_low_penalty_ra = %d\n",
681 coex_dm
->pre_low_penalty_ra
,
682 coex_dm
->cur_low_penalty_ra
);
684 if (coex_dm
->pre_low_penalty_ra
== coex_dm
->cur_low_penalty_ra
)
687 btc8821a2ant_set_sw_penalty_tx_rate_adaptive(btcoexist
,
688 coex_dm
->cur_low_penalty_ra
);
690 coex_dm
->pre_low_penalty_ra
= coex_dm
->cur_low_penalty_ra
;
693 static void btc8821a2ant_set_dac_swing_reg(struct btc_coexist
*btcoexist
,
696 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
699 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
700 "[BTCoex], Write SwDacSwing = 0x%x\n", level
);
701 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xc5b, 0x3e, val
);
704 static void btc8821a2ant_set_sw_full_dac_swing(struct btc_coexist
*btcoexist
,
705 bool sw_dac_swing_on
,
706 u32 sw_dac_swing_lvl
)
709 btc8821a2ant_set_dac_swing_reg(btcoexist
, sw_dac_swing_lvl
);
711 btc8821a2ant_set_dac_swing_reg(btcoexist
, 0x18);
714 static void btc8821a2ant_dac_swing(struct btc_coexist
*btcoexist
,
715 bool force_exec
, bool dac_swing_on
,
718 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
720 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
721 "[BTCoex], %s turn DacSwing = %s, dac_swing_lvl = 0x%x\n",
722 (force_exec
? "force to" : ""),
723 ((dac_swing_on
) ? "ON" : "OFF"),
725 coex_dm
->cur_dac_swing_on
= dac_swing_on
;
726 coex_dm
->cur_dac_swing_lvl
= dac_swing_lvl
;
729 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
730 "[BTCoex], pre_dac_swing_on = %d, pre_dac_swing_lvl = 0x%x, cur_dac_swing_on = %d, cur_dac_swing_lvl = 0x%x\n",
731 coex_dm
->pre_dac_swing_on
,
732 coex_dm
->pre_dac_swing_lvl
,
733 coex_dm
->cur_dac_swing_on
,
734 coex_dm
->cur_dac_swing_lvl
);
736 if ((coex_dm
->pre_dac_swing_on
== coex_dm
->cur_dac_swing_on
) &&
737 (coex_dm
->pre_dac_swing_lvl
==
738 coex_dm
->cur_dac_swing_lvl
))
742 btc8821a2ant_set_sw_full_dac_swing(btcoexist
, dac_swing_on
,
745 coex_dm
->pre_dac_swing_on
= coex_dm
->cur_dac_swing_on
;
746 coex_dm
->pre_dac_swing_lvl
= coex_dm
->cur_dac_swing_lvl
;
749 static void btc8821a2ant_set_coex_table(struct btc_coexist
*btcoexist
,
750 u32 val0x6c0
, u32 val0x6c4
,
751 u32 val0x6c8
, u8 val0x6cc
)
753 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
755 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
756 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0
);
757 btcoexist
->btc_write_4byte(btcoexist
, 0x6c0, val0x6c0
);
759 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
760 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4
);
761 btcoexist
->btc_write_4byte(btcoexist
, 0x6c4, val0x6c4
);
763 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
764 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8
);
765 btcoexist
->btc_write_4byte(btcoexist
, 0x6c8, val0x6c8
);
767 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
768 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc
);
769 btcoexist
->btc_write_1byte(btcoexist
, 0x6cc, val0x6cc
);
772 static void btc8821a2ant_coex_table(struct btc_coexist
*btcoexist
,
773 bool force_exec
, u32 val0x6c0
,
774 u32 val0x6c4
, u32 val0x6c8
, u8 val0x6cc
)
776 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
778 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
779 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
780 (force_exec
? "force to" : ""),
781 val0x6c0
, val0x6c4
, val0x6c8
, val0x6cc
);
782 coex_dm
->cur_val0x6c0
= val0x6c0
;
783 coex_dm
->cur_val0x6c4
= val0x6c4
;
784 coex_dm
->cur_val0x6c8
= val0x6c8
;
785 coex_dm
->cur_val0x6cc
= val0x6cc
;
788 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
789 "[BTCoex], pre_val0x6c0 = 0x%x, pre_val0x6c4 = 0x%x, pre_val0x6c8 = 0x%x, pre_val0x6cc = 0x%x !!\n",
790 coex_dm
->pre_val0x6c0
,
791 coex_dm
->pre_val0x6c4
,
792 coex_dm
->pre_val0x6c8
,
793 coex_dm
->pre_val0x6cc
);
794 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
795 "[BTCoex], cur_val0x6c0 = 0x%x, cur_val0x6c4 = 0x%x, cur_val0x6c8 = 0x%x, cur_val0x6cc = 0x%x !!\n",
796 coex_dm
->cur_val0x6c0
,
797 coex_dm
->cur_val0x6c4
,
798 coex_dm
->cur_val0x6c8
,
799 coex_dm
->cur_val0x6cc
);
801 if ((coex_dm
->pre_val0x6c0
== coex_dm
->cur_val0x6c0
) &&
802 (coex_dm
->pre_val0x6c4
== coex_dm
->cur_val0x6c4
) &&
803 (coex_dm
->pre_val0x6c8
== coex_dm
->cur_val0x6c8
) &&
804 (coex_dm
->pre_val0x6cc
== coex_dm
->cur_val0x6cc
))
807 btc8821a2ant_set_coex_table(btcoexist
, val0x6c0
, val0x6c4
, val0x6c8
,
810 coex_dm
->pre_val0x6c0
= coex_dm
->cur_val0x6c0
;
811 coex_dm
->pre_val0x6c4
= coex_dm
->cur_val0x6c4
;
812 coex_dm
->pre_val0x6c8
= coex_dm
->cur_val0x6c8
;
813 coex_dm
->pre_val0x6cc
= coex_dm
->cur_val0x6cc
;
816 static void btc8821a2ant_set_fw_ignore_wlan_act(struct btc_coexist
*btcoex
,
819 struct rtl_priv
*rtlpriv
= btcoex
->adapter
;
820 u8 h2c_parameter
[1] = {0};
823 h2c_parameter
[0] |= BIT0
; /* function enable */
825 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
826 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
829 btcoex
->btc_fill_h2c(btcoex
, 0x63, 1, h2c_parameter
);
832 static void btc8821a2ant_ignore_wlan_act(struct btc_coexist
*btcoexist
,
833 bool force_exec
, bool enable
)
835 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
837 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
838 "[BTCoex], %s turn Ignore WlanAct %s\n",
839 (force_exec
? "force to" : ""), (enable
? "ON" : "OFF"));
840 coex_dm
->cur_ignore_wlan_act
= enable
;
843 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
844 "[BTCoex], pre_ignore_wlan_act = %d, cur_ignore_wlan_act = %d!!\n",
845 coex_dm
->pre_ignore_wlan_act
,
846 coex_dm
->cur_ignore_wlan_act
);
848 if (coex_dm
->pre_ignore_wlan_act
==
849 coex_dm
->cur_ignore_wlan_act
)
852 btc8821a2ant_set_fw_ignore_wlan_act(btcoexist
, enable
);
854 coex_dm
->pre_ignore_wlan_act
= coex_dm
->cur_ignore_wlan_act
;
857 static void btc8821a2ant_set_fw_ps_tdma(struct btc_coexist
*btcoexist
,
858 u8 byte1
, u8 byte2
, u8 byte3
,
861 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
864 h2c_parameter
[0] = byte1
;
865 h2c_parameter
[1] = byte2
;
866 h2c_parameter
[2] = byte3
;
867 h2c_parameter
[3] = byte4
;
868 h2c_parameter
[4] = byte5
;
870 coex_dm
->ps_tdma_para
[0] = byte1
;
871 coex_dm
->ps_tdma_para
[1] = byte2
;
872 coex_dm
->ps_tdma_para
[2] = byte3
;
873 coex_dm
->ps_tdma_para
[3] = byte4
;
874 coex_dm
->ps_tdma_para
[4] = byte5
;
876 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
877 "[BTCoex], FW write 0x60(5bytes) = 0x%x%08x\n",
879 h2c_parameter
[1] << 24 |
880 h2c_parameter
[2] << 16 |
881 h2c_parameter
[3] << 8 |
884 btcoexist
->btc_fill_h2c(btcoexist
, 0x60, 5, h2c_parameter
);
887 static void btc8821a2ant_sw_mechanism1(struct btc_coexist
*btcoexist
,
888 bool shrink_rx_lpf
, bool low_penalty_ra
,
889 bool limited_dig
, bool bt_lna_constrain
)
893 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
895 if (BTC_WIFI_BW_HT40
!= wifi_bw
) {
896 /*only shrink RF Rx LPF for HT40*/
898 shrink_rx_lpf
= false;
901 btc8821a2ant_low_penalty_ra(btcoexist
, NORMAL_EXEC
, low_penalty_ra
);
904 static void btc8821a2ant_sw_mechanism2(struct btc_coexist
*btcoexist
,
905 bool agc_table_shift
, bool adc_back_off
,
906 bool sw_dac_swing
, u32 dac_swing_lvl
)
908 btc8821a2ant_dac_swing(btcoexist
, NORMAL_EXEC
, sw_dac_swing
,
912 static void btc8821a2ant_set_ant_path(struct btc_coexist
*btcoexist
,
913 u8 ant_pos_type
, bool init_hw_cfg
,
916 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
918 u8 h2c_parameter
[2] = {0};
921 /* 0x4c[23] = 0, 0x4c[24] = 1 Antenna control by WL/BT */
922 u4tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
925 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u4tmp
);
927 btcoexist
->btc_write_4byte(btcoexist
, 0x974, 0x3ff);
928 btcoexist
->btc_write_1byte(btcoexist
, 0xcb4, 0x77);
930 if (board_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
) {
931 /* tell firmware "antenna inverse" ==> WRONG firmware
932 * antenna control code ==>need fw to fix
934 h2c_parameter
[0] = 1;
935 h2c_parameter
[1] = 1;
936 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
939 /* tell firmware "no antenna inverse" ==> WRONG firmware
940 * antenna control code ==>need fw to fix
942 h2c_parameter
[0] = 0;
943 h2c_parameter
[1] = 1;
944 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
949 /* ext switch setting */
950 switch (ant_pos_type
) {
951 case BTC_ANT_WIFI_AT_MAIN
:
952 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xcb7, 0x30, 0x1);
954 case BTC_ANT_WIFI_AT_AUX
:
955 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xcb7, 0x30, 0x2);
960 static void btc8821a2ant_ps_tdma(struct btc_coexist
*btcoexist
,
961 bool force_exec
, bool turn_on
, u8 type
)
963 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
965 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
966 "[BTCoex], %s turn %s PS TDMA, type = %d\n",
967 (force_exec
? "force to" : ""), (turn_on
? "ON" : "OFF"),
969 coex_dm
->cur_ps_tdma_on
= turn_on
;
970 coex_dm
->cur_ps_tdma
= type
;
973 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
974 "[BTCoex], pre_ps_tdma_on = %d, cur_ps_tdma_on = %d!!\n",
975 coex_dm
->pre_ps_tdma_on
, coex_dm
->cur_ps_tdma_on
);
976 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
977 "[BTCoex], pre_ps_tdma = %d, cur_ps_tdma = %d!!\n",
978 coex_dm
->pre_ps_tdma
, coex_dm
->cur_ps_tdma
);
980 if ((coex_dm
->pre_ps_tdma_on
== coex_dm
->cur_ps_tdma_on
) &&
981 (coex_dm
->pre_ps_tdma
== coex_dm
->cur_ps_tdma
))
988 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1a,
992 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x12,
996 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1c,
1000 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x10,
1004 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1a,
1008 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x12,
1012 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1c,
1016 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xa3, 0x10,
1020 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1a,
1024 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x12,
1028 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1032 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x5,
1036 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1a,
1040 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3,
1041 0x12, 0x12, 0x60, 0x90);
1044 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1048 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x5,
1052 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xa3, 0x2f,
1056 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x5,
1060 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1064 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1068 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x15,
1072 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x1a,
1077 /* disable PS tdma */
1080 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1084 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1088 btc8821a2ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1094 /* update pre state */
1095 coex_dm
->pre_ps_tdma_on
= coex_dm
->cur_ps_tdma_on
;
1096 coex_dm
->pre_ps_tdma
= coex_dm
->cur_ps_tdma
;
1099 static void btc8821a2ant_coex_all_off(struct btc_coexist
*btcoexist
)
1102 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1103 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1104 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1107 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false, false);
1108 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false, 0x18);
1111 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
,
1112 0x55555555, 0x55555555, 0xffff, 0x3);
1115 static void btc8821a2ant_coex_under_5g(struct btc_coexist
*btcoexist
)
1117 btc8821a2ant_coex_all_off(btcoexist
);
1120 static void btc8821a2ant_init_coex_dm(struct btc_coexist
*btcoexist
)
1122 /* force to reset coex mechanism */
1123 btc8821a2ant_coex_table(btcoexist
, FORCE_EXEC
, 0x55555555,
1124 0x55555555, 0xffff, 0x3);
1126 btc8821a2ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 1);
1127 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, FORCE_EXEC
, 6);
1128 btc8821a2ant_dec_bt_pwr(btcoexist
, FORCE_EXEC
, false);
1130 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false, false);
1131 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false, 0x18);
1134 static void btc8821a2ant_bt_inquiry_page(struct btc_coexist
*btcoexist
)
1136 bool low_pwr_disable
= true;
1138 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1141 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
1142 0x5afa5afa, 0xffff, 0x3);
1143 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
1146 static bool btc8821a2ant_is_common_action(struct btc_coexist
*btcoexist
)
1148 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1149 bool common
= false, wifi_connected
= false, wifi_busy
= false;
1150 bool low_pwr_disable
= false;
1152 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1154 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1156 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
1157 0x5afa5afa, 0xffff, 0x3);
1159 if (!wifi_connected
&&
1160 BT_8821A_2ANT_BT_STATUS_IDLE
== coex_dm
->bt_status
) {
1161 low_pwr_disable
= false;
1162 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1165 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1166 "[BTCoex], Wifi IPS + BT IPS!!\n");
1168 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1169 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1170 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1172 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false,
1174 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false,
1178 } else if (wifi_connected
&&
1179 (BT_8821A_2ANT_BT_STATUS_IDLE
== coex_dm
->bt_status
)) {
1180 low_pwr_disable
= false;
1181 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1185 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1186 "[BTCoex], Wifi Busy + BT IPS!!\n");
1187 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1190 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1191 "[BTCoex], Wifi LPS + BT IPS!!\n");
1192 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1196 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1197 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1199 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false,
1201 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false,
1205 } else if (!wifi_connected
&&
1206 (BT_8821A_2ANT_BT_STATUS_CON_IDLE
== coex_dm
->bt_status
)) {
1207 low_pwr_disable
= true;
1208 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1210 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false,
1213 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1214 "[BTCoex], Wifi IPS + BT LPS!!\n");
1216 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1217 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1218 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1220 btc8821a2ant_sw_mechanism1(btcoexist
, false, false, false,
1222 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false,
1225 } else if (wifi_connected
&&
1226 (BT_8821A_2ANT_BT_STATUS_CON_IDLE
== coex_dm
->bt_status
)) {
1227 low_pwr_disable
= true;
1228 btcoexist
->btc_set(btcoexist
,
1229 BTC_SET_ACT_DISABLE_LOW_POWER
, &low_pwr_disable
);
1232 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1233 "[BTCoex], Wifi Busy + BT LPS!!\n");
1234 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1237 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1238 "[BTCoex], Wifi LPS + BT LPS!!\n");
1239 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1243 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1244 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1246 btc8821a2ant_sw_mechanism1(btcoexist
, true, true, true, true);
1247 btc8821a2ant_sw_mechanism2(btcoexist
, false, false, false,
1251 } else if (!wifi_connected
&&
1252 (coex_dm
->bt_status
== BT_8821A_2ANT_BT_STATUS_NON_IDLE
)) {
1253 low_pwr_disable
= false;
1254 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1257 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1258 "[BTCoex], Wifi IPS + BT Busy!!\n");
1260 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1261 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1262 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1264 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
1266 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1271 low_pwr_disable
= true;
1272 btcoexist
->btc_set(btcoexist
,
1273 BTC_SET_ACT_DISABLE_LOW_POWER
,
1277 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1278 "[BTCoex], Wifi Busy + BT Busy!!\n");
1281 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1282 "[BTCoex], Wifi LPS + BT Busy!!\n");
1283 btc8821a2ant_ps_tdma(btcoexist
,
1284 NORMAL_EXEC
, true, 21);
1288 btc8821a2ant_sw_mechanism1(btcoexist
, true, true, true, true);
1293 static void btc8821a2ant_tdma_dur_adj(struct btc_coexist
*btcoexist
,
1294 bool sco_hid
, bool tx_pause
,
1297 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1298 static long up
, dn
, m
, n
, wait_count
;
1300 * +1: increase WiFi duration
1301 * -1: decrease WiFi duration
1306 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1307 "[BTCoex], TdmaDurationAdjust()\n");
1309 if (coex_dm
->reset_tdma_adjust
) {
1310 coex_dm
->reset_tdma_adjust
= false;
1311 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1312 "[BTCoex], first run TdmaDurationAdjust()!!\n");
1315 if (max_interval
== 1) {
1316 btc8821a2ant_ps_tdma(btcoexist
,
1319 coex_dm
->tdma_adj_type
= 13;
1320 } else if (max_interval
== 2) {
1321 btc8821a2ant_ps_tdma(btcoexist
,
1324 coex_dm
->tdma_adj_type
= 14;
1326 btc8821a2ant_ps_tdma(btcoexist
,
1329 coex_dm
->tdma_adj_type
= 15;
1332 if (max_interval
== 1) {
1333 btc8821a2ant_ps_tdma(btcoexist
,
1336 coex_dm
->tdma_adj_type
= 9;
1337 } else if (max_interval
== 2) {
1338 btc8821a2ant_ps_tdma(btcoexist
,
1341 coex_dm
->tdma_adj_type
= 10;
1343 btc8821a2ant_ps_tdma(btcoexist
,
1346 coex_dm
->tdma_adj_type
= 11;
1351 if (max_interval
== 1) {
1352 btc8821a2ant_ps_tdma(btcoexist
,
1355 coex_dm
->tdma_adj_type
= 5;
1356 } else if (max_interval
== 2) {
1357 btc8821a2ant_ps_tdma(btcoexist
,
1360 coex_dm
->tdma_adj_type
= 6;
1362 btc8821a2ant_ps_tdma(btcoexist
,
1365 coex_dm
->tdma_adj_type
= 7;
1368 if (max_interval
== 1) {
1369 btc8821a2ant_ps_tdma(btcoexist
,
1372 coex_dm
->tdma_adj_type
= 1;
1373 } else if (max_interval
== 2) {
1374 btc8821a2ant_ps_tdma(btcoexist
,
1377 coex_dm
->tdma_adj_type
= 2;
1379 btc8821a2ant_ps_tdma(btcoexist
,
1382 coex_dm
->tdma_adj_type
= 3;
1394 /* accquire the BT TRx retry count from BT_Info byte2 */
1395 retry_count
= coex_sta
->bt_retry_cnt
;
1396 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1397 "[BTCoex], retry_count = %d\n", retry_count
);
1398 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1399 "[BTCoex], up = %d, dn = %d, m = %d, n = %d, wait_count = %d\n",
1400 (int)up
, (int)dn
, (int)m
, (int)n
, (int)wait_count
);
1404 if (retry_count
== 0) {
1405 /* no retry in the last 2-second duration */
1413 /* if (retry count == 0) for 2*n seconds,
1414 * make WiFi duration wider
1421 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1422 "[BTCoex], Increase wifi duration!!\n");
1424 } else if (retry_count
<= 3) {
1425 /* <=3 retry in the last 2-second duration */
1433 /* if retry count < 3 for 2*2 seconds,
1434 * shrink wifi duration
1436 if (wait_count
<= 2)
1437 m
++; /* avoid bounce in two levels */
1440 /* m max value is 20, max time is 120 second,
1441 * recheck if adjust WiFi duration.
1451 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1452 "[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
1455 /* retry count > 3, if retry count > 3 happens once,
1456 * shrink WiFi duration
1458 if (wait_count
== 1)
1459 m
++; /* avoid bounce in two levels */
1462 /* m max value is 20, max time is 120 second,
1463 * recheck if adjust WiFi duration.
1473 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1474 "[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
1477 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1478 "[BTCoex], max Interval = %d\n", max_interval
);
1481 /* if current PsTdma not match with the recorded one
1482 * (when scan, dhcp...), then we have to adjust it back to
1483 * the previous recorded one.
1485 if (coex_dm
->cur_ps_tdma
!= coex_dm
->tdma_adj_type
) {
1486 bool scan
= false, link
= false, roam
= false;
1488 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1489 "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma = %d, recordPsTdma = %d\n",
1490 coex_dm
->cur_ps_tdma
, coex_dm
->tdma_adj_type
);
1492 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
1493 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
1494 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
1496 if (!scan
&& !link
&& !roam
) {
1497 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true,
1498 coex_dm
->tdma_adj_type
);
1500 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1501 "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
1505 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 0x6);
1508 /* SCO only or SCO+PAN(HS)*/
1509 static void btc8821a2ant_action_sco(struct btc_coexist
*btcoexist
)
1511 u8 wifi_rssi_state
, bt_rssi_state
;
1514 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2,
1516 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2, 35, 0);
1518 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
1519 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 4);
1521 if (BTC_RSSI_HIGH(bt_rssi_state
))
1522 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
1524 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1526 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
1528 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
1529 /* for SCO quality at 11b/g mode */
1530 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
,
1531 0x5a5a5a5a, 0x5a5a5a5a, 0xffff, 0x3);
1533 /* for SCO quality & wifi performance balance at 11n mode */
1534 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
,
1535 0x5aea5aea, 0x5aea5aea, 0xffff, 0x3);
1538 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
1540 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1541 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1542 /* for voice quality */
1543 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1546 /* for voice quality */
1547 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1552 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1553 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1554 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
1556 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1559 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
1561 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1565 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1566 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1567 /* for voice quality */
1568 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
1570 /* for voice quality */
1571 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
1575 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1576 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1577 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
1579 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1582 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
1584 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1590 static void btc8821a2ant_action_hid(struct btc_coexist
*btcoexist
)
1592 u8 wifi_rssi_state
, bt_rssi_state
;
1595 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
1596 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2, 35, 0);
1598 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
1599 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1601 if (BTC_RSSI_HIGH(bt_rssi_state
))
1602 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
1604 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1606 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
1608 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
1609 /* for HID at 11b/g mode */
1610 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
1611 0x5a5a5a5a, 0xffff, 0x3);
1613 /* for HID quality & wifi performance balance at 11n mode */
1614 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
1615 0x5aea5aea, 0xffff, 0x3);
1618 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
1620 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1621 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1622 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1625 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1630 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1631 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1632 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
1634 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1637 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
1639 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1644 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1645 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1646 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1649 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1654 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1655 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1656 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
1658 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1661 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
1663 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1669 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
1670 static void btc8821a2ant_action_a2dp(struct btc_coexist
*btcoexist
)
1672 u8 wifi_rssi_state
, bt_rssi_state
;
1675 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2,
1677 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2, 35, 0);
1679 /* fw dac swing is called in btc8821a2ant_tdma_dur_adj()
1680 * btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1683 if (BTC_RSSI_HIGH(bt_rssi_state
))
1684 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
1686 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1688 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
1690 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
1692 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1693 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1694 btc8821a2ant_tdma_dur_adj(btcoexist
, false, false, 1);
1696 btc8821a2ant_tdma_dur_adj(btcoexist
, false, true, 1);
1700 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1701 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1702 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
1704 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1707 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
1709 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1714 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1715 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1716 btc8821a2ant_tdma_dur_adj(btcoexist
, false, false, 1);
1718 btc8821a2ant_tdma_dur_adj(btcoexist
, false, true, 1);
1722 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1723 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1724 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
1726 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1729 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
1731 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1737 static void btc8821a2ant_action_a2dp_pan_hs(struct btc_coexist
*btcoexist
)
1739 u8 wifi_rssi_state
, bt_rssi_state
, bt_info_ext
;
1742 bt_info_ext
= coex_sta
->bt_info_ext
;
1743 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
1744 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2, 35, 0);
1746 if (BTC_RSSI_HIGH(bt_rssi_state
))
1747 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
1749 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1751 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
1753 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
1755 if (bt_info_ext
&BIT0
) {
1756 /* a2dp basic rate */
1757 btc8821a2ant_tdma_dur_adj(btcoexist
, false, true, 2);
1760 btc8821a2ant_tdma_dur_adj(btcoexist
, false, true, 1);
1764 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1765 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1766 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
1768 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1771 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
1773 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1778 if (bt_info_ext
&BIT0
) {
1779 /* a2dp basic rate */
1780 btc8821a2ant_tdma_dur_adj(btcoexist
, false, true, 2);
1783 btc8821a2ant_tdma_dur_adj(btcoexist
, false, true, 1);
1787 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1788 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1789 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
1791 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1794 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
1796 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1802 static void btc8821a2ant_action_pan_edr(struct btc_coexist
*btcoexist
)
1804 u8 wifi_rssi_state
, bt_rssi_state
;
1807 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
1808 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2, 35, 0);
1810 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1812 if (BTC_RSSI_HIGH(bt_rssi_state
))
1813 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
1815 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1817 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
1819 if (BTC_WIFI_BW_LEGACY
== wifi_bw
) {
1820 /* for HID at 11b/g mode */
1821 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
1822 0x5aff5aff, 0xffff, 0x3);
1824 /* for HID quality & wifi performance balance at 11n mode */
1825 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
1826 0x5aff5aff, 0xffff, 0x3);
1829 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
1831 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1832 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1833 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1836 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1841 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1842 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1843 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
1845 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1848 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
1850 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1855 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1856 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1857 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1860 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1865 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1866 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1867 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
1869 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1872 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
1874 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1881 static void btc8821a2ant_action_pan_hs(struct btc_coexist
*btcoexist
)
1883 u8 wifi_rssi_state
, bt_rssi_state
;
1886 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
1887 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2, 35, 0);
1889 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
1890 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1892 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
1894 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
1896 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1897 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1898 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
1900 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1902 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1905 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1906 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1907 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
1909 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1912 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
1914 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1919 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1920 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1921 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
1923 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1926 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1927 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1928 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1930 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 1);
1934 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1935 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1936 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
1938 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1941 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
1943 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
1950 static void btc8821a2ant_action_pan_edr_a2dp(struct btc_coexist
*btcoexist
)
1952 u8 wifi_rssi_state
, bt_rssi_state
, bt_info_ext
;
1955 bt_info_ext
= coex_sta
->bt_info_ext
;
1956 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
1957 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2, 35, 0);
1959 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
1961 if (BTC_RSSI_HIGH(bt_rssi_state
))
1962 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
1964 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
1966 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
1968 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
1969 /* for HID at 11b/g mode */
1970 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
1971 0x5afa5afa, 0xffff, 0x3);
1973 /* for HID quality & wifi performance balance at 11n mode */
1974 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
1975 0x5afa5afa, 0xffff, 0x3);
1978 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
1980 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1981 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
))
1982 btc8821a2ant_tdma_dur_adj(btcoexist
, false,
1985 btc8821a2ant_tdma_dur_adj(btcoexist
, false,
1989 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1990 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1991 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
1993 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
1996 btc8821a2ant_sw_mechanism1(btcoexist
, true, false,
1998 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2003 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2004 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
))
2005 btc8821a2ant_tdma_dur_adj(btcoexist
, false, false, 3);
2007 btc8821a2ant_tdma_dur_adj(btcoexist
, false, true, 3);
2010 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2011 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2012 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
2014 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2017 btc8821a2ant_sw_mechanism1(btcoexist
, false, false,
2019 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2025 static void btc8821a2ant_action_pan_edr_hid(struct btc_coexist
*btcoexist
)
2027 u8 wifi_rssi_state
, bt_rssi_state
;
2030 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2031 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2, 35, 0);
2033 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2034 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2036 if (BTC_RSSI_HIGH(bt_rssi_state
))
2037 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2039 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2041 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2043 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
2044 /* for HID at 11b/g mode */
2045 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
2046 0x5a5f5a5f, 0xffff, 0x3);
2048 /* for HID quality & wifi performance balance at 11n mode */
2049 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
2050 0x5a5f5a5f, 0xffff, 0x3);
2053 if (wifi_bw
== BTC_WIFI_BW_HT40
) {
2054 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 3);
2056 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2057 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2058 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
2061 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
2065 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2066 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2067 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
2069 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2072 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
2074 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2078 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2080 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2081 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2082 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 10);
2084 btc8821a2ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
2088 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2089 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2090 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
2092 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2095 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
2097 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2103 /* HID+A2DP+PAN(EDR) */
2104 static void btc8821a2ant_act_hid_a2dp_pan_edr(struct btc_coexist
*btcoexist
)
2106 u8 wifi_rssi_state
, bt_rssi_state
, bt_info_ext
;
2109 bt_info_ext
= coex_sta
->bt_info_ext
;
2110 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2111 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2, 35, 0);
2113 btc8821a2ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 0x8);
2114 btc8821a2ant_fw_dac_swing_lvl(btcoexist
, NORMAL_EXEC
, 6);
2116 if (BTC_RSSI_HIGH(bt_rssi_state
))
2117 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2119 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2121 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2123 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
2124 /* for HID at 11b/g mode */
2125 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
2126 0x5a5a5a5a, 0xffff, 0x3);
2128 /* for HID quality & wifi performance balance at 11n mode */
2129 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
2130 0x5a5a5a5a, 0xffff, 0x3);
2133 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2135 btc8821a2ant_tdma_dur_adj(btcoexist
, true, true, 3);
2138 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2139 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2140 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
2142 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2145 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
2147 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2152 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2153 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2154 if (bt_info_ext
&BIT0
) {
2155 /* a2dp basic rate */
2156 btc8821a2ant_tdma_dur_adj(btcoexist
, true,
2160 btc8821a2ant_tdma_dur_adj(btcoexist
, true,
2164 if (bt_info_ext
&BIT0
) {
2165 /* a2dp basic rate */
2166 btc8821a2ant_tdma_dur_adj(btcoexist
, true,
2170 btc8821a2ant_tdma_dur_adj(btcoexist
, true,
2176 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2177 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2178 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
2180 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2183 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
2185 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2191 static void btc8821a2ant_action_hid_a2dp(struct btc_coexist
*btcoexist
)
2193 u8 wifi_rssi_state
, bt_rssi_state
, bt_info_ext
;
2196 bt_info_ext
= coex_sta
->bt_info_ext
;
2197 wifi_rssi_state
= btc8821a2ant_wifi_rssi_state(btcoexist
, 0, 2, 15, 0);
2198 bt_rssi_state
= btc8821a2ant_bt_rssi_state(btcoexist
, 2, 35, 0);
2200 if (BTC_RSSI_HIGH(bt_rssi_state
))
2201 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, true);
2203 btc8821a2ant_dec_bt_pwr(btcoexist
, NORMAL_EXEC
, false);
2205 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2207 if (wifi_bw
== BTC_WIFI_BW_LEGACY
) {
2208 /* for HID at 11b/g mode */
2209 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
2210 0x5f5b5f5b, 0xffffff, 0x3);
2212 /* for HID quality & wifi performance balance at 11n mode */
2213 btc8821a2ant_coex_table(btcoexist
, NORMAL_EXEC
, 0x55ff55ff,
2214 0x5f5b5f5b, 0xffffff, 0x3);
2217 if (BTC_WIFI_BW_HT40
== wifi_bw
) {
2219 btc8821a2ant_tdma_dur_adj(btcoexist
, true, true, 2);
2222 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2223 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2224 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
2226 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2229 btc8821a2ant_sw_mechanism1(btcoexist
, true, true,
2231 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2236 btc8821a2ant_tdma_dur_adj(btcoexist
, true, true, 2);
2239 if ((wifi_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
2240 (wifi_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
2241 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
2243 btc8821a2ant_sw_mechanism2(btcoexist
, true, false,
2246 btc8821a2ant_sw_mechanism1(btcoexist
, false, true,
2248 btc8821a2ant_sw_mechanism2(btcoexist
, false, false,
2254 static void btc8821a2ant_run_coexist_mechanism(struct btc_coexist
*btcoexist
)
2256 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2257 bool wifi_under_5g
= false;
2260 if (btcoexist
->manual_control
) {
2261 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2262 "[BTCoex], Manual control!!!\n");
2266 btcoexist
->btc_get(btcoexist
,
2267 BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
2269 if (wifi_under_5g
) {
2270 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2271 "[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n");
2272 btc8821a2ant_coex_under_5g(btcoexist
);
2276 algorithm
= btc8821a2ant_action_algorithm(btcoexist
);
2277 if (coex_sta
->c2h_bt_inquiry_page
&&
2278 (BT_8821A_2ANT_COEX_ALGO_PANHS
!= algorithm
)) {
2279 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2280 "[BTCoex], BT is under inquiry/page scan !!\n");
2281 btc8821a2ant_bt_inquiry_page(btcoexist
);
2285 coex_dm
->cur_algorithm
= algorithm
;
2286 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2287 "[BTCoex], Algorithm = %d\n", coex_dm
->cur_algorithm
);
2289 if (btc8821a2ant_is_common_action(btcoexist
)) {
2290 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2291 "[BTCoex], Action 2-Ant common\n");
2292 coex_dm
->reset_tdma_adjust
= true;
2294 if (coex_dm
->cur_algorithm
!= coex_dm
->pre_algorithm
) {
2295 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2296 "[BTCoex], pre_algorithm = %d, cur_algorithm = %d\n",
2297 coex_dm
->pre_algorithm
,
2298 coex_dm
->cur_algorithm
);
2299 coex_dm
->reset_tdma_adjust
= true;
2301 switch (coex_dm
->cur_algorithm
) {
2302 case BT_8821A_2ANT_COEX_ALGO_SCO
:
2303 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2304 "[BTCoex], Action 2-Ant, algorithm = SCO\n");
2305 btc8821a2ant_action_sco(btcoexist
);
2307 case BT_8821A_2ANT_COEX_ALGO_HID
:
2308 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2309 "[BTCoex], Action 2-Ant, algorithm = HID\n");
2310 btc8821a2ant_action_hid(btcoexist
);
2312 case BT_8821A_2ANT_COEX_ALGO_A2DP
:
2313 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2314 "[BTCoex], Action 2-Ant, algorithm = A2DP\n");
2315 btc8821a2ant_action_a2dp(btcoexist
);
2317 case BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS
:
2318 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2319 "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS)\n");
2320 btc8821a2ant_action_a2dp_pan_hs(btcoexist
);
2322 case BT_8821A_2ANT_COEX_ALGO_PANEDR
:
2323 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2324 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)\n");
2325 btc8821a2ant_action_pan_edr(btcoexist
);
2327 case BT_8821A_2ANT_COEX_ALGO_PANHS
:
2328 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2329 "[BTCoex], Action 2-Ant, algorithm = HS mode\n");
2330 btc8821a2ant_action_pan_hs(btcoexist
);
2332 case BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP
:
2333 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2334 "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP\n");
2335 btc8821a2ant_action_pan_edr_a2dp(btcoexist
);
2337 case BT_8821A_2ANT_COEX_ALGO_PANEDR_HID
:
2338 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2339 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID\n");
2340 btc8821a2ant_action_pan_edr_hid(btcoexist
);
2342 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR
:
2343 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2344 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN\n");
2345 btc8821a2ant_act_hid_a2dp_pan_edr(btcoexist
);
2347 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP
:
2348 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2349 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP\n");
2350 btc8821a2ant_action_hid_a2dp(btcoexist
);
2353 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2354 "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
2355 btc8821a2ant_coex_all_off(btcoexist
);
2358 coex_dm
->pre_algorithm
= coex_dm
->cur_algorithm
;
2362 /**************************************************************
2363 * extern function start with ex_btc8821a2ant_
2364 **************************************************************/
2365 void ex_btc8821a2ant_init_hwconfig(struct btc_coexist
*btcoexist
)
2367 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2370 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2371 "[BTCoex], 2Ant Init HW Config!!\n");
2373 /* backup rf 0x1e value */
2374 coex_dm
->bt_rf0x1e_backup
=
2375 btcoexist
->btc_get_rf_reg(btcoexist
, BTC_RF_A
, 0x1e, 0xfffff);
2377 /* 0x790[5:0] = 0x5 */
2378 u1tmp
= btcoexist
->btc_read_1byte(btcoexist
, 0x790);
2381 btcoexist
->btc_write_1byte(btcoexist
, 0x790, u1tmp
);
2384 btc8821a2ant_set_ant_path(btcoexist
, BTC_ANT_WIFI_AT_MAIN
, true, false);
2387 btc8821a2ant_coex_table(btcoexist
, FORCE_EXEC
, 0x55555555, 0x55555555,
2390 /* Enable counter statistics */
2391 /*0x76e[3] = 1, WLAN_Act control by PTA*/
2392 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
2393 btcoexist
->btc_write_1byte(btcoexist
, 0x778, 0x3);
2394 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x40, 0x20, 0x1);
2397 void ex_btc8821a2ant_init_coex_dm(struct btc_coexist
*btcoexist
)
2399 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2401 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2402 "[BTCoex], Coex Mechanism Init!!\n");
2404 btc8821a2ant_init_coex_dm(btcoexist
);
2407 void ex_btc8821a2ant_display_coex_info(struct btc_coexist
*btcoexist
)
2409 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
2410 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
2411 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2412 u8 u1tmp
[4], i
, bt_info_ext
, ps_tdma_case
= 0;
2414 bool roam
= false, scan
= false, link
= false, wifi_under_5g
= false;
2415 bool bt_hs_on
= false, wifi_busy
= false;
2416 long wifi_rssi
= 0, bt_hs_rssi
= 0;
2417 u32 wifi_bw
, wifi_traffic_dir
;
2418 u8 wifi_dot_11_chnl
, wifi_hs_chnl
;
2419 u32 fw_ver
= 0, bt_patch_ver
= 0;
2421 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2422 "\r\n ============[BT Coexist info]============");
2424 if (!board_info
->bt_exist
) {
2425 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n BT not exists !!!");
2429 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2430 "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:",
2431 board_info
->pg_ant_num
, board_info
->btdm_ant_num
);
2433 if (btcoexist
->manual_control
) {
2434 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2435 "\r\n %-35s", "[Action Manual control]!!");
2438 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2439 "\r\n %-35s = %s / %d", "BT stack/ hci ext ver",
2440 ((stack_info
->profile_notified
) ? "Yes" : "No"),
2441 stack_info
->hci_version
);
2443 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
, &bt_patch_ver
);
2444 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
2445 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2446 "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
2447 "CoexVer/ FwVer/ PatchVer",
2448 glcoex_ver_date_8821a_2ant
, glcoex_ver_8821a_2ant
,
2449 fw_ver
, bt_patch_ver
, bt_patch_ver
);
2451 btcoexist
->btc_get(btcoexist
,
2452 BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2453 btcoexist
->btc_get(btcoexist
,
2454 BTC_GET_U1_WIFI_DOT11_CHNL
, &wifi_dot_11_chnl
);
2455 btcoexist
->btc_get(btcoexist
,
2456 BTC_GET_U1_WIFI_HS_CHNL
, &wifi_hs_chnl
);
2457 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2458 "\r\n %-35s = %d / %d(%d)",
2459 "Dot11 channel / HsMode(HsChnl)",
2460 wifi_dot_11_chnl
, bt_hs_on
, wifi_hs_chnl
);
2462 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2463 "\r\n %-35s = %3ph ",
2464 "H2C Wifi inform bt chnl Info",
2465 coex_dm
->wifi_chnl_info
);
2467 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
2468 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_HS_RSSI
, &bt_hs_rssi
);
2469 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2470 "\r\n %-35s = %ld/ %ld", "Wifi rssi/ HS rssi",
2471 wifi_rssi
, bt_hs_rssi
);
2473 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2474 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2475 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2476 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2477 "\r\n %-35s = %d/ %d/ %d ", "Wifi link/ roam/ scan",
2480 btcoexist
->btc_get(btcoexist
,
2481 BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
2482 btcoexist
->btc_get(btcoexist
,
2483 BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2484 btcoexist
->btc_get(btcoexist
,
2485 BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
2486 btcoexist
->btc_get(btcoexist
,
2487 BTC_GET_U4_WIFI_TRAFFIC_DIRECTION
, &wifi_traffic_dir
);
2488 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2489 "\r\n %-35s = %s / %s/ %s ", "Wifi status",
2490 (wifi_under_5g
? "5G" : "2.4G"),
2491 ((BTC_WIFI_BW_LEGACY
== wifi_bw
) ? "Legacy" :
2492 (((BTC_WIFI_BW_HT40
== wifi_bw
) ? "HT40" : "HT20"))),
2493 ((!wifi_busy
) ? "idle" :
2494 ((BTC_WIFI_TRAFFIC_TX
== wifi_traffic_dir
) ?
2495 "uplink" : "downlink")));
2497 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2498 "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]",
2499 ((coex_sta
->c2h_bt_inquiry_page
) ? ("inquiry/page scan") :
2500 ((BT_8821A_2ANT_BT_STATUS_IDLE
== coex_dm
->bt_status
)
2501 ? "idle" : ((BT_8821A_2ANT_BT_STATUS_CON_IDLE
==
2502 coex_dm
->bt_status
) ? "connected-idle" : "busy"))),
2503 coex_sta
->bt_rssi
, coex_sta
->bt_retry_cnt
);
2505 if (stack_info
->profile_notified
) {
2506 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2507 "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
2508 stack_info
->sco_exist
, stack_info
->hid_exist
,
2509 stack_info
->pan_exist
, stack_info
->a2dp_exist
);
2511 btcoexist
->btc_disp_dbg_msg(btcoexist
,
2512 BTC_DBG_DISP_BT_LINK_INFO
);
2515 bt_info_ext
= coex_sta
->bt_info_ext
;
2516 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %s",
2517 "BT Info A2DP rate",
2518 (bt_info_ext
&BIT0
) ? "Basic rate" : "EDR rate");
2520 for (i
= 0; i
< BT_INFO_SRC_8821A_2ANT_MAX
; i
++) {
2521 if (coex_sta
->bt_info_c2h_cnt
[i
]) {
2522 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2523 "\r\n %-35s = %7ph(%d)",
2524 glbt_info_src_8821a_2ant
[i
],
2525 coex_sta
->bt_info_c2h
[i
],
2526 coex_sta
->bt_info_c2h_cnt
[i
]);
2530 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %s/%s",
2531 "PS state, IPS/LPS",
2532 ((coex_sta
->under_ips
? "IPS ON" : "IPS OFF")),
2533 ((coex_sta
->under_lps
? "LPS ON" : "LPS OFF")));
2534 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_FW_PWR_MODE_CMD
);
2537 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s",
2538 "============[Sw mechanism]============");
2539 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2540 "\r\n %-35s = %d/ %d/ %d/ %d ",
2541 "SM1[ShRf/ LpRA/ LimDig/ btLna]",
2542 coex_dm
->cur_rf_rx_lpf_shrink
, coex_dm
->cur_low_penalty_ra
,
2543 coex_dm
->limited_dig
, coex_dm
->cur_bt_lna_constrain
);
2544 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2545 "\r\n %-35s = %d/ %d/ %d(0x%x) ",
2546 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
2547 coex_dm
->cur_agc_table_en
, coex_dm
->cur_adc_back_off
,
2548 coex_dm
->cur_dac_swing_on
, coex_dm
->cur_dac_swing_lvl
);
2551 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s",
2552 "============[Fw mechanism]============");
2554 if (!btcoexist
->manual_control
) {
2555 ps_tdma_case
= coex_dm
->cur_ps_tdma
;
2556 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2557 "\r\n %-35s = %5ph case-%d",
2559 coex_dm
->ps_tdma_para
, ps_tdma_case
);
2561 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2562 "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct",
2563 coex_dm
->cur_dec_bt_pwr
,
2564 coex_dm
->cur_ignore_wlan_act
);
2568 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2569 "\r\n %-35s", "============[Hw setting]============");
2571 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2572 "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal",
2573 coex_dm
->bt_rf0x1e_backup
);
2575 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x778);
2576 u1tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x6cc);
2577 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x ",
2578 "0x778 (W_Act)/ 0x6cc (CoTab Sel)",
2579 u1tmp
[0], u1tmp
[1]);
2581 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x8db);
2582 u1tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0xc5b);
2583 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x",
2584 "0x8db(ADC)/0xc5b[29:25](DAC)",
2585 ((u1tmp
[0] & 0x60) >> 5), ((u1tmp
[1] & 0x3e) >> 1));
2587 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xcb4);
2588 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x",
2589 "0xcb4[7:0](ctrl)/ 0xcb4[29:28](val)",
2590 u4tmp
[0] & 0xff, ((u4tmp
[0] & 0x30000000) >> 28));
2592 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x40);
2593 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
2594 u4tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x974);
2595 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2596 "0x40/ 0x4c[24:23]/ 0x974",
2597 u1tmp
[0], ((u4tmp
[0] & 0x01800000) >> 23), u4tmp
[1]);
2599 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x550);
2600 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x522);
2601 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x",
2602 "0x550(bcn ctrl)/0x522",
2603 u4tmp
[0], u1tmp
[0]);
2605 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xc50);
2606 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0xa0a);
2607 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x",
2608 "0xc50(DIG)/0xa0a(CCK-TH)",
2609 u4tmp
[0], u1tmp
[0]);
2611 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xf48);
2612 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5b);
2613 u1tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5c);
2614 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x",
2616 u4tmp
[0], (u1tmp
[0] << 8) + u1tmp
[1]);
2618 u4tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c0);
2619 u4tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c4);
2620 u4tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c8);
2621 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2622 "0x6c0/0x6c4/0x6c8",
2623 u4tmp
[0], u4tmp
[1], u4tmp
[2]);
2625 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d",
2626 "0x770 (hi-pri Rx/Tx)",
2627 coex_sta
->high_priority_rx
, coex_sta
->high_priority_tx
);
2628 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = %d/ %d",
2629 "0x774(low-pri Rx/Tx)",
2630 coex_sta
->low_priority_rx
, coex_sta
->low_priority_tx
);
2632 /* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang*/
2633 u1tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x41b);
2634 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "\r\n %-35s = 0x%x",
2635 "0x41b (mgntQ hang chk == 0xf)",
2638 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_COEX_STATISTICS
);
2641 void ex_btc8821a2ant_ips_notify(struct btc_coexist
*btcoexist
, u8 type
)
2643 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2645 if (BTC_IPS_ENTER
== type
) {
2646 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2647 "[BTCoex], IPS ENTER notify\n");
2648 coex_sta
->under_ips
= true;
2649 btc8821a2ant_coex_all_off(btcoexist
);
2650 } else if (BTC_IPS_LEAVE
== type
) {
2651 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2652 "[BTCoex], IPS LEAVE notify\n");
2653 coex_sta
->under_ips
= false;
2657 void ex_btc8821a2ant_lps_notify(struct btc_coexist
*btcoexist
, u8 type
)
2659 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2661 if (BTC_LPS_ENABLE
== type
) {
2662 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2663 "[BTCoex], LPS ENABLE notify\n");
2664 coex_sta
->under_lps
= true;
2665 } else if (BTC_LPS_DISABLE
== type
) {
2666 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2667 "[BTCoex], LPS DISABLE notify\n");
2668 coex_sta
->under_lps
= false;
2672 void ex_btc8821a2ant_scan_notify(struct btc_coexist
*btcoexist
, u8 type
)
2674 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2676 if (BTC_SCAN_START
== type
) {
2677 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2678 "[BTCoex], SCAN START notify\n");
2679 } else if (BTC_SCAN_FINISH
== type
) {
2680 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2681 "[BTCoex], SCAN FINISH notify\n");
2685 void ex_btc8821a2ant_connect_notify(struct btc_coexist
*btcoexist
, u8 type
)
2687 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2689 if (BTC_ASSOCIATE_START
== type
) {
2690 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2691 "[BTCoex], CONNECT START notify\n");
2692 } else if (BTC_ASSOCIATE_FINISH
== type
) {
2693 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2694 "[BTCoex], CONNECT FINISH notify\n");
2698 void ex_btc8821a2ant_media_status_notify(struct btc_coexist
*btcoexist
,
2701 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2702 u8 h2c_parameter
[3] = {0};
2704 u8 wifi_central_chnl
;
2706 if (BTC_MEDIA_CONNECT
== type
) {
2707 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2708 "[BTCoex], MEDIA connect notify\n");
2710 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2711 "[BTCoex], MEDIA disconnect notify\n");
2714 /* only 2.4G we need to inform bt the chnl mask */
2715 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_CENTRAL_CHNL
,
2716 &wifi_central_chnl
);
2717 if ((BTC_MEDIA_CONNECT
== type
) &&
2718 (wifi_central_chnl
<= 14)) {
2719 h2c_parameter
[0] = 0x1;
2720 h2c_parameter
[1] = wifi_central_chnl
;
2721 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2722 if (BTC_WIFI_BW_HT40
== wifi_bw
)
2723 h2c_parameter
[2] = 0x30;
2725 h2c_parameter
[2] = 0x20;
2728 coex_dm
->wifi_chnl_info
[0] = h2c_parameter
[0];
2729 coex_dm
->wifi_chnl_info
[1] = h2c_parameter
[1];
2730 coex_dm
->wifi_chnl_info
[2] = h2c_parameter
[2];
2732 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2733 "[BTCoex], FW write 0x66 = 0x%x\n",
2734 h2c_parameter
[0] << 16 |
2735 h2c_parameter
[1] << 8 |
2738 btcoexist
->btc_fill_h2c(btcoexist
, 0x66, 3, h2c_parameter
);
2741 void ex_btc8821a2ant_special_packet_notify(struct btc_coexist
*btcoexist
,
2744 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2746 if (type
== BTC_PACKET_DHCP
) {
2747 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2748 "[BTCoex], DHCP Packet notify\n");
2752 void ex_btc8821a2ant_bt_info_notify(struct btc_coexist
*btcoexist
,
2753 u8
*tmp_buf
, u8 length
)
2755 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2757 u8 i
, rsp_source
= 0;
2758 bool bt_busy
= false, limited_dig
= false;
2759 bool wifi_connected
= false, bt_hs_on
= false;
2761 coex_sta
->c2h_bt_info_req_sent
= false;
2763 rsp_source
= tmp_buf
[0] & 0xf;
2764 if (rsp_source
>= BT_INFO_SRC_8821A_2ANT_MAX
)
2765 rsp_source
= BT_INFO_SRC_8821A_2ANT_WIFI_FW
;
2766 coex_sta
->bt_info_c2h_cnt
[rsp_source
]++;
2768 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2769 "[BTCoex], Bt info[%d], length = %d, hex data = [",
2770 rsp_source
, length
);
2771 for (i
= 0; i
< length
; i
++) {
2772 coex_sta
->bt_info_c2h
[rsp_source
][i
] = tmp_buf
[i
];
2774 bt_info
= tmp_buf
[i
];
2775 if (i
== length
- 1) {
2776 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2777 "0x%02x]\n", tmp_buf
[i
]);
2779 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2780 "0x%02x, ", tmp_buf
[i
]);
2784 if (BT_INFO_SRC_8821A_2ANT_WIFI_FW
!= rsp_source
) {
2786 coex_sta
->bt_retry_cnt
=
2787 coex_sta
->bt_info_c2h
[rsp_source
][2]&0xf;
2790 coex_sta
->bt_info_c2h
[rsp_source
][3]*2+10;
2792 coex_sta
->bt_info_ext
=
2793 coex_sta
->bt_info_c2h
[rsp_source
][4];
2795 /* Here we need to resend some wifi info to BT
2796 * because bt is reset and loss of the info
2798 if ((coex_sta
->bt_info_ext
& BIT1
)) {
2799 btcoexist
->btc_get(btcoexist
,
2800 BTC_GET_BL_WIFI_CONNECTED
, &wifi_connected
);
2801 if (wifi_connected
) {
2802 ex_btc8821a2ant_media_status_notify(btcoexist
,
2805 ex_btc8821a2ant_media_status_notify(btcoexist
,
2806 BTC_MEDIA_DISCONNECT
);
2811 if ((coex_sta
->bt_info_ext
& BIT3
)) {
2812 btc8821a2ant_ignore_wlan_act(btcoexist
,
2815 /* BT already NOT ignore Wlan active, do nothing here.*/
2819 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2820 /* check BIT2 first ==> check if bt is under inquiry or page scan*/
2821 if (bt_info
& BT_INFO_8821A_2ANT_B_INQ_PAGE
) {
2822 coex_sta
->c2h_bt_inquiry_page
= true;
2823 coex_dm
->bt_status
= BT_8821A_2ANT_BT_STATUS_NON_IDLE
;
2825 coex_sta
->c2h_bt_inquiry_page
= false;
2826 if (bt_info
== 0x1) {
2827 /* connection exists but not busy*/
2828 coex_sta
->bt_link_exist
= true;
2829 coex_dm
->bt_status
= BT_8821A_2ANT_BT_STATUS_CON_IDLE
;
2830 } else if (bt_info
& BT_INFO_8821A_2ANT_B_CONNECTION
) {
2831 /* connection exists and some link is busy*/
2832 coex_sta
->bt_link_exist
= true;
2833 if (bt_info
& BT_INFO_8821A_2ANT_B_FTP
)
2834 coex_sta
->pan_exist
= true;
2836 coex_sta
->pan_exist
= false;
2837 if (bt_info
& BT_INFO_8821A_2ANT_B_A2DP
)
2838 coex_sta
->a2dp_exist
= true;
2840 coex_sta
->a2dp_exist
= false;
2841 if (bt_info
& BT_INFO_8821A_2ANT_B_HID
)
2842 coex_sta
->hid_exist
= true;
2844 coex_sta
->hid_exist
= false;
2845 if (bt_info
& BT_INFO_8821A_2ANT_B_SCO_ESCO
)
2846 coex_sta
->sco_exist
= true;
2848 coex_sta
->sco_exist
= false;
2849 coex_dm
->bt_status
= BT_8821A_2ANT_BT_STATUS_NON_IDLE
;
2851 coex_sta
->bt_link_exist
= false;
2852 coex_sta
->pan_exist
= false;
2853 coex_sta
->a2dp_exist
= false;
2854 coex_sta
->hid_exist
= false;
2855 coex_sta
->sco_exist
= false;
2856 coex_dm
->bt_status
= BT_8821A_2ANT_BT_STATUS_IDLE
;
2860 coex_dm
->bt_status
= BT_8821A_2ANT_BT_STATUS_NON_IDLE
;
2863 if (BT_8821A_2ANT_BT_STATUS_NON_IDLE
== coex_dm
->bt_status
)
2867 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TRAFFIC_BUSY
, &bt_busy
);
2869 if (BT_8821A_2ANT_BT_STATUS_IDLE
!= coex_dm
->bt_status
)
2872 limited_dig
= false;
2873 coex_dm
->limited_dig
= limited_dig
;
2874 btcoexist
->btc_set(btcoexist
,
2875 BTC_SET_BL_BT_LIMITED_DIG
, &limited_dig
);
2877 btc8821a2ant_run_coexist_mechanism(btcoexist
);
2880 void ex_btc8821a2ant_halt_notify(struct btc_coexist
*btcoexist
)
2882 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2884 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2885 "[BTCoex], Halt notify\n");
2887 btc8821a2ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
2888 ex_btc8821a2ant_media_status_notify(btcoexist
, BTC_MEDIA_DISCONNECT
);
2891 void ex_btc8821a2ant_periodical(struct btc_coexist
*btcoexist
)
2893 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2894 static u8 dis_ver_info_cnt
;
2895 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
2896 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
2897 u32 fw_ver
= 0, bt_patch_ver
= 0;
2899 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2900 "[BTCoex], ==========================Periodical===========================\n");
2902 if (dis_ver_info_cnt
<= 5) {
2903 dis_ver_info_cnt
+= 1;
2904 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2905 "[BTCoex], ****************************************************************\n");
2906 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2907 "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
2908 board_info
->pg_ant_num
,
2909 board_info
->btdm_ant_num
,
2910 board_info
->btdm_ant_pos
);
2911 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2912 "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
2913 stack_info
->profile_notified
? "Yes" : "No",
2914 stack_info
->hci_version
);
2915 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
,
2917 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
2918 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2919 "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
2920 glcoex_ver_date_8821a_2ant
, glcoex_ver_8821a_2ant
,
2921 fw_ver
, bt_patch_ver
, bt_patch_ver
);
2922 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2923 "[BTCoex], ****************************************************************\n");
2926 btc8821a2ant_query_bt_info(btcoexist
);
2927 btc8821a2ant_monitor_bt_ctr(btcoexist
);
2928 btc8821a2ant_monitor_wifi_ctr(btcoexist
);