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 = 20150615;
35 u32 glcoex_ver_8821a_1ant = 0x61;
37 /* ************************************************************
38 * local function proto type if needed
39 * ************************************************************
40 * ************************************************************
41 * local function start with halbtc8821a1ant_
42 * ************************************************************ */
43 u8 halbtc8821a1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
46 u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
48 bt_rssi = coex_sta->bt_rssi;
51 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
52 (coex_sta->pre_bt_rssi_state ==
53 BTC_RSSI_STATE_STAY_LOW)) {
54 if (bt_rssi >= (rssi_thresh +
55 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
56 bt_rssi_state = BTC_RSSI_STATE_HIGH;
58 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
60 if (bt_rssi < rssi_thresh)
61 bt_rssi_state = BTC_RSSI_STATE_LOW;
63 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
65 } else if (level_num == 3) {
66 if (rssi_thresh > rssi_thresh1) {
67 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
68 "[BTCoex], BT Rssi thresh error!!\n");
70 return coex_sta->pre_bt_rssi_state;
73 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
74 (coex_sta->pre_bt_rssi_state ==
75 BTC_RSSI_STATE_STAY_LOW)) {
76 if (bt_rssi >= (rssi_thresh +
77 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
78 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
80 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
81 } else if ((coex_sta->pre_bt_rssi_state ==
82 BTC_RSSI_STATE_MEDIUM) ||
83 (coex_sta->pre_bt_rssi_state ==
84 BTC_RSSI_STATE_STAY_MEDIUM)) {
85 if (bt_rssi >= (rssi_thresh1 +
86 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
87 bt_rssi_state = BTC_RSSI_STATE_HIGH;
88 else if (bt_rssi < rssi_thresh)
89 bt_rssi_state = BTC_RSSI_STATE_LOW;
91 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
93 if (bt_rssi < rssi_thresh1)
94 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
96 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
100 coex_sta->pre_bt_rssi_state = bt_rssi_state;
102 return bt_rssi_state;
105 u8 halbtc8821a1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
106 IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
109 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
111 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
113 if (level_num == 2) {
114 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
116 (coex_sta->pre_wifi_rssi_state[index] ==
117 BTC_RSSI_STATE_STAY_LOW)) {
118 if (wifi_rssi >= (rssi_thresh +
119 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
120 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
122 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
124 if (wifi_rssi < rssi_thresh)
125 wifi_rssi_state = BTC_RSSI_STATE_LOW;
127 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
129 } else if (level_num == 3) {
130 if (rssi_thresh > rssi_thresh1) {
131 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
132 "[BTCoex], wifi RSSI thresh error!!\n");
133 BTC_TRACE(trace_buf);
134 return coex_sta->pre_wifi_rssi_state[index];
137 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
139 (coex_sta->pre_wifi_rssi_state[index] ==
140 BTC_RSSI_STATE_STAY_LOW)) {
141 if (wifi_rssi >= (rssi_thresh +
142 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
143 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
145 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
146 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
147 BTC_RSSI_STATE_MEDIUM) ||
148 (coex_sta->pre_wifi_rssi_state[index] ==
149 BTC_RSSI_STATE_STAY_MEDIUM)) {
150 if (wifi_rssi >= (rssi_thresh1 +
151 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
152 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
153 else if (wifi_rssi < rssi_thresh)
154 wifi_rssi_state = BTC_RSSI_STATE_LOW;
156 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
158 if (wifi_rssi < rssi_thresh1)
159 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
161 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
165 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
167 return wifi_rssi_state;
170 void halbtc8821a1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
171 IN boolean force_exec, IN u32 dis_rate_mask)
173 coex_dm->cur_ra_mask = dis_rate_mask;
175 if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
176 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
177 &coex_dm->cur_ra_mask);
178 coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
181 void halbtc8821a1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
182 IN boolean force_exec, IN u8 type)
184 boolean wifi_under_b_mode = false;
186 coex_dm->cur_arfr_type = type;
188 if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
189 switch (coex_dm->cur_arfr_type) {
190 case 0: /* normal mode */
191 btcoexist->btc_write_4byte(btcoexist, 0x430,
192 coex_dm->backup_arfr_cnt1);
193 btcoexist->btc_write_4byte(btcoexist, 0x434,
194 coex_dm->backup_arfr_cnt2);
197 btcoexist->btc_get(btcoexist,
198 BTC_GET_BL_WIFI_UNDER_B_MODE,
200 if (wifi_under_b_mode) {
201 btcoexist->btc_write_4byte(btcoexist,
203 btcoexist->btc_write_4byte(btcoexist,
206 btcoexist->btc_write_4byte(btcoexist,
208 btcoexist->btc_write_4byte(btcoexist,
217 coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
220 void halbtc8821a1ant_retry_limit(IN struct btc_coexist *btcoexist,
221 IN boolean force_exec, IN u8 type)
223 coex_dm->cur_retry_limit_type = type;
226 (coex_dm->pre_retry_limit_type !=
227 coex_dm->cur_retry_limit_type)) {
228 switch (coex_dm->cur_retry_limit_type) {
229 case 0: /* normal mode */
230 btcoexist->btc_write_2byte(btcoexist, 0x42a,
231 coex_dm->backup_retry_limit);
233 case 1: /* retry limit=8 */
234 btcoexist->btc_write_2byte(btcoexist, 0x42a,
242 coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
245 void halbtc8821a1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
246 IN boolean force_exec, IN u8 type)
248 coex_dm->cur_ampdu_time_type = type;
251 (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
252 switch (coex_dm->cur_ampdu_time_type) {
253 case 0: /* normal mode */
254 btcoexist->btc_write_1byte(btcoexist, 0x456,
255 coex_dm->backup_ampdu_max_time);
257 case 1: /* AMPDU timw = 0x38 * 32us */
258 btcoexist->btc_write_1byte(btcoexist, 0x456,
266 coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
269 void halbtc8821a1ant_limited_tx(IN struct btc_coexist *btcoexist,
270 IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
271 IN u8 retry_limit_type, IN u8 ampdu_time_type)
273 switch (ra_mask_type) {
274 case 0: /* normal mode */
275 halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
278 case 1: /* disable cck 1/2 */
279 halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
282 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
283 halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
290 halbtc8821a1ant_auto_rate_fallback_retry(btcoexist, force_exec,
292 halbtc8821a1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
293 halbtc8821a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
300 void halbtc8821a1ant_limited_rx(IN struct btc_coexist *btcoexist,
301 IN boolean force_exec, IN boolean rej_ap_agg_pkt,
302 IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
304 boolean reject_rx_agg = rej_ap_agg_pkt;
305 boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
306 u8 rx_agg_size = agg_buf_size;
308 /* ============================================ */
309 /* Rx Aggregation related setting */
310 /* ============================================ */
311 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
313 /* decide BT control aggregation buf size or not */
314 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
315 &bt_ctrl_rx_agg_size);
316 /* aggregation buf size, only work when BT control Rx aggregation size. */
317 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
318 /* real update aggregation setting */
319 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
324 void halbtc8821a1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
326 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
327 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
329 /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
330 if (!(btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8)) {
331 coex_sta->high_priority_tx = 65535;
332 coex_sta->high_priority_rx = 65535;
333 coex_sta->low_priority_tx = 65535;
334 coex_sta->low_priority_rx = 65535;
341 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
342 reg_hp_tx = u32tmp & MASKLWORD;
343 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
345 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
346 reg_lp_tx = u32tmp & MASKLWORD;
347 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
349 coex_sta->high_priority_tx = reg_hp_tx;
350 coex_sta->high_priority_rx = reg_hp_rx;
351 coex_sta->low_priority_tx = reg_lp_tx;
352 coex_sta->low_priority_rx = reg_lp_rx;
355 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
358 void halbtc8821a1ant_query_bt_info(IN struct btc_coexist *btcoexist)
360 u8 h2c_parameter[1] = {0};
362 coex_sta->c2h_bt_info_req_sent = true;
364 h2c_parameter[0] |= BIT(0); /* trigger */
366 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
369 boolean halbtc8821a1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
371 static boolean pre_wifi_busy = false, pre_under_4way = false,
372 pre_bt_hs_on = false;
373 boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
374 boolean wifi_connected = false;
376 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
378 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
379 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
380 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
383 if (wifi_connected) {
384 if (wifi_busy != pre_wifi_busy) {
385 pre_wifi_busy = wifi_busy;
388 if (under_4way != pre_under_4way) {
389 pre_under_4way = under_4way;
392 if (bt_hs_on != pre_bt_hs_on) {
393 pre_bt_hs_on = bt_hs_on;
401 void halbtc8821a1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
403 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
404 boolean bt_hs_on = false;
406 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
408 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
409 bt_link_info->sco_exist = coex_sta->sco_exist;
410 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
411 bt_link_info->pan_exist = coex_sta->pan_exist;
412 bt_link_info->hid_exist = coex_sta->hid_exist;
414 /* work around for HS mode. */
416 bt_link_info->pan_exist = true;
417 bt_link_info->bt_link_exist = true;
420 /* check if Sco only */
421 if (bt_link_info->sco_exist &&
422 !bt_link_info->a2dp_exist &&
423 !bt_link_info->pan_exist &&
424 !bt_link_info->hid_exist)
425 bt_link_info->sco_only = true;
427 bt_link_info->sco_only = false;
429 /* check if A2dp only */
430 if (!bt_link_info->sco_exist &&
431 bt_link_info->a2dp_exist &&
432 !bt_link_info->pan_exist &&
433 !bt_link_info->hid_exist)
434 bt_link_info->a2dp_only = true;
436 bt_link_info->a2dp_only = false;
438 /* check if Pan only */
439 if (!bt_link_info->sco_exist &&
440 !bt_link_info->a2dp_exist &&
441 bt_link_info->pan_exist &&
442 !bt_link_info->hid_exist)
443 bt_link_info->pan_only = true;
445 bt_link_info->pan_only = false;
447 /* check if Hid only */
448 if (!bt_link_info->sco_exist &&
449 !bt_link_info->a2dp_exist &&
450 !bt_link_info->pan_exist &&
451 bt_link_info->hid_exist)
452 bt_link_info->hid_only = true;
454 bt_link_info->hid_only = false;
457 u8 halbtc8821a1ant_action_algorithm(IN struct btc_coexist *btcoexist)
459 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
460 boolean bt_hs_on = false;
461 u8 algorithm = BT_8821A_1ANT_COEX_ALGO_UNDEFINED;
462 u8 num_of_diff_profile = 0;
464 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
466 if (!bt_link_info->bt_link_exist) {
467 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
468 "[BTCoex], No BT link exists!!!\n");
469 BTC_TRACE(trace_buf);
473 if (bt_link_info->sco_exist)
474 num_of_diff_profile++;
475 if (bt_link_info->hid_exist)
476 num_of_diff_profile++;
477 if (bt_link_info->pan_exist)
478 num_of_diff_profile++;
479 if (bt_link_info->a2dp_exist)
480 num_of_diff_profile++;
482 if (num_of_diff_profile == 1) {
483 if (bt_link_info->sco_exist) {
484 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
485 "[BTCoex], BT Profile = SCO only\n");
486 BTC_TRACE(trace_buf);
487 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
489 if (bt_link_info->hid_exist) {
490 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
491 "[BTCoex], BT Profile = HID only\n");
492 BTC_TRACE(trace_buf);
493 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
494 } else if (bt_link_info->a2dp_exist) {
495 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
496 "[BTCoex], BT Profile = A2DP only\n");
497 BTC_TRACE(trace_buf);
498 algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP;
499 } else if (bt_link_info->pan_exist) {
501 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
502 "[BTCoex], BT Profile = PAN(HS) only\n");
503 BTC_TRACE(trace_buf);
505 BT_8821A_1ANT_COEX_ALGO_PANHS;
507 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
508 "[BTCoex], BT Profile = PAN(EDR) only\n");
509 BTC_TRACE(trace_buf);
511 BT_8821A_1ANT_COEX_ALGO_PANEDR;
515 } else if (num_of_diff_profile == 2) {
516 if (bt_link_info->sco_exist) {
517 if (bt_link_info->hid_exist) {
518 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
519 "[BTCoex], BT Profile = SCO + HID\n");
520 BTC_TRACE(trace_buf);
521 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
522 } else if (bt_link_info->a2dp_exist) {
523 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
524 "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
525 BTC_TRACE(trace_buf);
526 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
527 } else if (bt_link_info->pan_exist) {
529 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
530 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
531 BTC_TRACE(trace_buf);
532 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
534 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
535 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
536 BTC_TRACE(trace_buf);
538 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
542 if (bt_link_info->hid_exist &&
543 bt_link_info->a2dp_exist) {
544 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
545 "[BTCoex], BT Profile = HID + A2DP\n");
546 BTC_TRACE(trace_buf);
547 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
548 } else if (bt_link_info->hid_exist &&
549 bt_link_info->pan_exist) {
551 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
552 "[BTCoex], BT Profile = HID + PAN(HS)\n");
553 BTC_TRACE(trace_buf);
555 BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
557 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
558 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
559 BTC_TRACE(trace_buf);
561 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
563 } else if (bt_link_info->pan_exist &&
564 bt_link_info->a2dp_exist) {
566 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
567 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
568 BTC_TRACE(trace_buf);
570 BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS;
572 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
573 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
574 BTC_TRACE(trace_buf);
576 BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP;
580 } else if (num_of_diff_profile == 3) {
581 if (bt_link_info->sco_exist) {
582 if (bt_link_info->hid_exist &&
583 bt_link_info->a2dp_exist) {
584 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
585 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
586 BTC_TRACE(trace_buf);
587 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
588 } else if (bt_link_info->hid_exist &&
589 bt_link_info->pan_exist) {
591 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
592 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
593 BTC_TRACE(trace_buf);
595 BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
597 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
598 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
599 BTC_TRACE(trace_buf);
601 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
603 } else if (bt_link_info->pan_exist &&
604 bt_link_info->a2dp_exist) {
606 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
607 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
608 BTC_TRACE(trace_buf);
609 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
611 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
612 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
613 BTC_TRACE(trace_buf);
615 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
619 if (bt_link_info->hid_exist &&
620 bt_link_info->pan_exist &&
621 bt_link_info->a2dp_exist) {
623 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
624 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
625 BTC_TRACE(trace_buf);
627 BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
629 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
630 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
631 BTC_TRACE(trace_buf);
633 BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
637 } else if (num_of_diff_profile >= 3) {
638 if (bt_link_info->sco_exist) {
639 if (bt_link_info->hid_exist &&
640 bt_link_info->pan_exist &&
641 bt_link_info->a2dp_exist) {
643 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
644 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
645 BTC_TRACE(trace_buf);
648 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
649 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
650 BTC_TRACE(trace_buf);
652 BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
661 void halbtc8821a1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
662 IN boolean enable_auto_report)
664 u8 h2c_parameter[1] = {0};
666 h2c_parameter[0] = 0;
668 if (enable_auto_report)
669 h2c_parameter[0] |= BIT(0);
671 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
674 void halbtc8821a1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
675 IN boolean force_exec, IN boolean enable_auto_report)
677 coex_dm->cur_bt_auto_report = enable_auto_report;
680 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
683 halbtc8821a1ant_set_bt_auto_report(btcoexist,
684 coex_dm->cur_bt_auto_report);
686 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
689 void halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
690 *btcoexist, IN boolean low_penalty_ra)
692 u8 h2c_parameter[6] = {0};
694 h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
696 if (low_penalty_ra) {
697 h2c_parameter[1] |= BIT(0);
699 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
700 h2c_parameter[3] = 0xf5; /* MCS7 or OFDM54 */
701 h2c_parameter[4] = 0xa0; /* MCS6 or OFDM48// */
702 h2c_parameter[5] = 0xa0; /* MCS5 or OFDM36 // */
705 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
708 void halbtc8821a1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
709 IN boolean force_exec, IN boolean low_penalty_ra)
711 coex_dm->cur_low_penalty_ra = low_penalty_ra;
714 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
717 halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
718 coex_dm->cur_low_penalty_ra);
720 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
723 void halbtc8821a1ant_set_coex_table(IN struct btc_coexist *btcoexist,
724 IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
726 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
728 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
730 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
732 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
735 void halbtc8821a1ant_coex_table(IN struct btc_coexist *btcoexist,
736 IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
737 IN u32 val0x6c8, IN u8 val0x6cc)
739 coex_dm->cur_val0x6c0 = val0x6c0;
740 coex_dm->cur_val0x6c4 = val0x6c4;
741 coex_dm->cur_val0x6c8 = val0x6c8;
742 coex_dm->cur_val0x6cc = val0x6cc;
745 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
746 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
747 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
748 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
751 halbtc8821a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
754 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
755 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
756 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
757 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
760 void halbtc8821a1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
761 IN boolean force_exec, IN u8 type)
763 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
764 "[BTCoex], ********** CoexTable(%d) **********\n", type);
765 BTC_TRACE(trace_buf);
769 halbtc8821a1ant_coex_table(btcoexist, force_exec,
770 0x55555555, 0x55555555, 0xffffff, 0x3);
773 halbtc8821a1ant_coex_table(btcoexist, force_exec,
774 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
777 halbtc8821a1ant_coex_table(btcoexist, force_exec,
778 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
781 halbtc8821a1ant_coex_table(btcoexist, force_exec,
782 0x5a5a5a5a, 0xaaaaaaaa, 0xffffff, 0x3);
785 halbtc8821a1ant_coex_table(btcoexist, force_exec,
786 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
789 halbtc8821a1ant_coex_table(btcoexist, force_exec,
790 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3);
793 halbtc8821a1ant_coex_table(btcoexist, force_exec,
794 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
797 halbtc8821a1ant_coex_table(btcoexist, force_exec,
798 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
805 void halbtc8821a1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
808 u8 h2c_parameter[1] = {0};
811 h2c_parameter[0] |= BIT(0); /* function enable */
814 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
817 void halbtc8821a1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
818 IN boolean force_exec, IN boolean enable)
820 coex_dm->cur_ignore_wlan_act = enable;
823 if (coex_dm->pre_ignore_wlan_act ==
824 coex_dm->cur_ignore_wlan_act)
827 halbtc8821a1ant_set_fw_ignore_wlan_act(btcoexist, enable);
829 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
832 void halbtc8821a1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
833 IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
835 u8 h2c_parameter[5] = {0};
836 u8 real_byte1 = byte1, real_byte5 = byte5;
837 boolean ap_enable = false;
839 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
843 if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
844 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
845 "[BTCoex], FW for 1Ant AP mode\n");
846 BTC_TRACE(trace_buf);
847 real_byte1 &= ~BIT(4);
848 real_byte1 |= BIT(5);
850 real_byte5 |= BIT(5);
851 real_byte5 &= ~BIT(6);
855 h2c_parameter[0] = real_byte1;
856 h2c_parameter[1] = byte2;
857 h2c_parameter[2] = byte3;
858 h2c_parameter[3] = byte4;
859 h2c_parameter[4] = real_byte5;
861 coex_dm->ps_tdma_para[0] = real_byte1;
862 coex_dm->ps_tdma_para[1] = byte2;
863 coex_dm->ps_tdma_para[2] = byte3;
864 coex_dm->ps_tdma_para[3] = byte4;
865 coex_dm->ps_tdma_para[4] = real_byte5;
867 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
870 void halbtc8821a1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
871 IN u8 lps_val, IN u8 rpwm_val)
876 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
877 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
880 void halbtc8821a1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
881 IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
883 coex_dm->cur_lps = lps_val;
884 coex_dm->cur_rpwm = rpwm_val;
887 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
888 (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
891 halbtc8821a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
893 coex_dm->pre_lps = coex_dm->cur_lps;
894 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
897 void halbtc8821a1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
898 IN boolean low_penalty_ra)
900 halbtc8821a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
903 void halbtc8821a1ant_set_ant_path(IN struct btc_coexist *btcoexist,
904 IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
906 struct btc_board_info *board_info = &btcoexist->board_info;
908 u8 h2c_parameter[2] = {0};
911 /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */
912 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
915 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
918 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
920 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
921 /* tell firmware "antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */
922 h2c_parameter[0] = 1;
923 h2c_parameter[1] = 1;
924 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
927 /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x1); //Main Ant to BT for IPS case 0x4c[23]=1 */
929 /* tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */
930 h2c_parameter[0] = 0;
931 h2c_parameter[1] = 1;
932 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
935 /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x0); //Aux Ant to BT for IPS case 0x4c[23]=1 */
937 } else if (wifi_off) {
938 /* 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL BT Vendor 0xac=0xf002 */
939 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
942 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
945 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
948 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x0);
951 /* ext switch setting */
952 switch (ant_pos_type) {
953 case BTC_ANT_PATH_WIFI:
954 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
955 if (board_info->btdm_ant_pos ==
956 BTC_ANTENNA_AT_MAIN_PORT)
957 btcoexist->btc_write_1byte_bitmask(btcoexist,
960 btcoexist->btc_write_1byte_bitmask(btcoexist,
963 case BTC_ANT_PATH_BT:
964 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
965 if (board_info->btdm_ant_pos ==
966 BTC_ANTENNA_AT_MAIN_PORT)
967 btcoexist->btc_write_1byte_bitmask(btcoexist,
970 btcoexist->btc_write_1byte_bitmask(btcoexist,
974 case BTC_ANT_PATH_PTA:
975 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x66);
976 if (board_info->btdm_ant_pos ==
977 BTC_ANTENNA_AT_MAIN_PORT)
978 btcoexist->btc_write_1byte_bitmask(btcoexist,
981 btcoexist->btc_write_1byte_bitmask(btcoexist,
987 void halbtc8821a1ant_ps_tdma(IN struct btc_coexist *btcoexist,
988 IN boolean force_exec, IN boolean turn_on, IN u8 type)
990 u8 rssi_adjust_val = 0;
993 coex_dm->cur_ps_tdma_on = turn_on;
994 coex_dm->cur_ps_tdma = type;
996 if (coex_dm->cur_ps_tdma_on) {
997 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
998 "[BTCoex], ********** TDMA(on, %d) **********\n",
999 coex_dm->cur_ps_tdma);
1000 BTC_TRACE(trace_buf);
1002 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1003 "[BTCoex], ********** TDMA(off, %d) **********\n",
1004 coex_dm->cur_ps_tdma);
1005 BTC_TRACE(trace_buf);
1009 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1010 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1016 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1017 0x1a, 0x1a, 0x0, 0x50);
1020 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1021 0x3a, 0x03, 0x10, 0x50);
1022 rssi_adjust_val = 11;
1025 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1026 0x2b, 0x03, 0x10, 0x50);
1027 rssi_adjust_val = 14;
1030 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1031 0x1d, 0x1d, 0x0, 0x52);
1034 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1035 0x15, 0x3, 0x14, 0x0);
1036 rssi_adjust_val = 17;
1039 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1040 0x15, 0x3, 0x11, 0x10);
1043 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1044 0x20, 0x3, 0x11, 0x13);
1047 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1048 0xc, 0x5, 0x0, 0x0);
1051 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1052 0x25, 0x3, 0x10, 0x0);
1055 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1056 0x21, 0x3, 0x10, 0x50);
1057 rssi_adjust_val = 18;
1060 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1061 0xa, 0xa, 0x0, 0x40);
1064 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1065 0x15, 0x03, 0x10, 0x50);
1066 rssi_adjust_val = 20;
1069 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1070 0x0a, 0x0a, 0x0, 0x50);
1073 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1074 0x12, 0x12, 0x0, 0x50);
1077 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1078 0x1e, 0x3, 0x10, 0x14);
1081 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1082 0xa, 0x3, 0x8, 0x0);
1085 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1086 0x15, 0x3, 0x10, 0x0);
1087 rssi_adjust_val = 18;
1090 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1091 0x25, 0x3, 0x10, 0x0);
1092 rssi_adjust_val = 14;
1095 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1096 0x35, 0x03, 0x11, 0x10);
1099 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1100 0x25, 0x03, 0x11, 0x11);
1103 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1104 0x25, 0x03, 0x11, 0x10);
1107 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1108 0x25, 0x3, 0x31, 0x18);
1109 rssi_adjust_val = 22;
1112 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1113 0x15, 0x3, 0x31, 0x18);
1114 rssi_adjust_val = 22;
1117 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1118 0xa, 0x3, 0x31, 0x18);
1119 rssi_adjust_val = 22;
1122 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1123 0xa, 0x3, 0x31, 0x18);
1124 rssi_adjust_val = 22;
1127 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1128 0x25, 0x3, 0x31, 0x98);
1129 rssi_adjust_val = 22;
1132 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x69,
1133 0x25, 0x3, 0x31, 0x0);
1136 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xab,
1137 0x1a, 0x1a, 0x1, 0x10);
1140 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1141 0x30, 0x3, 0x10, 0x10);
1144 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3,
1145 0x1a, 0x1a, 0, 0x58);
1148 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1149 0x35, 0x3, 0x11, 0x11);
1152 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xa3,
1153 0x25, 0x3, 0x30, 0x90);
1156 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x53,
1157 0x1a, 0x1a, 0x0, 0x10);
1160 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x63,
1161 0x1a, 0x1a, 0x0, 0x10);
1164 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3,
1165 0x12, 0x3, 0x14, 0x50);
1167 case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */
1168 /* here softap mode screen off will cost 70-80mA for phone */
1169 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x23,
1170 0x18, 0x00, 0x10, 0x24);
1173 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1174 0x15, 0x3, 0x11, 0x11);
1177 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1178 0x20, 0x3, 0x11, 0x11);
1181 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1182 0x30, 0x3, 0x10, 0x11);
1186 /* disable PS tdma */
1188 case 8: /* PTA Control */
1189 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x8,
1190 0x0, 0x0, 0x0, 0x0);
1191 halbtc8821a1ant_set_ant_path(btcoexist,
1192 BTC_ANT_PATH_PTA, false, false);
1195 default: /* Software control, Antenna at BT side */
1196 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1197 0x0, 0x0, 0x0, 0x0);
1198 halbtc8821a1ant_set_ant_path(btcoexist,
1199 BTC_ANT_PATH_BT, false, false);
1201 case 9: /* Software control, Antenna at WiFi side */
1202 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1203 0x0, 0x0, 0x0, 0x0);
1204 halbtc8821a1ant_set_ant_path(btcoexist,
1205 BTC_ANT_PATH_WIFI, false, false);
1207 case 10: /* under 5G */
1208 halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1209 0x0, 0x0, 0x8, 0x0);
1210 halbtc8821a1ant_set_ant_path(btcoexist,
1211 BTC_ANT_PATH_BT, false, false);
1215 rssi_adjust_val = 0;
1216 btcoexist->btc_set(btcoexist,
1217 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
1219 /* update pre state */
1220 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1221 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1224 void halbtc8821a1ant_coex_all_off(IN struct btc_coexist *btcoexist)
1227 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1230 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1233 boolean halbtc8821a1ant_is_common_action(IN struct btc_coexist *btcoexist)
1235 boolean common = false, wifi_connected = false, wifi_busy = false;
1237 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1239 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1241 if (!wifi_connected &&
1242 BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1243 coex_dm->bt_status) {
1244 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1245 "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
1246 BTC_TRACE(trace_buf);
1247 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1250 } else if (wifi_connected &&
1251 (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1252 coex_dm->bt_status)) {
1253 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1254 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1255 BTC_TRACE(trace_buf);
1256 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1259 } else if (!wifi_connected &&
1260 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
1261 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1262 "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
1263 BTC_TRACE(trace_buf);
1264 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1267 } else if (wifi_connected &&
1268 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
1269 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1270 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1271 BTC_TRACE(trace_buf);
1272 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1275 } else if (!wifi_connected &&
1276 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE != coex_dm->bt_status)) {
1277 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1278 "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
1279 BTC_TRACE(trace_buf);
1280 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1285 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1286 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1287 BTC_TRACE(trace_buf);
1289 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1290 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1291 BTC_TRACE(trace_buf);
1300 void halbtc8821a1ant_ps_tdma_check_for_power_save_state(
1301 IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1305 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1307 if (lps_mode) { /* already under LPS state */
1309 /* keep state under LPS, do nothing. */
1311 /* will leave LPS state, turn off psTdma first */
1312 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1315 } else { /* NO PS state */
1317 /* will enter LPS state, turn off psTdma first */
1318 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1321 /* keep state under NO PS state, do nothing. */
1326 void halbtc8821a1ant_power_save_state(IN struct btc_coexist *btcoexist,
1327 IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
1329 boolean low_pwr_disable = false;
1332 case BTC_PS_WIFI_NATIVE:
1333 /* recover to original 32k low power setting */
1334 low_pwr_disable = false;
1335 btcoexist->btc_set(btcoexist,
1336 BTC_SET_ACT_DISABLE_LOW_POWER,
1338 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1342 halbtc8821a1ant_ps_tdma_check_for_power_save_state(
1344 halbtc8821a1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1346 /* when coex force to enter LPS, do not enter 32k low power. */
1347 low_pwr_disable = true;
1348 btcoexist->btc_set(btcoexist,
1349 BTC_SET_ACT_DISABLE_LOW_POWER,
1351 /* power save must executed before psTdma. */
1352 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1355 case BTC_PS_LPS_OFF:
1356 halbtc8821a1ant_ps_tdma_check_for_power_save_state(
1358 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1366 void halbtc8821a1ant_coex_under_5g(IN struct btc_coexist *btcoexist)
1368 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1371 halbtc8821a1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
1373 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 10);
1375 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1377 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
1379 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5);
1382 void halbtc8821a1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
1384 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1385 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9);
1388 void halbtc8821a1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
1390 static u32 bt_disable_cnt = 0;
1391 boolean bt_active = true, bt_disabled = false;
1393 /* This function check if bt is disabled */
1395 if (coex_sta->high_priority_tx == 0 &&
1396 coex_sta->high_priority_rx == 0 &&
1397 coex_sta->low_priority_tx == 0 &&
1398 coex_sta->low_priority_rx == 0)
1400 if (coex_sta->high_priority_tx == 0xffff &&
1401 coex_sta->high_priority_rx == 0xffff &&
1402 coex_sta->low_priority_tx == 0xffff &&
1403 coex_sta->low_priority_rx == 0xffff)
1407 bt_disabled = false;
1408 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1410 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1411 "[BTCoex], BT is enabled !!\n");
1412 BTC_TRACE(trace_buf);
1415 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1416 "[BTCoex], bt all counters=0, %d times!!\n",
1418 BTC_TRACE(trace_buf);
1419 if (bt_disable_cnt >= 2) {
1421 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1423 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1424 "[BTCoex], BT is disabled !!\n");
1425 BTC_TRACE(trace_buf);
1426 halbtc8821a1ant_action_wifi_only(btcoexist);
1429 if (coex_sta->bt_disabled != bt_disabled) {
1430 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1431 "[BTCoex], BT is from %s to %s!!\n",
1432 (coex_sta->bt_disabled ? "disabled" : "enabled"),
1433 (bt_disabled ? "disabled" : "enabled"));
1434 BTC_TRACE(trace_buf);
1435 coex_sta->bt_disabled = bt_disabled;
1438 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1440 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1446 /* *********************************************
1448 * Software Coex Mechanism start
1450 * ********************************************* */
1452 void halbtc8821a1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist)
1454 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1457 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1458 /* halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false); */
1459 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, false, false);
1460 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1462 /* SCO only or SCO+PAN(HS) */
1463 void halbtc8821a1ant_action_sco(IN struct btc_coexist *btcoexist)
1465 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1468 void halbtc8821a1ant_action_hid(IN struct btc_coexist *btcoexist)
1470 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1473 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
1474 void halbtc8821a1ant_action_a2dp(IN struct btc_coexist *btcoexist)
1476 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1479 void halbtc8821a1ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
1481 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1484 void halbtc8821a1ant_action_pan_edr(IN struct btc_coexist *btcoexist)
1486 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1490 void halbtc8821a1ant_action_pan_hs(IN struct btc_coexist *btcoexist)
1492 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1496 void halbtc8821a1ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
1498 halbtc8821a1ant_sw_mechanism(btcoexist, false);
1501 void halbtc8821a1ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
1503 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1506 /* HID+A2DP+PAN(EDR) */
1507 void halbtc8821a1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
1509 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1512 void halbtc8821a1ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
1514 halbtc8821a1ant_sw_mechanism(btcoexist, true);
1517 /* *********************************************
1519 * Non-Software Coex Mechanism start
1521 * ********************************************* */
1522 void halbtc8821a1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
1524 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1527 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1528 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1531 void halbtc8821a1ant_action_hs(IN struct btc_coexist *btcoexist)
1533 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1534 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1537 void halbtc8821a1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
1539 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1540 boolean wifi_connected = false, ap_enable = false, wifi_busy = false,
1543 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1545 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1547 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1548 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
1550 if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) {
1551 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1553 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1555 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1559 else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1560 (bt_link_info->a2dp_exist)) {
1561 /* SCO/HID/A2DP busy */
1562 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1564 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1566 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1571 else if ((bt_link_info->a2dp_exist) &&
1572 (bt_link_info->hid_exist)) {
1574 halbtc8821a1ant_power_save_state(btcoexist,
1575 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1576 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1579 halbtc8821a1ant_coex_table_with_type(btcoexist,
1584 else if ((bt_link_info->pan_exist) || (wifi_busy)) {
1585 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1587 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1589 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1591 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1593 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1595 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1599 void halbtc8821a1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
1600 *btcoexist, IN u8 wifi_status)
1602 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1603 boolean wifi_connected = false;
1605 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1608 /* tdma and coex table */
1610 if (bt_link_info->sco_exist) {
1611 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 41);
1612 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1614 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 42);
1615 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1619 void halbtc8821a1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
1620 *btcoexist, IN u8 wifi_status)
1624 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1625 bt_rssi_state = halbtc8821a1ant_bt_rssi_state(2, 28, 0);
1627 if (bt_link_info->hid_only) { /* HID */
1628 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1630 coex_dm->auto_tdma_adjust = false;
1632 } else if (bt_link_info->a2dp_only) { /* A2DP */
1633 if (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
1634 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); */
1635 /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); */
1636 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1638 halbtc8821a1ant_coex_table_with_type(btcoexist,
1640 coex_dm->auto_tdma_adjust = false;
1641 } else if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
1642 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
1643 /* halbtc8821a1ant_tdma_duration_adjust_for_acl(btcoexist, wifi_status); */
1644 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1646 halbtc8821a1ant_coex_table_with_type(btcoexist,
1648 } else { /* for low BT RSSI */
1649 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1651 halbtc8821a1ant_coex_table_with_type(btcoexist,
1653 coex_dm->auto_tdma_adjust = false;
1655 } else if (bt_link_info->hid_exist &&
1656 bt_link_info->a2dp_exist) { /* HID+A2DP */
1657 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
1658 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
1659 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1661 coex_dm->auto_tdma_adjust = false;
1662 } else { /* for low BT RSSI */
1663 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1665 coex_dm->auto_tdma_adjust = false;
1668 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1669 } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
1670 bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
1671 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1672 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
1673 coex_dm->auto_tdma_adjust = false;
1674 } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
1675 (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
1676 bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
1677 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 43);
1678 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1679 coex_dm->auto_tdma_adjust = false;
1681 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1682 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1683 coex_dm->auto_tdma_adjust = false;
1687 void halbtc8821a1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
1689 /* power save state */
1690 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1693 /* tdma and coex table */
1694 halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
1695 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1698 void halbtc8821a1ant_action_wifi_not_connected_scan(IN struct btc_coexist
1701 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1703 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1706 /* tdma and coex table */
1707 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1708 if (bt_link_info->a2dp_exist) {
1710 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1712 halbtc8821a1ant_coex_table_with_type(btcoexist,
1714 } else if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
1715 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1717 halbtc8821a1ant_coex_table_with_type(btcoexist,
1720 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1722 halbtc8821a1ant_coex_table_with_type(btcoexist,
1725 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1726 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1727 coex_dm->bt_status)) {
1728 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1729 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1731 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */
1732 /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */
1735 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1736 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1740 void halbtc8821a1ant_action_wifi_not_connected_asso_auth(
1741 IN struct btc_coexist *btcoexist)
1743 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1745 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1748 /* tdma and coex table */
1749 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) {
1751 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
1752 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1753 } else if ((bt_link_info->a2dp_exist) || (bt_link_info->pan_exist)) {
1754 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1755 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1757 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1758 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1762 void halbtc8821a1ant_action_wifi_connected_scan(IN struct btc_coexist
1765 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1767 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1770 /* tdma and coex table */
1771 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1772 if (bt_link_info->a2dp_exist) {
1774 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1776 halbtc8821a1ant_coex_table_with_type(btcoexist,
1778 } else if (bt_link_info->a2dp_exist &&
1779 bt_link_info->pan_exist) {
1780 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1782 halbtc8821a1ant_coex_table_with_type(btcoexist,
1785 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1787 halbtc8821a1ant_coex_table_with_type(btcoexist,
1790 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1791 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1792 coex_dm->bt_status)) {
1793 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1794 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1796 /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */
1797 /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */
1800 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1801 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1805 void halbtc8821a1ant_action_wifi_connected_specific_packet(
1806 IN struct btc_coexist *btcoexist)
1808 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1810 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1813 /* tdma and coex table */
1815 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1816 (bt_link_info->a2dp_exist)) {
1817 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1818 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1821 if ((bt_link_info->hid_exist) && (bt_link_info->a2dp_exist)) {
1822 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1824 halbtc8821a1ant_coex_table_with_type(btcoexist,
1829 else if (bt_link_info->pan_exist) {
1830 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1831 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1833 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1834 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1838 void halbtc8821a1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
1840 boolean wifi_busy = false;
1841 boolean scan = false, link = false, roam = false;
1842 boolean under_4way = false, ap_enable = false;
1844 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1845 "[BTCoex], CoexForWifiConnect()===>\n");
1846 BTC_TRACE(trace_buf);
1848 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
1851 halbtc8821a1ant_action_wifi_connected_specific_packet(btcoexist);
1852 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1853 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
1854 BTC_TRACE(trace_buf);
1858 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1859 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1860 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1861 if (scan || link || roam) {
1863 halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
1865 halbtc8821a1ant_action_wifi_connected_specific_packet(
1867 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1868 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
1869 BTC_TRACE(trace_buf);
1873 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1875 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1876 /* power save state */
1878 BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status &&
1879 !btcoexist->bt_link_info.hid_only) {
1880 if (!wifi_busy && btcoexist->bt_link_info.a2dp_only) /* A2DP */
1881 halbtc8821a1ant_power_save_state(btcoexist,
1882 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1884 halbtc8821a1ant_power_save_state(btcoexist,
1885 BTC_PS_LPS_ON, 0x50, 0x4);
1887 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1890 /* tdma and coex table */
1892 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1893 halbtc8821a1ant_action_wifi_connected_bt_acl_busy(
1895 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1896 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
1897 coex_dm->bt_status) ||
1898 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1899 coex_dm->bt_status)) {
1900 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1901 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1903 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1905 halbtc8821a1ant_coex_table_with_type(btcoexist,
1909 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1910 halbtc8821a1ant_action_wifi_connected_bt_acl_busy(
1912 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
1913 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
1914 coex_dm->bt_status) ||
1915 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1916 coex_dm->bt_status)) {
1917 halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1918 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
1920 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1922 halbtc8821a1ant_coex_table_with_type(btcoexist,
1928 void halbtc8821a1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
1932 algorithm = halbtc8821a1ant_action_algorithm(btcoexist);
1933 coex_dm->cur_algorithm = algorithm;
1935 if (halbtc8821a1ant_is_common_action(btcoexist)) {
1938 switch (coex_dm->cur_algorithm) {
1939 case BT_8821A_1ANT_COEX_ALGO_SCO:
1940 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1941 "[BTCoex], Action algorithm = SCO.\n");
1942 BTC_TRACE(trace_buf);
1943 halbtc8821a1ant_action_sco(btcoexist);
1945 case BT_8821A_1ANT_COEX_ALGO_HID:
1946 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1947 "[BTCoex], Action algorithm = HID.\n");
1948 BTC_TRACE(trace_buf);
1949 halbtc8821a1ant_action_hid(btcoexist);
1951 case BT_8821A_1ANT_COEX_ALGO_A2DP:
1952 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1953 "[BTCoex], Action algorithm = A2DP.\n");
1954 BTC_TRACE(trace_buf);
1955 halbtc8821a1ant_action_a2dp(btcoexist);
1957 case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS:
1958 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1959 "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
1960 BTC_TRACE(trace_buf);
1961 halbtc8821a1ant_action_a2dp_pan_hs(btcoexist);
1963 case BT_8821A_1ANT_COEX_ALGO_PANEDR:
1964 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1965 "[BTCoex], Action algorithm = PAN(EDR).\n");
1966 BTC_TRACE(trace_buf);
1967 halbtc8821a1ant_action_pan_edr(btcoexist);
1969 case BT_8821A_1ANT_COEX_ALGO_PANHS:
1970 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1971 "[BTCoex], Action algorithm = HS mode.\n");
1972 BTC_TRACE(trace_buf);
1973 halbtc8821a1ant_action_pan_hs(btcoexist);
1975 case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP:
1976 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1977 "[BTCoex], Action algorithm = PAN+A2DP.\n");
1978 BTC_TRACE(trace_buf);
1979 halbtc8821a1ant_action_pan_edr_a2dp(btcoexist);
1981 case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID:
1982 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1983 "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
1984 BTC_TRACE(trace_buf);
1985 halbtc8821a1ant_action_pan_edr_hid(btcoexist);
1987 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
1988 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1989 "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
1990 BTC_TRACE(trace_buf);
1991 halbtc8821a1ant_action_hid_a2dp_pan_edr(
1994 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP:
1995 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1996 "[BTCoex], Action algorithm = HID+A2DP.\n");
1997 BTC_TRACE(trace_buf);
1998 halbtc8821a1ant_action_hid_a2dp(btcoexist);
2001 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2002 "[BTCoex], Action algorithm = coexist All Off!!\n");
2003 BTC_TRACE(trace_buf);
2004 /* halbtc8821a1ant_coex_all_off(btcoexist); */
2007 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
2011 void halbtc8821a1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
2013 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2014 boolean wifi_connected = false, bt_hs_on = false;
2015 boolean increase_scan_dev_num = false;
2016 boolean bt_ctrl_agg_buf_size = false;
2017 u8 agg_buf_size = 5;
2018 u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
2019 u32 wifi_link_status = 0;
2020 u32 num_of_wifi_link = 0;
2021 boolean wifi_under_5g = false;
2023 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2024 "[BTCoex], RunCoexistMechanism()===>\n");
2025 BTC_TRACE(trace_buf);
2027 if (btcoexist->manual_control) {
2028 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2029 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2030 BTC_TRACE(trace_buf);
2034 if (btcoexist->stop_coex_dm) {
2035 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2036 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2037 BTC_TRACE(trace_buf);
2041 if (coex_sta->under_ips) {
2042 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2043 "[BTCoex], wifi is under IPS !!!\n");
2044 BTC_TRACE(trace_buf);
2048 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2049 if (wifi_under_5g) {
2050 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2051 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2052 BTC_TRACE(trace_buf);
2053 halbtc8821a1ant_coex_under_5g(btcoexist);
2056 if (coex_sta->bt_whck_test) {
2057 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2058 "[BTCoex], BT is under WHCK TEST!!!\n");
2059 BTC_TRACE(trace_buf);
2060 halbtc8821a1ant_action_bt_whck_test(btcoexist);
2064 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
2065 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2066 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
2067 increase_scan_dev_num = true;
2069 btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
2070 &increase_scan_dev_num);
2071 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2074 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2076 num_of_wifi_link = wifi_link_status >> 16;
2077 if ((num_of_wifi_link >= 2) ||
2078 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
2079 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2080 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2081 bt_ctrl_agg_buf_size, agg_buf_size);
2082 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2086 if (!bt_link_info->sco_exist && !bt_link_info->hid_exist)
2087 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2089 if (wifi_connected) {
2090 wifi_rssi_state = halbtc8821a1ant_wifi_rssi_state(
2091 btcoexist, 1, 2, 30, 0);
2092 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2093 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2094 /* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */
2095 halbtc8821a1ant_limited_tx(btcoexist,
2096 NORMAL_EXEC, 1, 1, 0, 1);
2098 /* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */
2099 halbtc8821a1ant_limited_tx(btcoexist,
2100 NORMAL_EXEC, 1, 1, 0, 1);
2103 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
2108 if (bt_link_info->sco_exist) {
2109 bt_ctrl_agg_buf_size = true;
2111 } else if (bt_link_info->hid_exist) {
2112 bt_ctrl_agg_buf_size = true;
2114 } else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) {
2115 bt_ctrl_agg_buf_size = true;
2118 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2119 bt_ctrl_agg_buf_size, agg_buf_size);
2121 halbtc8821a1ant_run_sw_coexist_mechanism(btcoexist);
2123 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2124 if (coex_sta->c2h_bt_inquiry_page) {
2125 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2127 } else if (bt_hs_on) {
2128 halbtc8821a1ant_action_hs(btcoexist);
2133 if (!wifi_connected) {
2134 boolean scan = false, link = false, roam = false;
2136 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2137 "[BTCoex], wifi is non connected-idle !!!\n");
2138 BTC_TRACE(trace_buf);
2140 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2141 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2142 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2144 if (scan || link || roam) {
2146 halbtc8821a1ant_action_wifi_not_connected_scan(
2149 halbtc8821a1ant_action_wifi_not_connected_asso_auth(
2152 halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2153 } else /* wifi LPS/Busy */
2154 halbtc8821a1ant_action_wifi_connected(btcoexist);
2157 void halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2159 /* force to reset coex mechanism */
2161 halbtc8821a1ant_sw_mechanism(btcoexist, false);
2163 /* halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
2164 halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2167 void halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2168 IN boolean back_up, IN boolean wifi_only)
2171 boolean wifi_under_5g = false;
2174 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2175 "[BTCoex], 1Ant Init HW Config!!\n");
2176 BTC_TRACE(trace_buf);
2182 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
2184 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
2186 coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
2188 coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
2192 /* 0x790[5:0]=0x5 */
2193 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
2196 btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
2198 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2200 /* Antenna config */
2202 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, true,
2205 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, true,
2209 halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2211 /* Enable counter statistics */
2212 btcoexist->btc_write_1byte(btcoexist, 0x76e,
2213 0xc); /* 0x76e[3] =1, WLAN_Act control by PTA */
2214 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
2215 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
2218 /* ************************************************************
2219 * work around function start with wa_halbtc8821a1ant_
2220 * ************************************************************
2221 * ************************************************************
2222 * extern function start with ex_halbtc8821a1ant_
2223 * ************************************************************ */
2224 void ex_halbtc8821a1ant_power_on_setting(IN struct btc_coexist *btcoexist)
2228 void ex_halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2229 IN boolean wifi_only)
2231 halbtc8821a1ant_init_hw_config(btcoexist, true, wifi_only);
2234 void ex_halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2236 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2237 "[BTCoex], Coex Mechanism Init!!\n");
2238 BTC_TRACE(trace_buf);
2240 btcoexist->stop_coex_dm = false;
2242 halbtc8821a1ant_init_coex_dm(btcoexist);
2244 halbtc8821a1ant_query_bt_info(btcoexist);
2247 void ex_halbtc8821a1ant_display_coex_info(IN struct btc_coexist *btcoexist)
2249 struct btc_board_info *board_info = &btcoexist->board_info;
2250 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2251 u8 *cli_buf = btcoexist->cli_buf;
2252 u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
2255 u32 fw_ver = 0, bt_patch_ver = 0;
2257 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2258 "\r\n ============[BT Coexist info]============");
2261 if (btcoexist->manual_control) {
2262 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2263 "\r\n ============[Under Manual Control]============");
2265 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2266 "\r\n ==========================================");
2269 if (btcoexist->stop_coex_dm) {
2270 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2271 "\r\n ============[Coex is STOPPED]============");
2273 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2274 "\r\n ==========================================");
2278 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d",
2279 "Ant PG Num/ Ant Mech/ Ant Pos:",
2280 board_info->pg_ant_num, board_info->btdm_ant_num,
2281 board_info->btdm_ant_pos);
2284 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
2285 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
2286 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2287 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
2288 "CoexVer/ FwVer/ PatchVer",
2289 glcoex_ver_date_8821a_1ant, glcoex_ver_8821a_1ant, fw_ver,
2290 bt_patch_ver, bt_patch_ver);
2293 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
2294 "Wifi channel informed to BT",
2295 coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
2296 coex_dm->wifi_chnl_info[2]);
2300 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2301 "============[Wifi Status]============");
2303 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
2305 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2306 "============[BT Status]============");
2309 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
2310 "BT [status/ rssi/ retryCnt]",
2311 ((coex_sta->bt_disabled) ? ("disabled") : ((
2312 coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
2313 : ((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2314 coex_dm->bt_status) ? "non-connected idle" :
2315 ((BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
2316 ? "connected-idle" : "busy")))),
2317 coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
2320 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
2322 bt_link_info->sco_exist, bt_link_info->hid_exist,
2323 bt_link_info->pan_exist, bt_link_info->a2dp_exist);
2325 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
2327 bt_info_ext = coex_sta->bt_info_ext;
2328 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
2329 "BT Info A2DP rate",
2330 (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
2333 for (i = 0; i < BT_INFO_SRC_8821A_1ANT_MAX; i++) {
2334 if (coex_sta->bt_info_c2h_cnt[i]) {
2335 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2336 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
2337 glbt_info_src_8821a_1ant[i],
2338 coex_sta->bt_info_c2h[i][0],
2339 coex_sta->bt_info_c2h[i][1],
2340 coex_sta->bt_info_c2h[i][2],
2341 coex_sta->bt_info_c2h[i][3],
2342 coex_sta->bt_info_c2h[i][4],
2343 coex_sta->bt_info_c2h[i][5],
2344 coex_sta->bt_info_c2h[i][6],
2345 coex_sta->bt_info_c2h_cnt[i]);
2350 if (!btcoexist->manual_control) {
2351 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
2353 coex_dm->cur_low_penalty_ra);
2356 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2357 "============[mechanisms]============");
2360 ps_tdma_case = coex_dm->cur_ps_tdma;
2361 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2362 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
2364 coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
2365 coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
2366 coex_dm->ps_tdma_para[4], ps_tdma_case,
2367 coex_dm->auto_tdma_adjust);
2370 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ",
2372 coex_dm->cur_ignore_wlan_act);
2375 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ",
2376 "Latest error condition(should be 0)",
2377 coex_dm->error_condition);
2382 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2383 "============[Hw setting]============");
2386 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2387 "backup ARFR1/ARFR2/RL/AMaxTime",
2388 coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2,
2389 coex_dm->backup_retry_limit,
2390 coex_dm->backup_ampdu_max_time);
2393 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
2394 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
2395 u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
2396 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
2397 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2398 "0x430/0x434/0x42a/0x456",
2399 u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
2402 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
2403 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc58);
2404 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2405 "0x778/ 0xc58[29:25]",
2406 u8tmp[0], (u32tmp[0] & 0x3e000000) >> 25);
2409 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
2410 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x8db[6:5]",
2411 ((u8tmp[0] & 0x60) >> 5));
2414 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x975);
2415 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2416 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2417 "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]",
2418 (u32tmp[0] & 0x30000000) >> 28, u32tmp[0] & 0xff,
2423 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
2424 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
2425 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64);
2426 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2427 "0x40/0x4c[24:23]/0x64[0]",
2428 u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u8tmp[1] & 0x1);
2431 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
2432 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
2433 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2434 "0x550(bcn ctrl)/0x522",
2435 u32tmp[0], u8tmp[0]);
2438 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
2439 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)",
2443 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48);
2444 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5d);
2445 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
2446 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2448 u32tmp[0], (u8tmp[0] << 8) + u8tmp[1]);
2451 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
2452 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
2453 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
2454 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2455 "0x6c0/0x6c4/0x6c8(coexTable)",
2456 u32tmp[0], u32tmp[1], u32tmp[2]);
2459 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2460 "0x770(high-pri rx/tx)",
2461 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
2463 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2464 "0x774(low-pri rx/tx)",
2465 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
2467 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 1)
2468 halbtc8821a1ant_monitor_bt_ctr(btcoexist);
2470 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
2474 void ex_halbtc8821a1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2476 boolean wifi_under_5g = false;
2478 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2480 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
2482 if (wifi_under_5g) {
2483 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2484 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2485 BTC_TRACE(trace_buf);
2486 halbtc8821a1ant_coex_under_5g(btcoexist);
2490 if (BTC_IPS_ENTER == type) {
2491 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2492 "[BTCoex], IPS ENTER notify\n");
2493 BTC_TRACE(trace_buf);
2494 coex_sta->under_ips = true;
2496 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2497 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2498 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
2500 /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
2501 } else if (BTC_IPS_LEAVE == type) {
2502 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2503 "[BTCoex], IPS LEAVE notify\n");
2504 BTC_TRACE(trace_buf);
2505 coex_sta->under_ips = false;
2507 halbtc8821a1ant_init_hw_config(btcoexist, false, false);
2508 halbtc8821a1ant_init_coex_dm(btcoexist);
2509 halbtc8821a1ant_query_bt_info(btcoexist);
2513 void ex_halbtc8821a1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2517 if (BTC_LPS_ENABLE == type) {
2518 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2519 "[BTCoex], LPS ENABLE notify\n");
2520 BTC_TRACE(trace_buf);
2521 coex_sta->under_lps = true;
2522 } else if (BTC_LPS_DISABLE == type) {
2523 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2524 "[BTCoex], LPS DISABLE notify\n");
2525 BTC_TRACE(trace_buf);
2526 coex_sta->under_lps = false;
2530 void ex_halbtc8821a1ant_scan_notify(IN struct btc_coexist *btcoexist,
2533 boolean wifi_connected = false, bt_hs_on = false;
2534 u32 wifi_link_status = 0;
2535 u32 num_of_wifi_link = 0;
2536 boolean bt_ctrl_agg_buf_size = false;
2537 u8 agg_buf_size = 5;
2538 boolean wifi_under_5g = false;
2540 if (btcoexist->manual_control ||
2541 btcoexist->stop_coex_dm)
2543 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2544 if (wifi_under_5g) {
2545 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2546 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2547 BTC_TRACE(trace_buf);
2548 halbtc8821a1ant_coex_under_5g(btcoexist);
2552 if (BTC_SCAN_START == type) {
2553 coex_sta->wifi_is_high_pri_task = true;
2554 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2555 "[BTCoex], SCAN START notify\n");
2556 BTC_TRACE(trace_buf);
2558 halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
2559 8); /* Force antenna setup for no scan result issue */
2561 coex_sta->wifi_is_high_pri_task = false;
2562 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2563 "[BTCoex], SCAN FINISH notify\n");
2564 BTC_TRACE(trace_buf);
2567 if (coex_sta->bt_disabled)
2570 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2571 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2574 halbtc8821a1ant_query_bt_info(btcoexist);
2576 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2578 num_of_wifi_link = wifi_link_status >> 16;
2579 if (num_of_wifi_link >= 2) {
2580 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2581 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2582 bt_ctrl_agg_buf_size, agg_buf_size);
2583 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2587 if (coex_sta->c2h_bt_inquiry_page) {
2588 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2590 } else if (bt_hs_on) {
2591 halbtc8821a1ant_action_hs(btcoexist);
2595 if (BTC_SCAN_START == type) {
2596 if (!wifi_connected) /* non-connected scan */
2597 halbtc8821a1ant_action_wifi_not_connected_scan(
2599 else /* wifi is connected */
2600 halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
2601 } else if (BTC_SCAN_FINISH == type) {
2602 if (!wifi_connected) /* non-connected scan */
2603 halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2605 halbtc8821a1ant_action_wifi_connected(btcoexist);
2609 void ex_halbtc8821a1ant_connect_notify(IN struct btc_coexist *btcoexist,
2612 boolean wifi_connected = false, bt_hs_on = false;
2613 u32 wifi_link_status = 0;
2614 u32 num_of_wifi_link = 0;
2615 boolean bt_ctrl_agg_buf_size = false;
2616 u8 agg_buf_size = 5;
2617 boolean wifi_under_5g = false;
2619 if (btcoexist->manual_control ||
2620 btcoexist->stop_coex_dm ||
2621 coex_sta->bt_disabled)
2623 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2624 if (wifi_under_5g) {
2625 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2626 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2627 BTC_TRACE(trace_buf);
2628 halbtc8821a1ant_coex_under_5g(btcoexist);
2632 if (BTC_ASSOCIATE_START == type) {
2633 coex_sta->wifi_is_high_pri_task = true;
2634 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2635 "[BTCoex], CONNECT START notify\n");
2636 BTC_TRACE(trace_buf);
2637 coex_dm->arp_cnt = 0;
2639 coex_sta->wifi_is_high_pri_task = false;
2640 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2641 "[BTCoex], CONNECT FINISH notify\n");
2642 BTC_TRACE(trace_buf);
2643 coex_dm->arp_cnt = 0;
2646 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2648 num_of_wifi_link = wifi_link_status >> 16;
2649 if (num_of_wifi_link >= 2) {
2650 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2651 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2652 bt_ctrl_agg_buf_size, agg_buf_size);
2653 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2657 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2658 if (coex_sta->c2h_bt_inquiry_page) {
2659 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2661 } else if (bt_hs_on) {
2662 halbtc8821a1ant_action_hs(btcoexist);
2666 if (BTC_ASSOCIATE_START == type)
2667 halbtc8821a1ant_action_wifi_not_connected_asso_auth(btcoexist);
2668 else if (BTC_ASSOCIATE_FINISH == type) {
2669 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2671 if (!wifi_connected) /* non-connected scan */
2672 halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2674 halbtc8821a1ant_action_wifi_connected(btcoexist);
2678 void ex_halbtc8821a1ant_media_status_notify(IN struct btc_coexist *btcoexist,
2681 u8 h2c_parameter[3] = {0};
2683 u8 wifi_central_chnl;
2684 boolean wifi_under_5g = false;
2686 if (btcoexist->manual_control ||
2687 btcoexist->stop_coex_dm ||
2688 coex_sta->bt_disabled)
2690 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2691 if (wifi_under_5g) {
2692 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2693 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2694 BTC_TRACE(trace_buf);
2695 halbtc8821a1ant_coex_under_5g(btcoexist);
2699 if (BTC_MEDIA_CONNECT == type) {
2700 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2701 "[BTCoex], MEDIA connect notify\n");
2702 BTC_TRACE(trace_buf);
2704 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2705 "[BTCoex], MEDIA disconnect notify\n");
2706 BTC_TRACE(trace_buf);
2707 coex_dm->arp_cnt = 0;
2710 /* only 2.4G we need to inform bt the chnl mask */
2711 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
2712 &wifi_central_chnl);
2713 if ((BTC_MEDIA_CONNECT == type) &&
2714 (wifi_central_chnl <= 14)) {
2715 /* h2c_parameter[0] = 0x1; */
2716 h2c_parameter[0] = 0x0;
2717 h2c_parameter[1] = wifi_central_chnl;
2718 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2719 if (BTC_WIFI_BW_HT40 == wifi_bw)
2720 h2c_parameter[2] = 0x30;
2722 h2c_parameter[2] = 0x20;
2725 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
2726 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
2727 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
2729 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
2732 void ex_halbtc8821a1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
2735 boolean bt_hs_on = false;
2736 u32 wifi_link_status = 0;
2737 u32 num_of_wifi_link = 0;
2738 boolean bt_ctrl_agg_buf_size = false;
2739 u8 agg_buf_size = 5;
2740 boolean wifi_under_5g = false;
2742 if (btcoexist->manual_control ||
2743 btcoexist->stop_coex_dm ||
2744 coex_sta->bt_disabled)
2746 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2747 if (wifi_under_5g) {
2748 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2749 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2750 BTC_TRACE(trace_buf);
2751 halbtc8821a1ant_coex_under_5g(btcoexist);
2755 if (BTC_PACKET_DHCP == type ||
2756 BTC_PACKET_EAPOL == type ||
2757 BTC_PACKET_ARP == type) {
2758 coex_sta->wifi_is_high_pri_task = true;
2760 if (BTC_PACKET_ARP == type) {
2761 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2762 "[BTCoex], specific Packet ARP notify\n");
2763 BTC_TRACE(trace_buf);
2765 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2766 "[BTCoex], specific Packet DHCP or EAPOL notify\n");
2767 BTC_TRACE(trace_buf);
2770 coex_sta->wifi_is_high_pri_task = false;
2771 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2772 "[BTCoex], specific Packet [Type = %d] notify\n", type);
2773 BTC_TRACE(trace_buf);
2776 coex_sta->specific_pkt_period_cnt = 0;
2778 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2780 num_of_wifi_link = wifi_link_status >> 16;
2781 if (num_of_wifi_link >= 2) {
2782 halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2783 halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2784 bt_ctrl_agg_buf_size, agg_buf_size);
2785 halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2789 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2790 if (coex_sta->c2h_bt_inquiry_page) {
2791 halbtc8821a1ant_action_bt_inquiry(btcoexist);
2793 } else if (bt_hs_on) {
2794 halbtc8821a1ant_action_hs(btcoexist);
2798 if (BTC_PACKET_DHCP == type ||
2799 BTC_PACKET_EAPOL == type ||
2800 BTC_PACKET_ARP == type) {
2801 if (BTC_PACKET_ARP == type) {
2803 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2804 "[BTCoex], ARP Packet Count = %d\n",
2806 BTC_TRACE(trace_buf);
2807 if (coex_dm->arp_cnt >=
2808 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */
2812 halbtc8821a1ant_action_wifi_connected_specific_packet(btcoexist);
2816 void ex_halbtc8821a1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
2817 IN u8 *tmp_buf, IN u8 length)
2820 u8 i, rsp_source = 0;
2821 boolean wifi_connected = false;
2822 boolean bt_busy = false;
2823 boolean wifi_under_5g = false;
2826 coex_sta->c2h_bt_info_req_sent = false;
2828 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2830 rsp_source = tmp_buf[0] & 0xf;
2831 if (rsp_source >= BT_INFO_SRC_8821A_1ANT_MAX)
2832 rsp_source = BT_INFO_SRC_8821A_1ANT_WIFI_FW;
2833 coex_sta->bt_info_c2h_cnt[rsp_source]++;
2835 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2836 "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
2838 BTC_TRACE(trace_buf);
2839 for (i = 0; i < length; i++) {
2840 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
2842 bt_info = tmp_buf[i];
2843 if (i == length - 1) {
2844 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
2846 BTC_TRACE(trace_buf);
2848 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
2850 BTC_TRACE(trace_buf);
2853 /* if 0xff, it means BT is under WHCK test */
2854 if (bt_info == 0xff)
2855 coex_sta->bt_whck_test = true;
2857 coex_sta->bt_whck_test = false;
2859 if (BT_INFO_SRC_8821A_1ANT_WIFI_FW != rsp_source) {
2860 coex_sta->bt_retry_cnt = /* [3:0] */
2861 coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
2863 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
2864 coex_sta->c2h_bt_page = true;
2866 coex_sta->c2h_bt_page = false;
2869 coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
2871 coex_sta->bt_info_ext =
2872 coex_sta->bt_info_c2h[rsp_source][4];
2874 coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
2876 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
2877 &coex_sta->bt_tx_rx_mask);
2878 if (!coex_sta->bt_tx_rx_mask) {
2879 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
2880 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2881 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
2882 BTC_TRACE(trace_buf);
2883 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
2887 /* Here we need to resend some wifi info to BT */
2888 /* because bt is reset and loss of the info. */
2889 if (coex_sta->bt_info_ext & BIT(1)) {
2890 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2891 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
2892 BTC_TRACE(trace_buf);
2893 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2896 ex_halbtc8821a1ant_media_status_notify(
2897 btcoexist, BTC_MEDIA_CONNECT);
2899 ex_halbtc8821a1ant_media_status_notify(
2900 btcoexist, BTC_MEDIA_DISCONNECT);
2903 if ((coex_sta->bt_info_ext & BIT(3)) && !wifi_under_5g) {
2904 if (!btcoexist->manual_control &&
2905 !btcoexist->stop_coex_dm) {
2906 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2907 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
2908 BTC_TRACE(trace_buf);
2909 halbtc8821a1ant_ignore_wlan_act(btcoexist,
2913 /* BT already NOT ignore Wlan active, do nothing here. */
2915 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
2916 if ((coex_sta->bt_info_ext & BIT(4))) {
2917 /* BT auto report already enabled, do nothing */
2919 halbtc8821a1ant_bt_auto_report(btcoexist, FORCE_EXEC,
2924 /* check BIT2 first ==> check if bt is under inquiry or page scan */
2925 if (bt_info & BT_INFO_8821A_1ANT_B_INQ_PAGE)
2926 coex_sta->c2h_bt_inquiry_page = true;
2928 coex_sta->c2h_bt_inquiry_page = false;
2930 /* set link exist status */
2931 if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) {
2932 coex_sta->bt_link_exist = false;
2933 coex_sta->pan_exist = false;
2934 coex_sta->a2dp_exist = false;
2935 coex_sta->hid_exist = false;
2936 coex_sta->sco_exist = false;
2937 } else { /* connection exists */
2938 coex_sta->bt_link_exist = true;
2939 if (bt_info & BT_INFO_8821A_1ANT_B_FTP)
2940 coex_sta->pan_exist = true;
2942 coex_sta->pan_exist = false;
2943 if (bt_info & BT_INFO_8821A_1ANT_B_A2DP)
2944 coex_sta->a2dp_exist = true;
2946 coex_sta->a2dp_exist = false;
2947 if (bt_info & BT_INFO_8821A_1ANT_B_HID)
2948 coex_sta->hid_exist = true;
2950 coex_sta->hid_exist = false;
2951 if (bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO)
2952 coex_sta->sco_exist = true;
2954 coex_sta->sco_exist = false;
2957 halbtc8821a1ant_update_bt_link_info(btcoexist);
2960 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
2962 if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) {
2963 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
2964 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2965 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
2966 BTC_TRACE(trace_buf);
2967 } else if (bt_info ==
2968 BT_INFO_8821A_1ANT_B_CONNECTION) { /* connection exists but no busy */
2969 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE;
2970 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2971 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
2972 BTC_TRACE(trace_buf);
2973 } else if ((bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO) ||
2974 (bt_info & BT_INFO_8821A_1ANT_B_SCO_BUSY)) {
2975 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_SCO_BUSY;
2976 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2977 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
2978 BTC_TRACE(trace_buf);
2979 } else if (bt_info & BT_INFO_8821A_1ANT_B_ACL_BUSY) {
2980 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
2981 coex_dm->auto_tdma_adjust = false;
2982 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_ACL_BUSY;
2983 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2984 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
2985 BTC_TRACE(trace_buf);
2987 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_MAX;
2988 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2989 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
2990 BTC_TRACE(trace_buf);
2993 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
2994 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2995 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
2999 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3001 halbtc8821a1ant_run_coexist_mechanism(btcoexist);
3004 void ex_halbtc8821a1ant_halt_notify(IN struct btc_coexist *btcoexist)
3006 boolean wifi_under_5g = false;
3007 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3008 if (wifi_under_5g) {
3009 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3010 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
3011 BTC_TRACE(trace_buf);
3012 halbtc8821a1ant_coex_under_5g(btcoexist);
3016 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
3017 BTC_TRACE(trace_buf);
3019 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
3021 halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3022 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true);
3023 /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
3025 halbtc8821a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3027 ex_halbtc8821a1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3029 btcoexist->stop_coex_dm = true;
3032 void ex_halbtc8821a1ant_pnp_notify(IN struct btc_coexist *btcoexist,
3035 boolean wifi_under_5g = false;
3037 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3038 if (wifi_under_5g) {
3039 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3040 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
3041 BTC_TRACE(trace_buf);
3042 halbtc8821a1ant_coex_under_5g(btcoexist);
3045 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
3046 BTC_TRACE(trace_buf);
3048 if (BTC_WIFI_PNP_SLEEP == pnp_state) {
3049 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3050 "[BTCoex], Pnp notify to SLEEP\n");
3051 BTC_TRACE(trace_buf);
3053 halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3055 halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3056 halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3057 halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
3059 /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
3061 /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */
3062 /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */
3063 /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */
3064 coex_sta->under_ips = false;
3065 coex_sta->under_lps = false;
3066 btcoexist->stop_coex_dm = true;
3067 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
3068 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3069 "[BTCoex], Pnp notify to WAKE UP\n");
3070 BTC_TRACE(trace_buf);
3071 btcoexist->stop_coex_dm = false;
3072 halbtc8821a1ant_init_hw_config(btcoexist, false, false);
3073 halbtc8821a1ant_init_coex_dm(btcoexist);
3074 halbtc8821a1ant_query_bt_info(btcoexist);
3078 void ex_halbtc8821a1ant_periodical(IN struct btc_coexist *btcoexist)
3080 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
3081 halbtc8821a1ant_query_bt_info(btcoexist);
3082 halbtc8821a1ant_monitor_bt_ctr(btcoexist);
3083 halbtc8821a1ant_monitor_bt_enable_disable(btcoexist);
3085 if (halbtc8821a1ant_is_wifi_status_changed(btcoexist) ||
3086 coex_dm->auto_tdma_adjust) {
3087 /* if(coex_sta->specific_pkt_period_cnt > 2) */
3089 halbtc8821a1ant_run_coexist_mechanism(btcoexist);
3093 coex_sta->specific_pkt_period_cnt++;
3099 #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */