xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8723bu/hal/btc/HalBtc8821a1Ant.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* ************************************************************
3  * Description:
4  *
5  * This file is for 8821A_1ANT Co-exist mechanism
6  *
7  * History
8  * 2012/11/15 Cosa first check in.
9  *
10  * ************************************************************
11  * SY modify 2015/04/27
12  * ************************************************************
13  * include files
14  * ************************************************************ */
15 #include "Mp_Precomp.h"
16 
17 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
18 
19 #if (RTL8821A_SUPPORT == 1)
20 /* ************************************************************
21  * Global variables, these are static variables
22  * ************************************************************ */
23 static u8	 *trace_buf = &gl_btc_trace_buf[0];
24 static struct  coex_dm_8821a_1ant		glcoex_dm_8821a_1ant;
25 static struct  coex_dm_8821a_1ant	*coex_dm = &glcoex_dm_8821a_1ant;
26 static struct  coex_sta_8821a_1ant		glcoex_sta_8821a_1ant;
27 static struct  coex_sta_8821a_1ant	*coex_sta = &glcoex_sta_8821a_1ant;
28 
29 const char *const glbt_info_src_8821a_1ant[] = {
30 	"BT Info[wifi fw]",
31 	"BT Info[bt rsp]",
32 	"BT Info[bt auto report]",
33 };
34 
35 u32	glcoex_ver_date_8821a_1ant = 20150615;
36 u32	glcoex_ver_8821a_1ant = 0x61;
37 
38 /* ************************************************************
39  * local function proto type if needed
40  * ************************************************************
41  * ************************************************************
42  * local function start with halbtc8821a1ant_
43  * ************************************************************ */
halbtc8821a1ant_bt_rssi_state(u8 level_num,u8 rssi_thresh,u8 rssi_thresh1)44 u8 halbtc8821a1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
45 {
46 	s32			bt_rssi = 0;
47 	u8			bt_rssi_state = coex_sta->pre_bt_rssi_state;
48 
49 	bt_rssi = coex_sta->bt_rssi;
50 
51 	if (level_num == 2) {
52 		if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
53 		    (coex_sta->pre_bt_rssi_state ==
54 		     BTC_RSSI_STATE_STAY_LOW)) {
55 			if (bt_rssi >= (rssi_thresh +
56 					BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
57 				bt_rssi_state = BTC_RSSI_STATE_HIGH;
58 			else
59 				bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
60 		} else {
61 			if (bt_rssi < rssi_thresh)
62 				bt_rssi_state = BTC_RSSI_STATE_LOW;
63 			else
64 				bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
65 		}
66 	} else if (level_num == 3) {
67 		if (rssi_thresh > rssi_thresh1) {
68 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
69 				    "[BTCoex], BT Rssi thresh error!!\n");
70 			BTC_TRACE(trace_buf);
71 			return coex_sta->pre_bt_rssi_state;
72 		}
73 
74 		if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
75 		    (coex_sta->pre_bt_rssi_state ==
76 		     BTC_RSSI_STATE_STAY_LOW)) {
77 			if (bt_rssi >= (rssi_thresh +
78 					BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
79 				bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
80 			else
81 				bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
82 		} else if ((coex_sta->pre_bt_rssi_state ==
83 			    BTC_RSSI_STATE_MEDIUM) ||
84 			   (coex_sta->pre_bt_rssi_state ==
85 			    BTC_RSSI_STATE_STAY_MEDIUM)) {
86 			if (bt_rssi >= (rssi_thresh1 +
87 					BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
88 				bt_rssi_state = BTC_RSSI_STATE_HIGH;
89 			else if (bt_rssi < rssi_thresh)
90 				bt_rssi_state = BTC_RSSI_STATE_LOW;
91 			else
92 				bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
93 		} else {
94 			if (bt_rssi < rssi_thresh1)
95 				bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
96 			else
97 				bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
98 		}
99 	}
100 
101 	coex_sta->pre_bt_rssi_state = bt_rssi_state;
102 
103 	return bt_rssi_state;
104 }
105 
halbtc8821a1ant_wifi_rssi_state(IN struct btc_coexist * btcoexist,IN u8 index,IN u8 level_num,IN u8 rssi_thresh,IN u8 rssi_thresh1)106 u8 halbtc8821a1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
107 	   IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
108 {
109 	s32			wifi_rssi = 0;
110 	u8			wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
111 
112 	btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
113 
114 	if (level_num == 2) {
115 		if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
116 		    ||
117 		    (coex_sta->pre_wifi_rssi_state[index] ==
118 		     BTC_RSSI_STATE_STAY_LOW)) {
119 			if (wifi_rssi >= (rssi_thresh +
120 					  BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
121 				wifi_rssi_state = BTC_RSSI_STATE_HIGH;
122 			else
123 				wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
124 		} else {
125 			if (wifi_rssi < rssi_thresh)
126 				wifi_rssi_state = BTC_RSSI_STATE_LOW;
127 			else
128 				wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
129 		}
130 	} else if (level_num == 3) {
131 		if (rssi_thresh > rssi_thresh1) {
132 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
133 				    "[BTCoex], wifi RSSI thresh error!!\n");
134 			BTC_TRACE(trace_buf);
135 			return coex_sta->pre_wifi_rssi_state[index];
136 		}
137 
138 		if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
139 		    ||
140 		    (coex_sta->pre_wifi_rssi_state[index] ==
141 		     BTC_RSSI_STATE_STAY_LOW)) {
142 			if (wifi_rssi >= (rssi_thresh +
143 					  BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
144 				wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
145 			else
146 				wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
147 		} else if ((coex_sta->pre_wifi_rssi_state[index] ==
148 			    BTC_RSSI_STATE_MEDIUM) ||
149 			   (coex_sta->pre_wifi_rssi_state[index] ==
150 			    BTC_RSSI_STATE_STAY_MEDIUM)) {
151 			if (wifi_rssi >= (rssi_thresh1 +
152 					  BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
153 				wifi_rssi_state = BTC_RSSI_STATE_HIGH;
154 			else if (wifi_rssi < rssi_thresh)
155 				wifi_rssi_state = BTC_RSSI_STATE_LOW;
156 			else
157 				wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
158 		} else {
159 			if (wifi_rssi < rssi_thresh1)
160 				wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
161 			else
162 				wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
163 		}
164 	}
165 
166 	coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
167 
168 	return wifi_rssi_state;
169 }
170 
halbtc8821a1ant_update_ra_mask(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u32 dis_rate_mask)171 void halbtc8821a1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
172 				    IN boolean force_exec, IN u32 dis_rate_mask)
173 {
174 	coex_dm->cur_ra_mask = dis_rate_mask;
175 
176 	if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
177 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
178 				   &coex_dm->cur_ra_mask);
179 	coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
180 }
181 
halbtc8821a1ant_auto_rate_fallback_retry(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)182 void halbtc8821a1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
183 		IN boolean force_exec, IN u8 type)
184 {
185 	boolean	wifi_under_b_mode = false;
186 
187 	coex_dm->cur_arfr_type = type;
188 
189 	if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
190 		switch (coex_dm->cur_arfr_type) {
191 		case 0:	/* normal mode */
192 			btcoexist->btc_write_4byte(btcoexist, 0x430,
193 						   coex_dm->backup_arfr_cnt1);
194 			btcoexist->btc_write_4byte(btcoexist, 0x434,
195 						   coex_dm->backup_arfr_cnt2);
196 			break;
197 		case 1:
198 			btcoexist->btc_get(btcoexist,
199 					   BTC_GET_BL_WIFI_UNDER_B_MODE,
200 					   &wifi_under_b_mode);
201 			if (wifi_under_b_mode) {
202 				btcoexist->btc_write_4byte(btcoexist,
203 							   0x430, 0x0);
204 				btcoexist->btc_write_4byte(btcoexist,
205 							   0x434, 0x01010101);
206 			} else {
207 				btcoexist->btc_write_4byte(btcoexist,
208 							   0x430, 0x0);
209 				btcoexist->btc_write_4byte(btcoexist,
210 							   0x434, 0x04030201);
211 			}
212 			break;
213 		default:
214 			break;
215 		}
216 	}
217 
218 	coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
219 }
220 
halbtc8821a1ant_retry_limit(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)221 void halbtc8821a1ant_retry_limit(IN struct btc_coexist *btcoexist,
222 				 IN boolean force_exec, IN u8 type)
223 {
224 	coex_dm->cur_retry_limit_type = type;
225 
226 	if (force_exec ||
227 	    (coex_dm->pre_retry_limit_type !=
228 	     coex_dm->cur_retry_limit_type)) {
229 		switch (coex_dm->cur_retry_limit_type) {
230 		case 0:	/* normal mode */
231 			btcoexist->btc_write_2byte(btcoexist, 0x42a,
232 						   coex_dm->backup_retry_limit);
233 			break;
234 		case 1:	/* retry limit=8 */
235 			btcoexist->btc_write_2byte(btcoexist, 0x42a,
236 						   0x0808);
237 			break;
238 		default:
239 			break;
240 		}
241 	}
242 
243 	coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
244 }
245 
halbtc8821a1ant_ampdu_max_time(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)246 void halbtc8821a1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
247 				    IN boolean force_exec, IN u8 type)
248 {
249 	coex_dm->cur_ampdu_time_type = type;
250 
251 	if (force_exec ||
252 	    (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
253 		switch (coex_dm->cur_ampdu_time_type) {
254 		case 0:	/* normal mode */
255 			btcoexist->btc_write_1byte(btcoexist, 0x456,
256 					   coex_dm->backup_ampdu_max_time);
257 			break;
258 		case 1:	/* AMPDU timw = 0x38 * 32us */
259 			btcoexist->btc_write_1byte(btcoexist, 0x456,
260 						   0x38);
261 			break;
262 		default:
263 			break;
264 		}
265 	}
266 
267 	coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
268 }
269 
halbtc8821a1ant_limited_tx(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 ra_mask_type,IN u8 arfr_type,IN u8 retry_limit_type,IN u8 ampdu_time_type)270 void halbtc8821a1ant_limited_tx(IN struct btc_coexist *btcoexist,
271 		IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
272 				IN u8 retry_limit_type, IN u8 ampdu_time_type)
273 {
274 	switch (ra_mask_type) {
275 	case 0:	/* normal mode */
276 		halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
277 					       0x0);
278 		break;
279 	case 1:	/* disable cck 1/2 */
280 		halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
281 					       0x00000003);
282 		break;
283 	case 2:	/* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
284 		halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
285 					       0x0001f1f7);
286 		break;
287 	default:
288 		break;
289 	}
290 
291 	halbtc8821a1ant_auto_rate_fallback_retry(btcoexist, force_exec,
292 			arfr_type);
293 	halbtc8821a1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
294 	halbtc8821a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
295 }
296 
297 
298 /* ture/xxxx/x:1
299  * false/false/x: 64
300  * false/ture/x:x */
halbtc8821a1ant_limited_rx(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean rej_ap_agg_pkt,IN boolean bt_ctrl_agg_buf_size,IN u8 agg_buf_size)301 void halbtc8821a1ant_limited_rx(IN struct btc_coexist *btcoexist,
302 			IN boolean force_exec, IN boolean rej_ap_agg_pkt,
303 			IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
304 {
305 	boolean	reject_rx_agg = rej_ap_agg_pkt;
306 	boolean	bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
307 	u8	rx_agg_size = agg_buf_size;
308 
309 	/* ============================================ */
310 	/*	Rx Aggregation related setting */
311 	/* ============================================ */
312 	btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
313 			   &reject_rx_agg);
314 	/* decide BT control aggregation buf size or not */
315 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
316 			   &bt_ctrl_rx_agg_size);
317 	/* aggregation buf size, only work when BT control Rx aggregation size. */
318 	btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
319 	/* real update aggregation setting */
320 	btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
321 
322 
323 }
324 
halbtc8821a1ant_monitor_bt_ctr(IN struct btc_coexist * btcoexist)325 void halbtc8821a1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
326 {
327 	u32			reg_hp_txrx, reg_lp_txrx, u32tmp;
328 	u32			reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
329 #if 0
330 	/* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
331 	if (!(btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8)) {
332 		coex_sta->high_priority_tx = 65535;
333 		coex_sta->high_priority_rx = 65535;
334 		coex_sta->low_priority_tx = 65535;
335 		coex_sta->low_priority_rx = 65535;
336 		return;
337 	}
338 #endif
339 	reg_hp_txrx = 0x770;
340 	reg_lp_txrx = 0x774;
341 
342 	u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
343 	reg_hp_tx = u32tmp & MASKLWORD;
344 	reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
345 
346 	u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
347 	reg_lp_tx = u32tmp & MASKLWORD;
348 	reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
349 
350 	coex_sta->high_priority_tx = reg_hp_tx;
351 	coex_sta->high_priority_rx = reg_hp_rx;
352 	coex_sta->low_priority_tx = reg_lp_tx;
353 	coex_sta->low_priority_rx = reg_lp_rx;
354 
355 	/* reset counter */
356 	btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
357 }
358 
halbtc8821a1ant_query_bt_info(IN struct btc_coexist * btcoexist)359 void halbtc8821a1ant_query_bt_info(IN struct btc_coexist *btcoexist)
360 {
361 	u8			h2c_parameter[1] = {0};
362 
363 	coex_sta->c2h_bt_info_req_sent = true;
364 
365 	h2c_parameter[0] |= BIT(0);	/* trigger */
366 
367 	btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
368 }
369 
halbtc8821a1ant_is_wifi_status_changed(IN struct btc_coexist * btcoexist)370 boolean halbtc8821a1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
371 {
372 	static boolean	pre_wifi_busy = false, pre_under_4way = false,
373 			pre_bt_hs_on = false;
374 	boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
375 	boolean wifi_connected = false;
376 
377 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
378 			   &wifi_connected);
379 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
380 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
381 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
382 			   &under_4way);
383 
384 	if (wifi_connected) {
385 		if (wifi_busy != pre_wifi_busy) {
386 			pre_wifi_busy = wifi_busy;
387 			return true;
388 		}
389 		if (under_4way != pre_under_4way) {
390 			pre_under_4way = under_4way;
391 			return true;
392 		}
393 		if (bt_hs_on != pre_bt_hs_on) {
394 			pre_bt_hs_on = bt_hs_on;
395 			return true;
396 		}
397 	}
398 
399 	return false;
400 }
401 
halbtc8821a1ant_update_bt_link_info(IN struct btc_coexist * btcoexist)402 void halbtc8821a1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
403 {
404 	struct  btc_bt_link_info	*bt_link_info = &btcoexist->bt_link_info;
405 	boolean				bt_hs_on = false;
406 
407 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
408 
409 	bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
410 	bt_link_info->sco_exist = coex_sta->sco_exist;
411 	bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
412 	bt_link_info->pan_exist = coex_sta->pan_exist;
413 	bt_link_info->hid_exist = coex_sta->hid_exist;
414 
415 	/* work around for HS mode. */
416 	if (bt_hs_on) {
417 		bt_link_info->pan_exist = true;
418 		bt_link_info->bt_link_exist = true;
419 	}
420 
421 	/* check if Sco only */
422 	if (bt_link_info->sco_exist &&
423 	    !bt_link_info->a2dp_exist &&
424 	    !bt_link_info->pan_exist &&
425 	    !bt_link_info->hid_exist)
426 		bt_link_info->sco_only = true;
427 	else
428 		bt_link_info->sco_only = false;
429 
430 	/* check if A2dp only */
431 	if (!bt_link_info->sco_exist &&
432 	    bt_link_info->a2dp_exist &&
433 	    !bt_link_info->pan_exist &&
434 	    !bt_link_info->hid_exist)
435 		bt_link_info->a2dp_only = true;
436 	else
437 		bt_link_info->a2dp_only = false;
438 
439 	/* check if Pan only */
440 	if (!bt_link_info->sco_exist &&
441 	    !bt_link_info->a2dp_exist &&
442 	    bt_link_info->pan_exist &&
443 	    !bt_link_info->hid_exist)
444 		bt_link_info->pan_only = true;
445 	else
446 		bt_link_info->pan_only = false;
447 
448 	/* check if Hid only */
449 	if (!bt_link_info->sco_exist &&
450 	    !bt_link_info->a2dp_exist &&
451 	    !bt_link_info->pan_exist &&
452 	    bt_link_info->hid_exist)
453 		bt_link_info->hid_only = true;
454 	else
455 		bt_link_info->hid_only = false;
456 }
457 
halbtc8821a1ant_action_algorithm(IN struct btc_coexist * btcoexist)458 u8 halbtc8821a1ant_action_algorithm(IN struct btc_coexist *btcoexist)
459 {
460 	struct  btc_bt_link_info	*bt_link_info = &btcoexist->bt_link_info;
461 	boolean				bt_hs_on = false;
462 	u8				algorithm = BT_8821A_1ANT_COEX_ALGO_UNDEFINED;
463 	u8				num_of_diff_profile = 0;
464 
465 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
466 
467 	if (!bt_link_info->bt_link_exist) {
468 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
469 			    "[BTCoex], No BT link exists!!!\n");
470 		BTC_TRACE(trace_buf);
471 		return algorithm;
472 	}
473 
474 	if (bt_link_info->sco_exist)
475 		num_of_diff_profile++;
476 	if (bt_link_info->hid_exist)
477 		num_of_diff_profile++;
478 	if (bt_link_info->pan_exist)
479 		num_of_diff_profile++;
480 	if (bt_link_info->a2dp_exist)
481 		num_of_diff_profile++;
482 
483 	if (num_of_diff_profile == 1) {
484 		if (bt_link_info->sco_exist) {
485 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
486 				    "[BTCoex], BT Profile = SCO only\n");
487 			BTC_TRACE(trace_buf);
488 			algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
489 		} else {
490 			if (bt_link_info->hid_exist) {
491 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
492 					"[BTCoex], BT Profile = HID only\n");
493 				BTC_TRACE(trace_buf);
494 				algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
495 			} else if (bt_link_info->a2dp_exist) {
496 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
497 					"[BTCoex], BT Profile = A2DP only\n");
498 				BTC_TRACE(trace_buf);
499 				algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP;
500 			} else if (bt_link_info->pan_exist) {
501 				if (bt_hs_on) {
502 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
503 						"[BTCoex], BT Profile = PAN(HS) only\n");
504 					BTC_TRACE(trace_buf);
505 					algorithm =
506 						BT_8821A_1ANT_COEX_ALGO_PANHS;
507 				} else {
508 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
509 						"[BTCoex], BT Profile = PAN(EDR) only\n");
510 					BTC_TRACE(trace_buf);
511 					algorithm =
512 						BT_8821A_1ANT_COEX_ALGO_PANEDR;
513 				}
514 			}
515 		}
516 	} else if (num_of_diff_profile == 2) {
517 		if (bt_link_info->sco_exist) {
518 			if (bt_link_info->hid_exist) {
519 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
520 					"[BTCoex], BT Profile = SCO + HID\n");
521 				BTC_TRACE(trace_buf);
522 				algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
523 			} else if (bt_link_info->a2dp_exist) {
524 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
525 					"[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
526 				BTC_TRACE(trace_buf);
527 				algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
528 			} else if (bt_link_info->pan_exist) {
529 				if (bt_hs_on) {
530 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
531 						"[BTCoex], BT Profile = SCO + PAN(HS)\n");
532 					BTC_TRACE(trace_buf);
533 					algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
534 				} else {
535 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
536 						"[BTCoex], BT Profile = SCO + PAN(EDR)\n");
537 					BTC_TRACE(trace_buf);
538 					algorithm =
539 						BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
540 				}
541 			}
542 		} else {
543 			if (bt_link_info->hid_exist &&
544 			    bt_link_info->a2dp_exist) {
545 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
546 					"[BTCoex], BT Profile = HID + A2DP\n");
547 				BTC_TRACE(trace_buf);
548 				algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
549 			} else if (bt_link_info->hid_exist &&
550 				   bt_link_info->pan_exist) {
551 				if (bt_hs_on) {
552 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
553 						"[BTCoex], BT Profile = HID + PAN(HS)\n");
554 					BTC_TRACE(trace_buf);
555 					algorithm =
556 						BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
557 				} else {
558 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
559 						"[BTCoex], BT Profile = HID + PAN(EDR)\n");
560 					BTC_TRACE(trace_buf);
561 					algorithm =
562 						BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
563 				}
564 			} else if (bt_link_info->pan_exist &&
565 				   bt_link_info->a2dp_exist) {
566 				if (bt_hs_on) {
567 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
568 						"[BTCoex], BT Profile = A2DP + PAN(HS)\n");
569 					BTC_TRACE(trace_buf);
570 					algorithm =
571 						BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS;
572 				} else {
573 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
574 						"[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
575 					BTC_TRACE(trace_buf);
576 					algorithm =
577 						BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP;
578 				}
579 			}
580 		}
581 	} else if (num_of_diff_profile == 3) {
582 		if (bt_link_info->sco_exist) {
583 			if (bt_link_info->hid_exist &&
584 			    bt_link_info->a2dp_exist) {
585 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
586 					"[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
587 				BTC_TRACE(trace_buf);
588 				algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
589 			} else if (bt_link_info->hid_exist &&
590 				   bt_link_info->pan_exist) {
591 				if (bt_hs_on) {
592 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
593 						"[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
594 					BTC_TRACE(trace_buf);
595 					algorithm =
596 						BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
597 				} else {
598 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
599 						"[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
600 					BTC_TRACE(trace_buf);
601 					algorithm =
602 						BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
603 				}
604 			} else if (bt_link_info->pan_exist &&
605 				   bt_link_info->a2dp_exist) {
606 				if (bt_hs_on) {
607 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
608 						"[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
609 					BTC_TRACE(trace_buf);
610 					algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
611 				} else {
612 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
613 						"[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
614 					BTC_TRACE(trace_buf);
615 					algorithm =
616 						BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
617 				}
618 			}
619 		} else {
620 			if (bt_link_info->hid_exist &&
621 			    bt_link_info->pan_exist &&
622 			    bt_link_info->a2dp_exist) {
623 				if (bt_hs_on) {
624 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
625 						"[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
626 					BTC_TRACE(trace_buf);
627 					algorithm =
628 						BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
629 				} else {
630 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
631 						"[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
632 					BTC_TRACE(trace_buf);
633 					algorithm =
634 						BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
635 				}
636 			}
637 		}
638 	} else if (num_of_diff_profile >= 3) {
639 		if (bt_link_info->sco_exist) {
640 			if (bt_link_info->hid_exist &&
641 			    bt_link_info->pan_exist &&
642 			    bt_link_info->a2dp_exist) {
643 				if (bt_hs_on) {
644 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
645 						"[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
646 					BTC_TRACE(trace_buf);
647 
648 				} else {
649 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
650 						"[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
651 					BTC_TRACE(trace_buf);
652 					algorithm =
653 						BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
654 				}
655 			}
656 		}
657 	}
658 
659 	return algorithm;
660 }
661 
halbtc8821a1ant_set_bt_auto_report(IN struct btc_coexist * btcoexist,IN boolean enable_auto_report)662 void halbtc8821a1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
663 					IN boolean enable_auto_report)
664 {
665 	u8			h2c_parameter[1] = {0};
666 
667 	h2c_parameter[0] = 0;
668 
669 	if (enable_auto_report)
670 		h2c_parameter[0] |= BIT(0);
671 
672 	btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
673 }
674 
halbtc8821a1ant_bt_auto_report(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean enable_auto_report)675 void halbtc8821a1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
676 		    IN boolean force_exec, IN boolean enable_auto_report)
677 {
678 	coex_dm->cur_bt_auto_report = enable_auto_report;
679 
680 	if (!force_exec) {
681 		if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
682 			return;
683 	}
684 	halbtc8821a1ant_set_bt_auto_report(btcoexist,
685 					   coex_dm->cur_bt_auto_report);
686 
687 	coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
688 }
689 
halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist * btcoexist,IN boolean low_penalty_ra)690 void halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
691 		*btcoexist, IN boolean low_penalty_ra)
692 {
693 	u8			h2c_parameter[6] = {0};
694 
695 	h2c_parameter[0] = 0x6;	/* op_code, 0x6= Retry_Penalty */
696 
697 	if (low_penalty_ra) {
698 		h2c_parameter[1] |= BIT(0);
699 		h2c_parameter[2] =
700 			0x00;  /* normal rate except MCS7/6/5, OFDM54/48/36 */
701 		h2c_parameter[3] = 0xf5;  /* MCS7 or OFDM54 */
702 		h2c_parameter[4] = 0xa0;  /* MCS6 or OFDM48// */
703 		h2c_parameter[5] = 0xa0; /* MCS5 or OFDM36	// */
704 	}
705 
706 	btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
707 }
708 
halbtc8821a1ant_low_penalty_ra(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean low_penalty_ra)709 void halbtc8821a1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
710 			    IN boolean force_exec, IN boolean low_penalty_ra)
711 {
712 	coex_dm->cur_low_penalty_ra = low_penalty_ra;
713 
714 	if (!force_exec) {
715 		if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
716 			return;
717 	}
718 	halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
719 			coex_dm->cur_low_penalty_ra);
720 
721 	coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
722 }
723 
halbtc8821a1ant_set_coex_table(IN struct btc_coexist * btcoexist,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)724 void halbtc8821a1ant_set_coex_table(IN struct btc_coexist *btcoexist,
725 	    IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
726 {
727 	btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
728 
729 	btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
730 
731 	btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
732 
733 	btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
734 }
735 
halbtc8821a1ant_coex_table(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)736 void halbtc8821a1ant_coex_table(IN struct btc_coexist *btcoexist,
737 			IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
738 				IN u32 val0x6c8, IN u8 val0x6cc)
739 {
740 	coex_dm->cur_val0x6c0 = val0x6c0;
741 	coex_dm->cur_val0x6c4 = val0x6c4;
742 	coex_dm->cur_val0x6c8 = val0x6c8;
743 	coex_dm->cur_val0x6cc = val0x6cc;
744 
745 	if (!force_exec) {
746 		if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
747 		    (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
748 		    (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
749 		    (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
750 			return;
751 	}
752 	halbtc8821a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
753 				       val0x6cc);
754 
755 	coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
756 	coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
757 	coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
758 	coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
759 }
760 
halbtc8821a1ant_coex_table_with_type(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)761 void halbtc8821a1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
762 		IN boolean force_exec, IN u8 type)
763 {
764 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
765 		    "[BTCoex], ********** CoexTable(%d) **********\n", type);
766 	BTC_TRACE(trace_buf);
767 
768 	switch (type) {
769 	case 0:
770 		halbtc8821a1ant_coex_table(btcoexist, force_exec,
771 				   0x55555555, 0x55555555, 0xffffff, 0x3);
772 		break;
773 	case 1:
774 		halbtc8821a1ant_coex_table(btcoexist, force_exec,
775 				   0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
776 		break;
777 	case 2:
778 		halbtc8821a1ant_coex_table(btcoexist, force_exec,
779 				   0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
780 		break;
781 	case 3:
782 		halbtc8821a1ant_coex_table(btcoexist, force_exec,
783 				   0x5a5a5a5a, 0xaaaaaaaa, 0xffffff, 0x3);
784 		break;
785 	case 4:
786 		halbtc8821a1ant_coex_table(btcoexist, force_exec,
787 				   0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
788 		break;
789 	case 5:
790 		halbtc8821a1ant_coex_table(btcoexist, force_exec,
791 				   0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3);
792 		break;
793 	case 6:
794 		halbtc8821a1ant_coex_table(btcoexist, force_exec,
795 				   0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
796 		break;
797 	case 7:
798 		halbtc8821a1ant_coex_table(btcoexist, force_exec,
799 				   0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
800 		break;
801 	default:
802 		break;
803 	}
804 }
805 
halbtc8821a1ant_set_fw_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean enable)806 void halbtc8821a1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
807 		IN boolean enable)
808 {
809 	u8			h2c_parameter[1] = {0};
810 
811 	if (enable) {
812 		h2c_parameter[0] |= BIT(0);		/* function enable */
813 	}
814 
815 	btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
816 }
817 
halbtc8821a1ant_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean enable)818 void halbtc8821a1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
819 				     IN boolean force_exec, IN boolean enable)
820 {
821 	coex_dm->cur_ignore_wlan_act = enable;
822 
823 	if (!force_exec) {
824 		if (coex_dm->pre_ignore_wlan_act ==
825 		    coex_dm->cur_ignore_wlan_act)
826 			return;
827 	}
828 	halbtc8821a1ant_set_fw_ignore_wlan_act(btcoexist, enable);
829 
830 	coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
831 }
832 
halbtc8821a1ant_set_fw_pstdma(IN struct btc_coexist * btcoexist,IN u8 byte1,IN u8 byte2,IN u8 byte3,IN u8 byte4,IN u8 byte5)833 void halbtc8821a1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
834 	   IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
835 {
836 	u8			h2c_parameter[5] = {0};
837 	u8			real_byte1 = byte1, real_byte5 = byte5;
838 	boolean			ap_enable = false;
839 
840 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
841 			   &ap_enable);
842 
843 	if (ap_enable) {
844 		if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
845 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
846 				    "[BTCoex], FW for 1Ant AP mode\n");
847 			BTC_TRACE(trace_buf);
848 			real_byte1 &= ~BIT(4);
849 			real_byte1 |= BIT(5);
850 
851 			real_byte5 |= BIT(5);
852 			real_byte5 &= ~BIT(6);
853 		}
854 	}
855 
856 	h2c_parameter[0] = real_byte1;
857 	h2c_parameter[1] = byte2;
858 	h2c_parameter[2] = byte3;
859 	h2c_parameter[3] = byte4;
860 	h2c_parameter[4] = real_byte5;
861 
862 	coex_dm->ps_tdma_para[0] = real_byte1;
863 	coex_dm->ps_tdma_para[1] = byte2;
864 	coex_dm->ps_tdma_para[2] = byte3;
865 	coex_dm->ps_tdma_para[3] = byte4;
866 	coex_dm->ps_tdma_para[4] = real_byte5;
867 
868 	btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
869 }
870 
halbtc8821a1ant_set_lps_rpwm(IN struct btc_coexist * btcoexist,IN u8 lps_val,IN u8 rpwm_val)871 void halbtc8821a1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
872 				  IN u8 lps_val, IN u8 rpwm_val)
873 {
874 	u8	lps = lps_val;
875 	u8	rpwm = rpwm_val;
876 
877 	btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
878 	btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
879 }
880 
halbtc8821a1ant_lps_rpwm(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 lps_val,IN u8 rpwm_val)881 void halbtc8821a1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
882 		      IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
883 {
884 	coex_dm->cur_lps = lps_val;
885 	coex_dm->cur_rpwm = rpwm_val;
886 
887 	if (!force_exec) {
888 		if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
889 		    (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
890 			return;
891 	}
892 	halbtc8821a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
893 
894 	coex_dm->pre_lps = coex_dm->cur_lps;
895 	coex_dm->pre_rpwm = coex_dm->cur_rpwm;
896 }
897 
halbtc8821a1ant_sw_mechanism(IN struct btc_coexist * btcoexist,IN boolean low_penalty_ra)898 void halbtc8821a1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
899 				  IN boolean low_penalty_ra)
900 {
901 	halbtc8821a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
902 }
903 
halbtc8821a1ant_set_ant_path(IN struct btc_coexist * btcoexist,IN u8 ant_pos_type,IN boolean init_hwcfg,IN boolean wifi_off)904 void halbtc8821a1ant_set_ant_path(IN struct btc_coexist *btcoexist,
905 	  IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
906 {
907 	struct  btc_board_info *board_info = &btcoexist->board_info;
908 	u32			u32tmp = 0;
909 	u8			h2c_parameter[2] = {0};
910 
911 	if (init_hwcfg) {
912 		/* 0x4c[23]=0, 0x4c[24]=1  Antenna control by WL/BT */
913 		u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
914 		u32tmp &= ~BIT(23);
915 		u32tmp |= BIT(24);
916 		btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
917 
918 		/* 0x765 = 0x18 */
919 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
920 
921 		if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
922 			/* tell firmware "antenna inverse"  ==> WRONG firmware antenna control code.==>need fw to fix */
923 			h2c_parameter[0] = 1;
924 			h2c_parameter[1] = 1;
925 			btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
926 						h2c_parameter);
927 
928 			/* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x1); //Main Ant to  BT for IPS case 0x4c[23]=1 */
929 		} else {
930 			/* tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */
931 			h2c_parameter[0] = 0;
932 			h2c_parameter[1] = 1;
933 			btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
934 						h2c_parameter);
935 
936 			/* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x0); //Aux Ant to  BT for IPS case 0x4c[23]=1 */
937 		}
938 	} else if (wifi_off) {
939 		/* 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL	BT Vendor 0xac=0xf002 */
940 		u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
941 		u32tmp &= ~BIT(23);
942 		u32tmp &= ~BIT(24);
943 		btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
944 
945 		/* 0x765 = 0x18 */
946 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
947 	} else {
948 		/* 0x765 = 0x0 */
949 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x0);
950 	}
951 
952 	/* ext switch setting */
953 	switch (ant_pos_type) {
954 	case BTC_ANT_PATH_WIFI:
955 		btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
956 		if (board_info->btdm_ant_pos ==
957 		    BTC_ANTENNA_AT_MAIN_PORT)
958 			btcoexist->btc_write_1byte_bitmask(btcoexist,
959 							   0xcb7, 0x30, 0x1);
960 		else
961 			btcoexist->btc_write_1byte_bitmask(btcoexist,
962 							   0xcb7, 0x30, 0x2);
963 		break;
964 	case BTC_ANT_PATH_BT:
965 		btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
966 		if (board_info->btdm_ant_pos ==
967 		    BTC_ANTENNA_AT_MAIN_PORT)
968 			btcoexist->btc_write_1byte_bitmask(btcoexist,
969 							   0xcb7, 0x30, 0x2);
970 		else
971 			btcoexist->btc_write_1byte_bitmask(btcoexist,
972 							   0xcb7, 0x30, 0x1);
973 		break;
974 	default:
975 	case BTC_ANT_PATH_PTA:
976 		btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x66);
977 		if (board_info->btdm_ant_pos ==
978 		    BTC_ANTENNA_AT_MAIN_PORT)
979 			btcoexist->btc_write_1byte_bitmask(btcoexist,
980 							   0xcb7, 0x30, 0x1);
981 		else
982 			btcoexist->btc_write_1byte_bitmask(btcoexist,
983 							   0xcb7, 0x30, 0x2);
984 		break;
985 	}
986 }
987 
halbtc8821a1ant_ps_tdma(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean turn_on,IN u8 type)988 void halbtc8821a1ant_ps_tdma(IN struct btc_coexist *btcoexist,
989 		     IN boolean force_exec, IN boolean turn_on, IN u8 type)
990 {
991 	u8			rssi_adjust_val = 0;
992 	/* u32			fw_ver=0; */
993 
994 	coex_dm->cur_ps_tdma_on = turn_on;
995 	coex_dm->cur_ps_tdma = type;
996 
997 	if (coex_dm->cur_ps_tdma_on) {
998 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
999 			    "[BTCoex], ********** TDMA(on, %d) **********\n",
1000 			    coex_dm->cur_ps_tdma);
1001 		BTC_TRACE(trace_buf);
1002 	} else {
1003 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1004 			    "[BTCoex], ********** TDMA(off, %d) **********\n",
1005 			    coex_dm->cur_ps_tdma);
1006 		BTC_TRACE(trace_buf);
1007 	}
1008 
1009 	if (!force_exec) {
1010 		if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1011 		    (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1012 			return;
1013 	}
1014 	if (turn_on) {
1015 		switch (type) {
1016 		default:
1017 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1018 						      0x1a, 0x1a, 0x0, 0x50);
1019 			break;
1020 		case 1:
1021 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1022 						      0x3a, 0x03, 0x10, 0x50);
1023 			rssi_adjust_val = 11;
1024 			break;
1025 		case 2:
1026 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1027 						      0x2b, 0x03, 0x10, 0x50);
1028 			rssi_adjust_val = 14;
1029 			break;
1030 		case 3:
1031 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1032 						      0x1d, 0x1d, 0x0, 0x52);
1033 			break;
1034 		case 4:
1035 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1036 						      0x15, 0x3, 0x14, 0x0);
1037 			rssi_adjust_val = 17;
1038 			break;
1039 		case 5:
1040 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1041 						      0x15, 0x3, 0x11, 0x10);
1042 			break;
1043 		case 6:
1044 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1045 						      0x20, 0x3, 0x11, 0x13);
1046 			break;
1047 		case 7:
1048 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1049 						      0xc, 0x5, 0x0, 0x0);
1050 			break;
1051 		case 8:
1052 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1053 						      0x25, 0x3, 0x10, 0x0);
1054 			break;
1055 		case 9:
1056 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1057 						      0x21, 0x3, 0x10, 0x50);
1058 			rssi_adjust_val = 18;
1059 			break;
1060 		case 10:
1061 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1062 						      0xa, 0xa, 0x0, 0x40);
1063 			break;
1064 		case 11:
1065 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1066 						      0x15, 0x03, 0x10, 0x50);
1067 			rssi_adjust_val = 20;
1068 			break;
1069 		case 12:
1070 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1071 						      0x0a, 0x0a, 0x0, 0x50);
1072 			break;
1073 		case 13:
1074 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1075 						      0x12, 0x12, 0x0, 0x50);
1076 			break;
1077 		case 14:
1078 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1079 						      0x1e, 0x3, 0x10, 0x14);
1080 			break;
1081 		case 15:
1082 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
1083 						      0xa, 0x3, 0x8, 0x0);
1084 			break;
1085 		case 16:
1086 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1087 						      0x15, 0x3, 0x10, 0x0);
1088 			rssi_adjust_val = 18;
1089 			break;
1090 		case 18:
1091 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
1092 						      0x25, 0x3, 0x10, 0x0);
1093 			rssi_adjust_val = 14;
1094 			break;
1095 		case 20:
1096 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1097 						      0x35, 0x03, 0x11, 0x10);
1098 			break;
1099 		case 21:
1100 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1101 						      0x25, 0x03, 0x11, 0x11);
1102 			break;
1103 		case 22:
1104 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1105 						      0x25, 0x03, 0x11, 0x10);
1106 			break;
1107 		case 23:
1108 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1109 						      0x25, 0x3, 0x31, 0x18);
1110 			rssi_adjust_val = 22;
1111 			break;
1112 		case 24:
1113 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1114 						      0x15, 0x3, 0x31, 0x18);
1115 			rssi_adjust_val = 22;
1116 			break;
1117 		case 25:
1118 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1119 						      0xa, 0x3, 0x31, 0x18);
1120 			rssi_adjust_val = 22;
1121 			break;
1122 		case 26:
1123 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1124 						      0xa, 0x3, 0x31, 0x18);
1125 			rssi_adjust_val = 22;
1126 			break;
1127 		case 27:
1128 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
1129 						      0x25, 0x3, 0x31, 0x98);
1130 			rssi_adjust_val = 22;
1131 			break;
1132 		case 28:
1133 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x69,
1134 						      0x25, 0x3, 0x31, 0x0);
1135 			break;
1136 		case 29:
1137 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xab,
1138 						      0x1a, 0x1a, 0x1, 0x10);
1139 			break;
1140 		case 30:
1141 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1142 						      0x30, 0x3, 0x10, 0x10);
1143 			break;
1144 		case 31:
1145 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3,
1146 						      0x1a, 0x1a, 0, 0x58);
1147 			break;
1148 		case 32:
1149 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
1150 						      0x35, 0x3, 0x11, 0x11);
1151 			break;
1152 		case 33:
1153 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xa3,
1154 						      0x25, 0x3, 0x30, 0x90);
1155 			break;
1156 		case 34:
1157 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x53,
1158 						      0x1a, 0x1a, 0x0, 0x10);
1159 			break;
1160 		case 35:
1161 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x63,
1162 						      0x1a, 0x1a, 0x0, 0x10);
1163 			break;
1164 		case 36:
1165 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3,
1166 						      0x12, 0x3, 0x14, 0x50);
1167 			break;
1168 		case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */
1169 			/* here softap mode screen off will cost 70-80mA for phone */
1170 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x23,
1171 						      0x18, 0x00, 0x10, 0x24);
1172 			break;
1173 		case 41:
1174 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1175 						      0x15, 0x3, 0x11, 0x11);
1176 			break;
1177 		case 42:
1178 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1179 						      0x20, 0x3, 0x11, 0x11);
1180 			break;
1181 		case 43:
1182 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
1183 						      0x30, 0x3, 0x10, 0x11);
1184 			break;
1185 		}
1186 	} else {
1187 		/* disable PS tdma */
1188 		switch (type) {
1189 		case 8: /* PTA Control */
1190 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x8,
1191 						      0x0, 0x0, 0x0, 0x0);
1192 			halbtc8821a1ant_set_ant_path(btcoexist,
1193 					     BTC_ANT_PATH_PTA, false, false);
1194 			break;
1195 		case 0:
1196 		default:  /* Software control, Antenna at BT side */
1197 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1198 						      0x0, 0x0, 0x0, 0x0);
1199 			halbtc8821a1ant_set_ant_path(btcoexist,
1200 					     BTC_ANT_PATH_BT, false, false);
1201 			break;
1202 		case 9:   /* Software control, Antenna at WiFi side */
1203 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1204 						      0x0, 0x0, 0x0, 0x0);
1205 			halbtc8821a1ant_set_ant_path(btcoexist,
1206 					     BTC_ANT_PATH_WIFI, false, false);
1207 			break;
1208 		case 10:	/* under 5G */
1209 			halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
1210 						      0x0, 0x0, 0x8, 0x0);
1211 			halbtc8821a1ant_set_ant_path(btcoexist,
1212 					     BTC_ANT_PATH_BT, false, false);
1213 			break;
1214 		}
1215 	}
1216 	rssi_adjust_val = 0;
1217 	btcoexist->btc_set(btcoexist,
1218 		BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
1219 
1220 	/* update pre state */
1221 	coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1222 	coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1223 }
1224 
halbtc8821a1ant_coex_all_off(IN struct btc_coexist * btcoexist)1225 void halbtc8821a1ant_coex_all_off(IN struct btc_coexist *btcoexist)
1226 {
1227 	/* sw all off */
1228 	halbtc8821a1ant_sw_mechanism(btcoexist, false);
1229 
1230 	/* hw all off */
1231 	halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1232 }
1233 
halbtc8821a1ant_is_common_action(IN struct btc_coexist * btcoexist)1234 boolean halbtc8821a1ant_is_common_action(IN struct btc_coexist *btcoexist)
1235 {
1236 	boolean			common = false, wifi_connected = false, wifi_busy = false;
1237 
1238 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1239 			   &wifi_connected);
1240 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1241 
1242 	if (!wifi_connected &&
1243 	    BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1244 	    coex_dm->bt_status) {
1245 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1246 			"[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
1247 		BTC_TRACE(trace_buf);
1248 		halbtc8821a1ant_sw_mechanism(btcoexist, false);
1249 
1250 		common = true;
1251 	} else if (wifi_connected &&
1252 		   (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1253 		    coex_dm->bt_status)) {
1254 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1255 			"[BTCoex], Wifi connected + BT non connected-idle!!\n");
1256 		BTC_TRACE(trace_buf);
1257 		halbtc8821a1ant_sw_mechanism(btcoexist, false);
1258 
1259 		common = true;
1260 	} else if (!wifi_connected &&
1261 		(BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
1262 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1263 			"[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
1264 		BTC_TRACE(trace_buf);
1265 		halbtc8821a1ant_sw_mechanism(btcoexist, false);
1266 
1267 		common = true;
1268 	} else if (wifi_connected &&
1269 		(BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
1270 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1271 			    "[BTCoex], Wifi connected + BT connected-idle!!\n");
1272 		BTC_TRACE(trace_buf);
1273 		halbtc8821a1ant_sw_mechanism(btcoexist, false);
1274 
1275 		common = true;
1276 	} else if (!wifi_connected &&
1277 		(BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE != coex_dm->bt_status)) {
1278 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1279 			    "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
1280 		BTC_TRACE(trace_buf);
1281 		halbtc8821a1ant_sw_mechanism(btcoexist, false);
1282 
1283 		common = true;
1284 	} else {
1285 		if (wifi_busy) {
1286 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1287 				"[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1288 			BTC_TRACE(trace_buf);
1289 		} else {
1290 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1291 				"[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1292 			BTC_TRACE(trace_buf);
1293 		}
1294 
1295 		common = false;
1296 	}
1297 
1298 	return common;
1299 }
1300 
halbtc8821a1ant_ps_tdma_check_for_power_save_state(IN struct btc_coexist * btcoexist,IN boolean new_ps_state)1301 void halbtc8821a1ant_ps_tdma_check_for_power_save_state(
1302 	IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1303 {
1304 	u8	lps_mode = 0x0;
1305 
1306 	btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1307 
1308 	if (lps_mode) {	/* already under LPS state */
1309 		if (new_ps_state) {
1310 			/* keep state under LPS, do nothing. */
1311 		} else {
1312 			/* will leave LPS state, turn off psTdma first */
1313 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1314 						1);
1315 		}
1316 	} else {					/* NO PS state */
1317 		if (new_ps_state) {
1318 			/* will enter LPS state, turn off psTdma first */
1319 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1320 						0);
1321 		} else {
1322 			/* keep state under NO PS state, do nothing. */
1323 		}
1324 	}
1325 }
1326 
halbtc8821a1ant_power_save_state(IN struct btc_coexist * btcoexist,IN u8 ps_type,IN u8 lps_val,IN u8 rpwm_val)1327 void halbtc8821a1ant_power_save_state(IN struct btc_coexist *btcoexist,
1328 			      IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
1329 {
1330 	boolean		low_pwr_disable = false;
1331 
1332 	switch (ps_type) {
1333 	case BTC_PS_WIFI_NATIVE:
1334 		/* recover to original 32k low power setting */
1335 		low_pwr_disable = false;
1336 		btcoexist->btc_set(btcoexist,
1337 				   BTC_SET_ACT_DISABLE_LOW_POWER,
1338 				   &low_pwr_disable);
1339 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1340 				   NULL);
1341 		break;
1342 	case BTC_PS_LPS_ON:
1343 		halbtc8821a1ant_ps_tdma_check_for_power_save_state(
1344 			btcoexist, true);
1345 		halbtc8821a1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1346 					 lps_val, rpwm_val);
1347 		/* when coex force to enter LPS, do not enter 32k low power. */
1348 		low_pwr_disable = true;
1349 		btcoexist->btc_set(btcoexist,
1350 				   BTC_SET_ACT_DISABLE_LOW_POWER,
1351 				   &low_pwr_disable);
1352 		/* power save must executed before psTdma. */
1353 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1354 				   NULL);
1355 		break;
1356 	case BTC_PS_LPS_OFF:
1357 		halbtc8821a1ant_ps_tdma_check_for_power_save_state(
1358 			btcoexist, false);
1359 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1360 				   NULL);
1361 		break;
1362 	default:
1363 		break;
1364 	}
1365 }
1366 
halbtc8821a1ant_coex_under_5g(IN struct btc_coexist * btcoexist)1367 void halbtc8821a1ant_coex_under_5g(IN struct btc_coexist *btcoexist)
1368 {
1369 	halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1370 					 0x0);
1371 
1372 	halbtc8821a1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
1373 
1374 	halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 10);
1375 
1376 	halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1377 
1378 	halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
1379 
1380 	halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5);
1381 }
1382 
halbtc8821a1ant_action_wifi_only(IN struct btc_coexist * btcoexist)1383 void halbtc8821a1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
1384 {
1385 	halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1386 	halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9);
1387 }
1388 
halbtc8821a1ant_monitor_bt_enable_disable(IN struct btc_coexist * btcoexist)1389 void halbtc8821a1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
1390 {
1391 	static u32		bt_disable_cnt = 0;
1392 	boolean			bt_active = true, bt_disabled = false;
1393 
1394 	/* This function check if bt is disabled */
1395 
1396 	if (coex_sta->high_priority_tx == 0 &&
1397 	    coex_sta->high_priority_rx == 0 &&
1398 	    coex_sta->low_priority_tx == 0 &&
1399 	    coex_sta->low_priority_rx == 0)
1400 		bt_active = false;
1401 	if (coex_sta->high_priority_tx == 0xffff &&
1402 	    coex_sta->high_priority_rx == 0xffff &&
1403 	    coex_sta->low_priority_tx == 0xffff &&
1404 	    coex_sta->low_priority_rx == 0xffff)
1405 		bt_active = false;
1406 	if (bt_active) {
1407 		bt_disable_cnt = 0;
1408 		bt_disabled = false;
1409 		btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1410 				   &bt_disabled);
1411 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1412 			    "[BTCoex], BT is enabled !!\n");
1413 		BTC_TRACE(trace_buf);
1414 	} else {
1415 		bt_disable_cnt++;
1416 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1417 			    "[BTCoex], bt all counters=0, %d times!!\n",
1418 			    bt_disable_cnt);
1419 		BTC_TRACE(trace_buf);
1420 		if (bt_disable_cnt >= 2) {
1421 			bt_disabled = true;
1422 			btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1423 					   &bt_disabled);
1424 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1425 				    "[BTCoex], BT is disabled !!\n");
1426 			BTC_TRACE(trace_buf);
1427 			halbtc8821a1ant_action_wifi_only(btcoexist);
1428 		}
1429 	}
1430 	if (coex_sta->bt_disabled != bt_disabled) {
1431 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1432 			    "[BTCoex], BT is from %s to %s!!\n",
1433 			    (coex_sta->bt_disabled ? "disabled" : "enabled"),
1434 			    (bt_disabled ? "disabled" : "enabled"));
1435 		BTC_TRACE(trace_buf);
1436 		coex_sta->bt_disabled = bt_disabled;
1437 		if (!bt_disabled) {
1438 		} else {
1439 			btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1440 					   NULL);
1441 			btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1442 					   NULL);
1443 		}
1444 	}
1445 }
1446 
1447 /* *********************************************
1448  *
1449  *	Software Coex Mechanism start
1450  *
1451  * ********************************************* */
1452 
halbtc8821a1ant_action_bt_whck_test(IN struct btc_coexist * btcoexist)1453 void halbtc8821a1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist)
1454 {
1455 	halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1456 					 0x0);
1457 
1458 	halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1459 	/* halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false); */
1460 	halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, false, false);
1461 	halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1462 }
1463 /* SCO only or SCO+PAN(HS) */
halbtc8821a1ant_action_sco(IN struct btc_coexist * btcoexist)1464 void halbtc8821a1ant_action_sco(IN struct btc_coexist *btcoexist)
1465 {
1466 	halbtc8821a1ant_sw_mechanism(btcoexist, true);
1467 }
1468 
halbtc8821a1ant_action_hid(IN struct btc_coexist * btcoexist)1469 void halbtc8821a1ant_action_hid(IN struct btc_coexist *btcoexist)
1470 {
1471 	halbtc8821a1ant_sw_mechanism(btcoexist, true);
1472 }
1473 
1474 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
halbtc8821a1ant_action_a2dp(IN struct btc_coexist * btcoexist)1475 void halbtc8821a1ant_action_a2dp(IN struct btc_coexist *btcoexist)
1476 {
1477 	halbtc8821a1ant_sw_mechanism(btcoexist, false);
1478 }
1479 
halbtc8821a1ant_action_a2dp_pan_hs(IN struct btc_coexist * btcoexist)1480 void halbtc8821a1ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
1481 {
1482 	halbtc8821a1ant_sw_mechanism(btcoexist, false);
1483 }
1484 
halbtc8821a1ant_action_pan_edr(IN struct btc_coexist * btcoexist)1485 void halbtc8821a1ant_action_pan_edr(IN struct btc_coexist *btcoexist)
1486 {
1487 	halbtc8821a1ant_sw_mechanism(btcoexist, false);
1488 }
1489 
1490 /* PAN(HS) only */
halbtc8821a1ant_action_pan_hs(IN struct btc_coexist * btcoexist)1491 void halbtc8821a1ant_action_pan_hs(IN struct btc_coexist *btcoexist)
1492 {
1493 	halbtc8821a1ant_sw_mechanism(btcoexist, false);
1494 }
1495 
1496 /* PAN(EDR)+A2DP */
halbtc8821a1ant_action_pan_edr_a2dp(IN struct btc_coexist * btcoexist)1497 void halbtc8821a1ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
1498 {
1499 	halbtc8821a1ant_sw_mechanism(btcoexist, false);
1500 }
1501 
halbtc8821a1ant_action_pan_edr_hid(IN struct btc_coexist * btcoexist)1502 void halbtc8821a1ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
1503 {
1504 	halbtc8821a1ant_sw_mechanism(btcoexist, true);
1505 }
1506 
1507 /* HID+A2DP+PAN(EDR) */
halbtc8821a1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist * btcoexist)1508 void halbtc8821a1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
1509 {
1510 	halbtc8821a1ant_sw_mechanism(btcoexist, true);
1511 }
1512 
halbtc8821a1ant_action_hid_a2dp(IN struct btc_coexist * btcoexist)1513 void halbtc8821a1ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
1514 {
1515 	halbtc8821a1ant_sw_mechanism(btcoexist, true);
1516 }
1517 
1518 /* *********************************************
1519  *
1520  *	Non-Software Coex Mechanism start
1521  *
1522  * ********************************************* */
halbtc8821a1ant_action_wifi_multi_port(IN struct btc_coexist * btcoexist)1523 void halbtc8821a1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
1524 {
1525 	halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1526 					 0x0);
1527 
1528 	halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1529 	halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1530 }
1531 
halbtc8821a1ant_action_hs(IN struct btc_coexist * btcoexist)1532 void halbtc8821a1ant_action_hs(IN struct btc_coexist *btcoexist)
1533 {
1534 	halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1535 	halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1536 }
1537 
halbtc8821a1ant_action_bt_inquiry(IN struct btc_coexist * btcoexist)1538 void halbtc8821a1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
1539 {
1540 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1541 	boolean			wifi_connected = false, ap_enable = false, wifi_busy = false,
1542 				bt_busy = false;
1543 
1544 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1545 			   &ap_enable);
1546 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1547 			   &wifi_connected);
1548 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1549 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
1550 
1551 	if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) {
1552 		halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1553 						 0x0, 0x0);
1554 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1555 
1556 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1557 	}
1558 
1559 	/* sy modify	 */
1560 	else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1561 		 (bt_link_info->a2dp_exist)) {
1562 		/* SCO/HID/A2DP  busy */
1563 		halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1564 						 0x0, 0x0);
1565 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1566 
1567 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1568 	}
1569 
1570 	/* sy modify */
1571 
1572 	else if ((bt_link_info->a2dp_exist) &&
1573 		 (bt_link_info->hid_exist)) {
1574 		/* A2DP+HID	busy */
1575 		halbtc8821a1ant_power_save_state(btcoexist,
1576 						 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1577 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1578 					14);
1579 
1580 		halbtc8821a1ant_coex_table_with_type(btcoexist,
1581 						     NORMAL_EXEC, 1);
1582 	}
1583 
1584 
1585 	else if ((bt_link_info->pan_exist) || (wifi_busy)) {
1586 		halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1587 						 0x0, 0x0);
1588 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1589 
1590 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1591 	} else {
1592 		halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1593 						 0x0, 0x0);
1594 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1595 
1596 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1597 	}
1598 }
1599 
halbtc8821a1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist * btcoexist,IN u8 wifi_status)1600 void halbtc8821a1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
1601 		*btcoexist, IN u8 wifi_status)
1602 {
1603 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1604 	boolean	wifi_connected = false;
1605 
1606 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1607 			   &wifi_connected);
1608 
1609 	/* tdma and coex table */
1610 
1611 	if (bt_link_info->sco_exist) {
1612 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 41);
1613 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1614 	} else { /* HID */
1615 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 42);
1616 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1617 	}
1618 }
1619 
halbtc8821a1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist * btcoexist,IN u8 wifi_status)1620 void halbtc8821a1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
1621 		*btcoexist, IN u8 wifi_status)
1622 {
1623 	u8		bt_rssi_state;
1624 
1625 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1626 	bt_rssi_state = halbtc8821a1ant_bt_rssi_state(2, 28, 0);
1627 
1628 	if (bt_link_info->hid_only) { /* HID */
1629 		halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1630 				wifi_status);
1631 		coex_dm->auto_tdma_adjust = false;
1632 		return;
1633 	} else if (bt_link_info->a2dp_only) { /* A2DP		 */
1634 		if (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
1635 			/* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); */
1636 			/* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); */
1637 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1638 						32);
1639 			halbtc8821a1ant_coex_table_with_type(btcoexist,
1640 							     NORMAL_EXEC, 1);
1641 			coex_dm->auto_tdma_adjust = false;
1642 		} else if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
1643 			   (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
1644 			/* halbtc8821a1ant_tdma_duration_adjust_for_acl(btcoexist, wifi_status); */
1645 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1646 						14);
1647 			halbtc8821a1ant_coex_table_with_type(btcoexist,
1648 							     NORMAL_EXEC, 1);
1649 		} else { /* for low BT RSSI */
1650 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1651 						14);
1652 			halbtc8821a1ant_coex_table_with_type(btcoexist,
1653 							     NORMAL_EXEC, 1);
1654 			coex_dm->auto_tdma_adjust = false;
1655 		}
1656 	} else if (bt_link_info->hid_exist &&
1657 		   bt_link_info->a2dp_exist) { /* HID+A2DP */
1658 		if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
1659 		    (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
1660 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1661 						14);
1662 			coex_dm->auto_tdma_adjust = false;
1663 		} else { /* for low BT RSSI */
1664 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1665 						14);
1666 			coex_dm->auto_tdma_adjust = false;
1667 		}
1668 
1669 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1670 	} else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
1671 		bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP)			 */
1672 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1673 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
1674 		coex_dm->auto_tdma_adjust = false;
1675 	} else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
1676 		   (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
1677 		bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
1678 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 43);
1679 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1680 		coex_dm->auto_tdma_adjust = false;
1681 	} else {
1682 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1683 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1684 		coex_dm->auto_tdma_adjust = false;
1685 	}
1686 }
1687 
halbtc8821a1ant_action_wifi_not_connected(IN struct btc_coexist * btcoexist)1688 void halbtc8821a1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
1689 {
1690 	/* power save state */
1691 	halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1692 					 0x0);
1693 
1694 	/* tdma and coex table	 */
1695 	halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
1696 	halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1697 }
1698 
halbtc8821a1ant_action_wifi_not_connected_scan(IN struct btc_coexist * btcoexist)1699 void halbtc8821a1ant_action_wifi_not_connected_scan(IN struct btc_coexist
1700 		*btcoexist)
1701 {
1702 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1703 
1704 	halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1705 					 0x0);
1706 
1707 	/* tdma and coex table */
1708 	if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1709 		if (bt_link_info->a2dp_exist) {
1710 			/* sy modify */
1711 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1712 						14);
1713 			halbtc8821a1ant_coex_table_with_type(btcoexist,
1714 							     NORMAL_EXEC, 1);
1715 		} else if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
1716 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1717 						22);
1718 			halbtc8821a1ant_coex_table_with_type(btcoexist,
1719 							     NORMAL_EXEC, 4);
1720 		} else {
1721 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1722 						20);
1723 			halbtc8821a1ant_coex_table_with_type(btcoexist,
1724 							     NORMAL_EXEC, 4);
1725 		}
1726 	} else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1727 		   (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1728 		    coex_dm->bt_status)) {
1729 		halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1730 				BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1731 	} else {
1732 		/* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */
1733 		/* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */
1734 
1735 		/* Bryant Add */
1736 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1737 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1738 	}
1739 }
1740 
halbtc8821a1ant_action_wifi_not_connected_asso_auth(IN struct btc_coexist * btcoexist)1741 void halbtc8821a1ant_action_wifi_not_connected_asso_auth(
1742 	IN struct btc_coexist *btcoexist)
1743 {
1744 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1745 
1746 	halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1747 					 0x0);
1748 
1749 	/* tdma and coex table */
1750 	if ((bt_link_info->sco_exist)  || (bt_link_info->hid_exist)) {
1751 		/* sy modify */
1752 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
1753 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1754 	} else if ((bt_link_info->a2dp_exist)  || (bt_link_info->pan_exist)) {
1755 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1756 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1757 	} else {
1758 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1759 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1760 	}
1761 }
1762 
halbtc8821a1ant_action_wifi_connected_scan(IN struct btc_coexist * btcoexist)1763 void halbtc8821a1ant_action_wifi_connected_scan(IN struct btc_coexist
1764 		*btcoexist)
1765 {
1766 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1767 
1768 	halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1769 					 0x0);
1770 
1771 	/* tdma and coex table */
1772 	if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1773 		if (bt_link_info->a2dp_exist) {
1774 			/* sy modify */
1775 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1776 						14);
1777 			halbtc8821a1ant_coex_table_with_type(btcoexist,
1778 							     NORMAL_EXEC, 1);
1779 		} else if (bt_link_info->a2dp_exist &&
1780 			   bt_link_info->pan_exist) {
1781 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1782 						22);
1783 			halbtc8821a1ant_coex_table_with_type(btcoexist,
1784 							     NORMAL_EXEC, 4);
1785 		} else {
1786 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1787 						20);
1788 			halbtc8821a1ant_coex_table_with_type(btcoexist,
1789 							     NORMAL_EXEC, 4);
1790 		}
1791 	} else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1792 		   (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1793 		    coex_dm->bt_status)) {
1794 		halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1795 				BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1796 	} else {
1797 		/* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */
1798 		/* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */
1799 
1800 		/* Bryant Add */
1801 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1802 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1803 	}
1804 }
1805 
halbtc8821a1ant_action_wifi_connected_specific_packet(IN struct btc_coexist * btcoexist)1806 void halbtc8821a1ant_action_wifi_connected_specific_packet(
1807 	IN struct btc_coexist *btcoexist)
1808 {
1809 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1810 
1811 	halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1812 					 0x0);
1813 
1814 	/* tdma and coex table */
1815 	/* sy modify */
1816 	if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
1817 	    (bt_link_info->a2dp_exist)) {
1818 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1819 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1820 	}
1821 
1822 	if ((bt_link_info->hid_exist) && (bt_link_info->a2dp_exist)) {
1823 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1824 					14);
1825 		halbtc8821a1ant_coex_table_with_type(btcoexist,
1826 						     NORMAL_EXEC, 1);
1827 	}
1828 
1829 
1830 	else if (bt_link_info->pan_exist) {
1831 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1832 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1833 	} else {
1834 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1835 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1836 	}
1837 }
1838 
halbtc8821a1ant_action_wifi_connected(IN struct btc_coexist * btcoexist)1839 void halbtc8821a1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
1840 {
1841 	boolean	wifi_busy = false;
1842 	boolean	scan = false, link = false, roam = false;
1843 	boolean		under_4way = false, ap_enable = false;
1844 
1845 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1846 		    "[BTCoex], CoexForWifiConnect()===>\n");
1847 	BTC_TRACE(trace_buf);
1848 
1849 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
1850 			   &under_4way);
1851 	if (under_4way) {
1852 		halbtc8821a1ant_action_wifi_connected_specific_packet(btcoexist);
1853 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1854 			"[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
1855 		BTC_TRACE(trace_buf);
1856 		return;
1857 	}
1858 
1859 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1860 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1861 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1862 	if (scan || link || roam) {
1863 		if (scan)
1864 			halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
1865 		else
1866 			halbtc8821a1ant_action_wifi_connected_specific_packet(
1867 				btcoexist);
1868 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1869 			"[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
1870 		BTC_TRACE(trace_buf);
1871 		return;
1872 	}
1873 
1874 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1875 			   &ap_enable);
1876 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1877 	/* power save state */
1878 	if (!ap_enable &&
1879 	    BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status &&
1880 	    !btcoexist->bt_link_info.hid_only) {
1881 		if (!wifi_busy && btcoexist->bt_link_info.a2dp_only)	/* A2DP */
1882 			halbtc8821a1ant_power_save_state(btcoexist,
1883 						 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1884 		else
1885 			halbtc8821a1ant_power_save_state(btcoexist,
1886 						 BTC_PS_LPS_ON, 0x50, 0x4);
1887 	} else
1888 		halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1889 						 0x0, 0x0);
1890 
1891 	/* tdma and coex table */
1892 	if (!wifi_busy) {
1893 		if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1894 			halbtc8821a1ant_action_wifi_connected_bt_acl_busy(
1895 				btcoexist,
1896 				BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1897 		} else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
1898 			    coex_dm->bt_status) ||
1899 			   (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1900 			    coex_dm->bt_status)) {
1901 			halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1902 				BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1903 		} else {
1904 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1905 						8);
1906 			halbtc8821a1ant_coex_table_with_type(btcoexist,
1907 							     NORMAL_EXEC, 2);
1908 		}
1909 	} else {
1910 		if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1911 			halbtc8821a1ant_action_wifi_connected_bt_acl_busy(
1912 				btcoexist,
1913 				BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
1914 		} else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
1915 			    coex_dm->bt_status) ||
1916 			   (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1917 			    coex_dm->bt_status)) {
1918 			halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
1919 				BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
1920 		} else {
1921 			halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1922 						8);
1923 			halbtc8821a1ant_coex_table_with_type(btcoexist,
1924 							     NORMAL_EXEC, 2);
1925 		}
1926 	}
1927 }
1928 
halbtc8821a1ant_run_sw_coexist_mechanism(IN struct btc_coexist * btcoexist)1929 void halbtc8821a1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
1930 {
1931 	u8	algorithm = 0;
1932 
1933 	algorithm = halbtc8821a1ant_action_algorithm(btcoexist);
1934 	coex_dm->cur_algorithm = algorithm;
1935 
1936 	if (halbtc8821a1ant_is_common_action(btcoexist)) {
1937 
1938 	} else {
1939 		switch (coex_dm->cur_algorithm) {
1940 		case BT_8821A_1ANT_COEX_ALGO_SCO:
1941 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1942 				    "[BTCoex], Action algorithm = SCO.\n");
1943 			BTC_TRACE(trace_buf);
1944 			halbtc8821a1ant_action_sco(btcoexist);
1945 			break;
1946 		case BT_8821A_1ANT_COEX_ALGO_HID:
1947 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1948 				    "[BTCoex], Action algorithm = HID.\n");
1949 			BTC_TRACE(trace_buf);
1950 			halbtc8821a1ant_action_hid(btcoexist);
1951 			break;
1952 		case BT_8821A_1ANT_COEX_ALGO_A2DP:
1953 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1954 				    "[BTCoex], Action algorithm = A2DP.\n");
1955 			BTC_TRACE(trace_buf);
1956 			halbtc8821a1ant_action_a2dp(btcoexist);
1957 			break;
1958 		case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS:
1959 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1960 				"[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
1961 			BTC_TRACE(trace_buf);
1962 			halbtc8821a1ant_action_a2dp_pan_hs(btcoexist);
1963 			break;
1964 		case BT_8821A_1ANT_COEX_ALGO_PANEDR:
1965 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1966 				    "[BTCoex], Action algorithm = PAN(EDR).\n");
1967 			BTC_TRACE(trace_buf);
1968 			halbtc8821a1ant_action_pan_edr(btcoexist);
1969 			break;
1970 		case BT_8821A_1ANT_COEX_ALGO_PANHS:
1971 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1972 				    "[BTCoex], Action algorithm = HS mode.\n");
1973 			BTC_TRACE(trace_buf);
1974 			halbtc8821a1ant_action_pan_hs(btcoexist);
1975 			break;
1976 		case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP:
1977 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1978 				    "[BTCoex], Action algorithm = PAN+A2DP.\n");
1979 			BTC_TRACE(trace_buf);
1980 			halbtc8821a1ant_action_pan_edr_a2dp(btcoexist);
1981 			break;
1982 		case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID:
1983 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1984 				"[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
1985 			BTC_TRACE(trace_buf);
1986 			halbtc8821a1ant_action_pan_edr_hid(btcoexist);
1987 			break;
1988 		case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
1989 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1990 				"[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
1991 			BTC_TRACE(trace_buf);
1992 			halbtc8821a1ant_action_hid_a2dp_pan_edr(
1993 				btcoexist);
1994 			break;
1995 		case BT_8821A_1ANT_COEX_ALGO_HID_A2DP:
1996 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1997 				    "[BTCoex], Action algorithm = HID+A2DP.\n");
1998 			BTC_TRACE(trace_buf);
1999 			halbtc8821a1ant_action_hid_a2dp(btcoexist);
2000 			break;
2001 		default:
2002 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2003 				"[BTCoex], Action algorithm = coexist All Off!!\n");
2004 			BTC_TRACE(trace_buf);
2005 			/* halbtc8821a1ant_coex_all_off(btcoexist); */
2006 			break;
2007 		}
2008 		coex_dm->pre_algorithm = coex_dm->cur_algorithm;
2009 	}
2010 }
2011 
halbtc8821a1ant_run_coexist_mechanism(IN struct btc_coexist * btcoexist)2012 void halbtc8821a1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
2013 {
2014 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2015 	boolean	wifi_connected = false, bt_hs_on = false;
2016 	boolean	increase_scan_dev_num = false;
2017 	boolean	bt_ctrl_agg_buf_size = false;
2018 	u8	agg_buf_size = 5;
2019 	u8	wifi_rssi_state = BTC_RSSI_STATE_HIGH;
2020 	u32	wifi_link_status = 0;
2021 	u32	num_of_wifi_link = 0;
2022 	boolean	wifi_under_5g = false;
2023 
2024 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2025 		    "[BTCoex], RunCoexistMechanism()===>\n");
2026 	BTC_TRACE(trace_buf);
2027 
2028 	if (btcoexist->manual_control) {
2029 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2030 			"[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2031 		BTC_TRACE(trace_buf);
2032 		return;
2033 	}
2034 
2035 	if (btcoexist->stop_coex_dm) {
2036 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2037 			"[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2038 		BTC_TRACE(trace_buf);
2039 		return;
2040 	}
2041 
2042 	if (coex_sta->under_ips) {
2043 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2044 			    "[BTCoex], wifi is under IPS !!!\n");
2045 		BTC_TRACE(trace_buf);
2046 		return;
2047 	}
2048 
2049 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2050 	if (wifi_under_5g) {
2051 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2052 			"[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2053 		BTC_TRACE(trace_buf);
2054 		halbtc8821a1ant_coex_under_5g(btcoexist);
2055 		return;
2056 	}
2057 	if (coex_sta->bt_whck_test) {
2058 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2059 			    "[BTCoex], BT is under WHCK TEST!!!\n");
2060 		BTC_TRACE(trace_buf);
2061 		halbtc8821a1ant_action_bt_whck_test(btcoexist);
2062 		return;
2063 	}
2064 
2065 	if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
2066 	    (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2067 	    (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
2068 		increase_scan_dev_num = true;
2069 
2070 	btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
2071 			   &increase_scan_dev_num);
2072 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2073 			   &wifi_connected);
2074 
2075 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2076 			   &wifi_link_status);
2077 	num_of_wifi_link = wifi_link_status >> 16;
2078 	if ((num_of_wifi_link >= 2) ||
2079 	    (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
2080 		halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2081 		halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2082 					   bt_ctrl_agg_buf_size, agg_buf_size);
2083 		halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2084 		return;
2085 	}
2086 
2087 	if (!bt_link_info->sco_exist && !bt_link_info->hid_exist)
2088 		halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2089 	else {
2090 		if (wifi_connected) {
2091 			wifi_rssi_state = halbtc8821a1ant_wifi_rssi_state(
2092 						  btcoexist, 1, 2, 30, 0);
2093 			if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2094 			    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2095 				/* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */
2096 				halbtc8821a1ant_limited_tx(btcoexist,
2097 						   NORMAL_EXEC, 1, 1, 0, 1);
2098 			} else {
2099 				/* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */
2100 				halbtc8821a1ant_limited_tx(btcoexist,
2101 						   NORMAL_EXEC, 1, 1, 0, 1);
2102 			}
2103 		} else
2104 			halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
2105 						   0, 0);
2106 
2107 	}
2108 
2109 	if (bt_link_info->sco_exist) {
2110 		bt_ctrl_agg_buf_size = true;
2111 		agg_buf_size = 0x3;
2112 	} else if (bt_link_info->hid_exist) {
2113 		bt_ctrl_agg_buf_size = true;
2114 		agg_buf_size = 0x5;
2115 	} else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) {
2116 		bt_ctrl_agg_buf_size = true;
2117 		agg_buf_size = 0x8;
2118 	}
2119 	halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2120 				   bt_ctrl_agg_buf_size, agg_buf_size);
2121 
2122 	halbtc8821a1ant_run_sw_coexist_mechanism(btcoexist);
2123 
2124 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2125 	if (coex_sta->c2h_bt_inquiry_page) {
2126 		halbtc8821a1ant_action_bt_inquiry(btcoexist);
2127 		return;
2128 	} else if (bt_hs_on) {
2129 		halbtc8821a1ant_action_hs(btcoexist);
2130 		return;
2131 	}
2132 
2133 
2134 	if (!wifi_connected) {
2135 		boolean	scan = false, link = false, roam = false;
2136 
2137 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2138 			    "[BTCoex], wifi is non connected-idle !!!\n");
2139 		BTC_TRACE(trace_buf);
2140 
2141 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2142 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2143 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2144 
2145 		if (scan || link || roam) {
2146 			if (scan)
2147 				halbtc8821a1ant_action_wifi_not_connected_scan(
2148 					btcoexist);
2149 			else
2150 				halbtc8821a1ant_action_wifi_not_connected_asso_auth(
2151 					btcoexist);
2152 		} else
2153 			halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2154 	} else	/* wifi LPS/Busy */
2155 		halbtc8821a1ant_action_wifi_connected(btcoexist);
2156 }
2157 
halbtc8821a1ant_init_coex_dm(IN struct btc_coexist * btcoexist)2158 void halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2159 {
2160 	/* force to reset coex mechanism */
2161 	/* sw all off */
2162 	halbtc8821a1ant_sw_mechanism(btcoexist, false);
2163 
2164 	/* halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
2165 	halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2166 }
2167 
halbtc8821a1ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean back_up,IN boolean wifi_only)2168 void halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2169 				    IN boolean back_up, IN boolean wifi_only)
2170 {
2171 	u8	u8tmp = 0;
2172 	boolean			wifi_under_5g = false;
2173 
2174 
2175 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2176 		    "[BTCoex], 1Ant Init HW Config!!\n");
2177 	BTC_TRACE(trace_buf);
2178 
2179 	if (wifi_only)
2180 		return;
2181 
2182 	if (back_up) {
2183 		coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
2184 					    0x430);
2185 		coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
2186 					    0x434);
2187 		coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
2188 						      btcoexist, 0x42a);
2189 		coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
2190 				btcoexist, 0x456);
2191 	}
2192 
2193 	/* 0x790[5:0]=0x5 */
2194 	u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
2195 	u8tmp &= 0xc0;
2196 	u8tmp |= 0x5;
2197 	btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
2198 
2199 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2200 
2201 	/* Antenna config */
2202 	if (wifi_under_5g)
2203 		halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, true,
2204 					     false);
2205 	else
2206 		halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, true,
2207 					     false);
2208 
2209 	/* PTA parameter */
2210 	halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2211 
2212 	/* Enable counter statistics */
2213 	btcoexist->btc_write_1byte(btcoexist, 0x76e,
2214 			   0xc); /* 0x76e[3] =1, WLAN_Act control by PTA */
2215 	btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
2216 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
2217 }
2218 
2219 /* ************************************************************
2220  * work around function start with wa_halbtc8821a1ant_
2221  * ************************************************************
2222  * ************************************************************
2223  * extern function start with ex_halbtc8821a1ant_
2224  * ************************************************************ */
ex_halbtc8821a1ant_power_on_setting(IN struct btc_coexist * btcoexist)2225 void ex_halbtc8821a1ant_power_on_setting(IN struct btc_coexist *btcoexist)
2226 {
2227 }
2228 
ex_halbtc8821a1ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean wifi_only)2229 void ex_halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
2230 				       IN boolean wifi_only)
2231 {
2232 	halbtc8821a1ant_init_hw_config(btcoexist, true, wifi_only);
2233 }
2234 
ex_halbtc8821a1ant_init_coex_dm(IN struct btc_coexist * btcoexist)2235 void ex_halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
2236 {
2237 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2238 		    "[BTCoex], Coex Mechanism Init!!\n");
2239 	BTC_TRACE(trace_buf);
2240 
2241 	btcoexist->stop_coex_dm = false;
2242 
2243 	halbtc8821a1ant_init_coex_dm(btcoexist);
2244 
2245 	halbtc8821a1ant_query_bt_info(btcoexist);
2246 }
2247 
ex_halbtc8821a1ant_display_coex_info(IN struct btc_coexist * btcoexist)2248 void ex_halbtc8821a1ant_display_coex_info(IN struct btc_coexist *btcoexist)
2249 {
2250 	struct  btc_board_info		*board_info = &btcoexist->board_info;
2251 	struct  btc_bt_link_info	*bt_link_info = &btcoexist->bt_link_info;
2252 	u8				*cli_buf = btcoexist->cli_buf;
2253 	u8				u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
2254 	u16				u16tmp[4];
2255 	u32				u32tmp[4];
2256 	u32				fw_ver = 0, bt_patch_ver = 0;
2257 
2258 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2259 		   "\r\n ============[BT Coexist info]============");
2260 	CL_PRINTF(cli_buf);
2261 
2262 	if (btcoexist->manual_control) {
2263 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2264 			"\r\n ============[Under Manual Control]============");
2265 		CL_PRINTF(cli_buf);
2266 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2267 			   "\r\n ==========================================");
2268 		CL_PRINTF(cli_buf);
2269 	}
2270 	if (btcoexist->stop_coex_dm) {
2271 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2272 			   "\r\n ============[Coex is STOPPED]============");
2273 		CL_PRINTF(cli_buf);
2274 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2275 			   "\r\n ==========================================");
2276 		CL_PRINTF(cli_buf);
2277 	}
2278 
2279 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d",
2280 		   "Ant PG Num/ Ant Mech/ Ant Pos:",
2281 		   board_info->pg_ant_num, board_info->btdm_ant_num,
2282 		   board_info->btdm_ant_pos);
2283 	CL_PRINTF(cli_buf);
2284 
2285 	btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
2286 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
2287 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2288 		   "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
2289 		   "CoexVer/ FwVer/ PatchVer",
2290 		   glcoex_ver_date_8821a_1ant, glcoex_ver_8821a_1ant, fw_ver,
2291 		   bt_patch_ver, bt_patch_ver);
2292 	CL_PRINTF(cli_buf);
2293 
2294 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
2295 		   "Wifi channel informed to BT",
2296 		   coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
2297 		   coex_dm->wifi_chnl_info[2]);
2298 	CL_PRINTF(cli_buf);
2299 
2300 	/* wifi status */
2301 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2302 		   "============[Wifi Status]============");
2303 	CL_PRINTF(cli_buf);
2304 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
2305 
2306 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2307 		   "============[BT Status]============");
2308 	CL_PRINTF(cli_buf);
2309 
2310 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
2311 		   "BT [status/ rssi/ retryCnt]",
2312 		   ((coex_sta->bt_disabled) ? ("disabled") :	((
2313 		   coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
2314 			   : ((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2315 			       coex_dm->bt_status) ? "non-connected idle" :
2316 		((BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
2317 				       ? "connected-idle" : "busy")))),
2318 		   coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
2319 	CL_PRINTF(cli_buf);
2320 
2321 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
2322 		   "SCO/HID/PAN/A2DP",
2323 		   bt_link_info->sco_exist, bt_link_info->hid_exist,
2324 		   bt_link_info->pan_exist, bt_link_info->a2dp_exist);
2325 	CL_PRINTF(cli_buf);
2326 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
2327 
2328 	bt_info_ext = coex_sta->bt_info_ext;
2329 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
2330 		   "BT Info A2DP rate",
2331 		   (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
2332 	CL_PRINTF(cli_buf);
2333 
2334 	for (i = 0; i < BT_INFO_SRC_8821A_1ANT_MAX; i++) {
2335 		if (coex_sta->bt_info_c2h_cnt[i]) {
2336 			CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2337 				"\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
2338 				   glbt_info_src_8821a_1ant[i],
2339 				   coex_sta->bt_info_c2h[i][0],
2340 				   coex_sta->bt_info_c2h[i][1],
2341 				   coex_sta->bt_info_c2h[i][2],
2342 				   coex_sta->bt_info_c2h[i][3],
2343 				   coex_sta->bt_info_c2h[i][4],
2344 				   coex_sta->bt_info_c2h[i][5],
2345 				   coex_sta->bt_info_c2h[i][6],
2346 				   coex_sta->bt_info_c2h_cnt[i]);
2347 			CL_PRINTF(cli_buf);
2348 		}
2349 	}
2350 
2351 	if (!btcoexist->manual_control) {
2352 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
2353 			   "SM[LowPenaltyRA]",
2354 			   coex_dm->cur_low_penalty_ra);
2355 		CL_PRINTF(cli_buf);
2356 
2357 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2358 			   "============[mechanisms]============");
2359 		CL_PRINTF(cli_buf);
2360 
2361 		ps_tdma_case = coex_dm->cur_ps_tdma;
2362 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
2363 			"\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
2364 			   "PS TDMA",
2365 			   coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
2366 			   coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
2367 			   coex_dm->ps_tdma_para[4], ps_tdma_case,
2368 			   coex_dm->auto_tdma_adjust);
2369 		CL_PRINTF(cli_buf);
2370 
2371 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ",
2372 			   "IgnWlanAct",
2373 			   coex_dm->cur_ignore_wlan_act);
2374 		CL_PRINTF(cli_buf);
2375 
2376 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ",
2377 			   "Latest error condition(should be 0)",
2378 			   coex_dm->error_condition);
2379 		CL_PRINTF(cli_buf);
2380 	}
2381 
2382 	/* Hw setting		 */
2383 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
2384 		   "============[Hw setting]============");
2385 	CL_PRINTF(cli_buf);
2386 
2387 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2388 		   "backup ARFR1/ARFR2/RL/AMaxTime",
2389 		   coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2,
2390 		   coex_dm->backup_retry_limit,
2391 		   coex_dm->backup_ampdu_max_time);
2392 	CL_PRINTF(cli_buf);
2393 
2394 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
2395 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
2396 	u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
2397 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
2398 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2399 		   "0x430/0x434/0x42a/0x456",
2400 		   u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
2401 	CL_PRINTF(cli_buf);
2402 
2403 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
2404 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc58);
2405 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2406 		   "0x778/ 0xc58[29:25]",
2407 		   u8tmp[0], (u32tmp[0] & 0x3e000000) >> 25);
2408 	CL_PRINTF(cli_buf);
2409 
2410 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
2411 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x8db[6:5]",
2412 		   ((u8tmp[0] & 0x60) >> 5));
2413 	CL_PRINTF(cli_buf);
2414 
2415 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x975);
2416 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2417 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2418 		   "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]",
2419 		   (u32tmp[0] & 0x30000000) >> 28, u32tmp[0] & 0xff,
2420 		   u8tmp[0] & 0x3);
2421 	CL_PRINTF(cli_buf);
2422 
2423 
2424 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
2425 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
2426 	u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64);
2427 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2428 		   "0x40/0x4c[24:23]/0x64[0]",
2429 		   u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u8tmp[1] & 0x1);
2430 	CL_PRINTF(cli_buf);
2431 
2432 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
2433 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
2434 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2435 		   "0x550(bcn ctrl)/0x522",
2436 		   u32tmp[0], u8tmp[0]);
2437 	CL_PRINTF(cli_buf);
2438 
2439 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
2440 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)",
2441 		   u32tmp[0] & 0xff);
2442 	CL_PRINTF(cli_buf);
2443 
2444 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48);
2445 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5d);
2446 	u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
2447 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
2448 		   "OFDM-FA/ CCK-FA",
2449 		   u32tmp[0], (u8tmp[0] << 8) + u8tmp[1]);
2450 	CL_PRINTF(cli_buf);
2451 
2452 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
2453 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
2454 	u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
2455 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2456 		   "0x6c0/0x6c4/0x6c8(coexTable)",
2457 		   u32tmp[0], u32tmp[1], u32tmp[2]);
2458 	CL_PRINTF(cli_buf);
2459 
2460 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2461 		   "0x770(high-pri rx/tx)",
2462 		   coex_sta->high_priority_rx, coex_sta->high_priority_tx);
2463 	CL_PRINTF(cli_buf);
2464 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
2465 		   "0x774(low-pri rx/tx)",
2466 		   coex_sta->low_priority_rx, coex_sta->low_priority_tx);
2467 	CL_PRINTF(cli_buf);
2468 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 1)
2469 	halbtc8821a1ant_monitor_bt_ctr(btcoexist);
2470 #endif
2471 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
2472 }
2473 
2474 
ex_halbtc8821a1ant_ips_notify(IN struct btc_coexist * btcoexist,IN u8 type)2475 void ex_halbtc8821a1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2476 {
2477 	boolean	wifi_under_5g = false;
2478 
2479 	if (btcoexist->manual_control ||	btcoexist->stop_coex_dm)
2480 		return;
2481 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
2482 			   &wifi_under_5g);
2483 	if (wifi_under_5g) {
2484 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2485 			"[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2486 		BTC_TRACE(trace_buf);
2487 		halbtc8821a1ant_coex_under_5g(btcoexist);
2488 		return;
2489 	}
2490 
2491 	if (BTC_IPS_ENTER == type) {
2492 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2493 			    "[BTCoex], IPS ENTER notify\n");
2494 		BTC_TRACE(trace_buf);
2495 		coex_sta->under_ips = true;
2496 
2497 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2498 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2499 		halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
2500 					     true);
2501 		/* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
2502 	} else if (BTC_IPS_LEAVE == type) {
2503 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2504 			    "[BTCoex], IPS LEAVE notify\n");
2505 		BTC_TRACE(trace_buf);
2506 		coex_sta->under_ips = false;
2507 
2508 		halbtc8821a1ant_init_hw_config(btcoexist, false, false);
2509 		halbtc8821a1ant_init_coex_dm(btcoexist);
2510 		halbtc8821a1ant_query_bt_info(btcoexist);
2511 	}
2512 }
2513 
ex_halbtc8821a1ant_lps_notify(IN struct btc_coexist * btcoexist,IN u8 type)2514 void ex_halbtc8821a1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
2515 {
2516 
2517 
2518 	if (BTC_LPS_ENABLE == type) {
2519 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2520 			    "[BTCoex], LPS ENABLE notify\n");
2521 		BTC_TRACE(trace_buf);
2522 		coex_sta->under_lps = true;
2523 	} else if (BTC_LPS_DISABLE == type) {
2524 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2525 			    "[BTCoex], LPS DISABLE notify\n");
2526 		BTC_TRACE(trace_buf);
2527 		coex_sta->under_lps = false;
2528 	}
2529 }
2530 
ex_halbtc8821a1ant_scan_notify(IN struct btc_coexist * btcoexist,IN u8 type)2531 void ex_halbtc8821a1ant_scan_notify(IN struct btc_coexist *btcoexist,
2532 				    IN u8 type)
2533 {
2534 	boolean wifi_connected = false, bt_hs_on = false;
2535 	u32	wifi_link_status = 0;
2536 	u32	num_of_wifi_link = 0;
2537 	boolean	bt_ctrl_agg_buf_size = false;
2538 	u8	agg_buf_size = 5;
2539 	boolean	wifi_under_5g = false;
2540 
2541 	if (btcoexist->manual_control ||
2542 	    btcoexist->stop_coex_dm)
2543 		return;
2544 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2545 	if (wifi_under_5g) {
2546 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2547 			"[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2548 		BTC_TRACE(trace_buf);
2549 		halbtc8821a1ant_coex_under_5g(btcoexist);
2550 		return;
2551 	}
2552 
2553 	if (BTC_SCAN_START == type) {
2554 		coex_sta->wifi_is_high_pri_task = true;
2555 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2556 			    "[BTCoex], SCAN START notify\n");
2557 		BTC_TRACE(trace_buf);
2558 
2559 		halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
2560 			8);  /* Force antenna setup for no scan result issue */
2561 	} else {
2562 		coex_sta->wifi_is_high_pri_task = false;
2563 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2564 			    "[BTCoex], SCAN FINISH notify\n");
2565 		BTC_TRACE(trace_buf);
2566 	}
2567 
2568 	if (coex_sta->bt_disabled)
2569 		return;
2570 
2571 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2572 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2573 			   &wifi_connected);
2574 
2575 	halbtc8821a1ant_query_bt_info(btcoexist);
2576 
2577 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2578 			   &wifi_link_status);
2579 	num_of_wifi_link = wifi_link_status >> 16;
2580 	if (num_of_wifi_link >= 2) {
2581 		halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2582 		halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2583 					   bt_ctrl_agg_buf_size, agg_buf_size);
2584 		halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2585 		return;
2586 	}
2587 
2588 	if (coex_sta->c2h_bt_inquiry_page) {
2589 		halbtc8821a1ant_action_bt_inquiry(btcoexist);
2590 		return;
2591 	} else if (bt_hs_on) {
2592 		halbtc8821a1ant_action_hs(btcoexist);
2593 		return;
2594 	}
2595 
2596 	if (BTC_SCAN_START == type) {
2597 		if (!wifi_connected)	/* non-connected scan */
2598 			halbtc8821a1ant_action_wifi_not_connected_scan(
2599 				btcoexist);
2600 		else	/* wifi is connected */
2601 			halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
2602 	} else if (BTC_SCAN_FINISH == type) {
2603 		if (!wifi_connected)	/* non-connected scan */
2604 			halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2605 		else
2606 			halbtc8821a1ant_action_wifi_connected(btcoexist);
2607 	}
2608 }
2609 
ex_halbtc8821a1ant_connect_notify(IN struct btc_coexist * btcoexist,IN u8 type)2610 void ex_halbtc8821a1ant_connect_notify(IN struct btc_coexist *btcoexist,
2611 				       IN u8 type)
2612 {
2613 	boolean	wifi_connected = false, bt_hs_on = false;
2614 	u32	wifi_link_status = 0;
2615 	u32	num_of_wifi_link = 0;
2616 	boolean	bt_ctrl_agg_buf_size = false;
2617 	u8	agg_buf_size = 5;
2618 	boolean	wifi_under_5g = false;
2619 
2620 	if (btcoexist->manual_control ||
2621 	    btcoexist->stop_coex_dm ||
2622 	    coex_sta->bt_disabled)
2623 		return;
2624 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2625 	if (wifi_under_5g) {
2626 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2627 			"[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2628 		BTC_TRACE(trace_buf);
2629 		halbtc8821a1ant_coex_under_5g(btcoexist);
2630 		return;
2631 	}
2632 
2633 	if (BTC_ASSOCIATE_START == type) {
2634 		coex_sta->wifi_is_high_pri_task = true;
2635 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2636 			    "[BTCoex], CONNECT START notify\n");
2637 		BTC_TRACE(trace_buf);
2638 		coex_dm->arp_cnt = 0;
2639 	} else {
2640 		coex_sta->wifi_is_high_pri_task = false;
2641 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2642 			    "[BTCoex], CONNECT FINISH notify\n");
2643 		BTC_TRACE(trace_buf);
2644 		coex_dm->arp_cnt = 0;
2645 	}
2646 
2647 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2648 			   &wifi_link_status);
2649 	num_of_wifi_link = wifi_link_status >> 16;
2650 	if (num_of_wifi_link >= 2) {
2651 		halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2652 		halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2653 					   bt_ctrl_agg_buf_size, agg_buf_size);
2654 		halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2655 		return;
2656 	}
2657 
2658 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2659 	if (coex_sta->c2h_bt_inquiry_page) {
2660 		halbtc8821a1ant_action_bt_inquiry(btcoexist);
2661 		return;
2662 	} else if (bt_hs_on) {
2663 		halbtc8821a1ant_action_hs(btcoexist);
2664 		return;
2665 	}
2666 
2667 	if (BTC_ASSOCIATE_START == type)
2668 		halbtc8821a1ant_action_wifi_not_connected_asso_auth(btcoexist);
2669 	else if (BTC_ASSOCIATE_FINISH == type) {
2670 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2671 				   &wifi_connected);
2672 		if (!wifi_connected) /* non-connected scan */
2673 			halbtc8821a1ant_action_wifi_not_connected(btcoexist);
2674 		else
2675 			halbtc8821a1ant_action_wifi_connected(btcoexist);
2676 	}
2677 }
2678 
ex_halbtc8821a1ant_media_status_notify(IN struct btc_coexist * btcoexist,IN u8 type)2679 void ex_halbtc8821a1ant_media_status_notify(IN struct btc_coexist *btcoexist,
2680 		IN u8 type)
2681 {
2682 	u8			h2c_parameter[3] = {0};
2683 	u32			wifi_bw;
2684 	u8			wifi_central_chnl;
2685 	boolean	wifi_under_5g = false;
2686 
2687 	if (btcoexist->manual_control ||
2688 	    btcoexist->stop_coex_dm ||
2689 	    coex_sta->bt_disabled)
2690 		return;
2691 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2692 	if (wifi_under_5g) {
2693 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2694 			"[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2695 		BTC_TRACE(trace_buf);
2696 		halbtc8821a1ant_coex_under_5g(btcoexist);
2697 		return;
2698 	}
2699 
2700 	if (BTC_MEDIA_CONNECT == type) {
2701 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2702 			    "[BTCoex], MEDIA connect notify\n");
2703 		BTC_TRACE(trace_buf);
2704 	} else {
2705 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2706 			    "[BTCoex], MEDIA disconnect notify\n");
2707 		BTC_TRACE(trace_buf);
2708 		coex_dm->arp_cnt = 0;
2709 	}
2710 
2711 	/* only 2.4G we need to inform bt the chnl mask */
2712 	btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
2713 			   &wifi_central_chnl);
2714 	if ((BTC_MEDIA_CONNECT == type) &&
2715 	    (wifi_central_chnl <= 14)) {
2716 		/* h2c_parameter[0] = 0x1; */
2717 		h2c_parameter[0] = 0x0;
2718 		h2c_parameter[1] = wifi_central_chnl;
2719 		btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2720 		if (BTC_WIFI_BW_HT40 == wifi_bw)
2721 			h2c_parameter[2] = 0x30;
2722 		else
2723 			h2c_parameter[2] = 0x20;
2724 	}
2725 
2726 	coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
2727 	coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
2728 	coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
2729 
2730 	btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
2731 }
2732 
ex_halbtc8821a1ant_specific_packet_notify(IN struct btc_coexist * btcoexist,IN u8 type)2733 void ex_halbtc8821a1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
2734 		IN u8 type)
2735 {
2736 	boolean	bt_hs_on = false;
2737 	u32	wifi_link_status = 0;
2738 	u32	num_of_wifi_link = 0;
2739 	boolean	bt_ctrl_agg_buf_size = false;
2740 	u8	agg_buf_size = 5;
2741 	boolean	wifi_under_5g = false;
2742 
2743 	if (btcoexist->manual_control ||
2744 	    btcoexist->stop_coex_dm ||
2745 	    coex_sta->bt_disabled)
2746 		return;
2747 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2748 	if (wifi_under_5g) {
2749 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2750 			"[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2751 		BTC_TRACE(trace_buf);
2752 		halbtc8821a1ant_coex_under_5g(btcoexist);
2753 		return;
2754 	}
2755 
2756 	if (BTC_PACKET_DHCP == type ||
2757 	    BTC_PACKET_EAPOL == type ||
2758 	    BTC_PACKET_ARP == type) {
2759 		coex_sta->wifi_is_high_pri_task = true;
2760 
2761 		if (BTC_PACKET_ARP == type) {
2762 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2763 				    "[BTCoex], specific Packet ARP notify\n");
2764 			BTC_TRACE(trace_buf);
2765 		} else {
2766 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2767 				"[BTCoex], specific Packet DHCP or EAPOL notify\n");
2768 			BTC_TRACE(trace_buf);
2769 		}
2770 	} else {
2771 		coex_sta->wifi_is_high_pri_task = false;
2772 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2773 			"[BTCoex], specific Packet [Type = %d] notify\n", type);
2774 		BTC_TRACE(trace_buf);
2775 	}
2776 
2777 	coex_sta->specific_pkt_period_cnt = 0;
2778 
2779 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2780 			   &wifi_link_status);
2781 	num_of_wifi_link = wifi_link_status >> 16;
2782 	if (num_of_wifi_link >= 2) {
2783 		halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2784 		halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2785 					   bt_ctrl_agg_buf_size, agg_buf_size);
2786 		halbtc8821a1ant_action_wifi_multi_port(btcoexist);
2787 		return;
2788 	}
2789 
2790 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2791 	if (coex_sta->c2h_bt_inquiry_page) {
2792 		halbtc8821a1ant_action_bt_inquiry(btcoexist);
2793 		return;
2794 	} else if (bt_hs_on) {
2795 		halbtc8821a1ant_action_hs(btcoexist);
2796 		return;
2797 	}
2798 
2799 	if (BTC_PACKET_DHCP == type ||
2800 	    BTC_PACKET_EAPOL == type ||
2801 	    BTC_PACKET_ARP == type) {
2802 		if (BTC_PACKET_ARP == type) {
2803 			coex_dm->arp_cnt++;
2804 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2805 				    "[BTCoex], ARP Packet Count = %d\n",
2806 				    coex_dm->arp_cnt);
2807 			BTC_TRACE(trace_buf);
2808 			if (coex_dm->arp_cnt >=
2809 			    10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */
2810 				return;
2811 		}
2812 
2813 		halbtc8821a1ant_action_wifi_connected_specific_packet(btcoexist);
2814 	}
2815 }
2816 
ex_halbtc8821a1ant_bt_info_notify(IN struct btc_coexist * btcoexist,IN u8 * tmp_buf,IN u8 length)2817 void ex_halbtc8821a1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
2818 				       IN u8 *tmp_buf, IN u8 length)
2819 {
2820 	u8				bt_info = 0;
2821 	u8				i, rsp_source = 0;
2822 	boolean				wifi_connected = false;
2823 	boolean				bt_busy = false;
2824 	boolean				wifi_under_5g = false;
2825 
2826 
2827 	coex_sta->c2h_bt_info_req_sent = false;
2828 
2829 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2830 
2831 	rsp_source = tmp_buf[0] & 0xf;
2832 	if (rsp_source >= BT_INFO_SRC_8821A_1ANT_MAX)
2833 		rsp_source = BT_INFO_SRC_8821A_1ANT_WIFI_FW;
2834 	coex_sta->bt_info_c2h_cnt[rsp_source]++;
2835 
2836 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2837 		    "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
2838 		    length);
2839 	BTC_TRACE(trace_buf);
2840 	for (i = 0; i < length; i++) {
2841 		coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
2842 		if (i == 1)
2843 			bt_info = tmp_buf[i];
2844 		if (i == length - 1) {
2845 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
2846 				    tmp_buf[i]);
2847 			BTC_TRACE(trace_buf);
2848 		} else {
2849 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
2850 				    tmp_buf[i]);
2851 			BTC_TRACE(trace_buf);
2852 		}
2853 	}
2854 	/* if 0xff, it means BT is under WHCK test */
2855 	if (bt_info == 0xff)
2856 		coex_sta->bt_whck_test = true;
2857 	else
2858 		coex_sta->bt_whck_test = false;
2859 
2860 	if (BT_INFO_SRC_8821A_1ANT_WIFI_FW != rsp_source) {
2861 		coex_sta->bt_retry_cnt =	/* [3:0] */
2862 			coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
2863 
2864 		if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
2865 			coex_sta->c2h_bt_page = true;
2866 		else
2867 			coex_sta->c2h_bt_page = false;
2868 
2869 		coex_sta->bt_rssi =
2870 			coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
2871 
2872 		coex_sta->bt_info_ext =
2873 			coex_sta->bt_info_c2h[rsp_source][4];
2874 
2875 		coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
2876 					   & 0x40);
2877 		btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
2878 				   &coex_sta->bt_tx_rx_mask);
2879 		if (!coex_sta->bt_tx_rx_mask) {
2880 			/* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
2881 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2882 				"[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
2883 			BTC_TRACE(trace_buf);
2884 			btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
2885 						  0x3c, 0x15);
2886 		}
2887 
2888 		/* Here we need to resend some wifi info to BT */
2889 		/* because bt is reset and loss of the info. */
2890 		if (coex_sta->bt_info_ext & BIT(1)) {
2891 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2892 				"[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
2893 			BTC_TRACE(trace_buf);
2894 			btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2895 					   &wifi_connected);
2896 			if (wifi_connected)
2897 				ex_halbtc8821a1ant_media_status_notify(
2898 					btcoexist, BTC_MEDIA_CONNECT);
2899 			else
2900 				ex_halbtc8821a1ant_media_status_notify(
2901 					btcoexist, BTC_MEDIA_DISCONNECT);
2902 		}
2903 
2904 		if ((coex_sta->bt_info_ext & BIT(3)) && !wifi_under_5g) {
2905 			if (!btcoexist->manual_control &&
2906 			    !btcoexist->stop_coex_dm) {
2907 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2908 					"[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
2909 				BTC_TRACE(trace_buf);
2910 				halbtc8821a1ant_ignore_wlan_act(btcoexist,
2911 							FORCE_EXEC, false);
2912 			}
2913 		} else {
2914 			/* BT already NOT ignore Wlan active, do nothing here. */
2915 		}
2916 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
2917 		if ((coex_sta->bt_info_ext & BIT(4))) {
2918 			/* BT auto report already enabled, do nothing */
2919 		} else
2920 			halbtc8821a1ant_bt_auto_report(btcoexist, FORCE_EXEC,
2921 						       true);
2922 #endif
2923 	}
2924 
2925 	/* check BIT2 first ==> check if bt is under inquiry or page scan */
2926 	if (bt_info & BT_INFO_8821A_1ANT_B_INQ_PAGE)
2927 		coex_sta->c2h_bt_inquiry_page = true;
2928 	else
2929 		coex_sta->c2h_bt_inquiry_page = false;
2930 
2931 	/* set link exist status */
2932 	if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) {
2933 		coex_sta->bt_link_exist = false;
2934 		coex_sta->pan_exist = false;
2935 		coex_sta->a2dp_exist = false;
2936 		coex_sta->hid_exist = false;
2937 		coex_sta->sco_exist = false;
2938 	} else {	/* connection exists */
2939 		coex_sta->bt_link_exist = true;
2940 		if (bt_info & BT_INFO_8821A_1ANT_B_FTP)
2941 			coex_sta->pan_exist = true;
2942 		else
2943 			coex_sta->pan_exist = false;
2944 		if (bt_info & BT_INFO_8821A_1ANT_B_A2DP)
2945 			coex_sta->a2dp_exist = true;
2946 		else
2947 			coex_sta->a2dp_exist = false;
2948 		if (bt_info & BT_INFO_8821A_1ANT_B_HID)
2949 			coex_sta->hid_exist = true;
2950 		else
2951 			coex_sta->hid_exist = false;
2952 		if (bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO)
2953 			coex_sta->sco_exist = true;
2954 		else
2955 			coex_sta->sco_exist = false;
2956 	}
2957 
2958 	halbtc8821a1ant_update_bt_link_info(btcoexist);
2959 
2960 	bt_info = bt_info &
2961 		0x1f;  /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
2962 
2963 	if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) {
2964 		coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
2965 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2966 			"[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
2967 		BTC_TRACE(trace_buf);
2968 	} else if (bt_info ==
2969 		BT_INFO_8821A_1ANT_B_CONNECTION) {	/* connection exists but no busy */
2970 		coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE;
2971 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2972 			    "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
2973 		BTC_TRACE(trace_buf);
2974 	} else if ((bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO) ||
2975 		   (bt_info & BT_INFO_8821A_1ANT_B_SCO_BUSY)) {
2976 		coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_SCO_BUSY;
2977 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2978 			    "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
2979 		BTC_TRACE(trace_buf);
2980 	} else if (bt_info & BT_INFO_8821A_1ANT_B_ACL_BUSY) {
2981 		if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
2982 			coex_dm->auto_tdma_adjust = false;
2983 		coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_ACL_BUSY;
2984 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2985 			    "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
2986 		BTC_TRACE(trace_buf);
2987 	} else {
2988 		coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_MAX;
2989 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2990 			"[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
2991 		BTC_TRACE(trace_buf);
2992 	}
2993 
2994 	if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
2995 	    (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2996 	    (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
2997 		bt_busy = true;
2998 	else
2999 		bt_busy = false;
3000 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3001 
3002 	halbtc8821a1ant_run_coexist_mechanism(btcoexist);
3003 }
3004 
ex_halbtc8821a1ant_halt_notify(IN struct btc_coexist * btcoexist)3005 void ex_halbtc8821a1ant_halt_notify(IN struct btc_coexist *btcoexist)
3006 {
3007 	boolean	wifi_under_5g = false;
3008 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3009 	if (wifi_under_5g) {
3010 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3011 			"[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
3012 		BTC_TRACE(trace_buf);
3013 		halbtc8821a1ant_coex_under_5g(btcoexist);
3014 		return;
3015 	}
3016 
3017 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
3018 	BTC_TRACE(trace_buf);
3019 
3020 	halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
3021 					 0x0);
3022 	halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3023 	halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true);
3024 	/* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
3025 
3026 	halbtc8821a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3027 
3028 	ex_halbtc8821a1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3029 
3030 	btcoexist->stop_coex_dm = true;
3031 }
3032 
ex_halbtc8821a1ant_pnp_notify(IN struct btc_coexist * btcoexist,IN u8 pnp_state)3033 void ex_halbtc8821a1ant_pnp_notify(IN struct btc_coexist *btcoexist,
3034 				   IN u8 pnp_state)
3035 {
3036 	boolean wifi_under_5g = false;
3037 
3038 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3039 	if (wifi_under_5g) {
3040 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3041 			"[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
3042 		BTC_TRACE(trace_buf);
3043 		halbtc8821a1ant_coex_under_5g(btcoexist);
3044 		return;
3045 	}
3046 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
3047 	BTC_TRACE(trace_buf);
3048 
3049 	if (BTC_WIFI_PNP_SLEEP == pnp_state) {
3050 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3051 			    "[BTCoex], Pnp notify to SLEEP\n");
3052 		BTC_TRACE(trace_buf);
3053 
3054 		halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3055 						 0x0, 0x0);
3056 		halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3057 		halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3058 		halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
3059 					     true);
3060 		/* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
3061 
3062 		/* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */
3063 		/* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */
3064 		/* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */
3065 		coex_sta->under_ips = false;
3066 		coex_sta->under_lps = false;
3067 		btcoexist->stop_coex_dm = true;
3068 	} else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
3069 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3070 			    "[BTCoex], Pnp notify to WAKE UP\n");
3071 		BTC_TRACE(trace_buf);
3072 		btcoexist->stop_coex_dm = false;
3073 		halbtc8821a1ant_init_hw_config(btcoexist, false, false);
3074 		halbtc8821a1ant_init_coex_dm(btcoexist);
3075 		halbtc8821a1ant_query_bt_info(btcoexist);
3076 	}
3077 }
3078 
ex_halbtc8821a1ant_periodical(IN struct btc_coexist * btcoexist)3079 void ex_halbtc8821a1ant_periodical(IN struct btc_coexist *btcoexist)
3080 {
3081 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
3082 	halbtc8821a1ant_query_bt_info(btcoexist);
3083 	halbtc8821a1ant_monitor_bt_ctr(btcoexist);
3084 	halbtc8821a1ant_monitor_bt_enable_disable(btcoexist);
3085 #else
3086 	if (halbtc8821a1ant_is_wifi_status_changed(btcoexist) ||
3087 	    coex_dm->auto_tdma_adjust) {
3088 		/* if(coex_sta->specific_pkt_period_cnt > 2) */
3089 		/* { */
3090 		halbtc8821a1ant_run_coexist_mechanism(btcoexist);
3091 		/* } */
3092 	}
3093 
3094 	coex_sta->specific_pkt_period_cnt++;
3095 #endif
3096 }
3097 
3098 #endif
3099 
3100 #endif	/* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */
3101 
3102