1 /* ************************************************************
4 * This file is for RTL8192E 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 (RTL8192E_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_8192e_1ant glcoex_dm_8192e_1ant;
24 static struct coex_dm_8192e_1ant *coex_dm = &glcoex_dm_8192e_1ant;
25 static struct coex_sta_8192e_1ant glcoex_sta_8192e_1ant;
26 static struct coex_sta_8192e_1ant *coex_sta = &glcoex_sta_8192e_1ant;
28 const char *const glbt_info_src_8192e_1ant[] = {
31 "BT Info[bt auto report]",
34 u32 glcoex_ver_date_8192e_1ant = 20140527;
35 u32 glcoex_ver_8192e_1ant = 0x4f;
37 /* ************************************************************
38 * local function proto type if needed
39 * ************************************************************
40 * ************************************************************
41 * local function start with halbtc8192e1ant_
42 * ************************************************************ */
43 u8 halbtc8192e1ant_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_8192E_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_8192E_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_8192E_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 halbtc8192e1ant_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_8192E_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_8192E_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_8192E_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 halbtc8192e1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
171 IN boolean force_exec, IN u32 dis_rate_mask)
173 coex_dm->cur_ra_mask = dis_rate_mask;
175 if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
176 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
177 &coex_dm->cur_ra_mask);
178 coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
181 void halbtc8192e1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
182 IN boolean force_exec, IN u8 type)
184 boolean wifi_under_b_mode = false;
186 coex_dm->cur_arfr_type = type;
188 if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
189 switch (coex_dm->cur_arfr_type) {
190 case 0: /* normal mode */
191 btcoexist->btc_write_4byte(btcoexist, 0x430,
192 coex_dm->backup_arfr_cnt1);
193 btcoexist->btc_write_4byte(btcoexist, 0x434,
194 coex_dm->backup_arfr_cnt2);
197 btcoexist->btc_get(btcoexist,
198 BTC_GET_BL_WIFI_UNDER_B_MODE,
200 if (wifi_under_b_mode) {
201 btcoexist->btc_write_4byte(btcoexist,
203 btcoexist->btc_write_4byte(btcoexist,
206 btcoexist->btc_write_4byte(btcoexist,
208 btcoexist->btc_write_4byte(btcoexist,
217 coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
220 void halbtc8192e1ant_retry_limit(IN struct btc_coexist *btcoexist,
221 IN boolean force_exec, IN u8 type)
223 coex_dm->cur_retry_limit_type = type;
226 (coex_dm->pre_retry_limit_type !=
227 coex_dm->cur_retry_limit_type)) {
228 switch (coex_dm->cur_retry_limit_type) {
229 case 0: /* normal mode */
230 btcoexist->btc_write_2byte(btcoexist, 0x42a,
231 coex_dm->backup_retry_limit);
233 case 1: /* retry limit=8 */
234 btcoexist->btc_write_2byte(btcoexist, 0x42a,
242 coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
245 void halbtc8192e1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
246 IN boolean force_exec, IN u8 type)
248 coex_dm->cur_ampdu_time_type = type;
251 (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
252 switch (coex_dm->cur_ampdu_time_type) {
253 case 0: /* normal mode */
254 btcoexist->btc_write_1byte(btcoexist, 0x456,
255 coex_dm->backup_ampdu_max_time);
257 case 1: /* AMPDU timw = 0x38 * 32us */
258 btcoexist->btc_write_1byte(btcoexist, 0x456,
266 coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
269 void halbtc8192e1ant_limited_tx(IN struct btc_coexist *btcoexist,
270 IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
271 IN u8 retry_limit_type, IN u8 ampdu_time_type)
273 switch (ra_mask_type) {
274 case 0: /* normal mode */
275 halbtc8192e1ant_update_ra_mask(btcoexist, force_exec,
278 case 1: /* disable cck 1/2 */
279 halbtc8192e1ant_update_ra_mask(btcoexist, force_exec,
282 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
283 halbtc8192e1ant_update_ra_mask(btcoexist, force_exec,
290 halbtc8192e1ant_auto_rate_fallback_retry(btcoexist, force_exec,
292 halbtc8192e1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
293 halbtc8192e1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
296 void halbtc8192e1ant_limited_rx(IN struct btc_coexist *btcoexist,
297 IN boolean force_exec, IN boolean rej_ap_agg_pkt,
298 IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
300 boolean reject_rx_agg = rej_ap_agg_pkt;
301 boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
302 u8 rx_agg_size = agg_buf_size;
304 /* ============================================ */
305 /* Rx Aggregation related setting */
306 /* ============================================ */
307 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
309 /* decide BT control aggregation buf size or not */
310 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
311 &bt_ctrl_rx_agg_size);
312 /* aggregation buf size, only work when BT control Rx aggregation size. */
313 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
314 /* real update aggregation setting */
315 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
320 void halbtc8192e1ant_query_bt_info(IN struct btc_coexist *btcoexist)
322 u8 h2c_parameter[1] = {0};
324 coex_sta->c2h_bt_info_req_sent = true;
326 h2c_parameter[0] |= BIT(0); /* trigger */
328 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
331 void halbtc8192e1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
333 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
334 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
335 static u8 num_of_bt_counter_chk = 0;
337 /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
338 /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */
340 if (coex_sta->under_ips) {
341 coex_sta->high_priority_tx = 65535;
342 coex_sta->high_priority_rx = 65535;
343 coex_sta->low_priority_tx = 65535;
344 coex_sta->low_priority_rx = 65535;
351 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
352 reg_hp_tx = u32tmp & MASKLWORD;
353 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
355 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
356 reg_lp_tx = u32tmp & MASKLWORD;
357 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
359 coex_sta->high_priority_tx = reg_hp_tx;
360 coex_sta->high_priority_rx = reg_hp_rx;
361 coex_sta->low_priority_tx = reg_lp_tx;
362 coex_sta->low_priority_rx = reg_lp_rx;
364 if ((coex_sta->low_priority_tx >= 1050) &&
365 (!coex_sta->c2h_bt_inquiry_page))
366 coex_sta->pop_event_cnt++;
368 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
369 "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
370 reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
371 BTC_TRACE(trace_buf);
374 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
376 if ((reg_hp_tx == 0) && (reg_hp_rx == 0) && (reg_lp_tx == 0) &&
378 num_of_bt_counter_chk++;
379 if (num_of_bt_counter_chk >= 3) {
380 halbtc8192e1ant_query_bt_info(btcoexist);
381 num_of_bt_counter_chk = 0;
387 void halbtc8192e1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
390 boolean wifi_busy = false, wifi_under_b_mode = false;
391 static u8 cck_lock_counter = 0;
393 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
394 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
395 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
398 if (coex_sta->under_ips) {
399 coex_sta->crc_ok_cck = 0;
400 coex_sta->crc_ok_11g = 0;
401 coex_sta->crc_ok_11n = 0;
402 coex_sta->crc_ok_11n_agg = 0;
404 coex_sta->crc_err_cck = 0;
405 coex_sta->crc_err_11g = 0;
406 coex_sta->crc_err_11n = 0;
407 coex_sta->crc_err_11n_agg = 0;
409 coex_sta->crc_ok_cck = btcoexist->btc_read_4byte(btcoexist,
411 coex_sta->crc_ok_11g = btcoexist->btc_read_2byte(btcoexist,
413 coex_sta->crc_ok_11n = btcoexist->btc_read_2byte(btcoexist,
415 coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte(btcoexist,
418 coex_sta->crc_err_cck = btcoexist->btc_read_4byte(btcoexist,
420 coex_sta->crc_err_11g = btcoexist->btc_read_2byte(btcoexist,
422 coex_sta->crc_err_11n = btcoexist->btc_read_2byte(btcoexist,
424 coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte(btcoexist,
430 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x1);
431 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x0);
433 if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
434 if ((coex_dm->bt_status == BT_8192E_1ANT_BT_STATUS_ACL_BUSY) ||
435 (coex_dm->bt_status ==
436 BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
437 (coex_dm->bt_status ==
438 BT_8192E_1ANT_BT_STATUS_SCO_BUSY)) {
439 if (coex_sta->crc_ok_cck > (coex_sta->crc_ok_11g +
440 coex_sta->crc_ok_11n +
441 coex_sta->crc_ok_11n_agg)) {
442 if (cck_lock_counter < 5)
445 if (cck_lock_counter > 0)
450 if (cck_lock_counter > 0)
454 if (cck_lock_counter > 0)
458 if (!coex_sta->pre_ccklock) {
460 if (cck_lock_counter >= 5)
461 coex_sta->cck_lock = true;
463 coex_sta->cck_lock = false;
465 if (cck_lock_counter == 0)
466 coex_sta->cck_lock = false;
468 coex_sta->cck_lock = true;
471 coex_sta->pre_ccklock = coex_sta->cck_lock;
476 boolean halbtc8192e1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
478 static boolean pre_wifi_busy = false, pre_under_4way = false,
479 pre_bt_hs_on = false;
480 boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
481 boolean wifi_connected = false;
483 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
485 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
486 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
487 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
490 if (wifi_connected) {
491 if (wifi_busy != pre_wifi_busy) {
492 pre_wifi_busy = wifi_busy;
495 if (under_4way != pre_under_4way) {
496 pre_under_4way = under_4way;
499 if (bt_hs_on != pre_bt_hs_on) {
500 pre_bt_hs_on = bt_hs_on;
508 void halbtc8192e1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
510 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
511 boolean bt_hs_on = false;
513 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
515 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
516 bt_link_info->sco_exist = coex_sta->sco_exist;
517 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
518 bt_link_info->pan_exist = coex_sta->pan_exist;
519 bt_link_info->hid_exist = coex_sta->hid_exist;
521 /* work around for HS mode. */
523 bt_link_info->pan_exist = true;
524 bt_link_info->bt_link_exist = true;
527 /* check if Sco only */
528 if (bt_link_info->sco_exist &&
529 !bt_link_info->a2dp_exist &&
530 !bt_link_info->pan_exist &&
531 !bt_link_info->hid_exist)
532 bt_link_info->sco_only = true;
534 bt_link_info->sco_only = false;
536 /* check if A2dp only */
537 if (!bt_link_info->sco_exist &&
538 bt_link_info->a2dp_exist &&
539 !bt_link_info->pan_exist &&
540 !bt_link_info->hid_exist)
541 bt_link_info->a2dp_only = true;
543 bt_link_info->a2dp_only = false;
545 /* check if Pan only */
546 if (!bt_link_info->sco_exist &&
547 !bt_link_info->a2dp_exist &&
548 bt_link_info->pan_exist &&
549 !bt_link_info->hid_exist)
550 bt_link_info->pan_only = true;
552 bt_link_info->pan_only = false;
554 /* check if Hid only */
555 if (!bt_link_info->sco_exist &&
556 !bt_link_info->a2dp_exist &&
557 !bt_link_info->pan_exist &&
558 bt_link_info->hid_exist)
559 bt_link_info->hid_only = true;
561 bt_link_info->hid_only = false;
564 u8 halbtc8192e1ant_action_algorithm(IN struct btc_coexist *btcoexist)
566 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
567 boolean bt_hs_on = false;
568 u8 algorithm = BT_8192E_1ANT_COEX_ALGO_UNDEFINED;
569 u8 num_of_diff_profile = 0;
571 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
573 if (!bt_link_info->bt_link_exist) {
574 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
575 "[BTCoex], No BT link exists!!!\n");
576 BTC_TRACE(trace_buf);
580 if (bt_link_info->sco_exist)
581 num_of_diff_profile++;
582 if (bt_link_info->hid_exist)
583 num_of_diff_profile++;
584 if (bt_link_info->pan_exist)
585 num_of_diff_profile++;
586 if (bt_link_info->a2dp_exist)
587 num_of_diff_profile++;
589 if (num_of_diff_profile == 1) {
590 if (bt_link_info->sco_exist) {
591 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
592 "[BTCoex], BT Profile = SCO only\n");
593 BTC_TRACE(trace_buf);
594 algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
596 if (bt_link_info->hid_exist) {
597 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
598 "[BTCoex], BT Profile = HID only\n");
599 BTC_TRACE(trace_buf);
600 algorithm = BT_8192E_1ANT_COEX_ALGO_HID;
601 } else if (bt_link_info->a2dp_exist) {
602 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
603 "[BTCoex], BT Profile = A2DP only\n");
604 BTC_TRACE(trace_buf);
605 algorithm = BT_8192E_1ANT_COEX_ALGO_A2DP;
606 } else if (bt_link_info->pan_exist) {
608 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
609 "[BTCoex], BT Profile = PAN(HS) only\n");
610 BTC_TRACE(trace_buf);
612 BT_8192E_1ANT_COEX_ALGO_PANHS;
614 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
615 "[BTCoex], BT Profile = PAN(EDR) only\n");
616 BTC_TRACE(trace_buf);
618 BT_8192E_1ANT_COEX_ALGO_PANEDR;
622 } else if (num_of_diff_profile == 2) {
623 if (bt_link_info->sco_exist) {
624 if (bt_link_info->hid_exist) {
625 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
626 "[BTCoex], BT Profile = SCO + HID\n");
627 BTC_TRACE(trace_buf);
628 algorithm = BT_8192E_1ANT_COEX_ALGO_HID;
629 } else if (bt_link_info->a2dp_exist) {
630 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
631 "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
632 BTC_TRACE(trace_buf);
633 algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
634 } else if (bt_link_info->pan_exist) {
636 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
637 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
638 BTC_TRACE(trace_buf);
639 algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
641 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
642 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
643 BTC_TRACE(trace_buf);
645 BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
649 if (bt_link_info->hid_exist &&
650 bt_link_info->a2dp_exist) {
651 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
652 "[BTCoex], BT Profile = HID + A2DP\n");
653 BTC_TRACE(trace_buf);
654 algorithm = BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
655 } else if (bt_link_info->hid_exist &&
656 bt_link_info->pan_exist) {
658 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
659 "[BTCoex], BT Profile = HID + PAN(HS)\n");
660 BTC_TRACE(trace_buf);
662 BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
664 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
665 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
666 BTC_TRACE(trace_buf);
668 BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
670 } else if (bt_link_info->pan_exist &&
671 bt_link_info->a2dp_exist) {
673 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
674 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
675 BTC_TRACE(trace_buf);
677 BT_8192E_1ANT_COEX_ALGO_A2DP_PANHS;
679 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
680 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
681 BTC_TRACE(trace_buf);
683 BT_8192E_1ANT_COEX_ALGO_PANEDR_A2DP;
687 } else if (num_of_diff_profile == 3) {
688 if (bt_link_info->sco_exist) {
689 if (bt_link_info->hid_exist &&
690 bt_link_info->a2dp_exist) {
691 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
692 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
693 BTC_TRACE(trace_buf);
694 algorithm = BT_8192E_1ANT_COEX_ALGO_HID;
695 } else if (bt_link_info->hid_exist &&
696 bt_link_info->pan_exist) {
698 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
699 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
700 BTC_TRACE(trace_buf);
702 BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
704 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
705 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
706 BTC_TRACE(trace_buf);
708 BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
710 } else if (bt_link_info->pan_exist &&
711 bt_link_info->a2dp_exist) {
713 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
714 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
715 BTC_TRACE(trace_buf);
716 algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
718 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
719 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
720 BTC_TRACE(trace_buf);
722 BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
726 if (bt_link_info->hid_exist &&
727 bt_link_info->pan_exist &&
728 bt_link_info->a2dp_exist) {
730 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
731 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
732 BTC_TRACE(trace_buf);
734 BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
736 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
737 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
738 BTC_TRACE(trace_buf);
740 BT_8192E_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
744 } else if (num_of_diff_profile >= 3) {
745 if (bt_link_info->sco_exist) {
746 if (bt_link_info->hid_exist &&
747 bt_link_info->pan_exist &&
748 bt_link_info->a2dp_exist) {
750 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
751 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
752 BTC_TRACE(trace_buf);
755 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
756 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
757 BTC_TRACE(trace_buf);
759 BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
768 void halbtc8192e1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
769 IN boolean enable_auto_report)
771 u8 h2c_parameter[1] = {0};
773 h2c_parameter[0] = 0;
775 if (enable_auto_report)
776 h2c_parameter[0] |= BIT(0);
778 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
781 void halbtc8192e1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
782 IN boolean force_exec, IN boolean enable_auto_report)
784 coex_dm->cur_bt_auto_report = enable_auto_report;
787 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
790 halbtc8192e1ant_set_bt_auto_report(btcoexist,
791 coex_dm->cur_bt_auto_report);
793 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
796 void halbtc8192e1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
797 *btcoexist, IN boolean low_penalty_ra)
799 u8 h2c_parameter[6] = {0};
801 h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
803 if (low_penalty_ra) {
804 h2c_parameter[1] |= BIT(0);
806 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
807 h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */
808 h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */
809 h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */
812 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
815 void halbtc8192e1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
816 IN boolean force_exec, IN boolean low_penalty_ra)
818 coex_dm->cur_low_penalty_ra = low_penalty_ra;
821 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
824 halbtc8192e1ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
825 coex_dm->cur_low_penalty_ra);
827 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
830 void halbtc8192e1ant_set_coex_table(IN struct btc_coexist *btcoexist,
831 IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
833 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
835 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
837 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
839 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
842 void halbtc8192e1ant_coex_table(IN struct btc_coexist *btcoexist,
843 IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
844 IN u32 val0x6c8, IN u8 val0x6cc)
846 coex_dm->cur_val0x6c0 = val0x6c0;
847 coex_dm->cur_val0x6c4 = val0x6c4;
848 coex_dm->cur_val0x6c8 = val0x6c8;
849 coex_dm->cur_val0x6cc = val0x6cc;
852 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
853 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
854 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
855 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
858 halbtc8192e1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
861 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
862 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
863 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
864 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
867 void halbtc8192e1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
868 IN boolean force_exec, IN u8 type)
870 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
871 "[BTCoex], ********** CoexTable(%d) **********\n", type);
872 BTC_TRACE(trace_buf);
874 coex_sta->coex_table_type = type;
878 halbtc8192e1ant_coex_table(btcoexist, force_exec,
879 0x55555555, 0x55555555, 0xffffff, 0x3);
882 halbtc8192e1ant_coex_table(btcoexist, force_exec,
883 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
886 halbtc8192e1ant_coex_table(btcoexist, force_exec,
887 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
890 halbtc8192e1ant_coex_table(btcoexist, force_exec,
891 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
894 halbtc8192e1ant_coex_table(btcoexist, force_exec,
895 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
898 halbtc8192e1ant_coex_table(btcoexist, force_exec,
899 0x5a5a5a5a, 0xaa5a5a5a, 0xffffff, 0x3);
902 halbtc8192e1ant_coex_table(btcoexist, force_exec,
903 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);
906 halbtc8192e1ant_coex_table(btcoexist, force_exec,
907 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
914 void halbtc8192e1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
917 u8 h2c_parameter[1] = {0};
920 h2c_parameter[0] |= BIT(0); /* function enable */
923 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
926 void halbtc8192e1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
927 IN boolean force_exec, IN boolean enable)
929 coex_dm->cur_ignore_wlan_act = enable;
932 if (coex_dm->pre_ignore_wlan_act ==
933 coex_dm->cur_ignore_wlan_act)
936 halbtc8192e1ant_set_fw_ignore_wlan_act(btcoexist, enable);
938 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
941 void halbtc8192e1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
942 IN u8 lps_val, IN u8 rpwm_val)
947 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
948 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
951 void halbtc8192e1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
952 IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
954 coex_dm->cur_lps = lps_val;
955 coex_dm->cur_rpwm = rpwm_val;
958 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
959 (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
962 halbtc8192e1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
964 coex_dm->pre_lps = coex_dm->cur_lps;
965 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
968 void halbtc8192e1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
969 IN boolean low_penalty_ra)
971 halbtc8192e1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
974 void halbtc8192e1ant_set_ant_path(IN struct btc_coexist *btcoexist,
975 IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
980 btcoexist->btc_write_1byte(btcoexist, 0x944, 0x24);
981 btcoexist->btc_write_4byte(btcoexist, 0x930, 0x700700);
982 if (btcoexist->chip_interface == BTC_INTF_USB)
983 btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30430004);
985 btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30030004);
987 /* 0x4c[27][24]='00', Set Antenna to BB */
988 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
991 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
992 } else if (wifi_off) {
993 if (btcoexist->chip_interface == BTC_INTF_USB)
994 btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30430004);
996 btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30030004);
998 /* 0x4c[27][24]='11', Set Antenna to BT, 0x64[8:7]=0, 0x64[2]=1 */
999 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
1002 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
1005 /* ext switch setting */
1006 switch (ant_pos_type) {
1007 case BTC_ANT_PATH_WIFI:
1008 btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x4);
1010 case BTC_ANT_PATH_BT:
1011 btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x20);
1014 case BTC_ANT_PATH_PTA:
1015 btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x4);
1020 void halbtc8192e1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
1021 IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
1023 u8 h2c_parameter[5] = {0};
1024 u8 real_byte1 = byte1, real_byte5 = byte5;
1025 boolean ap_enable = false;
1027 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1031 if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1032 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1033 "[BTCoex], FW for 1Ant AP mode\n");
1034 BTC_TRACE(trace_buf);
1035 real_byte1 &= ~BIT(4);
1036 real_byte1 |= BIT(5);
1038 real_byte5 |= BIT(5);
1039 real_byte5 &= ~BIT(6);
1043 h2c_parameter[0] = real_byte1;
1044 h2c_parameter[1] = byte2;
1045 h2c_parameter[2] = byte3;
1046 h2c_parameter[3] = byte4;
1047 h2c_parameter[4] = real_byte5;
1049 coex_dm->ps_tdma_para[0] = real_byte1;
1050 coex_dm->ps_tdma_para[1] = byte2;
1051 coex_dm->ps_tdma_para[2] = byte3;
1052 coex_dm->ps_tdma_para[3] = byte4;
1053 coex_dm->ps_tdma_para[4] = real_byte5;
1055 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1059 void halbtc8192e1ant_ps_tdma(IN struct btc_coexist *btcoexist,
1060 IN boolean force_exec, IN boolean turn_on, IN u8 type)
1062 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1063 boolean wifi_busy = false;
1064 u8 rssi_adjust_val = 0;
1065 u8 ps_tdma_byte4_val = 0x50, ps_tdma_byte0_val = 0x51,
1066 ps_tdma_byte3_val = 0x10;
1067 s8 wifi_duration_adjust = 0x0;
1069 coex_dm->cur_ps_tdma_on = turn_on;
1070 coex_dm->cur_ps_tdma = type;
1072 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1074 if (coex_dm->cur_ps_tdma_on) {
1075 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1076 "[BTCoex], ********** TDMA(on, %d) **********\n",
1077 coex_dm->cur_ps_tdma);
1078 BTC_TRACE(trace_buf);
1080 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1081 "[BTCoex], ********** TDMA(off, %d) **********\n",
1082 coex_dm->cur_ps_tdma);
1083 BTC_TRACE(trace_buf);
1087 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1088 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1092 if (coex_sta->scan_ap_num <= 5)
1093 wifi_duration_adjust = 5;
1094 else if (coex_sta->scan_ap_num >= 40)
1095 wifi_duration_adjust = -15;
1096 else if (coex_sta->scan_ap_num >= 20)
1097 wifi_duration_adjust = -10;
1099 if (!coex_sta->force_lps_on) { /* only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30 */
1100 ps_tdma_byte0_val = 0x61; /* no null-pkt */
1101 ps_tdma_byte3_val = 0x11; /* no tx-pause at BT-slot */
1102 ps_tdma_byte4_val = 0x10; /* 0x778 = d/1 toggle */
1105 if ((type == 3) || (type == 13) || (type == 14))
1106 ps_tdma_byte4_val = ps_tdma_byte4_val &
1107 0xbf; /* no dynamic slot for multi-profile */
1109 if (bt_link_info->slave_role == true)
1110 ps_tdma_byte4_val = ps_tdma_byte4_val |
1111 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1116 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1117 0x1a, 0x1a, 0x0, ps_tdma_byte4_val);
1120 halbtc8192e1ant_set_fw_pstdma(btcoexist,
1121 ps_tdma_byte0_val, 0x3a +
1122 wifi_duration_adjust, 0x03,
1123 ps_tdma_byte3_val, ps_tdma_byte4_val);
1126 halbtc8192e1ant_set_fw_pstdma(btcoexist,
1127 ps_tdma_byte0_val, 0x2d +
1128 wifi_duration_adjust, 0x03,
1129 ps_tdma_byte3_val, ps_tdma_byte4_val);
1132 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1133 0x1d, 0x1d, 0x0, ps_tdma_byte4_val);
1136 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
1137 0x15, 0x3, 0x14, 0x0);
1140 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1141 0x15, 0x3, 0x11, 0x11);
1144 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1145 0x20, 0x3, 0x11, 0x11);
1148 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13,
1149 0xc, 0x5, 0x0, 0x0);
1152 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
1153 0x25, 0x3, 0x10, 0x0);
1156 halbtc8192e1ant_set_fw_pstdma(btcoexist,
1157 ps_tdma_byte0_val, 0x21, 0x3,
1158 ps_tdma_byte3_val, ps_tdma_byte4_val);
1161 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13,
1162 0xa, 0xa, 0x0, 0x40);
1165 halbtc8192e1ant_set_fw_pstdma(btcoexist,
1166 ps_tdma_byte0_val, 0x21, 0x03,
1167 ps_tdma_byte3_val, ps_tdma_byte4_val);
1170 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1171 0x0a, 0x0a, 0x0, 0x50);
1174 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1175 0x12, 0x12, 0x0, ps_tdma_byte4_val);
1178 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1179 0x21, 0x3, 0x10, ps_tdma_byte4_val);
1182 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13,
1183 0xa, 0x3, 0x8, 0x0);
1186 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
1187 0x15, 0x3, 0x10, 0x0);
1190 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
1191 0x25, 0x3, 0x10, 0x0);
1194 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1195 0x3f, 0x03, 0x11, 0x10);
1198 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1199 0x25, 0x03, 0x11, 0x11);
1202 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1203 0x25, 0x03, 0x11, 0x10);
1206 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
1207 0x25, 0x3, 0x31, 0x18);
1210 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
1211 0x15, 0x3, 0x31, 0x18);
1214 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
1215 0xa, 0x3, 0x31, 0x18);
1218 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
1219 0xa, 0x3, 0x31, 0x18);
1222 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
1223 0x25, 0x3, 0x31, 0x98);
1226 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x69,
1227 0x25, 0x3, 0x31, 0x0);
1230 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xab,
1231 0x1a, 0x1a, 0x1, 0x10);
1234 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
1235 0x30, 0x3, 0x10, 0x10);
1238 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xd3,
1239 0x1a, 0x1a, 0, 0x58);
1242 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
1243 0x35, 0x3, 0x11, 0x11);
1246 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xa3,
1247 0x25, 0x3, 0x30, 0x90);
1250 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x53,
1251 0x1a, 0x1a, 0x0, 0x10);
1254 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x63,
1255 0x1a, 0x1a, 0x0, 0x10);
1258 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xd3,
1259 0x12, 0x3, 0x14, 0x50);
1261 case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */
1262 /* here softap mode screen off will cost 70-80mA for phone */
1263 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x23,
1264 0x18, 0x00, 0x10, 0x24);
1269 /* disable PS tdma */
1271 case 8: /* PTA Control */
1272 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x8,
1273 0x0, 0x0, 0x0, 0x0);
1274 halbtc8192e1ant_set_ant_path(btcoexist,
1275 BTC_ANT_PATH_PTA, false, false);
1278 default: /* Software control, Antenna at BT side */
1279 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x0,
1280 0x0, 0x0, 0x0, 0x0);
1281 halbtc8192e1ant_set_ant_path(btcoexist,
1282 BTC_ANT_PATH_BT, false, false);
1284 case 9: /* Software control, Antenna at WiFi side */
1285 halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x0,
1286 0x0, 0x0, 0x0, 0x0);
1287 halbtc8192e1ant_set_ant_path(btcoexist,
1288 BTC_ANT_PATH_WIFI, false, false);
1292 rssi_adjust_val = 0;
1293 btcoexist->btc_set(btcoexist,
1294 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
1297 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1298 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
1299 btcoexist->btc_read_4byte(btcoexist, 0x948),
1300 btcoexist->btc_read_1byte(btcoexist, 0x765),
1301 btcoexist->btc_read_1byte(btcoexist, 0x67));
1302 BTC_TRACE(trace_buf);
1303 /* update pre state */
1304 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1305 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1308 void halbtc8192e1ant_coex_all_off(IN struct btc_coexist *btcoexist)
1311 halbtc8192e1ant_sw_mechanism(btcoexist, false);
1314 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1317 boolean halbtc8192e1ant_is_common_action(IN struct btc_coexist *btcoexist)
1319 boolean common = false, wifi_connected = false, wifi_busy = false;
1321 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1323 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1325 if (!wifi_connected &&
1326 BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1327 coex_dm->bt_status) {
1328 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1329 "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
1330 BTC_TRACE(trace_buf);
1331 /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
1334 } else if (wifi_connected &&
1335 (BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1336 coex_dm->bt_status)) {
1337 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1338 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1339 BTC_TRACE(trace_buf);
1340 /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
1343 } else if (!wifi_connected &&
1344 (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
1345 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1346 "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
1347 BTC_TRACE(trace_buf);
1348 /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
1351 } else if (wifi_connected &&
1352 (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
1353 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1354 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1355 BTC_TRACE(trace_buf);
1356 /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
1359 } else if (!wifi_connected &&
1360 (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE != coex_dm->bt_status)) {
1361 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1362 "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
1363 BTC_TRACE(trace_buf);
1364 /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
1369 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1370 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1371 BTC_TRACE(trace_buf);
1373 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1374 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1375 BTC_TRACE(trace_buf);
1385 void halbtc8192e1ant_tdma_duration_adjust_for_acl(IN struct btc_coexist
1386 *btcoexist, IN u8 wifi_status)
1388 static s32 up, dn, m, n, wait_count;
1389 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1390 u8 retry_count = 0, bt_info_ext;
1391 boolean wifi_busy = false;
1392 /*static boolean pre_wifi_busy = false;*/
1394 if (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifi_status)
1399 if ((BT_8192E_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN ==
1401 (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifi_status) ||
1402 (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT ==
1404 if (coex_dm->cur_ps_tdma != 1 &&
1405 coex_dm->cur_ps_tdma != 2 &&
1406 coex_dm->cur_ps_tdma != 3 &&
1407 coex_dm->cur_ps_tdma != 9) {
1408 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1410 coex_dm->ps_tdma_du_adj_type = 9;
1422 if (!coex_dm->auto_tdma_adjust) {
1423 coex_dm->auto_tdma_adjust = true;
1425 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
1426 coex_dm->ps_tdma_du_adj_type = 2;
1435 /* accquire the BT TRx retry count from BT_Info byte2 */
1436 retry_count = coex_sta->bt_retry_cnt;
1437 bt_info_ext = coex_sta->bt_info_ext;
1439 if ((coex_sta->low_priority_tx) > 1050 ||
1440 (coex_sta->low_priority_rx) > 1250)
1447 0) { /* no retry in the last 2-second duration */
1454 if (up >= n) { /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */
1461 } else if (retry_count <=
1462 3) { /* <=3 retry in the last 2-second duration */
1469 if (dn == 2) { /* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */
1470 if (wait_count <= 2)
1471 m++; /* to avoid loop between the two levels */
1475 if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
1484 } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */
1485 if (wait_count == 1)
1486 m++; /* to avoid loop between the two levels */
1490 if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
1501 if ((BT_INFO_8192E_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
1502 ((coex_dm->cur_ps_tdma == 1) ||
1503 (coex_dm->cur_ps_tdma == 2))) {
1504 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1506 coex_dm->ps_tdma_du_adj_type = 9;
1507 } else if (coex_dm->cur_ps_tdma == 1) {
1508 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1510 coex_dm->ps_tdma_du_adj_type = 2;
1511 } else if (coex_dm->cur_ps_tdma == 2) {
1512 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1514 coex_dm->ps_tdma_du_adj_type = 9;
1515 } else if (coex_dm->cur_ps_tdma == 9) {
1516 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1518 coex_dm->ps_tdma_du_adj_type = 11;
1520 } else if (result == 1) {
1521 if ((BT_INFO_8192E_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
1522 ((coex_dm->cur_ps_tdma == 1) ||
1523 (coex_dm->cur_ps_tdma == 2))) {
1524 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1526 coex_dm->ps_tdma_du_adj_type = 9;
1527 } else if (coex_dm->cur_ps_tdma == 11) {
1528 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1530 coex_dm->ps_tdma_du_adj_type = 9;
1531 } else if (coex_dm->cur_ps_tdma == 9) {
1532 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1534 coex_dm->ps_tdma_du_adj_type = 2;
1535 } else if (coex_dm->cur_ps_tdma == 2) {
1536 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1538 coex_dm->ps_tdma_du_adj_type = 1;
1540 } else { /* no change */
1542 if(wifi_busy != pre_wifi_busy)
1544 pre_wifi_busy = wifi_busy;
1545 halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, true, coex_dm->cur_ps_tdma);
1550 if (coex_dm->cur_ps_tdma != 1 &&
1551 coex_dm->cur_ps_tdma != 2 &&
1552 coex_dm->cur_ps_tdma != 9 &&
1553 coex_dm->cur_ps_tdma != 11) {
1554 /* recover to previous adjust type */
1555 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1556 coex_dm->ps_tdma_du_adj_type);
1561 void halbtc8192e1ant_ps_tdma_check_for_power_save_state(
1562 IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1566 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1568 if (lps_mode) { /* already under LPS state */
1570 /* keep state under LPS, do nothing. */
1572 /* will leave LPS state, turn off psTdma first */
1573 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1576 } else { /* NO PS state */
1578 /* will enter LPS state, turn off psTdma first */
1579 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1582 /* keep state under NO PS state, do nothing. */
1587 void halbtc8192e1ant_power_save_state(IN struct btc_coexist *btcoexist,
1588 IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
1590 boolean low_pwr_disable = false;
1593 case BTC_PS_WIFI_NATIVE:
1594 /* recover to original 32k low power setting */
1595 low_pwr_disable = false;
1596 btcoexist->btc_set(btcoexist,
1597 BTC_SET_ACT_DISABLE_LOW_POWER,
1599 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1601 coex_sta->force_lps_on = false;
1604 halbtc8192e1ant_ps_tdma_check_for_power_save_state(
1606 halbtc8192e1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1608 /* when coex force to enter LPS, do not enter 32k low power. */
1609 low_pwr_disable = true;
1610 btcoexist->btc_set(btcoexist,
1611 BTC_SET_ACT_DISABLE_LOW_POWER,
1613 /* power save must executed before psTdma. */
1614 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1616 coex_sta->force_lps_on = true;
1618 case BTC_PS_LPS_OFF:
1619 halbtc8192e1ant_ps_tdma_check_for_power_save_state(
1621 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1623 coex_sta->force_lps_on = false;
1630 void halbtc8192e1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
1632 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1633 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9);
1636 void halbtc8192e1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
1638 static u32 bt_disable_cnt = 0;
1639 boolean bt_active = true, bt_disabled = false;
1641 /* This function check if bt is disabled */
1643 if (coex_sta->high_priority_tx == 0 &&
1644 coex_sta->high_priority_rx == 0 &&
1645 coex_sta->low_priority_tx == 0 &&
1646 coex_sta->low_priority_rx == 0)
1648 if (coex_sta->high_priority_tx == 0xffff &&
1649 coex_sta->high_priority_rx == 0xffff &&
1650 coex_sta->low_priority_tx == 0xffff &&
1651 coex_sta->low_priority_rx == 0xffff)
1655 bt_disabled = false;
1656 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1658 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1659 "[BTCoex], BT is enabled !!\n");
1660 BTC_TRACE(trace_buf);
1663 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1664 "[BTCoex], bt all counters=0, %d times!!\n",
1666 BTC_TRACE(trace_buf);
1667 if (bt_disable_cnt >= 2) {
1669 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1671 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1672 "[BTCoex], BT is disabled !!\n");
1673 BTC_TRACE(trace_buf);
1674 halbtc8192e1ant_action_wifi_only(btcoexist);
1677 if (coex_sta->bt_disabled != bt_disabled) {
1678 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1679 "[BTCoex], BT is from %s to %s!!\n",
1680 (coex_sta->bt_disabled ? "disabled" : "enabled"),
1681 (bt_disabled ? "disabled" : "enabled"));
1682 BTC_TRACE(trace_buf);
1683 coex_sta->bt_disabled = bt_disabled;
1686 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1688 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1694 /* *********************************************
1696 * Software Coex Mechanism start
1698 * ********************************************* */
1700 /* SCO only or SCO+PAN(HS) */
1703 void halbtc8192e1ant_action_sco(IN struct btc_coexist* btcoexist)
1705 halbtc8192e1ant_sw_mechanism(btcoexist, true);
1709 void halbtc8192e1ant_action_hid(IN struct btc_coexist* btcoexist)
1711 halbtc8192e1ant_sw_mechanism(btcoexist, true);
1715 void halbtc8192e1ant_action_a2dp(IN struct btc_coexist* btcoexist)
1717 halbtc8192e1ant_sw_mechanism(btcoexist, false);
1720 void halbtc8192e1ant_action_a2dp_pan_hs(IN struct btc_coexist* btcoexist)
1722 halbtc8192e1ant_sw_mechanism(btcoexist, false);
1725 void halbtc8192e1ant_action_pan_edr(IN struct btc_coexist* btcoexist)
1727 halbtc8192e1ant_sw_mechanism(btcoexist, false);
1731 void halbtc8192e1ant_action_pan_hs(IN struct btc_coexist* btcoexist)
1733 halbtc8192e1ant_sw_mechanism(btcoexist, false);
1737 void halbtc8192e1ant_action_pan_edr_a2dp(IN struct btc_coexist* btcoexist)
1739 halbtc8192e1ant_sw_mechanism(btcoexist, false);
1742 void halbtc8192e1ant_action_pan_edr_hid(IN struct btc_coexist* btcoexist)
1744 halbtc8192e1ant_sw_mechanism(btcoexist, true);
1748 void halbtc8192e1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist* btcoexist)
1750 halbtc8192e1ant_sw_mechanism(btcoexist, true);
1753 void halbtc8192e1ant_action_hid_a2dp(IN struct btc_coexist* btcoexist)
1755 halbtc8192e1ant_sw_mechanism(btcoexist, true);
1760 /* *********************************************
1762 * Non-Software Coex Mechanism start
1764 * ********************************************* */
1765 void halbtc8192e1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
1767 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1770 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1771 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1774 void halbtc8192e1ant_action_hs(IN struct btc_coexist *btcoexist)
1776 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1777 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1780 void halbtc8192e1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
1782 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1783 boolean wifi_connected = false, ap_enable = false, wifi_busy = false,
1786 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1788 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1790 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1791 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
1793 if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) {
1794 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1796 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1798 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1799 } else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1800 (bt_link_info->a2dp_exist)) {
1801 /* SCO/HID/A2DP busy */
1802 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1804 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1806 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1807 } else if ((bt_link_info->pan_exist) || (wifi_busy)) {
1808 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1810 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1812 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1814 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1816 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1818 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1822 void halbtc8192e1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
1823 *btcoexist, IN u8 wifi_status)
1825 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1826 boolean wifi_connected = false;
1828 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1831 /* tdma and coex table */
1833 if (bt_link_info->sco_exist) {
1834 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1835 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
1837 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
1838 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
1842 void halbtc8192e1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
1843 *btcoexist, IN u8 wifi_status)
1847 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1848 bt_rssi_state = halbtc8192e1ant_bt_rssi_state(2, 28, 0);
1850 if ((coex_sta->low_priority_rx >= 1000) &&
1851 (coex_sta->low_priority_rx != 65535))
1852 bt_link_info->slave_role = true;
1854 bt_link_info->slave_role = false;
1856 if (bt_link_info->hid_only) { /* HID */
1857 halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
1859 coex_dm->auto_tdma_adjust = false;
1861 } else if (bt_link_info->a2dp_only) { /* A2DP */
1862 if (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
1863 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1865 halbtc8192e1ant_coex_table_with_type(btcoexist,
1867 coex_dm->auto_tdma_adjust = false;
1869 halbtc8192e1ant_tdma_duration_adjust_for_acl(btcoexist,
1872 if (coex_sta->cck_lock)
1873 halbtc8192e1ant_coex_table_with_type(btcoexist,
1877 halbtc8192e1ant_coex_table_with_type(btcoexist,
1879 coex_dm->auto_tdma_adjust = true;
1881 } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
1882 (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
1883 bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
1884 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
1885 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1886 coex_dm->auto_tdma_adjust = false;
1887 } else if (bt_link_info->hid_exist &&
1888 bt_link_info->a2dp_exist) { /* HID+A2DP */
1889 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
1890 coex_dm->auto_tdma_adjust = false;
1892 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
1893 } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
1894 bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
1895 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1896 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1897 coex_dm->auto_tdma_adjust = false;
1899 /* BT no-profile busy (0x9) */
1900 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1901 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1902 coex_dm->auto_tdma_adjust = false;
1906 void halbtc8192e1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
1908 /* power save state */
1909 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1912 /* tdma and coex table */
1913 halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
1914 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1917 void halbtc8192e1ant_action_wifi_not_connected_scan(IN struct btc_coexist
1920 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1922 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1925 /* tdma and coex table */
1926 if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1927 if (bt_link_info->a2dp_exist) {
1928 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1930 halbtc8192e1ant_coex_table_with_type(btcoexist,
1932 } else if (bt_link_info->a2dp_exist &&
1933 bt_link_info->pan_exist) {
1934 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1936 halbtc8192e1ant_coex_table_with_type(btcoexist,
1939 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1941 halbtc8192e1ant_coex_table_with_type(btcoexist,
1944 } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1945 (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1946 coex_dm->bt_status)) {
1947 halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
1948 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1951 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1952 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1956 void halbtc8192e1ant_action_wifi_not_connected_asso_auth(
1957 IN struct btc_coexist *btcoexist)
1959 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1961 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1964 /* tdma and coex table */
1965 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1966 (bt_link_info->a2dp_exist)) {
1967 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1968 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1969 } else if (bt_link_info->pan_exist) {
1970 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1971 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1973 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1974 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1978 void halbtc8192e1ant_action_wifi_connected_scan(IN struct btc_coexist
1981 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1983 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1986 /* tdma and coex table */
1987 if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1988 if (bt_link_info->a2dp_exist) {
1989 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1991 halbtc8192e1ant_coex_table_with_type(btcoexist,
1993 } else if (bt_link_info->a2dp_exist &&
1994 bt_link_info->pan_exist) {
1995 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1997 halbtc8192e1ant_coex_table_with_type(btcoexist,
2000 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2002 halbtc8192e1ant_coex_table_with_type(btcoexist,
2005 } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2006 (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
2007 coex_dm->bt_status)) {
2008 halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
2009 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN);
2012 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2013 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2017 void halbtc8192e1ant_action_wifi_connected_specific_packet(
2018 IN struct btc_coexist *btcoexist)
2020 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2022 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
2025 /* tdma and coex table */
2026 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
2027 (bt_link_info->a2dp_exist)) {
2028 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
2029 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2030 } else if (bt_link_info->pan_exist) {
2031 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
2032 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2034 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2035 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2039 void halbtc8192e1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
2041 boolean wifi_busy = false;
2042 boolean scan = false, link = false, roam = false;
2043 boolean under_4way = false, ap_enable = false;
2045 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2046 "[BTCoex], CoexForWifiConnect()===>\n");
2047 BTC_TRACE(trace_buf);
2049 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
2052 halbtc8192e1ant_action_wifi_connected_specific_packet(btcoexist);
2053 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2054 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
2055 BTC_TRACE(trace_buf);
2059 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2060 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2061 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2062 if (scan || link || roam) {
2064 halbtc8192e1ant_action_wifi_connected_scan(btcoexist);
2066 halbtc8192e1ant_action_wifi_connected_specific_packet(
2068 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2069 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
2070 BTC_TRACE(trace_buf);
2074 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
2076 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2078 /* power save state */
2080 BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status &&
2081 !btcoexist->bt_link_info.hid_only) {
2082 if (btcoexist->bt_link_info.a2dp_only) { /* A2DP */
2084 halbtc8192e1ant_power_save_state(btcoexist,
2085 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2087 if (coex_sta->scan_ap_num >=
2088 BT_8192E_1ANT_WIFI_NOISY_THRESH) /* no force LPS, no PS-TDMA, use pure TDMA */
2089 halbtc8192e1ant_power_save_state(
2090 btcoexist, BTC_PS_WIFI_NATIVE,
2093 halbtc8192e1ant_power_save_state(
2094 btcoexist, BTC_PS_LPS_ON, 0x50,
2097 } else if ((coex_sta->pan_exist == false) &&
2098 (coex_sta->a2dp_exist == false) &&
2099 (coex_sta->hid_exist == false))
2100 halbtc8192e1ant_power_save_state(btcoexist,
2101 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2103 halbtc8192e1ant_power_save_state(btcoexist,
2104 BTC_PS_LPS_ON, 0x50, 0x4);
2106 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2109 /* tdma and coex table */
2111 if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
2112 halbtc8192e1ant_action_wifi_connected_bt_acl_busy(
2114 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2115 } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY ==
2116 coex_dm->bt_status) ||
2117 (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
2118 coex_dm->bt_status)) {
2119 halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
2120 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2122 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
2125 if ((coex_sta->high_priority_tx) +
2126 (coex_sta->high_priority_rx) <= 60)
2127 halbtc8192e1ant_coex_table_with_type(btcoexist,
2130 halbtc8192e1ant_coex_table_with_type(btcoexist,
2134 if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
2135 halbtc8192e1ant_action_wifi_connected_bt_acl_busy(
2137 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2138 } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY ==
2139 coex_dm->bt_status) ||
2140 (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
2141 coex_dm->bt_status)) {
2142 halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
2143 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2145 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
2148 if ((coex_sta->high_priority_tx) +
2149 (coex_sta->high_priority_rx) <= 60)
2150 halbtc8192e1ant_coex_table_with_type(btcoexist,
2153 halbtc8192e1ant_coex_table_with_type(btcoexist,
2159 void halbtc8192e1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
2163 algorithm = halbtc8192e1ant_action_algorithm(btcoexist);
2164 coex_dm->cur_algorithm = algorithm;
2166 if (halbtc8192e1ant_is_common_action(btcoexist)) {
2169 switch (coex_dm->cur_algorithm) {
2170 case BT_8192E_1ANT_COEX_ALGO_SCO:
2171 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2172 "[BTCoex], Action algorithm = SCO.\n");
2173 BTC_TRACE(trace_buf);
2174 /* halbtc8192e1ant_action_sco(btcoexist); */
2176 case BT_8192E_1ANT_COEX_ALGO_HID:
2177 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2178 "[BTCoex], Action algorithm = HID.\n");
2179 BTC_TRACE(trace_buf);
2180 /* halbtc8192e1ant_action_hid(btcoexist); */
2182 case BT_8192E_1ANT_COEX_ALGO_A2DP:
2183 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2184 "[BTCoex], Action algorithm = A2DP.\n");
2185 BTC_TRACE(trace_buf);
2186 /* halbtc8192e1ant_action_a2dp(btcoexist); */
2188 case BT_8192E_1ANT_COEX_ALGO_A2DP_PANHS:
2189 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2190 "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
2191 BTC_TRACE(trace_buf);
2192 /* halbtc8192e1ant_action_a2dp_pan_hs(btcoexist); */
2194 case BT_8192E_1ANT_COEX_ALGO_PANEDR:
2195 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2196 "[BTCoex], Action algorithm = PAN(EDR).\n");
2197 BTC_TRACE(trace_buf);
2198 /* halbtc8192e1ant_action_pan_edr(btcoexist); */
2200 case BT_8192E_1ANT_COEX_ALGO_PANHS:
2201 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2202 "[BTCoex], Action algorithm = HS mode.\n");
2203 BTC_TRACE(trace_buf);
2204 /* halbtc8192e1ant_action_pan_hs(btcoexist); */
2206 case BT_8192E_1ANT_COEX_ALGO_PANEDR_A2DP:
2207 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2208 "[BTCoex], Action algorithm = PAN+A2DP.\n");
2209 BTC_TRACE(trace_buf);
2210 /* halbtc8192e1ant_action_pan_edr_a2dp(btcoexist); */
2212 case BT_8192E_1ANT_COEX_ALGO_PANEDR_HID:
2213 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2214 "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
2215 BTC_TRACE(trace_buf);
2216 /* halbtc8192e1ant_action_pan_edr_hid(btcoexist); */
2218 case BT_8192E_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
2219 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2220 "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
2221 BTC_TRACE(trace_buf);
2222 /* halbtc8192e1ant_action_hid_a2dp_pan_edr(btcoexist); */
2224 case BT_8192E_1ANT_COEX_ALGO_HID_A2DP:
2225 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2226 "[BTCoex], Action algorithm = HID+A2DP.\n");
2227 BTC_TRACE(trace_buf);
2228 /* halbtc8192e1ant_action_hid_a2dp(btcoexist); */
2231 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2232 "[BTCoex], Action algorithm = coexist All Off!!\n");
2233 BTC_TRACE(trace_buf);
2234 /* halbtc8192e1ant_coex_all_off(btcoexist); */
2237 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
2241 void halbtc8192e1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
2243 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2244 boolean wifi_connected = false, bt_hs_on = false;
2245 boolean increase_scan_dev_num = false;
2246 boolean bt_ctrl_agg_buf_size = false;
2247 boolean miracast_plus_bt = false;
2248 u8 agg_buf_size = 5;
2249 u32 wifi_link_status = 0;
2250 u32 num_of_wifi_link = 0;
2252 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2253 "[BTCoex], RunCoexistMechanism()===>\n");
2254 BTC_TRACE(trace_buf);
2256 if (btcoexist->manual_control) {
2257 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2258 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2259 BTC_TRACE(trace_buf);
2263 if (btcoexist->stop_coex_dm) {
2264 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2265 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2266 BTC_TRACE(trace_buf);
2270 if (coex_sta->under_ips) {
2271 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2272 "[BTCoex], wifi is under IPS !!!\n");
2273 BTC_TRACE(trace_buf);
2277 if ((BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
2278 (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2279 (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
2280 increase_scan_dev_num = true;
2282 btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
2283 &increase_scan_dev_num);
2284 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2287 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2289 num_of_wifi_link = wifi_link_status >> 16;
2291 if ((num_of_wifi_link >= 2) ||
2292 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
2293 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2294 "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
2295 num_of_wifi_link, wifi_link_status);
2296 BTC_TRACE(trace_buf);
2298 if (bt_link_info->bt_link_exist) {
2299 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1,
2301 miracast_plus_bt = true;
2303 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
2305 miracast_plus_bt = false;
2307 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
2309 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2310 bt_ctrl_agg_buf_size, agg_buf_size);
2312 if ((bt_link_info->a2dp_exist) &&
2313 (coex_sta->c2h_bt_inquiry_page)) {
2314 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2315 "############# [BTCoex], BT Is Inquirying\n");
2316 BTC_TRACE(trace_buf);
2317 halbtc8192e1ant_action_bt_inquiry(btcoexist);
2319 halbtc8192e1ant_action_wifi_multi_port(btcoexist);
2323 miracast_plus_bt = false;
2324 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
2328 if ((bt_link_info->bt_link_exist) && (wifi_connected)) {
2329 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1);
2331 if (bt_link_info->sco_exist)
2332 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC,
2335 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC,
2338 halbtc8192e1ant_sw_mechanism(btcoexist, true);
2339 halbtc8192e1ant_run_sw_coexist_mechanism(
2340 btcoexist); /* just print debug message */
2342 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2344 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
2347 halbtc8192e1ant_sw_mechanism(btcoexist, false);
2348 halbtc8192e1ant_run_sw_coexist_mechanism(
2349 btcoexist); /* just print debug message */
2352 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2353 if (coex_sta->c2h_bt_inquiry_page) {
2354 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2355 "############# [BTCoex], BT Is Inquirying\n");
2356 BTC_TRACE(trace_buf);
2357 halbtc8192e1ant_action_bt_inquiry(btcoexist);
2359 } else if (bt_hs_on) {
2360 halbtc8192e1ant_action_hs(btcoexist);
2365 if (!wifi_connected) {
2366 boolean scan = false, link = false, roam = false;
2368 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2369 "[BTCoex], wifi is non connected-idle !!!\n");
2370 BTC_TRACE(trace_buf);
2372 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2373 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2374 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2376 if (scan || link || roam) {
2378 halbtc8192e1ant_action_wifi_not_connected_scan(
2381 halbtc8192e1ant_action_wifi_not_connected_asso_auth(
2384 halbtc8192e1ant_action_wifi_not_connected(btcoexist);
2385 } else /* wifi LPS/Busy */
2386 halbtc8192e1ant_action_wifi_connected(btcoexist);
2389 void halbtc8192e1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2391 /* force to reset coex mechanism */
2394 halbtc8192e1ant_sw_mechanism(btcoexist, false);
2396 /* halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
2397 halbtc8192e1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2399 coex_sta->pop_event_cnt = 0;
2402 void halbtc8192e1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2403 IN boolean wifi_only)
2408 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2409 "[BTCoex], 1Ant Init HW Config!!\n");
2410 BTC_TRACE(trace_buf);
2412 /* antenna sw ctrl to bt */
2413 halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, true, false);
2415 halbtc8192e1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2417 /* antenna switch control parameter */
2418 btcoexist->btc_write_4byte(btcoexist, 0x858, 0x55555555);
2420 /* coex parameters */
2421 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
2422 /* 0x790[5:0]=0x5 */
2423 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
2426 btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
2428 /* enable counter statistics */
2429 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
2432 btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20);
2433 /* enable mailbox interface */
2434 u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x40);
2436 btcoexist->btc_write_2byte(btcoexist, 0x40, u16tmp);
2438 /* enable PTA I2C mailbox */
2439 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x101);
2441 btcoexist->btc_write_1byte(btcoexist, 0x101, u8tmp);
2443 /* enable bt clock when wifi is disabled. */
2444 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x93);
2446 btcoexist->btc_write_1byte(btcoexist, 0x93, u8tmp);
2447 /* enable bt clock when suspend. */
2448 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7);
2450 btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp);
2455 void halbtc8192e1ant_wifi_off_hw_cfg(IN struct btc_coexist* btcoexist)
2462 /* ************************************************************
2463 * work around function start with wa_halbtc8192e1ant_
2464 * ************************************************************
2465 * ************************************************************
2466 * extern function start with ex_halbtc8192e1ant_
2467 * ************************************************************ */
2468 void ex_halbtc8192e1ant_power_on_setting(IN struct btc_coexist *btcoexist)
2471 struct btc_board_info *board_info = &btcoexist->board_info;
2475 btcoexist->stop_coex_dm = true;
2477 btcoexist->btc_write_1byte(btcoexist, 0x67, 0x20);
2479 /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
2480 u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
2481 btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
2483 /* set GRAN_BT = 1 */
2484 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18);
2485 /* set WLAN_ACT = 0 */
2486 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
2489 /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
2490 /* Local setting bit define */
2491 /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
2492 /* BIT1: "0" for internal switch; "1" for external switch */
2493 /* BIT2: "0" for one antenna; "1" for two antenna */
2494 /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */
2495 if (btcoexist->chip_interface == BTC_INTF_USB) {
2496 /* fixed at S0 for USB interface */
2497 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0);
2499 u8tmp |= 0x1; /* antenna inverse */
2500 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
2502 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
2504 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
2505 if (board_info->single_ant_path == 0) {
2507 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x280);
2508 board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
2509 } else if (board_info->single_ant_path == 1) {
2511 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0);
2512 u8tmp |= 0x1; /* antenna inverse */
2513 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
2516 if (btcoexist->chip_interface == BTC_INTF_PCI)
2517 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384,
2519 else if (btcoexist->chip_interface == BTC_INTF_SDIO)
2520 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60,
2526 void ex_halbtc8192e1ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
2530 void ex_halbtc8192e1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2531 IN boolean wifi_only)
2533 halbtc8192e1ant_init_hw_config(btcoexist, wifi_only);
2534 btcoexist->stop_coex_dm = false;
2537 void ex_halbtc8192e1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2539 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2540 "[BTCoex], Coex Mechanism Init!!\n");
2541 BTC_TRACE(trace_buf);
2543 btcoexist->stop_coex_dm = false;
2545 halbtc8192e1ant_init_coex_dm(btcoexist);
2547 halbtc8192e1ant_query_bt_info(btcoexist);
2550 void ex_halbtc8192e1ant_display_coex_info(IN struct btc_coexist *btcoexist)
2552 struct btc_board_info *board_info = &btcoexist->board_info;
2553 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2554 u8 *cli_buf = btcoexist->cli_buf;
2555 u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
2557 u32 fw_ver = 0, bt_patch_ver = 0;
2559 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2560 "\r\n ============[BT Coexist info]============");
2563 if (btcoexist->manual_control) {
2564 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2565 "\r\n ============[Under Manual Control]============");
2567 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2568 "\r\n ==========================================");
2571 if (btcoexist->stop_coex_dm) {
2572 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2573 "\r\n ============[Coex is STOPPED]============");
2575 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2576 "\r\n ==========================================");
2580 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
2581 "Ant PG number/ Ant mechanism:",
2582 board_info->pg_ant_num, board_info->btdm_ant_num);
2585 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
2586 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
2587 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2588 "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
2589 "CoexVer/ FwVer/ PatchVer",
2590 glcoex_ver_date_8192e_1ant, glcoex_ver_8192e_1ant, fw_ver,
2591 bt_patch_ver, bt_patch_ver);
2594 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
2595 "Wifi channel informed to BT",
2596 coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
2597 coex_dm->wifi_chnl_info[2]);
2601 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2602 "============[Wifi Status]============");
2604 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
2606 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2607 "============[BT Status]============");
2610 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
2611 "BT [status/ rssi/ retryCnt]",
2612 ((coex_sta->bt_disabled) ? ("disabled") : ((
2613 coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
2614 : ((BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2615 coex_dm->bt_status) ? "non-connected idle" :
2616 ((BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
2617 ? "connected-idle" : "busy")))),
2618 coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
2621 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
2623 bt_link_info->sco_exist, bt_link_info->hid_exist,
2624 bt_link_info->pan_exist, bt_link_info->a2dp_exist);
2626 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
2628 bt_info_ext = coex_sta->bt_info_ext;
2629 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
2630 "BT Info A2DP rate",
2631 (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
2634 for (i = 0; i < BT_INFO_SRC_8192E_1ANT_MAX; i++) {
2635 if (coex_sta->bt_info_c2h_cnt[i]) {
2636 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2637 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
2638 glbt_info_src_8192e_1ant[i],
2639 coex_sta->bt_info_c2h[i][0],
2640 coex_sta->bt_info_c2h[i][1],
2641 coex_sta->bt_info_c2h[i][2],
2642 coex_sta->bt_info_c2h[i][3],
2643 coex_sta->bt_info_c2h[i][4],
2644 coex_sta->bt_info_c2h[i][5],
2645 coex_sta->bt_info_c2h[i][6],
2646 coex_sta->bt_info_c2h_cnt[i]);
2651 if (!btcoexist->manual_control) {
2652 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2653 "============[mechanisms]============");
2656 ps_tdma_case = coex_dm->cur_ps_tdma;
2657 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2658 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
2660 coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
2661 coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
2662 coex_dm->ps_tdma_para[4], ps_tdma_case,
2663 coex_dm->auto_tdma_adjust);
2666 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ",
2667 "Latest error condition(should be 0)",
2668 coex_dm->error_condition);
2671 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ",
2673 coex_dm->cur_ignore_wlan_act);
2678 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2679 "============[Hw setting]============");
2682 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc04);
2683 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xd04);
2684 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x90c);
2685 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2686 "0xc04/ 0xd04/ 0x90c",
2687 u32tmp[0], u32tmp[1], u32tmp[2]);
2690 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
2691 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778",
2695 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x92c);
2696 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x930);
2697 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2699 (u8tmp[0]), u32tmp[0]);
2702 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
2703 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x4f);
2704 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2706 u8tmp[0], u8tmp[1]);
2709 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
2710 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
2711 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2712 "0x550(bcn ctrl)/0x522",
2713 u32tmp[0], u8tmp[0]);
2716 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
2717 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)",
2721 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
2722 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
2723 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
2724 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
2725 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2726 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
2727 "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
2728 u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
2731 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2732 "0x770(hp rx[31:16]/tx[15:0])",
2733 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
2735 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2736 "0x774(lp rx[31:16]/tx[15:0])",
2737 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
2739 #if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 1)
2740 halbtc8192e1ant_monitor_bt_ctr(btcoexist);
2743 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
2746 void ex_halbtc8192e1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2748 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2751 if (BTC_IPS_ENTER == type) {
2752 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2753 "[BTCoex], IPS ENTER notify\n");
2754 BTC_TRACE(trace_buf);
2755 coex_sta->under_ips = true;
2757 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2758 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2759 halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
2761 } else if (BTC_IPS_LEAVE == type) {
2762 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2763 "[BTCoex], IPS LEAVE notify\n");
2764 BTC_TRACE(trace_buf);
2765 coex_sta->under_ips = false;
2767 halbtc8192e1ant_init_hw_config(btcoexist, false);
2768 halbtc8192e1ant_init_coex_dm(btcoexist);
2769 halbtc8192e1ant_query_bt_info(btcoexist);
2773 void ex_halbtc8192e1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2775 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2778 if (BTC_LPS_ENABLE == type) {
2779 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2780 "[BTCoex], LPS ENABLE notify\n");
2781 BTC_TRACE(trace_buf);
2782 coex_sta->under_lps = true;
2783 } else if (BTC_LPS_DISABLE == type) {
2784 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2785 "[BTCoex], LPS DISABLE notify\n");
2786 BTC_TRACE(trace_buf);
2787 coex_sta->under_lps = false;
2791 void ex_halbtc8192e1ant_scan_notify(IN struct btc_coexist *btcoexist,
2794 boolean wifi_connected = false, bt_hs_on = false;
2795 u32 wifi_link_status = 0;
2796 u32 num_of_wifi_link = 0;
2797 boolean bt_ctrl_agg_buf_size = false;
2798 u8 agg_buf_size = 5;
2803 if (btcoexist->manual_control ||
2804 btcoexist->stop_coex_dm)
2807 if (BTC_SCAN_START == type) {
2808 coex_sta->wifi_is_high_pri_task = true;
2809 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2810 "[BTCoex], SCAN START notify\n");
2811 BTC_TRACE(trace_buf);
2813 halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
2814 8); /* Force antenna setup for no scan result issue */
2815 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948);
2816 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
2817 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67);
2820 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2821 "[BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
2822 u32tmp, u8tmpa, u8tmpb);
2823 BTC_TRACE(trace_buf);
2825 coex_sta->wifi_is_high_pri_task = false;
2826 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2827 "[BTCoex], SCAN FINISH notify\n");
2828 BTC_TRACE(trace_buf);
2830 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
2831 &coex_sta->scan_ap_num);
2834 if (coex_sta->bt_disabled)
2837 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2838 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2841 halbtc8192e1ant_query_bt_info(btcoexist);
2843 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2845 num_of_wifi_link = wifi_link_status >> 16;
2846 if (num_of_wifi_link >= 2) {
2847 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2848 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2849 bt_ctrl_agg_buf_size, agg_buf_size);
2850 halbtc8192e1ant_action_wifi_multi_port(btcoexist);
2854 if (coex_sta->c2h_bt_inquiry_page) {
2855 halbtc8192e1ant_action_bt_inquiry(btcoexist);
2857 } else if (bt_hs_on) {
2858 halbtc8192e1ant_action_hs(btcoexist);
2862 if (BTC_SCAN_START == type) {
2863 if (!wifi_connected) /* non-connected scan */
2864 halbtc8192e1ant_action_wifi_not_connected_scan(
2866 else /* wifi is connected */
2867 halbtc8192e1ant_action_wifi_connected_scan(btcoexist);
2868 } else if (BTC_SCAN_FINISH == type) {
2869 if (!wifi_connected) /* non-connected scan */
2870 halbtc8192e1ant_action_wifi_not_connected(btcoexist);
2872 halbtc8192e1ant_action_wifi_connected(btcoexist);
2876 void ex_halbtc8192e1ant_connect_notify(IN struct btc_coexist *btcoexist,
2879 boolean wifi_connected = false, bt_hs_on = false;
2880 u32 wifi_link_status = 0;
2881 u32 num_of_wifi_link = 0;
2882 boolean bt_ctrl_agg_buf_size = false;
2883 u8 agg_buf_size = 5;
2885 if (btcoexist->manual_control ||
2886 btcoexist->stop_coex_dm ||
2887 coex_sta->bt_disabled)
2890 if (BTC_ASSOCIATE_START == type) {
2891 coex_sta->wifi_is_high_pri_task = true;
2892 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2893 "[BTCoex], CONNECT START notify\n");
2894 BTC_TRACE(trace_buf);
2895 coex_dm->arp_cnt = 0;
2897 coex_sta->wifi_is_high_pri_task = false;
2898 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2899 "[BTCoex], CONNECT FINISH notify\n");
2900 BTC_TRACE(trace_buf);
2901 /* coex_dm->arp_cnt = 0; */
2904 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2906 num_of_wifi_link = wifi_link_status >> 16;
2907 if (num_of_wifi_link >= 2) {
2908 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2909 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2910 bt_ctrl_agg_buf_size, agg_buf_size);
2911 halbtc8192e1ant_action_wifi_multi_port(btcoexist);
2915 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2916 if (coex_sta->c2h_bt_inquiry_page) {
2917 halbtc8192e1ant_action_bt_inquiry(btcoexist);
2919 } else if (bt_hs_on) {
2920 halbtc8192e1ant_action_hs(btcoexist);
2924 if (BTC_ASSOCIATE_START == type)
2925 halbtc8192e1ant_action_wifi_not_connected_asso_auth(btcoexist);
2926 else if (BTC_ASSOCIATE_FINISH == type) {
2927 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2929 if (!wifi_connected) /* non-connected scan */
2930 halbtc8192e1ant_action_wifi_not_connected(btcoexist);
2932 halbtc8192e1ant_action_wifi_connected(btcoexist);
2936 void ex_halbtc8192e1ant_media_status_notify(IN struct btc_coexist *btcoexist,
2939 u8 h2c_parameter[3] = {0};
2941 u8 wifi_central_chnl;
2942 boolean wifi_under_b_mode = false;
2944 if (btcoexist->manual_control ||
2945 btcoexist->stop_coex_dm ||
2946 coex_sta->bt_disabled)
2949 if (BTC_MEDIA_CONNECT == type) {
2950 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2951 "[BTCoex], MEDIA connect notify\n");
2952 BTC_TRACE(trace_buf);
2954 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
2955 &wifi_under_b_mode);
2957 /* Set CCK Tx/Rx high Pri except 11b mode */
2958 if (wifi_under_b_mode) {
2959 btcoexist->btc_write_1byte(btcoexist, 0x6cd,
2961 btcoexist->btc_write_1byte(btcoexist, 0x6cf,
2964 btcoexist->btc_write_1byte(btcoexist, 0x6cd,
2966 btcoexist->btc_write_1byte(btcoexist, 0x6cf,
2970 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
2972 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
2974 coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
2976 coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
2979 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2980 "[BTCoex], MEDIA disconnect notify\n");
2981 BTC_TRACE(trace_buf);
2982 coex_dm->arp_cnt = 0;
2984 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
2985 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
2988 /* only 2.4G we need to inform bt the chnl mask */
2989 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
2990 &wifi_central_chnl);
2991 if ((BTC_MEDIA_CONNECT == type) &&
2992 (wifi_central_chnl <= 14)) {
2993 /* h2c_parameter[0] = 0x1; */
2994 h2c_parameter[0] = 0x0;
2995 h2c_parameter[1] = wifi_central_chnl;
2996 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2997 if (BTC_WIFI_BW_HT40 == wifi_bw)
2998 h2c_parameter[2] = 0x30;
3000 h2c_parameter[2] = 0x20;
3003 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
3004 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
3005 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
3007 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
3010 void ex_halbtc8192e1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
3013 boolean bt_hs_on = false;
3014 u32 wifi_link_status = 0;
3015 u32 num_of_wifi_link = 0;
3016 boolean bt_ctrl_agg_buf_size = false;
3017 u8 agg_buf_size = 5;
3019 if (btcoexist->manual_control ||
3020 btcoexist->stop_coex_dm ||
3021 coex_sta->bt_disabled)
3024 if (BTC_PACKET_DHCP == type ||
3025 BTC_PACKET_EAPOL == type ||
3026 BTC_PACKET_ARP == type) {
3027 if (BTC_PACKET_ARP == type) {
3028 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3029 "[BTCoex], specific Packet ARP notify\n");
3030 BTC_TRACE(trace_buf);
3033 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3034 "[BTCoex], ARP Packet Count = %d\n",
3036 BTC_TRACE(trace_buf);
3038 if (coex_dm->arp_cnt >=
3039 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */
3040 coex_sta->wifi_is_high_pri_task = false;
3042 coex_sta->wifi_is_high_pri_task = true;
3044 coex_sta->wifi_is_high_pri_task = true;
3045 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3046 "[BTCoex], specific Packet DHCP or EAPOL notify\n");
3047 BTC_TRACE(trace_buf);
3050 coex_sta->wifi_is_high_pri_task = false;
3051 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3052 "[BTCoex], specific Packet [Type = %d] notify\n", type);
3053 BTC_TRACE(trace_buf);
3056 coex_sta->specific_pkt_period_cnt = 0;
3058 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3060 num_of_wifi_link = wifi_link_status >> 16;
3061 if (num_of_wifi_link >= 2) {
3062 halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
3063 halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
3064 bt_ctrl_agg_buf_size, agg_buf_size);
3065 halbtc8192e1ant_action_wifi_multi_port(btcoexist);
3069 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3070 if (coex_sta->c2h_bt_inquiry_page) {
3071 halbtc8192e1ant_action_bt_inquiry(btcoexist);
3073 } else if (bt_hs_on) {
3074 halbtc8192e1ant_action_hs(btcoexist);
3078 if (BTC_PACKET_DHCP == type ||
3079 BTC_PACKET_EAPOL == type ||
3080 ((BTC_PACKET_ARP == type) && (coex_sta->wifi_is_high_pri_task)))
3081 halbtc8192e1ant_action_wifi_connected_specific_packet(btcoexist);
3084 void ex_halbtc8192e1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
3085 IN u8 *tmp_buf, IN u8 length)
3088 u8 i, rsp_source = 0;
3089 boolean wifi_connected = false;
3090 boolean bt_busy = false;
3092 coex_sta->c2h_bt_info_req_sent = false;
3094 rsp_source = tmp_buf[0] & 0xf;
3095 if (rsp_source >= BT_INFO_SRC_8192E_1ANT_MAX)
3096 rsp_source = BT_INFO_SRC_8192E_1ANT_WIFI_FW;
3097 coex_sta->bt_info_c2h_cnt[rsp_source]++;
3099 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3100 "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
3102 BTC_TRACE(trace_buf);
3103 for (i = 0; i < length; i++) {
3104 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
3106 bt_info = tmp_buf[i];
3107 if (i == length - 1) {
3108 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
3110 BTC_TRACE(trace_buf);
3112 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
3114 BTC_TRACE(trace_buf);
3118 if (BT_INFO_SRC_8192E_1ANT_WIFI_FW != rsp_source) {
3119 coex_sta->bt_retry_cnt = /* [3:0] */
3120 coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
3122 if (coex_sta->bt_retry_cnt >= 1)
3123 coex_sta->pop_event_cnt++;
3125 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
3126 coex_sta->c2h_bt_page = true;
3128 coex_sta->c2h_bt_page = false;
3131 coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90;
3132 /* coex_sta->bt_info_c2h[rsp_source][3]*2+10; */
3134 coex_sta->bt_info_ext =
3135 coex_sta->bt_info_c2h[rsp_source][4];
3137 coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
3139 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
3140 &coex_sta->bt_tx_rx_mask);
3141 if (!coex_sta->bt_tx_rx_mask) {
3142 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
3143 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3144 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
3145 BTC_TRACE(trace_buf);
3146 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
3150 /* Here we need to resend some wifi info to BT */
3151 /* because bt is reset and loss of the info. */
3152 if (coex_sta->bt_info_ext & BIT(1)) {
3153 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3154 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
3155 BTC_TRACE(trace_buf);
3156 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3159 ex_halbtc8192e1ant_media_status_notify(
3160 btcoexist, BTC_MEDIA_CONNECT);
3162 ex_halbtc8192e1ant_media_status_notify(
3163 btcoexist, BTC_MEDIA_DISCONNECT);
3166 if (coex_sta->bt_info_ext & BIT(3)) {
3167 if (!btcoexist->manual_control &&
3168 !btcoexist->stop_coex_dm) {
3169 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3170 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
3171 BTC_TRACE(trace_buf);
3172 halbtc8192e1ant_ignore_wlan_act(btcoexist,
3176 /* BT already NOT ignore Wlan active, do nothing here. */
3178 #if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 0)
3179 if ((coex_sta->bt_info_ext & BIT(4))) {
3180 /* BT auto report already enabled, do nothing */
3182 halbtc8192e1ant_bt_auto_report(btcoexist, FORCE_EXEC,
3187 /* check BIT2 first ==> check if bt is under inquiry or page scan */
3188 if (bt_info & BT_INFO_8192E_1ANT_B_INQ_PAGE)
3189 coex_sta->c2h_bt_inquiry_page = true;
3191 coex_sta->c2h_bt_inquiry_page = false;
3193 /* set link exist status */
3194 if (!(bt_info & BT_INFO_8192E_1ANT_B_CONNECTION)) {
3195 coex_sta->bt_link_exist = false;
3196 coex_sta->pan_exist = false;
3197 coex_sta->a2dp_exist = false;
3198 coex_sta->hid_exist = false;
3199 coex_sta->sco_exist = false;
3200 } else { /* connection exists */
3201 coex_sta->bt_link_exist = true;
3202 if (bt_info & BT_INFO_8192E_1ANT_B_FTP)
3203 coex_sta->pan_exist = true;
3205 coex_sta->pan_exist = false;
3206 if (bt_info & BT_INFO_8192E_1ANT_B_A2DP)
3207 coex_sta->a2dp_exist = true;
3209 coex_sta->a2dp_exist = false;
3210 if (bt_info & BT_INFO_8192E_1ANT_B_HID)
3211 coex_sta->hid_exist = true;
3213 coex_sta->hid_exist = false;
3214 if (bt_info & BT_INFO_8192E_1ANT_B_SCO_ESCO)
3215 coex_sta->sco_exist = true;
3217 coex_sta->sco_exist = false;
3220 halbtc8192e1ant_update_bt_link_info(btcoexist);
3223 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
3225 if (!(bt_info & BT_INFO_8192E_1ANT_B_CONNECTION)) {
3226 coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
3227 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3228 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
3229 BTC_TRACE(trace_buf);
3230 } else if (bt_info ==
3231 BT_INFO_8192E_1ANT_B_CONNECTION) { /* connection exists but no busy */
3232 coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE;
3233 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3234 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
3235 BTC_TRACE(trace_buf);
3236 } else if ((bt_info & BT_INFO_8192E_1ANT_B_SCO_ESCO) ||
3237 (bt_info & BT_INFO_8192E_1ANT_B_SCO_BUSY)) {
3238 coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_SCO_BUSY;
3239 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3240 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
3241 BTC_TRACE(trace_buf);
3242 } else if (bt_info & BT_INFO_8192E_1ANT_B_ACL_BUSY) {
3243 if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
3244 coex_dm->auto_tdma_adjust = false;
3245 coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_ACL_BUSY;
3246 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3247 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
3248 BTC_TRACE(trace_buf);
3250 coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_MAX;
3251 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3252 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
3253 BTC_TRACE(trace_buf);
3256 if ((BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
3257 (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3258 (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
3262 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3264 halbtc8192e1ant_run_coexist_mechanism(btcoexist);
3267 void ex_halbtc8192e1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
3271 u8 u8tmpa, u8tmpb, u8tmpc;
3273 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
3274 BTC_TRACE(trace_buf);
3276 if (BTC_RF_ON == type) {
3277 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3278 "[BTCoex], RF is turned ON!!\n");
3279 BTC_TRACE(trace_buf);
3280 btcoexist->stop_coex_dm = false;
3281 } else if (BTC_RF_OFF == type) {
3282 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3283 "[BTCoex], RF is turned OFF!!\n");
3284 BTC_TRACE(trace_buf);
3286 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3288 halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3289 halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
3292 halbtc8192e1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3293 btcoexist->stop_coex_dm = true;
3295 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948);
3296 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
3297 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67);
3298 u8tmpc = btcoexist->btc_read_1byte(btcoexist, 0x76e);
3301 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3302 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x, 0x76e=0x%x\n",
3303 u32tmp, u8tmpa, u8tmpb, u8tmpc);
3304 BTC_TRACE(trace_buf);
3309 void ex_halbtc8192e1ant_halt_notify(IN struct btc_coexist *btcoexist)
3311 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
3312 BTC_TRACE(trace_buf);
3314 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
3316 halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3317 halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true);
3319 halbtc8192e1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3321 ex_halbtc8192e1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3323 btcoexist->stop_coex_dm = true;
3326 void ex_halbtc8192e1ant_pnp_notify(IN struct btc_coexist *btcoexist,
3329 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
3330 BTC_TRACE(trace_buf);
3332 if (BTC_WIFI_PNP_SLEEP == pnp_state) {
3333 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3334 "[BTCoex], Pnp notify to SLEEP\n");
3335 BTC_TRACE(trace_buf);
3337 halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3339 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3340 halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3341 halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
3344 /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */
3345 /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */
3346 /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */
3347 coex_sta->under_ips = false;
3348 coex_sta->under_lps = false;
3349 btcoexist->stop_coex_dm = true;
3350 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
3351 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3352 "[BTCoex], Pnp notify to WAKE UP\n");
3353 BTC_TRACE(trace_buf);
3354 btcoexist->stop_coex_dm = false;
3355 halbtc8192e1ant_init_hw_config(btcoexist, false);
3356 halbtc8192e1ant_init_coex_dm(btcoexist);
3357 halbtc8192e1ant_query_bt_info(btcoexist);
3361 void ex_halbtc8192e1ant_coex_dm_reset(IN struct btc_coexist *btcoexist)
3363 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3364 "[BTCoex], *****************Coex DM Reset*****************\n");
3365 BTC_TRACE(trace_buf);
3367 halbtc8192e1ant_init_hw_config(btcoexist, false);
3368 /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */
3369 /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x2, 0xfffff, 0x0); */
3370 halbtc8192e1ant_init_coex_dm(btcoexist);
3373 void ex_halbtc8192e1ant_periodical(IN struct btc_coexist *btcoexist)
3375 #if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 0)
3376 halbtc8192e1ant_query_bt_info(btcoexist);
3377 halbtc8192e1ant_monitor_bt_enable_disable(btcoexist);
3379 halbtc8192e1ant_monitor_bt_ctr(btcoexist);
3380 halbtc8192e1ant_monitor_wifi_ctr(btcoexist);
3382 if (halbtc8192e1ant_is_wifi_status_changed(btcoexist) ||
3383 coex_dm->auto_tdma_adjust)
3385 halbtc8192e1ant_run_coexist_mechanism(btcoexist);
3387 coex_sta->specific_pkt_period_cnt++;
3392 void ex_halbtc8192e1ant_dbg_control(IN struct btc_coexist *btcoexist,
3393 IN u8 op_code, IN u8 op_len, IN u8 *pdata)
3396 case BTC_DBG_SET_COEX_NORMAL:
3397 btcoexist->manual_control = false;
3398 halbtc8192e1ant_init_coex_dm(btcoexist);
3400 case BTC_DBG_SET_COEX_WIFI_ONLY:
3401 btcoexist->manual_control = true;
3402 halbtc8192e1ant_power_save_state(btcoexist,
3403 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3404 halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
3407 case BTC_DBG_SET_COEX_BT_ONLY:
3415 #endif /* #if (RTL8192E_SUPPORT == 1) */
3417 #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */