1 /* ************************************************************
4 * This file is for RTL8812A Co-exist mechanism
7 * 2012/11/15 Cosa first check in.
9 * ************************************************************ */
11 /* ************************************************************
13 * ************************************************************ */
14 #include "mp_precomp.h"
16 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
18 #if (RTL8812A_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_8812a_1ant glcoex_dm_8812a_1ant;
24 static struct coex_dm_8812a_1ant *coex_dm = &glcoex_dm_8812a_1ant;
25 static struct coex_sta_8812a_1ant glcoex_sta_8812a_1ant;
26 static struct coex_sta_8812a_1ant *coex_sta = &glcoex_sta_8812a_1ant;
28 const char *const glbt_info_src_8812a_1ant[] = {
31 "BT Info[bt auto report]",
34 u32 glcoex_ver_date_8812a_1ant = 20140708;
35 u32 glcoex_ver_8812a_1ant = 0x52;
37 /* ************************************************************
38 * local function proto type if needed
39 * ************************************************************
40 * ************************************************************
41 * local function start with halbtc8812a1ant_
42 * ************************************************************ */
43 u8 halbtc8812a1ant_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_8812A_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_8812A_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_8812A_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 halbtc8812a1ant_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_8812A_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_8812A_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_8812A_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 halbtc8812a1ant_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 /* to check 0x430/0x434 is correct?? */
182 void halbtc8812a1ant_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 /* to check 0x42a ?? */
222 void halbtc8812a1ant_retry_limit(IN struct btc_coexist *btcoexist,
223 IN boolean force_exec, IN u8 type)
225 coex_dm->cur_retry_limit_type = type;
228 (coex_dm->pre_retry_limit_type !=
229 coex_dm->cur_retry_limit_type)) {
230 switch (coex_dm->cur_retry_limit_type) {
231 case 0: /* normal mode */
232 btcoexist->btc_write_2byte(btcoexist, 0x42a,
233 coex_dm->backup_retry_limit);
235 case 1: /* retry limit=8 */
236 btcoexist->btc_write_2byte(btcoexist, 0x42a,
244 coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
247 /* to check 0x456?? */
248 void halbtc8812a1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
249 IN boolean force_exec, IN u8 type)
251 coex_dm->cur_ampdu_time_type = type;
254 (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
255 switch (coex_dm->cur_ampdu_time_type) {
256 case 0: /* normal mode */
257 btcoexist->btc_write_1byte(btcoexist, 0x456,
258 coex_dm->backup_ampdu_max_time);
260 case 1: /* AMPDU timw = 0x38 * 32us */
261 btcoexist->btc_write_1byte(btcoexist, 0x456,
269 coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
272 void halbtc8812a1ant_limited_tx(IN struct btc_coexist *btcoexist,
273 IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
274 IN u8 retry_limit_type, IN u8 ampdu_time_type)
276 switch (ra_mask_type) {
277 case 0: /* normal mode */
278 halbtc8812a1ant_update_ra_mask(btcoexist, force_exec,
281 case 1: /* disable cck 1/2 */
282 halbtc8812a1ant_update_ra_mask(btcoexist, force_exec,
285 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
286 halbtc8812a1ant_update_ra_mask(btcoexist, force_exec,
293 halbtc8812a1ant_auto_rate_fallback_retry(btcoexist, force_exec,
295 halbtc8812a1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
296 halbtc8812a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
299 void halbtc8812a1ant_limited_rx(IN struct btc_coexist *btcoexist,
300 IN boolean force_exec, IN boolean rej_ap_agg_pkt,
301 IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
303 boolean reject_rx_agg = rej_ap_agg_pkt;
304 boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
305 u8 rx_agg_size = agg_buf_size;
307 /* ============================================ */
308 /* Rx Aggregation related setting */
309 /* ============================================ */
310 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
312 /* decide BT control aggregation buf size or not */
313 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
314 &bt_ctrl_rx_agg_size);
315 /* aggregation buf size, only work when BT control Rx aggregation size. */
316 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
317 /* real update aggregation setting */
318 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
323 void halbtc8812a1ant_query_bt_info(IN struct btc_coexist *btcoexist)
328 if (!coex_sta->bt_disabled) {
329 if (!coex_sta->bt_info_query_cnt ||
330 (coex_sta->bt_info_c2h_cnt[BT_INFO_SRC_8812A_1ANT_BT_RSP]
331 - coex_sta->bt_info_query_cnt) > 2) {
333 buf[1] = 0x1; /* polling enable, 1=enable, 0=disable */
334 buf[2] = 0x2; /* polling time in seconds */
335 buf[3] = 0x1; /* auto report enable, 1=enable, 0=disable */
337 btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_INFO,
341 coex_sta->bt_info_query_cnt++;
344 void halbtc8812a1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
346 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
347 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
348 static u8 num_of_bt_counter_chk = 0;
353 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
354 reg_hp_tx = u32tmp & MASKLWORD;
355 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
357 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
358 reg_lp_tx = u32tmp & MASKLWORD;
359 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
361 coex_sta->high_priority_tx = reg_hp_tx;
362 coex_sta->high_priority_rx = reg_hp_rx;
363 coex_sta->low_priority_tx = reg_lp_tx;
364 coex_sta->low_priority_rx = reg_lp_rx;
366 if ((coex_sta->low_priority_tx > 1150) &&
367 (!coex_sta->c2h_bt_inquiry_page))
368 coex_sta->pop_event_cnt++;
370 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
371 "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
372 reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
373 BTC_TRACE(trace_buf);
376 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
378 if ((reg_hp_tx == 0) && (reg_hp_rx == 0) && (reg_lp_tx == 0) &&
380 num_of_bt_counter_chk++;
381 if (num_of_bt_counter_chk >= 3) {
382 halbtc8812a1ant_query_bt_info(btcoexist);
383 num_of_bt_counter_chk = 0;
388 /* to check registers */
389 void halbtc8812a1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
392 boolean wifi_busy = false, wifi_under_b_mode = false;
393 static u8 cck_lock_counter = 0;
395 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
396 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
397 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
400 if (coex_sta->under_ips) {
401 coex_sta->crc_ok_cck = 0;
402 coex_sta->crc_ok_11g = 0;
403 coex_sta->crc_ok_11n = 0;
404 coex_sta->crc_ok_11n_agg = 0;
406 coex_sta->crc_err_cck = 0;
407 coex_sta->crc_err_11g = 0;
408 coex_sta->crc_err_11n = 0;
409 coex_sta->crc_err_11n_agg = 0;
411 coex_sta->crc_ok_cck = btcoexist->btc_read_2byte(btcoexist,
413 coex_sta->crc_ok_11g = btcoexist->btc_read_2byte(btcoexist,
415 coex_sta->crc_ok_11n = btcoexist->btc_read_2byte(btcoexist,
417 coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte(btcoexist,
420 coex_sta->crc_err_cck = btcoexist->btc_read_2byte(btcoexist,
422 coex_sta->crc_err_11g = btcoexist->btc_read_2byte(btcoexist,
424 coex_sta->crc_err_11n = btcoexist->btc_read_2byte(btcoexist,
426 coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte(btcoexist,
432 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x1);
433 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x0);
435 if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
436 if ((coex_dm->bt_status == BT_8812A_1ANT_BT_STATUS_ACL_BUSY) ||
437 (coex_dm->bt_status ==
438 BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
439 (coex_dm->bt_status ==
440 BT_8812A_1ANT_BT_STATUS_SCO_BUSY)) {
441 if (coex_sta->crc_ok_cck > (coex_sta->crc_ok_11g +
442 coex_sta->crc_ok_11n +
443 coex_sta->crc_ok_11n_agg)) {
444 if (cck_lock_counter < 5)
447 if (cck_lock_counter > 0)
452 if (cck_lock_counter > 0)
456 if (cck_lock_counter > 0)
460 if (!coex_sta->pre_ccklock) {
462 if (cck_lock_counter >= 5)
463 coex_sta->cck_lock = true;
465 coex_sta->cck_lock = false;
467 if (cck_lock_counter == 0)
468 coex_sta->cck_lock = false;
470 coex_sta->cck_lock = true;
473 coex_sta->pre_ccklock = coex_sta->cck_lock;
478 boolean halbtc8812a1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
480 static boolean pre_wifi_busy = false, pre_under_4way = false,
481 pre_bt_hs_on = false;
482 boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
483 boolean wifi_connected = false;
485 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
487 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
488 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
489 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
492 if (wifi_connected) {
493 if (wifi_busy != pre_wifi_busy) {
494 pre_wifi_busy = wifi_busy;
497 if (under_4way != pre_under_4way) {
498 pre_under_4way = under_4way;
501 if (bt_hs_on != pre_bt_hs_on) {
502 pre_bt_hs_on = bt_hs_on;
510 void halbtc8812a1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
512 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
513 boolean bt_hs_on = false;
515 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
517 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
518 bt_link_info->sco_exist = coex_sta->sco_exist;
519 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
520 bt_link_info->pan_exist = coex_sta->pan_exist;
521 bt_link_info->hid_exist = coex_sta->hid_exist;
523 /* work around for HS mode. */
525 bt_link_info->pan_exist = true;
526 bt_link_info->bt_link_exist = true;
529 /* check if Sco only */
530 if (bt_link_info->sco_exist &&
531 !bt_link_info->a2dp_exist &&
532 !bt_link_info->pan_exist &&
533 !bt_link_info->hid_exist)
534 bt_link_info->sco_only = true;
536 bt_link_info->sco_only = false;
538 /* check if A2dp only */
539 if (!bt_link_info->sco_exist &&
540 bt_link_info->a2dp_exist &&
541 !bt_link_info->pan_exist &&
542 !bt_link_info->hid_exist)
543 bt_link_info->a2dp_only = true;
545 bt_link_info->a2dp_only = false;
547 /* check if Pan only */
548 if (!bt_link_info->sco_exist &&
549 !bt_link_info->a2dp_exist &&
550 bt_link_info->pan_exist &&
551 !bt_link_info->hid_exist)
552 bt_link_info->pan_only = true;
554 bt_link_info->pan_only = false;
556 /* check if Hid only */
557 if (!bt_link_info->sco_exist &&
558 !bt_link_info->a2dp_exist &&
559 !bt_link_info->pan_exist &&
560 bt_link_info->hid_exist)
561 bt_link_info->hid_only = true;
563 bt_link_info->hid_only = false;
566 u8 halbtc8812a1ant_action_algorithm(IN struct btc_coexist *btcoexist)
568 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
569 boolean bt_hs_on = false;
570 u8 algorithm = BT_8812A_1ANT_COEX_ALGO_UNDEFINED;
571 u8 num_of_diff_profile = 0;
573 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
575 if (!bt_link_info->bt_link_exist) {
576 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
577 "[BTCoex], No BT link exists!!!\n");
578 BTC_TRACE(trace_buf);
582 if (bt_link_info->sco_exist)
583 num_of_diff_profile++;
584 if (bt_link_info->hid_exist)
585 num_of_diff_profile++;
586 if (bt_link_info->pan_exist)
587 num_of_diff_profile++;
588 if (bt_link_info->a2dp_exist)
589 num_of_diff_profile++;
591 if (num_of_diff_profile == 1) {
592 if (bt_link_info->sco_exist) {
593 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
594 "[BTCoex], BT Profile = SCO only\n");
595 BTC_TRACE(trace_buf);
596 algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;
598 if (bt_link_info->hid_exist) {
599 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
600 "[BTCoex], BT Profile = HID only\n");
601 BTC_TRACE(trace_buf);
602 algorithm = BT_8812A_1ANT_COEX_ALGO_HID;
603 } else if (bt_link_info->a2dp_exist) {
604 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
605 "[BTCoex], BT Profile = A2DP only\n");
606 BTC_TRACE(trace_buf);
607 algorithm = BT_8812A_1ANT_COEX_ALGO_A2DP;
608 } else if (bt_link_info->pan_exist) {
610 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
611 "[BTCoex], BT Profile = PAN(HS) only\n");
612 BTC_TRACE(trace_buf);
614 BT_8812A_1ANT_COEX_ALGO_PANHS;
616 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
617 "[BTCoex], BT Profile = PAN(EDR) only\n");
618 BTC_TRACE(trace_buf);
620 BT_8812A_1ANT_COEX_ALGO_PANEDR;
624 } else if (num_of_diff_profile == 2) {
625 if (bt_link_info->sco_exist) {
626 if (bt_link_info->hid_exist) {
627 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
628 "[BTCoex], BT Profile = SCO + HID\n");
629 BTC_TRACE(trace_buf);
630 algorithm = BT_8812A_1ANT_COEX_ALGO_HID;
631 } else if (bt_link_info->a2dp_exist) {
632 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
633 "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
634 BTC_TRACE(trace_buf);
635 algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;
636 } else if (bt_link_info->pan_exist) {
638 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
639 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
640 BTC_TRACE(trace_buf);
641 algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;
643 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
644 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
645 BTC_TRACE(trace_buf);
647 BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;
651 if (bt_link_info->hid_exist &&
652 bt_link_info->a2dp_exist) {
653 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
654 "[BTCoex], BT Profile = HID + A2DP\n");
655 BTC_TRACE(trace_buf);
656 algorithm = BT_8812A_1ANT_COEX_ALGO_HID_A2DP;
657 } else if (bt_link_info->hid_exist &&
658 bt_link_info->pan_exist) {
660 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
661 "[BTCoex], BT Profile = HID + PAN(HS)\n");
662 BTC_TRACE(trace_buf);
664 BT_8812A_1ANT_COEX_ALGO_HID_A2DP;
666 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
667 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
668 BTC_TRACE(trace_buf);
670 BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;
672 } else if (bt_link_info->pan_exist &&
673 bt_link_info->a2dp_exist) {
675 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
676 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
677 BTC_TRACE(trace_buf);
679 BT_8812A_1ANT_COEX_ALGO_A2DP_PANHS;
681 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
682 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
683 BTC_TRACE(trace_buf);
685 BT_8812A_1ANT_COEX_ALGO_PANEDR_A2DP;
689 } else if (num_of_diff_profile == 3) {
690 if (bt_link_info->sco_exist) {
691 if (bt_link_info->hid_exist &&
692 bt_link_info->a2dp_exist) {
693 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
694 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
695 BTC_TRACE(trace_buf);
696 algorithm = BT_8812A_1ANT_COEX_ALGO_HID;
697 } else if (bt_link_info->hid_exist &&
698 bt_link_info->pan_exist) {
700 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
701 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
702 BTC_TRACE(trace_buf);
704 BT_8812A_1ANT_COEX_ALGO_HID_A2DP;
706 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
707 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
708 BTC_TRACE(trace_buf);
710 BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;
712 } else if (bt_link_info->pan_exist &&
713 bt_link_info->a2dp_exist) {
715 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
716 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
717 BTC_TRACE(trace_buf);
718 algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;
720 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
721 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
722 BTC_TRACE(trace_buf);
724 BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;
728 if (bt_link_info->hid_exist &&
729 bt_link_info->pan_exist &&
730 bt_link_info->a2dp_exist) {
732 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
733 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
734 BTC_TRACE(trace_buf);
736 BT_8812A_1ANT_COEX_ALGO_HID_A2DP;
738 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
739 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
740 BTC_TRACE(trace_buf);
742 BT_8812A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
746 } else if (num_of_diff_profile >= 3) {
747 if (bt_link_info->sco_exist) {
748 if (bt_link_info->hid_exist &&
749 bt_link_info->pan_exist &&
750 bt_link_info->a2dp_exist) {
752 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
753 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
754 BTC_TRACE(trace_buf);
757 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
758 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
759 BTC_TRACE(trace_buf);
761 BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;
770 void halbtc8812a1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
771 IN boolean enable_auto_report)
773 u8 h2c_parameter[1] = {0};
775 h2c_parameter[0] = 0;
777 if (enable_auto_report)
778 h2c_parameter[0] |= BIT(0);
780 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
783 void halbtc8812a1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
784 IN boolean force_exec, IN boolean enable_auto_report)
786 coex_dm->cur_bt_auto_report = enable_auto_report;
789 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
792 halbtc8812a1ant_set_bt_auto_report(btcoexist,
793 coex_dm->cur_bt_auto_report);
795 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
799 void halbtc8812a1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
800 *btcoexist, IN boolean low_penalty_ra)
804 tmp_u1 = btcoexist->btc_read_1byte(btcoexist, 0x4fd);
806 if (low_penalty_ra) {
807 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
808 "[BTCoex], Tx rate adaptive, set low penalty!!\n");
809 BTC_TRACE(trace_buf);
812 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
813 "[BTCoex], Tx rate adaptive, set normal!!\n");
814 BTC_TRACE(trace_buf);
818 btcoexist->btc_write_1byte(btcoexist, 0x4fd, tmp_u1);
821 void halbtc8812a1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
822 IN boolean force_exec, IN boolean low_penalty_ra)
824 coex_dm->cur_low_penalty_ra = low_penalty_ra;
827 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
830 halbtc8812a1ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
831 coex_dm->cur_low_penalty_ra);
833 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
836 void halbtc8812a1ant_set_coex_table(IN struct btc_coexist *btcoexist,
837 IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
839 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
841 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
843 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
845 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
848 void halbtc8812a1ant_coex_table(IN struct btc_coexist *btcoexist,
849 IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
850 IN u32 val0x6c8, IN u8 val0x6cc)
852 coex_dm->cur_val0x6c0 = val0x6c0;
853 coex_dm->cur_val0x6c4 = val0x6c4;
854 coex_dm->cur_val0x6c8 = val0x6c8;
855 coex_dm->cur_val0x6cc = val0x6cc;
858 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
859 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
860 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
861 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
864 halbtc8812a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
867 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
868 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
869 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
870 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
873 void halbtc8812a1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
874 IN boolean force_exec, IN u8 type)
876 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
877 "[BTCoex], ********** CoexTable(%d) **********\n", type);
878 BTC_TRACE(trace_buf);
880 coex_sta->coex_table_type = type;
884 halbtc8812a1ant_coex_table(btcoexist, force_exec,
885 0x55555555, 0x55555555, 0xffffff, 0x3);
888 halbtc8812a1ant_coex_table(btcoexist, force_exec,
889 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
892 halbtc8812a1ant_coex_table(btcoexist, force_exec,
893 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
896 halbtc8812a1ant_coex_table(btcoexist, force_exec,
897 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
900 halbtc8812a1ant_coex_table(btcoexist, force_exec,
901 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
904 halbtc8812a1ant_coex_table(btcoexist, force_exec,
905 0x5a5a5a5a, 0xaa5a5a5a, 0xffffff, 0x3);
908 halbtc8812a1ant_coex_table(btcoexist, force_exec,
909 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);
912 halbtc8812a1ant_coex_table(btcoexist, force_exec,
913 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
920 void halbtc8812a1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
927 buf[1] = 0x1; /* OP_Code */
928 buf[2] = 0x1; /* OP_Code_Length */
930 buf[3] = 0x1; /* OP_Code_Content */
934 btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
938 void halbtc8812a1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
939 IN boolean force_exec, IN boolean enable)
941 coex_dm->cur_ignore_wlan_act = enable;
944 if (coex_dm->pre_ignore_wlan_act ==
945 coex_dm->cur_ignore_wlan_act)
948 halbtc8812a1ant_set_fw_ignore_wlan_act(btcoexist, enable);
950 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
953 void halbtc8812a1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
954 IN u8 lps_val, IN u8 rpwm_val)
959 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
960 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
963 void halbtc8812a1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
964 IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
966 coex_dm->cur_lps = lps_val;
967 coex_dm->cur_rpwm = rpwm_val;
970 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
971 (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
974 halbtc8812a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
976 coex_dm->pre_lps = coex_dm->cur_lps;
977 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
980 void halbtc8812a1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
981 IN boolean low_penalty_ra)
983 halbtc8812a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
986 /* to check force_exec */
987 void halbtc8812a1ant_set_ant_path(IN struct btc_coexist *btcoexist,
988 IN u8 ant_pos_type, IN boolean force_exec, IN boolean init_hwcfg,
993 coex_dm->cur_ant_pos_type = ant_pos_type;
996 btcoexist->btc_write_1byte(btcoexist, 0xcb3, 0x77);
997 btcoexist->btc_write_4byte(btcoexist, 0x900, 0x00000400);
998 btcoexist->btc_write_1byte(btcoexist, 0x76d, 0x1);
999 } else if (wifi_off) {
1000 btcoexist->btc_write_1byte(btcoexist, 0xcb3, 0x77);
1001 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0xcb7);
1004 btcoexist->btc_write_1byte(btcoexist, 0xcb7, u8tmp);
1008 (coex_dm->cur_ant_pos_type != coex_dm->pre_ant_pos_type)) {
1009 /* ext switch setting */
1010 switch (ant_pos_type) {
1011 case BTC_ANT_PATH_WIFI:
1012 u8tmp = btcoexist->btc_read_1byte(btcoexist,
1016 btcoexist->btc_write_1byte(btcoexist, 0xcb7,
1019 case BTC_ANT_PATH_BT:
1020 u8tmp = btcoexist->btc_read_1byte(btcoexist,
1024 btcoexist->btc_write_1byte(btcoexist, 0xcb7,
1028 case BTC_ANT_PATH_PTA:
1029 u8tmp = btcoexist->btc_read_1byte(btcoexist,
1033 btcoexist->btc_write_1byte(btcoexist, 0xcb7,
1039 coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type;
1042 void halbtc8812a1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
1043 IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
1045 u8 h2c_parameter[5] = {0};
1046 u8 real_byte1 = byte1, real_byte5 = byte5;
1047 boolean ap_enable = false;
1049 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1053 if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1054 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1055 "[BTCoex], FW for 1Ant AP mode\n");
1056 BTC_TRACE(trace_buf);
1057 real_byte1 &= ~BIT(4);
1058 real_byte1 |= BIT(5);
1060 real_byte5 |= BIT(5);
1061 real_byte5 &= ~BIT(6);
1065 h2c_parameter[0] = real_byte1;
1066 h2c_parameter[1] = byte2;
1067 h2c_parameter[2] = byte3;
1068 h2c_parameter[3] = byte4;
1069 h2c_parameter[4] = real_byte5;
1071 coex_dm->ps_tdma_para[0] = real_byte1;
1072 coex_dm->ps_tdma_para[1] = byte2;
1073 coex_dm->ps_tdma_para[2] = byte3;
1074 coex_dm->ps_tdma_para[3] = byte4;
1075 coex_dm->ps_tdma_para[4] = real_byte5;
1077 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1081 void halbtc8812a1ant_ps_tdma(IN struct btc_coexist *btcoexist,
1082 IN boolean force_exec, IN boolean turn_on, IN u8 type)
1084 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1085 boolean wifi_busy = false;
1086 u8 rssi_adjust_val = 0;
1087 u8 ps_tdma_byte4_val = 0x50, ps_tdma_byte0_val = 0x51,
1088 ps_tdma_byte3_val = 0x10;
1089 s8 wifi_duration_adjust = 0x0;
1090 static boolean pre_wifi_busy = false;
1092 coex_dm->cur_ps_tdma_on = turn_on;
1093 coex_dm->cur_ps_tdma = type;
1095 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1097 if (wifi_busy != pre_wifi_busy) {
1099 pre_wifi_busy = wifi_busy;
1102 if (coex_dm->cur_ps_tdma_on) {
1103 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1104 "[BTCoex], ********** TDMA(on, %d) **********\n",
1105 coex_dm->cur_ps_tdma);
1106 BTC_TRACE(trace_buf);
1108 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1109 "[BTCoex], ********** TDMA(off, %d) **********\n",
1110 coex_dm->cur_ps_tdma);
1111 BTC_TRACE(trace_buf);
1115 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1116 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1120 if (coex_sta->scan_ap_num <= 5)
1121 wifi_duration_adjust = 2;
1122 else if (coex_sta->scan_ap_num >= 40)
1123 wifi_duration_adjust = -15;
1124 else if (coex_sta->scan_ap_num >= 20)
1125 wifi_duration_adjust = -10;
1127 if (!coex_sta->force_lps_on) { /* only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30 */
1128 ps_tdma_byte0_val = 0x61; /* no null-pkt */
1129 ps_tdma_byte3_val = 0x11; /* no tx-pause at BT-slot */
1130 ps_tdma_byte4_val = 0x10; /* 0x778 = d/1 toggle */
1133 if ((type == 3) || (type == 13) || (type == 14)) {
1134 ps_tdma_byte4_val = ps_tdma_byte4_val &
1135 0xbf; /* no dynamic slot for multi-profile */
1138 ps_tdma_byte4_val = ps_tdma_byte4_val |
1139 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1142 if (bt_link_info->slave_role == true)
1143 ps_tdma_byte4_val = ps_tdma_byte4_val |
1144 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1149 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
1150 0x1a, 0x1a, 0x0, ps_tdma_byte4_val);
1153 halbtc8812a1ant_set_fw_pstdma(btcoexist,
1154 ps_tdma_byte0_val, 0x3a +
1155 wifi_duration_adjust, 0x03,
1156 ps_tdma_byte3_val, ps_tdma_byte4_val);
1159 halbtc8812a1ant_set_fw_pstdma(btcoexist,
1160 ps_tdma_byte0_val, 0x2d +
1161 wifi_duration_adjust, 0x03,
1162 ps_tdma_byte3_val, ps_tdma_byte4_val);
1165 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
1166 0x1d, 0x1d, 0x0, ps_tdma_byte4_val);
1169 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93,
1170 0x15, 0x3, 0x14, 0x0);
1173 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
1174 0x15, 0x3, 0x11, 0x11);
1177 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
1178 0x20, 0x3, 0x11, 0x11);
1181 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x13,
1182 0xc, 0x5, 0x0, 0x0);
1185 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93,
1186 0x25, 0x3, 0x10, 0x0);
1189 halbtc8812a1ant_set_fw_pstdma(btcoexist,
1190 ps_tdma_byte0_val, 0x21, 0x3,
1191 ps_tdma_byte3_val, ps_tdma_byte4_val);
1194 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x13,
1195 0xa, 0xa, 0x0, 0x40);
1198 halbtc8812a1ant_set_fw_pstdma(btcoexist,
1199 ps_tdma_byte0_val, 0x21, 0x03,
1200 ps_tdma_byte3_val, ps_tdma_byte4_val);
1203 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
1204 0x0a, 0x0a, 0x0, 0x50);
1207 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
1208 0x12, 0x12, 0x0, ps_tdma_byte4_val);
1211 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
1212 0x21, 0x3, 0x10, ps_tdma_byte4_val);
1215 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x13,
1216 0xa, 0x3, 0x8, 0x0);
1219 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93,
1220 0x15, 0x3, 0x10, 0x0);
1223 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93,
1224 0x25, 0x3, 0x10, 0x0);
1227 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
1228 0x3f, 0x03, 0x11, 0x10);
1231 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
1232 0x25, 0x03, 0x11, 0x11);
1235 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
1236 0x25, 0x03, 0x11, 0x10);
1239 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3,
1240 0x25, 0x3, 0x31, 0x18);
1243 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3,
1244 0x15, 0x3, 0x31, 0x18);
1247 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3,
1248 0xa, 0x3, 0x31, 0x18);
1251 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3,
1252 0xa, 0x3, 0x31, 0x18);
1255 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3,
1256 0x25, 0x3, 0x31, 0x98);
1259 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x69,
1260 0x25, 0x3, 0x31, 0x0);
1263 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xab,
1264 0x1a, 0x1a, 0x1, 0x10);
1267 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
1268 0x30, 0x3, 0x10, 0x10);
1271 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xd3,
1272 0x1a, 0x1a, 0, 0x58);
1275 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
1276 0x35, 0x3, 0x11, 0x11);
1279 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xa3,
1280 0x25, 0x3, 0x30, 0x90);
1283 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x53,
1284 0x1a, 0x1a, 0x0, 0x10);
1287 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x63,
1288 0x1a, 0x1a, 0x0, 0x10);
1291 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xd3,
1292 0x12, 0x3, 0x14, 0x50);
1294 case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */
1295 /* here softap mode screen off will cost 70-80mA for phone */
1296 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x23,
1297 0x18, 0x00, 0x10, 0x24);
1302 /* disable PS tdma */
1304 case 8: /* PTA Control */
1305 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x8,
1306 0x0, 0x0, 0x0, 0x0);
1309 default: /* Software control, Antenna at BT side */
1310 halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x0,
1311 0x0, 0x0, 0x0, 0x0);
1315 rssi_adjust_val = 0;
1316 btcoexist->btc_set(btcoexist,
1317 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
1320 /* update pre state */
1321 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1322 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1325 boolean halbtc8812a1ant_is_common_action(IN struct btc_coexist *btcoexist)
1327 boolean common = false, wifi_connected = false, wifi_busy = false;
1329 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1331 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1333 if (!wifi_connected &&
1334 BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1335 coex_dm->bt_status) {
1336 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1337 "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
1338 BTC_TRACE(trace_buf);
1340 /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */
1343 } else if (wifi_connected &&
1344 (BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1345 coex_dm->bt_status)) {
1346 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1347 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1348 BTC_TRACE(trace_buf);
1350 /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */
1353 } else if (!wifi_connected &&
1354 (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
1355 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1356 "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
1357 BTC_TRACE(trace_buf);
1359 /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */
1362 } else if (wifi_connected &&
1363 (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
1364 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1365 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1366 BTC_TRACE(trace_buf);
1368 /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */
1371 } else if (!wifi_connected &&
1372 (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE != coex_dm->bt_status)) {
1373 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1374 "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
1375 BTC_TRACE(trace_buf);
1377 /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */
1382 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1383 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1384 BTC_TRACE(trace_buf);
1386 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1387 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1388 BTC_TRACE(trace_buf);
1398 void halbtc8812a1ant_tdma_duration_adjust_for_acl(IN struct btc_coexist
1399 *btcoexist, IN u8 wifi_status)
1401 static s32 up, dn, m, n, wait_count;
1402 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1403 u8 retry_count = 0, bt_info_ext;
1404 boolean wifi_busy = false;
1406 if (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifi_status)
1411 if ((BT_8812A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN ==
1413 (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifi_status) ||
1414 (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT ==
1416 if (coex_dm->cur_ps_tdma != 1 &&
1417 coex_dm->cur_ps_tdma != 2 &&
1418 coex_dm->cur_ps_tdma != 3 &&
1419 coex_dm->cur_ps_tdma != 9) {
1420 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1422 coex_dm->ps_tdma_du_adj_type = 9;
1434 if (!coex_dm->auto_tdma_adjust) {
1435 coex_dm->auto_tdma_adjust = true;
1437 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
1438 coex_dm->ps_tdma_du_adj_type = 2;
1447 /* acquire the BT TRx retry count from BT_Info byte2 */
1448 retry_count = coex_sta->bt_retry_cnt;
1449 bt_info_ext = coex_sta->bt_info_ext;
1451 if ((coex_sta->low_priority_tx) > 1150 ||
1452 (coex_sta->low_priority_rx) > 1250)
1459 0) { /* no retry in the last 2-second duration */
1466 if (up >= n) { /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */
1473 } else if (retry_count <=
1474 3) { /* <=3 retry in the last 2-second duration */
1481 if (dn == 2) { /* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */
1482 if (wait_count <= 2)
1483 m++; /* to avoid loop between the two levels */
1487 if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
1496 } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */
1497 if (wait_count == 1)
1498 m++; /* to avoid loop between the two levels */
1502 if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
1513 if ((BT_INFO_8812A_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
1514 ((coex_dm->cur_ps_tdma == 1) ||
1515 (coex_dm->cur_ps_tdma == 2))) {
1516 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1518 coex_dm->ps_tdma_du_adj_type = 9;
1519 } else if (coex_dm->cur_ps_tdma == 1) {
1520 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1522 coex_dm->ps_tdma_du_adj_type = 2;
1523 } else if (coex_dm->cur_ps_tdma == 2) {
1524 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1526 coex_dm->ps_tdma_du_adj_type = 9;
1527 } else if (coex_dm->cur_ps_tdma == 9) {
1528 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1530 coex_dm->ps_tdma_du_adj_type = 11;
1532 } else if (result == 1) {
1533 if ((BT_INFO_8812A_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
1534 ((coex_dm->cur_ps_tdma == 1) ||
1535 (coex_dm->cur_ps_tdma == 2))) {
1536 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1538 coex_dm->ps_tdma_du_adj_type = 9;
1539 } else if (coex_dm->cur_ps_tdma == 11) {
1540 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1542 coex_dm->ps_tdma_du_adj_type = 9;
1543 } else if (coex_dm->cur_ps_tdma == 9) {
1544 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1546 coex_dm->ps_tdma_du_adj_type = 2;
1547 } else if (coex_dm->cur_ps_tdma == 2) {
1548 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1550 coex_dm->ps_tdma_du_adj_type = 1;
1552 } else { /* no change */
1554 if(wifi_busy != pre_wifi_busy)
1556 pre_wifi_busy = wifi_busy;
1557 halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, true, coex_dm->cur_ps_tdma);
1561 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1562 "[BTCoex], ********** TDMA(on, %d) **********\n",
1563 coex_dm->cur_ps_tdma);
1564 BTC_TRACE(trace_buf);
1567 if (coex_dm->cur_ps_tdma != 1 &&
1568 coex_dm->cur_ps_tdma != 2 &&
1569 coex_dm->cur_ps_tdma != 9 &&
1570 coex_dm->cur_ps_tdma != 11) {
1571 /* recover to previous adjust type */
1572 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1573 coex_dm->ps_tdma_du_adj_type);
1578 void halbtc8812a1ant_ps_tdma_check_for_power_save_state(
1579 IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1583 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1585 if (lps_mode) { /* already under LPS state */
1587 /* keep state under LPS, do nothing. */
1589 /* will leave LPS state, turn off psTdma first */
1590 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1593 } else { /* NO PS state */
1595 /* will enter LPS state, turn off psTdma first */
1596 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1599 /* keep state under NO PS state, do nothing. */
1604 void halbtc8812a1ant_power_save_state(IN struct btc_coexist *btcoexist,
1605 IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
1607 boolean low_pwr_disable = false;
1610 case BTC_PS_WIFI_NATIVE:
1611 /* recover to original 32k low power setting */
1612 low_pwr_disable = false;
1613 btcoexist->btc_set(btcoexist,
1614 BTC_SET_ACT_DISABLE_LOW_POWER,
1616 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1618 coex_sta->force_lps_on = false;
1621 halbtc8812a1ant_ps_tdma_check_for_power_save_state(
1623 halbtc8812a1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1625 /* when coex force to enter LPS, do not enter 32k low power. */
1626 low_pwr_disable = true;
1627 btcoexist->btc_set(btcoexist,
1628 BTC_SET_ACT_DISABLE_LOW_POWER,
1630 /* power save must executed before psTdma. */
1631 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1633 coex_sta->force_lps_on = true;
1635 case BTC_PS_LPS_OFF:
1636 halbtc8812a1ant_ps_tdma_check_for_power_save_state(
1638 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1640 coex_sta->force_lps_on = false;
1647 void halbtc8812a1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
1649 halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
1650 halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
1651 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, FORCE_EXEC,
1655 void halbtc8812a1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
1657 static u32 bt_disable_cnt = 0;
1658 boolean bt_active = true, bt_disabled = false;
1660 /* This function check if bt is disabled */
1662 if (coex_sta->high_priority_tx == 0 &&
1663 coex_sta->high_priority_rx == 0 &&
1664 coex_sta->low_priority_tx == 0 &&
1665 coex_sta->low_priority_rx == 0)
1667 if (coex_sta->high_priority_tx == 0xffff &&
1668 coex_sta->high_priority_rx == 0xffff &&
1669 coex_sta->low_priority_tx == 0xffff &&
1670 coex_sta->low_priority_rx == 0xffff)
1674 bt_disabled = false;
1675 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1677 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1678 "[BTCoex], BT is enabled !!\n");
1679 BTC_TRACE(trace_buf);
1682 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1683 "[BTCoex], bt all counters=0, %d times!!\n",
1685 BTC_TRACE(trace_buf);
1686 if (bt_disable_cnt >= 2) {
1688 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1690 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1691 "[BTCoex], BT is disabled !!\n");
1692 BTC_TRACE(trace_buf);
1693 halbtc8812a1ant_action_wifi_only(btcoexist);
1696 if (coex_sta->bt_disabled != bt_disabled) {
1697 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1698 "[BTCoex], BT is from %s to %s!!\n",
1699 (coex_sta->bt_disabled ? "disabled" : "enabled"),
1700 (bt_disabled ? "disabled" : "enabled"));
1701 BTC_TRACE(trace_buf);
1702 coex_sta->bt_disabled = bt_disabled;
1705 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1707 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1713 /* *********************************************
1715 * Software Coex Mechanism start
1717 * ********************************************* */
1719 /* SCO only or SCO+PAN(HS) */
1722 void halbtc8812a1ant_action_sco(IN struct btc_coexist* btcoexist)
1724 halbtc8812a1ant_sw_mechanism(btcoexist, true);
1728 void halbtc8812a1ant_action_hid(IN struct btc_coexist* btcoexist)
1730 halbtc8812a1ant_sw_mechanism(btcoexist, true);
1734 void halbtc8812a1ant_action_a2dp(IN struct btc_coexist* btcoexist)
1736 halbtc8812a1ant_sw_mechanism(btcoexist, false);
1739 void halbtc8812a1ant_action_a2dp_pan_hs(IN struct btc_coexist* btcoexist)
1741 halbtc8812a1ant_sw_mechanism(btcoexist, false);
1744 void halbtc8812a1ant_action_pan_edr(IN struct btc_coexist* btcoexist)
1746 halbtc8812a1ant_sw_mechanism(btcoexist, false);
1750 void halbtc8812a1ant_action_pan_hs(IN struct btc_coexist* btcoexist)
1752 halbtc8812a1ant_sw_mechanism(btcoexist, false);
1756 void halbtc8812a1ant_action_pan_edr_a2dp(IN struct btc_coexist* btcoexist)
1758 halbtc8812a1ant_sw_mechanism(btcoexist, false);
1761 void halbtc8812a1ant_action_pan_edr_hid(IN struct btc_coexist* btcoexist)
1763 halbtc8812a1ant_sw_mechanism(btcoexist, true);
1767 void halbtc8812a1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist* btcoexist)
1769 halbtc8812a1ant_sw_mechanism(btcoexist, true);
1772 void halbtc8812a1ant_action_hid_a2dp(IN struct btc_coexist* btcoexist)
1774 halbtc8812a1ant_sw_mechanism(btcoexist, true);
1779 /* *********************************************
1781 * Non-Software Coex Mechanism start
1783 * ********************************************* */
1784 void halbtc8812a1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
1786 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1789 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1790 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC,
1792 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1795 void halbtc8812a1ant_action_hs(IN struct btc_coexist *btcoexist)
1797 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1798 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1801 void halbtc8812a1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
1803 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1804 boolean wifi_connected = false, ap_enable = false, wifi_busy = false,
1807 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1809 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1811 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1812 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
1814 if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) {
1815 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1817 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1818 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
1819 NORMAL_EXEC, false, false);
1820 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1821 } else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1822 (bt_link_info->a2dp_exist)) {
1823 /* SCO/HID/A2DP busy */
1824 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1826 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1828 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1829 } else if ((bt_link_info->pan_exist) || (wifi_busy)) {
1830 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1832 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1834 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1836 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1838 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1839 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
1840 NORMAL_EXEC, false, false);
1841 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1845 void halbtc8812a1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
1846 *btcoexist, IN u8 wifi_status)
1848 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1849 boolean wifi_connected = false;
1851 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1854 /* tdma and coex table */
1856 if (bt_link_info->sco_exist) {
1857 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1858 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
1860 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
1861 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
1865 void halbtc8812a1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
1866 *btcoexist, IN u8 wifi_status)
1870 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1872 bt_rssi_state = halbtc8812a1ant_bt_rssi_state(2, 28, 0);
1874 if ((coex_sta->low_priority_rx >= 950) && (!coex_sta->under_ips))
1875 bt_link_info->slave_role = true;
1877 bt_link_info->slave_role = false;
1879 if (bt_link_info->hid_only) { /* HID */
1880 halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist,
1882 coex_dm->auto_tdma_adjust = false;
1884 } else if (bt_link_info->a2dp_only) { /* A2DP */
1885 if (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
1886 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1888 halbtc8812a1ant_coex_table_with_type(btcoexist,
1890 coex_dm->auto_tdma_adjust = false;
1892 halbtc8812a1ant_tdma_duration_adjust_for_acl(btcoexist,
1894 halbtc8812a1ant_coex_table_with_type(btcoexist,
1896 coex_dm->auto_tdma_adjust = true;
1898 } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
1899 (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
1900 bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
1901 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
1902 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1903 coex_dm->auto_tdma_adjust = false;
1904 } else if (bt_link_info->hid_exist &&
1905 bt_link_info->a2dp_exist) { /* HID+A2DP */
1906 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
1907 coex_dm->auto_tdma_adjust = false;
1909 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
1910 } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
1911 bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
1912 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1913 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1914 coex_dm->auto_tdma_adjust = false;
1916 /* BT no-profile busy (0x9) */
1917 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1918 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1919 coex_dm->auto_tdma_adjust = false;
1923 void halbtc8812a1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
1925 /* power save state */
1926 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1929 /* tdma and coex table */
1930 halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
1931 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC,
1933 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1936 void halbtc8812a1ant_action_wifi_not_connected_scan(IN struct btc_coexist
1939 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1941 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1944 /* tdma and coex table */
1945 if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1946 if (bt_link_info->a2dp_exist) {
1947 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1949 halbtc8812a1ant_coex_table_with_type(btcoexist,
1951 } else if (bt_link_info->a2dp_exist &&
1952 bt_link_info->pan_exist) {
1953 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1955 halbtc8812a1ant_coex_table_with_type(btcoexist,
1958 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1960 halbtc8812a1ant_coex_table_with_type(btcoexist,
1963 } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1964 (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1965 coex_dm->bt_status)) {
1966 halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist,
1967 BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1970 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1971 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
1972 NORMAL_EXEC, false, false);
1973 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1977 void halbtc8812a1ant_action_wifi_not_connected_asso_auth(
1978 IN struct btc_coexist *btcoexist)
1980 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1982 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1985 /* tdma and coex table */
1986 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1987 (bt_link_info->a2dp_exist)) {
1988 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1989 halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
1990 } else if (bt_link_info->pan_exist) {
1991 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1992 halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
1994 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1995 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
1996 NORMAL_EXEC, false, false);
1997 halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2);
2001 void halbtc8812a1ant_action_wifi_connected_scan(IN struct btc_coexist
2004 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2006 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
2009 /* tdma and coex table */
2010 if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
2011 if (bt_link_info->a2dp_exist) {
2012 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2014 halbtc8812a1ant_coex_table_with_type(btcoexist,
2016 } else if (bt_link_info->a2dp_exist &&
2017 bt_link_info->pan_exist) {
2018 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2020 halbtc8812a1ant_coex_table_with_type(btcoexist,
2023 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2025 halbtc8812a1ant_coex_table_with_type(btcoexist,
2028 } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2029 (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
2030 coex_dm->bt_status)) {
2031 halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist,
2032 BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
2035 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2036 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
2037 NORMAL_EXEC, false, false);
2038 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2042 void halbtc8812a1ant_action_wifi_connected_specific_packet(
2043 IN struct btc_coexist *btcoexist)
2045 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2047 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
2050 /* tdma and coex table */
2051 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
2052 (bt_link_info->a2dp_exist)) {
2053 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
2054 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2055 } else if (bt_link_info->pan_exist) {
2056 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
2057 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2059 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2060 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
2061 NORMAL_EXEC, false, false);
2062 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2066 void halbtc8812a1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
2068 boolean wifi_busy = false;
2069 boolean scan = false, link = false, roam = false;
2070 boolean under_4way = false, ap_enable = false;
2072 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2073 "[BTCoex], CoexForWifiConnect()===>\n");
2074 BTC_TRACE(trace_buf);
2076 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
2079 halbtc8812a1ant_action_wifi_connected_specific_packet(btcoexist);
2080 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2081 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
2082 BTC_TRACE(trace_buf);
2086 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2087 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2088 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2089 if (scan || link || roam) {
2091 halbtc8812a1ant_action_wifi_connected_scan(btcoexist);
2093 halbtc8812a1ant_action_wifi_connected_specific_packet(
2095 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2096 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
2097 BTC_TRACE(trace_buf);
2101 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
2103 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2105 /* power save state */
2107 BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status &&
2108 !btcoexist->bt_link_info.hid_only) {
2109 if (btcoexist->bt_link_info.a2dp_only) { /* A2DP */
2111 halbtc8812a1ant_power_save_state(btcoexist,
2112 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2114 if (coex_sta->scan_ap_num >=
2115 BT_8812A_1ANT_WIFI_NOISY_THRESH) /* no force LPS, no PS-TDMA, use pure TDMA */
2116 halbtc8812a1ant_power_save_state(
2117 btcoexist, BTC_PS_WIFI_NATIVE,
2120 halbtc8812a1ant_power_save_state(
2121 btcoexist, BTC_PS_LPS_ON, 0x50,
2124 } else if ((coex_sta->pan_exist == false) &&
2125 (coex_sta->a2dp_exist == false) &&
2126 (coex_sta->hid_exist == false))
2127 halbtc8812a1ant_power_save_state(btcoexist,
2128 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2130 halbtc8812a1ant_power_save_state(btcoexist,
2131 BTC_PS_LPS_ON, 0x50, 0x4);
2133 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2136 /* tdma and coex table */
2138 if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
2139 halbtc8812a1ant_action_wifi_connected_bt_acl_busy(
2141 BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2142 } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY ==
2143 coex_dm->bt_status) ||
2144 (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
2145 coex_dm->bt_status)) {
2146 halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist,
2147 BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2149 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
2151 halbtc8812a1ant_set_ant_path(btcoexist,
2152 BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false);
2153 if ((coex_sta->high_priority_tx) +
2154 (coex_sta->high_priority_rx) <= 60)
2155 halbtc8812a1ant_coex_table_with_type(btcoexist,
2158 halbtc8812a1ant_coex_table_with_type(btcoexist,
2162 if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
2163 halbtc8812a1ant_action_wifi_connected_bt_acl_busy(
2165 BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2166 } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY ==
2167 coex_dm->bt_status) ||
2168 (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
2169 coex_dm->bt_status)) {
2170 halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist,
2171 BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2173 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
2175 halbtc8812a1ant_set_ant_path(btcoexist,
2176 BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false);
2177 if ((coex_sta->high_priority_tx) +
2178 (coex_sta->high_priority_rx) <= 60)
2179 halbtc8812a1ant_coex_table_with_type(btcoexist,
2182 halbtc8812a1ant_coex_table_with_type(btcoexist,
2188 void halbtc8812a1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
2192 algorithm = halbtc8812a1ant_action_algorithm(btcoexist);
2193 coex_dm->cur_algorithm = algorithm;
2195 if (halbtc8812a1ant_is_common_action(btcoexist)) {
2198 switch (coex_dm->cur_algorithm) {
2199 case BT_8812A_1ANT_COEX_ALGO_SCO:
2200 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2201 "[BTCoex], Action algorithm = SCO.\n");
2202 BTC_TRACE(trace_buf);
2203 /* halbtc8812a1ant_action_sco(btcoexist); */
2205 case BT_8812A_1ANT_COEX_ALGO_HID:
2206 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2207 "[BTCoex], Action algorithm = HID.\n");
2208 BTC_TRACE(trace_buf);
2209 /* halbtc8812a1ant_action_hid(btcoexist); */
2211 case BT_8812A_1ANT_COEX_ALGO_A2DP:
2212 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2213 "[BTCoex], Action algorithm = A2DP.\n");
2214 BTC_TRACE(trace_buf);
2215 /* halbtc8812a1ant_action_a2dp(btcoexist); */
2217 case BT_8812A_1ANT_COEX_ALGO_A2DP_PANHS:
2218 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2219 "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
2220 BTC_TRACE(trace_buf);
2221 /* halbtc8812a1ant_action_a2dp_pan_hs(btcoexist); */
2223 case BT_8812A_1ANT_COEX_ALGO_PANEDR:
2224 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2225 "[BTCoex], Action algorithm = PAN(EDR).\n");
2226 BTC_TRACE(trace_buf);
2227 /* halbtc8812a1ant_action_pan_edr(btcoexist); */
2229 case BT_8812A_1ANT_COEX_ALGO_PANHS:
2230 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2231 "[BTCoex], Action algorithm = HS mode.\n");
2232 BTC_TRACE(trace_buf);
2233 /* halbtc8812a1ant_action_pan_hs(btcoexist); */
2235 case BT_8812A_1ANT_COEX_ALGO_PANEDR_A2DP:
2236 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2237 "[BTCoex], Action algorithm = PAN+A2DP.\n");
2238 BTC_TRACE(trace_buf);
2239 /* halbtc8812a1ant_action_pan_edr_a2dp(btcoexist); */
2241 case BT_8812A_1ANT_COEX_ALGO_PANEDR_HID:
2242 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2243 "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
2244 BTC_TRACE(trace_buf);
2245 /* halbtc8812a1ant_action_pan_edr_hid(btcoexist); */
2247 case BT_8812A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
2248 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2249 "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
2250 BTC_TRACE(trace_buf);
2251 /* halbtc8812a1ant_action_hid_a2dp_pan_edr(btcoexist); */
2253 case BT_8812A_1ANT_COEX_ALGO_HID_A2DP:
2254 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2255 "[BTCoex], Action algorithm = HID+A2DP.\n");
2256 BTC_TRACE(trace_buf);
2257 /* halbtc8812a1ant_action_hid_a2dp(btcoexist); */
2260 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2261 "[BTCoex], Action algorithm = coexist All Off!!\n");
2262 BTC_TRACE(trace_buf);
2263 /* halbtc8812a1ant_coex_all_off(btcoexist); */
2266 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
2270 void halbtc8812a1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
2272 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2273 boolean wifi_connected = false, bt_hs_on = false;
2274 boolean increase_scan_dev_num = false;
2275 boolean bt_ctrl_agg_buf_size = false;
2276 boolean miracast_plus_bt = false;
2277 u8 agg_buf_size = 5;
2278 u32 wifi_link_status = 0;
2279 u32 num_of_wifi_link = 0, wifi_bw;
2281 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2282 "[BTCoex], RunCoexistMechanism()===>\n");
2283 BTC_TRACE(trace_buf);
2285 if (btcoexist->manual_control) {
2286 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2287 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2288 BTC_TRACE(trace_buf);
2292 if (btcoexist->stop_coex_dm) {
2293 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2294 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2295 BTC_TRACE(trace_buf);
2299 if (coex_sta->under_ips) {
2300 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2301 "[BTCoex], wifi is under IPS !!!\n");
2302 BTC_TRACE(trace_buf);
2306 if ((BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
2307 (BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2308 (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
2309 increase_scan_dev_num = true;
2311 btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
2312 &increase_scan_dev_num);
2313 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2316 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2318 num_of_wifi_link = wifi_link_status >> 16;
2320 if ((num_of_wifi_link >= 2) ||
2321 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
2322 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2323 "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
2324 num_of_wifi_link, wifi_link_status);
2325 BTC_TRACE(trace_buf);
2327 if (bt_link_info->bt_link_exist) {
2328 halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1,
2330 miracast_plus_bt = true;
2332 halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
2334 miracast_plus_bt = false;
2336 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
2338 halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2339 bt_ctrl_agg_buf_size, agg_buf_size);
2341 if ((bt_link_info->a2dp_exist) &&
2342 (coex_sta->c2h_bt_inquiry_page)) {
2343 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2344 "############# [BTCoex], BT Is Inquirying\n");
2345 BTC_TRACE(trace_buf);
2346 halbtc8812a1ant_action_bt_inquiry(btcoexist);
2348 halbtc8812a1ant_action_wifi_multi_port(btcoexist);
2353 miracast_plus_bt = false;
2354 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
2357 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2359 if ((bt_link_info->bt_link_exist) && (wifi_connected)) {
2360 halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1);
2362 if (bt_link_info->sco_exist)
2363 halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, true,
2366 if (BTC_WIFI_BW_HT40 == wifi_bw)
2367 halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC,
2370 halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC,
2374 halbtc8812a1ant_sw_mechanism(btcoexist, true);
2375 halbtc8812a1ant_run_sw_coexist_mechanism(
2376 btcoexist); /* just print debug message */
2378 halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2380 halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
2383 halbtc8812a1ant_sw_mechanism(btcoexist, false);
2384 halbtc8812a1ant_run_sw_coexist_mechanism(
2385 btcoexist); /* //just print debug message */
2388 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2389 if (coex_sta->c2h_bt_inquiry_page) {
2390 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2391 "############# [BTCoex], BT Is Inquirying\n");
2392 BTC_TRACE(trace_buf);
2393 halbtc8812a1ant_action_bt_inquiry(btcoexist);
2395 } else if (bt_hs_on) {
2396 halbtc8812a1ant_action_hs(btcoexist);
2401 if (!wifi_connected) {
2402 boolean scan = false, link = false, roam = false;
2404 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2405 "[BTCoex], wifi is non connected-idle !!!\n");
2406 BTC_TRACE(trace_buf);
2408 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2409 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2410 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2412 if (scan || link || roam) {
2414 halbtc8812a1ant_action_wifi_not_connected_scan(
2417 halbtc8812a1ant_action_wifi_not_connected_asso_auth(
2420 halbtc8812a1ant_action_wifi_not_connected(btcoexist);
2421 } else /* wifi LPS/Busy */
2422 halbtc8812a1ant_action_wifi_connected(btcoexist);
2425 void halbtc8812a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2427 /* force to reset coex mechanism */
2430 halbtc8812a1ant_sw_mechanism(btcoexist, false);
2432 /* halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
2433 /* halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); */
2435 coex_sta->pop_event_cnt = 0;
2438 void halbtc8812a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2439 IN boolean back_up, IN boolean wifi_only)
2443 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2444 "[BTCoex], 1Ant Init HW Config!!\n");
2445 BTC_TRACE(trace_buf);
2447 /* ant sw control to BT */
2448 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, FORCE_EXEC,
2451 /* 0x790[5:0]=0x5 */
2452 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
2455 btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
2458 btcoexist->btc_write_1byte(btcoexist, 0x6cc, 0x0);
2459 btcoexist->btc_write_4byte(btcoexist, 0x6c8, 0xffff);
2460 btcoexist->btc_write_4byte(btcoexist, 0x6c4, 0x55555555);
2461 btcoexist->btc_write_4byte(btcoexist, 0x6c0, 0x55555555);
2463 /* coex parameters */
2464 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
2466 /* enable counter statistics */
2467 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
2470 btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20);
2472 /* bt clock related */
2473 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x4);
2475 btcoexist->btc_write_1byte(btcoexist, 0x4, u8tmp);
2477 /* bt clock related */
2478 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7);
2480 btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp);
2483 /* ************************************************************
2484 * work around function start with wa_halbtc8812a1ant_
2485 * ************************************************************
2486 * ************************************************************
2487 * extern function start with ex_halbtc8812a1ant_
2488 * ************************************************************ */
2489 void ex_halbtc8812a1ant_power_on_setting(IN struct btc_coexist *btcoexist)
2493 void ex_halbtc8812a1ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
2497 void ex_halbtc8812a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2498 IN boolean wifi_only)
2500 halbtc8812a1ant_init_hw_config(btcoexist, true, wifi_only);
2501 btcoexist->stop_coex_dm = false;
2504 void ex_halbtc8812a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2506 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2507 "[BTCoex], Coex Mechanism Init!!\n");
2508 BTC_TRACE(trace_buf);
2510 btcoexist->stop_coex_dm = false;
2512 halbtc8812a1ant_init_coex_dm(btcoexist);
2514 halbtc8812a1ant_query_bt_info(btcoexist);
2517 void ex_halbtc8812a1ant_display_coex_info(IN struct btc_coexist *btcoexist)
2519 struct btc_board_info *board_info = &btcoexist->board_info;
2520 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2521 u8 *cli_buf = btcoexist->cli_buf;
2522 u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
2524 u32 fw_ver = 0, bt_patch_ver = 0;
2526 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2527 "\r\n ============[BT Coexist info]============");
2530 if (btcoexist->manual_control) {
2531 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2532 "\r\n ============[Under Manual Control]============");
2534 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2535 "\r\n ==========================================");
2538 if (btcoexist->stop_coex_dm) {
2539 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2540 "\r\n ============[Coex is STOPPED]============");
2542 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2543 "\r\n ==========================================");
2547 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
2548 "Ant PG number/ Ant mechanism:",
2549 board_info->pg_ant_num, board_info->btdm_ant_num);
2552 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
2553 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
2554 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2555 "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
2556 "CoexVer/ FwVer/ PatchVer",
2557 glcoex_ver_date_8812a_1ant, glcoex_ver_8812a_1ant, fw_ver,
2558 bt_patch_ver, bt_patch_ver);
2561 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
2562 "Wifi channel informed to BT",
2563 coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
2564 coex_dm->wifi_chnl_info[2]);
2568 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2569 "============[Wifi Status]============");
2571 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
2573 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2574 "============[BT Status]============");
2577 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
2578 "BT [status/ rssi/ retryCnt]",
2579 ((coex_sta->bt_disabled) ? ("disabled") : ((
2580 coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
2581 : ((BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2582 coex_dm->bt_status) ? "non-connected idle" :
2583 ((BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
2584 ? "connected-idle" : "busy")))),
2585 coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
2588 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
2590 bt_link_info->sco_exist, bt_link_info->hid_exist,
2591 bt_link_info->pan_exist, bt_link_info->a2dp_exist);
2593 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
2595 bt_info_ext = coex_sta->bt_info_ext;
2596 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
2597 "BT Info A2DP rate",
2598 (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
2601 for (i = 0; i < BT_INFO_SRC_8812A_1ANT_MAX; i++) {
2602 if (coex_sta->bt_info_c2h_cnt[i]) {
2603 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2604 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
2605 glbt_info_src_8812a_1ant[i],
2606 coex_sta->bt_info_c2h[i][0],
2607 coex_sta->bt_info_c2h[i][1],
2608 coex_sta->bt_info_c2h[i][2],
2609 coex_sta->bt_info_c2h[i][3],
2610 coex_sta->bt_info_c2h[i][4],
2611 coex_sta->bt_info_c2h[i][5],
2612 coex_sta->bt_info_c2h[i][6],
2613 coex_sta->bt_info_c2h_cnt[i]);
2618 if (!btcoexist->manual_control) {
2619 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2620 "============[mechanisms]============");
2623 ps_tdma_case = coex_dm->cur_ps_tdma;
2624 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2625 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d",
2627 coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
2628 coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
2629 coex_dm->ps_tdma_para[4], ps_tdma_case);
2632 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ",
2633 "Latest error condition(should be 0)",
2634 coex_dm->error_condition);
2637 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ",
2639 coex_dm->cur_ignore_wlan_act);
2644 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2645 "============[Hw setting]============");
2648 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
2649 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778",
2653 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcb3);
2654 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xcb7);
2655 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x900);
2656 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2657 "0xcb3/0xcb7/0x900",
2658 u8tmp[0], u8tmp[1], u32tmp[0]);
2661 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
2662 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40",
2666 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
2667 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
2668 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2669 "0x550(bcn ctrl)/0x522",
2670 u32tmp[0], u8tmp[0]);
2673 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
2674 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)",
2678 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
2679 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
2680 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
2681 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
2682 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2683 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
2684 "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
2685 u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
2688 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2689 "0x770(hp rx[31:16]/tx[15:0])",
2690 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
2692 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2693 "0x774(lp rx[31:16]/tx[15:0])",
2694 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
2697 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
2702 void ex_halbtc8812a1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2704 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2707 if (BTC_IPS_ENTER == type) {
2708 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2709 "[BTCoex], IPS ENTER notify\n");
2710 BTC_TRACE(trace_buf);
2711 coex_sta->under_ips = true;
2713 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2714 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
2715 FORCE_EXEC, false, true);
2716 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2717 } else if (BTC_IPS_LEAVE == type) {
2718 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2719 "[BTCoex], IPS LEAVE notify\n");
2720 BTC_TRACE(trace_buf);
2722 halbtc8812a1ant_init_hw_config(btcoexist, false, false);
2723 halbtc8812a1ant_init_coex_dm(btcoexist);
2724 halbtc8812a1ant_query_bt_info(btcoexist);
2726 coex_sta->under_ips = false;
2730 void ex_halbtc8812a1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2732 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2735 if (BTC_LPS_ENABLE == type) {
2736 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2737 "[BTCoex], LPS ENABLE notify\n");
2738 BTC_TRACE(trace_buf);
2739 coex_sta->under_lps = true;
2740 } else if (BTC_LPS_DISABLE == type) {
2741 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2742 "[BTCoex], LPS DISABLE notify\n");
2743 BTC_TRACE(trace_buf);
2744 coex_sta->under_lps = false;
2748 void ex_halbtc8812a1ant_scan_notify(IN struct btc_coexist *btcoexist,
2751 boolean wifi_connected = false, bt_hs_on = false;
2752 u32 wifi_link_status = 0;
2753 u32 num_of_wifi_link = 0;
2754 boolean bt_ctrl_agg_buf_size = false;
2755 u8 agg_buf_size = 5;
2757 if (btcoexist->manual_control ||
2758 btcoexist->stop_coex_dm)
2761 if (BTC_SCAN_START == type) {
2762 coex_sta->wifi_is_high_pri_task = true;
2763 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2764 "[BTCoex], SCAN START notify\n");
2765 BTC_TRACE(trace_buf);
2767 halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
2768 8); /* Force antenna setup for no scan result issue */
2769 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
2770 FORCE_EXEC, false, false);
2772 coex_sta->wifi_is_high_pri_task = false;
2773 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2774 "[BTCoex], SCAN FINISH notify\n");
2775 BTC_TRACE(trace_buf);
2777 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
2778 &coex_sta->scan_ap_num);
2781 if (coex_sta->bt_disabled)
2784 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2785 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2788 halbtc8812a1ant_query_bt_info(btcoexist);
2790 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2792 num_of_wifi_link = wifi_link_status >> 16;
2793 if (num_of_wifi_link >= 2) {
2794 halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2795 halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2796 bt_ctrl_agg_buf_size, agg_buf_size);
2797 halbtc8812a1ant_action_wifi_multi_port(btcoexist);
2801 if (coex_sta->c2h_bt_inquiry_page) {
2802 halbtc8812a1ant_action_bt_inquiry(btcoexist);
2804 } else if (bt_hs_on) {
2805 halbtc8812a1ant_action_hs(btcoexist);
2809 if (BTC_SCAN_START == type) {
2810 if (!wifi_connected) /* non-connected scan */
2811 halbtc8812a1ant_action_wifi_not_connected_scan(
2813 else /* wifi is connected */
2814 halbtc8812a1ant_action_wifi_connected_scan(btcoexist);
2815 } else if (BTC_SCAN_FINISH == type) {
2816 if (!wifi_connected) /* non-connected scan */
2817 halbtc8812a1ant_action_wifi_not_connected(btcoexist);
2819 halbtc8812a1ant_action_wifi_connected(btcoexist);
2823 void ex_halbtc8812a1ant_connect_notify(IN struct btc_coexist *btcoexist,
2826 boolean wifi_connected = false, bt_hs_on = false;
2827 u32 wifi_link_status = 0;
2828 u32 num_of_wifi_link = 0;
2829 boolean bt_ctrl_agg_buf_size = false;
2830 u8 agg_buf_size = 5;
2832 if (btcoexist->manual_control ||
2833 btcoexist->stop_coex_dm ||
2834 coex_sta->bt_disabled)
2837 if (BTC_ASSOCIATE_START == type) {
2838 coex_sta->wifi_is_high_pri_task = true;
2839 halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
2840 8); /* Force antenna setup for no scan result issue */
2841 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
2842 FORCE_EXEC, false, false);
2843 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2844 "[BTCoex], CONNECT START notify\n");
2845 BTC_TRACE(trace_buf);
2846 coex_dm->arp_cnt = 0;
2848 coex_sta->wifi_is_high_pri_task = false;
2849 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2850 "[BTCoex], CONNECT FINISH notify\n");
2851 BTC_TRACE(trace_buf);
2852 /* coex_dm->arp_cnt = 0; */
2855 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2857 num_of_wifi_link = wifi_link_status >> 16;
2858 if (num_of_wifi_link >= 2) {
2859 halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2860 halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2861 bt_ctrl_agg_buf_size, agg_buf_size);
2862 halbtc8812a1ant_action_wifi_multi_port(btcoexist);
2866 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2867 if (coex_sta->c2h_bt_inquiry_page) {
2868 halbtc8812a1ant_action_bt_inquiry(btcoexist);
2870 } else if (bt_hs_on) {
2871 halbtc8812a1ant_action_hs(btcoexist);
2875 if (BTC_ASSOCIATE_START == type)
2876 halbtc8812a1ant_action_wifi_not_connected_asso_auth(btcoexist);
2877 else if (BTC_ASSOCIATE_FINISH == type) {
2879 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2881 if (!wifi_connected) /* non-connected scan */
2882 halbtc8812a1ant_action_wifi_not_connected(btcoexist);
2884 halbtc8812a1ant_action_wifi_connected(btcoexist);
2888 /* to check registers... */
2889 void ex_halbtc8812a1ant_media_status_notify(IN struct btc_coexist *btcoexist,
2894 u8 h2c_parameter[3] = {0};
2896 u8 wifi_central_chnl;
2897 boolean wifi_under_b_mode = false;
2899 if (btcoexist->manual_control ||
2900 btcoexist->stop_coex_dm ||
2901 coex_sta->bt_disabled)
2904 if (BTC_MEDIA_CONNECT == type) {
2905 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2906 "[BTCoex], MEDIA connect notify\n");
2907 BTC_TRACE(trace_buf);
2908 halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
2909 8); /* Force antenna setup for no scan result issue */
2910 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
2911 FORCE_EXEC, false, false);
2912 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
2913 &wifi_under_b_mode);
2915 /* Set CCK Tx/Rx high Pri except 11b mode */
2916 if (wifi_under_b_mode) {
2917 btcoexist->btc_write_1byte(btcoexist, 0x6cd,
2919 btcoexist->btc_write_1byte(btcoexist, 0x6cf,
2922 btcoexist->btc_write_1byte(btcoexist, 0x6cd,
2924 btcoexist->btc_write_1byte(btcoexist, 0x6cf,
2928 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
2930 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
2932 coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
2934 coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
2937 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2938 "[BTCoex], MEDIA disconnect notify\n");
2939 BTC_TRACE(trace_buf);
2940 coex_dm->arp_cnt = 0;
2942 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
2943 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
2946 /* only 2.4G we need to inform bt the chnl mask */
2947 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
2948 &wifi_central_chnl);
2949 if ((BTC_MEDIA_CONNECT == type) &&
2950 (wifi_central_chnl <= 14)) {
2951 /* h2c_parameter[0] = 0x1; */
2952 h2c_parameter[0] = 0x0;
2953 h2c_parameter[1] = wifi_central_chnl;
2954 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2955 if (BTC_WIFI_BW_HT40 == wifi_bw)
2956 h2c_parameter[2] = 0x30;
2958 h2c_parameter[2] = 0x20;
2961 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
2962 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
2963 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
2966 buf[1] = 0x5; /* OP_Code */
2967 buf[2] = 0x3; /* OP_Code_Length */
2968 buf[3] = h2c_parameter[0]; /* OP_Code_Content */
2969 buf[4] = h2c_parameter[1];
2970 buf[5] = h2c_parameter[2];
2972 btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
2976 void ex_halbtc8812a1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
2979 boolean bt_hs_on = false;
2980 u32 wifi_link_status = 0;
2981 u32 num_of_wifi_link = 0;
2982 boolean bt_ctrl_agg_buf_size = false;
2983 u8 agg_buf_size = 5;
2985 if (btcoexist->manual_control ||
2986 btcoexist->stop_coex_dm ||
2987 coex_sta->bt_disabled)
2990 if (BTC_PACKET_DHCP == type ||
2991 BTC_PACKET_EAPOL == type ||
2992 BTC_PACKET_ARP == type) {
2993 if (BTC_PACKET_ARP == type) {
2994 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2995 "[BTCoex], specific Packet ARP notify\n");
2996 BTC_TRACE(trace_buf);
2999 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3000 "[BTCoex], ARP Packet Count = %d\n",
3002 BTC_TRACE(trace_buf);
3004 if (coex_dm->arp_cnt >=
3005 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */
3006 coex_sta->wifi_is_high_pri_task = false;
3008 coex_sta->wifi_is_high_pri_task = true;
3010 coex_sta->wifi_is_high_pri_task = true;
3011 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3012 "[BTCoex], specific Packet DHCP or EAPOL notify\n");
3013 BTC_TRACE(trace_buf);
3016 coex_sta->wifi_is_high_pri_task = false;
3017 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3018 "[BTCoex], specific Packet [Type = %d] notify\n", type);
3019 BTC_TRACE(trace_buf);
3022 coex_sta->specific_pkt_period_cnt = 0;
3024 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3026 num_of_wifi_link = wifi_link_status >> 16;
3027 if (num_of_wifi_link >= 2) {
3028 halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3029 halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3030 bt_ctrl_agg_buf_size, agg_buf_size);
3031 halbtc8812a1ant_action_wifi_multi_port(btcoexist);
3035 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3036 if (coex_sta->c2h_bt_inquiry_page) {
3037 halbtc8812a1ant_action_bt_inquiry(btcoexist);
3039 } else if (bt_hs_on) {
3040 halbtc8812a1ant_action_hs(btcoexist);
3044 if (BTC_PACKET_DHCP == type ||
3045 BTC_PACKET_EAPOL == type ||
3046 ((BTC_PACKET_ARP == type) && (coex_sta->wifi_is_high_pri_task)))
3047 halbtc8812a1ant_action_wifi_connected_specific_packet(btcoexist);
3050 void ex_halbtc8812a1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
3051 IN u8 *tmp_buf, IN u8 length)
3054 u8 i, rsp_source = 0;
3055 boolean wifi_connected = false;
3056 boolean bt_busy = false;
3058 coex_sta->c2h_bt_info_req_sent = false;
3060 rsp_source = tmp_buf[0] & 0xf;
3061 if (rsp_source >= BT_INFO_SRC_8812A_1ANT_MAX)
3062 rsp_source = BT_INFO_SRC_8812A_1ANT_WIFI_FW;
3063 coex_sta->bt_info_c2h_cnt[rsp_source]++;
3065 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3066 "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
3068 BTC_TRACE(trace_buf);
3069 for (i = 0; i < length; i++) {
3070 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
3072 bt_info = tmp_buf[i];
3073 if (i == length - 1) {
3074 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
3076 BTC_TRACE(trace_buf);
3078 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
3080 BTC_TRACE(trace_buf);
3084 if (BT_INFO_SRC_8812A_1ANT_WIFI_FW != rsp_source) {
3085 coex_sta->bt_retry_cnt = /* [3:0] */
3086 coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
3088 if (coex_sta->bt_retry_cnt >= 1)
3089 coex_sta->pop_event_cnt++;
3091 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
3092 coex_sta->c2h_bt_page = true;
3094 coex_sta->c2h_bt_page = false;
3097 coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90;
3098 /* coex_sta->bt_info_c2h[rsp_source][3]*2+10; */
3100 coex_sta->bt_info_ext =
3101 coex_sta->bt_info_c2h[rsp_source][4];
3103 coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
3105 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
3106 &coex_sta->bt_tx_rx_mask);
3107 if (!coex_sta->bt_tx_rx_mask) {
3108 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
3109 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3110 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
3111 BTC_TRACE(trace_buf);
3112 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
3116 /* Here we need to resend some wifi info to BT */
3117 /* because bt is reset and loss of the info. */
3118 if (coex_sta->bt_info_ext & BIT(1)) {
3119 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3120 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
3121 BTC_TRACE(trace_buf);
3122 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3125 ex_halbtc8812a1ant_media_status_notify(
3126 btcoexist, BTC_MEDIA_CONNECT);
3128 ex_halbtc8812a1ant_media_status_notify(
3129 btcoexist, BTC_MEDIA_DISCONNECT);
3132 if (coex_sta->bt_info_ext & BIT(3)) {
3133 if (!btcoexist->manual_control &&
3134 !btcoexist->stop_coex_dm) {
3135 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3136 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
3137 BTC_TRACE(trace_buf);
3138 halbtc8812a1ant_ignore_wlan_act(btcoexist,
3142 /* BT already NOT ignore Wlan active, do nothing here. */
3144 #if (BT_AUTO_REPORT_ONLY_8812A_1ANT == 0)
3145 if ((coex_sta->bt_info_ext & BIT(4))) {
3146 /* BT auto report already enabled, do nothing */
3148 halbtc8812a1ant_bt_auto_report(btcoexist, FORCE_EXEC,
3153 /* check BIT2 first ==> check if bt is under inquiry or page scan */
3154 if (bt_info & BT_INFO_8812A_1ANT_B_INQ_PAGE)
3155 coex_sta->c2h_bt_inquiry_page = true;
3157 coex_sta->c2h_bt_inquiry_page = false;
3159 /* set link exist status */
3160 if (!(bt_info & BT_INFO_8812A_1ANT_B_CONNECTION)) {
3161 coex_sta->bt_link_exist = false;
3162 coex_sta->pan_exist = false;
3163 coex_sta->a2dp_exist = false;
3164 coex_sta->hid_exist = false;
3165 coex_sta->sco_exist = false;
3166 } else { /* connection exists */
3167 coex_sta->bt_link_exist = true;
3168 if (bt_info & BT_INFO_8812A_1ANT_B_FTP)
3169 coex_sta->pan_exist = true;
3171 coex_sta->pan_exist = false;
3172 if (bt_info & BT_INFO_8812A_1ANT_B_A2DP)
3173 coex_sta->a2dp_exist = true;
3175 coex_sta->a2dp_exist = false;
3176 if (bt_info & BT_INFO_8812A_1ANT_B_HID)
3177 coex_sta->hid_exist = true;
3179 coex_sta->hid_exist = false;
3180 if (bt_info & BT_INFO_8812A_1ANT_B_SCO_ESCO)
3181 coex_sta->sco_exist = true;
3183 coex_sta->sco_exist = false;
3186 halbtc8812a1ant_update_bt_link_info(btcoexist);
3189 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
3191 if (!(bt_info & BT_INFO_8812A_1ANT_B_CONNECTION)) {
3192 coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
3193 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3194 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
3195 BTC_TRACE(trace_buf);
3196 } else if (bt_info ==
3197 BT_INFO_8812A_1ANT_B_CONNECTION) { /* connection exists but no busy */
3198 coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE;
3199 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3200 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
3201 BTC_TRACE(trace_buf);
3202 } else if ((bt_info & BT_INFO_8812A_1ANT_B_SCO_ESCO) ||
3203 (bt_info & BT_INFO_8812A_1ANT_B_SCO_BUSY)) {
3204 coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_SCO_BUSY;
3205 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3206 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
3207 BTC_TRACE(trace_buf);
3208 } else if (bt_info & BT_INFO_8812A_1ANT_B_ACL_BUSY) {
3209 if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
3210 coex_dm->auto_tdma_adjust = false;
3211 coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_ACL_BUSY;
3212 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3213 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
3214 BTC_TRACE(trace_buf);
3216 coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_MAX;
3217 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3218 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
3219 BTC_TRACE(trace_buf);
3222 if ((BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
3223 (BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3224 (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
3228 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3230 halbtc8812a1ant_run_coexist_mechanism(btcoexist);
3233 void ex_halbtc8812a1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
3236 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
3237 BTC_TRACE(trace_buf);
3239 if (BTC_RF_ON == type) {
3240 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3241 "[BTCoex], RF is turned ON!!\n");
3242 BTC_TRACE(trace_buf);
3243 btcoexist->stop_coex_dm = false;
3244 } else if (BTC_RF_OFF == type) {
3245 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3246 "[BTCoex], RF is turned OFF!!\n");
3247 BTC_TRACE(trace_buf);
3249 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3251 halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3252 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
3253 FORCE_EXEC, false, true);
3255 halbtc8812a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3256 btcoexist->stop_coex_dm = true;
3260 void ex_halbtc8812a1ant_halt_notify(IN struct btc_coexist *btcoexist)
3262 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
3263 BTC_TRACE(trace_buf);
3265 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
3267 halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3268 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, FORCE_EXEC,
3271 halbtc8812a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3273 ex_halbtc8812a1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3275 btcoexist->stop_coex_dm = true;
3278 void ex_halbtc8812a1ant_pnp_notify(IN struct btc_coexist *btcoexist,
3281 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
3282 BTC_TRACE(trace_buf);
3284 if (BTC_WIFI_PNP_SLEEP == pnp_state) {
3285 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3286 "[BTCoex], Pnp notify to SLEEP\n");
3287 BTC_TRACE(trace_buf);
3289 halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3291 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3292 halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
3293 FORCE_EXEC, false, true);
3294 halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3296 /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */
3297 /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */
3298 /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */
3299 coex_sta->under_ips = false;
3300 coex_sta->under_lps = false;
3301 btcoexist->stop_coex_dm = true;
3302 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
3303 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3304 "[BTCoex], Pnp notify to WAKE UP\n");
3305 BTC_TRACE(trace_buf);
3306 btcoexist->stop_coex_dm = false;
3307 halbtc8812a1ant_init_hw_config(btcoexist, false, false);
3308 halbtc8812a1ant_init_coex_dm(btcoexist);
3309 halbtc8812a1ant_query_bt_info(btcoexist);
3313 void ex_halbtc8812a1ant_coex_dm_reset(IN struct btc_coexist *btcoexist)
3315 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3316 "[BTCoex], *****************Coex DM Reset*****************\n");
3317 BTC_TRACE(trace_buf);
3319 halbtc8812a1ant_init_hw_config(btcoexist, false, false);
3320 halbtc8812a1ant_init_coex_dm(btcoexist);
3323 void ex_halbtc8812a1ant_periodical(IN struct btc_coexist *btcoexist)
3325 #if (BT_AUTO_REPORT_ONLY_8812A_1ANT == 0)
3326 halbtc8812a1ant_query_bt_info(btcoexist);
3327 halbtc8812a1ant_monitor_bt_enable_disable(btcoexist);
3329 halbtc8812a1ant_monitor_bt_ctr(btcoexist);
3330 halbtc8812a1ant_monitor_wifi_ctr(btcoexist);
3332 if (halbtc8812a1ant_is_wifi_status_changed(btcoexist) ||
3333 coex_dm->auto_tdma_adjust)
3334 halbtc8812a1ant_run_coexist_mechanism(btcoexist);
3336 coex_sta->specific_pkt_period_cnt++;
3340 void ex_halbtc8812a1ant_dbg_control(IN struct btc_coexist *btcoexist,
3341 IN u8 op_code, IN u8 op_len, IN u8 *pdata)
3344 case BTC_DBG_SET_COEX_NORMAL:
3345 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3346 "[BTCoex], Set CoexMode to Normal\n");
3347 BTC_TRACE(trace_buf);
3348 btcoexist->manual_control = false;
3349 halbtc8812a1ant_init_coex_dm(btcoexist);
3351 case BTC_DBG_SET_COEX_WIFI_ONLY:
3352 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3353 "[BTCoex], Set CoexMode to Wifi Only\n");
3354 BTC_TRACE(trace_buf);
3355 btcoexist->manual_control = true;
3356 halbtc8812a1ant_power_save_state(btcoexist,
3357 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3358 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
3361 case BTC_DBG_SET_COEX_BT_ONLY:
3362 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3363 "[BTCoex], Set CoexMode to BT only\n");
3364 BTC_TRACE(trace_buf);
3365 btcoexist->manual_control = true;
3366 halbtc8812a1ant_power_save_state(btcoexist,
3367 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3368 halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
3371 case BTC_DBG_SET_COEX_DEC_BT_PWR:
3372 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3373 "[BTCoex], Set Dec BT power\n");
3374 BTC_TRACE(trace_buf);
3378 u8 dec_bt_pwr = 0, pwr_level = 0;
3381 dec_bt_pwr = pdata[0];
3382 pwr_level = pdata[1];
3385 buf[1] = 0x3; /* OP_Code */
3386 buf[2] = 0x2; /* OP_Code_Length */
3388 buf[3] = dec_bt_pwr; /* OP_Code_Content */
3390 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3391 "[BTCoex], Set Dec BT power=%d, pwr_level=%d\n",
3392 dec_bt_pwr, pwr_level);
3393 BTC_TRACE(trace_buf);
3394 btcoexist->btc_set(btcoexist,
3395 BTC_SET_ACT_CTRL_BT_COEX,
3401 case BTC_DBG_SET_COEX_BT_AFH_MAP:
3402 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3403 "[BTCoex], Set BT AFH Map\n");
3404 BTC_TRACE(trace_buf);
3411 buf[1] = 0x5; /* OP_Code */
3412 buf[2] = 0x3; /* OP_Code_Length */
3414 buf[3] = pdata[0]; /* OP_Code_Content */
3418 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3419 "[BTCoex], Set BT AFH Map = %02x %02x %02x\n",
3420 pdata[0], pdata[1], pdata[2]);
3421 BTC_TRACE(trace_buf);
3422 btcoexist->btc_set(btcoexist,
3423 BTC_SET_ACT_CTRL_BT_COEX,
3429 case BTC_DBG_SET_COEX_BT_IGNORE_WLAN_ACT:
3430 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3431 "[BTCoex], Set BT Ignore Wlan Active\n");
3432 BTC_TRACE(trace_buf);
3439 buf[1] = 0x1; /* OP_Code */
3440 buf[2] = 0x1; /* OP_Code_Length */
3442 buf[3] = pdata[0]; /* OP_Code_Content */
3443 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3444 "[BTCoex], Set BT Ignore Wlan Active = 0x%x\n",
3446 BTC_TRACE(trace_buf);
3448 btcoexist->btc_set(btcoexist,
3449 BTC_SET_ACT_CTRL_BT_COEX,
3461 #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */