1 /* ************************************************************
4 * This file is for 8821A_1ANT Co-exist mechanism
7 * 2012/11/15 Cosa first check in.
9 * ************************************************************
10 * SY modify 2015/04/27
11 * ************************************************************
13 * ************************************************************ */
14 #include "mp_precomp.h"
16 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
18 #if (RTL8821A_SUPPORT == 1)
19 /* ************************************************************
20 * Global variables, these are static variables
21 * ************************************************************ */
22 static u8 *trace_buf = &gl_btc_trace_buf[0];
23 static struct coex_dm_8821a_1ant glcoex_dm_8821a_1ant;
24 static struct coex_dm_8821a_1ant *coex_dm = &glcoex_dm_8821a_1ant;
25 static struct coex_sta_8821a_1ant glcoex_sta_8821a_1ant;
26 static struct coex_sta_8821a_1ant *coex_sta = &glcoex_sta_8821a_1ant;
28 const char *const glbt_info_src_8821a_1ant[] = {
31 "BT Info[bt auto report]",
34 u32 glcoex_ver_date_8821a_1ant = 20161128;
35 u32 glcoex_ver_8821a_1ant = 0x64;
36 u32 glcoex_ver_btdesired_8821a_1ant = 0x62;
38 /* ************************************************************
39 * local function proto type if needed
40 * ************************************************************
41 * ************************************************************
42 * local function start with halbtc8821a1ant_
43 * ************************************************************ */
44 u8 halbtc8821a1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
47 u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
49 bt_rssi = coex_sta->bt_rssi;
52 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
53 (coex_sta->pre_bt_rssi_state ==
54 BTC_RSSI_STATE_STAY_LOW)) {
55 if (bt_rssi >= (rssi_thresh +
56 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
57 bt_rssi_state = BTC_RSSI_STATE_HIGH;
59 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
61 if (bt_rssi < rssi_thresh)
62 bt_rssi_state = BTC_RSSI_STATE_LOW;
64 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
66 } else if (level_num == 3) {
67 if (rssi_thresh > rssi_thresh1) {
68 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
69 "[BTCoex], BT Rssi thresh error!!\n");
71 return coex_sta->pre_bt_rssi_state;
74 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
75 (coex_sta->pre_bt_rssi_state ==
76 BTC_RSSI_STATE_STAY_LOW)) {
77 if (bt_rssi >= (rssi_thresh +
78 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
79 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
81 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
82 } else if ((coex_sta->pre_bt_rssi_state ==
83 BTC_RSSI_STATE_MEDIUM) ||
84 (coex_sta->pre_bt_rssi_state ==
85 BTC_RSSI_STATE_STAY_MEDIUM)) {
86 if (bt_rssi >= (rssi_thresh1 +
87 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
88 bt_rssi_state = BTC_RSSI_STATE_HIGH;
89 else if (bt_rssi < rssi_thresh)
90 bt_rssi_state = BTC_RSSI_STATE_LOW;
92 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
94 if (bt_rssi < rssi_thresh1)
95 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
97 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
101 coex_sta->pre_bt_rssi_state = bt_rssi_state;
103 return bt_rssi_state;
106 u8 halbtc8821a1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
107 IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
110 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
112 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
114 if (level_num == 2) {
115 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
117 (coex_sta->pre_wifi_rssi_state[index] ==
118 BTC_RSSI_STATE_STAY_LOW)) {
119 if (wifi_rssi >= (rssi_thresh +
120 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
121 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
123 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
125 if (wifi_rssi < rssi_thresh)
126 wifi_rssi_state = BTC_RSSI_STATE_LOW;
128 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
130 } else if (level_num == 3) {
131 if (rssi_thresh > rssi_thresh1) {
132 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
133 "[BTCoex], wifi RSSI thresh error!!\n");
134 BTC_TRACE(trace_buf);
135 return coex_sta->pre_wifi_rssi_state[index];
138 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
140 (coex_sta->pre_wifi_rssi_state[index] ==
141 BTC_RSSI_STATE_STAY_LOW)) {
142 if (wifi_rssi >= (rssi_thresh +
143 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
144 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
146 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
147 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
148 BTC_RSSI_STATE_MEDIUM) ||
149 (coex_sta->pre_wifi_rssi_state[index] ==
150 BTC_RSSI_STATE_STAY_MEDIUM)) {
151 if (wifi_rssi >= (rssi_thresh1 +
152 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
153 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
154 else if (wifi_rssi < rssi_thresh)
155 wifi_rssi_state = BTC_RSSI_STATE_LOW;
157 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
159 if (wifi_rssi < rssi_thresh1)
160 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
162 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
166 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
168 return wifi_rssi_state;
171 void halbtc8821a1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
172 IN boolean force_exec, IN u32 dis_rate_mask)
174 coex_dm->cur_ra_mask = dis_rate_mask;
176 if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
177 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
178 &coex_dm->cur_ra_mask);
179 coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
182 void halbtc8821a1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
183 IN boolean force_exec, IN u8 type)
185 boolean wifi_under_b_mode = false;
187 coex_dm->cur_arfr_type = type;
189 if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
190 switch (coex_dm->cur_arfr_type) {
191 case 0: /* normal mode */
192 btcoexist->btc_write_4byte(btcoexist, 0x430,
193 coex_dm->backup_arfr_cnt1);
194 btcoexist->btc_write_4byte(btcoexist, 0x434,
195 coex_dm->backup_arfr_cnt2);
198 btcoexist->btc_get(btcoexist,
199 BTC_GET_BL_WIFI_UNDER_B_MODE,
201 if (wifi_under_b_mode) {
202 btcoexist->btc_write_4byte(btcoexist,
204 btcoexist->btc_write_4byte(btcoexist,
207 btcoexist->btc_write_4byte(btcoexist,
209 btcoexist->btc_write_4byte(btcoexist,
218 coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
221 void halbtc8821a1ant_retry_limit(IN struct btc_coexist *btcoexist,
222 IN boolean force_exec, IN u8 type)
224 coex_dm->cur_retry_limit_type = type;
227 (coex_dm->pre_retry_limit_type !=
228 coex_dm->cur_retry_limit_type)) {
229 switch (coex_dm->cur_retry_limit_type) {
230 case 0: /* normal mode */
231 btcoexist->btc_write_2byte(btcoexist, 0x42a,
232 coex_dm->backup_retry_limit);
234 case 1: /* retry limit=8 */
235 btcoexist->btc_write_2byte(btcoexist, 0x42a,
243 coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
246 void halbtc8821a1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
247 IN boolean force_exec, IN u8 type)
249 coex_dm->cur_ampdu_time_type = type;
252 (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
253 switch (coex_dm->cur_ampdu_time_type) {
254 case 0: /* normal mode */
255 btcoexist->btc_write_1byte(btcoexist, 0x456,
256 coex_dm->backup_ampdu_max_time);
258 case 1: /* AMPDU timw = 0x38 * 32us */
259 btcoexist->btc_write_1byte(btcoexist, 0x456,
267 coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
270 void halbtc8821a1ant_limited_tx(IN struct btc_coexist *btcoexist,
271 IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
272 IN u8 retry_limit_type, IN u8 ampdu_time_type)
274 switch (ra_mask_type) {
275 case 0: /* normal mode */
276 halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
279 case 1: /* disable cck 1/2 */
280 halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
283 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
284 halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
291 halbtc8821a1ant_auto_rate_fallback_retry(btcoexist, force_exec,
293 halbtc8821a1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
294 halbtc8821a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
301 void halbtc8821a1ant_limited_rx(IN struct btc_coexist *btcoexist,
302 IN boolean force_exec, IN boolean rej_ap_agg_pkt,
303 IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
305 boolean reject_rx_agg = rej_ap_agg_pkt;
306 boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
307 u8 rx_agg_size = agg_buf_size;
309 /* ============================================ */
310 /* Rx Aggregation related setting */
311 /* ============================================ */
312 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
314 /* decide BT control aggregation buf size or not */
315 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
316 &bt_ctrl_rx_agg_size);
317 /* aggregation buf size, only work when BT control Rx aggregation size. */
318 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
319 /* real update aggregation setting */
320 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
325 void halbtc8821a1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
327 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
328 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
330 /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
331 if (!(btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8)) {
332 coex_sta->high_priority_tx = 65535;
333 coex_sta->high_priority_rx = 65535;
334 coex_sta->low_priority_tx = 65535;
335 coex_sta->low_priority_rx = 65535;
342 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
343 reg_hp_tx = u32tmp & MASKLWORD;
344 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
346 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
347 reg_lp_tx = u32tmp & MASKLWORD;
348 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
350 coex_sta->high_priority_tx = reg_hp_tx;
351 coex_sta->high_priority_rx = reg_hp_rx;
352 coex_sta->low_priority_tx = reg_lp_tx;
353 coex_sta->low_priority_rx = reg_lp_rx;
356 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
359 void halbtc8821a1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
363 coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter(
365 PHYDM_INFO_CRC32_OK_CCK);
366 coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter(
368 PHYDM_INFO_CRC32_OK_LEGACY);
369 coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter(
371 PHYDM_INFO_CRC32_OK_HT);
372 coex_sta->crc_ok_11n_vht =
373 btcoexist->btc_phydm_query_PHY_counter(
375 PHYDM_INFO_CRC32_OK_VHT);
377 coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter(
379 PHYDM_INFO_CRC32_ERROR_CCK);
380 coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter(
382 PHYDM_INFO_CRC32_ERROR_LEGACY);
383 coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter(
385 PHYDM_INFO_CRC32_ERROR_HT);
386 coex_sta->crc_err_11n_vht =
387 btcoexist->btc_phydm_query_PHY_counter(
389 PHYDM_INFO_CRC32_ERROR_VHT);
395 void halbtc8821a1ant_query_bt_info(IN struct btc_coexist *btcoexist)
397 u8 h2c_parameter[1] = {0};
399 coex_sta->c2h_bt_info_req_sent = true;
401 h2c_parameter[0] |= BIT(0); /* trigger */
403 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
406 boolean halbtc8821a1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
408 static boolean pre_wifi_busy = false, pre_under_4way = false,
409 pre_bt_hs_on = false;
410 boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
411 boolean wifi_connected = false;
413 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
415 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
416 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
417 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
420 if (wifi_connected) {
421 if (wifi_busy != pre_wifi_busy) {
422 pre_wifi_busy = wifi_busy;
425 if (under_4way != pre_under_4way) {
426 pre_under_4way = under_4way;
429 if (bt_hs_on != pre_bt_hs_on) {
430 pre_bt_hs_on = bt_hs_on;
438 void halbtc8821a1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
440 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
441 boolean bt_hs_on = false;
443 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
445 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
446 bt_link_info->sco_exist = coex_sta->sco_exist;
447 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
448 bt_link_info->pan_exist = coex_sta->pan_exist;
449 bt_link_info->hid_exist = coex_sta->hid_exist;
451 /* work around for HS mode. */
453 bt_link_info->pan_exist = true;
454 bt_link_info->bt_link_exist = true;
457 /* check if Sco only */
458 if (bt_link_info->sco_exist &&
459 !bt_link_info->a2dp_exist &&
460 !bt_link_info->pan_exist &&
461 !bt_link_info->hid_exist)
462 bt_link_info->sco_only = true;
464 bt_link_info->sco_only = false;
466 /* check if A2dp only */
467 if (!bt_link_info->sco_exist &&
468 bt_link_info->a2dp_exist &&
469 !bt_link_info->pan_exist &&
470 !bt_link_info->hid_exist)
471 bt_link_info->a2dp_only = true;
473 bt_link_info->a2dp_only = false;
475 /* check if Pan only */
476 if (!bt_link_info->sco_exist &&
477 !bt_link_info->a2dp_exist &&
478 bt_link_info->pan_exist &&
479 !bt_link_info->hid_exist)
480 bt_link_info->pan_only = true;
482 bt_link_info->pan_only = false;
484 /* check if Hid only */
485 if (!bt_link_info->sco_exist &&
486 !bt_link_info->a2dp_exist &&
487 !bt_link_info->pan_exist &&
488 bt_link_info->hid_exist)
489 bt_link_info->hid_only = true;
491 bt_link_info->hid_only = false;
494 u8 halbtc8821a1ant_action_algorithm(IN struct btc_coexist *btcoexist)
496 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
497 boolean bt_hs_on = false;
498 u8 algorithm = BT_8821A_1ANT_COEX_ALGO_UNDEFINED;
499 u8 num_of_diff_profile = 0;
501 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
503 if (!bt_link_info->bt_link_exist) {
504 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
505 "[BTCoex], No BT link exists!!!\n");
506 BTC_TRACE(trace_buf);
510 if (bt_link_info->sco_exist)
511 num_of_diff_profile++;
512 if (bt_link_info->hid_exist)
513 num_of_diff_profile++;
514 if (bt_link_info->pan_exist)
515 num_of_diff_profile++;
516 if (bt_link_info->a2dp_exist)
517 num_of_diff_profile++;
519 if (num_of_diff_profile == 1) {
520 if (bt_link_info->sco_exist) {
521 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
522 "[BTCoex], BT Profile = SCO only\n");
523 BTC_TRACE(trace_buf);
524 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
526 if (bt_link_info->hid_exist) {
527 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
528 "[BTCoex], BT Profile = HID only\n");
529 BTC_TRACE(trace_buf);
530 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
531 } else if (bt_link_info->a2dp_exist) {
532 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
533 "[BTCoex], BT Profile = A2DP only\n");
534 BTC_TRACE(trace_buf);
535 algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP;
536 } else if (bt_link_info->pan_exist) {
538 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
539 "[BTCoex], BT Profile = PAN(HS) only\n");
540 BTC_TRACE(trace_buf);
542 BT_8821A_1ANT_COEX_ALGO_PANHS;
544 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
545 "[BTCoex], BT Profile = PAN(EDR) only\n");
546 BTC_TRACE(trace_buf);
548 BT_8821A_1ANT_COEX_ALGO_PANEDR;
552 } else if (num_of_diff_profile == 2) {
553 if (bt_link_info->sco_exist) {
554 if (bt_link_info->hid_exist) {
555 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
556 "[BTCoex], BT Profile = SCO + HID\n");
557 BTC_TRACE(trace_buf);
558 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
559 } else if (bt_link_info->a2dp_exist) {
560 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
561 "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
562 BTC_TRACE(trace_buf);
563 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
564 } else if (bt_link_info->pan_exist) {
566 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
567 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
568 BTC_TRACE(trace_buf);
569 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
571 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
572 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
573 BTC_TRACE(trace_buf);
575 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
579 if (bt_link_info->hid_exist &&
580 bt_link_info->a2dp_exist) {
581 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
582 "[BTCoex], BT Profile = HID + A2DP\n");
583 BTC_TRACE(trace_buf);
584 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
585 } else if (bt_link_info->hid_exist &&
586 bt_link_info->pan_exist) {
588 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
589 "[BTCoex], BT Profile = HID + PAN(HS)\n");
590 BTC_TRACE(trace_buf);
592 BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
594 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
595 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
596 BTC_TRACE(trace_buf);
598 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
600 } else if (bt_link_info->pan_exist &&
601 bt_link_info->a2dp_exist) {
603 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
604 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
605 BTC_TRACE(trace_buf);
607 BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS;
609 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
610 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
611 BTC_TRACE(trace_buf);
613 BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP;
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->a2dp_exist) {
621 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
622 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
623 BTC_TRACE(trace_buf);
624 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
625 } else if (bt_link_info->hid_exist &&
626 bt_link_info->pan_exist) {
628 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
629 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
630 BTC_TRACE(trace_buf);
632 BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
634 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
635 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
636 BTC_TRACE(trace_buf);
638 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
640 } else if (bt_link_info->pan_exist &&
641 bt_link_info->a2dp_exist) {
643 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
644 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
645 BTC_TRACE(trace_buf);
646 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
648 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
649 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
650 BTC_TRACE(trace_buf);
652 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
656 if (bt_link_info->hid_exist &&
657 bt_link_info->pan_exist &&
658 bt_link_info->a2dp_exist) {
660 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
661 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
662 BTC_TRACE(trace_buf);
664 BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
666 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
667 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
668 BTC_TRACE(trace_buf);
670 BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
674 } else if (num_of_diff_profile >= 3) {
675 if (bt_link_info->sco_exist) {
676 if (bt_link_info->hid_exist &&
677 bt_link_info->pan_exist &&
678 bt_link_info->a2dp_exist) {
680 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
681 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
682 BTC_TRACE(trace_buf);
685 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
686 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
687 BTC_TRACE(trace_buf);
689 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
698 void halbtc8821a1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
699 IN boolean enable_auto_report)
701 u8 h2c_parameter[1] = {0};
703 h2c_parameter[0] = 0;
705 if (enable_auto_report)
706 h2c_parameter[0] |= BIT(0);
708 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
711 void halbtc8821a1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
712 IN boolean force_exec, IN boolean enable_auto_report)
714 coex_dm->cur_bt_auto_report = enable_auto_report;
717 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
720 halbtc8821a1ant_set_bt_auto_report(btcoexist,
721 coex_dm->cur_bt_auto_report);
723 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
726 void halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
727 *btcoexist, IN boolean low_penalty_ra)
729 u8 h2c_parameter[6] = {0};
731 h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
733 if (low_penalty_ra) {
734 h2c_parameter[1] |= BIT(0);
736 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
737 h2c_parameter[3] = 0xf5; /* MCS7 or OFDM54 */
738 h2c_parameter[4] = 0xa0; /* MCS6 or OFDM48 */
739 h2c_parameter[5] = 0xa0; /* MCS5 or OFDM36 */
742 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
745 void halbtc8821a1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
746 IN boolean force_exec, IN boolean low_penalty_ra)
748 coex_dm->cur_low_penalty_ra = low_penalty_ra;
751 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
754 halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
755 coex_dm->cur_low_penalty_ra);
757 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
760 void halbtc8821a1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
761 IN boolean low_penalty_ra)
763 halbtc8821a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
766 void halbtc8821a1ant_set_coex_table(IN struct btc_coexist *btcoexist,
767 IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
769 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
771 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
773 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
775 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
778 void halbtc8821a1ant_coex_table(IN struct btc_coexist *btcoexist,
779 IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
780 IN u32 val0x6c8, IN u8 val0x6cc)
782 coex_dm->cur_val0x6c0 = val0x6c0;
783 coex_dm->cur_val0x6c4 = val0x6c4;
784 coex_dm->cur_val0x6c8 = val0x6c8;
785 coex_dm->cur_val0x6cc = val0x6cc;
788 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
789 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
790 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
791 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
794 halbtc8821a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
797 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
798 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
799 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
800 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
803 void halbtc8821a1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
804 IN boolean force_exec, IN u8 type)
806 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
807 "[BTCoex], ********** CoexTable(%d) **********\n", type);
808 BTC_TRACE(trace_buf);
812 halbtc8821a1ant_coex_table(btcoexist, force_exec,
813 0x55555555, 0x55555555, 0xffffff, 0x3);
816 halbtc8821a1ant_coex_table(btcoexist, force_exec,
817 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
820 halbtc8821a1ant_coex_table(btcoexist, force_exec,
821 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
824 halbtc8821a1ant_coex_table(btcoexist, force_exec,
825 0x5a5a5a5a, 0xaaaaaaaa, 0xffffff, 0x3);
828 halbtc8821a1ant_coex_table(btcoexist, force_exec,
829 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
832 halbtc8821a1ant_coex_table(btcoexist, force_exec,
833 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3);
836 halbtc8821a1ant_coex_table(btcoexist, force_exec,
837 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
840 halbtc8821a1ant_coex_table(btcoexist, force_exec,
841 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
848 void halbtc8821a1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
851 u8 h2c_parameter[1] = {0};
854 h2c_parameter[0] |= BIT(0); /* function enable */
856 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
859 void halbtc8821a1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
860 IN boolean force_exec, IN boolean enable)
862 coex_dm->cur_ignore_wlan_act = enable;
865 if (coex_dm->pre_ignore_wlan_act ==
866 coex_dm->cur_ignore_wlan_act)
869 halbtc8821a1ant_set_fw_ignore_wlan_act(btcoexist, enable);
871 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
874 void halbtc8821a1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
875 IN u8 lps_val, IN u8 rpwm_val)
880 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
881 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
884 void halbtc8821a1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
885 IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
887 coex_dm->cur_lps = lps_val;
888 coex_dm->cur_rpwm = rpwm_val;
891 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
892 (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
895 halbtc8821a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
897 coex_dm->pre_lps = coex_dm->cur_lps;
898 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
901 void halbtc8821a1ant_set_ant_path(IN struct btc_coexist *btcoexist,
902 IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
904 struct btc_board_info *board_info = &btcoexist->board_info;
906 u8 h2c_parameter[2] = {0};
909 /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */
910 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
913 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
916 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
918 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
919 /* tell firmware "antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */
920 h2c_parameter[0] = 1;
921 h2c_parameter[1] = 1;
922 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
925 /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x1); */ /*Main Ant to BT for IPS case 0x4c[23]=1 */
927 /* tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */
928 h2c_parameter[0] = 0;
929 h2c_parameter[1] = 1;
930 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
933 /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x0); */ /*Aux Ant to BT for IPS case 0x4c[23]=1 */
935 } else if (wifi_off) {
936 /* 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL BT Vendor 0xac=0xf002 */
937 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
940 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
943 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
946 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x0);
949 /* ext switch setting */
950 switch (ant_pos_type) {
951 case BTC_ANT_PATH_WIFI:
952 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
953 if (board_info->btdm_ant_pos ==
954 BTC_ANTENNA_AT_MAIN_PORT)
955 btcoexist->btc_write_1byte_bitmask(btcoexist,
958 btcoexist->btc_write_1byte_bitmask(btcoexist,
961 case BTC_ANT_PATH_BT:
962 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
963 if (board_info->btdm_ant_pos ==
964 BTC_ANTENNA_AT_MAIN_PORT)
965 btcoexist->btc_write_1byte_bitmask(btcoexist,
968 btcoexist->btc_write_1byte_bitmask(btcoexist,
972 case BTC_ANT_PATH_PTA:
973 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x66);
974 if (board_info->btdm_ant_pos ==
975 BTC_ANTENNA_AT_MAIN_PORT)
976 btcoexist->btc_write_1byte_bitmask(btcoexist,
979 btcoexist->btc_write_1byte_bitmask(btcoexist,
986 void halbtc8821a1ant_ps_tdma_check_for_power_save_state(
987 IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
990 u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0};
992 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
994 if (lps_mode) { /* already under LPS state */
996 /* keep state under LPS, do nothing. */
998 /* will leave LPS state, turn off psTdma first */
999 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,8); */
1000 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1003 } else { /* NO PS state */
1005 /* will enter LPS state, turn off psTdma first */
1006 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,8); */
1007 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1010 /* keep state under NO PS state, do nothing. */
1015 void halbtc8821a1ant_power_save_state(IN struct btc_coexist *btcoexist,
1016 IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
1018 boolean low_pwr_disable = false;
1021 case BTC_PS_WIFI_NATIVE:
1022 /* recover to original 32k low power setting */
1023 low_pwr_disable = false;
1024 btcoexist->btc_set(btcoexist,
1025 BTC_SET_ACT_DISABLE_LOW_POWER,
1027 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1031 halbtc8821a1ant_ps_tdma_check_for_power_save_state(
1033 halbtc8821a1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1035 /* when coex force to enter LPS, do not enter 32k low power. */
1036 low_pwr_disable = true;
1037 btcoexist->btc_set(btcoexist,
1038 BTC_SET_ACT_DISABLE_LOW_POWER,
1040 /* power save must executed before psTdma. */
1041 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1044 case BTC_PS_LPS_OFF:
1045 halbtc8821a1ant_ps_tdma_check_for_power_save_state(
1047 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1055 void halbtc8821a1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
1056 IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
1058 u8 h2c_parameter[5] = {0};
1059 u8 real_byte1 = byte1, real_byte5 = byte5;
1060 boolean ap_enable = false;
1062 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1066 if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1067 real_byte1 &= ~BIT(4);
1068 real_byte1 |= BIT(5);
1070 real_byte5 |= BIT(5);
1071 real_byte5 &= ~BIT(6);
1073 halbtc8821a1ant_power_save_state(btcoexist,
1074 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1076 } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1077 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 0x4);
1080 halbtc8821a1ant_power_save_state(btcoexist,
1081 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1084 h2c_parameter[0] = real_byte1;
1085 h2c_parameter[1] = byte2;
1086 h2c_parameter[2] = byte3;
1087 h2c_parameter[3] = byte4;
1088 h2c_parameter[4] = real_byte5;
1090 coex_dm->ps_tdma_para[0] = real_byte1;
1091 coex_dm->ps_tdma_para[1] = byte2;
1092 coex_dm->ps_tdma_para[2] = byte3;
1093 coex_dm->ps_tdma_para[3] = byte4;
1094 coex_dm->ps_tdma_para[4] = real_byte5;
1096 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1099 void halbtc8821a1ant_ps_tdma(IN struct btc_coexist *btcoexist,
1100 IN boolean force_exec, IN boolean turn_on, IN u8 type)
1102 u8 rssi_adjust_val = 0;
1105 coex_dm->cur_ps_tdma_on = turn_on;
1106 coex_dm->cur_ps_tdma = type;
1108 if (coex_dm->cur_ps_tdma_on) {
1109 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1110 "[BTCoex], ********** TDMA(on, %d) **********\n",
1111 coex_dm->cur_ps_tdma);
1112 BTC_TRACE(trace_buf);
1114 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1115 "[BTCoex], ********** TDMA(off, %d) **********\n",
1116 coex_dm->cur_ps_tdma);
1117 BTC_TRACE(trace_buf);
1121 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1122 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1128 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1129 0x1a, 0x1a, 0x0, 0x50);
1132 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1133 0x3a, 0x03, 0x10, 0x50);
1134 rssi_adjust_val = 11;
1137 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1138 0x2b, 0x03, 0x10, 0x50);
1139 rssi_adjust_val = 14;
1142 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1143 0x1d, 0x1d, 0x0, 0x52);
1146 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1147 0x15, 0x3, 0x14, 0x0);
1148 rssi_adjust_val = 17;
1151 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1152 0x15, 0x3, 0x11, 0x10);
1155 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1156 0x20, 0x3, 0x11, 0x13);
1159 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1160 0xc, 0x5, 0x0, 0x0);
1163 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1164 0x25, 0x3, 0x10, 0x0);
1167 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1168 0x21, 0x3, 0x10, 0x50);
1169 rssi_adjust_val = 18;
1172 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1173 0xa, 0xa, 0x0, 0x40);
1176 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1177 0x15, 0x03, 0x10, 0x50);
1178 rssi_adjust_val = 20;
1181 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1182 0x0a, 0x0a, 0x0, 0x50);
1185 if (coex_sta->scan_ap_num <= 5)
1186 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1187 0x40, 0x3, 0x10, 0x50);
1189 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1190 0x12, 0x12, 0x0, 0x50);
1193 if (coex_sta->scan_ap_num <= 5)
1194 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1195 0x30, 0x3, 0x10, 0x50);
1197 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1198 0x1e, 0x3, 0x10, 0x14);
1201 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1202 0xa, 0x3, 0x8, 0x0);
1205 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1206 0x15, 0x3, 0x10, 0x0);
1207 rssi_adjust_val = 18;
1210 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1211 0x25, 0x3, 0x10, 0x0);
1212 rssi_adjust_val = 14;
1215 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1216 0x35, 0x03, 0x11, 0x10);
1219 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1220 0x25, 0x03, 0x11, 0x11);
1223 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1224 0x25, 0x03, 0x11, 0x10);
1227 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1228 0x25, 0x3, 0x31, 0x18);
1229 rssi_adjust_val = 22;
1232 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1233 0x15, 0x3, 0x31, 0x18);
1234 rssi_adjust_val = 22;
1237 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1238 0xa, 0x3, 0x31, 0x18);
1239 rssi_adjust_val = 22;
1242 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1243 0xa, 0x3, 0x31, 0x18);
1244 rssi_adjust_val = 22;
1247 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1248 0x25, 0x3, 0x31, 0x98);
1249 rssi_adjust_val = 22;
1252 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x69,
1253 0x25, 0x3, 0x31, 0x0);
1256 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xab,
1257 0x1a, 0x1a, 0x1, 0x10);
1260 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1261 0x30, 0x3, 0x10, 0x10);
1264 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3,
1265 0x1a, 0x1a, 0, 0x58);
1268 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1269 0x35, 0x3, 0x11, 0x11);
1272 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xa3,
1273 0x25, 0x3, 0x30, 0x90);
1276 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x53,
1277 0x1a, 0x1a, 0x0, 0x10);
1280 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x63,
1281 0x1a, 0x1a, 0x0, 0x10);
1284 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3,
1285 0x12, 0x3, 0x14, 0x50);
1287 case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */
1288 /* here softap mode screen off will cost 70-80mA for phone */
1289 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x23,
1290 0x18, 0x00, 0x10, 0x24);
1293 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1294 0x15, 0x3, 0x11, 0x11);
1297 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1298 0x20, 0x3, 0x11, 0x11);
1301 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1302 0x30, 0x3, 0x10, 0x11);
1306 /* disable PS tdma */
1308 case 8: /* PTA Control */
1309 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x8,
1310 0x0, 0x0, 0x0, 0x0);
1311 halbtc8821a1ant_set_ant_path(btcoexist,
1312 BTC_ANT_PATH_PTA, false, false);
1315 default: /* Software control, Antenna at BT side */
1316 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1317 0x0, 0x0, 0x0, 0x0);
1318 halbtc8821a1ant_set_ant_path(btcoexist,
1319 BTC_ANT_PATH_BT, false, false);
1321 case 9: /* Software control, Antenna at WiFi side */
1322 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1323 0x0, 0x0, 0x0, 0x0);
1324 halbtc8821a1ant_set_ant_path(btcoexist,
1325 BTC_ANT_PATH_WIFI, false, false);
1327 case 10: /* under 5G */
1328 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1329 0x0, 0x0, 0x8, 0x0);
1330 halbtc8821a1ant_set_ant_path(btcoexist,
1331 BTC_ANT_PATH_BT, false, false);
1335 rssi_adjust_val = 0;
1336 btcoexist->btc_set(btcoexist,
1337 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
1339 /* update pre state */
1340 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1341 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1344 void halbtc8821a1ant_coex_all_off(IN struct btc_coexist *btcoexist)
1347 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1350 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1353 boolean halbtc8821a1ant_is_common_action(IN struct btc_coexist *btcoexist)
1355 boolean common = false, wifi_connected = false, wifi_busy = false;
1357 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1359 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1361 if (!wifi_connected &&
1362 BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1363 coex_dm->bt_status) {
1364 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1365 "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
1366 BTC_TRACE(trace_buf);
1367 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1370 } else if (wifi_connected &&
1371 (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1372 coex_dm->bt_status)) {
1373 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1374 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1375 BTC_TRACE(trace_buf);
1376 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1379 } else if (!wifi_connected &&
1380 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
1381 coex_dm->bt_status)) {
1382 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1383 "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
1384 BTC_TRACE(trace_buf);
1385 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1388 } else if (wifi_connected &&
1389 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
1390 coex_dm->bt_status)) {
1391 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1392 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1393 BTC_TRACE(trace_buf);
1394 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1397 } else if (!wifi_connected &&
1398 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE !=
1399 coex_dm->bt_status)) {
1400 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1401 "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
1402 BTC_TRACE(trace_buf);
1403 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1408 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1409 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1410 BTC_TRACE(trace_buf);
1412 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1413 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1414 BTC_TRACE(trace_buf);
1423 /* *********************************************
1425 * Software Coex Mechanism start
1427 * ********************************************* */
1429 void halbtc8821a1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist)
1432 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1433 /* halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false); */
1434 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, false, false);
1435 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1437 /* SCO only or SCO+PAN(HS) */
1438 void halbtc8821a1ant_action_sco(IN struct btc_coexist *btcoexist)
1440 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1443 void halbtc8821a1ant_action_hid(IN struct btc_coexist *btcoexist)
1445 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1448 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
1449 void halbtc8821a1ant_action_a2dp(IN struct btc_coexist *btcoexist)
1451 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1454 void halbtc8821a1ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
1456 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1459 void halbtc8821a1ant_action_pan_edr(IN struct btc_coexist *btcoexist)
1461 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1465 void halbtc8821a1ant_action_pan_hs(IN struct btc_coexist *btcoexist)
1467 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1471 void halbtc8821a1ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
1473 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1476 void halbtc8821a1ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
1478 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1481 /* HID+A2DP+PAN(EDR) */
1482 void halbtc8821a1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
1484 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1487 void halbtc8821a1ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
1489 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1492 /* *********************************************
1494 * Non-Software Coex Mechanism start
1496 * ********************************************* */
1497 void halbtc8821a1ant_action_hs(IN struct btc_coexist *btcoexist)
1499 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1500 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1503 void halbtc8821a1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
1505 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1506 boolean wifi_connected = false, ap_enable = false, wifi_busy = false,
1509 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1511 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1513 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1514 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
1516 if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) {
1517 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1519 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1523 else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1524 (bt_link_info->a2dp_exist)) {
1525 /* SCO/HID/A2DP busy */
1527 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1529 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1534 else if ((bt_link_info->a2dp_exist) &&
1535 (bt_link_info->hid_exist)) {
1538 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1541 halbtc8821a1ant_coex_table_with_type(btcoexist,
1546 else if ((bt_link_info->pan_exist) || (wifi_busy)) {
1547 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1549 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1551 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1553 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1557 void halbtc8821a1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
1558 *btcoexist, IN u8 wifi_status)
1560 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1561 boolean wifi_connected = false;
1563 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1566 /* tdma and coex table */
1568 if (bt_link_info->sco_exist) {
1569 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 41);
1570 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1572 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 42);
1573 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1577 void halbtc8821a1ant_coex_under_5g(IN struct btc_coexist *btcoexist)
1580 halbtc8821a1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
1582 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 10);
1584 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1586 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
1588 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5);
1591 void halbtc8821a1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
1593 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1594 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9);
1597 void halbtc8821a1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
1599 static u32 bt_disable_cnt = 0;
1600 boolean bt_active = true, bt_disabled = false;
1602 /* This function check if bt is disabled */
1604 if (coex_sta->high_priority_tx == 0 &&
1605 coex_sta->high_priority_rx == 0 &&
1606 coex_sta->low_priority_tx == 0 &&
1607 coex_sta->low_priority_rx == 0)
1609 if (coex_sta->high_priority_tx == 0xffff &&
1610 coex_sta->high_priority_rx == 0xffff &&
1611 coex_sta->low_priority_tx == 0xffff &&
1612 coex_sta->low_priority_rx == 0xffff)
1616 bt_disabled = false;
1617 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1619 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1620 "[BTCoex], BT is enabled !!\n");
1621 BTC_TRACE(trace_buf);
1624 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1625 "[BTCoex], bt all counters=0, %d times!!\n",
1627 BTC_TRACE(trace_buf);
1628 if (bt_disable_cnt >= 10) {
1630 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1632 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1633 "[BTCoex], BT is disabled !!\n");
1634 BTC_TRACE(trace_buf);
1635 halbtc8821a1ant_action_wifi_only(btcoexist);
1638 if (coex_sta->bt_disabled != bt_disabled) {
1639 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1640 "[BTCoex], BT is from %s to %s!!\n",
1641 (coex_sta->bt_disabled ? "disabled" : "enabled"),
1642 (bt_disabled ? "disabled" : "enabled"));
1643 BTC_TRACE(trace_buf);
1644 coex_sta->bt_disabled = bt_disabled;
1647 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1649 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1655 void halbtc8821a1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
1658 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1659 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1663 void halbtc8821a1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
1664 *btcoexist, IN u8 wifi_status)
1668 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1670 bt_rssi_state = halbtc8821a1ant_bt_rssi_state(2, 28, 0);
1672 if (bt_link_info->hid_only) { /* HID */
1673 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1675 coex_dm->auto_tdma_adjust = false;
1677 } else if (bt_link_info->a2dp_only) { /* A2DP */
1678 if (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
1679 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); */
1680 /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); */
1681 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1683 halbtc8821a1ant_coex_table_with_type(btcoexist,
1685 coex_dm->auto_tdma_adjust = false;
1686 } else if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
1687 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
1688 /* halbtc8821a1ant_tdma_duration_adjust_for_acl(btcoexist, wifi_status); */
1689 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1691 halbtc8821a1ant_coex_table_with_type(btcoexist,
1693 } else { /* for low BT RSSI */
1694 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1696 halbtc8821a1ant_coex_table_with_type(btcoexist,
1698 coex_dm->auto_tdma_adjust = false;
1700 } else if (bt_link_info->hid_exist &&
1701 bt_link_info->a2dp_exist) { /* HID+A2DP */
1702 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
1703 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
1704 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1706 coex_dm->auto_tdma_adjust = false;
1707 } else { /* for low BT RSSI */
1708 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1710 coex_dm->auto_tdma_adjust = false;
1713 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1714 } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
1715 bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
1716 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1717 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
1718 coex_dm->auto_tdma_adjust = false;
1719 } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
1720 (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
1721 bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
1722 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 43);
1723 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1724 coex_dm->auto_tdma_adjust = false;
1726 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1727 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1728 coex_dm->auto_tdma_adjust = false;
1732 void halbtc8821a1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
1735 /* tdma and coex table */
1736 halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
1737 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1740 void halbtc8821a1ant_action_wifi_not_connected_scan(IN struct btc_coexist
1743 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1746 /* tdma and coex table */
1747 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1748 if (bt_link_info->a2dp_exist) {
1750 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1752 halbtc8821a1ant_coex_table_with_type(btcoexist,
1754 } else if (bt_link_info->a2dp_exist &&
1755 bt_link_info->pan_exist) {
1756 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1758 halbtc8821a1ant_coex_table_with_type(btcoexist,
1761 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1763 halbtc8821a1ant_coex_table_with_type(btcoexist,
1766 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1767 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1768 coex_dm->bt_status)) {
1769 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1770 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1772 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */
1773 /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */
1776 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1777 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1781 void halbtc8821a1ant_action_wifi_not_connected_asso_auth(
1782 IN struct btc_coexist *btcoexist)
1784 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1786 /* tdma and coex table */
1787 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) {
1789 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
1790 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1791 } else if ((bt_link_info->a2dp_exist) || (bt_link_info->pan_exist)) {
1792 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1793 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1795 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1796 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1800 void halbtc8821a1ant_action_wifi_connected_scan(IN struct btc_coexist
1803 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1805 /* tdma and coex table */
1806 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1807 if (bt_link_info->a2dp_exist) {
1809 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1811 halbtc8821a1ant_coex_table_with_type(btcoexist,
1813 } else if (bt_link_info->a2dp_exist &&
1814 bt_link_info->pan_exist) {
1815 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1817 halbtc8821a1ant_coex_table_with_type(btcoexist,
1820 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1822 halbtc8821a1ant_coex_table_with_type(btcoexist,
1825 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1826 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1827 coex_dm->bt_status)) {
1828 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1829 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1831 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */
1832 /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */
1835 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1836 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1840 void halbtc8821a1ant_action_wifi_connected_specific_packet(
1841 IN struct btc_coexist *btcoexist)
1843 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1845 /* tdma and coex table */
1847 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1848 (bt_link_info->a2dp_exist)) {
1849 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1850 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1853 if ((bt_link_info->hid_exist) && (bt_link_info->a2dp_exist)) {
1854 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1856 halbtc8821a1ant_coex_table_with_type(btcoexist,
1861 else if (bt_link_info->pan_exist) {
1862 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1863 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1865 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1866 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1870 void halbtc8821a1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
1872 boolean wifi_busy = false;
1873 boolean scan = false, link = false, roam = false;
1874 boolean under_4way = false, ap_enable = false;
1876 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1877 "[BTCoex], CoexForWifiConnect()===>\n");
1878 BTC_TRACE(trace_buf);
1880 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
1883 halbtc8821a1ant_action_wifi_connected_specific_packet(
1885 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1886 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
1887 BTC_TRACE(trace_buf);
1891 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1892 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1893 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1894 if (scan || link || roam) {
1896 halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
1898 halbtc8821a1ant_action_wifi_connected_specific_packet(
1900 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1901 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
1902 BTC_TRACE(trace_buf);
1906 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1908 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1910 /* tdma and coex table */
1912 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1913 halbtc8821a1ant_action_wifi_connected_bt_acl_busy(
1915 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1916 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
1917 coex_dm->bt_status) ||
1918 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1919 coex_dm->bt_status)) {
1920 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1921 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1923 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1925 halbtc8821a1ant_coex_table_with_type(btcoexist,
1929 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1930 halbtc8821a1ant_action_wifi_connected_bt_acl_busy(
1932 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
1933 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
1934 coex_dm->bt_status) ||
1935 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1936 coex_dm->bt_status)) {
1937 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1938 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
1940 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1942 halbtc8821a1ant_coex_table_with_type(btcoexist,
1948 void halbtc8821a1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
1952 algorithm = halbtc8821a1ant_action_algorithm(btcoexist);
1953 coex_dm->cur_algorithm = algorithm;
1955 if (halbtc8821a1ant_is_common_action(btcoexist)) {
1958 switch (coex_dm->cur_algorithm) {
1959 case BT_8821A_1ANT_COEX_ALGO_SCO:
1960 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1961 "[BTCoex], Action algorithm = SCO.\n");
1962 BTC_TRACE(trace_buf);
1963 halbtc8821a1ant_action_sco(btcoexist);
1965 case BT_8821A_1ANT_COEX_ALGO_HID:
1966 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1967 "[BTCoex], Action algorithm = HID.\n");
1968 BTC_TRACE(trace_buf);
1969 halbtc8821a1ant_action_hid(btcoexist);
1971 case BT_8821A_1ANT_COEX_ALGO_A2DP:
1972 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1973 "[BTCoex], Action algorithm = A2DP.\n");
1974 BTC_TRACE(trace_buf);
1975 halbtc8821a1ant_action_a2dp(btcoexist);
1977 case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS:
1978 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1979 "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
1980 BTC_TRACE(trace_buf);
1981 halbtc8821a1ant_action_a2dp_pan_hs(btcoexist);
1983 case BT_8821A_1ANT_COEX_ALGO_PANEDR:
1984 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1985 "[BTCoex], Action algorithm = PAN(EDR).\n");
1986 BTC_TRACE(trace_buf);
1987 halbtc8821a1ant_action_pan_edr(btcoexist);
1989 case BT_8821A_1ANT_COEX_ALGO_PANHS:
1990 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1991 "[BTCoex], Action algorithm = HS mode.\n");
1992 BTC_TRACE(trace_buf);
1993 halbtc8821a1ant_action_pan_hs(btcoexist);
1995 case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP:
1996 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1997 "[BTCoex], Action algorithm = PAN+A2DP.\n");
1998 BTC_TRACE(trace_buf);
1999 halbtc8821a1ant_action_pan_edr_a2dp(btcoexist);
2001 case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID:
2002 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2003 "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
2004 BTC_TRACE(trace_buf);
2005 halbtc8821a1ant_action_pan_edr_hid(btcoexist);
2007 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
2008 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2009 "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
2010 BTC_TRACE(trace_buf);
2011 halbtc8821a1ant_action_hid_a2dp_pan_edr(
2014 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP:
2015 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2016 "[BTCoex], Action algorithm = HID+A2DP.\n");
2017 BTC_TRACE(trace_buf);
2018 halbtc8821a1ant_action_hid_a2dp(btcoexist);
2021 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2022 "[BTCoex], Action algorithm = coexist All Off!!\n");
2023 BTC_TRACE(trace_buf);
2024 /* halbtc8821a1ant_coex_all_off(btcoexist); */
2027 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
2031 void halbtc8821a1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
2033 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2034 boolean wifi_connected = false, bt_hs_on = false;
2035 boolean increase_scan_dev_num = false;
2036 boolean bt_ctrl_agg_buf_size = false;
2037 u8 agg_buf_size = 5;
2038 u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
2039 u32 wifi_link_status = 0;
2040 u32 num_of_wifi_link = 0;
2041 boolean wifi_under_5g = false;
2043 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2044 "[BTCoex], RunCoexistMechanism()===>\n");
2045 BTC_TRACE(trace_buf);
2047 if (btcoexist->manual_control) {
2048 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2049 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2050 BTC_TRACE(trace_buf);
2054 if (btcoexist->stop_coex_dm) {
2055 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2056 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2057 BTC_TRACE(trace_buf);
2061 if (coex_sta->under_ips) {
2062 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2063 "[BTCoex], wifi is under IPS !!!\n");
2064 BTC_TRACE(trace_buf);
2068 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2069 if (wifi_under_5g) {
2070 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2071 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2072 BTC_TRACE(trace_buf);
2073 halbtc8821a1ant_coex_under_5g(btcoexist);
2076 if (coex_sta->bt_whck_test) {
2077 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2078 "[BTCoex], BT is under WHCK TEST!!!\n");
2079 BTC_TRACE(trace_buf);
2080 halbtc8821a1ant_action_bt_whck_test(btcoexist);
2084 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
2085 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2086 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
2087 increase_scan_dev_num = true;
2089 btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
2090 &increase_scan_dev_num);
2091 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2094 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2096 num_of_wifi_link = wifi_link_status >> 16;
2097 if ((num_of_wifi_link >= 2) ||
2098 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
2099 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2100 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2101 bt_ctrl_agg_buf_size, agg_buf_size);
2102 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2106 if (!bt_link_info->sco_exist && !bt_link_info->hid_exist)
2107 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2109 if (wifi_connected) {
2110 wifi_rssi_state = halbtc8821a1ant_wifi_rssi_state(
2111 btcoexist, 1, 2, 30, 0);
2112 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2113 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2114 /* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */
2115 halbtc8821a1ant_limited_tx(btcoexist,
2116 NORMAL_EXEC, 1, 1, 0, 1);
2118 /* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */
2119 halbtc8821a1ant_limited_tx(btcoexist,
2120 NORMAL_EXEC, 1, 1, 0, 1);
2123 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
2128 if (bt_link_info->sco_exist) {
2129 bt_ctrl_agg_buf_size = true;
2131 } else if (bt_link_info->hid_exist) {
2132 bt_ctrl_agg_buf_size = true;
2134 } else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) {
2135 bt_ctrl_agg_buf_size = true;
2138 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2139 bt_ctrl_agg_buf_size, agg_buf_size);
2141 halbtc8821a1ant_run_sw_coexist_mechanism(btcoexist);
2143 /* low pelnaty ra in pcr ra */
2144 btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25);
2146 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2147 if (coex_sta->c2h_bt_inquiry_page) {
2148 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2150 } else if (bt_hs_on) {
2151 halbtc8821a1ant_action_hs(btcoexist);
2156 if (!wifi_connected) {
2157 boolean scan = false, link = false, roam = false;
2159 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2160 "[BTCoex], wifi is non connected-idle !!!\n");
2161 BTC_TRACE(trace_buf);
2163 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2164 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2165 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2167 if (scan || link || roam) {
2169 halbtc8821a1ant_action_wifi_not_connected_scan(
2172 halbtc8821a1ant_action_wifi_not_connected_asso_auth(
2175 halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2176 } else /* wifi LPS/Busy */
2177 halbtc8821a1ant_action_wifi_connected(btcoexist);
2180 void halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2182 /* force to reset coex mechanism */
2184 halbtc8821a1ant_sw_mechanism(btcoexist, false);
2186 /* halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
2187 halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2190 void halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2191 IN boolean back_up, IN boolean wifi_only)
2194 boolean wifi_under_5g = false;
2197 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2198 "[BTCoex], 1Ant Init HW Config!!\n");
2199 BTC_TRACE(trace_buf);
2205 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
2207 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
2209 coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
2211 coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
2215 /* 0x790[5:0]=0x5 */
2216 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
2219 btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
2221 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2223 /* Give bt_coex_supported_version the default value */
2224 coex_sta->bt_coex_supported_version = 0;
2226 /* 0xf0[15:12] --> Chip Cut information */
2227 coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
2230 /* Antenna config */
2232 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, true,
2235 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, true,
2239 halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2241 /* Enable counter statistics */
2242 btcoexist->btc_write_1byte(btcoexist, 0x76e,
2243 0xc); /* 0x76e[3] =1, WLAN_Act control by PTA */
2244 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
2245 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
2248 /* ************************************************************
2249 * work around function start with wa_halbtc8821a1ant_
2250 * ************************************************************
2251 * ************************************************************
2252 * extern function start with ex_halbtc8821a1ant_
2253 * ************************************************************ */
2254 void ex_halbtc8821a1ant_power_on_setting(IN struct btc_coexist *btcoexist)
2258 void ex_halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2259 IN boolean wifi_only)
2261 halbtc8821a1ant_init_hw_config(btcoexist, true, wifi_only);
2264 void ex_halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2266 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2267 "[BTCoex], Coex Mechanism Init!!\n");
2268 BTC_TRACE(trace_buf);
2270 btcoexist->stop_coex_dm = false;
2272 halbtc8821a1ant_init_coex_dm(btcoexist);
2274 halbtc8821a1ant_query_bt_info(btcoexist);
2277 void ex_halbtc8821a1ant_display_coex_info(IN struct btc_coexist *btcoexist)
2279 struct btc_board_info *board_info = &btcoexist->board_info;
2280 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2281 u8 *cli_buf = btcoexist->cli_buf;
2282 u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
2285 u32 fw_ver = 0, bt_patch_ver = 0;
2286 u32 bt_coex_ver = 0;
2287 u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck;
2290 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2291 "\r\n ============[BT Coexist info]============");
2294 if (btcoexist->manual_control) {
2295 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2296 "\r\n ============[Under Manual Control]============");
2298 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2299 "\r\n ==========================================");
2302 if (btcoexist->stop_coex_dm) {
2303 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2304 "\r\n ============[Coex is STOPPED]============");
2306 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2307 "\r\n ==========================================");
2311 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d",
2312 "Ant PG Num/ Ant Mech/ Ant Pos:",
2313 board_info->pg_ant_num, board_info->btdm_ant_num,
2314 board_info->btdm_ant_pos);
2317 /* btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); */
2318 bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
2319 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
2320 phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
2321 bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8);
2323 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2324 "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
2325 "CoexVer WL/ BT_Desired/ BT_Report",
2326 glcoex_ver_date_8821a_1ant, glcoex_ver_8821a_1ant,
2327 glcoex_ver_btdesired_8821a_1ant,
2329 (bt_coex_ver == 0xff ? "Unknown" :
2330 (bt_coex_ver >= glcoex_ver_btdesired_8821a_1ant ?
2331 "Match" : "Mis-Match")));
2334 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2335 "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c",
2336 "W_FW/ B_FW/ Phy/ Kt",
2337 fw_ver, bt_patch_ver, phyver,
2338 coex_sta->cut_version + 65);
2341 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
2342 "Wifi channel informed to BT",
2343 coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
2344 coex_dm->wifi_chnl_info[2]);
2348 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2349 "============[Wifi Status]============");
2351 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
2353 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2354 "============[BT Status]============");
2357 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
2358 "BT [status/ rssi/ retryCnt]",
2359 ((coex_sta->bt_disabled) ? ("disabled") : ((
2360 coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
2361 : ((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2362 coex_dm->bt_status) ? "non-connected idle" :
2363 ((BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
2364 ? "connected-idle" : "busy")))),
2365 coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
2368 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
2370 bt_link_info->sco_exist, bt_link_info->hid_exist,
2371 bt_link_info->pan_exist, bt_link_info->a2dp_exist);
2373 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
2375 bt_info_ext = coex_sta->bt_info_ext;
2376 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
2377 "BT Info A2DP rate",
2378 (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
2381 for (i = 0; i < BT_INFO_SRC_8821A_1ANT_MAX; i++) {
2382 if (coex_sta->bt_info_c2h_cnt[i]) {
2383 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2384 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
2385 glbt_info_src_8821a_1ant[i],
2386 coex_sta->bt_info_c2h[i][0],
2387 coex_sta->bt_info_c2h[i][1],
2388 coex_sta->bt_info_c2h[i][2],
2389 coex_sta->bt_info_c2h[i][3],
2390 coex_sta->bt_info_c2h[i][4],
2391 coex_sta->bt_info_c2h[i][5],
2392 coex_sta->bt_info_c2h[i][6],
2393 coex_sta->bt_info_c2h_cnt[i]);
2398 if (!btcoexist->manual_control) {
2399 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
2401 coex_dm->cur_low_penalty_ra);
2404 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2405 "============[mechanisms]============");
2408 ps_tdma_case = coex_dm->cur_ps_tdma;
2409 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2410 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
2412 coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
2413 coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
2414 coex_dm->ps_tdma_para[4], ps_tdma_case,
2415 coex_dm->auto_tdma_adjust);
2418 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ",
2420 coex_dm->cur_ignore_wlan_act);
2423 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ",
2424 "Latest error condition(should be 0)",
2425 coex_dm->error_condition);
2430 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2431 "============[Hw setting]============");
2434 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2435 "backup ARFR1/ARFR2/RL/AMaxTime",
2436 coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2,
2437 coex_dm->backup_retry_limit,
2438 coex_dm->backup_ampdu_max_time);
2441 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
2442 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
2443 u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
2444 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
2445 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2446 "0x430/0x434/0x42a/0x456",
2447 u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
2450 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
2451 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc58);
2452 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2453 "0x778/ 0xc58[29:25]",
2454 u8tmp[0], (u32tmp[0] & 0x3e000000) >> 25);
2457 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
2458 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x8db[6:5]",
2459 ((u8tmp[0] & 0x60) >> 5));
2462 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x975);
2463 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2464 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2465 "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]",
2466 (u32tmp[0] & 0x30000000) >> 28, u32tmp[0] & 0xff,
2471 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
2472 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
2473 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64);
2474 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2475 "0x40/0x4c[24:23]/0x64[0]",
2476 u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u8tmp[1] & 0x1);
2479 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
2480 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
2481 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2482 "0x550(bcn ctrl)/0x522",
2483 u32tmp[0], u8tmp[0]);
2486 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
2487 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)",
2491 fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
2492 PHYDM_INFO_FA_OFDM);
2493 fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
2495 cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
2496 PHYDM_INFO_CCA_OFDM);
2497 cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
2498 PHYDM_INFO_CCA_CCK);
2500 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2501 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
2502 "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
2503 cca_cck, fa_cck, cca_ofdm, fa_ofdm);
2506 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
2507 "CRC_OK CCK/11g/11n/11n-agg",
2508 coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
2509 coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
2512 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
2513 "CRC_Err CCK/11g/11n/11n-agg",
2514 coex_sta->crc_err_cck, coex_sta->crc_err_11g,
2515 coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
2519 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
2520 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
2521 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
2522 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2523 "0x6c0/0x6c4/0x6c8(coexTable)",
2524 u32tmp[0], u32tmp[1], u32tmp[2]);
2527 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2528 "0x770(high-pri rx/tx)",
2529 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
2531 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2532 "0x774(low-pri rx/tx)",
2533 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
2535 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 1)
2536 halbtc8821a1ant_monitor_bt_ctr(btcoexist);
2538 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
2542 void ex_halbtc8821a1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2544 boolean wifi_under_5g = false;
2546 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2548 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
2550 if (wifi_under_5g) {
2551 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2552 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2553 BTC_TRACE(trace_buf);
2554 halbtc8821a1ant_coex_under_5g(btcoexist);
2558 if (BTC_IPS_ENTER == type) {
2559 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2560 "[BTCoex], IPS ENTER notify\n");
2561 BTC_TRACE(trace_buf);
2562 coex_sta->under_ips = true;
2564 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2565 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2566 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
2568 /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
2569 } else if (BTC_IPS_LEAVE == type) {
2570 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2571 "[BTCoex], IPS LEAVE notify\n");
2572 BTC_TRACE(trace_buf);
2573 coex_sta->under_ips = false;
2575 halbtc8821a1ant_init_hw_config(btcoexist, false, false);
2576 halbtc8821a1ant_init_coex_dm(btcoexist);
2577 halbtc8821a1ant_query_bt_info(btcoexist);
2581 void ex_halbtc8821a1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2585 if (BTC_LPS_ENABLE == type) {
2586 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2587 "[BTCoex], LPS ENABLE notify\n");
2588 BTC_TRACE(trace_buf);
2589 coex_sta->under_lps = true;
2590 } else if (BTC_LPS_DISABLE == type) {
2591 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2592 "[BTCoex], LPS DISABLE notify\n");
2593 BTC_TRACE(trace_buf);
2594 coex_sta->under_lps = false;
2598 void ex_halbtc8821a1ant_scan_notify(IN struct btc_coexist *btcoexist,
2601 boolean wifi_connected = false, bt_hs_on = false;
2602 u32 wifi_link_status = 0;
2603 u32 num_of_wifi_link = 0;
2604 boolean bt_ctrl_agg_buf_size = false;
2605 u8 agg_buf_size = 5;
2606 boolean wifi_under_5g = false;
2608 if (btcoexist->manual_control ||
2609 btcoexist->stop_coex_dm)
2611 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2612 if (wifi_under_5g) {
2613 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2614 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2615 BTC_TRACE(trace_buf);
2616 halbtc8821a1ant_coex_under_5g(btcoexist);
2620 if (BTC_SCAN_START == type) {
2621 coex_sta->wifi_is_high_pri_task = true;
2622 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2623 "[BTCoex], SCAN START notify\n");
2624 BTC_TRACE(trace_buf);
2626 halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
2627 8); /* Force antenna setup for no scan result issue */
2629 coex_sta->wifi_is_high_pri_task = false;
2630 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2631 "[BTCoex], SCAN FINISH notify\n");
2632 BTC_TRACE(trace_buf);
2635 if (coex_sta->bt_disabled)
2638 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2639 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2642 halbtc8821a1ant_query_bt_info(btcoexist);
2644 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2646 num_of_wifi_link = wifi_link_status >> 16;
2647 if (num_of_wifi_link >= 2) {
2648 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2649 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2650 bt_ctrl_agg_buf_size, agg_buf_size);
2651 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2655 if (coex_sta->c2h_bt_inquiry_page) {
2656 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2658 } else if (bt_hs_on) {
2659 halbtc8821a1ant_action_hs(btcoexist);
2663 if (BTC_SCAN_START == type) {
2664 if (!wifi_connected) /* non-connected scan */
2665 halbtc8821a1ant_action_wifi_not_connected_scan(
2667 else /* wifi is connected */
2668 halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
2669 } else if (BTC_SCAN_FINISH == type) {
2670 if (!wifi_connected) /* non-connected scan */
2671 halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2673 halbtc8821a1ant_action_wifi_connected(btcoexist);
2677 /* copy scan notify content to switch band notify */
2678 void ex_halbtc8821a1ant_switchband_notify(IN struct btc_coexist *btcoexist,
2681 boolean wifi_connected = false, bt_hs_on = false;
2682 u32 wifi_link_status = 0;
2683 u32 num_of_wifi_link = 0;
2684 boolean bt_ctrl_agg_buf_size = false;
2685 u8 agg_buf_size = 5;
2686 boolean wifi_under_5g = false;
2688 if (btcoexist->manual_control ||
2689 btcoexist->stop_coex_dm)
2691 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2692 if (wifi_under_5g) {
2693 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2694 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2695 BTC_TRACE(trace_buf);
2696 halbtc8821a1ant_coex_under_5g(btcoexist);
2700 if (BTC_SCAN_START == type) {
2701 coex_sta->wifi_is_high_pri_task = true;
2702 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2703 "[BTCoex], SCAN START notify\n");
2704 BTC_TRACE(trace_buf);
2706 halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
2707 8); /* Force antenna setup for no scan result issue */
2709 coex_sta->wifi_is_high_pri_task = false;
2710 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2711 "[BTCoex], SCAN FINISH notify\n");
2712 BTC_TRACE(trace_buf);
2715 if (coex_sta->bt_disabled)
2718 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2719 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2722 halbtc8821a1ant_query_bt_info(btcoexist);
2724 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2726 num_of_wifi_link = wifi_link_status >> 16;
2727 if (num_of_wifi_link >= 2) {
2728 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2729 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2730 bt_ctrl_agg_buf_size, agg_buf_size);
2731 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2735 if (coex_sta->c2h_bt_inquiry_page) {
2736 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2738 } else if (bt_hs_on) {
2739 halbtc8821a1ant_action_hs(btcoexist);
2743 if (BTC_SCAN_START == type) {
2744 if (!wifi_connected) /* non-connected scan */
2745 halbtc8821a1ant_action_wifi_not_connected_scan(
2747 else /* wifi is connected */
2748 halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
2749 } else if (BTC_SCAN_FINISH == type) {
2750 if (!wifi_connected) /* non-connected scan */
2751 halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2753 halbtc8821a1ant_action_wifi_connected(btcoexist);
2756 void ex_halbtc8821a1ant_connect_notify(IN struct btc_coexist *btcoexist,
2759 boolean wifi_connected = false, bt_hs_on = false;
2760 u32 wifi_link_status = 0;
2761 u32 num_of_wifi_link = 0;
2762 boolean bt_ctrl_agg_buf_size = false;
2763 u8 agg_buf_size = 5;
2764 boolean wifi_under_5g = false;
2766 if (btcoexist->manual_control ||
2767 btcoexist->stop_coex_dm ||
2768 coex_sta->bt_disabled)
2770 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2771 if (wifi_under_5g) {
2772 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2773 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2774 BTC_TRACE(trace_buf);
2775 halbtc8821a1ant_coex_under_5g(btcoexist);
2779 if (BTC_ASSOCIATE_START == type) {
2780 coex_sta->wifi_is_high_pri_task = true;
2781 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2782 "[BTCoex], CONNECT START notify\n");
2783 BTC_TRACE(trace_buf);
2784 coex_dm->arp_cnt = 0;
2786 coex_sta->wifi_is_high_pri_task = false;
2787 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2788 "[BTCoex], CONNECT FINISH notify\n");
2789 BTC_TRACE(trace_buf);
2790 coex_dm->arp_cnt = 0;
2793 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2795 num_of_wifi_link = wifi_link_status >> 16;
2796 if (num_of_wifi_link >= 2) {
2797 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2798 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2799 bt_ctrl_agg_buf_size, agg_buf_size);
2800 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2804 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2805 if (coex_sta->c2h_bt_inquiry_page) {
2806 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2808 } else if (bt_hs_on) {
2809 halbtc8821a1ant_action_hs(btcoexist);
2813 if (BTC_ASSOCIATE_START == type)
2814 halbtc8821a1ant_action_wifi_not_connected_asso_auth(btcoexist);
2815 else if (BTC_ASSOCIATE_FINISH == type) {
2816 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2818 if (!wifi_connected) /* non-connected scan */
2819 halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2821 halbtc8821a1ant_action_wifi_connected(btcoexist);
2825 void ex_halbtc8821a1ant_media_status_notify(IN struct btc_coexist *btcoexist,
2828 u8 h2c_parameter[3] = {0};
2830 u8 wifi_central_chnl;
2831 boolean wifi_under_5g = false;
2833 if (btcoexist->manual_control ||
2834 btcoexist->stop_coex_dm ||
2835 coex_sta->bt_disabled)
2837 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2838 if (wifi_under_5g) {
2839 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2840 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2841 BTC_TRACE(trace_buf);
2842 halbtc8821a1ant_coex_under_5g(btcoexist);
2846 if (BTC_MEDIA_CONNECT == type) {
2847 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2848 "[BTCoex], MEDIA connect notify\n");
2849 BTC_TRACE(trace_buf);
2851 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2852 "[BTCoex], MEDIA disconnect notify\n");
2853 BTC_TRACE(trace_buf);
2854 coex_dm->arp_cnt = 0;
2857 /* only 2.4G we need to inform bt the chnl mask */
2858 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
2859 &wifi_central_chnl);
2860 if ((BTC_MEDIA_CONNECT == type) &&
2861 (wifi_central_chnl <= 14)) {
2862 /* h2c_parameter[0] = 0x1; */
2863 h2c_parameter[0] = 0x0;
2864 h2c_parameter[1] = wifi_central_chnl;
2865 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2866 if (BTC_WIFI_BW_HT40 == wifi_bw)
2867 h2c_parameter[2] = 0x30;
2869 h2c_parameter[2] = 0x20;
2872 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
2873 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
2874 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
2876 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
2879 void ex_halbtc8821a1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
2882 boolean bt_hs_on = false;
2883 u32 wifi_link_status = 0;
2884 u32 num_of_wifi_link = 0;
2885 boolean bt_ctrl_agg_buf_size = false;
2886 u8 agg_buf_size = 5;
2887 boolean wifi_under_5g = false;
2889 if (btcoexist->manual_control ||
2890 btcoexist->stop_coex_dm ||
2891 coex_sta->bt_disabled)
2893 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2894 if (wifi_under_5g) {
2895 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2896 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2897 BTC_TRACE(trace_buf);
2898 halbtc8821a1ant_coex_under_5g(btcoexist);
2902 if (BTC_PACKET_DHCP == type ||
2903 BTC_PACKET_EAPOL == type ||
2904 BTC_PACKET_ARP == type) {
2905 coex_sta->wifi_is_high_pri_task = true;
2907 if (BTC_PACKET_ARP == type) {
2908 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2909 "[BTCoex], specific Packet ARP notify\n");
2910 BTC_TRACE(trace_buf);
2912 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2913 "[BTCoex], specific Packet DHCP or EAPOL notify\n");
2914 BTC_TRACE(trace_buf);
2917 coex_sta->wifi_is_high_pri_task = false;
2918 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2919 "[BTCoex], specific Packet [Type = %d] notify\n", type);
2920 BTC_TRACE(trace_buf);
2923 coex_sta->specific_pkt_period_cnt = 0;
2925 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2927 num_of_wifi_link = wifi_link_status >> 16;
2928 if (num_of_wifi_link >= 2) {
2929 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2930 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2931 bt_ctrl_agg_buf_size, agg_buf_size);
2932 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2936 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2937 if (coex_sta->c2h_bt_inquiry_page) {
2938 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2940 } else if (bt_hs_on) {
2941 halbtc8821a1ant_action_hs(btcoexist);
2945 if (BTC_PACKET_DHCP == type ||
2946 BTC_PACKET_EAPOL == type ||
2947 BTC_PACKET_ARP == type) {
2948 if (BTC_PACKET_ARP == type) {
2950 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2951 "[BTCoex], ARP Packet Count = %d\n",
2953 BTC_TRACE(trace_buf);
2954 if (coex_dm->arp_cnt >=
2955 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */
2959 halbtc8821a1ant_action_wifi_connected_specific_packet(
2964 void ex_halbtc8821a1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
2965 IN u8 *tmp_buf, IN u8 length)
2968 u8 i, rsp_source = 0;
2969 boolean wifi_connected = false;
2970 boolean bt_busy = false;
2971 boolean wifi_under_5g = false;
2974 coex_sta->c2h_bt_info_req_sent = false;
2976 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2978 rsp_source = tmp_buf[0] & 0xf;
2979 if (rsp_source >= BT_INFO_SRC_8821A_1ANT_MAX)
2980 rsp_source = BT_INFO_SRC_8821A_1ANT_WIFI_FW;
2981 coex_sta->bt_info_c2h_cnt[rsp_source]++;
2983 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2984 "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
2986 BTC_TRACE(trace_buf);
2987 for (i = 0; i < length; i++) {
2988 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
2990 bt_info = tmp_buf[i];
2991 if (i == length - 1) {
2992 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
2994 BTC_TRACE(trace_buf);
2996 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
2998 BTC_TRACE(trace_buf);
3001 /* if 0xff, it means BT is under WHCK test */
3002 if (bt_info == 0xff)
3003 coex_sta->bt_whck_test = true;
3005 coex_sta->bt_whck_test = false;
3007 if (BT_INFO_SRC_8821A_1ANT_WIFI_FW != rsp_source) {
3008 coex_sta->bt_retry_cnt = /* [3:0] */
3009 coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
3011 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
3012 coex_sta->c2h_bt_page = true;
3014 coex_sta->c2h_bt_page = false;
3017 coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
3019 coex_sta->bt_info_ext =
3020 coex_sta->bt_info_c2h[rsp_source][4];
3022 coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
3024 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
3025 &coex_sta->bt_tx_rx_mask);
3026 if (!coex_sta->bt_tx_rx_mask) {
3027 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
3028 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3029 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
3030 BTC_TRACE(trace_buf);
3031 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
3035 /* Here we need to resend some wifi info to BT */
3036 /* because bt is reset and loss of the info. */
3037 if (coex_sta->bt_info_ext & BIT(1)) {
3038 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3039 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
3040 BTC_TRACE(trace_buf);
3041 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3044 ex_halbtc8821a1ant_media_status_notify(
3045 btcoexist, BTC_MEDIA_CONNECT);
3047 ex_halbtc8821a1ant_media_status_notify(
3048 btcoexist, BTC_MEDIA_DISCONNECT);
3051 if ((coex_sta->bt_info_ext & BIT(3)) && !wifi_under_5g) {
3052 if (!btcoexist->manual_control &&
3053 !btcoexist->stop_coex_dm) {
3054 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3055 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
3056 BTC_TRACE(trace_buf);
3057 halbtc8821a1ant_ignore_wlan_act(btcoexist,
3061 /* BT already NOT ignore Wlan active, do nothing here. */
3063 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
3064 if ((coex_sta->bt_info_ext & BIT(4))) {
3065 /* BT auto report already enabled, do nothing */
3067 halbtc8821a1ant_bt_auto_report(btcoexist, FORCE_EXEC,
3072 /* check BIT2 first ==> check if bt is under inquiry or page scan */
3073 if (bt_info & BT_INFO_8821A_1ANT_B_INQ_PAGE)
3074 coex_sta->c2h_bt_inquiry_page = true;
3076 coex_sta->c2h_bt_inquiry_page = false;
3078 /* set link exist status */
3079 if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) {
3080 coex_sta->bt_link_exist = false;
3081 coex_sta->pan_exist = false;
3082 coex_sta->a2dp_exist = false;
3083 coex_sta->hid_exist = false;
3084 coex_sta->sco_exist = false;
3085 } else { /* connection exists */
3086 coex_sta->bt_link_exist = true;
3087 if (bt_info & BT_INFO_8821A_1ANT_B_FTP)
3088 coex_sta->pan_exist = true;
3090 coex_sta->pan_exist = false;
3091 if (bt_info & BT_INFO_8821A_1ANT_B_A2DP)
3092 coex_sta->a2dp_exist = true;
3094 coex_sta->a2dp_exist = false;
3095 if (bt_info & BT_INFO_8821A_1ANT_B_HID)
3096 coex_sta->hid_exist = true;
3098 coex_sta->hid_exist = false;
3099 if (bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO)
3100 coex_sta->sco_exist = true;
3102 coex_sta->sco_exist = false;
3105 halbtc8821a1ant_update_bt_link_info(btcoexist);
3108 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
3110 if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) {
3111 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
3112 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3113 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
3114 BTC_TRACE(trace_buf);
3115 } else if (bt_info ==
3116 BT_INFO_8821A_1ANT_B_CONNECTION) { /* connection exists but no busy */
3117 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE;
3118 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3119 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
3120 BTC_TRACE(trace_buf);
3121 } else if ((bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO) ||
3122 (bt_info & BT_INFO_8821A_1ANT_B_SCO_BUSY)) {
3123 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_SCO_BUSY;
3124 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3125 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
3126 BTC_TRACE(trace_buf);
3127 } else if (bt_info & BT_INFO_8821A_1ANT_B_ACL_BUSY) {
3128 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
3129 coex_dm->auto_tdma_adjust = false;
3130 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_ACL_BUSY;
3131 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3132 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
3133 BTC_TRACE(trace_buf);
3135 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_MAX;
3136 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3137 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
3138 BTC_TRACE(trace_buf);
3141 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
3142 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3143 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
3147 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3149 halbtc8821a1ant_run_coexist_mechanism(btcoexist);
3152 void ex_halbtc8821a1ant_halt_notify(IN struct btc_coexist *btcoexist)
3154 boolean wifi_under_5g = false;
3155 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3156 if (wifi_under_5g) {
3157 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3158 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
3159 BTC_TRACE(trace_buf);
3160 halbtc8821a1ant_coex_under_5g(btcoexist);
3164 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
3165 BTC_TRACE(trace_buf);
3167 halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3168 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true);
3169 /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
3171 halbtc8821a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3173 ex_halbtc8821a1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3175 btcoexist->stop_coex_dm = true;
3178 void ex_halbtc8821a1ant_pnp_notify(IN struct btc_coexist *btcoexist,
3181 boolean wifi_under_5g = false;
3183 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3184 if (wifi_under_5g) {
3185 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3186 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
3187 BTC_TRACE(trace_buf);
3188 halbtc8821a1ant_coex_under_5g(btcoexist);
3191 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
3192 BTC_TRACE(trace_buf);
3194 if (BTC_WIFI_PNP_SLEEP == pnp_state) {
3195 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3196 "[BTCoex], Pnp notify to SLEEP\n");
3197 BTC_TRACE(trace_buf);
3199 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3200 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3201 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
3203 /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
3205 /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */
3206 /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */
3207 /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */
3208 coex_sta->under_ips = false;
3209 coex_sta->under_lps = false;
3210 btcoexist->stop_coex_dm = true;
3211 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
3212 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3213 "[BTCoex], Pnp notify to WAKE UP\n");
3214 BTC_TRACE(trace_buf);
3215 btcoexist->stop_coex_dm = false;
3216 halbtc8821a1ant_init_hw_config(btcoexist, false, false);
3217 halbtc8821a1ant_init_coex_dm(btcoexist);
3218 halbtc8821a1ant_query_bt_info(btcoexist);
3222 void ex_halbtc8821a1ant_periodical(IN struct btc_coexist *btcoexist)
3226 if (((coex_sta->bt_coex_supported_version == 0) ||
3227 (coex_sta->bt_coex_supported_version == 0xffff)) && (!coex_sta->bt_disabled))
3228 btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, &coex_sta->bt_coex_supported_version);
3230 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3231 btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
3233 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
3234 halbtc8821a1ant_query_bt_info(btcoexist);
3235 halbtc8821a1ant_monitor_bt_enable_disable(btcoexist);
3237 halbtc8821a1ant_monitor_bt_ctr(btcoexist);
3238 halbtc8821a1ant_monitor_wifi_ctr(btcoexist);
3239 halbtc8821a1ant_monitor_bt_enable_disable(btcoexist);
3240 if (halbtc8821a1ant_is_wifi_status_changed(btcoexist) ||
3241 coex_dm->auto_tdma_adjust) {
3242 /* if(coex_sta->specific_pkt_period_cnt > 2) */
3244 halbtc8821a1ant_run_coexist_mechanism(btcoexist);
3248 coex_sta->specific_pkt_period_cnt++;
3254 #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */