1 /* ************************************************************
\r
4 * This file is for RTL8821C Co-exist mechanism
\r
7 * 2012/11/15 Cosa first check in.
\r
9 * ************************************************************ */
\r
11 /* ************************************************************
\r
13 * ************************************************************ */
\r
14 #include "Mp_Precomp.h"
\r
16 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
\r
18 #if (RTL8821C_SUPPORT == 1)
\r
19 /* ************************************************************
\r
20 * Global variables, these are static variables
\r
21 * ************************************************************ */
\r
22 static u8 *trace_buf = &gl_btc_trace_buf[0];
\r
23 static struct coex_dm_8821c_1ant glcoex_dm_8821c_1ant;
\r
24 static struct coex_dm_8821c_1ant *coex_dm = &glcoex_dm_8821c_1ant;
\r
25 static struct coex_sta_8821c_1ant glcoex_sta_8821c_1ant;
\r
26 static struct coex_sta_8821c_1ant *coex_sta = &glcoex_sta_8821c_1ant;
\r
27 static struct psdscan_sta_8821c_1ant gl_psd_scan_8821c_1ant;
\r
28 static struct psdscan_sta_8821c_1ant *psd_scan = &gl_psd_scan_8821c_1ant;
\r
29 static struct rfe_type_8821c_1ant gl_rfe_type_8821c_1ant;
\r
30 static struct rfe_type_8821c_1ant *rfe_type = &gl_rfe_type_8821c_1ant;
\r
33 const char *const glbt_info_src_8821c_1ant[] = {
\r
36 "BT Info[bt auto report]",
\r
39 u32 glcoex_ver_date_8821c_1ant = 20160316;
\r
40 u32 glcoex_ver_8821c_1ant = 0x00;
\r
42 /* ************************************************************
\r
43 * local function proto type if needed
\r
44 * ************************************************************
\r
45 * ************************************************************
\r
46 * local function start with halbtc8821c1ant_
\r
47 * ************************************************************ */
\r
48 u8 halbtc8821c1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
\r
51 u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
\r
53 bt_rssi = coex_sta->bt_rssi;
\r
55 if (level_num == 2) {
\r
56 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
\r
57 (coex_sta->pre_bt_rssi_state ==
\r
58 BTC_RSSI_STATE_STAY_LOW)) {
\r
59 if (bt_rssi >= (rssi_thresh +
\r
60 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
\r
61 bt_rssi_state = BTC_RSSI_STATE_HIGH;
\r
63 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
\r
65 if (bt_rssi < rssi_thresh)
\r
66 bt_rssi_state = BTC_RSSI_STATE_LOW;
\r
68 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
\r
70 } else if (level_num == 3) {
\r
71 if (rssi_thresh > rssi_thresh1) {
\r
72 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
73 "[BTCoex], BT Rssi thresh error!!\n");
\r
74 BTC_TRACE(trace_buf);
\r
75 return coex_sta->pre_bt_rssi_state;
\r
78 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
\r
79 (coex_sta->pre_bt_rssi_state ==
\r
80 BTC_RSSI_STATE_STAY_LOW)) {
\r
81 if (bt_rssi >= (rssi_thresh +
\r
82 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
\r
83 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
\r
85 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
\r
86 } else if ((coex_sta->pre_bt_rssi_state ==
\r
87 BTC_RSSI_STATE_MEDIUM) ||
\r
88 (coex_sta->pre_bt_rssi_state ==
\r
89 BTC_RSSI_STATE_STAY_MEDIUM)) {
\r
90 if (bt_rssi >= (rssi_thresh1 +
\r
91 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
\r
92 bt_rssi_state = BTC_RSSI_STATE_HIGH;
\r
93 else if (bt_rssi < rssi_thresh)
\r
94 bt_rssi_state = BTC_RSSI_STATE_LOW;
\r
96 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
\r
98 if (bt_rssi < rssi_thresh1)
\r
99 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
\r
101 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
\r
105 coex_sta->pre_bt_rssi_state = bt_rssi_state;
\r
107 return bt_rssi_state;
\r
110 u8 halbtc8821c1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
\r
111 IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
\r
114 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
\r
116 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
\r
118 if (level_num == 2) {
\r
119 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
\r
121 (coex_sta->pre_wifi_rssi_state[index] ==
\r
122 BTC_RSSI_STATE_STAY_LOW)) {
\r
123 if (wifi_rssi >= (rssi_thresh +
\r
124 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
\r
125 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
\r
127 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
\r
129 if (wifi_rssi < rssi_thresh)
\r
130 wifi_rssi_state = BTC_RSSI_STATE_LOW;
\r
132 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
\r
134 } else if (level_num == 3) {
\r
135 if (rssi_thresh > rssi_thresh1) {
\r
136 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
137 "[BTCoex], wifi RSSI thresh error!!\n");
\r
138 BTC_TRACE(trace_buf);
\r
139 return coex_sta->pre_wifi_rssi_state[index];
\r
142 if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
\r
144 (coex_sta->pre_wifi_rssi_state[index] ==
\r
145 BTC_RSSI_STATE_STAY_LOW)) {
\r
146 if (wifi_rssi >= (rssi_thresh +
\r
147 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
\r
148 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
\r
150 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
\r
151 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
\r
152 BTC_RSSI_STATE_MEDIUM) ||
\r
153 (coex_sta->pre_wifi_rssi_state[index] ==
\r
154 BTC_RSSI_STATE_STAY_MEDIUM)) {
\r
155 if (wifi_rssi >= (rssi_thresh1 +
\r
156 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
\r
157 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
\r
158 else if (wifi_rssi < rssi_thresh)
\r
159 wifi_rssi_state = BTC_RSSI_STATE_LOW;
\r
161 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
\r
163 if (wifi_rssi < rssi_thresh1)
\r
164 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
\r
166 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
\r
170 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
\r
172 return wifi_rssi_state;
\r
175 void halbtc8821c1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
\r
176 IN boolean force_exec, IN u32 dis_rate_mask)
\r
178 coex_dm->cur_ra_mask = dis_rate_mask;
\r
180 if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
\r
181 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
\r
182 &coex_dm->cur_ra_mask);
\r
183 coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
\r
186 void halbtc8821c1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
\r
187 IN boolean force_exec, IN u8 type)
\r
189 boolean wifi_under_b_mode = false;
\r
191 coex_dm->cur_arfr_type = type;
\r
193 if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
\r
194 switch (coex_dm->cur_arfr_type) {
\r
195 case 0: /* normal mode */
\r
196 btcoexist->btc_write_4byte(btcoexist, 0x430,
\r
197 coex_dm->backup_arfr_cnt1);
\r
198 btcoexist->btc_write_4byte(btcoexist, 0x434,
\r
199 coex_dm->backup_arfr_cnt2);
\r
202 btcoexist->btc_get(btcoexist,
\r
203 BTC_GET_BL_WIFI_UNDER_B_MODE,
\r
204 &wifi_under_b_mode);
\r
205 if (wifi_under_b_mode) {
\r
206 btcoexist->btc_write_4byte(btcoexist,
\r
208 btcoexist->btc_write_4byte(btcoexist,
\r
209 0x434, 0x01010101);
\r
211 btcoexist->btc_write_4byte(btcoexist,
\r
213 btcoexist->btc_write_4byte(btcoexist,
\r
214 0x434, 0x04030201);
\r
222 coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
\r
225 void halbtc8821c1ant_retry_limit(IN struct btc_coexist *btcoexist,
\r
226 IN boolean force_exec, IN u8 type)
\r
228 coex_dm->cur_retry_limit_type = type;
\r
231 (coex_dm->pre_retry_limit_type !=
\r
232 coex_dm->cur_retry_limit_type)) {
\r
233 switch (coex_dm->cur_retry_limit_type) {
\r
234 case 0: /* normal mode */
\r
235 btcoexist->btc_write_2byte(btcoexist, 0x42a,
\r
236 coex_dm->backup_retry_limit);
\r
238 case 1: /* retry limit=8 */
\r
239 btcoexist->btc_write_2byte(btcoexist, 0x42a,
\r
247 coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
\r
250 void halbtc8821c1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
\r
251 IN boolean force_exec, IN u8 type)
\r
253 coex_dm->cur_ampdu_time_type = type;
\r
256 (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
\r
257 switch (coex_dm->cur_ampdu_time_type) {
\r
258 case 0: /* normal mode */
\r
259 btcoexist->btc_write_1byte(btcoexist, 0x456,
\r
260 coex_dm->backup_ampdu_max_time);
\r
262 case 1: /* AMPDU timw = 0x38 * 32us */
\r
263 btcoexist->btc_write_1byte(btcoexist, 0x456,
\r
271 coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
\r
274 void halbtc8821c1ant_limited_tx(IN struct btc_coexist *btcoexist,
\r
275 IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
\r
276 IN u8 retry_limit_type, IN u8 ampdu_time_type)
\r
278 switch (ra_mask_type) {
\r
279 case 0: /* normal mode */
\r
280 halbtc8821c1ant_update_ra_mask(btcoexist, force_exec,
\r
283 case 1: /* disable cck 1/2 */
\r
284 halbtc8821c1ant_update_ra_mask(btcoexist, force_exec,
\r
287 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
\r
288 halbtc8821c1ant_update_ra_mask(btcoexist, force_exec,
\r
295 halbtc8821c1ant_auto_rate_fallback_retry(btcoexist, force_exec,
\r
297 halbtc8821c1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
\r
298 halbtc8821c1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
\r
301 void halbtc8821c1ant_limited_rx(IN struct btc_coexist *btcoexist,
\r
302 IN boolean force_exec, IN boolean rej_ap_agg_pkt,
\r
303 IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
\r
305 boolean reject_rx_agg = rej_ap_agg_pkt;
\r
306 boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
\r
307 u8 rx_agg_size = agg_buf_size;
\r
309 /* ============================================ */
\r
310 /* Rx Aggregation related setting */
\r
311 /* ============================================ */
\r
312 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
\r
314 /* decide BT control aggregation buf size or not */
\r
315 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
\r
316 &bt_ctrl_rx_agg_size);
\r
317 /* aggregation buf size, only work when BT control Rx aggregation size. */
\r
318 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
\r
319 /* real update aggregation setting */
\r
320 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
\r
325 void halbtc8821c1ant_query_bt_info(IN struct btc_coexist *btcoexist)
\r
327 u8 h2c_parameter[1] = {0};
\r
329 coex_sta->c2h_bt_info_req_sent = true;
\r
331 h2c_parameter[0] |= BIT(0); /* trigger */
\r
333 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
\r
335 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
336 "[BTCoex], WL query BT info!!\n");
\r
337 BTC_TRACE(trace_buf);
\r
340 void halbtc8821c1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
\r
342 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
\r
343 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
\r
344 static u8 num_of_bt_counter_chk = 0, cnt_slave = 0;
\r
345 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
347 /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
\r
348 /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */
\r
350 reg_hp_txrx = 0x770;
\r
351 reg_lp_txrx = 0x774;
\r
353 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
\r
354 reg_hp_tx = u32tmp & MASKLWORD;
\r
355 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
\r
357 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
\r
358 reg_lp_tx = u32tmp & MASKLWORD;
\r
359 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
\r
361 coex_sta->high_priority_tx = reg_hp_tx;
\r
362 coex_sta->high_priority_rx = reg_hp_rx;
\r
363 coex_sta->low_priority_tx = reg_lp_tx;
\r
364 coex_sta->low_priority_rx = reg_lp_rx;
\r
366 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
367 "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
\r
368 reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
\r
370 BTC_TRACE(trace_buf);
\r
372 /* reset counter */
\r
373 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
\r
375 if ((coex_sta->low_priority_tx > 1150) &&
\r
376 (!coex_sta->c2h_bt_inquiry_page))
\r
377 coex_sta->pop_event_cnt++;
\r
379 if ((coex_sta->low_priority_rx >= 1150) && (coex_sta->low_priority_rx >= coex_sta->low_priority_tx)
\r
380 && (!coex_sta->under_ips) && (!coex_sta->c2h_bt_inquiry_page) && (coex_sta->bt_link_exist)) {
\r
381 if (cnt_slave >= 3) {
\r
382 bt_link_info->slave_role = true;
\r
387 if (cnt_slave == 0) {
\r
388 bt_link_info->slave_role = false;
\r
395 if ((coex_sta->high_priority_tx == 0) && (coex_sta->high_priority_rx == 0) && (coex_sta->low_priority_tx == 0) &&
\r
396 (coex_sta->low_priority_rx == 0)) {
\r
397 num_of_bt_counter_chk++;
\r
398 if (num_of_bt_counter_chk >= 3) {
\r
399 halbtc8821c1ant_query_bt_info(btcoexist);
\r
400 num_of_bt_counter_chk = 0;
\r
405 /* Add Hi-Pri Tx/Rx counter to avoid false detection */
\r
406 if (((coex_sta->hid_exist) || (coex_sta->sco_exist)) &&
\r
407 (coex_sta->high_priority_tx + coex_sta->high_priority_rx
\r
409 && (!coex_sta->c2h_bt_inquiry_page))
\r
410 coex_sta->bt_hi_pri_link_exist = true;
\r
412 coex_sta->bt_hi_pri_link_exist = false;
\r
414 if ((coex_sta->acl_busy) &&
\r
415 (coex_sta->num_of_profile == 0)) {
\r
416 if (coex_sta->low_priority_tx +
\r
417 coex_sta->low_priority_rx >= 160) {
\r
418 coex_sta->pan_exist = true;
\r
419 coex_sta->num_of_profile++;
\r
420 coex_sta->wrong_profile_notification++;
\r
429 void halbtc8821c1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
\r
432 boolean wifi_busy = false, wifi_under_b_mode = false;
\r
433 static u8 cck_lock_counter = 0;
\r
436 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
\r
437 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
\r
438 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
\r
439 &wifi_under_b_mode);
\r
441 if (coex_sta->under_ips) {
\r
442 coex_sta->crc_ok_cck = 0;
\r
443 coex_sta->crc_ok_11g = 0;
\r
444 coex_sta->crc_ok_11n = 0;
\r
445 coex_sta->crc_ok_11n_agg = 0;
\r
447 coex_sta->crc_err_cck = 0;
\r
448 coex_sta->crc_err_11g = 0;
\r
449 coex_sta->crc_err_11n = 0;
\r
450 coex_sta->crc_err_11n_agg = 0;
\r
452 coex_sta->crc_ok_cck = btcoexist->btc_read_2byte(btcoexist,
\r
454 coex_sta->crc_ok_11g = btcoexist->btc_read_2byte(btcoexist,
\r
456 coex_sta->crc_ok_11n = btcoexist->btc_read_2byte(btcoexist,
\r
458 coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte(btcoexist,
\r
461 coex_sta->crc_err_cck = btcoexist->btc_read_2byte(btcoexist,0xf00) + btcoexist->btc_read_2byte(btcoexist,0xf06);
\r
463 coex_sta->crc_err_11g = btcoexist->btc_read_2byte(btcoexist,
\r
465 coex_sta->crc_err_11n = btcoexist->btc_read_2byte(btcoexist,
\r
467 coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte(btcoexist,
\r
472 /* reset counter */
\r
473 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x1);
\r
474 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x0);
\r
476 if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
\r
477 total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g +
\r
478 coex_sta->crc_ok_11n +
\r
479 coex_sta->crc_ok_11n_agg;
\r
481 if ((coex_dm->bt_status == BT_8821C_1ANT_BT_STATUS_ACL_BUSY) ||
\r
482 (coex_dm->bt_status ==
\r
483 BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
\r
484 (coex_dm->bt_status ==
\r
485 BT_8821C_1ANT_BT_STATUS_SCO_BUSY)) {
\r
486 if (coex_sta->crc_ok_cck > (total_cnt -
\r
487 coex_sta->crc_ok_cck)) {
\r
488 if (cck_lock_counter < 3)
\r
489 cck_lock_counter++;
\r
491 if (cck_lock_counter > 0)
\r
492 cck_lock_counter--;
\r
496 if (cck_lock_counter > 0)
\r
497 cck_lock_counter--;
\r
500 if (cck_lock_counter > 0)
\r
501 cck_lock_counter--;
\r
504 if (!coex_sta->pre_ccklock) {
\r
506 if (cck_lock_counter >= 3)
\r
507 coex_sta->cck_lock = true;
\r
509 coex_sta->cck_lock = false;
\r
511 if (cck_lock_counter == 0)
\r
512 coex_sta->cck_lock = false;
\r
514 coex_sta->cck_lock = true;
\r
517 if (coex_sta->cck_lock)
\r
518 coex_sta->cck_ever_lock = true;
\r
520 coex_sta->pre_ccklock = coex_sta->cck_lock;
\r
525 boolean halbtc8821c1ant_is_wifibt_status_changed(IN struct btc_coexist *btcoexist)
\r
527 static boolean pre_wifi_busy = false, pre_under_4way = false,
\r
528 pre_bt_hs_on = false, pre_bt_off = false;
\r
529 boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
\r
530 boolean wifi_connected = false;
\r
532 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
\r
534 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
\r
535 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
\r
536 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
\r
539 if (coex_sta->bt_disabled != pre_bt_off) {
\r
540 pre_bt_off = coex_sta->bt_disabled;
\r
542 if (coex_sta->bt_disabled)
\r
543 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
544 "[BTCoex], BT is disabled !!\n");
\r
546 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
547 "[BTCoex], BT is enabled !!\n");
\r
549 BTC_TRACE(trace_buf);
\r
551 coex_sta->bt_coex_supported_feature = 0;
\r
552 coex_sta->bt_coex_supported_version = 0;
\r
556 if (wifi_connected) {
\r
557 if (wifi_busy != pre_wifi_busy) {
\r
558 pre_wifi_busy = wifi_busy;
\r
561 if (under_4way != pre_under_4way) {
\r
562 pre_under_4way = under_4way;
\r
565 if (bt_hs_on != pre_bt_hs_on) {
\r
566 pre_bt_hs_on = bt_hs_on;
\r
574 void halbtc8821c1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
\r
576 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
577 boolean bt_hs_on = false;
\r
579 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
\r
581 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
\r
582 bt_link_info->sco_exist = coex_sta->sco_exist;
\r
583 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
\r
584 bt_link_info->pan_exist = coex_sta->pan_exist;
\r
585 bt_link_info->hid_exist = coex_sta->hid_exist;
\r
586 bt_link_info->bt_hi_pri_link_exist = coex_sta->bt_hi_pri_link_exist;
\r
587 bt_link_info->acl_busy = coex_sta->acl_busy;
\r
589 /* work around for HS mode. */
\r
591 bt_link_info->pan_exist = true;
\r
592 bt_link_info->bt_link_exist = true;
\r
595 /* check if Sco only */
\r
596 if (bt_link_info->sco_exist &&
\r
597 !bt_link_info->a2dp_exist &&
\r
598 !bt_link_info->pan_exist &&
\r
599 !bt_link_info->hid_exist)
\r
600 bt_link_info->sco_only = true;
\r
602 bt_link_info->sco_only = false;
\r
604 /* check if A2dp only */
\r
605 if (!bt_link_info->sco_exist &&
\r
606 bt_link_info->a2dp_exist &&
\r
607 !bt_link_info->pan_exist &&
\r
608 !bt_link_info->hid_exist)
\r
609 bt_link_info->a2dp_only = true;
\r
611 bt_link_info->a2dp_only = false;
\r
613 /* check if Pan only */
\r
614 if (!bt_link_info->sco_exist &&
\r
615 !bt_link_info->a2dp_exist &&
\r
616 bt_link_info->pan_exist &&
\r
617 !bt_link_info->hid_exist)
\r
618 bt_link_info->pan_only = true;
\r
620 bt_link_info->pan_only = false;
\r
622 /* check if Hid only */
\r
623 if (!bt_link_info->sco_exist &&
\r
624 !bt_link_info->a2dp_exist &&
\r
625 !bt_link_info->pan_exist &&
\r
626 bt_link_info->hid_exist)
\r
627 bt_link_info->hid_only = true;
\r
629 bt_link_info->hid_only = false;
\r
632 void halbtc8821c1ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist,
\r
635 u8 h2c_parameter[3] = {0};
\r
637 u8 wifi_central_chnl;
\r
639 /* only 2.4G we need to inform bt the chnl mask */
\r
640 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
\r
641 &wifi_central_chnl);
\r
642 if ((BTC_MEDIA_CONNECT == type) &&
\r
643 (wifi_central_chnl <= 14)) {
\r
645 0x1; /* enable BT AFH skip WL channel for 8821c because BT Rx LO interference */
\r
646 /* h2c_parameter[0] = 0x0; */
\r
647 h2c_parameter[1] = wifi_central_chnl;
\r
648 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
\r
649 if (BTC_WIFI_BW_HT40 == wifi_bw)
\r
650 h2c_parameter[2] = 0x30;
\r
652 h2c_parameter[2] = 0x20;
\r
655 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
\r
656 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
\r
657 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
\r
659 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
\r
663 u8 halbtc8821c1ant_action_algorithm(IN struct btc_coexist *btcoexist)
\r
665 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
666 boolean bt_hs_on = false;
\r
667 u8 algorithm = BT_8821C_1ANT_COEX_ALGO_UNDEFINED;
\r
668 u8 num_of_diff_profile = 0;
\r
670 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
\r
672 if (!bt_link_info->bt_link_exist) {
\r
673 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
674 "[BTCoex], No BT link exists!!!\n");
\r
675 BTC_TRACE(trace_buf);
\r
679 if (bt_link_info->sco_exist)
\r
680 num_of_diff_profile++;
\r
681 if (bt_link_info->hid_exist)
\r
682 num_of_diff_profile++;
\r
683 if (bt_link_info->pan_exist)
\r
684 num_of_diff_profile++;
\r
685 if (bt_link_info->a2dp_exist)
\r
686 num_of_diff_profile++;
\r
688 if (num_of_diff_profile == 1) {
\r
689 if (bt_link_info->sco_exist) {
\r
690 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
691 "[BTCoex], BT Profile = SCO only\n");
\r
692 BTC_TRACE(trace_buf);
\r
693 algorithm = BT_8821C_1ANT_COEX_ALGO_SCO;
\r
695 if (bt_link_info->hid_exist) {
\r
696 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
697 "[BTCoex], BT Profile = HID only\n");
\r
698 BTC_TRACE(trace_buf);
\r
699 algorithm = BT_8821C_1ANT_COEX_ALGO_HID;
\r
700 } else if (bt_link_info->a2dp_exist) {
\r
701 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
702 "[BTCoex], BT Profile = A2DP only\n");
\r
703 BTC_TRACE(trace_buf);
\r
704 algorithm = BT_8821C_1ANT_COEX_ALGO_A2DP;
\r
705 } else if (bt_link_info->pan_exist) {
\r
707 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
708 "[BTCoex], BT Profile = PAN(HS) only\n");
\r
709 BTC_TRACE(trace_buf);
\r
711 BT_8821C_1ANT_COEX_ALGO_PANHS;
\r
713 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
714 "[BTCoex], BT Profile = PAN(EDR) only\n");
\r
715 BTC_TRACE(trace_buf);
\r
717 BT_8821C_1ANT_COEX_ALGO_PANEDR;
\r
721 } else if (num_of_diff_profile == 2) {
\r
722 if (bt_link_info->sco_exist) {
\r
723 if (bt_link_info->hid_exist) {
\r
724 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
725 "[BTCoex], BT Profile = SCO + HID\n");
\r
726 BTC_TRACE(trace_buf);
\r
727 algorithm = BT_8821C_1ANT_COEX_ALGO_HID;
\r
728 } else if (bt_link_info->a2dp_exist) {
\r
729 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
730 "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
\r
731 BTC_TRACE(trace_buf);
\r
732 algorithm = BT_8821C_1ANT_COEX_ALGO_SCO;
\r
733 } else if (bt_link_info->pan_exist) {
\r
735 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
736 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
\r
737 BTC_TRACE(trace_buf);
\r
738 algorithm = BT_8821C_1ANT_COEX_ALGO_SCO;
\r
740 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
741 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
\r
742 BTC_TRACE(trace_buf);
\r
744 BT_8821C_1ANT_COEX_ALGO_PANEDR_HID;
\r
748 if (bt_link_info->hid_exist &&
\r
749 bt_link_info->a2dp_exist) {
\r
750 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
751 "[BTCoex], BT Profile = HID + A2DP\n");
\r
752 BTC_TRACE(trace_buf);
\r
753 algorithm = BT_8821C_1ANT_COEX_ALGO_HID_A2DP;
\r
754 } else if (bt_link_info->hid_exist &&
\r
755 bt_link_info->pan_exist) {
\r
757 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
758 "[BTCoex], BT Profile = HID + PAN(HS)\n");
\r
759 BTC_TRACE(trace_buf);
\r
761 BT_8821C_1ANT_COEX_ALGO_HID_A2DP;
\r
763 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
764 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
\r
765 BTC_TRACE(trace_buf);
\r
767 BT_8821C_1ANT_COEX_ALGO_PANEDR_HID;
\r
769 } else if (bt_link_info->pan_exist &&
\r
770 bt_link_info->a2dp_exist) {
\r
772 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
773 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
\r
774 BTC_TRACE(trace_buf);
\r
776 BT_8821C_1ANT_COEX_ALGO_A2DP_PANHS;
\r
778 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
779 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
\r
780 BTC_TRACE(trace_buf);
\r
782 BT_8821C_1ANT_COEX_ALGO_PANEDR_A2DP;
\r
786 } else if (num_of_diff_profile == 3) {
\r
787 if (bt_link_info->sco_exist) {
\r
788 if (bt_link_info->hid_exist &&
\r
789 bt_link_info->a2dp_exist) {
\r
790 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
791 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
\r
792 BTC_TRACE(trace_buf);
\r
793 algorithm = BT_8821C_1ANT_COEX_ALGO_HID;
\r
794 } else if (bt_link_info->hid_exist &&
\r
795 bt_link_info->pan_exist) {
\r
797 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
798 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
\r
799 BTC_TRACE(trace_buf);
\r
801 BT_8821C_1ANT_COEX_ALGO_HID_A2DP;
\r
803 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
804 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
\r
805 BTC_TRACE(trace_buf);
\r
807 BT_8821C_1ANT_COEX_ALGO_PANEDR_HID;
\r
809 } else if (bt_link_info->pan_exist &&
\r
810 bt_link_info->a2dp_exist) {
\r
812 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
813 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
\r
814 BTC_TRACE(trace_buf);
\r
815 algorithm = BT_8821C_1ANT_COEX_ALGO_SCO;
\r
817 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
818 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
\r
819 BTC_TRACE(trace_buf);
\r
821 BT_8821C_1ANT_COEX_ALGO_PANEDR_HID;
\r
825 if (bt_link_info->hid_exist &&
\r
826 bt_link_info->pan_exist &&
\r
827 bt_link_info->a2dp_exist) {
\r
829 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
830 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
\r
831 BTC_TRACE(trace_buf);
\r
833 BT_8821C_1ANT_COEX_ALGO_HID_A2DP;
\r
835 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
836 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
\r
837 BTC_TRACE(trace_buf);
\r
839 BT_8821C_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
\r
843 } else if (num_of_diff_profile >= 3) {
\r
844 if (bt_link_info->sco_exist) {
\r
845 if (bt_link_info->hid_exist &&
\r
846 bt_link_info->pan_exist &&
\r
847 bt_link_info->a2dp_exist) {
\r
849 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
850 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
\r
851 BTC_TRACE(trace_buf);
\r
854 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
855 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
\r
856 BTC_TRACE(trace_buf);
\r
858 BT_8821C_1ANT_COEX_ALGO_PANEDR_HID;
\r
867 void halbtc8821c1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
\r
868 IN boolean enable_auto_report)
\r
870 u8 h2c_parameter[1] = {0};
\r
872 h2c_parameter[0] = 0;
\r
874 if (enable_auto_report)
\r
875 h2c_parameter[0] |= BIT(0);
\r
877 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
\r
880 void halbtc8821c1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
\r
881 IN boolean force_exec, IN boolean enable_auto_report)
\r
883 coex_dm->cur_bt_auto_report = enable_auto_report;
\r
886 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
\r
889 halbtc8821c1ant_set_bt_auto_report(btcoexist,
\r
890 coex_dm->cur_bt_auto_report);
\r
892 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
\r
895 void halbtc8821c1ant_set_fw_low_penalty_ra(IN struct btc_coexist
\r
896 *btcoexist, IN boolean low_penalty_ra)
\r
898 u8 h2c_parameter[6] = {0};
\r
900 h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
\r
902 if (low_penalty_ra) {
\r
903 h2c_parameter[1] |= BIT(0);
\r
905 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
\r
906 h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */
\r
907 h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */
\r
908 h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */
\r
911 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
\r
914 void halbtc8821c1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
\r
915 IN boolean force_exec, IN boolean low_penalty_ra)
\r
917 coex_dm->cur_low_penalty_ra = low_penalty_ra;
\r
920 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
\r
923 halbtc8821c1ant_set_fw_low_penalty_ra(btcoexist,
\r
924 coex_dm->cur_low_penalty_ra);
\r
926 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
\r
929 void halbtc8821c1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
\r
930 IN boolean low_penalty_ra)
\r
932 halbtc8821c1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
\r
935 void halbtc8821c1ant_write_score_board(
\r
936 IN struct btc_coexist *btcoexist,
\r
942 static u16 originalval = 0x8002;
\r
945 originalval = originalval | bitpos;
\r
947 originalval = originalval & (~bitpos);
\r
949 btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval);
\r
952 void halbtc8821c1ant_read_score_board(
\r
953 IN struct btc_coexist *btcoexist,
\r
954 IN u16 *score_board_val
\r
958 *score_board_val = (btcoexist->btc_read_2byte(btcoexist,
\r
962 void halbtc8821c1ant_post_activestate_to_bt(
\r
963 IN struct btc_coexist *btcoexist,
\r
964 IN boolean wifi_active
\r
969 halbtc8821c1ant_write_score_board(btcoexist, (u16) BIT(0), TRUE);
\r
971 halbtc8821c1ant_write_score_board(btcoexist, (u16) BIT(0), FALSE);
\r
975 void halbtc8821c1ant_post_onoffstate_to_bt(
\r
976 IN struct btc_coexist *btcoexist,
\r
982 halbtc8821c1ant_write_score_board(btcoexist, (u16) BIT(1), TRUE);
\r
984 halbtc8821c1ant_write_score_board(btcoexist, (u16) BIT(1), FALSE);
\r
987 void halbtc8821c1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
\r
989 static u32 bt_disable_cnt = 0;
\r
990 boolean bt_active = true, bt_disabled = false;
\r
993 /* This function check if bt is disabled */
\r
995 if (coex_sta->high_priority_tx == 0 &&
\r
996 coex_sta->high_priority_rx == 0 &&
\r
997 coex_sta->low_priority_tx == 0 &&
\r
998 coex_sta->low_priority_rx == 0)
\r
1000 if (coex_sta->high_priority_tx == 0xffff &&
\r
1001 coex_sta->high_priority_rx == 0xffff &&
\r
1002 coex_sta->low_priority_tx == 0xffff &&
\r
1003 coex_sta->low_priority_rx == 0xffff)
\r
1004 bt_active = false;
\r
1009 /* Read BT on/off status from scoreboard[1], enable this only if BT patch support this feature */
\r
1010 halbtc8821c1ant_read_score_board(btcoexist, &u16tmp);
\r
1012 bt_active = u16tmp & BIT(1);
\r
1018 bt_disable_cnt = 0;
\r
1019 bt_disabled = false;
\r
1020 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
\r
1025 if (bt_disable_cnt >= 2) {
\r
1026 bt_disabled = true;
\r
1027 bt_disable_cnt = 2;
\r
1030 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
\r
1035 if (coex_sta->bt_disabled != bt_disabled) {
\r
1036 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
1037 "[BTCoex], BT is from %s to %s!!\n",
\r
1038 (coex_sta->bt_disabled ? "disabled" : "enabled"),
\r
1039 (bt_disabled ? "disabled" : "enabled"));
\r
1040 BTC_TRACE(trace_buf);
\r
1041 coex_sta->bt_disabled = bt_disabled;
\r
1046 void halbtc8821c1ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist,
\r
1049 static u8 bitVal[5] = {0,0,0,0,0};
\r
1050 static boolean state = false;
\r
1052 if (state ==isenable)
\r
1059 /* enable GNT_WL, GNT_BT to GPIO for debug */
\r
1060 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1);
\r
1062 /* store original value */
\r
1063 bitVal[0] = (btcoexist->btc_read_1byte(btcoexist, 0x66) & BIT(4)) >>4; /*0x66[4] */
\r
1064 bitVal[1] = (btcoexist->btc_read_1byte(btcoexist, 0x67) & BIT(0)); /*0x66[8] */
\r
1065 bitVal[2] = (btcoexist->btc_read_1byte(btcoexist, 0x42) & BIT(3)) >> 3; /*0x40[19] */
\r
1066 bitVal[3] = (btcoexist->btc_read_1byte(btcoexist, 0x65) & BIT(7)) >> 7; /*0x64[15] */
\r
1067 bitVal[4] = (btcoexist->btc_read_1byte(btcoexist, 0x72) & BIT(2)) >> 2; /*0x70[18] */
\r
1069 /* switch GPIO Mux */
\r
1070 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4), 0x0); /*0x66[4] = 0 */
\r
1071 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0), 0x0); /*0x66[8] = 0 */
\r
1072 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3), 0x0); /*0x40[19] = 0 */
\r
1073 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7), 0x0); /*0x64[15] = 0 */
\r
1074 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2), 0x0); /*0x70[18] = 0 */
\r
1078 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0);
\r
1080 /* Restore original value */
\r
1081 /* switch GPIO Mux */
\r
1082 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4), bitVal[0]); /*0x66[4] = 0 */
\r
1083 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0), bitVal[1]); /*0x66[8] = 0 */
\r
1084 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3), bitVal[2]); /*0x40[19] = 0 */
\r
1085 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7), bitVal[3]); /*0x64[15] = 0 */
\r
1086 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2), bitVal[4]); /*0x70[18] = 0 */
\r
1091 u32 halbtc8821c1ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist,
\r
1097 /* wait for ready bit before access 0x1700 */
\r
1098 btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr);
\r
1102 } while (((btcoexist->btc_read_1byte(btcoexist,
\r
1103 0x1703)&BIT(5)) == 0) &&
\r
1104 (j < BT_8821C_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
\r
1107 return btcoexist->btc_read_4byte(btcoexist,
\r
1108 0x1708); /* get read data */
\r
1112 void halbtc8821c1ant_ltecoex_indirect_write_reg(IN struct btc_coexist *btcoexist,
\r
1113 IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value)
\r
1115 u32 val, i = 0, j = 0, bitpos = 0;
\r
1118 if (bit_mask == 0x0)
\r
1120 if (bit_mask == 0xffffffff) {
\r
1121 btcoexist->btc_write_4byte(btcoexist, 0x1704,
\r
1122 reg_value); /* put write data */
\r
1124 /* wait for ready bit before access 0x1700 */
\r
1127 } while (((btcoexist->btc_read_1byte(btcoexist,
\r
1128 0x1703)&BIT(5)) == 0) &&
\r
1129 (j < BT_8821C_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
\r
1132 btcoexist->btc_write_4byte(btcoexist, 0x1700,
\r
1133 0xc00F0000 | reg_addr);
\r
1135 for (i = 0; i <= 31; i++) {
\r
1136 if (((bit_mask >> i) & 0x1) == 0x1) {
\r
1142 /* read back register value before write */
\r
1143 val = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
\r
1145 val = (val & (~bit_mask)) | (reg_value << bitpos);
\r
1147 btcoexist->btc_write_4byte(btcoexist, 0x1704,
\r
1148 val); /* put write data */
\r
1150 /* wait for ready bit before access 0x1700 */
\r
1153 } while (((btcoexist->btc_read_1byte(btcoexist,
\r
1154 0x1703)&BIT(5)) == 0) &&
\r
1155 (j < BT_8821C_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
\r
1158 btcoexist->btc_write_4byte(btcoexist, 0x1700,
\r
1159 0xc00F0000 | reg_addr);
\r
1165 void halbtc8821c1ant_ltecoex_enable(IN struct btc_coexist *btcoexist,
\r
1166 IN boolean enable)
\r
1170 val = (enable) ? 1 : 0;
\r
1171 halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80,
\r
1172 val); /* 0x38[7] */
\r
1176 void halbtc8821c1ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist,
\r
1177 IN boolean wifi_control)
\r
1181 val = (wifi_control) ? 1 : 0;
\r
1182 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4,
\r
1183 val); /* 0x70[26] */
\r
1187 void halbtc8821c1ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist,
\r
1188 IN u8 control_block, IN boolean sw_control, IN u8 state)
\r
1190 u32 val = 0, bit_mask;
\r
1192 state = state & 0x1;
\r
1193 val = (sw_control) ? ((state << 1) | 0x1) : 0;
\r
1195 switch (control_block) {
\r
1196 case BT_8821C_1ANT_GNT_BLOCK_RFC_BB:
\r
1198 bit_mask = 0xc000;
\r
1199 halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist,
\r
1200 0x38, bit_mask, val); /* 0x38[15:14] */
\r
1201 bit_mask = 0x0c00;
\r
1202 halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist,
\r
1203 0x38, bit_mask, val); /* 0x38[11:10] */
\r
1205 case BT_8821C_1ANT_GNT_BLOCK_RFC:
\r
1206 bit_mask = 0xc000;
\r
1207 halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist,
\r
1208 0x38, bit_mask, val); /* 0x38[15:14] */
\r
1210 case BT_8821C_1ANT_GNT_BLOCK_BB:
\r
1211 bit_mask = 0x0c00;
\r
1212 halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist,
\r
1213 0x38, bit_mask, val); /* 0x38[11:10] */
\r
1220 void halbtc8821c1ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist,
\r
1221 IN u8 control_block, IN boolean sw_control, IN u8 state)
\r
1223 u32 val = 0, bit_mask;
\r
1225 state = state & 0x1;
\r
1226 val = (sw_control) ? ((state << 1) | 0x1) : 0;
\r
1228 switch (control_block) {
\r
1229 case BT_8821C_1ANT_GNT_BLOCK_RFC_BB:
\r
1231 bit_mask = 0x3000;
\r
1232 halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist,
\r
1233 0x38, bit_mask, val); /* 0x38[13:12] */
\r
1234 bit_mask = 0x0300;
\r
1235 halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist,
\r
1236 0x38, bit_mask, val); /* 0x38[9:8] */
\r
1238 case BT_8821C_1ANT_GNT_BLOCK_RFC:
\r
1239 bit_mask = 0x3000;
\r
1240 halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist,
\r
1241 0x38, bit_mask, val); /* 0x38[13:12] */
\r
1243 case BT_8821C_1ANT_GNT_BLOCK_BB:
\r
1244 bit_mask = 0x0300;
\r
1245 halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist,
\r
1246 0x38, bit_mask, val); /* 0x38[9:8] */
\r
1253 void halbtc8821c1ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist,
\r
1254 IN u8 table_type, IN u16 table_content)
\r
1256 u16 reg_addr = 0x0000;
\r
1258 switch (table_type) {
\r
1259 case BT_8821C_1ANT_CTT_WL_VS_LTE:
\r
1262 case BT_8821C_1ANT_CTT_BT_VS_LTE:
\r
1267 if (reg_addr != 0x0000)
\r
1268 halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr,
\r
1269 0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */
\r
1275 void halbtc8821c1ant_ltecoex_set_break_table(IN struct btc_coexist *btcoexist,
\r
1276 IN u8 table_type, IN u8 table_content)
\r
1278 u16 reg_addr = 0x0000;
\r
1280 switch (table_type) {
\r
1281 case BT_8821C_1ANT_LBTT_WL_BREAK_LTE:
\r
1284 case BT_8821C_1ANT_LBTT_BT_BREAK_LTE:
\r
1287 case BT_8821C_1ANT_LBTT_LTE_BREAK_WL:
\r
1290 case BT_8821C_1ANT_LBTT_LTE_BREAK_BT:
\r
1295 if (reg_addr != 0x0000)
\r
1296 halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr,
\r
1297 0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */
\r
1302 void halbtc8821c1ant_set_coex_table(IN struct btc_coexist *btcoexist,
\r
1303 IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
\r
1305 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
\r
1307 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
\r
1309 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
\r
1311 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
\r
1314 void halbtc8821c1ant_coex_table(IN struct btc_coexist *btcoexist,
\r
1315 IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
\r
1316 IN u32 val0x6c8, IN u8 val0x6cc)
\r
1318 coex_dm->cur_val0x6c0 = val0x6c0;
\r
1319 coex_dm->cur_val0x6c4 = val0x6c4;
\r
1320 coex_dm->cur_val0x6c8 = val0x6c8;
\r
1321 coex_dm->cur_val0x6cc = val0x6cc;
\r
1323 if (!force_exec) {
\r
1324 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
\r
1325 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
\r
1326 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
\r
1327 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
\r
1331 halbtc8821c1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
\r
1334 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
\r
1335 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
\r
1336 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
\r
1337 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
\r
1340 void halbtc8821c1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
\r
1341 IN boolean force_exec, IN u8 type)
\r
1346 coex_sta->coex_table_type = type;
\r
1348 if (coex_sta->concurrent_rx_mode_on == true) {
\r
1349 break_table = 0xf0ffffff; /* set WL hi-pri can break BT */
\r
1351 0xb; /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */
\r
1353 break_table = 0xffffff;
\r
1354 select_table = 0x3;
\r
1359 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1360 0x55555555, 0x55555555, break_table,
\r
1364 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1365 0x55555555, 0x5a5a5a5a, break_table,
\r
1369 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1370 0xaa5a5a5a, 0xaa5a5a5a, break_table,
\r
1374 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1375 0xaa555555, 0xaa5a5a5a, break_table,
\r
1379 halbtc8821c1ant_coex_table(btcoexist,
\r
1380 force_exec, 0xaa555555, 0xaa5a5a5a,
\r
1381 break_table, select_table);
\r
1384 halbtc8821c1ant_coex_table(btcoexist,
\r
1385 force_exec, 0x5a5a5a5a, 0x5a5a5a5a,
\r
1386 break_table, select_table);
\r
1389 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1390 0x55555555, 0xaaaaaaaa, break_table,
\r
1394 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1395 0xaaaaaaaa, 0xaaaaaaaa, break_table,
\r
1399 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1400 0x55dd55dd, 0x5ada5ada, break_table,
\r
1404 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1405 0x55dd55dd, 0x5ada5ada, break_table,
\r
1409 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1410 0x55dd55dd, 0x5ada5ada, break_table,
\r
1414 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1415 0x55dd55dd, 0x5ada5ada, break_table,
\r
1419 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1420 0x55dd55dd, 0x5ada5ada, break_table,
\r
1424 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1425 0x5fff5fff, 0xaaaaaaaa, break_table,
\r
1429 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1430 0x5fff5fff, 0x5ada5ada, break_table,
\r
1434 halbtc8821c1ant_coex_table(btcoexist, force_exec,
\r
1435 0x55dd55dd, 0xaaaaaaaa, break_table,
\r
1443 void halbtc8821c1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
\r
1444 IN boolean enable)
\r
1446 u8 h2c_parameter[1] = {0};
\r
1449 h2c_parameter[0] |= BIT(0); /* function enable */
\r
1452 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
\r
1455 void halbtc8821c1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
\r
1456 IN boolean force_exec, IN boolean enable)
\r
1458 coex_dm->cur_ignore_wlan_act = enable;
\r
1460 if (!force_exec) {
\r
1461 if (coex_dm->pre_ignore_wlan_act ==
\r
1462 coex_dm->cur_ignore_wlan_act)
\r
1465 halbtc8821c1ant_set_fw_ignore_wlan_act(btcoexist, enable);
\r
1467 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
\r
1470 void halbtc8821c1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
\r
1471 IN u8 lps_val, IN u8 rpwm_val)
\r
1474 u8 rpwm = rpwm_val;
\r
1476 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
\r
1477 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
\r
1480 void halbtc8821c1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
\r
1481 IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
\r
1483 coex_dm->cur_lps = lps_val;
\r
1484 coex_dm->cur_rpwm = rpwm_val;
\r
1486 if (!force_exec) {
\r
1487 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
\r
1488 (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
\r
1491 halbtc8821c1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
\r
1493 coex_dm->pre_lps = coex_dm->cur_lps;
\r
1494 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
\r
1497 void halbtc8821c1ant_ps_tdma_check_for_power_save_state(
\r
1498 IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
\r
1500 u8 lps_mode = 0x0;
\r
1501 u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0};
\r
1503 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
\r
1505 if (lps_mode) { /* already under LPS state */
\r
1506 if (new_ps_state) {
\r
1507 /* keep state under LPS, do nothing. */
\r
1509 /* will leave LPS state, turn off psTdma first */
\r
1510 /*halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
\r
1512 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
\r
1514 } else { /* NO PS state */
\r
1515 if (new_ps_state) {
\r
1516 /* will enter LPS state, turn off psTdma first */
\r
1517 /*halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
\r
1519 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
\r
1521 /* keep state under NO PS state, do nothing. */
\r
1526 void halbtc8821c1ant_power_save_state(IN struct btc_coexist *btcoexist,
\r
1527 IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
\r
1529 boolean low_pwr_disable = false;
\r
1531 switch (ps_type) {
\r
1532 case BTC_PS_WIFI_NATIVE:
\r
1533 /* recover to original 32k low power setting */
\r
1534 coex_sta->force_lps_on = false;
\r
1535 low_pwr_disable = false;
\r
1536 btcoexist->btc_set(btcoexist,
\r
1537 BTC_SET_ACT_DISABLE_LOW_POWER,
\r
1538 &low_pwr_disable);
\r
1539 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
\r
1543 case BTC_PS_LPS_ON:
\r
1544 coex_sta->force_lps_on = true;
\r
1545 halbtc8821c1ant_ps_tdma_check_for_power_save_state(
\r
1547 halbtc8821c1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
\r
1548 lps_val, rpwm_val);
\r
1549 /* when coex force to enter LPS, do not enter 32k low power. */
\r
1550 low_pwr_disable = true;
\r
1551 btcoexist->btc_set(btcoexist,
\r
1552 BTC_SET_ACT_DISABLE_LOW_POWER,
\r
1553 &low_pwr_disable);
\r
1554 /* power save must executed before psTdma. */
\r
1555 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
\r
1559 case BTC_PS_LPS_OFF:
\r
1560 coex_sta->force_lps_on = false;
\r
1561 halbtc8821c1ant_ps_tdma_check_for_power_save_state(
\r
1562 btcoexist, false);
\r
1563 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
\r
1573 void halbtc8821c1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
\r
1574 IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
\r
1576 u8 h2c_parameter[5] = {0};
\r
1577 u8 real_byte1 = byte1, real_byte5 = byte5;
\r
1578 boolean ap_enable = false;
\r
1580 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
\r
1584 if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
\r
1585 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
1586 "[BTCoex], FW for 1Ant AP mode\n");
\r
1587 BTC_TRACE(trace_buf);
\r
1588 real_byte1 &= ~BIT(4);
\r
1589 real_byte1 |= BIT(5);
\r
1591 real_byte5 |= BIT(5);
\r
1592 real_byte5 &= ~BIT(6);
\r
1594 halbtc8821c1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
\r
1597 } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
\r
1599 halbtc8821c1ant_power_save_state(
\r
1600 btcoexist, BTC_PS_LPS_ON, 0x50,
\r
1603 halbtc8821c1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
\r
1608 h2c_parameter[0] = real_byte1;
\r
1609 h2c_parameter[1] = byte2;
\r
1610 h2c_parameter[2] = byte3;
\r
1611 h2c_parameter[3] = byte4;
\r
1612 h2c_parameter[4] = real_byte5;
\r
1614 coex_dm->ps_tdma_para[0] = real_byte1;
\r
1615 coex_dm->ps_tdma_para[1] = byte2;
\r
1616 coex_dm->ps_tdma_para[2] = byte3;
\r
1617 coex_dm->ps_tdma_para[3] = byte4;
\r
1618 coex_dm->ps_tdma_para[4] = real_byte5;
\r
1620 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
\r
1624 void halbtc8821c1ant_ps_tdma(IN struct btc_coexist *btcoexist,
\r
1625 IN boolean force_exec, IN boolean turn_on, IN u8 type)
\r
1627 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
1628 struct btc_board_info *board_info = &btcoexist->board_info;
\r
1629 boolean wifi_busy = false;
\r
1630 static u8 psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0;
\r
1631 static boolean pre_wifi_busy = false;
\r
1634 #if BT_8821C_1ANT_ANTDET_ENABLE
\r
1635 #if BT_8821C_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE
\r
1636 if (board_info->btdm_ant_num_by_ant_det == 2) {
\r
1639 100; /* for WiFi RSSI low or BT RSSI low */
\r
1645 coex_dm->cur_ps_tdma_on = turn_on;
\r
1646 coex_dm->cur_ps_tdma = type;
\r
1648 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
\r
1650 if (wifi_busy != pre_wifi_busy) {
\r
1651 force_exec = true;
\r
1652 pre_wifi_busy = wifi_busy;
\r
1655 /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
\r
1656 if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist))
\r
1657 psTdmaByte4Modify = 0x1;
\r
1659 psTdmaByte4Modify = 0x0;
\r
1661 if (pre_psTdmaByte4Modify != psTdmaByte4Modify) {
\r
1663 force_exec = true;
\r
1664 pre_psTdmaByte4Modify = psTdmaByte4Modify;
\r
1667 if (!force_exec) {
\r
1668 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
\r
1669 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
\r
1673 if (coex_dm->cur_ps_tdma_on) {
\r
1674 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
1675 "[BTCoex], ********** TDMA(on, %d) **********\n",
\r
1676 coex_dm->cur_ps_tdma);
\r
1677 BTC_TRACE(trace_buf);
\r
1679 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
1680 "[BTCoex], ********** TDMA(off, %d) **********\n",
\r
1681 coex_dm->cur_ps_tdma);
\r
1682 BTC_TRACE(trace_buf);
\r
1688 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
\r
1689 0x1); /* enable TBTT nterrupt */
\r
1693 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1694 0x61, 0x35, 0x03, 0x11, 0x11);
\r
1698 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1699 0x51, 0x3a, 0x03, 0x10, 0x10);
\r
1702 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1703 0x51, 0x21, 0x03, 0x10, 0x10);
\r
1706 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1707 0x61, 0x15, 0x03, 0x11, 0x11);
\r
1710 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1711 0x61, 0x20, 0x03, 0x11, 0x11);
\r
1714 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1715 0x51, 0x10, 0x03, 0x10, 0x14 | psTdmaByte4Modify);
\r
1718 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1719 0x51, 0x10, 0x03, 0x10, 0x14 | psTdmaByte4Modify);
\r
1722 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1723 0x51, 0x25, 0x03, 0x10, 0x10 | psTdmaByte4Modify);
\r
1726 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1727 0x51, 0x15, 0x03, 0x10, 0x10 | psTdmaByte4Modify);
\r
1730 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1731 0x51, 0x20, 0x03, 0x10, 0x10 | psTdmaByte4Modify);
\r
1734 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1735 0x61, 0x10, 0x03, 0x11, 0x14 | psTdmaByte4Modify);
\r
1738 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1739 0x61, 0x15, 0x03, 0x11, 0x10);
\r
1742 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1743 0x61, 0x30, 0x03, 0x11, 0x10);
\r
1746 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1747 0x61, 0x30, 0x03, 0x11, 0x10);
\r
1750 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1751 0x61, 0x25, 0x03, 0x11, 0x10);
\r
1754 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1755 0x61, 0x35, 0x03, 0x11, 0x11);
\r
1758 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1759 0x61, 0x35, 0x03, 0x11, 0x10);
\r
1762 /* 1-Ant to 2-Ant TDMA case */
\r
1764 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1765 0xd3, 0x3a, 0x03, 0x70, 0x10);
\r
1768 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1769 0xd3, 0x21, 0x03, 0x70, 0x10);
\r
1772 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1773 0xe3, 0x15, 0x03, 0x71, 0x11);
\r
1776 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1777 0xe3, 0x20, 0x03, 0x71, 0x11);
\r
1780 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1781 0xd3, 0x10, 0x03, 0x70, 0x14 | psTdmaByte4Modify);
\r
1784 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1785 0xd3, 0x10, 0x03, 0x70, 0x14 | psTdmaByte4Modify);
\r
1788 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1789 0xd3, 0x25, 0x03, 0x70, 0x10 | psTdmaByte4Modify);
\r
1792 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1793 0xd3, 0x15, 0x03, 0x70, 0x10 | psTdmaByte4Modify);
\r
1796 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1797 0xd3, 0x20, 0x03, 0x70, 0x10 | psTdmaByte4Modify);
\r
1800 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1801 0xe3, 0x10, 0x03, 0x71, 0x14 | psTdmaByte4Modify);
\r
1804 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1805 0xe3, 0x15, 0x03, 0x71, 0x10);
\r
1808 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1809 0xe3, 0x30, 0x03, 0x71, 0x10);
\r
1812 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1813 0xe3, 0x30, 0x03, 0x71, 0x10);
\r
1816 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1817 0xe3, 0x25, 0x03, 0x71, 0x10);
\r
1820 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1821 0xe3, 0x35, 0x03, 0x71, 0x11);
\r
1824 halbtc8821c1ant_set_fw_pstdma(btcoexist,
\r
1825 0xe3, 0x35, 0x03, 0x71, 0x10);
\r
1831 /* disable PS tdma */
\r
1833 case 8: /* PTA Control */
\r
1834 halbtc8821c1ant_set_fw_pstdma(btcoexist, 0x8,
\r
1835 0x0, 0x0, 0x0, 0x0);
\r
1838 default: /* Software control, Antenna at BT side */
\r
1839 halbtc8821c1ant_set_fw_pstdma(btcoexist, 0x0,
\r
1840 0x0, 0x0, 0x0, 0x0);
\r
1842 case 1: /* 2-Ant, 0x778=3, antenna control by antenna diversity */
\r
1843 halbtc8821c1ant_set_fw_pstdma(btcoexist, 0x0,
\r
1844 0x0, 0x0, 0x48, 0x0);
\r
1849 /* update pre state */
\r
1850 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
\r
1851 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
\r
1854 void halbtc8821c1ant_set_int_block(IN struct btc_coexist *btcoexist, IN boolean force_exec, IN u8 pos_type)
\r
1859 coex_dm->cur_int_block_status = pos_type;
\r
1861 if (!force_exec) {
\r
1862 if (coex_dm->pre_int_block_status == coex_dm->cur_int_block_status)
\r
1866 coex_dm->pre_int_block_status = coex_dm->cur_int_block_status;
\r
1868 regval_0xcba = btcoexist->btc_read_1byte(btcoexist, 0xcba);
\r
1872 case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG:
\r
1873 regval_0xcba = regval_0xcba & (~(BIT(2)) ) | BIT(0); /* 0xcb8[16] = 1, 0xcb8[18] = 0, WL_G select BTG */
\r
1875 case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG:
\r
1876 regval_0xcba = regval_0xcba & (~(BIT(2) | BIT(0)) ); /* 0xcb8[16] = 0, 0xcb8[18] = 0, WL_G select WLAG */
\r
1877 regval_0xcba = regval_0xcba | BIT(4) | BIT(5) ; /* 0xcb8[21:20] = 2b'11, WL_G @ WLAG on */
\r
1878 regval_0xcba = regval_0xcba & (~(BIT(7)) ) | BIT(6); /* 0xcb8[23:22] = 2b'01, WL_A @ WLAG off */
\r
1881 case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG:
\r
1882 regval_0xcba = regval_0xcba & (~(BIT(2) | BIT(0)) ); /* 0xcb8[16] = 0, 0xcb8[18] = 0, WL_G select WLAG */
\r
1883 regval_0xcba = regval_0xcba & (~(BIT(5))) | BIT(4); /* 0xcb8[21:20] = 2b'01, WL_G @ WLAG off */
\r
1884 regval_0xcba = regval_0xcba | BIT(6) | BIT(7); /* 0xcb8[23:22] = 2b'11, WL_A @ WLAG on */
\r
1889 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcba, 0xff, regval_0xcba);
\r
1891 u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb8);
\r
1893 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
1894 "[BTCoex], ********** (After Int Block setup) 0xcb8 = 0x%08x **********\n",
\r
1896 BTC_TRACE(trace_buf);
\r
1900 void halbtc8821c1ant_set_ext_band_switch(IN struct btc_coexist *btcoexist, IN boolean force_exec, IN u8 pos_type)
\r
1904 boolean switch_polatiry_inverse = false;
\r
1906 u32 u32tmp1 = 0, u32tmp2 = 0;
\r
1908 if (!rfe_type->ext_band_switch_exist)
\r
1911 coex_dm->cur_ext_band_switch_status = pos_type;
\r
1913 if (!force_exec) {
\r
1914 if (coex_dm->pre_ext_band_switch_status == coex_dm->cur_ext_band_switch_status)
\r
1918 coex_dm->pre_ext_band_switch_status = coex_dm->cur_ext_band_switch_status;
\r
1920 /* swap control polarity if use different switch control polarity*/
\r
1921 switch_polatiry_inverse = (rfe_type->ext_band_switch_ctrl_polarity == 1? ~switch_polatiry_inverse: switch_polatiry_inverse);
\r
1923 /*swap control polarity for WL_A, default polarity 0xcb4[21] = 0 && 0xcb4[23] = 1 is for WL_G */
\r
1924 switch_polatiry_inverse = (pos_type == BT_8821C_1ANT_EXT_BAND_SWITCH_TO_WLA? ~switch_polatiry_inverse: switch_polatiry_inverse);
\r
1926 regval_0xcb6 = btcoexist->btc_read_1byte(btcoexist, 0xcb6);
\r
1928 /* for normal switch polrity, 0xcb4[21] =1 && 0xcb4[23] = 0 for WL_A, vice versa */
\r
1929 regval_0xcb6 = (switch_polatiry_inverse == 1? ( (regval_0xcb6 & (~(BIT(7))) ) | BIT(5)) : ( (regval_0xcb6 & (~(BIT(5))) ) | BIT(7)) );
\r
1931 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb6, 0xff, regval_0xcb6);
\r
1933 u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb0);
\r
1934 u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
\r
1936 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
1937 "[BTCoex], ********** (After Ext Band switch setup) 0xcb0 = 0x%08x, 0xcb4 = 0x%08x**********\n",
\r
1938 u32tmp1, u32tmp2);
\r
1939 BTC_TRACE(trace_buf);
\r
1944 void halbtc8821c1ant_set_ext_ant_switch(IN struct btc_coexist *btcoexist, IN boolean force_exec, IN u8 ctrl_type, IN u8 pos_type)
\r
1946 struct btc_board_info *board_info = &btcoexist->board_info;
\r
1947 boolean switch_polatiry_inverse = false;
\r
1948 u8 regval_0xcb7 = 0, regval_0x64;
\r
1949 u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
\r
1951 if (!rfe_type->ext_ant_switch_exist)
\r
1954 coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type;
\r
1956 if (!force_exec) {
\r
1957 if (coex_dm->pre_ext_ant_switch_status == coex_dm->cur_ext_ant_switch_status)
\r
1961 coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status;
\r
1963 /* swap control polarity if use different switch control polarity*/
\r
1964 /* Normal switch polarity for DPDT, 0xcb4[29:28] = 2b'01 => BTG to Main, WLG to Aux, 0xcb4[29:28] = 2b'10 => BTG to Aux, WLG to Main */
\r
1965 /* Normal switch polarity for SPDT, 0xcb4[29:28] = 2b'01 => Ant to BTG, 0xcb4[29:28] = 2b'10 => Ant to WLG */
\r
1966 switch_polatiry_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1? ~switch_polatiry_inverse: switch_polatiry_inverse);
\r
1968 /* swap control polarity if 1-Ant at Aux */
\r
1969 if ( (rfe_type->ext_ant_switch_type == BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT) && (board_info->single_ant_path == 0) )
\r
1970 switch_polatiry_inverse = ~switch_polatiry_inverse;
\r
1975 case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_BT:
\r
1976 case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_NOCARE:
\r
1979 case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLG:
\r
1980 switch_polatiry_inverse = (rfe_type->wlg_Locate_at_btg == 0? ~switch_polatiry_inverse: switch_polatiry_inverse);
\r
1982 case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLA:
\r
1983 /*switch_polatiry_inverse = (rfe_type->ext_band_switch_exist == 1? ~switch_polatiry_inverse: switch_polatiry_inverse);*/
\r
1991 case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW:
\r
1992 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80, 0x0); /* 0x4c[23] = 0 */
\r
1993 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01, 0x1); /* 0x4c[24] = 1 */
\r
1994 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff, 0x77); /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as cotrol pin */
\r
1996 regval_0xcb7 = (switch_polatiry_inverse == false? 0x1 : 0x2); /* 0xcb4[29:28] = 2b'01 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */
\r
1997 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 0x30, regval_0xcb7);
\r
2000 case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA:
\r
2001 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80, 0x0); /* 0x4c[23] = 0 */
\r
2002 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01, 0x1); /* 0x4c[24] = 1 */
\r
2003 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff, 0x66); /* PTA, DPDT use RFE_ctrl8 and RFE_ctrl9 as cotrol pin */
\r
2005 regval_0xcb7 = (switch_polatiry_inverse == false? 0x2 : 0x1); /* 0xcb4[29:28] = 2b'10 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 @ GNT_BT=1 */
\r
2006 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 0x30, regval_0xcb7);
\r
2009 case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV:
\r
2010 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80, 0x0); /* 0x4c[23] = 0 */
\r
2011 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01, 0x1); /* 0x4c[24] = 1 */
\r
2012 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff, 0x88); /* */
\r
2014 /* no regval_0xcb7 setup required, because antenna switch control value by antenna diversity */
\r
2017 case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC:
\r
2018 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80, 0x1); /* 0x4c[23] = 1 */
\r
2020 regval_0x64 = (switch_polatiry_inverse == false? 0x0 : 0x1); /* 0x64[0] = 1b'0 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */
\r
2021 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, regval_0x64);
\r
2023 case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT:
\r
2024 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80, 0x0); /* 0x4c[23] = 0 */
\r
2025 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01, 0x0); /* 0x4c[24] = 0 */
\r
2027 /* no setup required, because antenna switch control value by BT vendor 0xac[1:0] */
\r
2031 u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
\r
2032 u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c);
\r
2033 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff;
\r
2035 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2036 "[BTCoex], ********** (After Ext Ant switch setup) 0xcb4 = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x**********\n",
\r
2037 u32tmp1, u32tmp2, u32tmp3);
\r
2038 BTC_TRACE(trace_buf);
\r
2043 void halbtc8821c1ant_set_rfe_type(IN struct btc_coexist *btcoexist)
\r
2045 struct btc_board_info *board_info = &btcoexist->board_info;
\r
2048 rfe_type->ext_band_switch_exist = false;
\r
2049 rfe_type->ext_band_switch_type = BT_8821C_1ANT_EXT_BAND_SWITCH_USE_SPDT; // SPDT;
\r
2050 rfe_type->ext_band_switch_ctrl_polarity = 0;
\r
2052 if (rfe_type->ext_band_switch_exist) {
\r
2054 /* band switch use RFE_ctrl1 (pin name: PAPE_A) and RFE_ctrl3 (pin name: LNAON_A) */
\r
2056 /* set RFE_ctrl1 as software control */
\r
2057 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb0, 0xf0, 0x7);
\r
2059 /* set RFE_ctrl3 as software control */
\r
2060 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb1, 0xf0, 0x7);
\r
2065 /* the following setup should be got from Efuse in the future */
\r
2066 rfe_type->rfe_module_type = board_info->rfe_type;
\r
2068 rfe_type->ext_ant_switch_ctrl_polarity = 0;
\r
2069 rfe_type->ext_ant_switch_diversity = false;
\r
2071 switch(rfe_type->rfe_module_type)
\r
2075 rfe_type->ext_ant_switch_exist = true;
\r
2076 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT; /*2-Ant, DPDT, WLG*/
\r
2077 rfe_type->wlg_Locate_at_btg = false;
\r
2078 rfe_type->ext_ant_switch_diversity = true;
\r
2081 rfe_type->ext_ant_switch_exist = true;
\r
2082 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, WLG */
\r
2083 rfe_type->wlg_Locate_at_btg = false;
\r
2086 rfe_type->ext_ant_switch_exist = true;
\r
2087 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, BTG */
\r
2088 rfe_type->wlg_Locate_at_btg = true;
\r
2091 rfe_type->ext_ant_switch_exist = true;
\r
2092 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, WLG */
\r
2093 rfe_type->wlg_Locate_at_btg = false;
\r
2096 rfe_type->ext_ant_switch_exist = true;
\r
2097 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, BTG */;
\r
2098 rfe_type->wlg_Locate_at_btg = true;
\r
2101 rfe_type->ext_ant_switch_exist = false; /*2-Ant, no antenna switch, WLG*/
\r
2102 rfe_type->wlg_Locate_at_btg = false;
\r
2107 if (rfe_type->wlg_Locate_at_btg)
\r
2108 halbtc8821c1ant_set_int_block(btcoexist, FORCE_EXEC, BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG);
\r
2110 halbtc8821c1ant_set_int_block(btcoexist, FORCE_EXEC, BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG);
\r
2116 void halbtc8821c1ant_set_ant_path(IN struct btc_coexist *btcoexist,
\r
2117 IN u8 ant_pos_type, IN boolean force_exec,
\r
2120 struct btc_board_info *board_info = &btcoexist->board_info;
\r
2121 u32 cnt_bt_cal_chk = 0;
\r
2122 boolean is_in_mp_mode = false;
\r
2124 u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
\r
2127 #if BT_8821C_1ANT_ANTDET_ENABLE
\r
2128 #if BT_8821C_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE
\r
2129 if (ant_pos_type == BTC_ANT_PATH_PTA) {
\r
2130 if ((board_info->btdm_ant_det_finish) &&
\r
2131 (board_info->btdm_ant_num_by_ant_det == 2)) {
\r
2132 if (board_info->btdm_ant_pos ==
\r
2133 BTC_ANTENNA_AT_MAIN_PORT)
\r
2134 ant_pos_type = BTC_ANT_PATH_WIFI;
\r
2136 ant_pos_type = BTC_ANT_PATH_BT;
\r
2142 coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase;
\r
2144 if (!force_exec) {
\r
2145 if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type)
\r
2149 coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type;
\r
2152 u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
\r
2154 u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
\r
2156 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
\r
2158 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
\r
2160 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2161 "[BTCoex], ********** (Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
\r
2162 u32tmp3, u8tmp, u32tmp1, u32tmp2);
\r
2163 BTC_TRACE(trace_buf);
\r
2169 case BT_8821C_1ANT_PHASE_COEX_INIT:
\r
2170 /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */
\r
2171 halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0);
\r
2173 /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */
\r
2174 halbtc8821c1ant_ltecoex_set_coex_table(btcoexist,
\r
2175 BT_8821C_1ANT_CTT_WL_VS_LTE, 0xffff);
\r
2177 /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */
\r
2178 halbtc8821c1ant_ltecoex_set_coex_table(btcoexist,
\r
2179 BT_8821C_1ANT_CTT_BT_VS_LTE, 0xffff);
\r
2181 /* Wait If BT IQK running, because Path control owner is at BT during BT IQK (setup by WiFi firmware) */
\r
2182 while (cnt_bt_cal_chk <= 20) {
\r
2183 u8tmp = btcoexist->btc_read_1byte(btcoexist,
\r
2186 if (u8tmp & BIT(0)) {
\r
2187 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2188 "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n",
\r
2190 BTC_TRACE(trace_buf);
\r
2193 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2194 "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n",
\r
2196 BTC_TRACE(trace_buf);
\r
2201 /* set Path control owner to WL at initial step */
\r
2202 halbtc8821c1ant_ltecoex_pathcontrol_owner(btcoexist,
\r
2203 BT_8821C_1ANT_PCO_WLSIDE);
\r
2205 /* set GNT_BT to SW high */
\r
2206 halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
\r
2207 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
2208 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
\r
2209 BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
\r
2210 /* Set GNT_WL to SW low */
\r
2211 halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
\r
2212 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
2213 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
\r
2214 BT_8821C_1ANT_SIG_STA_SET_TO_LOW);
\r
2216 coex_sta->run_time_state = false;
\r
2218 if (BTC_ANT_PATH_AUTO == ant_pos_type)
\r
2219 ant_pos_type = BTC_ANT_PATH_BT;
\r
2222 case BT_8821C_1ANT_PHASE_WLANONLY_INIT:
\r
2223 /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */
\r
2224 halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0);
\r
2226 /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */
\r
2227 halbtc8821c1ant_ltecoex_set_coex_table(btcoexist,
\r
2228 BT_8821C_1ANT_CTT_WL_VS_LTE, 0xffff);
\r
2230 /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */
\r
2231 halbtc8821c1ant_ltecoex_set_coex_table(btcoexist,
\r
2232 BT_8821C_1ANT_CTT_BT_VS_LTE, 0xffff);
\r
2234 /* set Path control owner to WL at initial step */
\r
2235 halbtc8821c1ant_ltecoex_pathcontrol_owner(btcoexist,
\r
2236 BT_8821C_1ANT_PCO_WLSIDE);
\r
2238 /* set GNT_BT to SW Low */
\r
2239 halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
\r
2240 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
2241 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
\r
2242 BT_8821C_1ANT_SIG_STA_SET_TO_LOW);
\r
2243 /* Set GNT_WL to SW high */
\r
2244 halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
\r
2245 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
2246 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
\r
2247 BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
\r
2249 coex_sta->run_time_state = false;
\r
2251 if (BTC_ANT_PATH_AUTO == ant_pos_type)
\r
2252 ant_pos_type = BTC_ANT_PATH_WIFI;
\r
2255 case BT_8821C_1ANT_PHASE_WLAN_OFF:
\r
2256 /* Disable LTE Coex Function in WiFi side */
\r
2257 halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0);
\r
2259 /* set Path control owner to BT */
\r
2260 halbtc8821c1ant_ltecoex_pathcontrol_owner(btcoexist,
\r
2261 BT_8821C_1ANT_PCO_BTSIDE);
\r
2263 /* Set Ext Ant Switch to BT control at wifi off step */
\r
2264 halbtc8821c1ant_set_ext_ant_switch(btcoexist,
\r
2266 BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT,
\r
2267 BT_8821C_1ANT_EXT_ANT_SWITCH_TO_NOCARE);
\r
2269 coex_sta->run_time_state = false;
\r
2271 case BT_8821C_1ANT_PHASE_2G_RUNTIME:
\r
2273 /* set Path control owner to WL at runtime step */
\r
2274 halbtc8821c1ant_ltecoex_pathcontrol_owner(btcoexist,
\r
2275 BT_8821C_1ANT_PCO_WLSIDE);
\r
2277 /* set GNT_BT to PTA */
\r
2278 halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
\r
2279 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
2280 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA,
\r
2281 BT_8821C_1ANT_SIG_STA_SET_BY_HW);
\r
2283 if (rfe_type->wlg_Locate_at_btg) /* Set GNT_WL to PTA */
\r
2284 halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
\r
2285 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
2286 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA,
\r
2287 BT_8821C_1ANT_SIG_STA_SET_BY_HW);
\r
2288 else /* Set GNT_WL to SW High */
\r
2289 halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
\r
2290 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
2291 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
\r
2292 BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
\r
2294 coex_sta->run_time_state = true;
\r
2296 if (BTC_ANT_PATH_AUTO == ant_pos_type){
\r
2297 if (rfe_type->wlg_Locate_at_btg)
\r
2298 ant_pos_type = BTC_ANT_PATH_WIFI;
\r
2300 ant_pos_type = BTC_ANT_PATH_PTA;
\r
2303 if (rfe_type->wlg_Locate_at_btg)
\r
2304 halbtc8821c1ant_set_int_block(btcoexist, NORMAL_EXEC, BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG);
\r
2306 halbtc8821c1ant_set_int_block(btcoexist, NORMAL_EXEC, BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG);
\r
2309 case BT_8821C_1ANT_PHASE_5G_RUNTIME:
\r
2311 /* set Path control owner to WL at runtime step */
\r
2312 halbtc8821c1ant_ltecoex_pathcontrol_owner(btcoexist,
\r
2313 BT_8821C_1ANT_PCO_WLSIDE);
\r
2315 /* set GNT_BT to SW Hi */
\r
2316 halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
\r
2317 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
2318 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
\r
2319 BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
\r
2321 /* Set GNT_WL to SW Hi */
\r
2322 halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
\r
2323 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
2324 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
\r
2325 BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
\r
2327 coex_sta->run_time_state = true;
\r
2329 if (BTC_ANT_PATH_AUTO == ant_pos_type) {
\r
2330 /* if (rfe_type->ext_band_switch_exist)
\r
2331 ant_pos_type = BTC_ANT_PATH_PTA;
\r
2333 ant_pos_type = BTC_ANT_PATH_WIFI5G;
\r
2336 halbtc8821c1ant_set_int_block(btcoexist, NORMAL_EXEC, BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG);
\r
2339 case BT_8821C_1ANT_PHASE_BTMPMODE:
\r
2340 /* Disable LTE Coex Function in WiFi side */
\r
2341 halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0);
\r
2343 /* set Path control owner to WL */
\r
2344 halbtc8821c1ant_ltecoex_pathcontrol_owner(btcoexist,
\r
2345 BT_8821C_1ANT_PCO_WLSIDE);
\r
2347 /* set GNT_BT to SW Hi */
\r
2348 halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
\r
2349 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
2350 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
\r
2351 BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
\r
2353 /* Set GNT_WL to SW Lo */
\r
2354 halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
\r
2355 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
2356 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
\r
2357 BT_8821C_1ANT_SIG_STA_SET_TO_LOW);
\r
2359 coex_sta->run_time_state = false;
\r
2361 /* Set Ext Ant Switch to BT side at BT MP mode */
\r
2362 if (BTC_ANT_PATH_AUTO == ant_pos_type)
\r
2363 ant_pos_type = BTC_ANT_PATH_BT;
\r
2368 if (phase != BT_8821C_1ANT_PHASE_WLAN_OFF)
\r
2370 switch (ant_pos_type) {
\r
2371 case BTC_ANT_PATH_WIFI:
\r
2372 halbtc8821c1ant_set_ext_ant_switch( btcoexist,
\r
2374 BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
\r
2375 BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLG);
\r
2377 case BTC_ANT_PATH_WIFI5G:
\r
2378 halbtc8821c1ant_set_ext_ant_switch( btcoexist,
\r
2380 BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
\r
2381 BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLA);
\r
2383 case BTC_ANT_PATH_BT:
\r
2384 halbtc8821c1ant_set_ext_ant_switch( btcoexist,
\r
2386 BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
\r
2387 BT_8821C_1ANT_EXT_ANT_SWITCH_TO_BT);
\r
2390 case BTC_ANT_PATH_PTA:
\r
2391 halbtc8821c1ant_set_ext_ant_switch( btcoexist,
\r
2393 BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA,
\r
2394 BT_8821C_1ANT_EXT_ANT_SWITCH_TO_NOCARE);
\r
2400 u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
\r
2401 u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
\r
2402 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
\r
2403 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
\r
2405 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2406 "[BTCoex], ********** (After Ant-Setup phase---%d) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
\r
2407 phase, u32tmp3, u8tmp, u32tmp1, u32tmp2);
\r
2409 BTC_TRACE(trace_buf);
\r
2414 boolean halbtc8821c1ant_is_common_action(IN struct btc_coexist *btcoexist)
\r
2416 boolean common = false, wifi_connected = false, wifi_busy = false;
\r
2418 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
\r
2420 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
\r
2422 if (!wifi_connected &&
\r
2423 BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
\r
2424 coex_dm->bt_status) {
\r
2425 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2426 "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
\r
2427 BTC_TRACE(trace_buf);
\r
2429 /* halbtc8821c1ant_sw_mechanism(btcoexist, false); */
\r
2432 } else if (wifi_connected &&
\r
2433 (BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
\r
2434 coex_dm->bt_status)) {
\r
2435 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2436 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
\r
2437 BTC_TRACE(trace_buf);
\r
2439 /* halbtc8821c1ant_sw_mechanism(btcoexist, false); */
\r
2442 } else if (!wifi_connected &&
\r
2443 (BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
\r
2444 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2445 "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
\r
2446 BTC_TRACE(trace_buf);
\r
2448 /* halbtc8821c1ant_sw_mechanism(btcoexist, false); */
\r
2451 } else if (wifi_connected &&
\r
2452 (BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
\r
2453 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2454 "[BTCoex], Wifi connected + BT connected-idle!!\n");
\r
2455 BTC_TRACE(trace_buf);
\r
2457 /* halbtc8821c1ant_sw_mechanism(btcoexist, false); */
\r
2460 } else if (!wifi_connected &&
\r
2461 (BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE != coex_dm->bt_status)) {
\r
2462 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2463 "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
\r
2464 BTC_TRACE(trace_buf);
\r
2466 /* halbtc8821c1ant_sw_mechanism(btcoexist, false); */
\r
2471 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2472 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
\r
2473 BTC_TRACE(trace_buf);
\r
2475 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2476 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
\r
2477 BTC_TRACE(trace_buf);
\r
2487 /* *********************************************
\r
2489 * Software Coex Mechanism start
\r
2491 * ********************************************* */
\r
2493 /* SCO only or SCO+PAN(HS) */
\r
2496 void halbtc8821c1ant_action_sco(IN struct btc_coexist* btcoexist)
\r
2498 halbtc8821c1ant_sw_mechanism(btcoexist, true);
\r
2502 void halbtc8821c1ant_action_hid(IN struct btc_coexist* btcoexist)
\r
2504 halbtc8821c1ant_sw_mechanism(btcoexist, true);
\r
2508 void halbtc8821c1ant_action_a2dp(IN struct btc_coexist* btcoexist)
\r
2510 halbtc8821c1ant_sw_mechanism(btcoexist, false);
\r
2513 void halbtc8821c1ant_action_a2dp_pan_hs(IN struct btc_coexist* btcoexist)
\r
2515 halbtc8821c1ant_sw_mechanism(btcoexist, false);
\r
2518 void halbtc8821c1ant_action_pan_edr(IN struct btc_coexist* btcoexist)
\r
2520 halbtc8821c1ant_sw_mechanism(btcoexist, false);
\r
2524 void halbtc8821c1ant_action_pan_hs(IN struct btc_coexist* btcoexist)
\r
2526 halbtc8821c1ant_sw_mechanism(btcoexist, false);
\r
2530 void halbtc8821c1ant_action_pan_edr_a2dp(IN struct btc_coexist* btcoexist)
\r
2532 halbtc8821c1ant_sw_mechanism(btcoexist, false);
\r
2535 void halbtc8821c1ant_action_pan_edr_hid(IN struct btc_coexist* btcoexist)
\r
2537 halbtc8821c1ant_sw_mechanism(btcoexist, true);
\r
2541 void halbtc8821c1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist* btcoexist)
\r
2543 halbtc8821c1ant_sw_mechanism(btcoexist, true);
\r
2546 void halbtc8821c1ant_action_hid_a2dp(IN struct btc_coexist* btcoexist)
\r
2548 halbtc8821c1ant_sw_mechanism(btcoexist, true);
\r
2553 /* *********************************************
\r
2555 * Non-Software Coex Mechanism start
\r
2557 * ********************************************* */
\r
2558 void halbtc8821c1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist)
\r
2560 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
\r
2562 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
\r
2563 BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
2565 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
\r
2568 void halbtc8821c1ant_action_wifi_under5g(IN struct btc_coexist *btcoexist)
\r
2571 halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
\r
2572 halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
\r
2574 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
\r
2575 BT_8821C_1ANT_PHASE_5G_RUNTIME);
\r
2579 void halbtc8821c1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
\r
2581 boolean wifi_under_5g = false;
\r
2583 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
\r
2586 halbtc8821c1ant_action_wifi_under5g(btcoexist);
\r
2588 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2589 "[BTCoex], ********** (wlan only -- under 5g ) **********\n");
\r
2590 BTC_TRACE(trace_buf);
\r
2594 halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
\r
2596 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
\r
2597 BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
2599 halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
\r
2602 void halbtc8821c1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
\r
2604 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
\r
2606 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
\r
2607 BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
2609 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
\r
2612 void halbtc8821c1ant_action_hs(IN struct btc_coexist *btcoexist)
\r
2614 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
\r
2616 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
\r
2617 BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
2619 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
\r
2622 void halbtc8821c1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
\r
2624 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
2625 boolean wifi_connected = false, ap_enable = false, wifi_busy = false,
\r
2627 boolean wifi_scan = false, wifi_link = false, wifi_roam = false;
\r
2629 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
\r
2631 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
\r
2633 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
\r
2634 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
\r
2635 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
\r
2637 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link);
\r
2638 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam);
\r
2640 if ((wifi_link) || (wifi_roam) || (coex_sta->wifi_is_high_pri_task)) {
\r
2642 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33);
\r
2643 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
\r
2645 } else if ((wifi_scan) && (coex_sta->bt_create_connection)) {
\r
2647 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
\r
2648 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
\r
2650 } else if ((!wifi_connected) && (!wifi_scan)) {
\r
2652 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
\r
2654 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
\r
2655 } else if ((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) {
\r
2657 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
\r
2658 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
\r
2660 } else if (bt_link_info->a2dp_exist) {
\r
2662 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
\r
2664 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
\r
2665 } else if (wifi_scan) {
\r
2667 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
\r
2669 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
\r
2671 } else if (wifi_busy) {
\r
2672 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21);
\r
2674 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
\r
2676 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 19);
\r
2678 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
\r
2682 void halbtc8821c1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
\r
2683 *btcoexist, IN u8 wifi_status)
\r
2685 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
2686 boolean wifi_connected = false;
\r
2688 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
\r
2691 /* tdma and coex table */
\r
2693 if (bt_link_info->sco_exist) {
\r
2694 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
\r
2695 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
\r
2696 } else { /* HID */
\r
2697 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
\r
2698 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
\r
2702 void halbtc8821c1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
\r
2703 *btcoexist, IN u8 wifi_status)
\r
2706 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
2707 boolean wifi_busy = false;
\r
2709 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
\r
2711 if (bt_link_info->hid_only) { /* HID */
\r
2712 halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist,
\r
2714 coex_dm->auto_tdma_adjust = false;
\r
2716 } else if (bt_link_info->a2dp_only) { /* A2DP */
\r
2717 if (BT_8821C_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
\r
2718 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
\r
2720 halbtc8821c1ant_coex_table_with_type(btcoexist,
\r
2722 coex_dm->auto_tdma_adjust = false;
\r
2725 if (coex_sta->scan_ap_num >=
\r
2726 BT_8821C_1ANT_WIFI_NOISY_THRESH) {
\r
2727 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
\r
2730 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
\r
2734 halbtc8821c1ant_coex_table_with_type(btcoexist,
\r
2736 coex_dm->auto_tdma_adjust = true;
\r
2738 } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
\r
2739 (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
\r
2740 bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
\r
2744 if ((coex_sta->a2dp_bit_pool > 40) && (coex_sta->a2dp_bit_pool < 255))
\r
2745 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 15);
\r
2747 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
\r
2749 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
\r
2751 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
\r
2752 coex_dm->auto_tdma_adjust = false;
\r
2753 } else if (bt_link_info->hid_exist &&
\r
2754 bt_link_info->a2dp_exist) { /* HID+A2DP */
\r
2755 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 8);
\r
2756 coex_dm->auto_tdma_adjust = false;
\r
2758 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
\r
2759 } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
\r
2760 bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
\r
2761 if (BT_8821C_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status)
\r
2762 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
\r
2765 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
\r
2767 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
\r
2768 coex_dm->auto_tdma_adjust = false;
\r
2770 /* BT no-profile busy (0x9) */
\r
2771 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33);
\r
2772 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
\r
2773 coex_dm->auto_tdma_adjust = false;
\r
2777 void halbtc8821c1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
\r
2779 /* tdma and coex table */
\r
2780 halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
\r
2782 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
\r
2783 BT_8821C_1ANT_PHASE_2G_RUNTIME );
\r
2785 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
\r
2788 void halbtc8821c1ant_action_wifi_not_connected_scan(IN struct btc_coexist
\r
2791 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
2792 boolean wifi_connected = false, bt_hs_on = false;
\r
2793 u32 wifi_link_status = 0;
\r
2794 u32 num_of_wifi_link = 0;
\r
2795 boolean bt_ctrl_agg_buf_size = false;
\r
2796 u8 agg_buf_size = 5;
\r
2798 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
\r
2799 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
\r
2800 &wifi_link_status);
\r
2802 num_of_wifi_link = wifi_link_status >> 16;
\r
2804 if (num_of_wifi_link >= 2) {
\r
2805 halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
\r
2806 halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
\r
2807 bt_ctrl_agg_buf_size, agg_buf_size);
\r
2809 if (coex_sta->c2h_bt_inquiry_page) {
\r
2810 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2811 "############# [BTCoex], BT Is Inquirying\n");
\r
2812 BTC_TRACE(trace_buf);
\r
2813 halbtc8821c1ant_action_bt_inquiry(btcoexist);
\r
2815 halbtc8821c1ant_action_wifi_multi_port(btcoexist);
\r
2819 if (coex_sta->c2h_bt_inquiry_page) {
\r
2820 halbtc8821c1ant_action_bt_inquiry(btcoexist);
\r
2822 } else if (bt_hs_on) {
\r
2823 halbtc8821c1ant_action_hs(btcoexist);
\r
2827 /* tdma and coex table */
\r
2828 if (BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
\r
2829 if (bt_link_info->a2dp_exist) {
\r
2830 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
\r
2832 halbtc8821c1ant_coex_table_with_type(btcoexist,
\r
2834 } else if (bt_link_info->a2dp_exist &&
\r
2835 bt_link_info->pan_exist) {
\r
2836 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
\r
2838 halbtc8821c1ant_coex_table_with_type(btcoexist,
\r
2841 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
\r
2842 halbtc8821c1ant_coex_table_with_type(btcoexist,
\r
2845 } else if ((BT_8821C_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
\r
2846 (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY ==
\r
2847 coex_dm->bt_status)) {
\r
2848 halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist,
\r
2849 BT_8821C_1ANT_WIFI_STATUS_CONNECTED_SCAN);
\r
2851 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
\r
2853 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
\r
2854 NORMAL_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
2856 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
\r
2860 void halbtc8821c1ant_action_wifi_connected_scan(IN struct btc_coexist
\r
2863 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
2864 boolean wifi_connected = false, bt_hs_on = false;
\r
2865 u32 wifi_link_status = 0;
\r
2866 u32 num_of_wifi_link = 0;
\r
2867 boolean bt_ctrl_agg_buf_size = false;
\r
2868 u8 agg_buf_size = 5;
\r
2870 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
\r
2871 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
\r
2872 &wifi_link_status);
\r
2874 num_of_wifi_link = wifi_link_status >> 16;
\r
2876 if (num_of_wifi_link >= 2) {
\r
2877 halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
\r
2878 halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
\r
2879 bt_ctrl_agg_buf_size, agg_buf_size);
\r
2881 if (coex_sta->c2h_bt_inquiry_page) {
\r
2882 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2883 "############# [BTCoex], BT Is Inquirying\n");
\r
2884 BTC_TRACE(trace_buf);
\r
2885 halbtc8821c1ant_action_bt_inquiry(btcoexist);
\r
2887 halbtc8821c1ant_action_wifi_multi_port(btcoexist);
\r
2891 if (coex_sta->c2h_bt_inquiry_page) {
\r
2892 halbtc8821c1ant_action_bt_inquiry(btcoexist);
\r
2894 } else if (bt_hs_on) {
\r
2895 halbtc8821c1ant_action_hs(btcoexist);
\r
2900 /* tdma and coex table */
\r
2901 if (BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
\r
2902 if (bt_link_info->a2dp_exist) {
\r
2903 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
\r
2905 halbtc8821c1ant_coex_table_with_type(btcoexist,
\r
2907 } else if (bt_link_info->a2dp_exist &&
\r
2908 bt_link_info->pan_exist) {
\r
2909 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
\r
2911 halbtc8821c1ant_coex_table_with_type(btcoexist,
\r
2914 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
\r
2915 halbtc8821c1ant_coex_table_with_type(btcoexist,
\r
2918 } else if ((BT_8821C_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
\r
2919 (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY ==
\r
2920 coex_dm->bt_status)) {
\r
2921 halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist,
\r
2922 BT_8821C_1ANT_WIFI_STATUS_CONNECTED_SCAN);
\r
2924 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
\r
2926 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
\r
2927 NORMAL_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
2929 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
\r
2933 void halbtc8821c1ant_action_wifi_not_connected_asso_auth(
\r
2934 IN struct btc_coexist *btcoexist)
\r
2936 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
2937 boolean wifi_connected = false, bt_hs_on = false;
\r
2938 u32 wifi_link_status = 0;
\r
2939 u32 num_of_wifi_link = 0;
\r
2940 boolean bt_ctrl_agg_buf_size = false;
\r
2941 u8 agg_buf_size = 5;
\r
2943 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
\r
2944 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
\r
2945 &wifi_link_status);
\r
2947 num_of_wifi_link = wifi_link_status >> 16;
\r
2949 if (num_of_wifi_link >= 2) {
\r
2950 halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
\r
2951 halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
\r
2952 bt_ctrl_agg_buf_size, agg_buf_size);
\r
2954 if (coex_sta->c2h_bt_inquiry_page) {
\r
2955 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
2956 "############# [BTCoex], BT Is Inquirying\n");
\r
2957 BTC_TRACE(trace_buf);
\r
2958 halbtc8821c1ant_action_bt_inquiry(btcoexist);
\r
2960 halbtc8821c1ant_action_wifi_multi_port(btcoexist);
\r
2964 if (coex_sta->c2h_bt_inquiry_page) {
\r
2965 halbtc8821c1ant_action_bt_inquiry(btcoexist);
\r
2967 } else if (bt_hs_on) {
\r
2968 halbtc8821c1ant_action_hs(btcoexist);
\r
2972 /* tdma and coex table */
\r
2973 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
\r
2974 (bt_link_info->a2dp_exist)) {
\r
2975 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
\r
2976 halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
\r
2977 } else if (bt_link_info->pan_exist) {
\r
2978 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
\r
2979 halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
\r
2981 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
\r
2982 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
\r
2983 NORMAL_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
2984 halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2);
\r
2988 void halbtc8821c1ant_action_wifi_connected_specific_packet(
\r
2989 IN struct btc_coexist *btcoexist)
\r
2991 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
2992 boolean wifi_connected = false, bt_hs_on = false;
\r
2993 u32 wifi_link_status = 0;
\r
2994 u32 num_of_wifi_link = 0;
\r
2995 boolean bt_ctrl_agg_buf_size = false;
\r
2996 u8 agg_buf_size = 5;
\r
2997 boolean wifi_busy = false;
\r
2999 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
\r
3000 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
\r
3001 &wifi_link_status);
\r
3003 num_of_wifi_link = wifi_link_status >> 16;
\r
3005 if (num_of_wifi_link >= 2) {
\r
3006 halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
\r
3007 halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
\r
3008 bt_ctrl_agg_buf_size, agg_buf_size);
\r
3010 if (coex_sta->c2h_bt_inquiry_page) {
\r
3011 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3012 "############# [BTCoex], BT Is Inquirying\n");
\r
3013 BTC_TRACE(trace_buf);
\r
3014 halbtc8821c1ant_action_bt_inquiry(btcoexist);
\r
3016 halbtc8821c1ant_action_wifi_multi_port(btcoexist);
\r
3020 if (coex_sta->c2h_bt_inquiry_page) {
\r
3021 halbtc8821c1ant_action_bt_inquiry(btcoexist);
\r
3023 } else if (bt_hs_on) {
\r
3024 halbtc8821c1ant_action_hs(btcoexist);
\r
3029 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
\r
3031 /* no specific packet process for both WiFi and BT very busy */
\r
3032 if ((wifi_busy) && ((bt_link_info->pan_exist) ||
\r
3033 (coex_sta->num_of_profile >= 2)))
\r
3036 /* tdma and coex table */
\r
3037 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) {
\r
3038 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
\r
3039 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
\r
3040 } else if (bt_link_info->a2dp_exist) {
\r
3041 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
\r
3042 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
\r
3043 } else if (bt_link_info->pan_exist) {
\r
3044 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
\r
3045 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
\r
3047 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
\r
3048 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
\r
3049 NORMAL_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
3050 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
\r
3054 void halbtc8821c1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
\r
3056 boolean wifi_busy = false;
\r
3057 boolean scan = false, link = false, roam = false;
\r
3058 boolean under_4way = false, ap_enable = false, wifi_under_5g = false;
\r
3060 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3061 "[BTCoex], CoexForWifiConnect()===>\n");
\r
3062 BTC_TRACE(trace_buf);
\r
3064 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
\r
3066 if (wifi_under_5g) {
\r
3068 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3069 "[BTCoex], WiFi is under 5G!!!\n");
\r
3070 BTC_TRACE(trace_buf);
\r
3072 halbtc8821c1ant_action_wifi_under5g(btcoexist);
\r
3076 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
\r
3077 NORMAL_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
3080 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
\r
3083 halbtc8821c1ant_action_wifi_connected_specific_packet(btcoexist);
\r
3084 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3085 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
\r
3086 BTC_TRACE(trace_buf);
\r
3090 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
\r
3091 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
\r
3092 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
\r
3093 if (scan || link || roam) {
\r
3095 halbtc8821c1ant_action_wifi_connected_scan(btcoexist);
\r
3097 halbtc8821c1ant_action_wifi_connected_specific_packet(
\r
3099 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3100 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
\r
3101 BTC_TRACE(trace_buf);
\r
3105 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
\r
3107 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
\r
3110 /* tdma and coex table */
\r
3112 if (BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
\r
3113 halbtc8821c1ant_action_wifi_connected_bt_acl_busy(
\r
3115 BT_8821C_1ANT_WIFI_STATUS_CONNECTED_IDLE);
\r
3116 } else if ((BT_8821C_1ANT_BT_STATUS_SCO_BUSY ==
\r
3117 coex_dm->bt_status) ||
\r
3118 (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY ==
\r
3119 coex_dm->bt_status)) {
\r
3120 halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist,
\r
3121 BT_8821C_1ANT_WIFI_STATUS_CONNECTED_IDLE);
\r
3123 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
\r
3126 halbtc8821c1ant_set_ant_path(btcoexist,
\r
3127 BTC_ANT_PATH_AUTO, NORMAL_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
3129 halbtc8821c1ant_coex_table_with_type(btcoexist,
\r
3133 if (BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
\r
3134 halbtc8821c1ant_action_wifi_connected_bt_acl_busy(
\r
3136 BT_8821C_1ANT_WIFI_STATUS_CONNECTED_BUSY);
\r
3137 } else if ((BT_8821C_1ANT_BT_STATUS_SCO_BUSY ==
\r
3138 coex_dm->bt_status) ||
\r
3139 (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY ==
\r
3140 coex_dm->bt_status)) {
\r
3141 halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist,
\r
3142 BT_8821C_1ANT_WIFI_STATUS_CONNECTED_BUSY);
\r
3145 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
\r
3148 halbtc8821c1ant_set_ant_path(btcoexist,
\r
3149 BTC_ANT_PATH_AUTO, NORMAL_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
3151 halbtc8821c1ant_coex_table_with_type(btcoexist,
\r
3157 void halbtc8821c1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
\r
3161 algorithm = halbtc8821c1ant_action_algorithm(btcoexist);
\r
3162 coex_dm->cur_algorithm = algorithm;
\r
3164 if (halbtc8821c1ant_is_common_action(btcoexist)) {
\r
3167 switch (coex_dm->cur_algorithm) {
\r
3168 case BT_8821C_1ANT_COEX_ALGO_SCO:
\r
3169 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3170 "[BTCoex], Action algorithm = SCO.\n");
\r
3171 BTC_TRACE(trace_buf);
\r
3172 /* halbtc8821c1ant_action_sco(btcoexist); */
\r
3174 case BT_8821C_1ANT_COEX_ALGO_HID:
\r
3175 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3176 "[BTCoex], Action algorithm = HID.\n");
\r
3177 BTC_TRACE(trace_buf);
\r
3178 /* halbtc8821c1ant_action_hid(btcoexist); */
\r
3180 case BT_8821C_1ANT_COEX_ALGO_A2DP:
\r
3181 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3182 "[BTCoex], Action algorithm = A2DP.\n");
\r
3183 BTC_TRACE(trace_buf);
\r
3184 /* halbtc8821c1ant_action_a2dp(btcoexist); */
\r
3186 case BT_8821C_1ANT_COEX_ALGO_A2DP_PANHS:
\r
3187 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3188 "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
\r
3189 BTC_TRACE(trace_buf);
\r
3190 /* halbtc8821c1ant_action_a2dp_pan_hs(btcoexist); */
\r
3192 case BT_8821C_1ANT_COEX_ALGO_PANEDR:
\r
3193 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3194 "[BTCoex], Action algorithm = PAN(EDR).\n");
\r
3195 BTC_TRACE(trace_buf);
\r
3196 /* halbtc8821c1ant_action_pan_edr(btcoexist); */
\r
3198 case BT_8821C_1ANT_COEX_ALGO_PANHS:
\r
3199 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3200 "[BTCoex], Action algorithm = HS mode.\n");
\r
3201 BTC_TRACE(trace_buf);
\r
3202 /* halbtc8821c1ant_action_pan_hs(btcoexist); */
\r
3204 case BT_8821C_1ANT_COEX_ALGO_PANEDR_A2DP:
\r
3205 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3206 "[BTCoex], Action algorithm = PAN+A2DP.\n");
\r
3207 BTC_TRACE(trace_buf);
\r
3208 /* halbtc8821c1ant_action_pan_edr_a2dp(btcoexist); */
\r
3210 case BT_8821C_1ANT_COEX_ALGO_PANEDR_HID:
\r
3211 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3212 "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
\r
3213 BTC_TRACE(trace_buf);
\r
3214 /* halbtc8821c1ant_action_pan_edr_hid(btcoexist); */
\r
3216 case BT_8821C_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
\r
3217 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3218 "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
\r
3219 BTC_TRACE(trace_buf);
\r
3220 /* halbtc8821c1ant_action_hid_a2dp_pan_edr(btcoexist); */
\r
3222 case BT_8821C_1ANT_COEX_ALGO_HID_A2DP:
\r
3223 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3224 "[BTCoex], Action algorithm = HID+A2DP.\n");
\r
3225 BTC_TRACE(trace_buf);
\r
3226 /* halbtc8821c1ant_action_hid_a2dp(btcoexist); */
\r
3229 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3230 "[BTCoex], Action algorithm = coexist All Off!!\n");
\r
3231 BTC_TRACE(trace_buf);
\r
3232 /* halbtc8821c1ant_coex_all_off(btcoexist); */
\r
3235 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
\r
3240 void halbtc8821c1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
\r
3242 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
3243 boolean wifi_connected = false, bt_hs_on = false;
\r
3244 boolean increase_scan_dev_num = false;
\r
3245 boolean bt_ctrl_agg_buf_size = false;
\r
3246 boolean miracast_plus_bt = false, wifi_under_5g = false;
\r
3247 u8 agg_buf_size = 5;
\r
3248 u32 wifi_link_status = 0;
\r
3249 u32 num_of_wifi_link = 0, wifi_bw;
\r
3250 u8 iot_peer = BTC_IOT_PEER_UNKNOWN;
\r
3252 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3253 "[BTCoex], RunCoexistMechanism()===>\n");
\r
3254 BTC_TRACE(trace_buf);
\r
3256 if (btcoexist->manual_control) {
\r
3257 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3258 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
\r
3259 BTC_TRACE(trace_buf);
\r
3263 if (btcoexist->stop_coex_dm) {
\r
3264 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3265 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
\r
3266 BTC_TRACE(trace_buf);
\r
3270 if (coex_sta->under_ips) {
\r
3271 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3272 "[BTCoex], wifi is under IPS !!!\n");
\r
3273 BTC_TRACE(trace_buf);
\r
3277 if (!coex_sta->run_time_state){
\r
3278 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3279 "[BTCoex], return for run_time_state = false !!!\n");
\r
3280 BTC_TRACE(trace_buf);
\r
3284 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
\r
3286 if (wifi_under_5g) {
\r
3288 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3289 "[BTCoex], WiFi is under 5G!!!\n");
\r
3290 BTC_TRACE(trace_buf);
\r
3292 halbtc8821c1ant_action_wifi_under5g(btcoexist);
\r
3296 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3297 "[BTCoex], WiFi is under 2G!!!\n");
\r
3298 BTC_TRACE(trace_buf);
\r
3300 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
\r
3301 NORMAL_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
3304 if (coex_sta->bt_whck_test) {
\r
3305 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3306 "[BTCoex], BT is under WHCK TEST!!!\n");
\r
3307 BTC_TRACE(trace_buf);
\r
3308 halbtc8821c1ant_action_bt_whck_test(btcoexist);
\r
3312 if (coex_sta->bt_disabled) {
\r
3313 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3314 "[BTCoex], BT is disabled !!!\n");
\r
3315 halbtc8821c1ant_action_wifi_only(btcoexist);
\r
3319 if ((BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
\r
3320 (BT_8821C_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
\r
3321 (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
\r
3322 increase_scan_dev_num = true;
\r
3324 btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
\r
3325 &increase_scan_dev_num);
\r
3326 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
\r
3329 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
\r
3330 &wifi_link_status);
\r
3331 num_of_wifi_link = wifi_link_status >> 16;
\r
3333 if ((num_of_wifi_link >= 2) ||
\r
3334 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
\r
3335 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3336 "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
\r
3337 num_of_wifi_link, wifi_link_status);
\r
3338 BTC_TRACE(trace_buf);
\r
3340 if (bt_link_info->bt_link_exist) {
\r
3341 halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1,
\r
3343 miracast_plus_bt = true;
\r
3345 halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
\r
3346 miracast_plus_bt = false;
\r
3348 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
\r
3349 &miracast_plus_bt);
\r
3350 halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
\r
3351 bt_ctrl_agg_buf_size, agg_buf_size);
\r
3353 if (coex_sta->c2h_bt_inquiry_page) {
\r
3354 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3355 "############# [BTCoex], BT Is Inquirying\n");
\r
3356 BTC_TRACE(trace_buf);
\r
3357 halbtc8821c1ant_action_bt_inquiry(btcoexist);
\r
3359 halbtc8821c1ant_action_wifi_multi_port(btcoexist);
\r
3364 miracast_plus_bt = false;
\r
3365 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
\r
3366 &miracast_plus_bt);
\r
3369 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
\r
3371 if ((bt_link_info->bt_link_exist) && (wifi_connected)) {
\r
3372 halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1);
\r
3374 btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer);
\r
3376 if (BTC_IOT_PEER_CISCO != iot_peer) {
\r
3377 if (bt_link_info->sco_exist) /* if (bt_link_info->bt_hi_pri_link_exist) */
\r
3378 halbtc8821c1ant_limited_rx(btcoexist,
\r
3379 NORMAL_EXEC, true, false, 0x5);
\r
3381 halbtc8821c1ant_limited_rx(btcoexist,
\r
3382 NORMAL_EXEC, false, false, 0x5);
\r
3384 if (bt_link_info->sco_exist)
\r
3385 halbtc8821c1ant_limited_rx(btcoexist,
\r
3386 NORMAL_EXEC, true, false, 0x5);
\r
3388 if (BTC_WIFI_BW_HT40 == wifi_bw)
\r
3389 halbtc8821c1ant_limited_rx(btcoexist,
\r
3390 NORMAL_EXEC, false, true, 0x10);
\r
3392 halbtc8821c1ant_limited_rx(btcoexist,
\r
3393 NORMAL_EXEC, false, true, 0x8);
\r
3397 halbtc8821c1ant_sw_mechanism(btcoexist, true);
\r
3398 halbtc8821c1ant_run_sw_coexist_mechanism(
\r
3399 btcoexist); /* just print debug message */
\r
3401 halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
\r
3403 halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
\r
3406 halbtc8821c1ant_sw_mechanism(btcoexist, false);
\r
3407 halbtc8821c1ant_run_sw_coexist_mechanism(
\r
3408 btcoexist); /* just print debug message */
\r
3411 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
\r
3412 if (coex_sta->c2h_bt_inquiry_page) {
\r
3413 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3414 "############# [BTCoex], BT Is Inquirying\n");
\r
3415 BTC_TRACE(trace_buf);
\r
3416 halbtc8821c1ant_action_bt_inquiry(btcoexist);
\r
3418 } else if (bt_hs_on) {
\r
3419 halbtc8821c1ant_action_hs(btcoexist);
\r
3424 if (!wifi_connected) {
\r
3425 boolean scan = false, link = false, roam = false;
\r
3427 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3428 "[BTCoex], wifi is non connected-idle !!!\n");
\r
3429 BTC_TRACE(trace_buf);
\r
3431 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
\r
3432 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
\r
3433 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
\r
3435 if (scan || link || roam) {
\r
3437 halbtc8821c1ant_action_wifi_not_connected_scan(
\r
3440 halbtc8821c1ant_action_wifi_not_connected_asso_auth(
\r
3443 halbtc8821c1ant_action_wifi_not_connected(btcoexist);
\r
3444 } else /* wifi LPS/Busy */
\r
3445 halbtc8821c1ant_action_wifi_connected(btcoexist);
\r
3448 void halbtc8821c1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
\r
3450 /* force to reset coex mechanism */
\r
3453 halbtc8821c1ant_sw_mechanism(btcoexist, false);
\r
3455 coex_sta->pop_event_cnt = 0;
\r
3458 void halbtc8821c1ant_init_hw_config(IN struct btc_coexist *btcoexist,
\r
3459 IN boolean back_up, IN boolean wifi_only)
\r
3461 u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
\r
3463 struct btc_board_info *board_info = &btcoexist->board_info;
\r
3466 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
\r
3467 u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
\r
3468 u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
\r
3470 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3471 "[BTCoex], ********** (Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
\r
3472 u32tmp3, u32tmp1, u32tmp2);
\r
3473 BTC_TRACE(trace_buf);
\r
3475 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3476 "[BTCoex], 1Ant Init HW Config!!\n");
\r
3477 BTC_TRACE(trace_buf);
\r
3479 coex_sta->bt_coex_supported_feature = 0;
\r
3480 coex_sta->bt_coex_supported_version = 0;
\r
3482 /* Setup RF front end type */
\r
3483 halbtc8821c1ant_set_rfe_type(btcoexist);
\r
3485 /* 0xf0[15:12] --> Chip Cut information */
\r
3486 coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
\r
3487 0xf1) & 0xf0) >> 4;
\r
3489 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
\r
3490 0x1); /* enable TBTT nterrupt */
\r
3492 /* BT report packet sample rate */
\r
3493 btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5);
\r
3495 /* Init 0x778 = 0x1 for 1-Ant */
\r
3496 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
\r
3498 /* Enable PTA (3-wire function form BT side) */
\r
3499 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
\r
3500 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1);
\r
3502 /* Enable PTA (tx/rx signal form WiFi side) */
\r
3503 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1);
\r
3505 halbtc8821c1ant_enable_gnt_to_gpio(btcoexist, TRUE);
\r
3507 /* check if WL firmware download ok */
\r
3508 if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6)
\r
3509 halbtc8821c1ant_post_onoffstate_to_bt(btcoexist, TRUE);
\r
3511 halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
\r
3513 /* Antenna config */
\r
3515 coex_sta->concurrent_rx_mode_on = false;
\r
3516 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI,
\r
3517 FORCE_EXEC, BT_8821C_1ANT_PHASE_WLANONLY_INIT);
\r
3519 coex_sta->concurrent_rx_mode_on = true;
\r
3520 /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x2, 0x1); */
\r
3522 /* RF 0x1[1] = 0->Set GNT_WL_RF_Rx always = 1 for con-current Rx, mask Tx only */
\r
3523 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0x2, 0x0);
\r
3525 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
\r
3526 FORCE_EXEC, BT_8821C_1ANT_PHASE_COEX_INIT);
\r
3529 /* PTA parameter */
\r
3530 halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
\r
3532 psd_scan->ant_det_is_ant_det_available = TRUE;
\r
3534 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
\r
3535 u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
\r
3536 u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
\r
3538 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3539 "[BTCoex], ********** (After Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
\r
3540 u32tmp3, u32tmp1, u32tmp2);
\r
3541 BTC_TRACE(trace_buf);
\r
3545 u32 halbtc8821c1ant_psd_log2base(IN struct btc_coexist *btcoexist, IN u32 val)
\r
3548 u32 tmp, tmp2, val_integerd_b = 0, tindex, shiftcount = 0;
\r
3549 u32 result, val_fractiond_b = 0, table_fraction[21] = {0, 432, 332, 274, 232, 200,
\r
3550 174, 151, 132, 115, 100, 86, 74, 62, 51, 42,
\r
3569 val_integerd_b = shiftcount + 1;
\r
3572 for (j = 1; j <= val_integerd_b; j++)
\r
3575 tmp = (val * 100) / tmp2;
\r
3581 val_fractiond_b = table_fraction[tindex];
\r
3583 result = val_integerd_b * 100 - val_fractiond_b;
\r
3590 void halbtc8821c1ant_psd_show_antenna_detect_result(IN struct btc_coexist
\r
3593 u8 *cli_buf = btcoexist->cli_buf;
\r
3594 struct btc_board_info *board_info = &btcoexist->board_info;
\r
3596 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3597 "\r\n============[Antenna Detection info] ============\n");
\r
3598 CL_PRINTF(cli_buf);
\r
3600 if (psd_scan->ant_det_result == 1)
\r
3601 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (>%d)",
\r
3602 "Ant Det Result", "2-Antenna (Bad-Isolation)",
\r
3603 BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION);
\r
3604 else if (psd_scan->ant_det_result == 2)
\r
3605 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)",
\r
3606 "Ant Det Result", "2-Antenna (Good-Isolation)",
\r
3607 BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION
\r
3608 + psd_scan->ant_det_thres_offset,
\r
3609 BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION);
\r
3611 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)",
\r
3612 "Ant Det Result", "1-Antenna",
\r
3613 BT_8821C_1ANT_ANTDET_PSDTHRES_1ANT,
\r
3614 BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION
\r
3615 + psd_scan->ant_det_thres_offset);
\r
3617 CL_PRINTF(cli_buf);
\r
3619 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s ",
\r
3620 "Antenna Detection Finish",
\r
3621 (board_info->btdm_ant_det_finish
\r
3623 CL_PRINTF(cli_buf);
\r
3625 switch (psd_scan->ant_det_result) {
\r
3627 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3628 "(BT is not available)");
\r
3630 case 1: /* 2-Ant bad-isolation */
\r
3631 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3632 "(BT is available)");
\r
3634 case 2: /* 2-Ant good-isolation */
\r
3635 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3636 "(BT is available)");
\r
3638 case 3: /* 1-Ant */
\r
3639 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3640 "(BT is available)");
\r
3643 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3644 "(Uncertainty result)");
\r
3647 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "(Pre-Scan fai)");
\r
3650 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3651 "(WiFi is Scanning)");
\r
3654 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3655 "(BT is not idle)");
\r
3658 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3659 "(Abort by WiFi Scanning)");
\r
3662 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3663 "(Antenna Init is not ready)");
\r
3666 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3667 "(BT is Inquiry or page)");
\r
3670 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3671 "(BT is Disabled)");
\r
3674 CL_PRINTF(cli_buf);
\r
3677 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
\r
3678 "Ant Detect Total Count", psd_scan->ant_det_try_count);
\r
3679 CL_PRINTF(cli_buf);
\r
3681 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
\r
3682 "Ant Detect Fail Count", psd_scan->ant_det_fail_count);
\r
3683 CL_PRINTF(cli_buf);
\r
3685 if ((!board_info->btdm_ant_det_finish) &&
\r
3686 (psd_scan->ant_det_result != 5))
\r
3689 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Response",
\r
3690 (psd_scan->ant_det_result ? "ok" : "fail"));
\r
3691 CL_PRINTF(cli_buf);
\r
3693 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ms", "BT Tx Time",
\r
3694 psd_scan->ant_det_bt_tx_time);
\r
3695 CL_PRINTF(cli_buf);
\r
3697 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "BT Tx Ch",
\r
3698 psd_scan->ant_det_bt_le_channel);
\r
3699 CL_PRINTF(cli_buf);
\r
3701 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d",
\r
3702 "WiFi PSD Cent-Ch/Offset/Span",
\r
3703 psd_scan->real_cent_freq, psd_scan->real_offset,
\r
3704 psd_scan->real_span);
\r
3705 CL_PRINTF(cli_buf);
\r
3707 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dB",
\r
3708 "PSD Pre-Scan Peak Value",
\r
3709 psd_scan->ant_det_pre_psdscan_peak_val / 100);
\r
3710 CL_PRINTF(cli_buf);
\r
3712 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (<= %d)",
\r
3713 "PSD Pre-Scan result",
\r
3714 (psd_scan->ant_det_result != 5 ? "ok" : "fail"),
\r
3715 BT_8821C_1ANT_ANTDET_PSDTHRES_BACKGROUND
\r
3716 + psd_scan->ant_det_thres_offset);
\r
3717 CL_PRINTF(cli_buf);
\r
3719 if (psd_scan->ant_det_result == 5)
\r
3722 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s dB",
\r
3723 "PSD Scan Peak Value", psd_scan->ant_det_peak_val);
\r
3724 CL_PRINTF(cli_buf);
\r
3726 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s MHz",
\r
3727 "PSD Scan Peak Freq", psd_scan->ant_det_peak_freq);
\r
3728 CL_PRINTF(cli_buf);
\r
3731 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "TFBGA Package",
\r
3732 (board_info->tfbga_package) ? "Yes" : "No");
\r
3733 CL_PRINTF(cli_buf);
\r
3735 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
\r
3736 "PSD Threshold Offset", psd_scan->ant_det_thres_offset);
\r
3737 CL_PRINTF(cli_buf);
\r
3743 void halbtc8821c1ant_psd_showdata(IN struct btc_coexist *btcoexist)
\r
3745 u8 *cli_buf = btcoexist->cli_buf;
\r
3746 u32 delta_freq_per_point;
\r
3747 u32 freq, freq1, freq2, n = 0, i = 0, j = 0, m = 0, psd_rep1, psd_rep2;
\r
3749 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3750 "\r\n\n============[PSD info] (%d)============\n",
\r
3751 psd_scan->psd_gen_count);
\r
3752 CL_PRINTF(cli_buf);
\r
3754 if (psd_scan->psd_gen_count == 0) {
\r
3755 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n No data !!\n");
\r
3756 CL_PRINTF(cli_buf);
\r
3760 if (psd_scan->psd_point == 0)
\r
3761 delta_freq_per_point = 0;
\r
3763 delta_freq_per_point = psd_scan->psd_band_width /
\r
3764 psd_scan->psd_point;
\r
3766 /* if (psd_scan->is_psd_show_max_only) */
\r
3768 psd_rep1 = psd_scan->psd_max_value / 100;
\r
3769 psd_rep2 = psd_scan->psd_max_value - psd_rep1 * 100;
\r
3771 freq = ((psd_scan->real_cent_freq - 20) * 1000000 +
\r
3772 psd_scan->psd_max_value_point * delta_freq_per_point);
\r
3773 freq1 = freq / 1000000;
\r
3774 freq2 = freq / 1000 - freq1 * 1000;
\r
3777 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3778 "\r\n Freq = %d.0%d MHz",
\r
3781 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3782 "\r\n Freq = %d.%d MHz",
\r
3785 if (psd_rep2 < 10)
\r
3786 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3787 ", Value = %d.0%d dB, (%d)\n",
\r
3788 psd_rep1, psd_rep2, psd_scan->psd_max_value);
\r
3790 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3791 ", Value = %d.%d dB, (%d)\n",
\r
3792 psd_rep1, psd_rep2, psd_scan->psd_max_value);
\r
3794 CL_PRINTF(cli_buf);
\r
3796 m = psd_scan->psd_start_point;
\r
3797 n = psd_scan->psd_start_point;
\r
3803 freq = ((psd_scan->real_cent_freq - 20) * 1000000 + m *
\r
3804 delta_freq_per_point);
\r
3805 freq1 = freq / 1000000;
\r
3806 freq2 = freq / 1000 - freq1 * 1000;
\r
3810 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3811 "\r\n Freq%6d.000", freq1);
\r
3812 else if (freq2 < 100)
\r
3813 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3814 "\r\n Freq%6d.0%2d", freq1,
\r
3817 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3818 "\r\n Freq%6d.%3d", freq1,
\r
3820 } else if ((i % 8 == 0) ||
\r
3821 (m == psd_scan->psd_stop_point)) {
\r
3823 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3824 "%6d.000\n", freq1);
\r
3825 else if (freq2 < 100)
\r
3826 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3827 "%6d.0%2d\n", freq1, freq2);
\r
3829 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3830 "%6d.%3d\n", freq1, freq2);
\r
3833 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3834 "%6d.000", freq1);
\r
3835 else if (freq2 < 100)
\r
3836 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3837 "%6d.0%2d", freq1, freq2);
\r
3839 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3840 "%6d.%3d", freq1, freq2);
\r
3845 CL_PRINTF(cli_buf);
\r
3847 } while ((i <= 8) && (m <= psd_scan->psd_stop_point));
\r
3851 psd_rep1 = psd_scan->psd_report_max_hold[n] / 100;
\r
3852 psd_rep2 = psd_scan->psd_report_max_hold[n] - psd_rep1 *
\r
3856 if (psd_rep2 < 10)
\r
3857 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3858 "\r\n Val %7d.0%d", psd_rep1,
\r
3861 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3862 "\r\n Val %7d.%d", psd_rep1,
\r
3864 } else if ((j % 8 == 0) ||
\r
3865 (n == psd_scan->psd_stop_point)) {
\r
3866 if (psd_rep2 < 10)
\r
3867 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3868 "%7d.0%d\n", psd_rep1,
\r
3871 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3872 "%7d.%d\n", psd_rep1, psd_rep2);
\r
3874 if (psd_rep2 < 10)
\r
3875 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3876 "%7d.0%d", psd_rep1, psd_rep2);
\r
3878 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
3879 "%7d.%d", psd_rep1, psd_rep2);
\r
3884 CL_PRINTF(cli_buf);
\r
3886 } while ((j <= 8) && (n <= psd_scan->psd_stop_point));
\r
3888 if ((m > psd_scan->psd_stop_point) ||
\r
3889 (n > psd_scan->psd_stop_point))
\r
3902 void halbtc8821c1ant_psd_maxholddata(IN struct btc_coexist *btcoexist,
\r
3905 u32 i = 0, i_max = 0, val_max = 0;
\r
3907 if (gen_count == 1) {
\r
3908 memcpy(psd_scan->psd_report_max_hold,
\r
3909 psd_scan->psd_report,
\r
3910 BT_8821C_1ANT_ANTDET_PSD_POINTS * sizeof(u32));
\r
3912 for (i = psd_scan->psd_start_point;
\r
3913 i <= psd_scan->psd_stop_point; i++) {
\r
3917 psd_scan->psd_max_value_point = 0;
\r
3918 psd_scan->psd_max_value = 0;
\r
3921 for (i = psd_scan->psd_start_point;
\r
3922 i <= psd_scan->psd_stop_point; i++) {
\r
3923 if (psd_scan->psd_report[i] >
\r
3924 psd_scan->psd_report_max_hold[i])
\r
3925 psd_scan->psd_report_max_hold[i] =
\r
3926 psd_scan->psd_report[i];
\r
3928 /* search Max Value */
\r
3929 if (i == psd_scan->psd_start_point) {
\r
3931 val_max = psd_scan->psd_report_max_hold[i];
\r
3933 if (psd_scan->psd_report_max_hold[i] >
\r
3936 val_max = psd_scan->psd_report_max_hold[i];
\r
3943 psd_scan->psd_max_value_point = i_max;
\r
3944 psd_scan->psd_max_value = val_max;
\r
3951 u32 halbtc8821c1ant_psd_getdata(IN struct btc_coexist *btcoexist, IN u32 point)
\r
3953 /* reg 0x808[9:0]: FFT data x */
\r
3954 /* reg 0x808[22]: 0-->1 to get 1 FFT data y */
\r
3955 /* reg 0x8b4[15:0]: FFT data y report */
\r
3957 u32 val = 0, psd_report = 0;
\r
3959 val = btcoexist->btc_read_4byte(btcoexist, 0x808);
\r
3961 val &= 0xffbffc00;
\r
3964 btcoexist->btc_write_4byte(btcoexist, 0x808, val);
\r
3966 val |= 0x00400000;
\r
3967 btcoexist->btc_write_4byte(btcoexist, 0x808, val);
\r
3970 val = btcoexist->btc_read_4byte(btcoexist, 0x8b4);
\r
3972 psd_report = val & 0x0000ffff;
\r
3974 return psd_report;
\r
3978 boolean halbtc8821c1ant_psd_sweep_point(IN struct btc_coexist *btcoexist,
\r
3979 IN u32 cent_freq, IN s32 offset, IN u32 span, IN u32 points,
\r
3980 IN u32 avgnum, IN u32 loopcnt)
\r
3982 u32 i = 0, val = 0, n = 0, k = 0, j, point_index = 0;
\r
3983 u32 points1 = 0, psd_report = 0;
\r
3984 u32 start_p = 0, stop_p = 0, delta_freq_per_point = 156250;
\r
3985 u32 psd_center_freq = 20 * 10 ^ 6;
\r
3986 boolean outloop = false, scan , roam, is_sweep_ok = true;
\r
3988 u32 tmp = 0, u32tmp1 = 0;
\r
3989 u32 wifi_original_channel = 1;
\r
3991 psd_scan->is_psd_running = true;
\r
3992 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
3993 "xxxxxxxxxxxxxxxx PSD Sweep Start!!\n");
\r
3994 BTC_TRACE(trace_buf);
\r
3998 case 0: /* Get PSD parameters */
\r
4001 psd_scan->psd_band_width = 40 * 1000000;
\r
4002 psd_scan->psd_point = points;
\r
4003 psd_scan->psd_start_base = points / 2;
\r
4004 psd_scan->psd_avg_num = avgnum;
\r
4005 psd_scan->real_cent_freq = cent_freq;
\r
4006 psd_scan->real_offset = offset;
\r
4007 psd_scan->real_span = span;
\r
4010 points1 = psd_scan->psd_point;
\r
4011 delta_freq_per_point = psd_scan->psd_band_width /
\r
4012 psd_scan->psd_point;
\r
4014 /* PSD point setup */
\r
4015 val = btcoexist->btc_read_4byte(btcoexist, 0x808);
\r
4016 val &= 0xffff0fff;
\r
4018 switch (psd_scan->psd_point) {
\r
4024 val |= 0x00004000;
\r
4027 val |= 0x00008000;
\r
4030 val |= 0x0000c000;
\r
4034 switch (psd_scan->psd_avg_num) {
\r
4039 val |= 0x00001000;
\r
4042 val |= 0x00002000;
\r
4046 val |= 0x00003000;
\r
4049 btcoexist->btc_write_4byte(btcoexist, 0x808, val);
\r
4053 case 1: /* calculate the PSD point index from freq/offset/span */
\r
4054 psd_center_freq = psd_scan->psd_band_width / 2 +
\r
4055 offset * (1000000);
\r
4057 start_p = psd_scan->psd_start_base + (psd_center_freq -
\r
4058 span * (1000000) / 2) / delta_freq_per_point;
\r
4059 psd_scan->psd_start_point = start_p -
\r
4060 psd_scan->psd_start_base;
\r
4062 stop_p = psd_scan->psd_start_base + (psd_center_freq +
\r
4063 span * (1000000) / 2) / delta_freq_per_point;
\r
4064 psd_scan->psd_stop_point = stop_p -
\r
4065 psd_scan->psd_start_base - 1;
\r
4069 case 2: /* set RF channel/BW/Mode */
\r
4071 /* set 3-wire off */
\r
4072 val = btcoexist->btc_read_4byte(btcoexist, 0x88c);
\r
4073 val |= 0x00300000;
\r
4074 btcoexist->btc_write_4byte(btcoexist, 0x88c, val);
\r
4077 val = btcoexist->btc_read_4byte(btcoexist, 0x800);
\r
4078 val &= 0xfeffffff;
\r
4079 btcoexist->btc_write_4byte(btcoexist, 0x800, val);
\r
4082 btcoexist->btc_write_1byte(btcoexist, 0x522, 0x6f);
\r
4084 /* store WiFi original channel */
\r
4085 wifi_original_channel = btcoexist->btc_get_rf_reg(
\r
4086 btcoexist, BTC_RF_A, 0x18, 0x3ff);
\r
4088 /* Set RF channel */
\r
4089 if (cent_freq == 2484)
\r
4090 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A,
\r
4091 0x18, 0x3ff, 0xe);
\r
4093 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A,
\r
4094 0x18, 0x3ff, (cent_freq - 2412) / 5 +
\r
4095 1); /* WiFi TRx Mask on */
\r
4097 /* save original RCK value */
\r
4098 u32tmp1 = btcoexist->btc_get_rf_reg(
\r
4099 btcoexist, BTC_RF_A, 0x1d, 0xfffff);
\r
4101 /* Enter debug mode */
\r
4102 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xde,
\r
4105 /* Set RF Rx filter corner */
\r
4106 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1d,
\r
4110 /* Set RF mode = Rx, RF Gain = 0x320a0 */
\r
4111 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x0,
\r
4112 0xfffff, 0x320a0);
\r
4115 if (k++ > BT_8821C_1ANT_ANTDET_SWEEPPOINT_DELAY)
\r
4121 psd_scan->psd_gen_count = 0;
\r
4122 for (j = 1; j <= loopcnt; j++) {
\r
4124 btcoexist->btc_get(btcoexist,
\r
4125 BTC_GET_BL_WIFI_SCAN, &scan);
\r
4126 btcoexist->btc_get(btcoexist,
\r
4127 BTC_GET_BL_WIFI_ROAM, &roam);
\r
4129 if (scan || roam) {
\r
4130 is_sweep_ok = false;
\r
4133 memset(psd_scan->psd_report, 0,
\r
4134 psd_scan->psd_point * sizeof(u32));
\r
4135 start_p = psd_scan->psd_start_point +
\r
4136 psd_scan->psd_start_base;
\r
4137 stop_p = psd_scan->psd_stop_point +
\r
4138 psd_scan->psd_start_base + 1;
\r
4143 while (i < stop_p) {
\r
4146 halbtc8821c1ant_psd_getdata(
\r
4147 btcoexist, i - points1);
\r
4150 halbtc8821c1ant_psd_getdata(
\r
4153 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4154 "Point=%d, psd_raw_data = 0x%08x\n",
\r
4156 BTC_TRACE(trace_buf);
\r
4157 if (psd_report == 0)
\r
4160 /* tmp = 20*log10((double)psd_report); */
\r
4161 /* 20*log2(x)/log2(10), log2Base return theresult of the psd_report*100 */
\r
4162 tmp = 6 * halbtc8821c1ant_psd_log2base(
\r
4163 btcoexist, psd_report);
\r
4165 n = i - psd_scan->psd_start_base;
\r
4166 psd_scan->psd_report[n] = tmp;
\r
4169 halbtc8821c1ant_psd_maxholddata(
\r
4176 psd_scan->psd_gen_count = j;
\r
4181 case 99: /* error */
\r
4185 case 100: /* recovery */
\r
4187 /* set 3-wire on */
\r
4188 val = btcoexist->btc_read_4byte(btcoexist, 0x88c);
\r
4189 val &= 0xffcfffff;
\r
4190 btcoexist->btc_write_4byte(btcoexist, 0x88c, val);
\r
4193 val = btcoexist->btc_read_4byte(btcoexist, 0x800);
\r
4194 val |= 0x01000000;
\r
4195 btcoexist->btc_write_4byte(btcoexist, 0x800, val);
\r
4197 /* Tx-pause off */
\r
4198 btcoexist->btc_write_1byte(btcoexist, 0x522, 0x0);
\r
4201 val = btcoexist->btc_read_4byte(btcoexist, 0x808);
\r
4202 val &= 0xffbfffff;
\r
4203 btcoexist->btc_write_4byte(btcoexist, 0x808, val);
\r
4205 /* restore RF Rx filter corner */
\r
4206 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1d,
\r
4207 0xfffff, u32tmp1);
\r
4209 /* Exit debug mode */
\r
4210 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xde,
\r
4213 /* restore WiFi original channel */
\r
4214 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x18,
\r
4215 0x3ff, wifi_original_channel);
\r
4222 } while (!outloop);
\r
4226 psd_scan->is_psd_running = false;
\r
4228 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4229 "xxxxxxxxxxxxxxxx PSD Sweep Stop!!\n");
\r
4230 BTC_TRACE(trace_buf);
\r
4231 return is_sweep_ok;
\r
4236 void halbtc8821c1ant_psd_antenna_detection(IN struct btc_coexist *btcoexist,
\r
4237 IN u32 bt_tx_time, IN u32 bt_le_channel)
\r
4240 u32 wlpsd_cent_freq = 2484, wlpsd_span = 2, wlpsd_sweep_count = 50;
\r
4241 s32 wlpsd_offset = -4;
\r
4242 u8 bt_le_ch[13] = {3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 33};
\r
4244 u8 h2c_parameter[3] = {0}, u8tmpa, u8tmpb;
\r
4247 boolean outloop = false, bt_resp = false;
\r
4248 u32 freq, freq1, freq2, psd_rep1, psd_rep2, delta_freq_per_point,
\r
4249 u32tmp, u32tmp0, u32tmp1, u32tmp2 ;
\r
4250 struct btc_board_info *board_info = &btcoexist->board_info;
\r
4252 board_info->btdm_ant_det_finish = false;
\r
4253 memset(psd_scan->ant_det_peak_val, 0, 16 * sizeof(u8));
\r
4254 memset(psd_scan->ant_det_peak_freq, 0, 16 * sizeof(u8));
\r
4256 if (board_info->tfbga_package) /* for TFBGA */
\r
4257 psd_scan->ant_det_thres_offset = 5;
\r
4259 psd_scan->ant_det_thres_offset = 0;
\r
4264 if (bt_le_channel == 39)
\r
4265 wlpsd_cent_freq = 2484;
\r
4267 for (i = 1; i <= 13; i++) {
\r
4268 if (bt_le_ch[i - 1] ==
\r
4270 wlpsd_cent_freq = 2412
\r
4278 BTC_SPRINTF(trace_buf,
\r
4280 "xxxxxxxxxxxxxxxx AntennaDetect(), Abort!!, Invalid LE channel = %d\n ",
\r
4282 BTC_TRACE(trace_buf);
\r
4288 wlpsd_sweep_count = bt_tx_time * 238 /
\r
4289 100; /* bt_tx_time/0.42 */
\r
4290 wlpsd_sweep_count = wlpsd_sweep_count / 5;
\r
4292 if (wlpsd_sweep_count % 5 != 0)
\r
4293 wlpsd_sweep_count = (wlpsd_sweep_count /
\r
4296 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4297 "xxxxxxxxxxxxxxxx AntennaDetect(), BT_LETxTime=%d, BT_LECh = %d\n",
\r
4298 bt_tx_time, bt_le_channel);
\r
4299 BTC_TRACE(trace_buf);
\r
4300 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4301 "xxxxxxxxxxxxxxxx AntennaDetect(), wlpsd_cent_freq=%d, wlpsd_offset = %d, wlpsd_span = %d, wlpsd_sweep_count = %d\n",
\r
4305 wlpsd_sweep_count);
\r
4306 BTC_TRACE(trace_buf);
\r
4310 case 1: /* stop coex DM & set antenna path */
\r
4311 /* Stop Coex DM */
\r
4312 btcoexist->stop_coex_dm = true;
\r
4314 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4315 "xxxxxxxxxxxxxxxx AntennaDetect(), Stop Coex DM!!\n");
\r
4316 BTC_TRACE(trace_buf);
\r
4318 /* Set TDMA off, */
\r
4319 halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC,
\r
4322 /* Set coex table */
\r
4323 halbtc8821c1ant_coex_table_with_type(btcoexist,
\r
4326 if (board_info->btdm_ant_pos ==
\r
4327 BTC_ANTENNA_AT_MAIN_PORT) {
\r
4328 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4329 "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Main Port\n");
\r
4330 BTC_TRACE(trace_buf);
\r
4332 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4333 "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Aux Port\n");
\r
4334 BTC_TRACE(trace_buf);
\r
4337 halbtc8821c1ant_set_int_block(btcoexist, FORCE_EXEC, BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG);
\r
4339 halbtc8821c1ant_set_ext_ant_switch( btcoexist,
\r
4341 BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
\r
4342 BT_8821C_1ANT_EXT_ANT_SWITCH_TO_BT);
\r
4344 /* Set Antenna Path, both GNT_WL/GNT_BT = 1, and control by SW */
\r
4345 /* set GNT_BT to SW high */
\r
4346 halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
\r
4347 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
4348 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
\r
4349 BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
\r
4350 /* Set GNT_WL to SW high */
\r
4351 halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
\r
4352 BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
\r
4353 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
\r
4354 BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
\r
4356 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4357 "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to BT!!\n");
\r
4358 BTC_TRACE(trace_buf);
\r
4360 /* Set AFH mask on at WiFi channel 2472MHz +/- 10MHz */
\r
4361 h2c_parameter[0] = 0x1;
\r
4362 h2c_parameter[1] = 0xd;
\r
4363 h2c_parameter[2] = 0x14;
\r
4365 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4366 "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n",
\r
4368 h2c_parameter[2]);
\r
4369 BTC_TRACE(trace_buf);
\r
4371 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3,
\r
4374 u32tmp0 = btcoexist->btc_read_4byte(btcoexist, 0x70);
\r
4375 u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
\r
4376 u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
\r
4378 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4379 "[BTCoex], ********** 0x70 = 0x%x, 0x38= 0x%x, 0x54= 0x%x (Before Ant Det) **********\n",
\r
4380 u32tmp0, u32tmp1, u32tmp2);
\r
4381 BTC_TRACE(trace_buf);
\r
4385 case 2: /* Pre-sweep background psd */
\r
4386 if (!halbtc8821c1ant_psd_sweep_point(btcoexist,
\r
4387 wlpsd_cent_freq, wlpsd_offset, wlpsd_span,
\r
4388 BT_8821C_1ANT_ANTDET_PSD_POINTS,
\r
4389 BT_8821C_1ANT_ANTDET_PSD_AVGNUM, 3)) {
\r
4390 board_info->btdm_ant_det_finish = false;
\r
4391 board_info->btdm_ant_num_by_ant_det = 1;
\r
4392 psd_scan->ant_det_result = 8;
\r
4397 psd_scan->ant_det_pre_psdscan_peak_val =
\r
4398 psd_scan->psd_max_value;
\r
4400 if (psd_scan->psd_max_value >
\r
4401 (BT_8821C_1ANT_ANTDET_PSDTHRES_BACKGROUND
\r
4402 + psd_scan->ant_det_thres_offset) * 100) {
\r
4403 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4404 "xxxxxxxxxxxxxxxx AntennaDetect(), Abort Antenna Detection!! becaus background = %d > thres (%d)\n",
\r
4405 psd_scan->psd_max_value / 100,
\r
4406 BT_8821C_1ANT_ANTDET_PSDTHRES_BACKGROUND
\r
4407 + psd_scan->ant_det_thres_offset);
\r
4408 BTC_TRACE(trace_buf);
\r
4409 board_info->btdm_ant_det_finish = false;
\r
4410 board_info->btdm_ant_num_by_ant_det = 1;
\r
4411 psd_scan->ant_det_result = 5;
\r
4414 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4415 "xxxxxxxxxxxxxxxx AntennaDetect(), Start Antenna Detection!! becaus background = %d <= thres (%d)\n",
\r
4416 psd_scan->psd_max_value / 100,
\r
4417 BT_8821C_1ANT_ANTDET_PSDTHRES_BACKGROUND
\r
4418 + psd_scan->ant_det_thres_offset);
\r
4419 BTC_TRACE(trace_buf);
\r
4425 bt_resp = btcoexist->btc_set_bt_ant_detection(
\r
4426 btcoexist, (u8)(bt_tx_time & 0xff),
\r
4427 (u8)(bt_le_channel & 0xff));
\r
4429 if (!halbtc8821c1ant_psd_sweep_point(btcoexist,
\r
4430 wlpsd_cent_freq, wlpsd_offset,
\r
4432 BT_8821C_1ANT_ANTDET_PSD_POINTS,
\r
4433 BT_8821C_1ANT_ANTDET_PSD_AVGNUM,
\r
4434 wlpsd_sweep_count)) {
\r
4435 board_info->btdm_ant_det_finish
\r
4437 board_info->btdm_ant_num_by_ant_det
\r
4439 psd_scan->ant_det_result = 8;
\r
4444 psd_scan->ant_det_psd_scan_peak_val =
\r
4445 psd_scan->psd_max_value;
\r
4446 psd_scan->ant_det_psd_scan_peak_freq =
\r
4447 psd_scan->psd_max_value_point;
\r
4452 if (psd_scan->psd_point == 0)
\r
4453 delta_freq_per_point = 0;
\r
4455 delta_freq_per_point =
\r
4456 psd_scan->psd_band_width /
\r
4457 psd_scan->psd_point;
\r
4459 psd_rep1 = psd_scan->psd_max_value / 100;
\r
4460 psd_rep2 = psd_scan->psd_max_value - psd_rep1 *
\r
4463 freq = ((psd_scan->real_cent_freq - 20) *
\r
4464 1000000 + psd_scan->psd_max_value_point
\r
4465 * delta_freq_per_point);
\r
4466 freq1 = freq / 1000000;
\r
4467 freq2 = freq / 1000 - freq1 * 1000;
\r
4469 if (freq2 < 100) {
\r
4470 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4471 "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.0%d MHz",
\r
4473 BTC_TRACE(trace_buf);
\r
4474 CL_SPRINTF(psd_scan->ant_det_peak_freq,
\r
4475 BT_8821C_1ANT_ANTDET_BUF_LEN,
\r
4476 "%d.0%d", freq1, freq2);
\r
4478 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4479 "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.%d MHz",
\r
4481 BTC_TRACE(trace_buf);
\r
4482 CL_SPRINTF(psd_scan->ant_det_peak_freq,
\r
4483 BT_8821C_1ANT_ANTDET_BUF_LEN,
\r
4484 "%d.%d", freq1, freq2);
\r
4487 if (psd_rep2 < 10) {
\r
4488 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4489 ", Value = %d.0%d dB\n",
\r
4490 psd_rep1, psd_rep2);
\r
4491 BTC_TRACE(trace_buf);
\r
4492 CL_SPRINTF(psd_scan->ant_det_peak_val,
\r
4493 BT_8821C_1ANT_ANTDET_BUF_LEN,
\r
4494 "%d.0%d", psd_rep1, psd_rep2);
\r
4496 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4497 ", Value = %d.%d dB\n",
\r
4498 psd_rep1, psd_rep2);
\r
4499 BTC_TRACE(trace_buf);
\r
4500 CL_SPRINTF(psd_scan->ant_det_peak_val,
\r
4501 BT_8821C_1ANT_ANTDET_BUF_LEN,
\r
4502 "%d.%d", psd_rep1, psd_rep2);
\r
4505 psd_scan->ant_det_is_btreply_available = true;
\r
4507 if (bt_resp == false) {
\r
4508 psd_scan->ant_det_is_btreply_available =
\r
4510 psd_scan->ant_det_result = 0;
\r
4511 board_info->btdm_ant_det_finish = false;
\r
4512 board_info->btdm_ant_num_by_ant_det = 1;
\r
4513 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4514 "xxxxxxxxxxxxxxxx AntennaDetect(), BT Response = Fail\n ");
\r
4515 BTC_TRACE(trace_buf);
\r
4516 } else if (psd_scan->psd_max_value >
\r
4517 (BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION)
\r
4519 psd_scan->ant_det_result = 1;
\r
4520 board_info->btdm_ant_det_finish = true;
\r
4521 board_info->btdm_ant_num_by_ant_det = 2;
\r
4522 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4523 "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Bad-Isolation!!\n");
\r
4524 BTC_TRACE(trace_buf);
\r
4525 } else if (psd_scan->psd_max_value >
\r
4526 (BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION
\r
4527 + psd_scan->ant_det_thres_offset) * 100) {
\r
4528 psd_scan->ant_det_result = 2;
\r
4529 board_info->btdm_ant_det_finish = true;
\r
4530 board_info->btdm_ant_num_by_ant_det = 2;
\r
4531 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4532 "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Good-Isolation!!\n");
\r
4533 BTC_TRACE(trace_buf);
\r
4534 } else if (psd_scan->psd_max_value >
\r
4535 (BT_8821C_1ANT_ANTDET_PSDTHRES_1ANT) *
\r
4537 psd_scan->ant_det_result = 3;
\r
4538 board_info->btdm_ant_det_finish = true;
\r
4539 board_info->btdm_ant_num_by_ant_det = 1;
\r
4540 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4541 "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant!!\n");
\r
4542 BTC_TRACE(trace_buf);
\r
4544 psd_scan->ant_det_result = 4;
\r
4545 board_info->btdm_ant_det_finish = false;
\r
4546 board_info->btdm_ant_num_by_ant_det = 1;
\r
4547 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4548 "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant, un-certainity!!\n");
\r
4549 BTC_TRACE(trace_buf);
\r
4554 case 99: /* restore setup */
\r
4556 /* Set AFH mask off at WiFi channel 2472MHz +/- 10MHz */
\r
4557 h2c_parameter[0] = 0x0;
\r
4558 h2c_parameter[1] = 0x0;
\r
4559 h2c_parameter[2] = 0x0;
\r
4561 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4562 "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n",
\r
4563 h2c_parameter[1], h2c_parameter[2]);
\r
4564 BTC_TRACE(trace_buf);
\r
4566 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3,
\r
4569 /* Set Antenna Path, GNT_WL/GNT_BT control by PTA */
\r
4570 halbtc8821c1ant_set_ant_path(btcoexist,
\r
4571 BTC_ANT_PATH_AUTO,
\r
4573 BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
4575 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4576 "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to PTA\n!!");
\r
4577 BTC_TRACE(trace_buf);
\r
4579 /* Resume Coex DM */
\r
4580 btcoexist->stop_coex_dm = false;
\r
4581 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4582 "xxxxxxxxxxxxxxxx AntennaDetect(), Resume Coex DM\n!!");
\r
4583 BTC_TRACE(trace_buf);
\r
4585 /* stimulate coex running */
\r
4586 halbtc8821c1ant_run_coexist_mechanism(
\r
4588 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4589 "xxxxxxxxxxxxxxxx AntennaDetect(), Stimulate Coex running\n!!");
\r
4590 BTC_TRACE(trace_buf);
\r
4596 } while (!outloop);
\r
4602 void halbtc8821c1ant_psd_antenna_detection_check(IN struct btc_coexist
\r
4605 static u32 ant_det_count = 0, ant_det_fail_count = 0;
\r
4606 struct btc_board_info *board_info = &btcoexist->board_info;
\r
4608 boolean scan, roam;
\r
4610 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
\r
4611 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
\r
4614 /* psd_scan->ant_det_bt_tx_time = 20; */
\r
4615 psd_scan->ant_det_bt_tx_time =
\r
4616 BT_8821C_1ANT_ANTDET_BTTXTIME; /* 0.42ms*50 = 20ms (0.42ms = 1 PSD sweep) */
\r
4617 psd_scan->ant_det_bt_le_channel = BT_8821C_1ANT_ANTDET_BTTXCHANNEL;
\r
4621 psd_scan->ant_det_try_count = ant_det_count;
\r
4623 if (scan || roam) {
\r
4624 board_info->btdm_ant_det_finish = false;
\r
4625 psd_scan->ant_det_result = 6;
\r
4626 } else if (coex_sta->bt_disabled) {
\r
4627 board_info->btdm_ant_det_finish = false;
\r
4628 psd_scan->ant_det_result = 11;
\r
4629 } else if (coex_sta->num_of_profile >= 1) {
\r
4630 board_info->btdm_ant_det_finish = false;
\r
4631 psd_scan->ant_det_result = 7;
\r
4633 !psd_scan->ant_det_is_ant_det_available) { /* Antenna initial setup is not ready */
\r
4634 board_info->btdm_ant_det_finish = false;
\r
4635 psd_scan->ant_det_result = 9;
\r
4636 } else if (coex_sta->c2h_bt_inquiry_page) {
\r
4637 board_info->btdm_ant_det_finish = false;
\r
4638 psd_scan->ant_det_result = 10;
\r
4641 btcoexist->stop_coex_dm = true;
\r
4643 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4644 "xxxxxxxxxxxxxxxx AntennaDetect(), Stop Coex DM!!\n");
\r
4645 BTC_TRACE(trace_buf);
\r
4647 halbtc8821c1ant_psd_antenna_detection(btcoexist,
\r
4648 psd_scan->ant_det_bt_tx_time,
\r
4649 psd_scan->ant_det_bt_le_channel);
\r
4651 delay_ms(psd_scan->ant_det_bt_tx_time);
\r
4653 btcoexist->stop_coex_dm = false;
\r
4655 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4656 "xxxxxxxxxxxxxxxx AntennaDetect(), Resume Coex DM\n!!");
\r
4657 BTC_TRACE(trace_buf);
\r
4659 /* stimulate coex running */
\r
4661 halbtc8821c1ant_run_coexist_mechanism(
\r
4663 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4664 "xxxxxxxxxxxxxxxx AntennaDetect(), Stimulate Coex running\n!!");
\r
4665 BTC_TRACE(trace_buf);
\r
4669 if (!board_info->btdm_ant_det_finish)
\r
4670 ant_det_fail_count++;
\r
4672 psd_scan->ant_det_fail_count = ant_det_fail_count;
\r
4674 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4675 "xxxxxxxxxxxxxxxx AntennaDetect(), result = %d, fail_count = %d, finish = %s\n",
\r
4676 psd_scan->ant_det_result,
\r
4677 psd_scan->ant_det_fail_count,
\r
4678 board_info->btdm_ant_det_finish == TRUE ? "Yes" : "No");
\r
4679 BTC_TRACE(trace_buf);
\r
4684 /* ************************************************************
\r
4685 * work around function start with wa_halbtc8821c1ant_
\r
4686 * ************************************************************
\r
4687 * ************************************************************
\r
4688 * extern function start with ex_halbtc8821c1ant_
\r
4689 * ************************************************************ */
\r
4690 void ex_halbtc8821c1ant_power_on_setting(IN struct btc_coexist *btcoexist)
\r
4692 struct btc_board_info *board_info = &btcoexist->board_info;
\r
4697 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4698 "xxxxxxxxxxxxxxxx Execute 8821c 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n");
\r
4699 BTC_TRACE(trace_buf);
\r
4701 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4702 "Ant Det Finish = %s, Ant Det Number = %d\n",
\r
4703 (board_info->btdm_ant_det_finish ? "Yes" : "No"),
\r
4704 board_info->btdm_ant_num_by_ant_det);
\r
4705 BTC_TRACE(trace_buf);
\r
4707 btcoexist->stop_coex_dm = true;
\r
4708 psd_scan->ant_det_is_ant_det_available = FALSE;
\r
4710 /* enable BB, REG_SYS_FUNC_EN such that we can write BB Register correctly. */
\r
4711 u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
\r
4712 btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
\r
4714 /* Local setting bit define */
\r
4715 /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
\r
4716 /* BIT1: "0" for internal switch; "1" for external switch */
\r
4717 /* BIT2: "0" for one antenna; "1" for two antenna */
\r
4718 /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */
\r
4720 /* Check efuse 0xc3[6] for Single Antenna Path */
\r
4721 if (board_info->single_ant_path == 0) {
\r
4722 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4723 "[BTCoex], ********** Single Antenna, Antenna at Aux Port**********\n");
\r
4724 BTC_TRACE(trace_buf);
\r
4726 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
\r
4729 } else if (board_info->single_ant_path == 1) {
\r
4730 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4731 "[BTCoex], ********** Single Antenna, Antenna at Main Port**********\n");
\r
4732 BTC_TRACE(trace_buf);
\r
4734 board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
\r
4740 /* Save"single antenna position" info in Local register setting for FW reading, because FW may not ready at power on */
\r
4741 if (btcoexist->chip_interface == BTC_INTF_PCI)
\r
4742 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, u8tmp);
\r
4743 else if (btcoexist->chip_interface == BTC_INTF_USB)
\r
4744 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
\r
4745 else if (btcoexist->chip_interface == BTC_INTF_SDIO)
\r
4746 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp);
\r
4748 /* Setup RF front end type */
\r
4749 halbtc8821c1ant_set_rfe_type(btcoexist);
\r
4751 /* Set Antenna Path to BT side */
\r
4752 halbtc8821c1ant_set_ant_path(btcoexist,
\r
4753 BTC_ANT_PATH_AUTO,
\r
4755 BT_8821C_1ANT_PHASE_COEX_INIT);
\r
4757 /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */
\r
4758 halbtc8821c1ant_enable_gnt_to_gpio(btcoexist, TRUE);
\r
4760 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4761 "[BTCoex], ********** LTE coex Reg 0x38 (Power-On) = 0x%x**********\n",
\r
4762 halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38));
\r
4763 BTC_TRACE(trace_buf);
\r
4765 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4766 "[BTCoex], ********** MAC Reg 0x70/ BB Reg 0xcb4 (Power-On) = 0x%x / 0x%x**********\n",
\r
4767 btcoexist->btc_read_4byte(btcoexist, 0x70), btcoexist->btc_read_4byte(btcoexist, 0xcb4));
\r
4768 BTC_TRACE(trace_buf);
\r
4772 void ex_halbtc8821c1ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
\r
4776 void ex_halbtc8821c1ant_init_hw_config(IN struct btc_coexist *btcoexist,
\r
4777 IN boolean wifi_only)
\r
4779 halbtc8821c1ant_init_hw_config(btcoexist, true, wifi_only);
\r
4780 btcoexist->stop_coex_dm = false;
\r
4784 void ex_halbtc8821c1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
\r
4786 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
4787 "[BTCoex], Coex Mechanism Init!!\n");
\r
4788 BTC_TRACE(trace_buf);
\r
4790 halbtc8821c1ant_init_coex_dm(btcoexist);
\r
4792 /* halbtc8821c1ant_query_bt_info(btcoexist); */
\r
4795 void ex_halbtc8821c1ant_display_coex_info(IN struct btc_coexist *btcoexist)
\r
4797 struct btc_board_info *board_info = &btcoexist->board_info;
\r
4798 struct btc_stack_info *stack_info = &btcoexist->stack_info;
\r
4799 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
\r
4800 u8 *cli_buf = btcoexist->cli_buf;
\r
4801 u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
\r
4804 u32 fa_of_dm, fa_cck;
\r
4805 u32 fw_ver = 0, bt_patch_ver = 0;
\r
4806 static u8 pop_report_in_10s = 0;
\r
4808 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4809 "\r\n ============[BT Coexist info]============");
\r
4810 CL_PRINTF(cli_buf);
\r
4812 if (btcoexist->manual_control) {
\r
4813 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4814 "\r\n ============[Under Manual Control]============");
\r
4815 CL_PRINTF(cli_buf);
\r
4816 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4817 "\r\n ==========================================");
\r
4818 CL_PRINTF(cli_buf);
\r
4820 if (btcoexist->stop_coex_dm) {
\r
4821 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4822 "\r\n ============[Coex is STOPPED]============");
\r
4823 CL_PRINTF(cli_buf);
\r
4824 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4825 "\r\n ==========================================");
\r
4826 CL_PRINTF(cli_buf);
\r
4829 if (psd_scan->ant_det_try_count == 0) {
\r
4830 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s / %d",
\r
4831 "Ant PG Num/ Mech/ Pos/ RFE",
\r
4832 board_info->pg_ant_num, board_info->btdm_ant_num,
\r
4833 (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT? "Main" : "Aux"),
\r
4834 rfe_type->rfe_module_type);
\r
4835 CL_PRINTF(cli_buf);
\r
4837 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4838 "\r\n %-35s = %d/ %d/ %s/ %d (%d/%d/%d)",
\r
4839 "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
\r
4840 board_info->pg_ant_num, board_info->btdm_ant_num_by_ant_det,
\r
4841 (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT ? "Main" : "Aux"),
\r
4842 rfe_type->rfe_module_type,
\r
4843 psd_scan->ant_det_try_count, psd_scan->ant_det_fail_count,
\r
4844 psd_scan->ant_det_result);
\r
4845 CL_PRINTF(cli_buf);
\r
4847 if (board_info->btdm_ant_det_finish) {
\r
4848 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
\r
4849 "Ant Det PSD Value",
\r
4850 psd_scan->ant_det_peak_val);
\r
4851 CL_PRINTF(cli_buf);
\r
4855 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d",
\r
4856 "BT stack/ hci ext ver",
\r
4857 ((stack_info->profile_notified) ? "Yes" : "No"),
\r
4858 stack_info->hci_version);
\r
4859 CL_PRINTF(cli_buf);
\r
4861 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
\r
4862 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
\r
4863 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4864 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)/ %c",
\r
4865 "Version Coex/ Fw/ Patch/ Cut",
\r
4866 glcoex_ver_date_8821c_1ant, glcoex_ver_8821c_1ant, fw_ver,
\r
4867 bt_patch_ver, bt_patch_ver, coex_sta->cut_version + 65);
\r
4868 CL_PRINTF(cli_buf);
\r
4870 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
\r
4871 "Wifi channel informed to BT",
\r
4872 coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
\r
4873 coex_dm->wifi_chnl_info[2]);
\r
4874 CL_PRINTF(cli_buf);
\r
4875 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s",
\r
4876 "WifibHiPri/ Ccklock/ CckEverLock",
\r
4877 (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"),
\r
4878 (coex_sta->cck_lock ? "Yes" : "No"),
\r
4879 (coex_sta->cck_ever_lock ? "Yes" : "No"));
\r
4880 CL_PRINTF(cli_buf);
\r
4883 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
\r
4884 "============[Wifi Status]============");
\r
4885 CL_PRINTF(cli_buf);
\r
4886 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
\r
4888 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
\r
4889 "============[BT Status]============");
\r
4890 CL_PRINTF(cli_buf);
\r
4892 pop_report_in_10s++;
\r
4893 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ",
\r
4894 "BT [status/ rssi/ retryCnt/ popCnt]",
\r
4895 ((coex_sta->bt_disabled) ? ("disabled") : ((
\r
4896 coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page")
\r
4897 : ((BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
\r
4898 coex_dm->bt_status) ? "non-connected idle" :
\r
4899 ((BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
\r
4900 ? "connected-idle" : "busy")))),
\r
4901 coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
\r
4902 coex_sta->pop_event_cnt);
\r
4903 CL_PRINTF(cli_buf);
\r
4905 if (pop_report_in_10s >= 5) {
\r
4906 coex_sta->pop_event_cnt = 0;
\r
4907 pop_report_in_10s = 0;
\r
4910 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4911 "\r\n %-35s = %d / %d / %d / %d / %d",
\r
4912 "SCO/HID/PAN/A2DP/Hi-Pri",
\r
4913 bt_link_info->sco_exist, bt_link_info->hid_exist,
\r
4914 bt_link_info->pan_exist, bt_link_info->a2dp_exist,
\r
4915 bt_link_info->bt_hi_pri_link_exist);
\r
4916 CL_PRINTF(cli_buf);
\r
4918 if (stack_info->profile_notified)
\r
4919 btcoexist->btc_disp_dbg_msg(btcoexist,
\r
4920 BTC_DBG_DISP_BT_LINK_INFO);
\r
4922 bt_info_ext = coex_sta->bt_info_ext;
\r
4924 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s / %d/ %x/ %04x",
\r
4925 "Role/A2DP Rate/Bitpool/Feature/Ver",
\r
4926 ((bt_link_info->slave_role) ? "Slave" : "Master"),
\r
4927 (bt_info_ext & BIT(0)) ? "BR" : "EDR", coex_sta->a2dp_bit_pool,
\r
4928 coex_sta->bt_coex_supported_feature,
\r
4929 coex_sta->bt_coex_supported_version);
\r
4930 CL_PRINTF(cli_buf);
\r
4934 for (i = 0; i < BT_INFO_SRC_8821C_1ANT_MAX; i++) {
\r
4935 if (coex_sta->bt_info_c2h_cnt[i]) {
\r
4936 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4937 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
\r
4938 glbt_info_src_8821c_1ant[i],
\r
4939 coex_sta->bt_info_c2h[i][0],
\r
4940 coex_sta->bt_info_c2h[i][1],
\r
4941 coex_sta->bt_info_c2h[i][2],
\r
4942 coex_sta->bt_info_c2h[i][3],
\r
4943 coex_sta->bt_info_c2h[i][4],
\r
4944 coex_sta->bt_info_c2h[i][5],
\r
4945 coex_sta->bt_info_c2h[i][6],
\r
4946 coex_sta->bt_info_c2h_cnt[i]);
\r
4947 CL_PRINTF(cli_buf);
\r
4952 if (btcoexist->manual_control)
\r
4953 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
\r
4954 "============[mechanisms] (before Manual)============");
\r
4956 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
\r
4957 "============[mechanisms]============");
\r
4959 CL_PRINTF(cli_buf);
\r
4961 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
\r
4962 "SM[LowPenaltyRA]",
\r
4963 coex_dm->cur_low_penalty_ra);
\r
4964 CL_PRINTF(cli_buf);
\r
4966 ps_tdma_case = coex_dm->cur_ps_tdma;
\r
4967 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4968 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)",
\r
4970 coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
\r
4971 coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
\r
4972 coex_dm->ps_tdma_para[4], ps_tdma_case,
\r
4973 (coex_dm->cur_ps_tdma_on ? "On" : "Off"),
\r
4974 (coex_dm->auto_tdma_adjust ? "Adj" : "Fix"));
\r
4976 CL_PRINTF(cli_buf);
\r
4978 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
\r
4979 "WL/BT Coex Table Type",
\r
4980 coex_sta->coex_table_type);
\r
4981 CL_PRINTF(cli_buf);
\r
4983 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
\r
4984 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
\r
4985 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
\r
4986 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4987 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
\r
4988 "0x6c0/0x6c4/0x6c8(coexTable)",
\r
4989 u32tmp[0], u32tmp[1], u32tmp[2]);
\r
4990 CL_PRINTF(cli_buf);
\r
4992 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
\r
4993 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
\r
4994 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
4995 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
\r
4996 "0x778/0x6cc/IgnWlanAct",
\r
4997 u8tmp[0], u32tmp[0], coex_dm->cur_ignore_wlan_act);
\r
4998 CL_PRINTF(cli_buf);
\r
5000 u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
\r
5002 u32tmp[1] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
\r
5005 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
\r
5006 "LTE Coex Table W_L/B_L",
\r
5007 u32tmp[0] & 0xffff, u32tmp[1] & 0xffff);
\r
5008 CL_PRINTF(cli_buf);
\r
5010 u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
\r
5012 u32tmp[1] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
\r
5014 u32tmp[2] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
\r
5016 u32tmp[3] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
\r
5019 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
5020 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
\r
5021 "LTE Break Table W_L/B_L/L_W/L_B",
\r
5022 u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
\r
5023 u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
\r
5024 CL_PRINTF(cli_buf);
\r
5027 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
\r
5028 "============[Hw setting]============");
\r
5029 CL_PRINTF(cli_buf);
\r
5032 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
\r
5033 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
\r
5034 u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
\r
5035 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
\r
5036 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
\r
5037 "0x430/0x434/0x42a/0x456",
\r
5038 u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
\r
5039 CL_PRINTF(cli_buf);
\r
5042 u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
\r
5043 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73);
\r
5045 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %s",
\r
5046 "LTE CoexOn/Path Ctrl Owner",
\r
5047 (int)((u32tmp[0] & BIT(7)) >> 7), ((u8tmp[0] & BIT(2)) ? "WL" : "BT"));
\r
5048 CL_PRINTF(cli_buf);
\r
5050 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
\r
5051 "LTE 3Wire/OPMode/UART/UARTMode",
\r
5052 (int)((u32tmp[0] & BIT(6)) >> 6), (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
\r
5053 (int)((u32tmp[0] & BIT(3)) >> 3),
\r
5054 (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
\r
5055 CL_PRINTF(cli_buf);
\r
5057 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s",
\r
5058 "GNT_WL_SWCtrl/GNT_BT_SWCtrl/Dbg",
\r
5059 (int)((u32tmp[0] & BIT(12)) >> 12), (int)((u32tmp[0] & BIT(14)) >> 14),
\r
5060 ((u8tmp[0] & BIT(3)) ? "On" : "Off"));
\r
5061 CL_PRINTF(cli_buf);
\r
5063 u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
\r
5065 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
\r
5066 "GNT_WL/GNT_BT/LTE_Busy/UART_Busy",
\r
5067 (int)((u32tmp[0] & BIT(2)) >> 2), (int)((u32tmp[0] & BIT(3)) >> 3),
\r
5068 (int)((u32tmp[0] & BIT(1)) >> 1), (int)(u32tmp[0] & BIT(0)));
\r
5069 CL_PRINTF(cli_buf);
\r
5072 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb0);
\r
5073 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
\r
5074 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcba);
\r
5076 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%04x/ 0x%04x/ 0x%02x %s",
\r
5077 "0xcb0/0xcb4/0xcb8[23:16]",
\r
5078 u32tmp[0], u32tmp[1],u8tmp[0], ( (u8tmp[0] & 0x5) == 0x1 ? "BTG": ( (u8tmp[0] & 0xf0) == 0x70? "WL_G" : "WL_A" ) ));
\r
5079 CL_PRINTF(cli_buf);
\r
5081 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
\r
5082 u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
\r
5083 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6);
\r
5084 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
\r
5086 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
\r
5087 "0x4c[24:23]/0x64[0]/x4c6[4]/0x40[5]",
\r
5088 (u32tmp[0] & ( BIT(24) | BIT(23) )) >> 23 , u8tmp[2]&0x1 , (int)((u8tmp[0] & BIT(4)) >> 4), (int)((u8tmp[1] & BIT(5)) >> 5));
\r
5089 CL_PRINTF(cli_buf);
\r
5091 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
\r
5092 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
\r
5093 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953);
\r
5094 u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50);
\r
5096 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x",
\r
5097 "0x550/0x522/4-RxAGC/0xc50",
\r
5098 u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off", u8tmp[2]);
\r
5099 CL_PRINTF(cli_buf);
\r
5101 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48);
\r
5102 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xf4c);
\r
5103 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xf08);
\r
5105 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
\r
5106 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5d);
\r
5108 fa_of_dm = (u32tmp[0] & 0xffff) + (u32tmp[1] & 0xffff);
\r
5110 fa_cck = (u8tmp[0] << 8) + u8tmp[1];
\r
5112 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
\r
5113 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
\r
5114 "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
\r
5115 u32tmp[2] & 0xffff, fa_cck, ((u32tmp[2] & 0xffff0000) >> 16), fa_of_dm);
\r
5116 CL_PRINTF(cli_buf);
\r
5119 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
\r
5120 "CRC_OK CCK/11g/11n/11ac",
\r
5121 coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
\r
5122 coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_agg);
\r
5123 CL_PRINTF(cli_buf);
\r
5125 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
\r
5126 "CRC_Err CCK/11g/11n/11ac",
\r
5127 coex_sta->crc_err_cck, coex_sta->crc_err_11g,
\r
5128 coex_sta->crc_err_11n, coex_sta->crc_err_11n_agg);
\r
5129 CL_PRINTF(cli_buf);
\r
5131 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
\r
5132 "0x770(high-pri rx/tx)",
\r
5133 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
\r
5134 CL_PRINTF(cli_buf);
\r
5135 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
\r
5136 "0x774(low-pri rx/tx)",
\r
5137 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
\r
5138 CL_PRINTF(cli_buf);
\r
5140 halbtc8821c1ant_read_score_board(btcoexist, &u16tmp[0]);
\r
5142 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %04x",
\r
5143 "ScoreBoard[14:0] (from BT)", u16tmp[0]);
\r
5144 CL_PRINTF(cli_buf);
\r
5146 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
\r
5150 void ex_halbtc8821c1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
\r
5152 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
\r
5155 if (BTC_IPS_ENTER == type) {
\r
5156 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5157 "[BTCoex], IPS ENTER notify\n");
\r
5158 BTC_TRACE(trace_buf);
\r
5159 coex_sta->under_ips = true;
\r
5161 /* Write WL "Active" in Score-board for LPS off */
\r
5162 halbtc8821c1ant_post_activestate_to_bt(btcoexist, false);
\r
5164 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
\r
5166 halbtc8821c1ant_set_ant_path(btcoexist,
\r
5167 BTC_ANT_PATH_AUTO,
\r
5169 BT_8821C_1ANT_PHASE_WLAN_OFF);
\r
5171 halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
\r
5172 } else if (BTC_IPS_LEAVE == type) {
\r
5173 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5174 "[BTCoex], IPS LEAVE notify\n");
\r
5175 BTC_TRACE(trace_buf);
\r
5176 halbtc8821c1ant_post_activestate_to_bt(btcoexist, true);
\r
5178 halbtc8821c1ant_init_hw_config(btcoexist, false, false);
\r
5179 halbtc8821c1ant_init_coex_dm(btcoexist);;
\r
5181 coex_sta->under_ips = false;
\r
5185 void ex_halbtc8821c1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
\r
5187 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
\r
5190 if (BTC_LPS_ENABLE == type) {
\r
5191 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5192 "[BTCoex], LPS ENABLE notify\n");
\r
5193 BTC_TRACE(trace_buf);
\r
5194 coex_sta->under_lps = true;
\r
5196 if (coex_sta->force_lps_on == true) { /* LPS No-32K */
\r
5197 /* Write WL "Active" in Score-board for PS-TDMA */
\r
5198 halbtc8821c1ant_post_activestate_to_bt(btcoexist, true);
\r
5200 } else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */
\r
5201 /* Write WL "Non-Active" in Score-board for Native-PS */
\r
5202 halbtc8821c1ant_post_activestate_to_bt(btcoexist, false);
\r
5205 } else if (BTC_LPS_DISABLE == type) {
\r
5206 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5207 "[BTCoex], LPS DISABLE notify\n");
\r
5208 BTC_TRACE(trace_buf);
\r
5209 coex_sta->under_lps = false;
\r
5211 /* Write WL "Active" in Score-board for LPS off */
\r
5212 halbtc8821c1ant_post_activestate_to_bt(btcoexist, true);
\r
5217 void ex_halbtc8821c1ant_scan_notify(IN struct btc_coexist *btcoexist,
\r
5220 boolean wifi_connected = false;
\r
5224 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5225 "[BTCoex], SCAN notify()\n");
\r
5226 BTC_TRACE(trace_buf);
\r
5228 halbtc8821c1ant_post_activestate_to_bt(btcoexist, true);
\r
5230 if (btcoexist->manual_control ||
\r
5231 btcoexist->stop_coex_dm)
\r
5234 if (BTC_SCAN_START == type) //for dual band, no action for BTC_SCAN_START, the action is change to switchband_notify
\r
5237 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
\r
5240 halbtc8821c1ant_query_bt_info(btcoexist);
\r
5242 if (BTC_SCAN_START_2G == type) {
\r
5244 if (!wifi_connected)
\r
5245 coex_sta->wifi_is_high_pri_task = true;
\r
5247 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5248 "[BTCoex], SCAN START notify (2G)\n");
\r
5249 BTC_TRACE(trace_buf);
\r
5251 halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
\r
5254 /* Force antenna setup for no scan result issue */
\r
5255 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
\r
5256 FORCE_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
5258 if (!wifi_connected) /* non-connected scan */
\r
5259 halbtc8821c1ant_action_wifi_not_connected_scan(btcoexist);
\r
5260 else /* wifi is connected */
\r
5261 halbtc8821c1ant_action_wifi_connected_scan(btcoexist);
\r
5265 coex_sta->wifi_is_high_pri_task = false;
\r
5267 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
\r
5268 &coex_sta->scan_ap_num);
\r
5270 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5271 "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n", coex_sta->scan_ap_num);
\r
5272 BTC_TRACE(trace_buf);
\r
5274 if (!wifi_connected)
\r
5275 halbtc8821c1ant_action_wifi_not_connected(btcoexist);
\r
5277 halbtc8821c1ant_action_wifi_connected(btcoexist);
\r
5283 void ex_halbtc8821c1ant_switchband_notify(IN struct btc_coexist *btcoexist,
\r
5287 boolean wifi_connected = false, bt_hs_on = false;
\r
5288 u32 wifi_link_status = 0;
\r
5289 u32 num_of_wifi_link = 0;
\r
5290 boolean bt_ctrl_agg_buf_size = false;
\r
5291 u8 agg_buf_size = 5;
\r
5294 if (btcoexist->manual_control ||
\r
5295 btcoexist->stop_coex_dm)
\r
5299 if(type == BTC_SWITCH_TO_5G) {
\r
5301 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5302 "[BTCoex], switchband_notify --- switch to 5G\n");
\r
5303 BTC_TRACE(trace_buf);
\r
5305 halbtc8821c1ant_action_wifi_under5g(btcoexist);
\r
5309 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5310 "[BTCoex], switchband_notify --- switch to 2G\n");
\r
5311 BTC_TRACE(trace_buf);
\r
5313 ex_halbtc8821c1ant_scan_notify(btcoexist,
\r
5314 BTC_SCAN_START_2G);
\r
5319 void ex_halbtc8821c1ant_connect_notify(IN struct btc_coexist *btcoexist,
\r
5322 boolean wifi_connected = false;
\r
5325 halbtc8821c1ant_post_activestate_to_bt(btcoexist, true);
\r
5327 if (btcoexist->manual_control ||
\r
5328 btcoexist->stop_coex_dm)
\r
5331 if ( (BTC_ASSOCIATE_5G_START == type) || (BTC_ASSOCIATE_5G_FINISH== type)) {
\r
5333 if (BTC_ASSOCIATE_5G_START == type)
\r
5334 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5335 "[BTCoex], connect_notify --- 5G start\n");
\r
5337 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5338 "[BTCoex], connect_notify --- 5G finish\n");
\r
5340 BTC_TRACE(trace_buf);
\r
5342 halbtc8821c1ant_action_wifi_under5g(btcoexist);
\r
5346 if (BTC_ASSOCIATE_START == type) {
\r
5348 coex_sta->wifi_is_high_pri_task = true;
\r
5350 /* Force antenna setup for no scan result issue */
\r
5351 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
\r
5352 FORCE_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
5354 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5355 "[BTCoex], CONNECT START notify (2G)\n");
\r
5356 BTC_TRACE(trace_buf);
\r
5358 coex_dm->arp_cnt = 0;
\r
5360 halbtc8821c1ant_action_wifi_not_connected_asso_auth(btcoexist);
\r
5363 coex_sta->wifi_is_high_pri_task = false;
\r
5365 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5366 "[BTCoex], CONNECT FINISH notify (2G)\n");
\r
5367 BTC_TRACE(trace_buf);
\r
5369 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
\r
5372 if (!wifi_connected) /* non-connected scan */
\r
5373 halbtc8821c1ant_action_wifi_not_connected(btcoexist);
\r
5375 halbtc8821c1ant_action_wifi_connected(btcoexist);
\r
5380 void ex_halbtc8821c1ant_media_status_notify(IN struct btc_coexist *btcoexist,
\r
5383 boolean wifi_under_b_mode = false, wifi_under_5g = false;
\r
5386 if (btcoexist->manual_control ||
\r
5387 btcoexist->stop_coex_dm)
\r
5390 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
\r
5392 if (wifi_under_5g) {
5394 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5395 "[BTCoex], WiFi is under 5G!!!\n");
5396 BTC_TRACE(trace_buf);
5398 halbtc8821c1ant_post_activestate_to_bt(btcoexist, true);
\r
5399 halbtc8821c1ant_action_wifi_under5g(btcoexist);
\r
5403 if (BTC_MEDIA_CONNECT == type) {
\r
5405 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5406 "[BTCoex], MEDIA connect notify\n");
\r
5407 BTC_TRACE(trace_buf);
\r
5409 halbtc8821c1ant_post_activestate_to_bt(btcoexist, true);
\r
5411 /* Force antenna setup for no scan result issue */
\r
5412 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
\r
5413 FORCE_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
5415 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
\r
5416 &wifi_under_b_mode);
\r
5418 /* Set CCK Tx/Rx high Pri except 11b mode */
\r
5419 if (wifi_under_b_mode) {
\r
5420 btcoexist->btc_write_1byte(btcoexist, 0x6cd,
\r
5421 0x00); /* CCK Tx */
\r
5422 btcoexist->btc_write_1byte(btcoexist, 0x6cf,
\r
5423 0x00); /* CCK Rx */
\r
5425 /* btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x10); */ /*CCK Tx */
\r
5426 /* btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x10); */ /*CCK Rx */
\r
5427 btcoexist->btc_write_1byte(btcoexist, 0x6cd,
\r
5428 0x00); /* CCK Tx */
\r
5429 btcoexist->btc_write_1byte(btcoexist, 0x6cf,
\r
5430 0x10); /* CCK Rx */
\r
5433 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
\r
5435 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
\r
5437 coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
\r
5438 btcoexist, 0x42a);
\r
5439 coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
\r
5440 btcoexist, 0x456);
\r
5443 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5444 "[BTCoex], MEDIA disconnect notify\n");
\r
5445 BTC_TRACE(trace_buf);
\r
5447 halbtc8821c1ant_post_activestate_to_bt(btcoexist, false);
\r
5449 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
\r
5450 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
\r
5452 coex_sta->cck_ever_lock = false;
\r
5455 halbtc8821c1ant_update_wifi_channel_info(btcoexist, type);
\r
5459 void ex_halbtc8821c1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
\r
5462 boolean under_4way = false, wifi_under_5g = false;
\r
5464 if (btcoexist->manual_control ||
\r
5465 btcoexist->stop_coex_dm ||
\r
5466 coex_sta->bt_disabled)
\r
5469 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
\r
5471 if (wifi_under_5g) {
5473 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5474 "[BTCoex], WiFi is under 5G!!!\n");
5475 BTC_TRACE(trace_buf);
5477 halbtc8821c1ant_action_wifi_under5g(btcoexist);
\r
5481 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
\r
5486 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5487 "[BTCoex], specific Packet ---- under_4way!!\n");
\r
5488 BTC_TRACE(trace_buf);
\r
5490 coex_sta->wifi_is_high_pri_task = true;
\r
5491 coex_sta->specific_pkt_period_cnt = 2;
\r
5492 } else if (BTC_PACKET_ARP == type) {
\r
5494 coex_dm->arp_cnt++;
\r
5496 if (coex_sta->wifi_is_high_pri_task) {
\r
5497 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5498 "[BTCoex], specific Packet ARP notify -cnt = %d\n", coex_dm->arp_cnt);
\r
5499 BTC_TRACE(trace_buf);
\r
5504 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5505 "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n", type);
\r
5506 BTC_TRACE(trace_buf);
\r
5508 coex_sta->wifi_is_high_pri_task = true;
\r
5509 coex_sta->specific_pkt_period_cnt = 2;
\r
5512 if (coex_sta->wifi_is_high_pri_task)
\r
5513 halbtc8821c1ant_action_wifi_connected_specific_packet(btcoexist);
\r
5516 void ex_halbtc8821c1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
\r
5517 IN u8 *tmp_buf, IN u8 length)
\r
5520 u8 i, rsp_source = 0;
\r
5521 boolean wifi_connected = false;
\r
5522 boolean bt_busy = false;
\r
5524 coex_sta->c2h_bt_info_req_sent = false;
\r
5526 rsp_source = tmp_buf[0] & 0xf;
\r
5527 if (rsp_source >= BT_INFO_SRC_8821C_1ANT_MAX)
\r
5528 rsp_source = BT_INFO_SRC_8821C_1ANT_WIFI_FW;
\r
5529 coex_sta->bt_info_c2h_cnt[rsp_source]++;
\r
5531 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5532 "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
\r
5534 BTC_TRACE(trace_buf);
\r
5535 for (i = 0; i < length; i++) {
\r
5536 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
\r
5538 bt_info = tmp_buf[i];
\r
5539 if (i == length - 1) {
\r
5540 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
\r
5542 BTC_TRACE(trace_buf);
\r
5544 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
\r
5546 BTC_TRACE(trace_buf);
\r
5550 if (BT_INFO_SRC_8821C_1ANT_WIFI_FW != rsp_source) {
\r
5552 /* if 0xff, it means BT is under WHCK test */
\r
5553 if (bt_info == 0xff)
\r
5554 coex_sta->bt_whck_test = true;
\r
5556 coex_sta->bt_whck_test = false;
\r
5558 coex_sta->bt_retry_cnt = /* [3:0] */
\r
5559 coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
\r
5561 if (coex_sta->bt_retry_cnt >= 1)
\r
5562 coex_sta->pop_event_cnt++;
\r
5564 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
\r
5565 coex_sta->c2h_bt_page = true;
\r
5567 coex_sta->c2h_bt_page = false;
\r
5569 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x80)
\r
5570 coex_sta->bt_create_connection = true;
\r
5572 coex_sta->bt_create_connection = false;
\r
5574 /* unit: %, value-100 to translate to unit: dBm */
\r
5575 coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
\r
5577 /* coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90; */
\r
5579 if ((coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) {
\r
5580 coex_sta->a2dp_bit_pool =
\r
5581 coex_sta->bt_info_c2h[rsp_source][6];
\r
5583 coex_sta->a2dp_bit_pool = 0;
\r
5585 if (coex_sta->bt_info_c2h[rsp_source][1] & 0x9)
\r
5586 coex_sta->acl_busy = true;
\r
5588 coex_sta->acl_busy = false;
\r
5590 coex_sta->bt_info_ext =
\r
5591 coex_sta->bt_info_c2h[rsp_source][4];
\r
5593 /* Here we need to resend some wifi info to BT */
\r
5594 /* because bt is reset and loss of the info. */
\r
5596 if ((!btcoexist->manual_control) && (!btcoexist->stop_coex_dm)) {
\r
5599 if (coex_sta->bt_info_ext & BIT(1)) {
\r
5600 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5601 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
\r
5602 BTC_TRACE(trace_buf);
\r
5603 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
\r
5605 if (wifi_connected)
\r
5606 halbtc8821c1ant_update_wifi_channel_info(btcoexist,
\r
5607 BTC_MEDIA_CONNECT);
\r
5609 halbtc8821c1ant_update_wifi_channel_info(btcoexist,
\r
5610 BTC_MEDIA_DISCONNECT);
\r
5613 /* If Ignore_WLanAct && not SetUp_Link */
\r
5614 if ((coex_sta->bt_info_ext & BIT(3)) && (!(coex_sta->bt_info_ext & BIT(2)))) {
\r
5616 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5617 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
\r
5618 BTC_TRACE(trace_buf);
\r
5619 halbtc8821c1ant_ignore_wlan_act(btcoexist,
\r
5620 FORCE_EXEC, false);
\r
5623 /* check BIT2 first ==> check if bt is under inquiry or page scan */
\r
5624 if (bt_info & BT_INFO_8821C_1ANT_B_INQ_PAGE)
\r
5625 coex_sta->c2h_bt_inquiry_page = true;
\r
5627 coex_sta->c2h_bt_inquiry_page = false;
\r
5630 coex_sta->num_of_profile = 0;
\r
5632 /* set link exist status */
\r
5633 if (!(bt_info & BT_INFO_8821C_1ANT_B_CONNECTION)) {
\r
5634 coex_sta->bt_link_exist = false;
\r
5635 coex_sta->pan_exist = false;
\r
5636 coex_sta->a2dp_exist = false;
\r
5637 coex_sta->hid_exist = false;
\r
5638 coex_sta->sco_exist = false;
\r
5640 coex_sta->bt_hi_pri_link_exist = false;
\r
5641 } else { /* connection exists */
\r
5642 coex_sta->bt_link_exist = true;
\r
5643 if (bt_info & BT_INFO_8821C_1ANT_B_FTP) {
\r
5644 coex_sta->pan_exist = true;
\r
5645 coex_sta->num_of_profile++;
\r
5647 coex_sta->pan_exist = false;
\r
5648 if (bt_info & BT_INFO_8821C_1ANT_B_A2DP) {
\r
5649 coex_sta->a2dp_exist = true;
\r
5650 coex_sta->num_of_profile++;
\r
5652 coex_sta->a2dp_exist = false;
\r
5653 if (bt_info & BT_INFO_8821C_1ANT_B_HID) {
\r
5654 coex_sta->hid_exist = true;
\r
5655 coex_sta->num_of_profile++;
\r
5657 coex_sta->hid_exist = false;
\r
5658 if (bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) {
\r
5659 coex_sta->sco_exist = true;
\r
5660 coex_sta->num_of_profile++;
\r
5662 coex_sta->sco_exist = false;
\r
5666 halbtc8821c1ant_update_bt_link_info(btcoexist);
\r
5668 bt_info = bt_info &
\r
5669 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
\r
5671 if (!(bt_info & BT_INFO_8821C_1ANT_B_CONNECTION)) {
\r
5672 coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
\r
5673 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5674 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
\r
5675 BTC_TRACE(trace_buf);
\r
5676 } else if (bt_info ==
\r
5677 BT_INFO_8821C_1ANT_B_CONNECTION) { /* connection exists but no busy */
\r
5678 coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE;
\r
5679 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5680 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
\r
5681 BTC_TRACE(trace_buf);
\r
5682 } else if ((bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) ||
\r
5683 (bt_info & BT_INFO_8821C_1ANT_B_SCO_BUSY)) {
\r
5684 coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_SCO_BUSY;
\r
5685 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5686 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
\r
5687 BTC_TRACE(trace_buf);
\r
5688 } else if (bt_info & BT_INFO_8821C_1ANT_B_ACL_BUSY) {
\r
5689 if (BT_8821C_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
\r
5690 coex_dm->auto_tdma_adjust = false;
\r
5691 coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_ACL_BUSY;
\r
5692 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5693 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
\r
5694 BTC_TRACE(trace_buf);
\r
5696 coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_MAX;
\r
5697 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5698 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
\r
5699 BTC_TRACE(trace_buf);
\r
5702 if ((BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
\r
5703 (BT_8821C_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
\r
5704 (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
\r
5708 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
\r
5710 if (btcoexist->manual_control) {
\r
5711 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5712 "[BTCoex], BtInfoNotify(), No run_coexist_mechanism return for Manual CTRL<===\n");
\r
5713 BTC_TRACE(trace_buf);
\r
5717 if (btcoexist->stop_coex_dm) {
\r
5718 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5719 "[BTCoex], BtInfoNotify(), No run_coexist_mechanism return for Stop Coex DM <===\n");
\r
5720 BTC_TRACE(trace_buf);
\r
5724 halbtc8821c1ant_run_coexist_mechanism(btcoexist);
\r
5727 void ex_halbtc8821c1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
\r
5730 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
\r
5731 BTC_TRACE(trace_buf);
\r
5733 if (BTC_RF_ON == type) {
\r
5735 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5736 "[BTCoex], RF is turned ON!!\n");
\r
5737 BTC_TRACE(trace_buf);
\r
5739 coex_sta->wl_rf_off_on_event = true;
\r
5740 btcoexist->stop_coex_dm = false;
\r
5742 halbtc8821c1ant_post_activestate_to_bt(btcoexist, TRUE);
\r
5743 halbtc8821c1ant_post_onoffstate_to_bt(btcoexist, TRUE);
\r
5745 } else if (BTC_RF_OFF == type) {
\r
5747 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5748 "[BTCoex], RF is turned OFF!!\n");
\r
5749 BTC_TRACE(trace_buf);
\r
5751 halbtc8821c1ant_post_activestate_to_bt(btcoexist, FALSE);
\r
5752 halbtc8821c1ant_post_onoffstate_to_bt(btcoexist, FALSE);
\r
5754 halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
\r
5755 halbtc8821c1ant_set_ant_path(btcoexist,
\r
5756 BTC_ANT_PATH_AUTO,
\r
5758 BT_8821C_1ANT_PHASE_WLAN_OFF);
\r
5760 btcoexist->stop_coex_dm = true;
\r
5761 coex_sta->wl_rf_off_on_event = false;
\r
5765 void ex_halbtc8821c1ant_halt_notify(IN struct btc_coexist *btcoexist)
\r
5767 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
\r
5768 BTC_TRACE(trace_buf);
\r
5770 /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */
\r
5771 halbtc8821c1ant_enable_gnt_to_gpio(btcoexist, FALSE);
\r
5773 halbtc8821c1ant_post_activestate_to_bt(btcoexist, FALSE);
\r
5774 halbtc8821c1ant_post_onoffstate_to_bt(btcoexist, FALSE);
\r
5776 halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
\r
5778 halbtc8821c1ant_set_ant_path(btcoexist,
\r
5779 BTC_ANT_PATH_AUTO,
\r
5781 BT_8821C_1ANT_PHASE_WLAN_OFF);
\r
5783 halbtc8821c1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
\r
5785 ex_halbtc8821c1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
\r
5787 btcoexist->stop_coex_dm = true;
\r
5790 void ex_halbtc8821c1ant_pnp_notify(IN struct btc_coexist *btcoexist,
\r
5793 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
\r
5794 BTC_TRACE(trace_buf);
\r
5796 if (BTC_WIFI_PNP_SLEEP == pnp_state) {
\r
5797 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5798 "[BTCoex], Pnp notify to SLEEP\n");
\r
5799 BTC_TRACE(trace_buf);
\r
5801 /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */
\r
5802 halbtc8821c1ant_enable_gnt_to_gpio(btcoexist, FALSE);
\r
5804 halbtc8821c1ant_post_activestate_to_bt(btcoexist, FALSE);
\r
5805 halbtc8821c1ant_post_onoffstate_to_bt(btcoexist, FALSE);
\r
5807 halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
\r
5809 halbtc8821c1ant_set_ant_path(btcoexist,
\r
5810 BTC_ANT_PATH_AUTO,
\r
5812 BT_8821C_1ANT_PHASE_WLAN_OFF);
\r
5814 btcoexist->stop_coex_dm = true;
\r
5815 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
\r
5817 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5818 "[BTCoex], Pnp notify to WAKE UP\n");
\r
5819 BTC_TRACE(trace_buf);
\r
5821 halbtc8821c1ant_post_activestate_to_bt(btcoexist, TRUE);
\r
5822 halbtc8821c1ant_post_onoffstate_to_bt(btcoexist, TRUE);
\r
5824 btcoexist->stop_coex_dm = false;
\r
5829 void ex_halbtc8821c1ant_coex_dm_reset(IN struct btc_coexist *btcoexist)
\r
5831 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5832 "[BTCoex], *****************Coex DM Reset*****************\n");
\r
5833 BTC_TRACE(trace_buf);
\r
5835 halbtc8821c1ant_init_hw_config(btcoexist, false, false);
\r
5836 halbtc8821c1ant_init_coex_dm(btcoexist);
\r
5839 void ex_halbtc8821c1ant_periodical(IN struct btc_coexist *btcoexist)
\r
5842 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5843 "[BTCoex], ============== Periodical ==============\n");
\r
5844 BTC_TRACE(trace_buf);
\r
5846 #if (BT_AUTO_REPORT_ONLY_8821C_1ANT == 0)
\r
5847 halbtc8821c1ant_query_bt_info(btcoexist);
\r
5851 halbtc8821c1ant_monitor_bt_ctr(btcoexist);
\r
5852 halbtc8821c1ant_monitor_wifi_ctr(btcoexist);
\r
5854 halbtc8821c1ant_monitor_bt_enable_disable(btcoexist);
\r
5856 /* for 4-way, DHCP, EAPOL packet */
\r
5857 if (coex_sta->specific_pkt_period_cnt > 0) {
\r
5859 coex_sta->specific_pkt_period_cnt--;
\r
5861 if ((coex_sta->specific_pkt_period_cnt == 0) && (coex_sta->wifi_is_high_pri_task))
\r
5862 coex_sta->wifi_is_high_pri_task = false;
\r
5864 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5865 "[BTCoex], ***************** Hi-Pri Task = %s*****************\n", (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"));
\r
5866 BTC_TRACE(trace_buf);
\r
5869 if (coex_sta->bt_coex_supported_feature == 0)
\r
5870 coex_sta->bt_coex_supported_feature = btcoexist->btc_get_bt_coex_supported_feature(btcoexist);
\r
5872 if ( (coex_sta->bt_coex_supported_version == 0) && (!coex_sta->bt_disabled) )
\r
5873 coex_sta->bt_coex_supported_version = btcoexist->btc_get_bt_coex_supported_version(btcoexist);
\r
5875 if (halbtc8821c1ant_is_wifibt_status_changed(btcoexist))
\r
5876 halbtc8821c1ant_run_coexist_mechanism(btcoexist);
\r
5881 void ex_halbtc8821c1ant_antenna_detection(IN struct btc_coexist *btcoexist,
\r
5882 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
\r
5884 #if BT_8821C_1ANT_ANTDET_ENABLE
\r
5885 static u32 ant_det_count = 0, ant_det_fail_count = 0;
\r
5886 struct btc_board_info *board_info = &btcoexist->board_info;
\r
5887 /*boolean scan, roam;*/
\r
5889 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5890 "xxxxxxxxxxxxxxxx Call AntennaDetect()!!\n");
\r
5891 BTC_TRACE(trace_buf);
\r
5893 if (seconds == 0) {
\r
5894 psd_scan->ant_det_try_count = 0;
\r
5895 psd_scan->ant_det_fail_count = 0;
\r
5896 ant_det_count = 0;
\r
5897 ant_det_fail_count = 0;
\r
5898 board_info->btdm_ant_det_finish = false;
\r
5899 board_info->btdm_ant_num_by_ant_det = 1;
\r
5903 if (!board_info->btdm_ant_det_finish) {
\r
5904 psd_scan->ant_det_inteval_count =
\r
5905 psd_scan->ant_det_inteval_count + 2;
\r
5907 if (psd_scan->ant_det_inteval_count >=
\r
5908 BT_8821C_2ANT_ANTDET_RETRY_INTERVAL) {
\r
5909 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5910 "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is up, Try Detect!!\n");
\r
5911 BTC_TRACE(trace_buf);
\r
5912 halbtc8821c1ant_psd_antenna_detection_check(btcoexist);
\r
5914 if (board_info->btdm_ant_det_finish) {
\r
5915 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5916 "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Success!!\n");
\r
5917 BTC_TRACE(trace_buf);
\r
5919 if (board_info->btdm_ant_num_by_ant_det == 2)
\r
5920 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI,
\r
5921 FORCE_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
5923 halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
\r
5924 FORCE_EXEC, BT_8821C_1ANT_PHASE_2G_RUNTIME);
\r
5927 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5928 "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Fail!!\n");
\r
5929 BTC_TRACE(trace_buf);
\r
5931 psd_scan->ant_det_inteval_count = 0;
\r
5933 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
\r
5934 "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is not up! (%d)\n",
\r
5935 psd_scan->ant_det_inteval_count);
\r
5936 BTC_TRACE(trace_buf);
\r
5946 void ex_halbtc8821c1ant_display_ant_detection(IN struct btc_coexist *btcoexist)
\r
5948 #if BT_8821C_1ANT_ANTDET_ENABLE
\r
5949 struct btc_board_info *board_info = &btcoexist->board_info;
\r
5951 if (psd_scan->ant_det_try_count != 0) {
\r
5952 halbtc8821c1ant_psd_show_antenna_detect_result(btcoexist);
\r
5954 if (board_info->btdm_ant_det_finish)
\r
5955 halbtc8821c1ant_psd_showdata(btcoexist);
\r
5962 void ex_halbtc8821c1ant_antenna_isolation(IN struct btc_coexist *btcoexist,
\r
5963 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
\r
5969 void ex_halbtc8821c1ant_psd_scan(IN struct btc_coexist *btcoexist,
\r
5970 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
\r
5979 #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */
\r