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 bool btc8821a2ant_is_wifi_status_changed(struct btc_coexist *btcoexist)
364 static bool pre_wifi_busy = true;
365 static bool pre_under_4way = true;
366 static bool pre_bt_hs_on = true;
367 bool wifi_busy = false, under_4way = false, bt_hs_on = false;
368 bool wifi_connected = false;
369 u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
371 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
373 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
374 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
375 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
378 if (wifi_connected) {
379 if (wifi_busy != pre_wifi_busy) {
380 pre_wifi_busy = wifi_busy;
383 if (under_4way != pre_under_4way) {
384 pre_under_4way = under_4way;
387 if (bt_hs_on != pre_bt_hs_on) {
388 pre_bt_hs_on = bt_hs_on;
392 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 3, 2,
393 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
395 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
396 (wifi_rssi_state == BTC_RSSI_STATE_LOW))
403 static void btc8821a2ant_update_bt_link_info(struct btc_coexist *btcoexist)
405 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
406 bool bt_hs_on = false;
408 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
410 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
411 bt_link_info->sco_exist = coex_sta->sco_exist;
412 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
413 bt_link_info->pan_exist = coex_sta->pan_exist;
414 bt_link_info->hid_exist = coex_sta->hid_exist;
416 /* work around for HS mode. */
418 bt_link_info->pan_exist = true;
419 bt_link_info->bt_link_exist = true;
422 /* check if Sco only */
423 if (bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
424 !bt_link_info->pan_exist && !bt_link_info->hid_exist)
425 bt_link_info->sco_only = true;
427 bt_link_info->sco_only = false;
429 /* check if A2dp only */
430 if (!bt_link_info->sco_exist && bt_link_info->a2dp_exist &&
431 !bt_link_info->pan_exist && !bt_link_info->hid_exist)
432 bt_link_info->a2dp_only = true;
434 bt_link_info->a2dp_only = false;
436 /* check if Pan only */
437 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
438 bt_link_info->pan_exist && !bt_link_info->hid_exist)
439 bt_link_info->pan_only = true;
441 bt_link_info->pan_only = false;
443 /* check if Hid only */
444 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
445 !bt_link_info->pan_exist && bt_link_info->hid_exist)
446 bt_link_info->hid_only = true;
448 bt_link_info->hid_only = false;
451 static u8 btc8821a2ant_action_algorithm(struct btc_coexist *btcoexist)
453 struct rtl_priv *rtlpriv = btcoexist->adapter;
454 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
455 bool bt_hs_on = false;
456 u8 algorithm = BT_8821A_2ANT_COEX_ALGO_UNDEFINED;
457 u8 num_of_diff_profile = 0;
459 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
461 if (!bt_link_info->bt_link_exist) {
462 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
463 "[BTCoex], No BT link exists!!!\n");
467 if (bt_link_info->sco_exist)
468 num_of_diff_profile++;
469 if (bt_link_info->hid_exist)
470 num_of_diff_profile++;
471 if (bt_link_info->pan_exist)
472 num_of_diff_profile++;
473 if (bt_link_info->a2dp_exist)
474 num_of_diff_profile++;
476 if (num_of_diff_profile == 1) {
477 if (bt_link_info->sco_exist) {
478 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
479 "[BTCoex], SCO only\n");
480 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
482 if (bt_link_info->hid_exist) {
483 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
484 "[BTCoex], HID only\n");
485 algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
486 } else if (bt_link_info->a2dp_exist) {
487 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
488 "[BTCoex], A2DP only\n");
489 algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP;
490 } else if (bt_link_info->pan_exist) {
492 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
494 "[BTCoex], PAN(HS) only\n");
495 algorithm = BT_8821A_2ANT_COEX_ALGO_PANHS;
497 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
499 "[BTCoex], PAN(EDR) only\n");
500 algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR;
504 } else if (num_of_diff_profile == 2) {
505 if (bt_link_info->sco_exist) {
506 if (bt_link_info->hid_exist) {
507 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
508 "[BTCoex], SCO + HID\n");
509 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
510 } else if (bt_link_info->a2dp_exist) {
511 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
512 "[BTCoex], SCO + A2DP ==> SCO\n");
513 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
514 } else if (bt_link_info->pan_exist) {
516 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
518 "[BTCoex], SCO + PAN(HS)\n");
519 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
521 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
523 "[BTCoex], SCO + PAN(EDR)\n");
524 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
528 if (bt_link_info->hid_exist &&
529 bt_link_info->a2dp_exist) {
530 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
531 "[BTCoex], HID + A2DP\n");
532 algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
533 } else if (bt_link_info->hid_exist &&
534 bt_link_info->pan_exist) {
536 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
538 "[BTCoex], HID + PAN(HS)\n");
539 algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
541 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
543 "[BTCoex], HID + PAN(EDR)\n");
545 BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
547 } else if (bt_link_info->pan_exist &&
548 bt_link_info->a2dp_exist) {
550 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
552 "[BTCoex], A2DP + PAN(HS)\n");
554 BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS;
556 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
558 "[BTCoex], A2DP + PAN(EDR)\n");
560 BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP;
564 } else if (num_of_diff_profile == 3) {
565 if (bt_link_info->sco_exist) {
566 if (bt_link_info->hid_exist &&
567 bt_link_info->a2dp_exist) {
568 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
569 "[BTCoex], SCO + HID + A2DP ==> HID\n");
570 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
571 } else if (bt_link_info->hid_exist &&
572 bt_link_info->pan_exist) {
574 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
576 "[BTCoex], SCO + HID + PAN(HS)\n");
577 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
579 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
581 "[BTCoex], SCO + HID + PAN(EDR)\n");
582 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
584 } else if (bt_link_info->pan_exist &&
585 bt_link_info->a2dp_exist) {
587 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
589 "[BTCoex], SCO + A2DP + PAN(HS)\n");
590 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
592 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
594 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
595 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
599 if (bt_link_info->hid_exist &&
600 bt_link_info->pan_exist &&
601 bt_link_info->a2dp_exist) {
603 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
605 "[BTCoex], HID + A2DP + PAN(HS)\n");
607 BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
609 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
611 "[BTCoex], HID + A2DP + PAN(EDR)\n");
613 BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
617 } else if (num_of_diff_profile >= 3) {
618 if (bt_link_info->sco_exist) {
619 if (bt_link_info->hid_exist &&
620 bt_link_info->pan_exist &&
621 bt_link_info->a2dp_exist) {
623 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
625 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
628 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
630 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
631 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
639 static void btc8821a2ant_set_fw_dac_swing_lvl(struct btc_coexist *btcoexist,
642 struct rtl_priv *rtlpriv = btcoexist->adapter;
643 u8 h2c_parameter[1] = {0};
645 /* There are several type of dacswing
646 * 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6
648 h2c_parameter[0] = dac_swing_lvl;
650 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
651 "[BTCoex], Set Dac Swing Level = 0x%x\n", dac_swing_lvl);
652 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
653 "[BTCoex], FW write 0x64 = 0x%x\n", h2c_parameter[0]);
655 btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
658 static void btc8821a2ant_set_fw_dec_bt_pwr(struct btc_coexist *btcoexist,
661 struct rtl_priv *rtlpriv = btcoexist->adapter;
662 u8 h2c_parameter[1] = {0};
664 h2c_parameter[0] = dec_bt_pwr_lvl;
666 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
667 "[BTCoex], decrease Bt Power Level : %u, FW write 0x62 = 0x%x\n",
668 dec_bt_pwr_lvl, h2c_parameter[0]);
670 btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter);
673 static void btc8821a2ant_dec_bt_pwr(struct btc_coexist *btcoexist,
674 bool force_exec, u8 dec_bt_pwr_lvl)
676 struct rtl_priv *rtlpriv = btcoexist->adapter;
678 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
679 "[BTCoex], %s Dec BT power level = %u\n",
680 (force_exec ? "force to" : ""), dec_bt_pwr_lvl);
681 coex_dm->cur_dec_bt_pwr_lvl = dec_bt_pwr_lvl;
684 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
685 "[BTCoex], pre_dec_bt_pwr_lvl = %d, cur_dec_bt_pwr_lvl = %d\n",
686 coex_dm->pre_dec_bt_pwr_lvl,
687 coex_dm->cur_dec_bt_pwr_lvl);
689 if (coex_dm->pre_dec_bt_pwr_lvl == coex_dm->cur_dec_bt_pwr_lvl)
692 btc8821a2ant_set_fw_dec_bt_pwr(btcoexist, coex_dm->cur_dec_bt_pwr_lvl);
694 coex_dm->pre_dec_bt_pwr_lvl = coex_dm->cur_dec_bt_pwr_lvl;
697 static void btc8821a2ant_fw_dac_swing_lvl(struct btc_coexist *btcoexist,
698 bool force_exec, u8 fw_dac_swing_lvl)
700 struct rtl_priv *rtlpriv = btcoexist->adapter;
702 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
703 "[BTCoex], %s set FW Dac Swing level = %d\n",
704 (force_exec ? "force to" : ""), fw_dac_swing_lvl);
705 coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
708 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
709 "[BTCoex], pre_fw_dac_swing_lvl = %d, cur_fw_dac_swing_lvl = %d\n",
710 coex_dm->pre_fw_dac_swing_lvl,
711 coex_dm->cur_fw_dac_swing_lvl);
713 if (coex_dm->pre_fw_dac_swing_lvl ==
714 coex_dm->cur_fw_dac_swing_lvl)
718 btc8821a2ant_set_fw_dac_swing_lvl(btcoexist,
719 coex_dm->cur_fw_dac_swing_lvl);
721 coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
724 static void btc8821a2ant_set_sw_penalty_tx_rate_adaptive(
725 struct btc_coexist *btcoexist, bool low_penalty_ra)
727 struct rtl_priv *rtlpriv = btcoexist->adapter;
728 u8 h2c_parameter[6] = {0};
730 h2c_parameter[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */
732 if (low_penalty_ra) {
733 h2c_parameter[1] |= BIT0;
734 /* normal rate except MCS7/6/5, OFDM54/48/36 */
735 h2c_parameter[2] = 0x00;
737 h2c_parameter[3] = 0xf5;
739 h2c_parameter[4] = 0xa0;
741 h2c_parameter[5] = 0xa0;
744 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
745 "[BTCoex], set WiFi Low-Penalty Retry: %s",
746 (low_penalty_ra ? "ON!!" : "OFF!!"));
748 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
751 static void btc8821a2ant_low_penalty_ra(struct btc_coexist *btcoexist,
752 bool force_exec, bool low_penalty_ra)
754 struct rtl_priv *rtlpriv = btcoexist->adapter;
756 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
757 "[BTCoex], %s turn LowPenaltyRA = %s\n",
758 (force_exec ? "force to" : ""),
759 ((low_penalty_ra) ? "ON" : "OFF"));
760 coex_dm->cur_low_penalty_ra = low_penalty_ra;
763 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
764 "[BTCoex], pre_low_penalty_ra = %d, cur_low_penalty_ra = %d\n",
765 coex_dm->pre_low_penalty_ra,
766 coex_dm->cur_low_penalty_ra);
768 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
771 btc8821a2ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
772 coex_dm->cur_low_penalty_ra);
774 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
777 static void btc8821a2ant_set_dac_swing_reg(struct btc_coexist *btcoexist,
780 struct rtl_priv *rtlpriv = btcoexist->adapter;
783 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
784 "[BTCoex], Write SwDacSwing = 0x%x\n", level);
785 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc5b, 0x3e, val);
788 static void btc8821a2ant_set_sw_full_dac_swing(struct btc_coexist *btcoexist,
789 bool sw_dac_swing_on,
790 u32 sw_dac_swing_lvl)
793 btc8821a2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl);
795 btc8821a2ant_set_dac_swing_reg(btcoexist, 0x18);
798 static void btc8821a2ant_dac_swing(struct btc_coexist *btcoexist,
799 bool force_exec, bool dac_swing_on,
802 struct rtl_priv *rtlpriv = btcoexist->adapter;
804 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
805 "[BTCoex], %s turn DacSwing = %s, dac_swing_lvl = 0x%x\n",
806 (force_exec ? "force to" : ""),
807 ((dac_swing_on) ? "ON" : "OFF"),
809 coex_dm->cur_dac_swing_on = dac_swing_on;
810 coex_dm->cur_dac_swing_lvl = dac_swing_lvl;
813 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
814 "[BTCoex], pre_dac_swing_on = %d, pre_dac_swing_lvl = 0x%x, cur_dac_swing_on = %d, cur_dac_swing_lvl = 0x%x\n",
815 coex_dm->pre_dac_swing_on,
816 coex_dm->pre_dac_swing_lvl,
817 coex_dm->cur_dac_swing_on,
818 coex_dm->cur_dac_swing_lvl);
820 if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) &&
821 (coex_dm->pre_dac_swing_lvl ==
822 coex_dm->cur_dac_swing_lvl))
826 btc8821a2ant_set_sw_full_dac_swing(btcoexist, dac_swing_on,
829 coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on;
830 coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl;
833 static void btc8821a2ant_set_coex_table(struct btc_coexist *btcoexist,
834 u32 val0x6c0, u32 val0x6c4,
835 u32 val0x6c8, u8 val0x6cc)
837 struct rtl_priv *rtlpriv = btcoexist->adapter;
839 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
840 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0);
841 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
843 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
844 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4);
845 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
847 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
848 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8);
849 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
851 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
852 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc);
853 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
856 static void btc8821a2ant_coex_table(struct btc_coexist *btcoexist,
857 bool force_exec, u32 val0x6c0,
858 u32 val0x6c4, u32 val0x6c8, u8 val0x6cc)
860 struct rtl_priv *rtlpriv = btcoexist->adapter;
862 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
863 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
864 (force_exec ? "force to" : ""),
865 val0x6c0, val0x6c4, val0x6c8, val0x6cc);
866 coex_dm->cur_val0x6c0 = val0x6c0;
867 coex_dm->cur_val0x6c4 = val0x6c4;
868 coex_dm->cur_val0x6c8 = val0x6c8;
869 coex_dm->cur_val0x6cc = val0x6cc;
872 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
873 "[BTCoex], pre_val0x6c0 = 0x%x, pre_val0x6c4 = 0x%x, pre_val0x6c8 = 0x%x, pre_val0x6cc = 0x%x !!\n",
874 coex_dm->pre_val0x6c0,
875 coex_dm->pre_val0x6c4,
876 coex_dm->pre_val0x6c8,
877 coex_dm->pre_val0x6cc);
878 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
879 "[BTCoex], cur_val0x6c0 = 0x%x, cur_val0x6c4 = 0x%x, cur_val0x6c8 = 0x%x, cur_val0x6cc = 0x%x !!\n",
880 coex_dm->cur_val0x6c0,
881 coex_dm->cur_val0x6c4,
882 coex_dm->cur_val0x6c8,
883 coex_dm->cur_val0x6cc);
885 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
886 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
887 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
888 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
891 btc8821a2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
894 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
895 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
896 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
897 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
900 static void btc8821a2ant_coex_table_with_type(struct btc_coexist *btcoexist,
901 bool force_exec, u8 type)
903 coex_sta->coex_table_type = type;
907 btc8821a2ant_coex_table(btcoexist, force_exec, 0x55555555,
908 0x55555555, 0xffffff, 0x3);
911 btc8821a2ant_coex_table(btcoexist, force_exec, 0x55555555,
912 0x5afa5afa, 0xffffff, 0x3);
915 btc8821a2ant_coex_table(btcoexist, force_exec, 0x5ada5ada,
916 0x5ada5ada, 0xffffff, 0x3);
919 btc8821a2ant_coex_table(btcoexist, force_exec, 0xaaaaaaaa,
920 0xaaaaaaaa, 0xffffff, 0x3);
923 btc8821a2ant_coex_table(btcoexist, force_exec, 0xffffffff,
924 0xffffffff, 0xffffff, 0x3);
927 btc8821a2ant_coex_table(btcoexist, force_exec, 0x5fff5fff,
928 0x5fff5fff, 0xffffff, 0x3);
931 btc8821a2ant_coex_table(btcoexist, force_exec, 0x55ff55ff,
932 0x5a5a5a5a, 0xffffff, 0x3);
935 btc8821a2ant_coex_table(btcoexist, force_exec, 0x55dd55dd,
936 0x5ada5ada, 0xffffff, 0x3);
939 btc8821a2ant_coex_table(btcoexist, force_exec, 0x55dd55dd,
940 0x5ada5ada, 0xffffff, 0x3);
943 btc8821a2ant_coex_table(btcoexist, force_exec, 0x55dd55dd,
944 0x5ada5ada, 0xffffff, 0x3);
947 btc8821a2ant_coex_table(btcoexist, force_exec, 0x55dd55dd,
948 0x5ada5ada, 0xffffff, 0x3);
951 btc8821a2ant_coex_table(btcoexist, force_exec, 0x55dd55dd,
952 0x5ada5ada, 0xffffff, 0x3);
955 btc8821a2ant_coex_table(btcoexist, force_exec, 0x55dd55dd,
956 0x5ada5ada, 0xffffff, 0x3);
959 btc8821a2ant_coex_table(btcoexist, force_exec, 0x5fff5fff,
960 0xaaaaaaaa, 0xffffff, 0x3);
963 btc8821a2ant_coex_table(btcoexist, force_exec, 0x5fff5fff,
964 0x5ada5ada, 0xffffff, 0x3);
967 btc8821a2ant_coex_table(btcoexist, force_exec, 0x55dd55dd,
968 0xaaaaaaaa, 0xffffff, 0x3);
971 btc8821a2ant_coex_table(btcoexist, force_exec, 0x5fdf5fdf,
972 0x5fdb5fdb, 0xffffff, 0x3);
975 btc8821a2ant_coex_table(btcoexist, force_exec, 0xfafafafa,
976 0xfafafafa, 0xffffff, 0x3);
983 static void btc8821a2ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoex,
986 struct rtl_priv *rtlpriv = btcoex->adapter;
987 u8 h2c_parameter[1] = {0};
990 h2c_parameter[0] |= BIT0; /* function enable */
992 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
993 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
996 btcoex->btc_fill_h2c(btcoex, 0x63, 1, h2c_parameter);
999 static void btc8821a2ant_set_lps_rpwm(struct btc_coexist *btcoexist, u8 lps_val,
1005 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
1006 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1009 static void btc8821a2ant_lps_rpwm(struct btc_coexist *btcoexist,
1010 bool force_exec, u8 lps_val, u8 rpwm_val)
1012 coex_dm->cur_lps = lps_val;
1013 coex_dm->cur_rpwm = rpwm_val;
1016 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
1017 (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
1020 btc8821a2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
1022 coex_dm->pre_lps = coex_dm->cur_lps;
1023 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
1026 static void btc8821a2ant_ignore_wlan_act(struct btc_coexist *btcoexist,
1027 bool force_exec, bool enable)
1029 struct rtl_priv *rtlpriv = btcoexist->adapter;
1031 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1032 "[BTCoex], %s turn Ignore WlanAct %s\n",
1033 (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
1034 coex_dm->cur_ignore_wlan_act = enable;
1037 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1038 "[BTCoex], pre_ignore_wlan_act = %d, cur_ignore_wlan_act = %d!!\n",
1039 coex_dm->pre_ignore_wlan_act,
1040 coex_dm->cur_ignore_wlan_act);
1042 if (coex_dm->pre_ignore_wlan_act ==
1043 coex_dm->cur_ignore_wlan_act)
1046 btc8821a2ant_set_fw_ignore_wlan_act(btcoexist, enable);
1048 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1051 static void btc8821a2ant_set_fw_ps_tdma(struct btc_coexist *btcoexist,
1052 u8 byte1, u8 byte2, u8 byte3,
1055 struct rtl_priv *rtlpriv = btcoexist->adapter;
1056 u8 h2c_parameter[5];
1058 h2c_parameter[0] = byte1;
1059 h2c_parameter[1] = byte2;
1060 h2c_parameter[2] = byte3;
1061 h2c_parameter[3] = byte4;
1062 h2c_parameter[4] = byte5;
1064 coex_dm->ps_tdma_para[0] = byte1;
1065 coex_dm->ps_tdma_para[1] = byte2;
1066 coex_dm->ps_tdma_para[2] = byte3;
1067 coex_dm->ps_tdma_para[3] = byte4;
1068 coex_dm->ps_tdma_para[4] = byte5;
1070 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1071 "[BTCoex], FW write 0x60(5bytes) = 0x%x%08x\n",
1073 h2c_parameter[1] << 24 |
1074 h2c_parameter[2] << 16 |
1075 h2c_parameter[3] << 8 |
1078 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1081 static void btc8821a2ant_sw_mechanism1(struct btc_coexist *btcoexist,
1082 bool shrink_rx_lpf, bool low_penalty_ra,
1083 bool limited_dig, bool bt_lna_constrain)
1085 btc8821a2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
1088 static void btc8821a2ant_sw_mechanism2(struct btc_coexist *btcoexist,
1089 bool agc_table_shift, bool adc_back_off,
1090 bool sw_dac_swing, u32 dac_swing_lvl)
1092 btc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing,
1096 static void btc8821a2ant_set_ant_path(struct btc_coexist *btcoexist,
1097 u8 ant_pos_type, bool init_hw_cfg,
1100 struct btc_board_info *board_info = &btcoexist->board_info;
1102 u8 h2c_parameter[2] = {0};
1105 /* 0x4c[23] = 0, 0x4c[24] = 1 Antenna control by WL/BT */
1106 u4tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
1109 btcoexist->btc_write_4byte(btcoexist, 0x4c, u4tmp);
1111 btcoexist->btc_write_4byte(btcoexist, 0x974, 0x3ff);
1113 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
1114 /* tell firmware "antenna inverse" ==> WRONG firmware
1115 * antenna control code ==>need fw to fix
1117 h2c_parameter[0] = 1;
1118 h2c_parameter[1] = 1;
1119 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
1122 /* tell firmware "no antenna inverse" ==> WRONG firmware
1123 * antenna control code ==>need fw to fix
1125 h2c_parameter[0] = 0;
1126 h2c_parameter[1] = 1;
1127 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
1132 /* ext switch setting */
1133 switch (ant_pos_type) {
1134 case BTC_ANT_WIFI_AT_MAIN:
1135 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 0x30, 0x1);
1137 case BTC_ANT_WIFI_AT_AUX:
1138 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 0x30, 0x2);
1143 static void btc8821a2ant_ps_tdma(struct btc_coexist *btcoexist,
1144 bool force_exec, bool turn_on, u8 type)
1146 struct rtl_priv *rtlpriv = btcoexist->adapter;
1148 u8 wifi_rssi_state, bt_rssi_state;
1150 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
1151 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
1152 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist, 2,
1153 BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
1155 if (!(BTC_RSSI_HIGH(wifi_rssi_state) &&
1156 BTC_RSSI_HIGH(bt_rssi_state)) &&
1158 /* for WiFi RSSI low or BT RSSI low */
1162 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1163 "[BTCoex], %s turn %s PS TDMA, type = %d\n",
1164 (force_exec ? "force to" : ""), (turn_on ? "ON" : "OFF"),
1166 coex_dm->cur_ps_tdma_on = turn_on;
1167 coex_dm->cur_ps_tdma = type;
1170 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1171 "[BTCoex], pre_ps_tdma_on = %d, cur_ps_tdma_on = %d!!\n",
1172 coex_dm->pre_ps_tdma_on, coex_dm->cur_ps_tdma_on);
1173 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1174 "[BTCoex], pre_ps_tdma = %d, cur_ps_tdma = %d!!\n",
1175 coex_dm->pre_ps_tdma, coex_dm->cur_ps_tdma);
1177 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1178 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1185 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x3c,
1189 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x2d,
1193 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c,
1197 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x10,
1201 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x3c,
1205 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x2d,
1209 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c,
1213 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x10,
1217 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x3c,
1221 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x2d,
1225 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c,
1229 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x10,
1233 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x3c,
1237 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x2d,
1241 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c,
1245 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x10,
1249 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x2f,
1253 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x5, 0x5,
1257 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
1261 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
1265 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15,
1269 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1e,
1274 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x3c,
1278 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x14,
1282 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x30,
1286 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x3c,
1292 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x3a,
1299 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x2d,
1306 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x1c,
1313 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x10,
1317 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x3c,
1321 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x3c,
1325 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15,
1330 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x35,
1334 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x1c,
1338 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x14,
1342 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x30,
1347 /* disable PS tdma */
1350 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
1354 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
1358 btc8821a2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
1364 /* update pre state */
1365 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1366 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1370 btc8821a2ant_ps_tdma_check_for_power_save_state(struct btc_coexist *btcoexist,
1375 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1378 /* already under LPS state */
1380 /* keep state under LPS, do nothing */
1382 /* will leave LPS state, turn off psTdma first */
1383 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1388 /* will enter LPS state, turn off psTdma first */
1389 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1391 /* keep state under NO PS state, do nothing */
1396 static void btc8821a2ant_power_save_state(struct btc_coexist *btcoexist,
1397 u8 ps_type, u8 lps_val, u8 rpwm_val)
1399 bool low_pwr_disable = false;
1402 case BTC_PS_WIFI_NATIVE:
1403 /* recover to original 32k low power setting */
1404 low_pwr_disable = false;
1405 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1407 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1408 coex_sta->force_lps_on = false;
1411 btc8821a2ant_ps_tdma_check_for_power_save_state(btcoexist,
1413 btc8821a2ant_lps_rpwm(btcoexist, NORMAL_EXEC, lps_val,
1415 /* when coex force to enter LPS, do not enter 32k low power */
1416 low_pwr_disable = true;
1417 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1419 /* power save must executed before psTdma */
1420 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1421 coex_sta->force_lps_on = true;
1423 case BTC_PS_LPS_OFF:
1424 btc8821a2ant_ps_tdma_check_for_power_save_state(btcoexist,
1426 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
1427 coex_sta->force_lps_on = false;
1434 static void btc8821a2ant_coex_all_off(struct btc_coexist *btcoexist)
1437 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1438 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1439 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1440 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1443 btc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1444 btc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1447 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1450 static void btc8821a2ant_coex_under_5g(struct btc_coexist *btcoexist)
1452 btc8821a2ant_coex_all_off(btcoexist);
1453 btc8821a2ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
1456 static void btc8821a2ant_init_coex_dm(struct btc_coexist *btcoexist)
1458 /* force to reset coex mechanism */
1459 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1461 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1462 btc8821a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
1463 btc8821a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
1464 btc8821a2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, 0);
1466 btc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1467 btc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1470 static void btc8821a2ant_action_bt_inquiry(struct btc_coexist *btcoexist)
1472 struct rtl_priv *rtlpriv = btcoexist->adapter;
1473 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
1474 bool wifi_connected = false;
1475 bool low_pwr_disable = true;
1476 bool scan = false, link = false, roam = false;
1479 btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
1480 wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
1481 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
1482 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
1483 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
1485 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1487 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1490 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1491 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1492 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1494 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1496 if (scan || link || roam) {
1497 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1498 "[BTCoex], Wifi link process + BT Inq/Page!!\n");
1499 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 15);
1500 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
1501 } else if (wifi_connected) {
1502 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1503 "[BTCoex], Wifi connected + BT Inq/Page!!\n");
1504 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 15);
1505 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
1507 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1508 "[BTCoex], Wifi no-link + BT Inq/Page!!\n");
1509 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1510 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1513 btc8821a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
1514 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1516 btc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1517 btc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1520 void btc8821a2ant_action_wifi_link_process(struct btc_coexist *btcoexist)
1522 struct rtl_priv *rtlpriv = btcoexist->adapter;
1525 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 15);
1526 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
1528 btc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1529 btc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1531 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
1532 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e);
1534 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1535 "[BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u8tmpa, u8tmpb);
1538 static bool btc8821a2ant_action_wifi_idle_process(struct btc_coexist *btcoexist)
1540 struct rtl_priv *rtlpriv = btcoexist->adapter;
1541 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
1545 btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
1546 wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
1547 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 20, 0);
1548 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
1549 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
1551 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
1553 /* define the office environment */
1554 if (BTC_RSSI_HIGH(wifi_rssi_state1) && (coex_sta->hid_exist) &&
1555 (coex_sta->a2dp_exist)) {
1556 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1557 "[BTCoex], Wifi idle process for BT HID+A2DP exist!!\n");
1559 btc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6);
1560 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1563 btc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
1565 btc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
1568 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1569 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1571 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1574 } else if (coex_sta->pan_exist) {
1575 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1576 "[BTCoex], Wifi idle process for BT PAN exist!!\n");
1578 btc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6);
1579 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1582 btc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
1584 btc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
1587 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1588 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1590 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1594 btc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x18);
1598 static bool btc8821a2ant_is_common_action(struct btc_coexist *btcoexist)
1600 struct rtl_priv *rtlpriv = btcoexist->adapter;
1601 bool common = false, wifi_connected = false, wifi_busy = false;
1602 bool low_pwr_disable = false;
1603 bool bt_hs_on = false;
1605 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
1606 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1608 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1610 if (!wifi_connected) {
1611 low_pwr_disable = false;
1612 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1614 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
1617 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1618 "[BTCoex], Wifi non-connected idle!!\n");
1620 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
1622 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1623 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1625 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1626 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1627 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1629 btc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
1631 btc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
1636 if (BT_8821A_2ANT_BT_STATUS_IDLE ==
1637 coex_dm->bt_status) {
1638 low_pwr_disable = false;
1639 btcoexist->btc_set(btcoexist,
1640 BTC_SET_ACT_DISABLE_LOW_POWER,
1642 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC,
1645 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1646 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1648 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
1650 btc8821a2ant_coex_table_with_type(btcoexist,
1653 btc8821a2ant_power_save_state(
1654 btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1655 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1656 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1658 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1660 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
1662 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
1666 } else if (BT_8821A_2ANT_BT_STATUS_CON_IDLE ==
1667 coex_dm->bt_status) {
1668 low_pwr_disable = true;
1669 btcoexist->btc_set(btcoexist,
1670 BTC_SET_ACT_DISABLE_LOW_POWER,
1675 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1676 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1677 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC,
1680 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
1682 btc8821a2ant_coex_table_with_type(btcoexist,
1685 btc8821a2ant_power_save_state(
1686 btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1687 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1688 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1690 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1692 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
1694 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
1698 low_pwr_disable = true;
1699 btcoexist->btc_set(btcoexist,
1700 BTC_SET_ACT_DISABLE_LOW_POWER,
1704 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1705 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1708 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1709 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1711 btc8821a2ant_action_wifi_idle_process(
1719 static void btc8821a2ant_tdma_duration_adjust(struct btc_coexist *btcoexist,
1720 bool sco_hid, bool tx_pause,
1723 struct rtl_priv *rtlpriv = btcoexist->adapter;
1724 static long up, dn, m, n, wait_count;
1726 * +1: increase WiFi duration
1727 * -1: decrease WiFi duration
1732 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1733 "[BTCoex], TdmaDurationAdjust()\n");
1735 if (coex_dm->auto_tdma_adjust) {
1736 coex_dm->auto_tdma_adjust = false;
1737 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1738 "[BTCoex], first run TdmaDurationAdjust()!!\n");
1741 if (max_interval == 1) {
1742 btc8821a2ant_ps_tdma(btcoexist,
1743 NORMAL_EXEC, true, 13);
1744 coex_dm->ps_tdma_du_adj_type = 13;
1745 } else if (max_interval == 2) {
1746 btc8821a2ant_ps_tdma(btcoexist,
1747 NORMAL_EXEC, true, 14);
1748 coex_dm->ps_tdma_du_adj_type = 14;
1749 } else if (max_interval == 3) {
1750 btc8821a2ant_ps_tdma(btcoexist,
1751 NORMAL_EXEC, true, 15);
1752 coex_dm->ps_tdma_du_adj_type = 15;
1754 btc8821a2ant_ps_tdma(btcoexist,
1755 NORMAL_EXEC, true, 15);
1756 coex_dm->ps_tdma_du_adj_type = 15;
1759 if (max_interval == 1) {
1760 btc8821a2ant_ps_tdma(btcoexist,
1761 NORMAL_EXEC, true, 9);
1762 coex_dm->ps_tdma_du_adj_type = 9;
1763 } else if (max_interval == 2) {
1764 btc8821a2ant_ps_tdma(btcoexist,
1765 NORMAL_EXEC, true, 10);
1766 coex_dm->ps_tdma_du_adj_type = 10;
1767 } else if (max_interval == 3) {
1768 btc8821a2ant_ps_tdma(btcoexist,
1769 NORMAL_EXEC, true, 11);
1770 coex_dm->ps_tdma_du_adj_type = 11;
1772 btc8821a2ant_ps_tdma(btcoexist,
1773 NORMAL_EXEC, true, 11);
1774 coex_dm->ps_tdma_du_adj_type = 11;
1779 if (max_interval == 1) {
1780 btc8821a2ant_ps_tdma(btcoexist,
1781 NORMAL_EXEC, true, 5);
1782 coex_dm->ps_tdma_du_adj_type = 5;
1783 } else if (max_interval == 2) {
1784 btc8821a2ant_ps_tdma(btcoexist,
1785 NORMAL_EXEC, true, 6);
1786 coex_dm->ps_tdma_du_adj_type = 6;
1787 } else if (max_interval == 3) {
1788 btc8821a2ant_ps_tdma(btcoexist,
1789 NORMAL_EXEC, true, 7);
1790 coex_dm->ps_tdma_du_adj_type = 7;
1792 btc8821a2ant_ps_tdma(btcoexist,
1793 NORMAL_EXEC, true, 7);
1794 coex_dm->ps_tdma_du_adj_type = 7;
1797 if (max_interval == 1) {
1798 btc8821a2ant_ps_tdma(btcoexist,
1799 NORMAL_EXEC, true, 1);
1800 coex_dm->ps_tdma_du_adj_type = 1;
1801 } else if (max_interval == 2) {
1802 btc8821a2ant_ps_tdma(btcoexist,
1803 NORMAL_EXEC, true, 2);
1804 coex_dm->ps_tdma_du_adj_type = 2;
1805 } else if (max_interval == 3) {
1806 btc8821a2ant_ps_tdma(btcoexist,
1807 NORMAL_EXEC, true, 3);
1808 coex_dm->ps_tdma_du_adj_type = 3;
1810 btc8821a2ant_ps_tdma(btcoexist,
1811 NORMAL_EXEC, true, 3);
1812 coex_dm->ps_tdma_du_adj_type = 3;
1824 /* accquire the BT TRx retry count from BT_Info byte2 */
1825 retry_count = coex_sta->bt_retry_cnt;
1826 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1827 "[BTCoex], retry_count = %d\n", retry_count);
1828 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1829 "[BTCoex], up = %d, dn = %d, m = %d, n = %d, wait_count = %d\n",
1830 (int)up, (int)dn, (int)m, (int)n, (int)wait_count);
1834 if (retry_count == 0) {
1835 /* no retry in the last 2-second duration */
1843 /* if (retry count == 0) for 2*n seconds,
1844 * make WiFi duration wider
1851 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1852 "[BTCoex], Increase wifi duration!!\n");
1854 } else if (retry_count <= 3) {
1855 /* <=3 retry in the last 2-second duration */
1863 /* if retry count < 3 for 2*2 seconds,
1864 * shrink wifi duration
1866 if (wait_count <= 2)
1867 m++; /* avoid bounce in two levels */
1870 /* m max value is 20, max time is 120 second,
1871 * recheck if adjust WiFi duration.
1881 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1882 "[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
1885 /* retry count > 3, if retry count > 3 happens once,
1886 * shrink WiFi duration
1888 if (wait_count == 1)
1889 m++; /* avoid bounce in two levels */
1892 /* m max value is 20, max time is 120 second,
1893 * recheck if adjust WiFi duration.
1903 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1904 "[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
1907 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1908 "[BTCoex], max Interval = %d\n", max_interval);
1910 if (max_interval == 1) {
1912 if (coex_dm->cur_ps_tdma == 71) {
1913 btc8821a2ant_ps_tdma(btcoexist,
1914 NORMAL_EXEC, true, 5);
1915 coex_dm->ps_tdma_du_adj_type = 5;
1916 } else if (coex_dm->cur_ps_tdma == 1) {
1917 btc8821a2ant_ps_tdma(btcoexist,
1918 NORMAL_EXEC, true, 5);
1919 coex_dm->ps_tdma_du_adj_type = 5;
1920 } else if (coex_dm->cur_ps_tdma == 2) {
1921 btc8821a2ant_ps_tdma(btcoexist,
1922 NORMAL_EXEC, true, 6);
1923 coex_dm->ps_tdma_du_adj_type = 6;
1924 } else if (coex_dm->cur_ps_tdma == 3) {
1925 btc8821a2ant_ps_tdma(btcoexist,
1926 NORMAL_EXEC, true, 7);
1927 coex_dm->ps_tdma_du_adj_type = 7;
1928 } else if (coex_dm->cur_ps_tdma == 4) {
1929 btc8821a2ant_ps_tdma(btcoexist,
1930 NORMAL_EXEC, true, 8);
1931 coex_dm->ps_tdma_du_adj_type = 8;
1933 if (coex_dm->cur_ps_tdma == 9) {
1934 btc8821a2ant_ps_tdma(btcoexist,
1935 NORMAL_EXEC, true, 13);
1936 coex_dm->ps_tdma_du_adj_type = 13;
1937 } else if (coex_dm->cur_ps_tdma == 10) {
1938 btc8821a2ant_ps_tdma(btcoexist,
1939 NORMAL_EXEC, true, 14);
1940 coex_dm->ps_tdma_du_adj_type = 14;
1941 } else if (coex_dm->cur_ps_tdma == 11) {
1942 btc8821a2ant_ps_tdma(btcoexist,
1943 NORMAL_EXEC, true, 15);
1944 coex_dm->ps_tdma_du_adj_type = 15;
1945 } else if (coex_dm->cur_ps_tdma == 12) {
1946 btc8821a2ant_ps_tdma(btcoexist,
1947 NORMAL_EXEC, true, 16);
1948 coex_dm->ps_tdma_du_adj_type = 16;
1952 if (coex_dm->cur_ps_tdma == 5) {
1953 btc8821a2ant_ps_tdma(
1954 btcoexist, NORMAL_EXEC,
1956 coex_dm->ps_tdma_du_adj_type =
1958 } else if (coex_dm->cur_ps_tdma == 6) {
1959 btc8821a2ant_ps_tdma(
1960 btcoexist, NORMAL_EXEC,
1962 coex_dm->ps_tdma_du_adj_type =
1964 } else if (coex_dm->cur_ps_tdma == 7) {
1965 btc8821a2ant_ps_tdma(
1966 btcoexist, NORMAL_EXEC,
1968 coex_dm->ps_tdma_du_adj_type =
1970 } else if (coex_dm->cur_ps_tdma == 13) {
1971 btc8821a2ant_ps_tdma(
1972 btcoexist, NORMAL_EXEC,
1974 coex_dm->ps_tdma_du_adj_type =
1976 } else if (coex_dm->cur_ps_tdma == 14) {
1977 btc8821a2ant_ps_tdma(
1978 btcoexist, NORMAL_EXEC,
1980 coex_dm->ps_tdma_du_adj_type =
1982 } else if (coex_dm->cur_ps_tdma == 15) {
1983 btc8821a2ant_ps_tdma(
1984 btcoexist, NORMAL_EXEC,
1986 coex_dm->ps_tdma_du_adj_type =
1989 } else if (result == 1) {
1990 if (coex_dm->cur_ps_tdma == 8) {
1991 btc8821a2ant_ps_tdma(
1992 btcoexist, NORMAL_EXEC,
1994 coex_dm->ps_tdma_du_adj_type =
1996 } else if (coex_dm->cur_ps_tdma == 7) {
1997 btc8821a2ant_ps_tdma(
1998 btcoexist, NORMAL_EXEC,
2000 coex_dm->ps_tdma_du_adj_type =
2002 } else if (coex_dm->cur_ps_tdma == 6) {
2003 btc8821a2ant_ps_tdma(
2004 btcoexist, NORMAL_EXEC,
2006 coex_dm->ps_tdma_du_adj_type =
2008 } else if (coex_dm->cur_ps_tdma == 16) {
2009 btc8821a2ant_ps_tdma(
2010 btcoexist, NORMAL_EXEC,
2012 coex_dm->ps_tdma_du_adj_type =
2014 } else if (coex_dm->cur_ps_tdma == 15) {
2015 btc8821a2ant_ps_tdma(
2016 btcoexist, NORMAL_EXEC,
2018 coex_dm->ps_tdma_du_adj_type =
2020 } else if (coex_dm->cur_ps_tdma == 14) {
2021 btc8821a2ant_ps_tdma(
2022 btcoexist, NORMAL_EXEC,
2024 coex_dm->ps_tdma_du_adj_type =
2029 if (coex_dm->cur_ps_tdma == 5) {
2030 btc8821a2ant_ps_tdma(btcoexist,
2031 NORMAL_EXEC, true, 71);
2032 coex_dm->ps_tdma_du_adj_type = 71;
2033 } else if (coex_dm->cur_ps_tdma == 6) {
2034 btc8821a2ant_ps_tdma(btcoexist,
2035 NORMAL_EXEC, true, 2);
2036 coex_dm->ps_tdma_du_adj_type = 2;
2037 } else if (coex_dm->cur_ps_tdma == 7) {
2038 btc8821a2ant_ps_tdma(btcoexist,
2039 NORMAL_EXEC, true, 3);
2040 coex_dm->ps_tdma_du_adj_type = 3;
2041 } else if (coex_dm->cur_ps_tdma == 8) {
2042 btc8821a2ant_ps_tdma(btcoexist,
2043 NORMAL_EXEC, true, 4);
2044 coex_dm->ps_tdma_du_adj_type = 4;
2046 if (coex_dm->cur_ps_tdma == 13) {
2047 btc8821a2ant_ps_tdma(btcoexist,
2048 NORMAL_EXEC, true, 9);
2049 coex_dm->ps_tdma_du_adj_type = 9;
2050 } else if (coex_dm->cur_ps_tdma == 14) {
2051 btc8821a2ant_ps_tdma(btcoexist,
2052 NORMAL_EXEC, true, 10);
2053 coex_dm->ps_tdma_du_adj_type = 10;
2054 } else if (coex_dm->cur_ps_tdma == 15) {
2055 btc8821a2ant_ps_tdma(btcoexist,
2056 NORMAL_EXEC, true, 11);
2057 coex_dm->ps_tdma_du_adj_type = 11;
2058 } else if (coex_dm->cur_ps_tdma == 16) {
2059 btc8821a2ant_ps_tdma(btcoexist,
2060 NORMAL_EXEC, true, 12);
2061 coex_dm->ps_tdma_du_adj_type = 12;
2065 if (coex_dm->cur_ps_tdma == 71) {
2066 btc8821a2ant_ps_tdma(
2067 btcoexist, NORMAL_EXEC,
2069 coex_dm->ps_tdma_du_adj_type =
2071 } else if (coex_dm->cur_ps_tdma == 1) {
2072 btc8821a2ant_ps_tdma(
2073 btcoexist, NORMAL_EXEC,
2075 coex_dm->ps_tdma_du_adj_type =
2077 } else if (coex_dm->cur_ps_tdma == 2) {
2078 btc8821a2ant_ps_tdma(
2079 btcoexist, NORMAL_EXEC,
2081 coex_dm->ps_tdma_du_adj_type =
2083 } else if (coex_dm->cur_ps_tdma == 3) {
2084 btc8821a2ant_ps_tdma(
2085 btcoexist, NORMAL_EXEC,
2087 coex_dm->ps_tdma_du_adj_type =
2089 } else if (coex_dm->cur_ps_tdma == 9) {
2090 btc8821a2ant_ps_tdma(
2091 btcoexist, NORMAL_EXEC,
2093 coex_dm->ps_tdma_du_adj_type =
2095 } else if (coex_dm->cur_ps_tdma == 10) {
2096 btc8821a2ant_ps_tdma(
2097 btcoexist, NORMAL_EXEC,
2099 coex_dm->ps_tdma_du_adj_type =
2101 } else if (coex_dm->cur_ps_tdma == 11) {
2102 btc8821a2ant_ps_tdma(
2103 btcoexist, NORMAL_EXEC,
2105 coex_dm->ps_tdma_du_adj_type =
2108 } else if (result == 1) {
2109 if (coex_dm->cur_ps_tdma == 4) {
2110 btc8821a2ant_ps_tdma(
2111 btcoexist, NORMAL_EXEC,
2113 coex_dm->ps_tdma_du_adj_type =
2115 } else if (coex_dm->cur_ps_tdma == 3) {
2116 btc8821a2ant_ps_tdma(
2117 btcoexist, NORMAL_EXEC,
2119 coex_dm->ps_tdma_du_adj_type =
2121 } else if (coex_dm->cur_ps_tdma == 2) {
2122 btc8821a2ant_ps_tdma(
2123 btcoexist, NORMAL_EXEC,
2125 coex_dm->ps_tdma_du_adj_type =
2127 } else if (coex_dm->cur_ps_tdma == 1) {
2128 btc8821a2ant_ps_tdma(
2129 btcoexist, NORMAL_EXEC,
2131 coex_dm->ps_tdma_du_adj_type =
2133 } else if (coex_dm->cur_ps_tdma == 12) {
2134 btc8821a2ant_ps_tdma(
2135 btcoexist, NORMAL_EXEC,
2137 coex_dm->ps_tdma_du_adj_type =
2139 } else if (coex_dm->cur_ps_tdma == 11) {
2140 btc8821a2ant_ps_tdma(
2141 btcoexist, NORMAL_EXEC,
2143 coex_dm->ps_tdma_du_adj_type =
2145 } else if (coex_dm->cur_ps_tdma == 10) {
2146 btc8821a2ant_ps_tdma(
2147 btcoexist, NORMAL_EXEC,
2149 coex_dm->ps_tdma_du_adj_type =
2154 } else if (max_interval == 2) {
2156 if (coex_dm->cur_ps_tdma == 1) {
2157 btc8821a2ant_ps_tdma(btcoexist,
2158 NORMAL_EXEC, true, 6);
2159 coex_dm->ps_tdma_du_adj_type = 6;
2160 } else if (coex_dm->cur_ps_tdma == 2) {
2161 btc8821a2ant_ps_tdma(btcoexist,
2162 NORMAL_EXEC, true, 6);
2163 coex_dm->ps_tdma_du_adj_type = 6;
2164 } else if (coex_dm->cur_ps_tdma == 3) {
2165 btc8821a2ant_ps_tdma(btcoexist,
2166 NORMAL_EXEC, true, 7);
2167 coex_dm->ps_tdma_du_adj_type = 7;
2168 } else if (coex_dm->cur_ps_tdma == 4) {
2169 btc8821a2ant_ps_tdma(btcoexist,
2170 NORMAL_EXEC, true, 8);
2171 coex_dm->ps_tdma_du_adj_type = 8;
2173 if (coex_dm->cur_ps_tdma == 9) {
2174 btc8821a2ant_ps_tdma(btcoexist,
2175 NORMAL_EXEC, true, 14);
2176 coex_dm->ps_tdma_du_adj_type = 14;
2177 } else if (coex_dm->cur_ps_tdma == 10) {
2178 btc8821a2ant_ps_tdma(btcoexist,
2179 NORMAL_EXEC, true, 14);
2180 coex_dm->ps_tdma_du_adj_type = 14;
2181 } else if (coex_dm->cur_ps_tdma == 11) {
2182 btc8821a2ant_ps_tdma(btcoexist,
2183 NORMAL_EXEC, true, 15);
2184 coex_dm->ps_tdma_du_adj_type = 15;
2185 } else if (coex_dm->cur_ps_tdma == 12) {
2186 btc8821a2ant_ps_tdma(btcoexist,
2187 NORMAL_EXEC, true, 16);
2188 coex_dm->ps_tdma_du_adj_type = 16;
2191 if (coex_dm->cur_ps_tdma == 5) {
2192 btc8821a2ant_ps_tdma(
2193 btcoexist, NORMAL_EXEC,
2195 coex_dm->ps_tdma_du_adj_type =
2197 } else if (coex_dm->cur_ps_tdma == 6) {
2198 btc8821a2ant_ps_tdma(
2199 btcoexist, NORMAL_EXEC,
2201 coex_dm->ps_tdma_du_adj_type =
2203 } else if (coex_dm->cur_ps_tdma == 7) {
2204 btc8821a2ant_ps_tdma(
2205 btcoexist, NORMAL_EXEC,
2207 coex_dm->ps_tdma_du_adj_type =
2209 } else if (coex_dm->cur_ps_tdma == 13) {
2210 btc8821a2ant_ps_tdma(
2211 btcoexist, NORMAL_EXEC,
2213 coex_dm->ps_tdma_du_adj_type =
2215 } else if (coex_dm->cur_ps_tdma == 14) {
2216 btc8821a2ant_ps_tdma(
2217 btcoexist, NORMAL_EXEC,
2219 coex_dm->ps_tdma_du_adj_type =
2221 } else if (coex_dm->cur_ps_tdma == 15) {
2222 btc8821a2ant_ps_tdma(
2223 btcoexist, NORMAL_EXEC,
2225 coex_dm->ps_tdma_du_adj_type =
2228 } else if (result == 1) {
2229 if (coex_dm->cur_ps_tdma == 8) {
2230 btc8821a2ant_ps_tdma(
2231 btcoexist, NORMAL_EXEC,
2233 coex_dm->ps_tdma_du_adj_type =
2235 } else if (coex_dm->cur_ps_tdma == 7) {
2236 btc8821a2ant_ps_tdma(
2237 btcoexist, NORMAL_EXEC,
2239 coex_dm->ps_tdma_du_adj_type =
2241 } else if (coex_dm->cur_ps_tdma == 6) {
2242 btc8821a2ant_ps_tdma(
2243 btcoexist, NORMAL_EXEC,
2245 coex_dm->ps_tdma_du_adj_type =
2247 } else if (coex_dm->cur_ps_tdma == 16) {
2248 btc8821a2ant_ps_tdma(
2249 btcoexist, NORMAL_EXEC,
2251 coex_dm->ps_tdma_du_adj_type =
2253 } else if (coex_dm->cur_ps_tdma == 15) {
2254 btc8821a2ant_ps_tdma(
2255 btcoexist, NORMAL_EXEC,
2257 coex_dm->ps_tdma_du_adj_type =
2259 } else if (coex_dm->cur_ps_tdma == 14) {
2260 btc8821a2ant_ps_tdma(
2261 btcoexist, NORMAL_EXEC,
2263 coex_dm->ps_tdma_du_adj_type =
2268 if (coex_dm->cur_ps_tdma == 5) {
2269 btc8821a2ant_ps_tdma(btcoexist,
2270 NORMAL_EXEC, true, 2);
2271 coex_dm->ps_tdma_du_adj_type = 2;
2272 } else if (coex_dm->cur_ps_tdma == 6) {
2273 btc8821a2ant_ps_tdma(btcoexist,
2274 NORMAL_EXEC, true, 2);
2275 coex_dm->ps_tdma_du_adj_type = 2;
2276 } else if (coex_dm->cur_ps_tdma == 7) {
2277 btc8821a2ant_ps_tdma(btcoexist,
2278 NORMAL_EXEC, true, 3);
2279 coex_dm->ps_tdma_du_adj_type = 3;
2280 } else if (coex_dm->cur_ps_tdma == 8) {
2281 btc8821a2ant_ps_tdma(btcoexist,
2282 NORMAL_EXEC, true, 4);
2283 coex_dm->ps_tdma_du_adj_type = 4;
2285 if (coex_dm->cur_ps_tdma == 13) {
2286 btc8821a2ant_ps_tdma(btcoexist,
2287 NORMAL_EXEC, true, 10);
2288 coex_dm->ps_tdma_du_adj_type = 10;
2289 } else if (coex_dm->cur_ps_tdma == 14) {
2290 btc8821a2ant_ps_tdma(btcoexist,
2291 NORMAL_EXEC, true, 10);
2292 coex_dm->ps_tdma_du_adj_type = 10;
2293 } else if (coex_dm->cur_ps_tdma == 15) {
2294 btc8821a2ant_ps_tdma(btcoexist,
2295 NORMAL_EXEC, true, 11);
2296 coex_dm->ps_tdma_du_adj_type = 11;
2297 } else if (coex_dm->cur_ps_tdma == 16) {
2298 btc8821a2ant_ps_tdma(btcoexist,
2299 NORMAL_EXEC, true, 12);
2300 coex_dm->ps_tdma_du_adj_type = 12;
2303 if (coex_dm->cur_ps_tdma == 1) {
2304 btc8821a2ant_ps_tdma(
2305 btcoexist, NORMAL_EXEC,
2307 coex_dm->ps_tdma_du_adj_type =
2309 } else if (coex_dm->cur_ps_tdma == 2) {
2310 btc8821a2ant_ps_tdma(
2311 btcoexist, NORMAL_EXEC,
2313 coex_dm->ps_tdma_du_adj_type =
2315 } else if (coex_dm->cur_ps_tdma == 3) {
2316 btc8821a2ant_ps_tdma(
2317 btcoexist, NORMAL_EXEC,
2319 coex_dm->ps_tdma_du_adj_type =
2321 } else if (coex_dm->cur_ps_tdma == 9) {
2322 btc8821a2ant_ps_tdma(
2323 btcoexist, NORMAL_EXEC,
2325 coex_dm->ps_tdma_du_adj_type =
2327 } else if (coex_dm->cur_ps_tdma == 10) {
2328 btc8821a2ant_ps_tdma(
2329 btcoexist, NORMAL_EXEC,
2331 coex_dm->ps_tdma_du_adj_type =
2333 } else if (coex_dm->cur_ps_tdma == 11) {
2334 btc8821a2ant_ps_tdma(
2335 btcoexist, NORMAL_EXEC,
2337 coex_dm->ps_tdma_du_adj_type =
2340 } else if (result == 1) {
2341 if (coex_dm->cur_ps_tdma == 4) {
2342 btc8821a2ant_ps_tdma(
2343 btcoexist, NORMAL_EXEC,
2345 coex_dm->ps_tdma_du_adj_type =
2347 } else if (coex_dm->cur_ps_tdma == 3) {
2348 btc8821a2ant_ps_tdma(
2349 btcoexist, NORMAL_EXEC,
2351 coex_dm->ps_tdma_du_adj_type =
2353 } else if (coex_dm->cur_ps_tdma == 2) {
2354 btc8821a2ant_ps_tdma(
2355 btcoexist, NORMAL_EXEC,
2357 coex_dm->ps_tdma_du_adj_type =
2359 } else if (coex_dm->cur_ps_tdma == 12) {
2360 btc8821a2ant_ps_tdma(
2361 btcoexist, NORMAL_EXEC,
2363 coex_dm->ps_tdma_du_adj_type =
2365 } else if (coex_dm->cur_ps_tdma == 11) {
2366 btc8821a2ant_ps_tdma(
2367 btcoexist, NORMAL_EXEC,
2369 coex_dm->ps_tdma_du_adj_type =
2371 } else if (coex_dm->cur_ps_tdma == 10) {
2372 btc8821a2ant_ps_tdma(
2373 btcoexist, NORMAL_EXEC,
2375 coex_dm->ps_tdma_du_adj_type =
2380 } else if (max_interval == 3) {
2382 if (coex_dm->cur_ps_tdma == 1) {
2383 btc8821a2ant_ps_tdma(btcoexist,
2384 NORMAL_EXEC, true, 7);
2385 coex_dm->ps_tdma_du_adj_type = 7;
2386 } else if (coex_dm->cur_ps_tdma == 2) {
2387 btc8821a2ant_ps_tdma(btcoexist,
2388 NORMAL_EXEC, true, 7);
2389 coex_dm->ps_tdma_du_adj_type = 7;
2390 } else if (coex_dm->cur_ps_tdma == 3) {
2391 btc8821a2ant_ps_tdma(btcoexist,
2392 NORMAL_EXEC, true, 7);
2393 coex_dm->ps_tdma_du_adj_type = 7;
2394 } else if (coex_dm->cur_ps_tdma == 4) {
2395 btc8821a2ant_ps_tdma(btcoexist,
2396 NORMAL_EXEC, true, 8);
2397 coex_dm->ps_tdma_du_adj_type = 8;
2399 if (coex_dm->cur_ps_tdma == 9) {
2400 btc8821a2ant_ps_tdma(btcoexist,
2401 NORMAL_EXEC, true, 15);
2402 coex_dm->ps_tdma_du_adj_type = 15;
2403 } else if (coex_dm->cur_ps_tdma == 10) {
2404 btc8821a2ant_ps_tdma(btcoexist,
2405 NORMAL_EXEC, true, 15);
2406 coex_dm->ps_tdma_du_adj_type = 15;
2407 } else if (coex_dm->cur_ps_tdma == 11) {
2408 btc8821a2ant_ps_tdma(btcoexist,
2409 NORMAL_EXEC, true, 15);
2410 coex_dm->ps_tdma_du_adj_type = 15;
2411 } else if (coex_dm->cur_ps_tdma == 12) {
2412 btc8821a2ant_ps_tdma(btcoexist,
2413 NORMAL_EXEC, true, 16);
2414 coex_dm->ps_tdma_du_adj_type = 16;
2417 if (coex_dm->cur_ps_tdma == 5) {
2418 btc8821a2ant_ps_tdma(
2419 btcoexist, NORMAL_EXEC,
2421 coex_dm->ps_tdma_du_adj_type =
2423 } else if (coex_dm->cur_ps_tdma == 6) {
2424 btc8821a2ant_ps_tdma(
2425 btcoexist, NORMAL_EXEC,
2427 coex_dm->ps_tdma_du_adj_type =
2429 } else if (coex_dm->cur_ps_tdma == 7) {
2430 btc8821a2ant_ps_tdma(
2431 btcoexist, NORMAL_EXEC,
2433 coex_dm->ps_tdma_du_adj_type =
2435 } else if (coex_dm->cur_ps_tdma == 13) {
2436 btc8821a2ant_ps_tdma(
2437 btcoexist, NORMAL_EXEC,
2439 coex_dm->ps_tdma_du_adj_type =
2441 } else if (coex_dm->cur_ps_tdma == 14) {
2442 btc8821a2ant_ps_tdma(
2443 btcoexist, NORMAL_EXEC,
2445 coex_dm->ps_tdma_du_adj_type =
2447 } else if (coex_dm->cur_ps_tdma == 15) {
2448 btc8821a2ant_ps_tdma(
2449 btcoexist, NORMAL_EXEC,
2451 coex_dm->ps_tdma_du_adj_type =
2454 } else if (result == 1) {
2455 if (coex_dm->cur_ps_tdma == 8) {
2456 btc8821a2ant_ps_tdma(
2457 btcoexist, NORMAL_EXEC,
2459 coex_dm->ps_tdma_du_adj_type =
2461 } else if (coex_dm->cur_ps_tdma == 7) {
2462 btc8821a2ant_ps_tdma(
2463 btcoexist, NORMAL_EXEC,
2465 coex_dm->ps_tdma_du_adj_type =
2467 } else if (coex_dm->cur_ps_tdma == 6) {
2468 btc8821a2ant_ps_tdma(
2469 btcoexist, NORMAL_EXEC,
2471 coex_dm->ps_tdma_du_adj_type =
2473 } else if (coex_dm->cur_ps_tdma == 16) {
2474 btc8821a2ant_ps_tdma(
2475 btcoexist, NORMAL_EXEC,
2477 coex_dm->ps_tdma_du_adj_type =
2479 } else if (coex_dm->cur_ps_tdma == 15) {
2480 btc8821a2ant_ps_tdma(
2481 btcoexist, NORMAL_EXEC,
2483 coex_dm->ps_tdma_du_adj_type =
2485 } else if (coex_dm->cur_ps_tdma == 14) {
2486 btc8821a2ant_ps_tdma(
2487 btcoexist, NORMAL_EXEC,
2489 coex_dm->ps_tdma_du_adj_type =
2494 if (coex_dm->cur_ps_tdma == 5) {
2495 btc8821a2ant_ps_tdma(btcoexist,
2496 NORMAL_EXEC, true, 3);
2497 coex_dm->ps_tdma_du_adj_type = 3;
2498 } else if (coex_dm->cur_ps_tdma == 6) {
2499 btc8821a2ant_ps_tdma(btcoexist,
2500 NORMAL_EXEC, true, 3);
2501 coex_dm->ps_tdma_du_adj_type = 3;
2502 } else if (coex_dm->cur_ps_tdma == 7) {
2503 btc8821a2ant_ps_tdma(btcoexist,
2504 NORMAL_EXEC, true, 3);
2505 coex_dm->ps_tdma_du_adj_type = 3;
2506 } else if (coex_dm->cur_ps_tdma == 8) {
2507 btc8821a2ant_ps_tdma(btcoexist,
2508 NORMAL_EXEC, true, 4);
2509 coex_dm->ps_tdma_du_adj_type = 4;
2511 if (coex_dm->cur_ps_tdma == 13) {
2512 btc8821a2ant_ps_tdma(btcoexist,
2513 NORMAL_EXEC, true, 11);
2514 coex_dm->ps_tdma_du_adj_type = 11;
2515 } else if (coex_dm->cur_ps_tdma == 14) {
2516 btc8821a2ant_ps_tdma(btcoexist,
2517 NORMAL_EXEC, true, 11);
2518 coex_dm->ps_tdma_du_adj_type = 11;
2519 } else if (coex_dm->cur_ps_tdma == 15) {
2520 btc8821a2ant_ps_tdma(btcoexist,
2521 NORMAL_EXEC, true, 11);
2522 coex_dm->ps_tdma_du_adj_type = 11;
2523 } else if (coex_dm->cur_ps_tdma == 16) {
2524 btc8821a2ant_ps_tdma(btcoexist,
2525 NORMAL_EXEC, true, 12);
2526 coex_dm->ps_tdma_du_adj_type = 12;
2529 if (coex_dm->cur_ps_tdma == 1) {
2530 btc8821a2ant_ps_tdma(
2531 btcoexist, NORMAL_EXEC,
2533 coex_dm->ps_tdma_du_adj_type =
2535 } else if (coex_dm->cur_ps_tdma == 2) {
2536 btc8821a2ant_ps_tdma(
2537 btcoexist, NORMAL_EXEC,
2539 coex_dm->ps_tdma_du_adj_type =
2541 } else if (coex_dm->cur_ps_tdma == 3) {
2542 btc8821a2ant_ps_tdma(
2543 btcoexist, NORMAL_EXEC,
2545 coex_dm->ps_tdma_du_adj_type =
2547 } else if (coex_dm->cur_ps_tdma == 9) {
2548 btc8821a2ant_ps_tdma(
2549 btcoexist, NORMAL_EXEC,
2551 coex_dm->ps_tdma_du_adj_type =
2553 } else if (coex_dm->cur_ps_tdma == 10) {
2554 btc8821a2ant_ps_tdma(
2555 btcoexist, NORMAL_EXEC,
2557 coex_dm->ps_tdma_du_adj_type =
2559 } else if (coex_dm->cur_ps_tdma == 11) {
2560 btc8821a2ant_ps_tdma(
2561 btcoexist, NORMAL_EXEC,
2563 coex_dm->ps_tdma_du_adj_type =
2566 } else if (result == 1) {
2567 if (coex_dm->cur_ps_tdma == 4) {
2568 btc8821a2ant_ps_tdma(
2569 btcoexist, NORMAL_EXEC,
2571 coex_dm->ps_tdma_du_adj_type =
2573 } else if (coex_dm->cur_ps_tdma == 3) {
2574 btc8821a2ant_ps_tdma(
2575 btcoexist, NORMAL_EXEC,
2577 coex_dm->ps_tdma_du_adj_type =
2579 } else if (coex_dm->cur_ps_tdma == 2) {
2580 btc8821a2ant_ps_tdma(
2581 btcoexist, NORMAL_EXEC,
2583 coex_dm->ps_tdma_du_adj_type =
2585 } else if (coex_dm->cur_ps_tdma == 12) {
2586 btc8821a2ant_ps_tdma(
2587 btcoexist, NORMAL_EXEC,
2589 coex_dm->ps_tdma_du_adj_type =
2591 } else if (coex_dm->cur_ps_tdma == 11) {
2592 btc8821a2ant_ps_tdma(
2593 btcoexist, NORMAL_EXEC,
2595 coex_dm->ps_tdma_du_adj_type =
2597 } else if (coex_dm->cur_ps_tdma == 10) {
2598 btc8821a2ant_ps_tdma(
2599 btcoexist, NORMAL_EXEC,
2601 coex_dm->ps_tdma_du_adj_type =
2609 /* if current PsTdma not match with the recorded one
2610 * (when scan, dhcp...), then we have to adjust it back to
2611 * the previous recorded one.
2613 if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) {
2614 bool scan = false, link = false, roam = false;
2616 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2617 "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma = %d, recordPsTdma = %d\n",
2618 coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type);
2620 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2621 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2622 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2624 if (!scan && !link && !roam) {
2625 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2626 coex_dm->ps_tdma_du_adj_type);
2628 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2629 "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
2634 /* SCO only or SCO+PAN(HS)*/
2635 static void btc8821a2ant_action_sco(struct btc_coexist *btcoexist)
2637 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2638 u8 wifi_rssi_state, bt_rssi_state;
2641 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
2642 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist, 2, 35, 0);
2644 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2646 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2647 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 4);
2649 if (BTC_RSSI_HIGH(bt_rssi_state))
2650 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2652 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2654 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2656 if (wifi_bw == BTC_WIFI_BW_LEGACY) {
2657 /* for SCO quality at 11b/g mode */
2658 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2660 /* for SCO quality & wifi performance balance at 11n mode */
2661 if (wifi_bw == BTC_WIFI_BW_HT40) {
2662 btc8821a2ant_coex_table_with_type(btcoexist,
2665 if (bt_link_info->sco_only)
2666 btc8821a2ant_coex_table_with_type(
2667 btcoexist, NORMAL_EXEC, 17);
2669 btc8821a2ant_coex_table_with_type(
2670 btcoexist, NORMAL_EXEC, 12);
2674 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2675 /* for voice quality */
2676 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2679 if (wifi_bw == BTC_WIFI_BW_HT40) {
2680 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2681 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2682 btc8821a2ant_sw_mechanism1(btcoexist, true, true,
2684 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2687 btc8821a2ant_sw_mechanism1(btcoexist, true, true,
2689 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2693 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2694 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2695 btc8821a2ant_sw_mechanism1(btcoexist, false, true,
2697 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2700 btc8821a2ant_sw_mechanism1(btcoexist, false, true,
2702 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2708 static void btc8821a2ant_action_hid(struct btc_coexist *btcoexist)
2710 u8 wifi_rssi_state, bt_rssi_state;
2713 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
2714 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
2715 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2717 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2719 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2720 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2722 if (BTC_RSSI_HIGH(bt_rssi_state))
2723 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2725 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2727 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2729 if (wifi_bw == BTC_WIFI_BW_LEGACY) {
2730 /* for HID at 11b/g mode */
2731 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
2733 /* for HID quality & wifi performance balance at 11n mode */
2734 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2737 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2738 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 24);
2740 if (wifi_bw == BTC_WIFI_BW_HT40) {
2742 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2743 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2744 btc8821a2ant_sw_mechanism1(btcoexist, true, true,
2746 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2749 btc8821a2ant_sw_mechanism1(btcoexist, true, true,
2751 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2756 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2757 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2758 btc8821a2ant_sw_mechanism1(btcoexist, false, true,
2760 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2763 btc8821a2ant_sw_mechanism1(btcoexist, false, true,
2765 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2771 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
2772 static void btc8821a2ant_action_a2dp(struct btc_coexist *btcoexist)
2774 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
2778 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
2779 wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
2780 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
2781 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
2782 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2784 if ((ap_num >= 10) && BTC_RSSI_HIGH(wifi_rssi_state1) &&
2785 BTC_RSSI_HIGH(bt_rssi_state)) {
2786 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2789 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
2791 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
2793 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2794 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2796 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2798 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2800 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
2803 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2804 if (wifi_bw == BTC_WIFI_BW_HT40) {
2805 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2807 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2810 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2812 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2818 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2819 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2821 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2823 if (BTC_RSSI_HIGH(bt_rssi_state))
2824 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2826 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2828 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
2829 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
2830 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2833 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
2834 btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
2838 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2839 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2840 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
2842 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
2846 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2847 if (wifi_bw == BTC_WIFI_BW_HT40) {
2848 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2849 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2850 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2852 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2855 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2857 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2861 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2862 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2863 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2865 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2868 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2870 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2876 static void btc8821a2ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist)
2878 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
2881 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
2882 wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
2883 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
2884 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
2885 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2887 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2889 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2890 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2892 if (BTC_RSSI_HIGH(bt_rssi_state))
2893 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2895 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2897 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
2898 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
2899 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2902 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
2903 btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
2907 btc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 2);
2910 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2911 if (wifi_bw == BTC_WIFI_BW_HT40) {
2912 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2913 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2914 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2916 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2919 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2921 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2925 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2926 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2927 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2929 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2932 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2934 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2940 static void btc8821a2ant_action_pan_edr(struct btc_coexist *btcoexist)
2942 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
2945 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
2946 wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
2947 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
2948 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
2949 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2951 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2953 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2955 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2957 if (BTC_RSSI_HIGH(bt_rssi_state))
2958 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2960 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2962 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
2963 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 10);
2964 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2967 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
2968 btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
2972 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2973 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
2974 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 26);
2976 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 26);
2979 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2980 if (wifi_bw == BTC_WIFI_BW_HT40) {
2981 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2982 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2983 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2985 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2988 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2990 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2994 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2995 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2996 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2998 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3001 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
3003 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3010 static void btc8821a2ant_action_pan_hs(struct btc_coexist *btcoexist)
3012 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3015 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
3016 wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3017 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3018 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
3019 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3021 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3023 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3024 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3026 if (BTC_RSSI_HIGH(bt_rssi_state))
3027 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3029 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3031 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3032 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3033 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
3035 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3036 if (wifi_bw == BTC_WIFI_BW_HT40) {
3037 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3038 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3039 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
3041 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3044 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
3046 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3050 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3051 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3052 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
3054 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3057 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
3059 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3066 static void btc8821a2ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist)
3068 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3071 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
3072 wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3073 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3074 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
3075 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3077 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3079 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3081 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3083 if (BTC_RSSI_HIGH(bt_rssi_state))
3084 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3086 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3088 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state))
3089 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3092 btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3095 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3097 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3098 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3099 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 12);
3101 if (wifi_bw == BTC_WIFI_BW_HT40)
3102 btc8821a2ant_tdma_duration_adjust(btcoexist, false,
3105 btc8821a2ant_tdma_duration_adjust(btcoexist, false,
3108 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
3109 btc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 3);
3113 if (wifi_bw == BTC_WIFI_BW_HT40) {
3114 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3115 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3116 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
3118 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3121 btc8821a2ant_sw_mechanism1(btcoexist, true, false,
3123 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3127 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3128 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3129 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
3131 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3134 btc8821a2ant_sw_mechanism1(btcoexist, false, false,
3136 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3142 static void btc8821a2ant_action_pan_edr_hid(struct btc_coexist *btcoexist)
3144 u8 wifi_rssi_state, bt_rssi_state;
3147 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
3148 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
3149 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3151 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3153 if (BTC_RSSI_HIGH(bt_rssi_state))
3154 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
3156 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
3158 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3160 if (wifi_bw == BTC_WIFI_BW_LEGACY) {
3161 /* for HID at 11b/g mode */
3162 btc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
3163 0x5a5f5a5f, 0xffff, 0x3);
3165 /* for HID quality & wifi performance balance at 11n mode */
3166 btc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
3167 0x5a5f5a5f, 0xffff, 0x3);
3170 if (wifi_bw == BTC_WIFI_BW_HT40) {
3171 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 3);
3173 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3174 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3175 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3178 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
3182 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3183 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3184 btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3186 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3189 btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3191 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3195 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3197 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3198 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3199 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
3201 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
3205 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3206 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3207 btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3209 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3212 btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3214 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3220 /* HID+A2DP+PAN(EDR) */
3221 static void btc8821a2ant_act_hid_a2dp_pan_edr(struct btc_coexist *btcoexist)
3223 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3226 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
3227 wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3228 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3229 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
3230 2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3232 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3234 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3235 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3237 if (BTC_RSSI_HIGH(bt_rssi_state))
3238 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3240 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3242 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
3243 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3244 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3247 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14);
3248 btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3252 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3254 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3255 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3256 if (wifi_bw == BTC_WIFI_BW_HT40)
3257 btc8821a2ant_tdma_duration_adjust(btcoexist, true,
3260 btc8821a2ant_tdma_duration_adjust(btcoexist, true,
3263 btc8821a2ant_tdma_duration_adjust(btcoexist, true, true, 3);
3267 if (wifi_bw == BTC_WIFI_BW_HT40) {
3268 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3269 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3270 btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3272 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3275 btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3277 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3281 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3282 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3283 btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3285 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3288 btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3290 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3296 static void btc8821a2ant_action_hid_a2dp(struct btc_coexist *btcoexist)
3299 u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3302 wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
3303 wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3304 BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3305 bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
3306 3, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 37);
3308 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3310 btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x5);
3311 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3313 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3314 if (wifi_bw == BTC_WIFI_BW_LEGACY) {
3315 if (BTC_RSSI_HIGH(bt_rssi_state))
3316 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3317 else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3318 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3320 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3322 /* only 802.11N mode we have to dec bt power to 4 degree */
3323 if (BTC_RSSI_HIGH(bt_rssi_state)) {
3324 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
3327 btc8821a2ant_dec_bt_pwr(btcoexist,
3330 btc8821a2ant_dec_bt_pwr(btcoexist,
3332 } else if (BTC_RSSI_MEDIUM(bt_rssi_state)) {
3333 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3335 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3339 if (wifi_bw == BTC_WIFI_BW_LEGACY) {
3340 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3341 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3344 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14);
3345 btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3349 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3350 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3351 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
3353 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
3357 if (wifi_bw == BTC_WIFI_BW_HT40) {
3358 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3359 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3360 btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3362 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3365 btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3367 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3371 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3372 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3373 btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3375 btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3378 btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3380 btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3386 static void btc8821a2ant_action_wifi_multi_port(struct btc_coexist *btcoexist)
3388 btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3389 btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3392 btc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
3393 btc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
3396 btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3398 btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3399 btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
3402 static void btc8821a2ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
3404 struct rtl_priv *rtlpriv = btcoexist->adapter;
3405 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3406 bool wifi_under_5g = false;
3408 u32 num_of_wifi_link = 0;
3409 u32 wifi_link_status = 0;
3410 bool miracast_plus_bt = false;
3411 bool scan = false, link = false, roam = false;
3413 if (btcoexist->manual_control) {
3414 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3415 "[BTCoex], Manual control!!!\n");
3419 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3421 if (wifi_under_5g) {
3422 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3423 "[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n");
3424 btc8821a2ant_coex_under_5g(btcoexist);
3428 if (coex_sta->under_ips) {
3429 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3430 "[BTCoex], wifi is under IPS !!!\n");
3434 algorithm = btc8821a2ant_action_algorithm(btcoexist);
3435 if (coex_sta->c2h_bt_inquiry_page &&
3436 (BT_8821A_2ANT_COEX_ALGO_PANHS != algorithm)) {
3437 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3438 "[BTCoex], BT is under inquiry/page scan !!\n");
3439 btc8821a2ant_action_bt_inquiry(btcoexist);
3443 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3444 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3445 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3447 if (scan || link || roam) {
3448 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3449 "[BTCoex], WiFi is under Link Process !!\n");
3450 btc8821a2ant_action_wifi_link_process(btcoexist);
3455 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3457 num_of_wifi_link = wifi_link_status >> 16;
3459 if ((num_of_wifi_link >= 2) ||
3460 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
3461 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3462 "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
3463 num_of_wifi_link, wifi_link_status);
3465 if (bt_link_info->bt_link_exist)
3466 miracast_plus_bt = true;
3468 miracast_plus_bt = false;
3470 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3472 btc8821a2ant_action_wifi_multi_port(btcoexist);
3477 miracast_plus_bt = false;
3478 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3481 coex_dm->cur_algorithm = algorithm;
3482 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3483 "[BTCoex], Algorithm = %d\n", coex_dm->cur_algorithm);
3485 if (btc8821a2ant_is_common_action(btcoexist)) {
3486 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3487 "[BTCoex], Action 2-Ant common\n");
3488 coex_dm->auto_tdma_adjust = true;
3490 if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
3491 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3492 "[BTCoex], pre_algorithm = %d, cur_algorithm = %d\n",
3493 coex_dm->pre_algorithm,
3494 coex_dm->cur_algorithm);
3495 coex_dm->auto_tdma_adjust = false;
3497 switch (coex_dm->cur_algorithm) {
3498 case BT_8821A_2ANT_COEX_ALGO_SCO:
3499 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3500 "[BTCoex], Action 2-Ant, algorithm = SCO\n");
3501 btc8821a2ant_action_sco(btcoexist);
3503 case BT_8821A_2ANT_COEX_ALGO_HID:
3504 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3505 "[BTCoex], Action 2-Ant, algorithm = HID\n");
3506 btc8821a2ant_action_hid(btcoexist);
3508 case BT_8821A_2ANT_COEX_ALGO_A2DP:
3509 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3510 "[BTCoex], Action 2-Ant, algorithm = A2DP\n");
3511 btc8821a2ant_action_a2dp(btcoexist);
3513 case BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS:
3514 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3515 "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS)\n");
3516 btc8821a2ant_action_a2dp_pan_hs(btcoexist);
3518 case BT_8821A_2ANT_COEX_ALGO_PANEDR:
3519 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3520 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)\n");
3521 btc8821a2ant_action_pan_edr(btcoexist);
3523 case BT_8821A_2ANT_COEX_ALGO_PANHS:
3524 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3525 "[BTCoex], Action 2-Ant, algorithm = HS mode\n");
3526 btc8821a2ant_action_pan_hs(btcoexist);
3528 case BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP:
3529 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3530 "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP\n");
3531 btc8821a2ant_action_pan_edr_a2dp(btcoexist);
3533 case BT_8821A_2ANT_COEX_ALGO_PANEDR_HID:
3534 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3535 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID\n");
3536 btc8821a2ant_action_pan_edr_hid(btcoexist);
3538 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
3539 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3540 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN\n");
3541 btc8821a2ant_act_hid_a2dp_pan_edr(btcoexist);
3543 case BT_8821A_2ANT_COEX_ALGO_HID_A2DP:
3544 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3545 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP\n");
3546 btc8821a2ant_action_hid_a2dp(btcoexist);
3549 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3550 "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3551 btc8821a2ant_coex_all_off(btcoexist);
3554 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3558 static void btc8821a2ant_wifi_off_hw_cfg(struct btc_coexist *btcoexist)
3560 u8 h2c_parameter[2] = {0};
3563 /* set wlan_act to low */
3564 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
3566 /* WiFi goto standby while GNT_BT 0-->1 */
3567 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
3568 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3569 if (fw_ver >= 0x180000) {
3570 /* Use H2C to set GNT_BT to HIGH */
3571 h2c_parameter[0] = 1;
3572 btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, h2c_parameter);
3574 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18);
3578 /**************************************************************
3579 * extern function start with ex_btc8821a2ant_
3580 **************************************************************/
3581 void ex_btc8821a2ant_init_hwconfig(struct btc_coexist *btcoexist)
3583 struct rtl_priv *rtlpriv = btcoexist->adapter;
3586 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3587 "[BTCoex], 2Ant Init HW Config!!\n");
3589 /* backup rf 0x1e value */
3590 coex_dm->bt_rf0x1e_backup =
3591 btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff);
3593 /* 0x790[5:0] = 0x5 */
3594 u1tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
3597 btcoexist->btc_write_1byte(btcoexist, 0x790, u1tmp);
3599 /* Antenna config */
3600 btc8821a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_MAIN, true, false);
3601 coex_sta->dis_ver_info_cnt = 0;
3604 btc8821a2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
3606 /* Enable counter statistics */
3607 /* 0x76e[3] = 1, WLAN_Act control by PTA */
3608 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
3609 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
3610 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
3613 void ex_btc8821a2ant_pre_load_firmware(struct btc_coexist *btcoexist)
3615 struct btc_board_info *board_info = &btcoexist->board_info;
3616 u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */
3619 * S0 or S1 setting and Local register setting(By the setting fw can get
3620 * ant number, S0/S1, ... info)
3622 * Local setting bit define
3623 * BIT0: "0" for no antenna inverse; "1" for antenna inverse
3624 * BIT1: "0" for internal switch; "1" for external switch
3625 * BIT2: "0" for one antenna; "1" for two antenna
3626 * NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and
3629 if (btcoexist->chip_interface == BTC_INTF_USB) {
3630 /* fixed at S0 for USB interface */
3631 u8tmp |= 0x1; /* antenna inverse */
3632 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
3634 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
3635 if (board_info->single_ant_path == 0) {
3636 } else if (board_info->single_ant_path == 1) {
3638 u8tmp |= 0x1; /* antenna inverse */
3641 if (btcoexist->chip_interface == BTC_INTF_PCI)
3642 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384,
3644 else if (btcoexist->chip_interface == BTC_INTF_SDIO)
3645 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60,
3650 void ex_btc8821a2ant_init_coex_dm(struct btc_coexist *btcoexist)
3652 struct rtl_priv *rtlpriv = btcoexist->adapter;
3654 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3655 "[BTCoex], Coex Mechanism Init!!\n");
3657 btc8821a2ant_init_coex_dm(btcoexist);
3660 void ex_btc8821a2ant_display_coex_info(struct btc_coexist *btcoexist)
3662 struct btc_board_info *board_info = &btcoexist->board_info;
3663 struct btc_stack_info *stack_info = &btcoexist->stack_info;
3664 struct rtl_priv *rtlpriv = btcoexist->adapter;
3665 u8 u1tmp[4], i, bt_info_ext, ps_tdma_case = 0;
3667 bool roam = false, scan = false, link = false, wifi_under_5g = false;
3668 bool bt_hs_on = false, wifi_busy = false;
3669 long wifi_rssi = 0, bt_hs_rssi = 0;
3670 u32 wifi_bw, wifi_traffic_dir;
3671 u8 wifi_dot_11_chnl, wifi_hs_chnl;
3672 u32 fw_ver = 0, bt_patch_ver = 0;
3674 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3675 "\r\n ============[BT Coexist info]============");
3677 if (!board_info->bt_exist) {
3678 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n BT not exists !!!");
3682 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3683 "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:",
3684 board_info->pg_ant_num, board_info->btdm_ant_num);
3686 if (btcoexist->manual_control) {
3687 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3688 "\r\n %-35s", "[Action Manual control]!!");
3691 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3692 "\r\n %-35s = %s / %d", "BT stack/ hci ext ver",
3693 ((stack_info->profile_notified) ? "Yes" : "No"),
3694 stack_info->hci_version);
3696 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3697 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3698 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3699 "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
3700 "CoexVer/ FwVer/ PatchVer",
3701 glcoex_ver_date_8821a_2ant, glcoex_ver_8821a_2ant,
3702 fw_ver, bt_patch_ver, bt_patch_ver);
3704 btcoexist->btc_get(btcoexist,
3705 BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3706 btcoexist->btc_get(btcoexist,
3707 BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_dot_11_chnl);
3708 btcoexist->btc_get(btcoexist,
3709 BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
3710 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3711 "\r\n %-35s = %d / %d(%d)",
3712 "Dot11 channel / HsMode(HsChnl)",
3713 wifi_dot_11_chnl, bt_hs_on, wifi_hs_chnl);
3715 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3716 "\r\n %-35s = %3ph ",
3717 "H2C Wifi inform bt chnl Info",
3718 coex_dm->wifi_chnl_info);
3720 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
3721 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
3722 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3723 "\r\n %-35s = %ld/ %ld", "Wifi rssi/ HS rssi",
3724 wifi_rssi, bt_hs_rssi);
3726 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3727 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3728 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3729 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3730 "\r\n %-35s = %d/ %d/ %d ", "Wifi link/ roam/ scan",
3733 btcoexist->btc_get(btcoexist,
3734 BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3735 btcoexist->btc_get(btcoexist,
3736 BTC_GET_U4_WIFI_BW, &wifi_bw);
3737 btcoexist->btc_get(btcoexist,
3738 BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3739 btcoexist->btc_get(btcoexist,
3740 BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifi_traffic_dir);
3741 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3742 "\r\n %-35s = %s / %s/ %s ", "Wifi status",
3743 (wifi_under_5g ? "5G" : "2.4G"),
3744 ((BTC_WIFI_BW_LEGACY == wifi_bw) ? "Legacy" :
3745 (((BTC_WIFI_BW_HT40 == wifi_bw) ? "HT40" : "HT20"))),
3746 ((!wifi_busy) ? "idle" :
3747 ((BTC_WIFI_TRAFFIC_TX == wifi_traffic_dir) ?
3748 "uplink" : "downlink")));
3750 if (stack_info->profile_notified) {
3751 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3752 "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
3753 stack_info->sco_exist, stack_info->hid_exist,
3754 stack_info->pan_exist, stack_info->a2dp_exist);
3756 btcoexist->btc_disp_dbg_msg(btcoexist,
3757 BTC_DBG_DISP_BT_LINK_INFO);
3760 bt_info_ext = coex_sta->bt_info_ext;
3761 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s",
3762 "BT Info A2DP rate",
3763 (bt_info_ext&BIT0) ? "Basic rate" : "EDR rate");
3765 for (i = 0; i < BT_INFO_SRC_8821A_2ANT_MAX; i++) {
3766 if (coex_sta->bt_info_c2h_cnt[i]) {
3767 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3768 "\r\n %-35s = %7ph(%d)",
3769 glbt_info_src_8821a_2ant[i],
3770 coex_sta->bt_info_c2h[i],
3771 coex_sta->bt_info_c2h_cnt[i]);
3775 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s/%s",
3776 "PS state, IPS/LPS",
3777 ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
3778 ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")));
3779 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
3782 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
3783 "============[Sw mechanism]============");
3784 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3785 "\r\n %-35s = %d/ %d/ %d(0x%x) ",
3786 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
3787 coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
3788 coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
3791 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
3792 "============[Fw mechanism]============");
3794 if (!btcoexist->manual_control) {
3795 ps_tdma_case = coex_dm->cur_ps_tdma;
3796 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3797 "\r\n %-35s = %5ph case-%d",
3799 coex_dm->ps_tdma_para, ps_tdma_case);
3801 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3802 "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct",
3803 coex_dm->cur_dec_bt_pwr_lvl,
3804 coex_dm->cur_ignore_wlan_act);
3808 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3809 "\r\n %-35s", "============[Hw setting]============");
3811 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3812 "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal",
3813 coex_dm->bt_rf0x1e_backup);
3815 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
3816 u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
3817 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x ",
3818 "0x778 (W_Act)/ 0x6cc (CoTab Sel)",
3819 u1tmp[0], u1tmp[1]);
3821 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
3822 u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xc5b);
3823 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3824 "0x8db(ADC)/0xc5b[29:25](DAC)",
3825 ((u1tmp[0] & 0x60) >> 5), ((u1tmp[1] & 0x3e) >> 1));
3827 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
3828 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3829 "0xcb4[7:0](ctrl)/ 0xcb4[29:28](val)",
3830 u4tmp[0] & 0xff, ((u4tmp[0] & 0x30000000) >> 28));
3832 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
3833 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
3834 u4tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x974);
3835 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3836 "0x40/ 0x4c[24:23]/ 0x974",
3837 u1tmp[0], ((u4tmp[0] & 0x01800000) >> 23), u4tmp[1]);
3839 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
3840 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
3841 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3842 "0x550(bcn ctrl)/0x522",
3843 u4tmp[0], u1tmp[0]);
3845 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
3846 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa0a);
3847 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3848 "0xc50(DIG)/0xa0a(CCK-TH)",
3849 u4tmp[0], u1tmp[0]);
3851 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48);
3852 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
3853 u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
3854 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
3856 u4tmp[0], (u1tmp[0] << 8) + u1tmp[1]);
3858 u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
3859 u4tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
3860 u4tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
3861 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
3862 "0x6c0/0x6c4/0x6c8",
3863 u4tmp[0], u4tmp[1], u4tmp[2]);
3865 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
3866 "0x770 (hi-pri Rx/Tx)",
3867 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
3868 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
3869 "0x774(low-pri Rx/Tx)",
3870 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
3872 /* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang*/
3873 u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x41b);
3874 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x",
3875 "0x41b (mgntQ hang chk == 0xf)",
3878 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
3881 void ex_btc8821a2ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
3883 struct rtl_priv *rtlpriv = btcoexist->adapter;
3885 if (BTC_IPS_ENTER == type) {
3886 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3887 "[BTCoex], IPS ENTER notify\n");
3888 coex_sta->under_ips = true;
3889 btc8821a2ant_wifi_off_hw_cfg(btcoexist);
3890 btc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3891 btc8821a2ant_coex_all_off(btcoexist);
3892 } else if (BTC_IPS_LEAVE == type) {
3893 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3894 "[BTCoex], IPS LEAVE notify\n");
3895 coex_sta->under_ips = false;
3896 ex_btc8821a2ant_init_hwconfig(btcoexist);
3897 btc8821a2ant_init_coex_dm(btcoexist);
3898 btc8821a2ant_query_bt_info(btcoexist);
3902 void ex_btc8821a2ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
3904 struct rtl_priv *rtlpriv = btcoexist->adapter;
3906 if (BTC_LPS_ENABLE == type) {
3907 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3908 "[BTCoex], LPS ENABLE notify\n");
3909 coex_sta->under_lps = true;
3910 } else if (BTC_LPS_DISABLE == type) {
3911 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3912 "[BTCoex], LPS DISABLE notify\n");
3913 coex_sta->under_lps = false;
3917 void ex_btc8821a2ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
3919 struct rtl_priv *rtlpriv = btcoexist->adapter;
3921 if (BTC_SCAN_START == type) {
3922 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3923 "[BTCoex], SCAN START notify\n");
3924 } else if (BTC_SCAN_FINISH == type) {
3925 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3926 "[BTCoex], SCAN FINISH notify\n");
3930 void ex_btc8821a2ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
3932 struct rtl_priv *rtlpriv = btcoexist->adapter;
3934 if (BTC_ASSOCIATE_START == type) {
3935 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3936 "[BTCoex], CONNECT START notify\n");
3937 } else if (BTC_ASSOCIATE_FINISH == type) {
3938 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3939 "[BTCoex], CONNECT FINISH notify\n");
3943 void ex_btc8821a2ant_media_status_notify(struct btc_coexist *btcoexist,
3946 struct rtl_priv *rtlpriv = btcoexist->adapter;
3947 u8 h2c_parameter[3] = {0};
3949 u8 wifi_central_chnl;
3952 if (BTC_MEDIA_CONNECT == type) {
3953 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3954 "[BTCoex], MEDIA connect notify\n");
3956 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3957 "[BTCoex], MEDIA disconnect notify\n");
3960 /* only 2.4G we need to inform bt the chnl mask */
3961 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
3962 &wifi_central_chnl);
3963 if ((BTC_MEDIA_CONNECT == type) &&
3964 (wifi_central_chnl <= 14)) {
3965 h2c_parameter[0] = 0x1;
3966 h2c_parameter[1] = wifi_central_chnl;
3967 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3968 if (wifi_bw == BTC_WIFI_BW_HT40) {
3969 h2c_parameter[2] = 0x30;
3971 h2c_parameter[2] = 0x20;
3973 h2c_parameter[2] = 0x30;
3975 h2c_parameter[2] = 0x20;
3979 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
3980 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
3981 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
3983 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3984 "[BTCoex], FW write 0x66 = 0x%x\n",
3985 h2c_parameter[0] << 16 |
3986 h2c_parameter[1] << 8 |
3989 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
3992 void ex_btc8821a2ant_special_packet_notify(struct btc_coexist *btcoexist,
3995 struct rtl_priv *rtlpriv = btcoexist->adapter;
3997 if (type == BTC_PACKET_DHCP) {
3998 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3999 "[BTCoex], DHCP Packet notify\n");
4003 void ex_btc8821a2ant_bt_info_notify(struct btc_coexist *btcoexist,
4004 u8 *tmp_buf, u8 length)
4006 struct rtl_priv *rtlpriv = btcoexist->adapter;
4008 u8 i, rsp_source = 0;
4009 bool bt_busy = false, limited_dig = false;
4010 bool wifi_connected = false, wifi_under_5g = false;
4012 coex_sta->c2h_bt_info_req_sent = false;
4013 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4014 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
4017 rsp_source = tmp_buf[0] & 0xf;
4018 if (rsp_source >= BT_INFO_SRC_8821A_2ANT_MAX)
4019 rsp_source = BT_INFO_SRC_8821A_2ANT_WIFI_FW;
4020 coex_sta->bt_info_c2h_cnt[rsp_source]++;
4022 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4023 "[BTCoex], Bt info[%d], length = %d, hex data = [",
4024 rsp_source, length);
4025 for (i = 0; i < length; i++) {
4026 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
4028 bt_info = tmp_buf[i];
4029 if (i == length - 1) {
4030 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4031 "0x%02x]\n", tmp_buf[i]);
4033 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4034 "0x%02x, ", tmp_buf[i]);
4038 if (btcoexist->manual_control) {
4039 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4040 "[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n");
4044 if (BT_INFO_SRC_8821A_2ANT_WIFI_FW != rsp_source) {
4046 coex_sta->bt_retry_cnt =
4047 coex_sta->bt_info_c2h[rsp_source][2]&0xf;
4050 coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
4052 coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4];
4054 coex_sta->bt_tx_rx_mask =
4055 (coex_sta->bt_info_c2h[rsp_source][2] & 0x40);
4056 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
4057 &coex_sta->bt_tx_rx_mask);
4058 if (coex_sta->bt_tx_rx_mask) {
4059 /* BT into is responded by BT FW and BT RF REG 0x3C !=
4060 * 0x01 => Need to switch BT TRx Mask
4062 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4063 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n");
4064 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
4068 /* Here we need to resend some wifi info to BT
4069 * because bt is reset and loss of the info
4071 if ((coex_sta->bt_info_ext & BIT1)) {
4072 btcoexist->btc_get(btcoexist,
4073 BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
4074 if (wifi_connected) {
4075 ex_btc8821a2ant_media_status_notify(btcoexist,
4078 ex_btc8821a2ant_media_status_notify(btcoexist,
4079 BTC_MEDIA_DISCONNECT);
4084 if (!btcoexist->manual_control && !wifi_under_5g) {
4085 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4086 "[BTCoex], BT ext info = 0x%x!!\n",
4087 coex_sta->bt_info_ext);
4088 if ((coex_sta->bt_info_ext & BIT(3))) {
4089 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4090 "[BTCoex], BT ext info bit3=1, wifi_connected=%d\n",
4092 if (wifi_connected) {
4093 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
4095 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
4096 btc8821a2ant_ignore_wlan_act(btcoexist,
4101 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4102 "[BTCoex], BT ext info bit3=0, wifi_connected=%d\n",
4104 /* BT already NOT ignore Wlan active, do nothing
4107 if (!wifi_connected) {
4108 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
4110 "[BTCoex], BT ext info bit3 check, set BT to ignore Wlan active!!\n");
4111 btc8821a2ant_ignore_wlan_act(
4112 btcoexist, FORCE_EXEC, true);
4118 /* check BIT2 first ==> check if bt is under inquiry or page scan*/
4119 if (bt_info & BT_INFO_8821A_2ANT_B_INQ_PAGE) {
4120 coex_sta->c2h_bt_inquiry_page = true;
4122 coex_sta->c2h_bt_inquiry_page = false;
4124 /* set link exist status */
4125 if (!(bt_info & BT_INFO_8821A_2ANT_B_CONNECTION)) {
4126 coex_sta->bt_link_exist = false;
4127 coex_sta->pan_exist = false;
4128 coex_sta->a2dp_exist = false;
4129 coex_sta->hid_exist = false;
4130 coex_sta->sco_exist = false;
4131 } else { /* connection exists */
4132 coex_sta->bt_link_exist = true;
4133 if (bt_info & BT_INFO_8821A_2ANT_B_FTP)
4134 coex_sta->pan_exist = true;
4136 coex_sta->pan_exist = false;
4137 if (bt_info & BT_INFO_8821A_2ANT_B_A2DP)
4138 coex_sta->a2dp_exist = true;
4140 coex_sta->a2dp_exist = false;
4141 if (bt_info & BT_INFO_8821A_2ANT_B_HID)
4142 coex_sta->hid_exist = true;
4144 coex_sta->hid_exist = false;
4145 if (bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO)
4146 coex_sta->sco_exist = true;
4148 coex_sta->sco_exist = false;
4150 if ((!coex_sta->hid_exist) &&
4151 (!coex_sta->c2h_bt_inquiry_page) &&
4152 (!coex_sta->sco_exist)) {
4153 if (coex_sta->high_priority_tx +
4154 coex_sta->high_priority_rx >= 160)
4155 coex_sta->hid_exist = true;
4159 btc8821a2ant_update_bt_link_info(btcoexist);
4161 if (!(bt_info & BT_INFO_8821A_2ANT_B_CONNECTION)) {
4162 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_IDLE;
4163 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4164 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
4165 } else if (bt_info == BT_INFO_8821A_2ANT_B_CONNECTION) {
4166 /* connection exists but no busy */
4167 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_CON_IDLE;
4168 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4169 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
4170 } else if ((bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO) ||
4171 (bt_info & BT_INFO_8821A_2ANT_B_SCO_BUSY)) {
4172 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_SCO_BUSY;
4173 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4174 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
4175 } else if (bt_info & BT_INFO_8821A_2ANT_B_ACL_BUSY) {
4176 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_ACL_BUSY;
4177 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4178 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
4180 coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_MAX;
4181 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4182 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
4185 if ((coex_dm->bt_status == BT_8821A_2ANT_BT_STATUS_ACL_BUSY) ||
4186 (coex_dm->bt_status == BT_8821A_2ANT_BT_STATUS_SCO_BUSY) ||
4187 (coex_dm->bt_status == BT_8821A_2ANT_BT_STATUS_ACL_SCO_BUSY)) {
4192 limited_dig = false;
4195 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
4197 coex_dm->limited_dig = limited_dig;
4198 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
4200 btc8821a2ant_run_coexist_mechanism(btcoexist);
4203 void ex_btc8821a2ant_halt_notify(struct btc_coexist *btcoexist)
4205 struct rtl_priv *rtlpriv = btcoexist->adapter;
4207 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4208 "[BTCoex], Halt notify\n");
4210 btc8821a2ant_wifi_off_hw_cfg(btcoexist);
4211 btc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
4212 ex_btc8821a2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
4215 void ex_btc8821a2ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
4217 struct rtl_priv *rtlpriv = btcoexist->adapter;
4219 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Pnp notify\n");
4221 if (pnp_state == BTC_WIFI_PNP_SLEEP) {
4222 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4223 "[BTCoex], Pnp notify to SLEEP\n");
4224 } else if (pnp_state == BTC_WIFI_PNP_WAKE_UP) {
4225 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4226 "[BTCoex], Pnp notify to WAKE UP\n");
4227 ex_btc8821a2ant_init_hwconfig(btcoexist);
4228 btc8821a2ant_init_coex_dm(btcoexist);
4229 btc8821a2ant_query_bt_info(btcoexist);
4233 void ex_btc8821a2ant_periodical(struct btc_coexist *btcoexist)
4235 struct rtl_priv *rtlpriv = btcoexist->adapter;
4237 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4238 "[BTCoex], ==========================Periodical===========================\n");
4240 if (coex_sta->dis_ver_info_cnt <= 5) {
4241 coex_sta->dis_ver_info_cnt += 1;
4242 if (coex_sta->dis_ver_info_cnt == 3) {
4243 /* Antenna config to set 0x765 = 0x0 (GNT_BT control by
4244 * PTA) after initial
4246 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4247 "[BTCoex], Set GNT_BT control by PTA\n");
4248 btc8821a2ant_set_ant_path(btcoexist,
4249 BTC_ANT_WIFI_AT_MAIN, false, false);
4253 if (btcoexist->auto_report_2ant) {
4254 btc8821a2ant_query_bt_info(btcoexist);
4256 btc8821a2ant_monitor_bt_ctr(btcoexist);
4257 btc8821a2ant_monitor_wifi_ctr(btcoexist);
4259 if (btc8821a2ant_is_wifi_status_changed(btcoexist) ||
4260 coex_dm->auto_tdma_adjust)
4261 btc8821a2ant_run_coexist_mechanism(btcoexist);