xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8723bs/hal/btc/halbtc8821c1ant.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2016 - 2017 Realtek Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  *****************************************************************************/
16 
17 /* ************************************************************
18  * Description:
19  *
20  * This file is for RTL8821C Co-exist mechanism
21  *
22  * History
23  * 2012/11/15 Cosa first check in.
24  *
25  * ************************************************************ */
26 
27 /* ************************************************************
28  * include files
29  * ************************************************************ */
30 #include "mp_precomp.h"
31 
32 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
33 
34 #if (RTL8821C_SUPPORT == 1)
35 /* ************************************************************
36  * Global variables, these are static variables
37  * ************************************************************ */
38 static u8	*trace_buf = &gl_btc_trace_buf[0];
39 static struct  coex_dm_8821c_1ant		glcoex_dm_8821c_1ant;
40 static struct  coex_dm_8821c_1ant	*coex_dm = &glcoex_dm_8821c_1ant;
41 static struct  coex_sta_8821c_1ant		glcoex_sta_8821c_1ant;
42 static struct  coex_sta_8821c_1ant	*coex_sta = &glcoex_sta_8821c_1ant;
43 static struct  psdscan_sta_8821c_1ant		gl_psd_scan_8821c_1ant;
44 static struct  psdscan_sta_8821c_1ant	*psd_scan = &gl_psd_scan_8821c_1ant;
45 static struct	rfe_type_8821c_1ant		gl_rfe_type_8821c_1ant;
46 static struct	rfe_type_8821c_1ant		*rfe_type = &gl_rfe_type_8821c_1ant;
47 
48 
49 const char *const glbt_info_src_8821c_1ant[] = {
50 	"BT Info[wifi fw]",
51 	"BT Info[bt rsp]",
52 	"BT Info[bt auto report]",
53 };
54 
55 u32	glcoex_ver_date_8821c_1ant = 20170727;
56 u32	glcoex_ver_8821c_1ant = 0x1b;
57 u32	glcoex_ver_btdesired_8821c_1ant = 0x1b;
58 
59 
60 /* ************************************************************
61  * local function proto type if needed
62  * ************************************************************
63  * ************************************************************
64  * local function start with halbtc8821c1ant_
65  * ************************************************************ */
halbtc8821c1ant_bt_rssi_state(u8 level_num,u8 rssi_thresh,u8 rssi_thresh1)66 u8 halbtc8821c1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
67 {
68 	s32			bt_rssi = 0;
69 	u8			bt_rssi_state = coex_sta->pre_bt_rssi_state;
70 
71 	bt_rssi = coex_sta->bt_rssi;
72 
73 	if (level_num == 2) {
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_8821C_1ANT))
79 				bt_rssi_state = BTC_RSSI_STATE_HIGH;
80 			else
81 				bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
82 		} else {
83 			if (bt_rssi < rssi_thresh)
84 				bt_rssi_state = BTC_RSSI_STATE_LOW;
85 			else
86 				bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
87 		}
88 	} else if (level_num == 3) {
89 		if (rssi_thresh > rssi_thresh1) {
90 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
91 				    "[BTCoex], BT Rssi thresh error!!\n");
92 			BTC_TRACE(trace_buf);
93 			return coex_sta->pre_bt_rssi_state;
94 		}
95 
96 		if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
97 		    (coex_sta->pre_bt_rssi_state ==
98 		     BTC_RSSI_STATE_STAY_LOW)) {
99 			if (bt_rssi >= (rssi_thresh +
100 					BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
101 				bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
102 			else
103 				bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
104 		} else if ((coex_sta->pre_bt_rssi_state ==
105 			    BTC_RSSI_STATE_MEDIUM) ||
106 			   (coex_sta->pre_bt_rssi_state ==
107 			    BTC_RSSI_STATE_STAY_MEDIUM)) {
108 			if (bt_rssi >= (rssi_thresh1 +
109 					BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
110 				bt_rssi_state = BTC_RSSI_STATE_HIGH;
111 			else if (bt_rssi < rssi_thresh)
112 				bt_rssi_state = BTC_RSSI_STATE_LOW;
113 			else
114 				bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
115 		} else {
116 			if (bt_rssi < rssi_thresh1)
117 				bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
118 			else
119 				bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
120 		}
121 	}
122 
123 	coex_sta->pre_bt_rssi_state = bt_rssi_state;
124 
125 	return bt_rssi_state;
126 }
127 
halbtc8821c1ant_wifi_rssi_state(IN struct btc_coexist * btcoexist,IN u8 index,IN u8 level_num,IN u8 rssi_thresh,IN u8 rssi_thresh1)128 u8 halbtc8821c1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
129 	   IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
130 {
131 	s32			wifi_rssi = 0;
132 	u8			wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
133 
134 	btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
135 
136 	if (level_num == 2) {
137 		if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
138 		    ||
139 		    (coex_sta->pre_wifi_rssi_state[index] ==
140 		     BTC_RSSI_STATE_STAY_LOW)) {
141 			if (wifi_rssi >= (rssi_thresh +
142 					  BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
143 				wifi_rssi_state = BTC_RSSI_STATE_HIGH;
144 			else
145 				wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
146 		} else {
147 			if (wifi_rssi < rssi_thresh)
148 				wifi_rssi_state = BTC_RSSI_STATE_LOW;
149 			else
150 				wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
151 		}
152 	} else if (level_num == 3) {
153 		if (rssi_thresh > rssi_thresh1) {
154 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
155 				    "[BTCoex], wifi RSSI thresh error!!\n");
156 			BTC_TRACE(trace_buf);
157 			return coex_sta->pre_wifi_rssi_state[index];
158 		}
159 
160 		if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
161 		    ||
162 		    (coex_sta->pre_wifi_rssi_state[index] ==
163 		     BTC_RSSI_STATE_STAY_LOW)) {
164 			if (wifi_rssi >= (rssi_thresh +
165 					  BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
166 				wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
167 			else
168 				wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
169 		} else if ((coex_sta->pre_wifi_rssi_state[index] ==
170 			    BTC_RSSI_STATE_MEDIUM) ||
171 			   (coex_sta->pre_wifi_rssi_state[index] ==
172 			    BTC_RSSI_STATE_STAY_MEDIUM)) {
173 			if (wifi_rssi >= (rssi_thresh1 +
174 					  BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
175 				wifi_rssi_state = BTC_RSSI_STATE_HIGH;
176 			else if (wifi_rssi < rssi_thresh)
177 				wifi_rssi_state = BTC_RSSI_STATE_LOW;
178 			else
179 				wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
180 		} else {
181 			if (wifi_rssi < rssi_thresh1)
182 				wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
183 			else
184 				wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
185 		}
186 	}
187 
188 	coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
189 
190 	return wifi_rssi_state;
191 }
192 
halbtc8821c1ant_update_ra_mask(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u32 dis_rate_mask)193 void halbtc8821c1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
194 				    IN boolean force_exec, IN u32 dis_rate_mask)
195 {
196 	coex_dm->cur_ra_mask = dis_rate_mask;
197 
198 	if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
199 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
200 				   &coex_dm->cur_ra_mask);
201 	coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
202 }
203 
halbtc8821c1ant_auto_rate_fallback_retry(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)204 void halbtc8821c1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
205 		IN boolean force_exec, IN u8 type)
206 {
207 	boolean	wifi_under_b_mode = FALSE;
208 
209 	coex_dm->cur_arfr_type = type;
210 
211 	if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
212 		switch (coex_dm->cur_arfr_type) {
213 		case 0:	/* normal mode */
214 			btcoexist->btc_write_4byte(btcoexist, 0x430,
215 						   coex_dm->backup_arfr_cnt1);
216 			btcoexist->btc_write_4byte(btcoexist, 0x434,
217 						   coex_dm->backup_arfr_cnt2);
218 			break;
219 		case 1:
220 			btcoexist->btc_get(btcoexist,
221 					   BTC_GET_BL_WIFI_UNDER_B_MODE,
222 					   &wifi_under_b_mode);
223 			if (wifi_under_b_mode) {
224 				btcoexist->btc_write_4byte(btcoexist,
225 							   0x430, 0x0);
226 				btcoexist->btc_write_4byte(btcoexist,
227 							   0x434, 0x01010101);
228 			} else {
229 				btcoexist->btc_write_4byte(btcoexist,
230 							   0x430, 0x0);
231 				btcoexist->btc_write_4byte(btcoexist,
232 							   0x434, 0x04030201);
233 			}
234 			break;
235 		default:
236 			break;
237 		}
238 	}
239 
240 	coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
241 }
242 
halbtc8821c1ant_retry_limit(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)243 void halbtc8821c1ant_retry_limit(IN struct btc_coexist *btcoexist,
244 				 IN boolean force_exec, IN u8 type)
245 {
246 	coex_dm->cur_retry_limit_type = type;
247 
248 	if (force_exec ||
249 	    (coex_dm->pre_retry_limit_type !=
250 	     coex_dm->cur_retry_limit_type)) {
251 		switch (coex_dm->cur_retry_limit_type) {
252 		case 0:	/* normal mode */
253 			btcoexist->btc_write_2byte(btcoexist, 0x42a,
254 						   coex_dm->backup_retry_limit);
255 			break;
256 		case 1:	/* retry limit=8 */
257 			btcoexist->btc_write_2byte(btcoexist, 0x42a,
258 						   0x0808);
259 			break;
260 		default:
261 			break;
262 		}
263 	}
264 
265 	coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
266 }
267 
halbtc8821c1ant_ampdu_max_time(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)268 void halbtc8821c1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
269 				    IN boolean force_exec, IN u8 type)
270 {
271 	coex_dm->cur_ampdu_time_type = type;
272 
273 	if (force_exec ||
274 	    (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
275 		switch (coex_dm->cur_ampdu_time_type) {
276 		case 0:	/* normal mode */
277 			btcoexist->btc_write_1byte(btcoexist, 0x456,
278 					   coex_dm->backup_ampdu_max_time);
279 			break;
280 		case 1:	/* AMPDU timw = 0x38 * 32us */
281 			btcoexist->btc_write_1byte(btcoexist, 0x456,
282 						   0x38);
283 			break;
284 		default:
285 			break;
286 		}
287 	}
288 
289 	coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
290 }
291 
halbtc8821c1ant_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)292 void halbtc8821c1ant_limited_tx(IN struct btc_coexist *btcoexist,
293 		IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
294 				IN u8 retry_limit_type, IN u8 ampdu_time_type)
295 {
296 	switch (ra_mask_type) {
297 	case 0:	/* normal mode */
298 		halbtc8821c1ant_update_ra_mask(btcoexist, force_exec,
299 					       0x0);
300 		break;
301 	case 1:	/* disable cck 1/2 */
302 		halbtc8821c1ant_update_ra_mask(btcoexist, force_exec,
303 					       0x00000003);
304 		break;
305 	case 2:	/* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
306 		halbtc8821c1ant_update_ra_mask(btcoexist, force_exec,
307 					       0x0001f1f7);
308 		break;
309 	default:
310 		break;
311 	}
312 
313 	halbtc8821c1ant_auto_rate_fallback_retry(btcoexist, force_exec, arfr_type);
314 	halbtc8821c1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
315 	halbtc8821c1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
316 }
317 
halbtc8821c1ant_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)318 void halbtc8821c1ant_limited_rx(IN struct btc_coexist *btcoexist,
319 			IN boolean force_exec, IN boolean rej_ap_agg_pkt,
320 			IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
321 {
322 	boolean	reject_rx_agg = rej_ap_agg_pkt;
323 	boolean	bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
324 	u8	rx_agg_size = agg_buf_size;
325 
326 	/* ============================================ */
327 	/*	Rx Aggregation related setting */
328 	/* ============================================ */
329 	btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
330 			   &reject_rx_agg);
331 	/* decide BT control aggregation buf size or not */
332 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
333 			   &bt_ctrl_rx_agg_size);
334 	/* aggregation buf size, only work when BT control Rx aggregation size. */
335 	btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
336 	/* real update aggregation setting */
337 	btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
338 
339 
340 }
341 
halbtc8821c1ant_query_bt_info(IN struct btc_coexist * btcoexist)342 void halbtc8821c1ant_query_bt_info(IN struct btc_coexist *btcoexist)
343 {
344 	u8			h2c_parameter[1] = {0};
345 
346 	if (coex_sta->bt_disabled) {
347 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
348 			"[BTCoex], No query BT info because BT is disabled!\n");
349 		BTC_TRACE(trace_buf);
350 		return;
351 	}
352 
353 
354 	h2c_parameter[0] |= BIT(0);	/* trigger */
355 
356 	btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
357 
358 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
359 		    "[BTCoex], WL query BT info!!\n");
360 	BTC_TRACE(trace_buf);
361 }
362 
halbtc8821c1ant_monitor_bt_ctr(IN struct btc_coexist * btcoexist)363 void halbtc8821c1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
364 {
365 	u32			reg_hp_txrx, reg_lp_txrx, u32tmp;
366 	u32			reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
367 	static u8		num_of_bt_counter_chk = 0, cnt_slave = 0, cnt_overhead = 0,
368 				cnt_autoslot_hang = 0;
369 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
370 
371 	/* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
372 	/* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */
373 
374 	reg_hp_txrx = 0x770;
375 	reg_lp_txrx = 0x774;
376 
377 	u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
378 	reg_hp_tx = u32tmp & MASKLWORD;
379 	reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
380 
381 	u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
382 	reg_lp_tx = u32tmp & MASKLWORD;
383 	reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
384 
385 	coex_sta->high_priority_tx = reg_hp_tx;
386 	coex_sta->high_priority_rx = reg_hp_rx;
387 	coex_sta->low_priority_tx = reg_lp_tx;
388 	coex_sta->low_priority_rx = reg_lp_rx;
389 
390 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
391 		    "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
392 		    reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
393 
394 	BTC_TRACE(trace_buf);
395 
396 	if (BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
397 	    coex_dm->bt_status) {
398 
399 		if (coex_sta->high_priority_rx >= 15) {
400 			if (cnt_overhead < 3)
401 				cnt_overhead++;
402 
403 			if (cnt_overhead == 3)
404 				coex_sta->is_hiPri_rx_overhead = TRUE;
405 
406 		} else {
407 			if (cnt_overhead > 0)
408 				cnt_overhead--;
409 
410 			if (cnt_overhead == 0)
411 				coex_sta->is_hiPri_rx_overhead = FALSE;
412 		}
413 	} else
414 		coex_sta->is_hiPri_rx_overhead = FALSE;
415 
416 	/* reset counter */
417 	btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
418 
419 	if ((coex_sta->low_priority_tx > 1150)  &&
420 	    (!coex_sta->c2h_bt_inquiry_page))
421 		coex_sta->pop_event_cnt++;
422 
423 	if ((coex_sta->low_priority_rx >= 1150) &&
424 	    (coex_sta->low_priority_rx >= coex_sta->low_priority_tx)
425 	    && (!coex_sta->under_ips)
426 	    && (!coex_sta->c2h_bt_inquiry_page)
427 	    && ((bt_link_info->a2dp_exist) || (bt_link_info->pan_exist))) {
428 		if (cnt_slave >= 2) {
429 			bt_link_info->slave_role = TRUE;
430 			cnt_slave = 2;
431 		} else
432 			cnt_slave++;
433 	} else {
434 		if (cnt_slave == 0)	{
435 			bt_link_info->slave_role = FALSE;
436 			cnt_slave = 0;
437 		} else
438 			cnt_slave--;
439 	}
440 
441 	if (coex_sta->is_tdma_btautoslot) {
442 		if ((coex_sta->low_priority_tx >= 1300) &&
443 		(coex_sta->low_priority_rx <= 150)) {
444 			if (cnt_autoslot_hang >= 2) {
445 				coex_sta->is_tdma_btautoslot_hang = TRUE;
446 				cnt_autoslot_hang = 2;
447 			} else
448 				cnt_autoslot_hang++;
449 		} else {
450 			if (cnt_autoslot_hang == 0)	{
451 				coex_sta->is_tdma_btautoslot_hang = FALSE;
452 				cnt_autoslot_hang = 0;
453 			} else
454 				cnt_autoslot_hang--;
455 		}
456 	}
457 
458 	if (bt_link_info->hid_only) {
459 		if (coex_sta->low_priority_rx > 50)
460 			coex_sta->is_hid_low_pri_tx_overhead = true;
461 		else
462 			coex_sta->is_hid_low_pri_tx_overhead = false;
463 	}
464 
465 	if (!coex_sta->bt_disabled) {
466 
467 		if ((coex_sta->high_priority_tx == 0) &&
468 		    (coex_sta->high_priority_rx == 0) &&
469 		    (coex_sta->low_priority_tx == 0) &&
470 		    (coex_sta->low_priority_rx == 0)) {
471 			num_of_bt_counter_chk++;
472 			if (num_of_bt_counter_chk >= 3) {
473 				halbtc8821c1ant_query_bt_info(btcoexist);
474 				num_of_bt_counter_chk = 0;
475 			}
476 		}
477 	}
478 
479 }
480 
481 
482 
halbtc8821c1ant_monitor_wifi_ctr(IN struct btc_coexist * btcoexist)483 void halbtc8821c1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
484 {
485 	s32	wifi_rssi = 0;
486 	boolean wifi_busy = FALSE, wifi_under_b_mode = FALSE,
487 			wifi_scan = FALSE, wifi_connected = FALSE;
488 	boolean bt_idle = FALSE, wl_idle = FALSE, is_cck_deadlock = FALSE;
489 	static u8 cck_lock_counter = 0, wl_noisy_count0 = 0,
490 		  wl_noisy_count1 = 3, wl_noisy_count2 = 0;
491 	u32	total_cnt, reg_val1, reg_val2, cnt_cck;
492 	u32 cnt_crcok = 0, cnt_crcerr = 0;
493 	static u8 cnt = 0, cnt_ccklocking = 0;
494 	u8	h2c_parameter[1] = {0};
495 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
496 
497 	/* Only enable for windows becaus 8821cu H2C 0x69 unknown fail @ linux */
498 	if (btcoexist->chip_interface != BTC_INTF_USB) {
499 		/*send h2c to query WL FW dbg info  */
500 		if (((coex_dm->cur_ps_tdma_on) && (coex_sta->force_lps_ctrl)) ||
501 			 ((coex_sta->acl_busy) && (bt_link_info->a2dp_exist))) {
502 			h2c_parameter[0] = 0x8;
503 			btcoexist->btc_fill_h2c(btcoexist, 0x69, 1, h2c_parameter);
504 		}
505 	}
506 
507 
508 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
509 	btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
510 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
511 			   &wifi_under_b_mode);
512 
513 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
514 
515 	coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter(
516 						btcoexist,
517 						PHYDM_INFO_CRC32_OK_CCK);
518 	coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter(
519 						btcoexist,
520 						PHYDM_INFO_CRC32_OK_LEGACY);
521 	coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter(
522 						btcoexist,
523 						PHYDM_INFO_CRC32_OK_HT);
524 	coex_sta->crc_ok_11n_vht = btcoexist->btc_phydm_query_PHY_counter(
525 						btcoexist,
526 						PHYDM_INFO_CRC32_OK_VHT);
527 
528 	coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter(
529 						btcoexist, PHYDM_INFO_CRC32_ERROR_CCK);
530 	coex_sta->crc_err_11g =  btcoexist->btc_phydm_query_PHY_counter(
531 						btcoexist, PHYDM_INFO_CRC32_ERROR_LEGACY);
532 	coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter(
533 						btcoexist, PHYDM_INFO_CRC32_ERROR_HT);
534 	coex_sta->crc_err_11n_vht = btcoexist->btc_phydm_query_PHY_counter(
535 						btcoexist,
536 						PHYDM_INFO_CRC32_ERROR_VHT);
537 
538 	cnt_crcok =  coex_sta->crc_ok_cck + coex_sta->crc_ok_11g
539 				+ coex_sta->crc_ok_11n
540 				+ coex_sta->crc_ok_11n_vht;
541 
542 	cnt_crcerr =  coex_sta->crc_err_cck + coex_sta->crc_err_11g
543 				+ coex_sta->crc_err_11n
544 				+ coex_sta->crc_err_11n_vht;
545 
546 	/* CCK lock identification */
547 	if (coex_sta->cck_lock)
548 		cnt_ccklocking++;
549 	else if	(cnt_ccklocking != 0)
550 		cnt_ccklocking--;
551 
552 	if (cnt_ccklocking >= 3) {
553 		cnt_ccklocking = 3;
554 		coex_sta->cck_lock_ever = TRUE;
555 	}
556 
557 	/* WiFi environment noisy identification */
558 	cnt_cck = coex_sta->crc_ok_cck + coex_sta->crc_err_cck;
559 
560 	if ((!wifi_busy) && (!coex_sta->cck_lock)) {
561 		if (cnt_cck > 250) {
562 			if (wl_noisy_count2 < 3)
563 				wl_noisy_count2++;
564 
565 			if (wl_noisy_count2 == 3) {
566 				wl_noisy_count0 = 0;
567 				wl_noisy_count1 = 0;
568 			}
569 
570 		} else if (cnt_cck < 50) {
571 			if (wl_noisy_count0 < 3)
572 				wl_noisy_count0++;
573 
574 			if (wl_noisy_count0 == 3) {
575 				wl_noisy_count1 = 0;
576 				wl_noisy_count2 = 0;
577 			}
578 
579 		} else {
580 			if (wl_noisy_count1 < 3)
581 				wl_noisy_count1++;
582 
583 			if (wl_noisy_count1 == 3) {
584 				wl_noisy_count0 = 0;
585 				wl_noisy_count2 = 0;
586 			}
587 	}
588 
589 		if (wl_noisy_count2 == 3)
590 			coex_sta->wl_noisy_level = 2;
591 		else if (wl_noisy_count1 == 3)
592 			coex_sta->wl_noisy_level = 1;
593 		else
594 			coex_sta->wl_noisy_level = 0;
595 	}
596 
597 }
598 
599 
halbtc8821c1ant_update_bt_link_info(IN struct btc_coexist * btcoexist)600 void halbtc8821c1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
601 {
602 	struct  btc_bt_link_info	*bt_link_info = &btcoexist->bt_link_info;
603 	boolean				bt_hs_on = FALSE;
604 	boolean		bt_busy = FALSE;
605 
606 
607 	coex_sta->num_of_profile = 0;
608 
609 	/* set link exist status */
610 	if (!(coex_sta->bt_info & BT_INFO_8821C_1ANT_B_CONNECTION)) {
611 		coex_sta->bt_link_exist = FALSE;
612 		coex_sta->pan_exist = FALSE;
613 		coex_sta->a2dp_exist = FALSE;
614 		coex_sta->hid_exist = FALSE;
615 		coex_sta->sco_exist = FALSE;
616 	} else {	/* connection exists */
617 		coex_sta->bt_link_exist = TRUE;
618 		if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_FTP) {
619 			coex_sta->pan_exist = TRUE;
620 			coex_sta->num_of_profile++;
621 		} else
622 			coex_sta->pan_exist = FALSE;
623 
624 		if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_A2DP) {
625 			coex_sta->a2dp_exist = TRUE;
626 			coex_sta->num_of_profile++;
627 		} else
628 			coex_sta->a2dp_exist = FALSE;
629 
630 		if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_HID) {
631 			coex_sta->hid_exist = TRUE;
632 			coex_sta->num_of_profile++;
633 		} else
634 			coex_sta->hid_exist = FALSE;
635 
636 		if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) {
637 			coex_sta->sco_exist = TRUE;
638 			coex_sta->num_of_profile++;
639 		} else
640 			coex_sta->sco_exist = FALSE;
641 
642 	}
643 
644 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
645 
646 	bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
647 	bt_link_info->sco_exist = coex_sta->sco_exist;
648 	bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
649 	bt_link_info->pan_exist = coex_sta->pan_exist;
650 	bt_link_info->hid_exist = coex_sta->hid_exist;
651 	bt_link_info->acl_busy = coex_sta->acl_busy;
652 
653 	/* work around for HS mode. */
654 	if (bt_hs_on) {
655 		bt_link_info->pan_exist = TRUE;
656 		bt_link_info->bt_link_exist = TRUE;
657 	}
658 
659 	/* check if Sco only */
660 	if (bt_link_info->sco_exist &&
661 	    !bt_link_info->a2dp_exist &&
662 	    !bt_link_info->pan_exist &&
663 	    !bt_link_info->hid_exist)
664 		bt_link_info->sco_only = TRUE;
665 	else
666 		bt_link_info->sco_only = FALSE;
667 
668 	/* check if A2dp only */
669 	if (!bt_link_info->sco_exist &&
670 	    bt_link_info->a2dp_exist &&
671 	    !bt_link_info->pan_exist &&
672 	    !bt_link_info->hid_exist)
673 		bt_link_info->a2dp_only = TRUE;
674 	else
675 		bt_link_info->a2dp_only = FALSE;
676 
677 	/* check if Pan only */
678 	if (!bt_link_info->sco_exist &&
679 	    !bt_link_info->a2dp_exist &&
680 	    bt_link_info->pan_exist &&
681 	    !bt_link_info->hid_exist)
682 		bt_link_info->pan_only = TRUE;
683 	else
684 		bt_link_info->pan_only = FALSE;
685 
686 	/* check if Hid only */
687 	if (!bt_link_info->sco_exist &&
688 	    !bt_link_info->a2dp_exist &&
689 	    !bt_link_info->pan_exist &&
690 	    bt_link_info->hid_exist)
691 		bt_link_info->hid_only = TRUE;
692 	else
693 		bt_link_info->hid_only = FALSE;
694 
695 	if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_INQ_PAGE) {
696 		coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_INQ_PAGE;
697 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
698 			    "[BTCoex], BtInfoNotify(), BT Inq/page!!!\n");
699 	} else if (!(coex_sta->bt_info & BT_INFO_8821C_1ANT_B_CONNECTION)) {
700 		coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
701 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
702 			"[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
703 	} else if (coex_sta->bt_info == BT_INFO_8821C_1ANT_B_CONNECTION) {
704 		/* connection exists but no busy */
705 		coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE;
706 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
707 			    "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
708 	} else if (((coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) ||
709 		    (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_BUSY)) &&
710 		   (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_ACL_BUSY)) {
711 		coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY;
712 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
713 			    "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n");
714 	} else if ((coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) ||
715 		   (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_BUSY)) {
716 		coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_SCO_BUSY;
717 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
718 			    "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
719 	} else if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_ACL_BUSY) {
720 		coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_ACL_BUSY;
721 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
722 			    "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
723 	} else {
724 		coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_MAX;
725 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
726 			"[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
727 	}
728 
729 	BTC_TRACE(trace_buf);
730 
731 	if ((BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
732 	    (BT_8821C_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
733 	    (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
734 		bt_busy = TRUE;
735 	else
736 		bt_busy = FALSE;
737 
738 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
739 }
740 
halbtc8821c1ant_update_wifi_channel_info(IN struct btc_coexist * btcoexist,IN u8 type)741 void halbtc8821c1ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist,
742 		IN u8 type)
743 {
744 	u8			h2c_parameter[3] = {0}, i;
745 	u32			wifi_bw;
746 	u8			wifi_central_chnl = 0;
747 	u8			wifi_5g_chnl[19] = {120, 124, 128, 132, 136, 140, 144, 149,
748 									153, 157, 118, 126, 134, 142, 151, 159,
749 									122, 138, 155};
750 	u8			bt_skip_cneter_chanl[19] = {2, 8, 17, 26, 34, 42, 51, 62,
751 											71, 77, 2, 12, 29, 46, 66, 76,
752 											10, 37, 68};
753 	u8			bt_skip_span[19] = {4, 8, 8, 10, 8, 10, 8, 8, 10, 4, 4, 16,
754 									16, 16, 16, 4, 20, 34, 20};
755 	boolean		wifi_under_5g = FALSE;
756 
757 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
758 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
759 
760 	if (type == BTC_MEDIA_CONNECT) {
761 
762 		if (!wifi_under_5g) {
763 
764 			btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
765 				&wifi_central_chnl);
766 
767 			h2c_parameter[0] = 0x1;
768 			h2c_parameter[1] = wifi_central_chnl;
769 
770 			if (wifi_bw == BTC_WIFI_BW_HT40)
771 				h2c_parameter[2] = 0x30;
772 			else
773 				h2c_parameter[2] = 0x20;
774 		} else {  /* for 5G  */
775 
776 			wifi_central_chnl =
777 				btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x18, 0xfffff) & 0xff;
778 
779 			for (i = 0; i <= 18; i++) {
780 				if (wifi_central_chnl == wifi_5g_chnl[i])
781 					break;
782 			}
783 
784 			if (i <= 18) {
785 				h2c_parameter[0] = 0x3;
786 				h2c_parameter[1] = bt_skip_cneter_chanl[i];
787 				h2c_parameter[2] = bt_skip_span[i];
788 			}
789 
790 		}
791 	}
792 
793 	coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
794 	coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
795 	coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
796 	coex_sta->wl_center_channel = wifi_central_chnl;
797 
798 	btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
799 
800 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
801 				"[BTCoex], para[0:2] = 0x%x 0x%x 0x%x\n",
802 				h2c_parameter[0], h2c_parameter[1], h2c_parameter[2]);
803 	BTC_TRACE(trace_buf);
804 
805 }
806 
halbtc8821c1ant_action_algorithm(IN struct btc_coexist * btcoexist)807 u8 halbtc8821c1ant_action_algorithm(IN struct btc_coexist *btcoexist)
808 {
809 	struct  btc_bt_link_info	*bt_link_info = &btcoexist->bt_link_info;
810 	boolean				bt_hs_on = FALSE;
811 	u8				algorithm = BT_8821C_1ANT_COEX_ALGO_UNDEFINED;
812 	u8				num_of_diff_profile = 0;
813 
814 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
815 
816 	if (!bt_link_info->bt_link_exist) {
817 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
818 			    "[BTCoex], No BT link exists!!!\n");
819 		BTC_TRACE(trace_buf);
820 		return algorithm;
821 	}
822 
823 	if (bt_link_info->sco_exist)
824 		num_of_diff_profile++;
825 	if (bt_link_info->hid_exist)
826 		num_of_diff_profile++;
827 	if (bt_link_info->pan_exist)
828 		num_of_diff_profile++;
829 	if (bt_link_info->a2dp_exist)
830 		num_of_diff_profile++;
831 
832 	if (num_of_diff_profile == 1) {
833 		if (bt_link_info->sco_exist) {
834 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
835 				    "[BTCoex], BT Profile = SCO only\n");
836 			BTC_TRACE(trace_buf);
837 			algorithm = BT_8821C_1ANT_COEX_ALGO_SCO;
838 		} else {
839 			if (bt_link_info->hid_exist) {
840 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
841 					"[BTCoex], BT Profile = HID only\n");
842 				BTC_TRACE(trace_buf);
843 				algorithm = BT_8821C_1ANT_COEX_ALGO_HID;
844 			} else if (bt_link_info->a2dp_exist) {
845 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
846 					"[BTCoex], BT Profile = A2DP only\n");
847 				BTC_TRACE(trace_buf);
848 				algorithm = BT_8821C_1ANT_COEX_ALGO_A2DP;
849 			} else if (bt_link_info->pan_exist) {
850 				if (bt_hs_on) {
851 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
852 						"[BTCoex], BT Profile = PAN(HS) only\n");
853 					BTC_TRACE(trace_buf);
854 					algorithm =
855 						BT_8821C_1ANT_COEX_ALGO_PANHS;
856 				} else {
857 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
858 						"[BTCoex], BT Profile = PAN(EDR) only\n");
859 					BTC_TRACE(trace_buf);
860 					algorithm =
861 						BT_8821C_1ANT_COEX_ALGO_PANEDR;
862 				}
863 			}
864 		}
865 	} else if (num_of_diff_profile == 2) {
866 		if (bt_link_info->sco_exist) {
867 			if (bt_link_info->hid_exist) {
868 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
869 					"[BTCoex], BT Profile = SCO + HID\n");
870 				BTC_TRACE(trace_buf);
871 				algorithm = BT_8821C_1ANT_COEX_ALGO_HID;
872 			} else if (bt_link_info->a2dp_exist) {
873 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
874 					"[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
875 				BTC_TRACE(trace_buf);
876 				algorithm = BT_8821C_1ANT_COEX_ALGO_SCO;
877 			} else if (bt_link_info->pan_exist) {
878 				if (bt_hs_on) {
879 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
880 						"[BTCoex], BT Profile = SCO + PAN(HS)\n");
881 					BTC_TRACE(trace_buf);
882 					algorithm = BT_8821C_1ANT_COEX_ALGO_SCO;
883 				} else {
884 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
885 						"[BTCoex], BT Profile = SCO + PAN(EDR)\n");
886 					BTC_TRACE(trace_buf);
887 					algorithm =
888 						BT_8821C_1ANT_COEX_ALGO_PANEDR_HID;
889 				}
890 			}
891 		} else {
892 			if (bt_link_info->hid_exist &&
893 			    bt_link_info->a2dp_exist) {
894 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
895 					"[BTCoex], BT Profile = HID + A2DP\n");
896 				BTC_TRACE(trace_buf);
897 				algorithm = BT_8821C_1ANT_COEX_ALGO_HID_A2DP;
898 			} else if (bt_link_info->hid_exist &&
899 				   bt_link_info->pan_exist) {
900 				if (bt_hs_on) {
901 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
902 						"[BTCoex], BT Profile = HID + PAN(HS)\n");
903 					BTC_TRACE(trace_buf);
904 					algorithm =
905 						BT_8821C_1ANT_COEX_ALGO_HID_A2DP;
906 				} else {
907 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
908 						"[BTCoex], BT Profile = HID + PAN(EDR)\n");
909 					BTC_TRACE(trace_buf);
910 					algorithm =
911 						BT_8821C_1ANT_COEX_ALGO_PANEDR_HID;
912 				}
913 			} else if (bt_link_info->pan_exist &&
914 				   bt_link_info->a2dp_exist) {
915 				if (bt_hs_on) {
916 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
917 						"[BTCoex], BT Profile = A2DP + PAN(HS)\n");
918 					BTC_TRACE(trace_buf);
919 					algorithm =
920 						BT_8821C_1ANT_COEX_ALGO_A2DP_PANHS;
921 				} else {
922 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
923 						"[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
924 					BTC_TRACE(trace_buf);
925 					algorithm =
926 						BT_8821C_1ANT_COEX_ALGO_PANEDR_A2DP;
927 				}
928 			}
929 		}
930 	} else if (num_of_diff_profile == 3) {
931 		if (bt_link_info->sco_exist) {
932 			if (bt_link_info->hid_exist &&
933 			    bt_link_info->a2dp_exist) {
934 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
935 					"[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
936 				BTC_TRACE(trace_buf);
937 				algorithm = BT_8821C_1ANT_COEX_ALGO_HID;
938 			} else if (bt_link_info->hid_exist &&
939 				   bt_link_info->pan_exist) {
940 				if (bt_hs_on) {
941 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
942 						"[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
943 					BTC_TRACE(trace_buf);
944 					algorithm =
945 						BT_8821C_1ANT_COEX_ALGO_HID_A2DP;
946 				} else {
947 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
948 						"[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
949 					BTC_TRACE(trace_buf);
950 					algorithm =
951 						BT_8821C_1ANT_COEX_ALGO_PANEDR_HID;
952 				}
953 			} else if (bt_link_info->pan_exist &&
954 				   bt_link_info->a2dp_exist) {
955 				if (bt_hs_on) {
956 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
957 						"[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
958 					BTC_TRACE(trace_buf);
959 					algorithm = BT_8821C_1ANT_COEX_ALGO_SCO;
960 				} else {
961 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
962 						"[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
963 					BTC_TRACE(trace_buf);
964 					algorithm =
965 						BT_8821C_1ANT_COEX_ALGO_PANEDR_HID;
966 				}
967 			}
968 		} else {
969 			if (bt_link_info->hid_exist &&
970 			    bt_link_info->pan_exist &&
971 			    bt_link_info->a2dp_exist) {
972 				if (bt_hs_on) {
973 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
974 						"[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
975 					BTC_TRACE(trace_buf);
976 					algorithm =
977 						BT_8821C_1ANT_COEX_ALGO_HID_A2DP;
978 				} else {
979 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
980 						"[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
981 					BTC_TRACE(trace_buf);
982 					algorithm =
983 						BT_8821C_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
984 				}
985 			}
986 		}
987 	} else if (num_of_diff_profile >= 3) {
988 		if (bt_link_info->sco_exist) {
989 			if (bt_link_info->hid_exist &&
990 			    bt_link_info->pan_exist &&
991 			    bt_link_info->a2dp_exist) {
992 				if (bt_hs_on) {
993 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
994 						"[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
995 					BTC_TRACE(trace_buf);
996 
997 				} else {
998 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
999 						"[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
1000 					BTC_TRACE(trace_buf);
1001 					algorithm =
1002 						BT_8821C_1ANT_COEX_ALGO_PANEDR_HID;
1003 				}
1004 			}
1005 		}
1006 	}
1007 
1008 	return algorithm;
1009 }
1010 
halbtc8821c1ant_set_bt_auto_report(IN struct btc_coexist * btcoexist,IN boolean enable_auto_report)1011 void halbtc8821c1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
1012 					IN boolean enable_auto_report)
1013 {
1014 	u8			h2c_parameter[1] = {0};
1015 
1016 	h2c_parameter[0] = 0;
1017 
1018 	if (enable_auto_report)
1019 		h2c_parameter[0] |= BIT(0);
1020 
1021 	btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
1022 }
1023 
halbtc8821c1ant_bt_auto_report(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean enable_auto_report)1024 void halbtc8821c1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
1025 		    IN boolean force_exec, IN boolean enable_auto_report)
1026 {
1027 	coex_dm->cur_bt_auto_report = enable_auto_report;
1028 
1029 	if (!force_exec) {
1030 		if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
1031 			return;
1032 	}
1033 	halbtc8821c1ant_set_bt_auto_report(btcoexist,
1034 					   coex_dm->cur_bt_auto_report);
1035 
1036 	coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
1037 }
1038 
1039 
halbtc8821c1ant_low_penalty_ra(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean low_penalty_ra)1040 void halbtc8821c1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
1041 			    IN boolean force_exec, IN boolean low_penalty_ra)
1042 {
1043 
1044 #if 1
1045 	coex_dm->cur_low_penalty_ra = low_penalty_ra;
1046 
1047 	if (!force_exec) {
1048 		if (coex_dm->pre_low_penalty_ra ==
1049 		    coex_dm->cur_low_penalty_ra)
1050 			return;
1051 	}
1052 
1053 	if (low_penalty_ra)
1054 		btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 15);
1055 	else
1056 		btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 0);
1057 
1058 	coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
1059 
1060 #endif
1061 
1062 }
1063 
halbtc8821c1ant_write_score_board(IN struct btc_coexist * btcoexist,IN u16 bitpos,IN boolean state)1064 void halbtc8821c1ant_write_score_board(
1065 	IN	struct  btc_coexist		*btcoexist,
1066 	IN	u16				bitpos,
1067 	IN	boolean		state
1068 )
1069 {
1070 
1071 	static u16 originalval = 0x8002, preval = 0x0;
1072 
1073 	if (state)
1074 		originalval = originalval | bitpos;
1075 	else
1076 		originalval = originalval & (~bitpos);
1077 
1078 	coex_sta->score_board_WB = originalval;
1079 
1080 	if (originalval != preval) {
1081 
1082 		preval = originalval;
1083 		btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval);
1084 	} else {
1085 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1086 		"[BTCoex], halbtc8821c1ant_write_score_board: return for nochange\n");
1087 		BTC_TRACE(trace_buf);
1088 	}
1089 }
1090 
halbtc8821c1ant_read_score_board(IN struct btc_coexist * btcoexist,IN u16 * score_board_val)1091 void halbtc8821c1ant_read_score_board(
1092 	IN	struct  btc_coexist		*btcoexist,
1093 	IN   u16				*score_board_val
1094 )
1095 {
1096 
1097 	*score_board_val = (btcoexist->btc_read_2byte(btcoexist,
1098 			    0xaa)) & 0x7fff;
1099 }
1100 
halbtc8821c1ant_post_state_to_bt(IN struct btc_coexist * btcoexist,IN u16 type,IN boolean state)1101 void halbtc8821c1ant_post_state_to_bt(
1102 	IN	struct  btc_coexist		*btcoexist,
1103 	IN	u16						type,
1104 	IN  boolean                 state
1105 )
1106 {
1107 
1108 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1109 		"[BTCoex], halbtc8821c1ant_post_state_to_bt: type = %d, state =%d\n",
1110 		type, state);
1111 	BTC_TRACE(trace_buf);
1112 
1113 	halbtc8821c1ant_write_score_board(btcoexist, (u16) type, state);
1114 }
1115 
halbtc8821c1ant_is_wifibt_status_changed(IN struct btc_coexist * btcoexist)1116 boolean halbtc8821c1ant_is_wifibt_status_changed(IN struct btc_coexist
1117 		*btcoexist)
1118 {
1119 	static boolean	pre_wifi_busy = FALSE, pre_under_4way = FALSE,
1120 			pre_bt_hs_on = FALSE, pre_bt_off = FALSE,
1121 			pre_bt_slave = FALSE, pre_hid_low_pri_tx_overhead = FALSE,
1122 			pre_wifi_under_lps = FALSE, pre_bt_setup_link = FALSE,
1123 			pre_cck_lock = FALSE, pre_cck_lock_warn = FALSE;
1124 	static u8 pre_hid_busy_num = 0, pre_wl_noisy_level = 0;
1125 	boolean wifi_busy = FALSE, under_4way = FALSE, bt_hs_on = FALSE;
1126 	boolean wifi_connected = FALSE;
1127 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1128 
1129 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1130 			   &wifi_connected);
1131 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1132 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
1133 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
1134 			   &under_4way);
1135 
1136 	if (coex_sta->bt_disabled != pre_bt_off) {
1137 		pre_bt_off = coex_sta->bt_disabled;
1138 
1139 		if (coex_sta->bt_disabled)
1140 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1141 				    "[BTCoex], BT is disabled !!\n");
1142 		else
1143 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1144 				    "[BTCoex], BT is enabled !!\n");
1145 
1146 		BTC_TRACE(trace_buf);
1147 
1148 		coex_sta->bt_coex_supported_feature = 0;
1149 		coex_sta->bt_coex_supported_version = 0;
1150 		coex_sta->bt_ble_scan_type = 0;
1151 		coex_sta->bt_ble_scan_para[0] = 0;
1152 		coex_sta->bt_ble_scan_para[1] = 0;
1153 		coex_sta->bt_ble_scan_para[2] = 0;
1154 		coex_sta->bt_reg_vendor_ac = 0xffff;
1155 		coex_sta->bt_reg_vendor_ae = 0xffff;
1156 		return TRUE;
1157 	}
1158 
1159 
1160 	if (wifi_connected) {
1161 #if 0
1162 		if ((wifi_busy) &&
1163 			(coex_dm->bt_status ==  BT_8821C_1ANT_BT_STATUS_ACL_BUSY))
1164 			halbtc8821c1ant_post_state_to_bt(btcoexist,
1165 						BT_8821C_1ANT_SCOREBOARD_UNDERTEST, TRUE);
1166 		else
1167 			halbtc8821c1ant_post_state_to_bt(btcoexist,
1168 						BT_8821C_1ANT_SCOREBOARD_UNDERTEST, FALSE);
1169 #endif
1170 		if (wifi_busy != pre_wifi_busy) {
1171 			pre_wifi_busy = wifi_busy;
1172 			return TRUE;
1173 		}
1174 		if (under_4way != pre_under_4way) {
1175 			pre_under_4way = under_4way;
1176 			return TRUE;
1177 		}
1178 		if (bt_hs_on != pre_bt_hs_on) {
1179 			pre_bt_hs_on = bt_hs_on;
1180 			return TRUE;
1181 		}
1182 		if (coex_sta->wl_noisy_level != pre_wl_noisy_level) {
1183 			pre_wl_noisy_level = coex_sta->wl_noisy_level;
1184 			return TRUE;
1185 		}
1186 		if (coex_sta->under_lps != pre_wifi_under_lps) {
1187 			pre_wifi_under_lps = coex_sta->under_lps;
1188 			if (coex_sta->under_lps == TRUE)
1189 				return TRUE;
1190 		}
1191 		if (coex_sta->cck_lock != pre_cck_lock) {
1192 			pre_cck_lock = coex_sta->cck_lock;
1193 			return TRUE;
1194 		}
1195 		if (coex_sta->cck_lock_warn != pre_cck_lock_warn) {
1196 			pre_cck_lock_warn = coex_sta->cck_lock_warn;
1197 			return TRUE;
1198 		}
1199 	}
1200 
1201 	if (!coex_sta->bt_disabled) {
1202 		if (coex_sta->hid_busy_num != pre_hid_busy_num) {
1203 			pre_hid_busy_num = coex_sta->hid_busy_num;
1204 			return TRUE;
1205 		}
1206 
1207 		if (bt_link_info->slave_role != pre_bt_slave) {
1208 			pre_bt_slave = bt_link_info->slave_role;
1209 			return TRUE;
1210 		}
1211 
1212 		if (pre_hid_low_pri_tx_overhead != coex_sta->is_hid_low_pri_tx_overhead) {
1213 			pre_hid_low_pri_tx_overhead = coex_sta->is_hid_low_pri_tx_overhead;
1214 			return TRUE;
1215 		}
1216 
1217 		if (pre_bt_setup_link != coex_sta->is_setupLink) {
1218 			pre_bt_setup_link = coex_sta->is_setupLink;
1219 			return TRUE;
1220 		}
1221 	}
1222 
1223 	return FALSE;
1224 }
1225 
1226 
halbtc8821c1ant_monitor_bt_enable_disable(IN struct btc_coexist * btcoexist)1227 void halbtc8821c1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
1228 {
1229 	static u32		bt_disable_cnt = 0;
1230 	boolean		bt_active = TRUE, bt_disabled = FALSE, wifi_under_5g = FALSE;
1231 	u16			u16tmp;
1232 
1233 	/* This function check if bt is disabled */
1234 #if 0
1235 	if (coex_sta->high_priority_tx == 0 &&
1236 	    coex_sta->high_priority_rx == 0 &&
1237 	    coex_sta->low_priority_tx == 0 &&
1238 	    coex_sta->low_priority_rx == 0)
1239 		bt_active = FALSE;
1240 	if (coex_sta->high_priority_tx == 0xffff &&
1241 	    coex_sta->high_priority_rx == 0xffff &&
1242 	    coex_sta->low_priority_tx == 0xffff &&
1243 	    coex_sta->low_priority_rx == 0xffff)
1244 		bt_active = FALSE;
1245 
1246 
1247 #else
1248 
1249 	/* Read BT on/off status from scoreboard[1], enable this only if BT patch support this feature */
1250 	halbtc8821c1ant_read_score_board(btcoexist,	&u16tmp);
1251 
1252 	bt_active = u16tmp & BIT(1);
1253 
1254 
1255 #endif
1256 
1257 	if (bt_active) {
1258 		bt_disable_cnt = 0;
1259 		bt_disabled = FALSE;
1260 		btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1261 				   &bt_disabled);
1262 	} else {
1263 
1264 		bt_disable_cnt++;
1265 		if (bt_disable_cnt >= 2) {
1266 			bt_disabled = TRUE;
1267 			bt_disable_cnt = 2;
1268 		}
1269 
1270 		btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1271 				   &bt_disabled);
1272 	}
1273 
1274 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
1275 
1276 	if ((wifi_under_5g) || (bt_disabled))
1277 		halbtc8821c1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, FALSE);
1278 	else
1279 		halbtc8821c1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, TRUE);
1280 
1281 
1282 	if (coex_sta->bt_disabled != bt_disabled) {
1283 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1284 			    "[BTCoex], BT is from %s to %s!!\n",
1285 			    (coex_sta->bt_disabled ? "disabled" : "enabled"),
1286 			    (bt_disabled ? "disabled" : "enabled"));
1287 		BTC_TRACE(trace_buf);
1288 		coex_sta->bt_disabled = bt_disabled;
1289 	}
1290 
1291 }
1292 
halbtc8821c1ant_enable_gnt_to_gpio(IN struct btc_coexist * btcoexist,boolean isenable)1293 void halbtc8821c1ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist,
1294 					boolean isenable)
1295 {
1296 #if BT_8821C_1ANT_COEX_DBG
1297 	static u8			bitVal[5] = {0, 0, 0, 0, 0};
1298 	static boolean		state = FALSE;
1299 	/*
1300 		if (state ==isenable)
1301 			return;
1302 		else
1303 			state = isenable;
1304 	*/
1305 	if (isenable) {
1306 
1307 		/* enable GNT_WL, GNT_BT to GPIO for debug */
1308 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1);
1309 
1310 		/* store original value */
1311 		bitVal[0] = (btcoexist->btc_read_1byte(btcoexist,
1312 				       0x66) & BIT(4)) >> 4;	/*0x66[4] */
1313 		bitVal[1] = (btcoexist->btc_read_1byte(btcoexist,
1314 					       0x67) & BIT(0));		/*0x66[8] */
1315 		bitVal[2] = (btcoexist->btc_read_1byte(btcoexist,
1316 				       0x42) & BIT(3)) >> 3;  /*0x40[19] */
1317 		bitVal[3] = (btcoexist->btc_read_1byte(btcoexist,
1318 				       0x65) & BIT(7)) >> 7;  /*0x64[15] */
1319 		bitVal[4] = (btcoexist->btc_read_1byte(btcoexist,
1320 				       0x72) & BIT(2)) >> 2;  /*0x70[18] */
1321 
1322 		/*  switch GPIO Mux */
1323 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
1324 						   0x0);  /*0x66[4] = 0 */
1325 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
1326 						   0x0);  /*0x66[8] = 0 */
1327 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
1328 						   0x0);  /*0x40[19] = 0 */
1329 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
1330 						   0x0);  /*0x64[15] = 0 */
1331 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
1332 						   0x0);  /*0x70[18] = 0 */
1333 
1334 
1335 	} else {
1336 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0);
1337 
1338 		/*  Restore original value */
1339 		/*  switch GPIO Mux */
1340 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
1341 						   bitVal[0]);  /*0x66[4] = 0 */
1342 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
1343 						   bitVal[1]);  /*0x66[8] = 0 */
1344 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
1345 					   bitVal[2]);  /*0x40[19] = 0 */
1346 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
1347 					   bitVal[3]);  /*0x64[15] = 0 */
1348 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
1349 					   bitVal[4]);  /*0x70[18] = 0 */
1350 	}
1351 
1352 #endif
1353 }
1354 
halbtc8821c1ant_ltecoex_indirect_read_reg(IN struct btc_coexist * btcoexist,IN u16 reg_addr)1355 u32 halbtc8821c1ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist,
1356 		IN u16 reg_addr)
1357 {
1358 	u32 j = 0, delay_count = 0;
1359 
1360 	/* wait for ready bit before access 0x1700 */
1361 	while (1) {
1362 		if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
1363 			delay_ms(50);
1364 			delay_count++;
1365 			if (delay_count >= 10) {
1366 				delay_count = 0;
1367 				break;
1368 			}
1369 		} else
1370 			break;
1371 	}
1372 
1373 	btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr);
1374 
1375 	return btcoexist->btc_read_4byte(btcoexist,
1376 					 0x1708);  /* get read data */
1377 }
1378 
halbtc8821c1ant_ltecoex_indirect_write_reg(IN struct btc_coexist * btcoexist,IN u16 reg_addr,IN u32 bit_mask,IN u32 reg_value)1379 void halbtc8821c1ant_ltecoex_indirect_write_reg(IN struct btc_coexist
1380 		*btcoexist,
1381 		IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value)
1382 {
1383 	u32 val, i = 0, j = 0, bitpos = 0, delay_count = 0;
1384 
1385 	if (bit_mask == 0x0)
1386 		return;
1387 
1388 	if (bit_mask == 0xffffffff) {
1389 		/* wait for ready bit before access 0x1700/0x1704 */
1390 		while (1) {
1391 			if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
1392 				delay_ms(50);
1393 				delay_count++;
1394 				if (delay_count >= 10) {
1395 					delay_count = 0;
1396 					break;
1397 				}
1398 			} else
1399 				break;
1400 		}
1401 
1402 		btcoexist->btc_write_4byte(btcoexist, 0x1704,
1403 					   reg_value); /* put write data */
1404 
1405 		btcoexist->btc_write_4byte(btcoexist, 0x1700,
1406 					   0xc00F0000 | reg_addr);
1407 	} else {
1408 		for (i = 0; i <= 31; i++) {
1409 			if (((bit_mask >> i) & 0x1) == 0x1) {
1410 				bitpos = i;
1411 				break;
1412 			}
1413 		}
1414 
1415 		/* read back register value before write */
1416 		val = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
1417 				reg_addr);
1418 		val = (val & (~bit_mask)) | (reg_value << bitpos);
1419 
1420 		/* wait for ready bit before access 0x1700/0x1704 */
1421 		while (1) {
1422 			if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
1423 				delay_ms(50);
1424 				delay_count++;
1425 				if (delay_count >= 10) {
1426 					delay_count = 0;
1427 					break;
1428 				}
1429 			} else
1430 				break;
1431 		}
1432 
1433 		btcoexist->btc_write_4byte(btcoexist, 0x1704,
1434 					   val); /* put write data */
1435 
1436 		btcoexist->btc_write_4byte(btcoexist, 0x1700,
1437 					   0xc00F0000 | reg_addr);
1438 
1439 	}
1440 
1441 }
1442 
halbtc8821c1ant_ltecoex_enable(IN struct btc_coexist * btcoexist,IN boolean enable)1443 void halbtc8821c1ant_ltecoex_enable(IN struct btc_coexist *btcoexist,
1444 				    IN boolean enable)
1445 {
1446 	u8 val;
1447 
1448 	val = (enable) ? 1 : 0;
1449 	halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80,
1450 			val);  /* 0x38[7] */
1451 
1452 }
1453 
halbtc8821c1ant_ltecoex_pathcontrol_owner(IN struct btc_coexist * btcoexist,IN boolean wifi_control)1454 void halbtc8821c1ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist,
1455 		IN boolean wifi_control)
1456 {
1457 	u8 val;
1458 
1459 	val = (wifi_control) ? 1 : 0;
1460 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4,
1461 					   val); /* 0x70[26] */
1462 
1463 }
1464 
halbtc8821c1ant_ltecoex_set_gnt_bt(IN struct btc_coexist * btcoexist,IN u8 control_block,IN boolean sw_control,IN u8 state)1465 void halbtc8821c1ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist,
1466 			IN u8 control_block, IN boolean sw_control, IN u8 state)
1467 {
1468 	u32 val = 0, val_orig = 0;
1469 
1470 	if (!sw_control)
1471 		val = 0x0;
1472 	else if (state & 0x1)
1473 		val = 0x3;
1474 	else
1475 		val = 0x1;
1476 
1477 	val_orig = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
1478 			0x38);
1479 
1480 	switch (control_block) {
1481 	case BT_8821C_1ANT_GNT_BLOCK_RFC_BB:
1482 	default:
1483 		val = ((val << 14) | (val << 10)) | (val_orig & 0xffff33ff);
1484 		break;
1485 	case BT_8821C_1ANT_GNT_BLOCK_RFC:
1486 		val = (val << 14) | (val_orig & 0xffff3fff);
1487 		break;
1488 	case BT_8821C_1ANT_GNT_BLOCK_BB:
1489 		val = (val << 10) | (val_orig & 0xfffff3ff);
1490 		break;
1491 	}
1492 
1493 	halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist,
1494 			0x38, 0xffffffff, val);
1495 }
1496 
halbtc8821c1ant_ltecoex_set_gnt_wl(IN struct btc_coexist * btcoexist,IN u8 control_block,IN boolean sw_control,IN u8 state)1497 void halbtc8821c1ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist,
1498 			IN u8 control_block, IN boolean sw_control, IN u8 state)
1499 {
1500 	u32 val = 0, val_orig = 0;
1501 
1502 	if (!sw_control)
1503 		val = 0x0;
1504 	else if (state & 0x1)
1505 		val = 0x3;
1506 	else
1507 		val = 0x1;
1508 
1509 	val_orig = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
1510 			0x38);
1511 
1512 	switch (control_block) {
1513 	case BT_8821C_1ANT_GNT_BLOCK_RFC_BB:
1514 	default:
1515 		val = ((val << 12) | (val << 8)) | (val_orig & 0xffffccff);
1516 		break;
1517 	case BT_8821C_1ANT_GNT_BLOCK_RFC:
1518 		val = (val << 12) | (val_orig & 0xffffcfff);
1519 		break;
1520 	case BT_8821C_1ANT_GNT_BLOCK_BB:
1521 		val = (val << 8) | (val_orig & 0xfffffcff);
1522 		break;
1523 	}
1524 
1525 	halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist,
1526 			0x38, 0xffffffff, val);
1527 }
1528 
halbtc8821c1ant_ltecoex_set_coex_table(IN struct btc_coexist * btcoexist,IN u8 table_type,IN u16 table_content)1529 void halbtc8821c1ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist,
1530 		IN u8 table_type, IN u16 table_content)
1531 {
1532 	u16 reg_addr = 0x0000;
1533 
1534 	switch (table_type) {
1535 	case BT_8821C_1ANT_CTT_WL_VS_LTE:
1536 		reg_addr = 0xa0;
1537 		break;
1538 	case BT_8821C_1ANT_CTT_BT_VS_LTE:
1539 		reg_addr = 0xa4;
1540 		break;
1541 	}
1542 
1543 	if (reg_addr != 0x0000)
1544 		halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr,
1545 			0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */
1546 
1547 
1548 }
1549 
1550 
halbtc8821c1ant_ltecoex_set_break_table(IN struct btc_coexist * btcoexist,IN u8 table_type,IN u8 table_content)1551 void halbtc8821c1ant_ltecoex_set_break_table(IN struct btc_coexist *btcoexist,
1552 		IN u8 table_type, IN u8 table_content)
1553 {
1554 	u16 reg_addr = 0x0000;
1555 
1556 	switch (table_type) {
1557 	case BT_8821C_1ANT_LBTT_WL_BREAK_LTE:
1558 		reg_addr = 0xa8;
1559 		break;
1560 	case BT_8821C_1ANT_LBTT_BT_BREAK_LTE:
1561 		reg_addr = 0xac;
1562 		break;
1563 	case BT_8821C_1ANT_LBTT_LTE_BREAK_WL:
1564 		reg_addr = 0xb0;
1565 		break;
1566 	case BT_8821C_1ANT_LBTT_LTE_BREAK_BT:
1567 		reg_addr = 0xb4;
1568 		break;
1569 	}
1570 
1571 	if (reg_addr != 0x0000)
1572 		halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr,
1573 			0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */
1574 
1575 
1576 }
1577 
halbtc8821c1ant_set_wltoggle_coex_table(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 interval,IN u8 val0x6c4_b0,IN u8 val0x6c4_b1,IN u8 val0x6c4_b2,IN u8 val0x6c4_b3)1578 void halbtc8821c1ant_set_wltoggle_coex_table(IN struct btc_coexist *btcoexist,
1579 		IN boolean force_exec,  IN u8 interval,
1580 		IN u8 val0x6c4_b0, IN u8 val0x6c4_b1, IN u8 val0x6c4_b2,
1581 		IN u8 val0x6c4_b3)
1582 {
1583 	static u8 pre_h2c_parameter[6] = {0};
1584 	u8	cur_h2c_parameter[6] = {0};
1585 	u8 i, match_cnt = 0;
1586 
1587 	cur_h2c_parameter[0] = 0x7;	/* op_code, 0x7= wlan toggle slot*/
1588 
1589 	cur_h2c_parameter[1] = interval;
1590 	cur_h2c_parameter[2] = val0x6c4_b0;
1591 	cur_h2c_parameter[3] = val0x6c4_b1;
1592 	cur_h2c_parameter[4] = val0x6c4_b2;
1593 	cur_h2c_parameter[5] = val0x6c4_b3;
1594 
1595 	if (!force_exec) {
1596 		for (i = 1; i <= 5; i++) {
1597 			if (cur_h2c_parameter[i] != pre_h2c_parameter[i])
1598 				break;
1599 
1600 			match_cnt++;
1601 		}
1602 
1603 		if (match_cnt == 5)
1604 			return;
1605 	}
1606 
1607 	for (i = 1; i <= 5; i++)
1608 		pre_h2c_parameter[i] = cur_h2c_parameter[i];
1609 
1610 	btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter);
1611 }
1612 
1613 
halbtc8821c1ant_set_coex_table(IN struct btc_coexist * btcoexist,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)1614 void halbtc8821c1ant_set_coex_table(IN struct btc_coexist *btcoexist,
1615 	    IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
1616 {
1617 	btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
1618 
1619 	btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
1620 
1621 	btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
1622 
1623 	btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
1624 }
1625 
halbtc8821c1ant_coex_table(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)1626 void halbtc8821c1ant_coex_table(IN struct btc_coexist *btcoexist,
1627 			IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
1628 				IN u32 val0x6c8, IN u8 val0x6cc)
1629 {
1630 	coex_dm->cur_val0x6c0 = val0x6c0;
1631 	coex_dm->cur_val0x6c4 = val0x6c4;
1632 	coex_dm->cur_val0x6c8 = val0x6c8;
1633 	coex_dm->cur_val0x6cc = val0x6cc;
1634 
1635 	if (!force_exec) {
1636 		if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
1637 		    (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
1638 		    (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
1639 		    (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
1640 			return;
1641 	}
1642 
1643 	halbtc8821c1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
1644 				       val0x6cc);
1645 
1646 	coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
1647 	coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
1648 	coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
1649 	coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
1650 }
1651 
halbtc8821c1ant_coex_table_with_type(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)1652 void halbtc8821c1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
1653 		IN boolean force_exec, IN u8 type)
1654 {
1655 	u32	break_table;
1656 	u8	select_table;
1657 
1658 	coex_sta->coex_table_type = type;
1659 
1660 	if (coex_sta->concurrent_rx_mode_on == TRUE) {
1661 		 /* set WL hi-pri can break BT */
1662 		break_table = 0xf0ffffff;
1663 		 /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */
1664 		select_table = 0xb;
1665 	} else {
1666 		break_table = 0xffffff;
1667 		select_table = 0x3;
1668 	}
1669 
1670 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1671 		    "[BTCoex], ********** Table-%d **********\n",
1672 		    coex_sta->coex_table_type);
1673 	BTC_TRACE(trace_buf);
1674 
1675 	switch (type) {
1676 	case 0:
1677 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1678 					   0x55555555, 0x55555555, break_table,
1679 					   select_table);
1680 		break;
1681 	case 1:
1682 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1683 					   0xa5555555, 0xaa5a5a5a, break_table,
1684 					   select_table);
1685 		break;
1686 	case 2:
1687 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1688 					   0xaa5a5a5a, 0xaa5a5a5a, break_table,
1689 					   select_table);
1690 		break;
1691 	case 3:
1692 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1693 					   0xa5555555, 0x5a5a5a5a, break_table,
1694 					   select_table);
1695 		break;
1696 	case 4:
1697 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1698 					   0xa5555555, 0xaa5a5a5a, break_table,
1699 					   select_table);
1700 		break;
1701 	case 5:
1702 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1703 					   0x5a5a5a5a, 0x5a5a5a5a, break_table,
1704 					   select_table);
1705 		break;
1706 	case 6:
1707 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1708 					   0xa5555555, 0xaa5a5a5a, break_table,
1709 					   select_table);
1710 		break;
1711 	case 7:
1712 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1713 					   0xaa555555, 0xaa555555, break_table,
1714 					   select_table);
1715 		break;
1716 	case 8:
1717 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1718 					   0xa5555555, 0xaaaa5aaa, break_table,
1719 					   select_table);
1720 		break;
1721 	case 9:
1722 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1723 					   0x5a5a5a5a, 0xaaaa5aaa, break_table,
1724 					   select_table);
1725 		break;
1726 	case 10:
1727 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1728 					   0xaaaaaaaa, 0xaaaaaaaa, break_table,
1729 					   select_table);
1730 		break;
1731 	case 11:
1732 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1733 					   0xa5a55555, 0xaaaa5a5a, break_table,
1734 					   select_table);
1735 		break;
1736 	case 12:
1737 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1738 					   0xa5555555, 0xaaaa5a5a, break_table,
1739 					   select_table);
1740 		break;
1741 	case 13:
1742 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1743 					   0xaa5555aa, 0xaa5a5a5a, break_table,
1744 					   select_table);
1745 		break;
1746 	case 14:
1747 		halbtc8821c1ant_coex_table(btcoexist, force_exec,
1748 					   0xaa5555aa, 0x5a5a5a5a, break_table,
1749 					   select_table);
1750 		break;
1751 	default:
1752 		break;
1753 	}
1754 }
1755 
halbtc8821c1ant_set_fw_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean enable)1756 void halbtc8821c1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1757 		IN boolean enable)
1758 {
1759 	u8			h2c_parameter[1] = {0};
1760 
1761 	if (enable)
1762 		h2c_parameter[0] |= BIT(0);		/* function enable */
1763 
1764 	btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
1765 }
1766 
halbtc8821c1ant_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean enable)1767 void halbtc8821c1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1768 				     IN boolean force_exec, IN boolean enable)
1769 {
1770 	coex_dm->cur_ignore_wlan_act = enable;
1771 
1772 	if (!force_exec) {
1773 		if (coex_dm->pre_ignore_wlan_act ==
1774 		    coex_dm->cur_ignore_wlan_act)
1775 			return;
1776 	}
1777 	halbtc8821c1ant_set_fw_ignore_wlan_act(btcoexist, enable);
1778 
1779 	coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1780 }
1781 
halbtc8821c1ant_set_lps_rpwm(IN struct btc_coexist * btcoexist,IN u8 lps_val,IN u8 rpwm_val)1782 void halbtc8821c1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
1783 				  IN u8 lps_val, IN u8 rpwm_val)
1784 {
1785 	u8	lps = lps_val;
1786 	u8	rpwm = rpwm_val;
1787 
1788 	btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
1789 	btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1790 }
1791 
halbtc8821c1ant_lps_rpwm(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 lps_val,IN u8 rpwm_val)1792 void halbtc8821c1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
1793 		      IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
1794 {
1795 	coex_dm->cur_lps = lps_val;
1796 	coex_dm->cur_rpwm = rpwm_val;
1797 
1798 	if (!force_exec) {
1799 		if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
1800 		    (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
1801 			return;
1802 	}
1803 	halbtc8821c1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
1804 
1805 	coex_dm->pre_lps = coex_dm->cur_lps;
1806 	coex_dm->pre_rpwm = coex_dm->cur_rpwm;
1807 }
1808 
halbtc8821c1ant_ps_tdma_check_for_power_save_state(IN struct btc_coexist * btcoexist,IN boolean new_ps_state)1809 void halbtc8821c1ant_ps_tdma_check_for_power_save_state(
1810 	IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1811 {
1812 	u8	lps_mode = 0x0;
1813 	u8	h2c_parameter[5] = {0x8, 0, 0, 0, 0};
1814 
1815 	btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1816 
1817 	if (lps_mode) {	/* already under LPS state */
1818 		if (new_ps_state) {
1819 			/* keep state under LPS, do nothing. */
1820 		} else {
1821 			/* will leave LPS state, turn off psTdma first */
1822 			btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1823 						h2c_parameter);
1824 		}
1825 	} else {					/* NO PS state */
1826 		if (new_ps_state) {
1827 			/* will enter LPS state, turn off psTdma first */
1828 			btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1829 						h2c_parameter);
1830 		} else {
1831 			/* keep state under NO PS state, do nothing. */
1832 		}
1833 	}
1834 }
1835 
halbtc8821c1ant_power_save_state(IN struct btc_coexist * btcoexist,IN u8 ps_type,IN u8 lps_val,IN u8 rpwm_val)1836 boolean halbtc8821c1ant_power_save_state(IN struct btc_coexist *btcoexist,
1837 			      IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
1838 {
1839 	boolean		low_pwr_disable = FALSE, result = TRUE;
1840 
1841 	switch (ps_type) {
1842 	case BTC_PS_WIFI_NATIVE:
1843 		/* recover to original 32k low power setting */
1844 		coex_sta->force_lps_ctrl = FALSE;
1845 		low_pwr_disable = FALSE;
1846 		/* btcoexist->btc_set(btcoexist,
1847 				   BTC_SET_ACT_DISABLE_LOW_POWER,
1848 				   &low_pwr_disable); */
1849 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_PRE_NORMAL_LPS,
1850 				   NULL);
1851 
1852 		break;
1853 	case BTC_PS_LPS_ON:
1854 		coex_sta->force_lps_ctrl = TRUE;
1855 		halbtc8821c1ant_ps_tdma_check_for_power_save_state(
1856 			btcoexist, TRUE);
1857 		halbtc8821c1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1858 					 lps_val, rpwm_val);
1859 		/* when coex force to enter LPS, do not enter 32k low power. */
1860 		low_pwr_disable = TRUE;
1861 		btcoexist->btc_set(btcoexist,
1862 				   BTC_SET_ACT_DISABLE_LOW_POWER,
1863 				   &low_pwr_disable);
1864 		/* power save must executed before psTdma.			 */
1865 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1866 				   NULL);
1867 
1868 		break;
1869 	case BTC_PS_LPS_OFF:
1870 		coex_sta->force_lps_ctrl = TRUE;
1871 		halbtc8821c1ant_ps_tdma_check_for_power_save_state(
1872 			btcoexist, FALSE);
1873 		result = btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1874 				   NULL);
1875 
1876 		break;
1877 	default:
1878 		break;
1879 	}
1880 
1881 	return result;
1882 }
1883 
1884 
halbtc8821c1ant_set_fw_pstdma(IN struct btc_coexist * btcoexist,IN u8 byte1,IN u8 byte2,IN u8 byte3,IN u8 byte4,IN u8 byte5)1885 void halbtc8821c1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
1886 	   IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
1887 {
1888 	u8			h2c_parameter[5] = {0};
1889 	u8			real_byte1 = byte1, real_byte5 = byte5;
1890 	boolean			ap_enable = FALSE, result = FALSE;
1891 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1892 	u8		ps_type = BTC_PS_WIFI_NATIVE;
1893 
1894 	if (byte5 & BIT(2))
1895 		coex_sta->is_tdma_btautoslot = TRUE;
1896 	else
1897 		coex_sta->is_tdma_btautoslot = FALSE;
1898 
1899 	/* release bt-auto slot for auto-slot hang is detected!! */
1900 	if (coex_sta->is_tdma_btautoslot)
1901 		if ((coex_sta->is_tdma_btautoslot_hang) ||
1902 			(bt_link_info->slave_role))
1903 			byte5 = byte5 & 0xfb;
1904 
1905 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1906 			   &ap_enable);
1907 
1908 	if ((ap_enable) && (byte1 & BIT(4) && !(byte1 & BIT(5)))) {
1909 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1910 			    "[BTCoex], halbtc8821c1ant_set_fw_pstdma == FW for 1Ant AP mode\n");
1911 		BTC_TRACE(trace_buf);
1912 		real_byte1 &= ~BIT(4);
1913 		real_byte1 |= BIT(5);
1914 
1915 		real_byte5 |= BIT(5);
1916 		real_byte5 &= ~BIT(6);
1917 
1918 		ps_type = BTC_PS_WIFI_NATIVE;
1919 		halbtc8821c1ant_power_save_state(btcoexist,
1920 					 ps_type, 0x0,
1921 						 0x0);
1922 	} else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1923 
1924 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1925 			    "[BTCoex], halbtc8821c1ant_set_fw_pstdma == Force LPS Leave (byte1 = 0x%x)\n", byte1);
1926 		BTC_TRACE(trace_buf);
1927 
1928 		ps_type = BTC_PS_LPS_OFF;
1929 		if (!halbtc8821c1ant_power_save_state(btcoexist, ps_type, 0x50, 0x4))
1930 			result = TRUE;
1931 
1932 	} else {
1933 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1934 			    "[BTCoex], halbtc8821c1ant_set_fw_pstdma == native power save (byte1 = 0x%x)\n", byte1);
1935 		BTC_TRACE(trace_buf);
1936 
1937 		ps_type = BTC_PS_WIFI_NATIVE;
1938 		halbtc8821c1ant_power_save_state(btcoexist, ps_type,
1939 						 0x0,
1940 						 0x0);
1941 	}
1942 
1943 	coex_sta->is_set_ps_state_fail = result;
1944 
1945 	if (!coex_sta->is_set_ps_state_fail) {
1946 		h2c_parameter[0] = real_byte1;
1947 		h2c_parameter[1] = byte2;
1948 		h2c_parameter[2] = byte3;
1949 		h2c_parameter[3] = byte4;
1950 		h2c_parameter[4] = real_byte5;
1951 
1952 		coex_dm->ps_tdma_para[0] = real_byte1;
1953 		coex_dm->ps_tdma_para[1] = byte2;
1954 		coex_dm->ps_tdma_para[2] = byte3;
1955 		coex_dm->ps_tdma_para[3] = byte4;
1956 		coex_dm->ps_tdma_para[4] = real_byte5;
1957 
1958 		btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1959 
1960 	} else {
1961 		coex_sta->cnt_set_ps_state_fail++;
1962 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1963 			    "[BTCoex], halbtc8821c1ant_set_fw_pstdma == Force Leave LPS Fail (cnt = %d)\n",
1964 			    coex_sta->cnt_set_ps_state_fail);
1965 		BTC_TRACE(trace_buf);
1966 	}
1967 
1968 	if (ps_type == BTC_PS_WIFI_NATIVE)
1969 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_POST_NORMAL_LPS, NULL);
1970 }
1971 
1972 
halbtc8821c1ant_ps_tdma(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean turn_on,IN u8 type)1973 void halbtc8821c1ant_ps_tdma(IN struct btc_coexist *btcoexist,
1974 		     IN boolean force_exec, IN boolean turn_on, IN u8 type)
1975 {
1976 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1977 	struct  btc_board_info	*board_info = &btcoexist->board_info;
1978 	boolean			wifi_busy = FALSE;
1979 	static u8			psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0;
1980 	static boolean	 pre_wifi_busy = FALSE;
1981 
1982 
1983 	coex_dm->cur_ps_tdma_on = turn_on;
1984 	coex_dm->cur_ps_tdma = type;
1985 
1986 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1987 
1988 	if (wifi_busy != pre_wifi_busy) {
1989 		force_exec = TRUE;
1990 		pre_wifi_busy = wifi_busy;
1991 	}
1992 
1993 	/* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1994 	if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist))
1995 		psTdmaByte4Modify = 0x1;
1996 	else
1997 		psTdmaByte4Modify = 0x0;
1998 
1999 	if (pre_psTdmaByte4Modify != psTdmaByte4Modify) {
2000 		force_exec = TRUE;
2001 		pre_psTdmaByte4Modify = psTdmaByte4Modify;
2002 	}
2003 
2004 	if (!force_exec) {
2005 		if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
2006 		    (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) {
2007 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2008 				"[BTCoex], Skip TDMA because no change TDMA(%s, %d)\n",
2009 				    (coex_dm->cur_ps_tdma_on ? "on" : "off"),
2010 				    coex_dm->cur_ps_tdma);
2011 			BTC_TRACE(trace_buf);
2012 			return;
2013 		}
2014 	}
2015 
2016 	if (coex_dm->cur_ps_tdma_on) {
2017 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2018 			    "[BTCoex], ********** TDMA(on, %d) **********\n",
2019 			    coex_dm->cur_ps_tdma);
2020 		BTC_TRACE(trace_buf);
2021 
2022 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
2023 					   0x1);  /* enable TBTT nterrupt */
2024 	} else {
2025 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2026 			    "[BTCoex], ********** TDMA(off, %d) **********\n",
2027 			    coex_dm->cur_ps_tdma);
2028 		BTC_TRACE(trace_buf);
2029 	}
2030 
2031 
2032 	if (turn_on) {
2033 		switch (type) {
2034 		default:
2035 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2036 					      0x61, 0x35, 0x03, 0x11, 0x11);
2037 			break;
2038 		case 3:
2039 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2040 					      0x51, 0x30, 0x03, 0x10, 0x50);
2041 			break;
2042 		case 4:
2043 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2044 					      0x51, 0x21, 0x03, 0x10, 0x50);
2045 			break;
2046 		case 5:
2047 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2048 					      0x61, 0x3a, 0x03, 0x11, 0x11);
2049 			break;
2050 		case 6:
2051 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2052 					      0x61, 0x20, 0x03, 0x11, 0x10);
2053 			break;
2054 		case 7:
2055 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2056 					      0x51, 0x10, 0x03, 0x10,  0x54 |
2057 						      psTdmaByte4Modify);
2058 			break;
2059 		case 8:
2060 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2061 					      0x51, 0x10, 0x03, 0x10,  0x54 |
2062 						      psTdmaByte4Modify);
2063 			break;
2064 		case 9:
2065 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2066 					      0x51, 0x10, 0x03, 0x10,  0x54 |
2067 						      psTdmaByte4Modify);
2068 			break;
2069 		case 10:
2070 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2071 					      0x61, 0x30, 0x03, 0x11, 0x10);
2072 			break;
2073 		case 11:
2074 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2075 					      0x61, 0x25, 0x03, 0x11, 0x11);
2076 			break;
2077 		case 12:
2078 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2079 					      0x51, 0x35, 0x03, 0x10,  0x50 |
2080 						      psTdmaByte4Modify);
2081 			break;
2082 		case 13:
2083 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2084 					      0x51, 0x10, 0x07, 0x10,  0x54 |
2085 						      psTdmaByte4Modify);
2086 			break;
2087 		case 14:
2088 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2089 					      0x51, 0x15, 0x03, 0x10,  0x50 |
2090 						      psTdmaByte4Modify);
2091 			break;
2092 		case 15:
2093 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2094 					      0x51, 0x20, 0x03, 0x10,  0x50 |
2095 						      psTdmaByte4Modify);
2096 			break;
2097 		case 16:
2098 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2099 					      0x61, 0x10, 0x03, 0x11,  0x15 |
2100 						      psTdmaByte4Modify);
2101 			break;
2102 		case 17:
2103 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2104 					      0x61, 0x10, 0x03, 0x11, 0x14 |
2105 							psTdmaByte4Modify);
2106 			break;
2107 		case 18:
2108 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2109 					      0x51, 0x30, 0x03, 0x10,  0x50 |
2110 						      psTdmaByte4Modify);
2111 			break;
2112 		case 19:
2113 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2114 					      0x61, 0x15, 0x03, 0x11, 0x10);
2115 			break;
2116 		case 20:
2117 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2118 					      0x61, 0x30, 0x03, 0x11, 0x10);
2119 			break;
2120 		case 21:
2121 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2122 					      0x61, 0x30, 0x03, 0x11, 0x10);
2123 			break;
2124 		case 22:
2125 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2126 					      0x61, 0x25, 0x03, 0x11, 0x10);
2127 			break;
2128 		case 23:
2129 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2130 					      0x61, 0x10, 0x03, 0x11, 0x10);
2131 			break;
2132 		case 24:
2133 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2134 					      0x51, 0x08, 0x03, 0x10,  0x54 |
2135 						      psTdmaByte4Modify);
2136 			break;
2137 		case 27:
2138 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2139 					      0x61, 0x10, 0x03, 0x11, 0x15);
2140 			break;
2141 		case 28:
2142 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2143 					      0x51, 0x10, 0x0b, 0x10,  0x54);
2144 			break;
2145 		case 32:
2146 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2147 					      0x61, 0x35, 0x03, 0x11, 0x11);
2148 			break;
2149 		case 33:
2150 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2151 					      0x61, 0x35, 0x03, 0x11, 0x10);
2152 			break;
2153 		case 57:
2154 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2155 					      0x51, 0x10, 0x03, 0x10,  0x50 |
2156 						      psTdmaByte4Modify);
2157 			break;
2158 		case 58:
2159 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2160 					      0x51, 0x10, 0x03, 0x10,  0x50 |
2161 						      psTdmaByte4Modify);
2162 			break;
2163 		case 67:
2164 			halbtc8821c1ant_set_fw_pstdma(btcoexist,
2165 					      0x61, 0x10, 0x03, 0x11,  0x10 |
2166 						      psTdmaByte4Modify);
2167 			break;
2168 		}
2169 	} else {
2170 
2171 		/* disable PS tdma */
2172 		switch (type) {
2173 		case 8: /* PTA Control */
2174 			halbtc8821c1ant_set_fw_pstdma(btcoexist, 0x8,
2175 						      0x0, 0x0, 0x0, 0x0);
2176 			break;
2177 		case 0:
2178 		default:  /* Software control, Antenna at BT side */
2179 			halbtc8821c1ant_set_fw_pstdma(btcoexist, 0x0,
2180 						      0x0, 0x0, 0x0, 0x0);
2181 			break;
2182 		case 1: /* 2-Ant, 0x778=3, antenna control by antenna diversity */
2183 			halbtc8821c1ant_set_fw_pstdma(btcoexist, 0x0,
2184 						      0x0, 0x0, 0x48, 0x0);
2185 			break;
2186 		}
2187 	}
2188 
2189 	if (!coex_sta->is_set_ps_state_fail) {
2190 		/* update pre state */
2191 		coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
2192 		coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
2193 	}
2194 }
2195 
halbtc8821c1ant_set_int_block(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 pos_type)2196 void halbtc8821c1ant_set_int_block(IN struct btc_coexist *btcoexist,
2197 				   IN boolean force_exec,  IN u8 pos_type)
2198 {
2199 #if 0
2200 	u8		regval_0xcba;
2201 	u32		u32tmp1 = 0;
2202 
2203 	coex_dm->cur_int_block_status = pos_type;
2204 
2205 	if (!force_exec) {
2206 		if (coex_dm->pre_int_block_status ==
2207 		    coex_dm->cur_int_block_status)
2208 			return;
2209 	}
2210 
2211 	coex_dm->pre_int_block_status = coex_dm->cur_int_block_status;
2212 
2213 	regval_0xcba =  btcoexist->btc_read_1byte(btcoexist, 0xcba);
2214 
2215 	switch (pos_type) {
2216 
2217 	case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG:
2218 		regval_0xcba = (regval_0xcba | BIT(0)) & (~(BIT(
2219 			2)));				/* 0xcb8[16] = 1, 0xcb8[18] = 0, WL_G select BTG */
2220 		regval_0xcba =   regval_0xcba & 0x0f;
2221 
2222 		/*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc1d, 0x0f, 0x5); */ /* Gain Table */
2223 		/*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xa9e, 0x0f, 0x2); */ /* CCK Gain Table */
2224 
2225 		break;
2226 	case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG:
2227 		regval_0xcba =   regval_0xcba & (~(BIT(2) | BIT(
2228 			0)));			/* 0xcb8[16] = 0, 0xcb8[18] = 0, WL_G select WLAG */
2229 
2230 		/* regval_0xcba =   regval_0xcba | BIT(4) | BIT(5) ; */			/* 0xcb8[21:20] = 2b'11, WL_G @ WLAG on */
2231 		/* regval_0xcba =    (regval_0xcba | BIT(6)) & (~(BIT(7)) ) ; */		/* 0xcb8[23:22] = 2b'01, WL_A @ WLAG off */
2232 		/*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc1d, 0x0f, 0x0); */ /* Gain Table */
2233 		/*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xa9e, 0x0f, 0x6); */ /* CCK Gain Table */
2234 
2235 		break;
2236 	case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG:
2237 		regval_0xcba =   regval_0xcba & (~(BIT(2) | BIT(
2238 			0)));			/* 0xcb8[16] = 0, 0xcb8[18] = 0, WL_G select WLAG */
2239 		/*regval_0xcba = (regval_0xcba | BIT(4)) & (~(BIT(5))); */			/* 0xcb8[21:20] = 2b'01, WL_G @ WLAG off */
2240 		/*regval_0xcba = regval_0xcba | BIT(6) | BIT(7); */				/* 0xcb8[23:22] = 2b'11, WL_A @ WLAG on */
2241 
2242 		break;
2243 	}
2244 
2245 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcba, 0xff,
2246 					   regval_0xcba);
2247 
2248 	u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb8);
2249 
2250 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2251 		"[BTCoex], ********** (After Int Block setup) 0xcb8 = 0x%08x **********\n",
2252 		    u32tmp1);
2253 	BTC_TRACE(trace_buf);
2254 
2255 #endif
2256 }
2257 
halbtc8821c1ant_set_ext_band_switch(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 pos_type)2258 void halbtc8821c1ant_set_ext_band_switch(IN struct btc_coexist *btcoexist,
2259 		IN boolean force_exec, IN u8 pos_type)
2260 {
2261 
2262 #if 0
2263 	boolean	switch_polatiry_inverse = FALSE;
2264 	u8		regval_0xcb6;
2265 	u32		u32tmp1 = 0, u32tmp2 = 0;
2266 
2267 	if (!rfe_type->ext_band_switch_exist)
2268 		return;
2269 
2270 	coex_dm->cur_ext_band_switch_status = pos_type;
2271 
2272 	if (!force_exec) {
2273 		if (coex_dm->pre_ext_band_switch_status ==
2274 		    coex_dm->cur_ext_band_switch_status)
2275 			return;
2276 	}
2277 
2278 	coex_dm->pre_ext_band_switch_status =
2279 		coex_dm->cur_ext_band_switch_status;
2280 
2281 	/* swap control polarity if use different switch control polarity*/
2282 	switch_polatiry_inverse = (rfe_type->ext_band_switch_ctrl_polarity == 1
2283 		   ? ~switch_polatiry_inverse : switch_polatiry_inverse);
2284 
2285 	/*swap control polarity for WL_A, default polarity 0xcb4[21] = 0 && 0xcb4[23] = 1 is for WL_G */
2286 	switch_polatiry_inverse = (pos_type ==
2287 		BT_8821C_1ANT_EXT_BAND_SWITCH_TO_WLA ? ~switch_polatiry_inverse
2288 				   : switch_polatiry_inverse);
2289 
2290 	regval_0xcb6 =  btcoexist->btc_read_1byte(btcoexist, 0xcb6);
2291 
2292 	/* for normal switch polrity, 0xcb4[21] =1 && 0xcb4[23] = 0 for WL_A, vice versa */
2293 	regval_0xcb6 = (switch_polatiry_inverse == 1 ? ((regval_0xcb6 & (~(BIT(
2294 		7)))) | BIT(5)) : ((regval_0xcb6 & (~(BIT(5)))) | BIT(7)));
2295 
2296 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb6, 0xff,
2297 					   regval_0xcb6);
2298 
2299 	u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb0);
2300 	u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2301 
2302 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2303 		"[BTCoex], ********** (After Ext Band switch setup) 0xcb0 = 0x%08x, 0xcb4 = 0x%08x**********\n",
2304 		    u32tmp1, u32tmp2);
2305 	BTC_TRACE(trace_buf);
2306 #endif
2307 
2308 }
2309 
halbtc8821c1ant_set_ext_ant_switch(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 ctrl_type,IN u8 pos_type)2310 void halbtc8821c1ant_set_ext_ant_switch(IN struct btc_coexist *btcoexist,
2311 			IN boolean force_exec, IN u8 ctrl_type, IN u8 pos_type)
2312 {
2313 	struct  btc_board_info	*board_info = &btcoexist->board_info;
2314 	boolean	switch_polatiry_inverse = FALSE;
2315 	u8		regval_0xcb7 = 0, regval_0x64;
2316 	u32		u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
2317 
2318 	if (!rfe_type->ext_ant_switch_exist)
2319 		return;
2320 
2321 	coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8)  + pos_type;
2322 
2323 	if (!force_exec) {
2324 		if (coex_dm->pre_ext_ant_switch_status ==
2325 		    coex_dm->cur_ext_ant_switch_status)
2326 			return;
2327 	}
2328 
2329 	coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status;
2330 
2331 	/* swap control polarity if use different switch control polarity*/
2332 	/*  Normal switch polarity for DPDT, 0xcb4[29:28] = 2b'01 => BTG to Main, WLG to Aux,  0xcb4[29:28] = 2b'10 => BTG to Aux, WLG to Main */
2333 	/*  Normal switch polarity for SPDT, 0xcb4[29:28] = 2b'01 => Ant to BTG,  0xcb4[29:28] = 2b'10 => Ant to WLG */
2334 	if (rfe_type->ext_ant_switch_ctrl_polarity)
2335 		switch_polatiry_inverse =  ~switch_polatiry_inverse;
2336 
2337 	/* swap control polarity if 1-Ant at Aux */
2338 	if (rfe_type->ant_at_main_port == FALSE)
2339 		switch_polatiry_inverse =  ~switch_polatiry_inverse;
2340 
2341 	switch (pos_type) {
2342 	default:
2343 	case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_BT:
2344 	case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_NOCARE:
2345 	case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLA:
2346 
2347 		break;
2348 	case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLG:
2349 		if (!rfe_type->wlg_Locate_at_btg)
2350 			switch_polatiry_inverse =  ~switch_polatiry_inverse;
2351 		break;
2352 	}
2353 
2354 	if (board_info->ant_div_cfg)
2355 		ctrl_type = BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV;
2356 
2357 
2358 	switch (ctrl_type) {
2359 	default:
2360 	case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW:
2361 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2362 					   0x80, 0x0);  /*  0x4c[23] = 0 */
2363 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2364 					   0x01, 0x1);  /* 0x4c[24] = 1 */
2365 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
2366 			0xff, 0x77);	/* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
2367 
2368 		regval_0xcb7 = (switch_polatiry_inverse == FALSE ?
2369 			0x1 : 0x2);     /* 0xcb4[29:28] = 2b'01 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */
2370 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
2371 						   0x30, regval_0xcb7);
2372 
2373 		break;
2374 	case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA:
2375 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2376 					   0x80, 0x0);  /* 0x4c[23] = 0 */
2377 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2378 					   0x01, 0x1);  /* 0x4c[24] = 1 */
2379 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
2380 			0xff, 0x66);	/* PTA,  DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
2381 
2382 		regval_0xcb7 = (switch_polatiry_inverse == FALSE ?
2383 			0x2 : 0x1);     /* 0xcb4[29:28] = 2b'10 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0  @ GNT_BT=1 */
2384 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
2385 						   0x30, regval_0xcb7);
2386 
2387 		break;
2388 	case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV:
2389 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2390 					   0x80, 0x0);  /* 0x4c[23] = 0 */
2391 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2392 					   0x01, 0x1);  /* 0x4c[24] = 1 */
2393 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
2394 						   0xff, 0x88);  /* */
2395 
2396 		/* no regval_0xcb7 setup required, because  antenna switch control value by antenna diversity */
2397 
2398 		break;
2399 	case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC:
2400 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2401 					   0x80, 0x1);  /*  0x4c[23] = 1 */
2402 
2403 		regval_0x64 = (switch_polatiry_inverse == FALSE ?  0x0 :
2404 			0x1);     /* 0x64[0] = 1b'0 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */
2405 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1,
2406 						   regval_0x64);
2407 		break;
2408 	case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT:
2409 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
2410 					   0x80, 0x0);  /* 0x4c[23] = 0 */
2411 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
2412 					   0x01, 0x0);  /* 0x4c[24] = 0 */
2413 
2414 		/* no  setup required, because  antenna switch control value by BT vendor 0xac[1:0] */
2415 		break;
2416 	}
2417 
2418 	/* PAPE, LNA_ON control by BT  while WLAN off for current leakage issue */
2419 	if (ctrl_type == BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT) {
2420 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20,
2421 					   0x0);  /* PAPE   0x64[29] = 0 */
2422 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10,
2423 					   0x0);  /* LNA_ON 0x64[28] = 0 */
2424 	} else {
2425 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20,
2426 					   0x1);  /* PAPE   0x64[29] = 1 */
2427 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10,
2428 					   0x1);  /* LNA_ON 0x64[28] = 1 */
2429 	}
2430 
2431 #if BT_8821C_1ANT_COEX_DBG
2432 	u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2433 	u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c);
2434 	u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff;
2435 
2436 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2437 		"[BTCoex], (After Ext Ant switch setup) 0xcb4 = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x\n",
2438 		    u32tmp1, u32tmp2, u32tmp3);
2439 	BTC_TRACE(trace_buf);
2440 #endif
2441 
2442 }
2443 
halbtc8821c1ant_set_rfe_type(IN struct btc_coexist * btcoexist)2444 void halbtc8821c1ant_set_rfe_type(IN struct btc_coexist *btcoexist)
2445 {
2446 	struct  btc_board_info *board_info = &btcoexist->board_info;
2447 
2448 
2449 	/* the following setup should be got from Efuse in the future */
2450 	rfe_type->rfe_module_type = board_info->rfe_type & 0x1f;
2451 
2452 	rfe_type->ext_ant_switch_ctrl_polarity = 0;
2453 
2454 	switch (rfe_type->rfe_module_type) {
2455 	case 0:
2456 	case 8:
2457 	default:
2458 		rfe_type->ext_ant_switch_exist = TRUE;
2459 		rfe_type->ext_ant_switch_type =
2460 			BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT;    /*2-Ant, DPDT, WLG*/
2461 		rfe_type->wlg_Locate_at_btg = FALSE;
2462 		rfe_type->ant_at_main_port = TRUE;
2463 		break;
2464 	case 1:
2465 	case 9:
2466 		rfe_type->ext_ant_switch_exist = TRUE;
2467 		rfe_type->ext_ant_switch_type =
2468 			BT_8821C_1ANT_EXT_ANT_SWITCH_USE_SPDT;     /*1-Ant, Main, WLG */
2469 		rfe_type->wlg_Locate_at_btg = FALSE;
2470 		rfe_type->ant_at_main_port = TRUE;
2471 		break;
2472 	case 2:
2473 	case 10:
2474 		rfe_type->ext_ant_switch_exist = TRUE;
2475 		rfe_type->ext_ant_switch_type =
2476 			BT_8821C_1ANT_EXT_ANT_SWITCH_USE_SPDT;     /*1-Ant, Main, BTG */
2477 		rfe_type->wlg_Locate_at_btg = TRUE;
2478 		rfe_type->ant_at_main_port = TRUE;
2479 		break;
2480 	case 3:
2481 	case 11:
2482 		rfe_type->ext_ant_switch_exist = TRUE;
2483 		rfe_type->ext_ant_switch_type =
2484 			BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT;    /*1-Ant, Aux, WLG */
2485 		rfe_type->wlg_Locate_at_btg = FALSE;
2486 		rfe_type->ant_at_main_port = FALSE;
2487 		break;
2488 	case 4:
2489 	case 12:
2490 		rfe_type->ext_ant_switch_exist = TRUE;
2491 		rfe_type->ext_ant_switch_type =
2492 			BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT;    /*1-Ant, Aux, BTG */
2493 		rfe_type->wlg_Locate_at_btg = TRUE;
2494 		rfe_type->ant_at_main_port = FALSE;
2495 		break;
2496 	case 5:
2497 	case 13:
2498 		rfe_type->ext_ant_switch_exist = FALSE;		/*2-Ant, no switch, WLG*/
2499 		rfe_type->ext_ant_switch_type =
2500 			BT_8821C_1ANT_EXT_ANT_SWITCH_NONE;
2501 		rfe_type->wlg_Locate_at_btg = FALSE;
2502 		rfe_type->ant_at_main_port = TRUE;
2503 		break;
2504 	case 6:
2505 	case 14:
2506 		rfe_type->ext_ant_switch_exist = FALSE;		/*2-Ant, no antenna switch, WLG*/
2507 		rfe_type->ext_ant_switch_type =
2508 			BT_8821C_1ANT_EXT_ANT_SWITCH_NONE;
2509 		rfe_type->wlg_Locate_at_btg = FALSE;
2510 		rfe_type->ant_at_main_port = TRUE;
2511 		break;
2512 	case 7:
2513 	case 15:
2514 		rfe_type->ext_ant_switch_exist = TRUE;	/*2-Ant, DPDT, BTG*/
2515 		rfe_type->ext_ant_switch_type =
2516 			BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT;
2517 		rfe_type->wlg_Locate_at_btg = TRUE;
2518 		rfe_type->ant_at_main_port = TRUE;
2519 		break;
2520 	}
2521 
2522 #if 0
2523 	if (rfe_type->wlg_Locate_at_btg)
2524 		halbtc8821c1ant_set_int_block(btcoexist, FORCE_EXEC,
2525 			      BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG);
2526 	else
2527 		halbtc8821c1ant_set_int_block(btcoexist, FORCE_EXEC,
2528 			      BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG);
2529 #endif
2530 
2531 }
2532 
2533 
halbtc8821c1ant_set_ant_path(IN struct btc_coexist * btcoexist,IN u8 ant_pos_type,IN boolean force_exec,IN u8 phase)2534 void halbtc8821c1ant_set_ant_path(IN struct btc_coexist *btcoexist,
2535 				  IN u8 ant_pos_type, IN boolean force_exec,
2536 				  IN u8 phase)
2537 {
2538 	struct  btc_board_info *board_info = &btcoexist->board_info;
2539 	u32			cnt_bt_cal_chk = 0;
2540 	boolean			is_in_mp_mode = FALSE;
2541 	u8			u8tmp = 0;
2542 	u32			u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
2543 	u16			u16tmp1 = 0;
2544 
2545 
2546 	u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
2547 			0x38);
2548 
2549 	/* To avoid indirect access fail  */
2550 	if (((u32tmp1 & 0xf000) >> 12) != ((u32tmp1 & 0x0f00) >> 8)) {
2551 		force_exec = TRUE;
2552 		coex_sta->gnt_error_cnt++;
2553 
2554 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2555 		"[BTCoex],(Before Ant Setup) 0x38= 0x%x\n",
2556 		    u32tmp1);
2557 		BTC_TRACE(trace_buf);
2558 	}
2559 
2560 
2561 #if BT_8821C_1ANT_COEX_DBG
2562 
2563 	u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
2564 			0x54);
2565 	u8tmp  = btcoexist->btc_read_1byte(btcoexist, 0x73);
2566 
2567 	u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2568 
2569 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2570 		"[BTCoex],(Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
2571 		    u32tmp3, u8tmp, u32tmp1, u32tmp2);
2572 	BTC_TRACE(trace_buf);
2573 #endif
2574 
2575 	coex_dm->cur_ant_pos_type = (ant_pos_type << 8)  + phase;
2576 
2577 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2578 		"[BTCoex],(Before Ant Setup) pre_ant_pos_type = 0x%x, cur_ant_pos_type = 0x%x\n",
2579 		    coex_dm->pre_ant_pos_type,
2580 		    coex_dm->cur_ant_pos_type);
2581 	BTC_TRACE(trace_buf);
2582 
2583 
2584 	if (!force_exec) {
2585 		if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type)
2586 			return;
2587 	}
2588 
2589 	coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type;
2590 
2591 
2592 	switch (phase) {
2593 	case BT_8821C_1ANT_PHASE_COEX_POWERON:
2594 
2595 		/* set Path control owner to BT at power-on step */
2596 		halbtc8821c1ant_ltecoex_pathcontrol_owner(btcoexist,
2597 				BT_8821C_1ANT_PCO_BTSIDE);
2598 
2599 		/* set GNT_BT to SW high */
2600 		halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
2601 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2602 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
2603 					   BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
2604 		/* Set GNT_WL to SW high */
2605 		halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
2606 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2607 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
2608 					   BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
2609 
2610 		if (BTC_ANT_PATH_AUTO == ant_pos_type)
2611 			ant_pos_type = BTC_ANT_PATH_BT;
2612 
2613 		coex_sta->run_time_state = FALSE;
2614 
2615 		break;
2616 	case BT_8821C_1ANT_PHASE_COEX_INIT:
2617 		/* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */
2618 		halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0);
2619 
2620 		/* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */
2621 		halbtc8821c1ant_ltecoex_set_coex_table(
2622 			btcoexist,
2623 			BT_8821C_1ANT_CTT_WL_VS_LTE,
2624 			0xffff);
2625 
2626 		/* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */
2627 		halbtc8821c1ant_ltecoex_set_coex_table(
2628 			btcoexist,
2629 			BT_8821C_1ANT_CTT_BT_VS_LTE,
2630 			0xffff);
2631 
2632 		/* Wait If BT IQK running, because Path control owner is at BT during BT IQK (setup by WiFi firmware) */
2633 		while (cnt_bt_cal_chk <= 20) {
2634 			u8tmp = btcoexist->btc_read_1byte(
2635 					btcoexist,
2636 					0x49c);
2637 			cnt_bt_cal_chk++;
2638 			if (u8tmp & BIT(1)) {
2639 				BTC_SPRINTF(
2640 					trace_buf,
2641 					BT_TMP_BUF_SIZE,
2642 					"[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n",
2643 					cnt_bt_cal_chk);
2644 				BTC_TRACE(
2645 					trace_buf);
2646 				delay_ms(50);
2647 			} else {
2648 				BTC_SPRINTF(
2649 					trace_buf,
2650 					BT_TMP_BUF_SIZE,
2651 					"[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n",
2652 					cnt_bt_cal_chk);
2653 				BTC_TRACE(
2654 					trace_buf);
2655 				break;
2656 			}
2657 		}
2658 
2659 		/* set Path control owner to WL at initial step */
2660 		halbtc8821c1ant_ltecoex_pathcontrol_owner(
2661 			btcoexist,
2662 			BT_8821C_1ANT_PCO_WLSIDE);
2663 
2664 		/* set GNT_BT to SW high */
2665 		halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
2666 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2667 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
2668 					   BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
2669 		/* Set GNT_WL to SW low */
2670 		halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
2671 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2672 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
2673 					   BT_8821C_1ANT_SIG_STA_SET_TO_LOW);
2674 
2675 		coex_sta->run_time_state = FALSE;
2676 
2677 		if (BTC_ANT_PATH_AUTO == ant_pos_type)
2678 			ant_pos_type = BTC_ANT_PATH_BT;
2679 
2680 		break;
2681 	case BT_8821C_1ANT_PHASE_WLANONLY_INIT:
2682 		/* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */
2683 		halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0);
2684 
2685 		/* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */
2686 		halbtc8821c1ant_ltecoex_set_coex_table(
2687 			btcoexist,
2688 			BT_8821C_1ANT_CTT_WL_VS_LTE,
2689 			0xffff);
2690 
2691 		/* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */
2692 		halbtc8821c1ant_ltecoex_set_coex_table(
2693 			btcoexist,
2694 			BT_8821C_1ANT_CTT_BT_VS_LTE,
2695 			0xffff);
2696 
2697 		/* set Path control owner to WL at initial step */
2698 		halbtc8821c1ant_ltecoex_pathcontrol_owner(
2699 			btcoexist,
2700 			BT_8821C_1ANT_PCO_WLSIDE);
2701 
2702 		/* set GNT_BT to SW Low */
2703 		halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
2704 						BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2705 						BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
2706 						BT_8821C_1ANT_SIG_STA_SET_TO_LOW);
2707 		/* Set GNT_WL to SW high */
2708 		halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
2709 						BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2710 						BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
2711 						BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
2712 
2713 		coex_sta->run_time_state = FALSE;
2714 
2715 		if (BTC_ANT_PATH_AUTO == ant_pos_type)
2716 			ant_pos_type = BTC_ANT_PATH_WIFI;
2717 
2718 		break;
2719 	case BT_8821C_1ANT_PHASE_WLAN_OFF:
2720 		/* Disable LTE Coex Function in WiFi side */
2721 		halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0);
2722 
2723 		/* set Path control owner to BT */
2724 		halbtc8821c1ant_ltecoex_pathcontrol_owner(
2725 			btcoexist,
2726 			BT_8821C_1ANT_PCO_BTSIDE);
2727 
2728 		/* Set Ext Ant Switch to BT control at wifi off step */
2729 		halbtc8821c1ant_set_ext_ant_switch(btcoexist,
2730 						FORCE_EXEC,
2731 						BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT,
2732 						BT_8821C_1ANT_EXT_ANT_SWITCH_TO_NOCARE);
2733 
2734 		halbtc8821c1ant_ignore_wlan_act(btcoexist,
2735 							FORCE_EXEC, TRUE);
2736 
2737 		coex_sta->run_time_state = FALSE;
2738 		break;
2739 	case BT_8821C_1ANT_PHASE_2G_RUNTIME:
2740 
2741 		while (cnt_bt_cal_chk <= 20) {
2742 			/* 0x49c[0]=1 WL IQK, 0x49c[1]=1 BT IQK*/
2743 			u8tmp = btcoexist->btc_read_1byte(
2744 					btcoexist,
2745 					0x49c);
2746 
2747 			cnt_bt_cal_chk++;
2748 			if (u8tmp & BIT(0)) {
2749 				BTC_SPRINTF(trace_buf,
2750 					    BT_TMP_BUF_SIZE,
2751 					"[BTCoex], ########### WL is IQK (wait cnt=%d)\n",
2752 					    cnt_bt_cal_chk);
2753 				BTC_TRACE(trace_buf);
2754 				delay_ms(50);
2755 			} else if (u8tmp & BIT(1)) {
2756 				BTC_SPRINTF(trace_buf,
2757 					    BT_TMP_BUF_SIZE,
2758 					"[BTCoex], ########### BT is IQK (wait cnt=%d)\n",
2759 					    cnt_bt_cal_chk);
2760 				BTC_TRACE(trace_buf);
2761 				delay_ms(50);
2762 			} else {
2763 				BTC_SPRINTF(trace_buf,
2764 					    BT_TMP_BUF_SIZE,
2765 					"[BTCoex], ********** WL and BT is NOT IQK (wait cnt=%d)\n",
2766 					    cnt_bt_cal_chk);
2767 				BTC_TRACE(trace_buf);
2768 				break;
2769 			}
2770 		}
2771 
2772 		/* set Path control owner to WL at runtime step */
2773 		halbtc8821c1ant_ltecoex_pathcontrol_owner(
2774 			btcoexist,
2775 			BT_8821C_1ANT_PCO_WLSIDE);
2776 
2777 		/* set GNT_BT to PTA */
2778 		halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
2779 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2780 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA,
2781 					   BT_8821C_1ANT_SIG_STA_SET_BY_HW);
2782 
2783 		halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
2784 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2785 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA,
2786 					   BT_8821C_1ANT_SIG_STA_SET_BY_HW);
2787 
2788 		coex_sta->run_time_state = TRUE;
2789 
2790 		if (BTC_ANT_PATH_AUTO == ant_pos_type) {
2791 			if (rfe_type->wlg_Locate_at_btg)
2792 				ant_pos_type =
2793 					BTC_ANT_PATH_WIFI;
2794 			else
2795 				ant_pos_type = BTC_ANT_PATH_PTA;
2796 		}
2797 
2798 		if (rfe_type->wlg_Locate_at_btg)
2799 			halbtc8821c1ant_set_int_block(btcoexist,
2800 						      NORMAL_EXEC,
2801 				BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG);
2802 		else
2803 			halbtc8821c1ant_set_int_block(btcoexist,
2804 						      NORMAL_EXEC,
2805 				BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG);
2806 
2807 		break;
2808 	case BT_8821C_1ANT_PHASE_5G_RUNTIME:
2809 
2810 		/* set Path control owner to WL at runtime step */
2811 		halbtc8821c1ant_ltecoex_pathcontrol_owner(
2812 			btcoexist,
2813 			BT_8821C_1ANT_PCO_WLSIDE);
2814 
2815 		/* set GNT_BT to SW Hi */
2816 		halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
2817 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2818 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA,
2819 					   BT_8821C_1ANT_SIG_STA_SET_BY_HW);
2820 
2821 		/* Set GNT_WL to SW Hi */
2822 		halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
2823 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2824 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
2825 					   BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
2826 
2827 		coex_sta->run_time_state = TRUE;
2828 
2829 		if (BTC_ANT_PATH_AUTO == ant_pos_type) {
2830 			/*	if (rfe_type->ext_band_switch_exist)
2831 					ant_pos_type =   BTC_ANT_PATH_PTA;
2832 				else */
2833 			ant_pos_type =
2834 				BTC_ANT_PATH_WIFI5G;
2835 		}
2836 
2837 		halbtc8821c1ant_set_int_block(btcoexist,
2838 					      NORMAL_EXEC,
2839 			      BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG);
2840 
2841 		break;
2842 	case BT_8821C_1ANT_PHASE_BTMPMODE:
2843 		/* Disable LTE Coex Function in WiFi side */
2844 		halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0);
2845 
2846 		/* set Path control owner to WL */
2847 		halbtc8821c1ant_ltecoex_pathcontrol_owner(
2848 			btcoexist,
2849 			BT_8821C_1ANT_PCO_WLSIDE);
2850 
2851 		/* set GNT_BT to SW Hi */
2852 		halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
2853 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2854 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
2855 					   BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
2856 
2857 		/* Set GNT_WL to SW Lo */
2858 		halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
2859 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2860 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
2861 					   BT_8821C_1ANT_SIG_STA_SET_TO_LOW);
2862 
2863 		coex_sta->run_time_state = FALSE;
2864 
2865 		/* Set Ext Ant Switch to BT side at BT MP mode */
2866 		if (BTC_ANT_PATH_AUTO == ant_pos_type)
2867 			ant_pos_type = BTC_ANT_PATH_BT;
2868 
2869 		break;
2870 	case BT_8821C_1ANT_PHASE_ANTENNA_DET:
2871 		halbtc8821c1ant_ltecoex_pathcontrol_owner(btcoexist,
2872 				BT_8821C_1ANT_PCO_WLSIDE);
2873 
2874 		/* set GNT_BT to high */
2875 		halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist,
2876 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2877 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
2878 					   BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
2879 		/* Set GNT_WL to high */
2880 		halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist,
2881 					   BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
2882 					   BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
2883 					   BT_8821C_1ANT_SIG_STA_SET_TO_HIGH);
2884 
2885 		if (BTC_ANT_PATH_AUTO == ant_pos_type)
2886 			ant_pos_type = BTC_ANT_PATH_BT;
2887 
2888 		coex_sta->run_time_state = FALSE;
2889 
2890 		break;
2891 	}
2892 
2893 	if (phase != BT_8821C_1ANT_PHASE_WLAN_OFF) {
2894 		switch (ant_pos_type) {
2895 		case BTC_ANT_PATH_WIFI:
2896 			halbtc8821c1ant_set_ext_ant_switch(
2897 				btcoexist,
2898 				force_exec,
2899 				BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
2900 				BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLG);
2901 			break;
2902 		case BTC_ANT_PATH_WIFI5G
2903 				:
2904 			halbtc8821c1ant_set_ext_ant_switch(
2905 				btcoexist,
2906 				force_exec,
2907 				BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
2908 				BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLA);
2909 			break;
2910 		case BTC_ANT_PATH_BT:
2911 			halbtc8821c1ant_set_ext_ant_switch(
2912 				btcoexist,
2913 				force_exec,
2914 				BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
2915 				BT_8821C_1ANT_EXT_ANT_SWITCH_TO_BT);
2916 			break;
2917 		default:
2918 		case BTC_ANT_PATH_PTA:
2919 			halbtc8821c1ant_set_ext_ant_switch(
2920 				btcoexist,
2921 				force_exec,
2922 				BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA,
2923 				BT_8821C_1ANT_EXT_ANT_SWITCH_TO_NOCARE);
2924 			break;
2925 		}
2926 
2927 	}
2928 
2929 #if BT_8821C_1ANT_COEX_DBG
2930 	u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
2931 	u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
2932 	u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2933 	u8tmp  = btcoexist->btc_read_1byte(btcoexist, 0x73);
2934 
2935 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2936 		"[BTCoex],(After Ant-Setup phase---%d) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
2937 		    phase, u32tmp3, u8tmp, u32tmp1, u32tmp2);
2938 
2939 	BTC_TRACE(trace_buf);
2940 #endif
2941 }
2942 
2943 
halbtc8821c1ant_is_common_action(IN struct btc_coexist * btcoexist)2944 boolean halbtc8821c1ant_is_common_action(IN struct btc_coexist *btcoexist)
2945 {
2946 	boolean			common = FALSE, wifi_connected = FALSE, wifi_busy = FALSE;
2947 
2948 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2949 			   &wifi_connected);
2950 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2951 
2952 	if (!wifi_connected &&
2953 	    BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2954 	    coex_dm->bt_status) {
2955 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2956 			"[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
2957 		BTC_TRACE(trace_buf);
2958 
2959 		common = TRUE;
2960 	} else if (wifi_connected &&
2961 		   (BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2962 		    coex_dm->bt_status)) {
2963 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2964 			"[BTCoex], Wifi connected + BT non connected-idle!!\n");
2965 		BTC_TRACE(trace_buf);
2966 
2967 		common = TRUE;
2968 	} else if (!wifi_connected &&
2969 		   (BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE ==
2970 		    coex_dm->bt_status)) {
2971 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2972 			"[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
2973 		BTC_TRACE(trace_buf);
2974 
2975 		common = TRUE;
2976 	} else if (wifi_connected &&
2977 		   (BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE ==
2978 		    coex_dm->bt_status)) {
2979 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2980 			    "[BTCoex], Wifi connected + BT connected-idle!!\n");
2981 		BTC_TRACE(trace_buf);
2982 
2983 		common = TRUE;
2984 	} else if (!wifi_connected &&
2985 		   (BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE !=
2986 		    coex_dm->bt_status)) {
2987 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2988 			    "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
2989 		BTC_TRACE(trace_buf);
2990 
2991 		common = TRUE;
2992 	} else {
2993 		if (wifi_busy) {
2994 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2995 				"[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
2996 			BTC_TRACE(trace_buf);
2997 		} else {
2998 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2999 				"[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
3000 			BTC_TRACE(trace_buf);
3001 		}
3002 
3003 		common = FALSE;
3004 	}
3005 
3006 	return common;
3007 }
3008 
3009 
3010 /* *********************************************
3011  *
3012  *	Software Coex Mechanism start
3013  *
3014  * ********************************************* */
3015 
3016 
3017 
3018 /* *********************************************
3019  *
3020  *	Non-Software Coex Mechanism start
3021  *
3022  * ********************************************* */
halbtc8821c1ant_action_bt_whql_test(IN struct btc_coexist * btcoexist)3023 void halbtc8821c1ant_action_bt_whql_test(IN struct btc_coexist *btcoexist)
3024 {
3025 	halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
3026 				     BT_8821C_1ANT_PHASE_2G_RUNTIME);
3027 	halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3028 	halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 8);
3029 }
3030 
halbtc8821c1ant_action_bt_hs(IN struct btc_coexist * btcoexist)3031 void halbtc8821c1ant_action_bt_hs(IN struct btc_coexist *btcoexist)
3032 {
3033 	halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3034 	halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 5);
3035 }
3036 
halbtc8821c1ant_action_bt_relink(IN struct btc_coexist * btcoexist)3037 void halbtc8821c1ant_action_bt_relink(IN struct btc_coexist *btcoexist)
3038 {
3039 	if (coex_sta->is_bt_multi_link == TRUE)
3040 		return;
3041 
3042 	halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3043 	halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 8);
3044 }
3045 
halbtc8821c1ant_action_bt_idle(IN struct btc_coexist * btcoexist)3046 void halbtc8821c1ant_action_bt_idle(IN struct btc_coexist *btcoexist)
3047 {
3048 	boolean wifi_busy = FALSE;
3049 
3050 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3051 
3052 	if (!wifi_busy) {
3053 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3054 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 6);
3055 	} else {  /* if wl busy */
3056 
3057 		if (BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
3058 		    coex_dm->bt_status) {
3059 
3060 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3061 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 33);
3062 		} else {
3063 
3064 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3065 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 32);
3066 		}
3067 	}
3068 
3069 }
3070 
halbtc8821c1ant_action_bt_inquiry(IN struct btc_coexist * btcoexist)3071 void halbtc8821c1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
3072 {
3073 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3074 	boolean			wifi_connected = FALSE, wifi_busy = FALSE,
3075 				bt_busy = FALSE;
3076 	boolean	wifi_scan = FALSE, wifi_link = FALSE, wifi_roam = FALSE;
3077 
3078 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
3079 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3080 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3081 
3082 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
3083 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link);
3084 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam);
3085 
3086 
3087 	if ((coex_sta->bt_create_connection) && ((wifi_link) || (wifi_roam)
3088 		|| (wifi_scan) || (wifi_busy) || (coex_sta->wifi_is_high_pri_task))) {
3089 
3090 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3091 			"[BTCoex], Wifi link/roam/Scan/busy/hi-pri-task + BT Inq/Page!!\n");
3092 		BTC_TRACE(trace_buf);
3093 
3094 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
3095 
3096 		if ((bt_link_info->a2dp_exist) && (!bt_link_info->pan_exist))
3097 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 17);
3098 		else
3099 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 33);
3100 	} else if ((!wifi_connected) && (!wifi_scan)) {
3101 
3102 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3103 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 8);
3104 	} else if (bt_link_info->pan_exist) {
3105 
3106 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3107 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 22);
3108 	} else if (bt_link_info->a2dp_exist) {
3109 
3110 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3111 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 16);
3112 	} else {
3113 
3114 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3115 
3116 		if ((wifi_link) || (wifi_roam) || (wifi_scan) || (wifi_busy)
3117 			|| (coex_sta->wifi_is_high_pri_task))
3118 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 21);
3119 		else
3120 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 23);
3121 	}
3122 }
3123 
halbtc8821c1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist * btcoexist)3124 void halbtc8821c1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
3125 		*btcoexist)
3126 {
3127 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3128 	boolean	wifi_connected = FALSE, wifi_busy = FALSE, wifi_cckdeadlock_ap = FALSE;
3129 	u32  wifi_bw = 1;
3130 	u8	iot_peer = BTC_IOT_PEER_UNKNOWN;
3131 
3132 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
3133 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3134 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3135 	btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer);
3136 
3137 	if ((iot_peer == BTC_IOT_PEER_ATHEROS) && (coex_sta->cck_lock_ever))
3138 		wifi_cckdeadlock_ap = TRUE;
3139 
3140 	if (bt_link_info->sco_exist) {
3141 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
3142 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 5);
3143 	} else {
3144 		/* for HID exist */
3145 		if ((wifi_cckdeadlock_ap) && (coex_sta->is_bt_multi_link)) {
3146 
3147 			if (coex_sta->hid_busy_num < 2)
3148 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14);
3149 			else
3150 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
3151 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 18);
3152 		} else if (coex_sta->is_hid_low_pri_tx_overhead) {
3153 			if (coex_sta->hid_busy_num < 2)
3154 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3155 			else
3156 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
3157 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 18);
3158 		} else if (coex_sta->hid_busy_num < 2) {
3159 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3160 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 11);
3161 		} else if (wifi_bw == 0) { /* if 11bg mode */
3162 
3163 			if (coex_sta->is_bt_multi_link) {
3164 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 11);
3165 				halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 11);
3166 			} else {
3167 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 11);
3168 				halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 11);
3169 			}
3170 		} else {
3171 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
3172 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 11);
3173 		}
3174 	}
3175 }
3176 
halbtc8821c1ant_action_wifi_under5g(IN struct btc_coexist * btcoexist)3177 void halbtc8821c1ant_action_wifi_under5g(IN struct btc_coexist *btcoexist)
3178 {
3179 	halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
3180 				     BT_8821C_1ANT_PHASE_5G_RUNTIME);
3181 	halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3182 	halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 8);
3183 }
3184 
3185 
halbtc8821c1ant_action_wifi_only(IN struct btc_coexist * btcoexist)3186 void halbtc8821c1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
3187 {
3188 	halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
3189 				     BT_8821C_1ANT_PHASE_2G_RUNTIME);
3190 	halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 10);
3191 	halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, FALSE, 8);
3192 }
3193 
halbtc8821c1ant_action_wifi_native_lps(IN struct btc_coexist * btcoexist)3194 void halbtc8821c1ant_action_wifi_native_lps(IN struct btc_coexist *btcoexist)
3195 {
3196 	halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3197 	halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 8);
3198 }
3199 
halbtc8821c1ant_action_wifi_cck_dead_lock(IN struct btc_coexist * btcoexist)3200 void halbtc8821c1ant_action_wifi_cck_dead_lock(IN struct btc_coexist *btcoexist)
3201 {
3202 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3203 
3204 	if ((bt_link_info->hid_exist) && (bt_link_info->a2dp_exist) &&
3205 		(!bt_link_info->pan_exist)) {
3206 
3207 		if ((coex_sta->cck_lock) || (coex_sta->cck_lock_warn)) {
3208 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
3209 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 28);
3210 		} else {
3211 
3212 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
3213 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 8);
3214 		}
3215 	}
3216 }
3217 
halbtc8821c1ant_action_wifi_multi_port(IN struct btc_coexist * btcoexist)3218 void halbtc8821c1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
3219 {
3220 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3221 
3222 	if ((BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
3223 		coex_dm->bt_status) ||
3224 		(BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE ==
3225 		coex_dm->bt_status))
3226 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3227 	else if (!bt_link_info->pan_exist)
3228 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3229 	else
3230 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3231 
3232 	halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
3233 				     BT_8821C_1ANT_PHASE_2G_RUNTIME);
3234 	halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 8);
3235 }
3236 
3237 
halbtc8821c1ant_action_wifi_linkscan_process(IN struct btc_coexist * btcoexist)3238 void halbtc8821c1ant_action_wifi_linkscan_process(IN struct btc_coexist
3239 		*btcoexist)
3240 {
3241 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3242 
3243 	if (bt_link_info->pan_exist) {
3244 
3245 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3246 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 22);
3247 	} else if (bt_link_info->a2dp_exist) {
3248 
3249 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3250 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 27);
3251 	} else {
3252 
3253 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3254 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 21);
3255 	}
3256 
3257 }
3258 
halbtc8821c1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist * btcoexist)3259 void halbtc8821c1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
3260 		*btcoexist)
3261 {
3262 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3263 	boolean	wifi_busy = FALSE, wifi_turbo = FALSE, wifi_cckdeadlock_ap = FALSE;
3264 	u32  wifi_bw = 1;
3265 	u8	iot_peer = BTC_IOT_PEER_UNKNOWN;
3266 
3267 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW,
3268 			   &wifi_bw);
3269 
3270 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3271 	btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &coex_sta->scan_ap_num);
3272 	btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer);
3273 
3274 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3275 		"############# [BTCoex],  scan_ap_num = %d, wl_noisy_level = %d\n",
3276 		    coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
3277 	BTC_TRACE(trace_buf);
3278 
3279 	if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
3280 		wifi_turbo = TRUE;
3281 
3282 	if ((iot_peer == BTC_IOT_PEER_ATHEROS) && (coex_sta->cck_lock_ever))
3283 		wifi_cckdeadlock_ap = TRUE;
3284 
3285 	if ((bt_link_info->a2dp_exist) && (coex_sta->is_bt_a2dp_sink)) {
3286 
3287 		if (wifi_cckdeadlock_ap)
3288 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
3289 		else
3290 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
3291 
3292 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 12);
3293 	} else if (bt_link_info->a2dp_only) { /* A2DP		 */
3294 
3295 		if (wifi_cckdeadlock_ap)
3296 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
3297 		else if (wifi_turbo)
3298 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3299 		else
3300 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3301 
3302 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 7);
3303 	} else if (((bt_link_info->a2dp_exist) &&
3304 		    (bt_link_info->pan_exist)) ||
3305 			(bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
3306 		bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
3307 
3308 		if (wifi_cckdeadlock_ap) {
3309 			if ((bt_link_info->hid_exist) && (coex_sta->hid_busy_num < 2))
3310 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14);
3311 			else
3312 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
3313 		} else if (bt_link_info->hid_exist) {
3314 			if (coex_sta->hid_busy_num < 2)
3315 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3316 			else
3317 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
3318 		} else if (wifi_turbo)
3319 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3320 		else
3321 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3322 
3323 		if (wifi_busy)
3324 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 13);
3325 		else
3326 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 14);
3327 	} else if (bt_link_info->hid_exist &&
3328 		   bt_link_info->a2dp_exist) { /* HID+A2DP */
3329 
3330 		if (wifi_cckdeadlock_ap) {
3331 #if 1
3332 			if (coex_sta->hid_busy_num < 2)
3333 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14);
3334 			else
3335 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
3336 
3337 			if (coex_sta->hid_pair_cnt > 1)
3338 				halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 24);
3339 			else
3340 				halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 8);
3341 #endif
3342 
3343 #if 0
3344 			halbtc8821c1ant_action_wifi_cck_dead_lock(btcoexist);
3345 #endif
3346 		} else {
3347 			if (coex_sta->hid_busy_num < 2) /* 2/18 HID */
3348 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3349 			else if (wifi_bw == 0)/* if 11bg mode */
3350 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 12);
3351 			else
3352 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
3353 
3354 			if (coex_sta->hid_pair_cnt > 1)
3355 				halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 24);
3356 			else
3357 				halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 8);
3358 		}
3359 	} else if ((bt_link_info->pan_only)
3360 		   || (bt_link_info->hid_exist && bt_link_info->pan_exist)) {
3361 			/* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
3362 
3363 		if (wifi_cckdeadlock_ap) {
3364 			if ((bt_link_info->hid_exist) && (coex_sta->hid_busy_num < 2))
3365 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14);
3366 			else
3367 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
3368 		} else if (bt_link_info->hid_exist) {
3369 			if (coex_sta->hid_busy_num < 2)
3370 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3371 			else
3372 				halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
3373 		} else if (wifi_turbo)
3374 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3375 		else
3376 			halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3377 
3378 		if (!wifi_busy)
3379 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 4);
3380 		else
3381 			halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 3);
3382 	} else {
3383 		/* BT no-profile busy (0x9) */
3384 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3385 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, TRUE, 33);
3386 	}
3387 
3388 }
3389 
halbtc8821c1ant_action_wifi_not_connected(IN struct btc_coexist * btcoexist)3390 void halbtc8821c1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
3391 {
3392 	/* tdma and coex table */
3393 	halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3394 	halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, FALSE, 8);
3395 }
3396 
halbtc8821c1ant_action_wifi_connected(IN struct btc_coexist * btcoexist)3397 void halbtc8821c1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
3398 {
3399 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3400 	boolean	wifi_busy = FALSE;
3401 	boolean	wifi_under_5g = FALSE;
3402 
3403 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3404 		"[BTCoex], CoexForWifiConnect()===>\n");
3405 	BTC_TRACE(trace_buf);
3406 
3407 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3408 
3409 	if (wifi_under_5g) {
3410 
3411 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3412 			    "[BTCoex], WiFi is under 5G!!!\n");
3413 		BTC_TRACE(trace_buf);
3414 
3415 		halbtc8821c1ant_action_wifi_under5g(btcoexist);
3416 		return;
3417 	}
3418 
3419 	halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3420 				     NORMAL_EXEC,
3421 				     BT_8821C_1ANT_PHASE_2G_RUNTIME);
3422 
3423 	if ((coex_dm->bt_status == BT_8821C_1ANT_BT_STATUS_ACL_BUSY) ||
3424 		(coex_dm->bt_status == BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY)) {
3425 
3426 		if (bt_link_info->hid_only)  /* HID only */
3427 			halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist);
3428 		else
3429 			halbtc8821c1ant_action_wifi_connected_bt_acl_busy(btcoexist);
3430 
3431 	} else if (coex_dm->bt_status == BT_8821C_1ANT_BT_STATUS_SCO_BUSY)
3432 		halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist);
3433 	else
3434 		halbtc8821c1ant_action_bt_idle(btcoexist);
3435 
3436 }
3437 
halbtc8821c1ant_run_sw_coexist_mechanism(IN struct btc_coexist * btcoexist)3438 void halbtc8821c1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
3439 {
3440 	u8				algorithm = 0;
3441 
3442 	algorithm = halbtc8821c1ant_action_algorithm(btcoexist);
3443 	coex_dm->cur_algorithm = algorithm;
3444 
3445 	if (!halbtc8821c1ant_is_common_action(btcoexist)) {
3446 		switch (coex_dm->cur_algorithm) {
3447 		case BT_8821C_1ANT_COEX_ALGO_SCO:
3448 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3449 				    "[BTCoex], Action algorithm = SCO.\n");
3450 			BTC_TRACE(trace_buf);
3451 			break;
3452 		case BT_8821C_1ANT_COEX_ALGO_HID:
3453 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3454 				    "[BTCoex], Action algorithm = HID.\n");
3455 			BTC_TRACE(trace_buf);
3456 			break;
3457 		case BT_8821C_1ANT_COEX_ALGO_A2DP:
3458 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3459 				    "[BTCoex], Action algorithm = A2DP.\n");
3460 			BTC_TRACE(trace_buf);
3461 			break;
3462 		case BT_8821C_1ANT_COEX_ALGO_A2DP_PANHS:
3463 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3464 				"[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
3465 			BTC_TRACE(trace_buf);
3466 			break;
3467 		case BT_8821C_1ANT_COEX_ALGO_PANEDR:
3468 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3469 				    "[BTCoex], Action algorithm = PAN(EDR).\n");
3470 			BTC_TRACE(trace_buf);
3471 			break;
3472 		case BT_8821C_1ANT_COEX_ALGO_PANHS:
3473 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3474 				    "[BTCoex], Action algorithm = HS mode.\n");
3475 			BTC_TRACE(trace_buf);
3476 			break;
3477 		case BT_8821C_1ANT_COEX_ALGO_PANEDR_A2DP:
3478 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3479 				    "[BTCoex], Action algorithm = PAN+A2DP.\n");
3480 			BTC_TRACE(trace_buf);
3481 			break;
3482 		case BT_8821C_1ANT_COEX_ALGO_PANEDR_HID:
3483 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3484 				"[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
3485 			BTC_TRACE(trace_buf);
3486 			break;
3487 		case BT_8821C_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
3488 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3489 				"[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
3490 			BTC_TRACE(trace_buf);
3491 			break;
3492 		case BT_8821C_1ANT_COEX_ALGO_HID_A2DP:
3493 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3494 				    "[BTCoex], Action algorithm = HID+A2DP.\n");
3495 			BTC_TRACE(trace_buf);
3496 			break;
3497 		default:
3498 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3499 				"[BTCoex], Action algorithm = coexist All Off!!\n");
3500 			BTC_TRACE(trace_buf);
3501 			break;
3502 		}
3503 		coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3504 	}
3505 }
3506 
3507 
halbtc8821c1ant_run_coexist_mechanism(IN struct btc_coexist * btcoexist)3508 void halbtc8821c1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
3509 {
3510 	struct  btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3511 	boolean	wifi_connected = FALSE, bt_hs_on = FALSE;
3512 	boolean	increase_scan_dev_num = FALSE;
3513 	boolean	bt_ctrl_agg_buf_size = FALSE;
3514 	boolean	miracast_plus_bt = FALSE, wifi_under_5g = FALSE;
3515 	u8	agg_buf_size = 5;
3516 	u32	wifi_link_status = 0;
3517 	u32	num_of_wifi_link = 0, wifi_bw;
3518 	u8	iot_peer = BTC_IOT_PEER_UNKNOWN;
3519 	boolean	scan = FALSE, link = FALSE, roam = FALSE, under_4way = FALSE;
3520 
3521 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3522 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3523 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3524 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &under_4way);
3525 
3526 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3527 		    "[BTCoex], RunCoexistMechanism()===>\n");
3528 	BTC_TRACE(trace_buf);
3529 
3530 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3531 			"[BTCoex], under_lps = %d, force_lps_ctrl = %d, acl_busy = %d!!!\n",
3532 			coex_sta->under_lps, coex_sta->force_lps_ctrl, coex_sta->acl_busy);
3533 	BTC_TRACE(trace_buf);
3534 
3535 	if (btcoexist->manual_control) {
3536 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3537 			"[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
3538 		BTC_TRACE(trace_buf);
3539 		return;
3540 	}
3541 
3542 	if (btcoexist->stop_coex_dm) {
3543 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3544 			"[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
3545 		BTC_TRACE(trace_buf);
3546 		return;
3547 	}
3548 
3549 	if (coex_sta->under_ips) {
3550 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3551 			    "[BTCoex], RunCoexistMechanism(), wifi is under IPS !!!\n");
3552 		BTC_TRACE(trace_buf);
3553 		return;
3554 	}
3555 
3556 	if (!coex_sta->run_time_state) {
3557 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3558 			"[BTCoex], return for run_time_state = FALSE !!!\n");
3559 		BTC_TRACE(trace_buf);
3560 		return;
3561 	}
3562 
3563 	if (coex_sta->freeze_coexrun_by_btinfo) {
3564 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3565 			"[BTCoex], BtInfoNotify(), return for freeze_coexrun_by_btinfo\n");
3566 		BTC_TRACE(trace_buf);
3567 		return;
3568 	}
3569 
3570 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3571 
3572 	if ((wifi_under_5g) &&
3573 		(coex_sta->switch_band_notify_to != BTC_SWITCH_TO_24G) &&
3574 		(coex_sta->switch_band_notify_to != BTC_SWITCH_TO_24G_NOFORSCAN)) {
3575 
3576 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3577 			    "[BTCoex], WiFi is under 5G!!!\n");
3578 		BTC_TRACE(trace_buf);
3579 
3580 		halbtc8821c1ant_action_wifi_under5g(btcoexist);
3581 		return;
3582 	} else {
3583 
3584 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3585 			    "[BTCoex], WiFi is under 2G!!!\n");
3586 		BTC_TRACE(trace_buf);
3587 
3588 		halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3589 					     NORMAL_EXEC,
3590 					     BT_8821C_1ANT_PHASE_2G_RUNTIME);
3591 	}
3592 
3593 	if ((coex_sta->under_lps) && (!coex_sta->force_lps_ctrl) &&
3594 		(!coex_sta->acl_busy)) {
3595 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3596 			    "[BTCoex], RunCoexistMechanism(), wifi is under LPS !!!\n");
3597 		BTC_TRACE(trace_buf);
3598 		halbtc8821c1ant_action_wifi_native_lps(btcoexist);
3599 		return;
3600 	}
3601 
3602 	if (coex_sta->bt_whck_test) {
3603 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3604 			    "[BTCoex], BT is under WHCK TEST!!!\n");
3605 		BTC_TRACE(trace_buf);
3606 		halbtc8821c1ant_action_bt_whql_test(btcoexist);
3607 		return;
3608 	}
3609 
3610 	if (coex_sta->bt_disabled) {
3611 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3612 			    "[BTCoex], BT is disabled !!!\n");
3613 		BTC_TRACE(trace_buf);
3614 		halbtc8821c1ant_action_wifi_only(btcoexist);
3615 		return;
3616 	}
3617 
3618 	if (coex_sta->c2h_bt_inquiry_page) {
3619 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3620 			    "[BTCoex], BT is under inquiry/page scan !!\n");
3621 		BTC_TRACE(trace_buf);
3622 		halbtc8821c1ant_action_bt_inquiry(btcoexist);
3623 		return;
3624 	}
3625 
3626 	if ((coex_sta->is_setupLink) &&
3627 			(coex_sta->bt_relink_downcount != 0)) {
3628 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3629 			    "[BTCoex], BT is re-link !!!\n");
3630 		BTC_TRACE(trace_buf);
3631 		halbtc8821c1ant_action_bt_relink(btcoexist);
3632 		return;
3633 	}
3634 
3635 	if ((BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
3636 	    (BT_8821C_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3637 	    (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
3638 		increase_scan_dev_num = TRUE;
3639 
3640 	btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
3641 			   &increase_scan_dev_num);
3642 
3643 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3644 			   &wifi_link_status);
3645 
3646 	num_of_wifi_link = wifi_link_status >> 16;
3647 
3648 	if ((num_of_wifi_link >= 2) ||
3649 	    (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
3650 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3651 			"############# [BTCoex],  Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
3652 			    num_of_wifi_link, wifi_link_status);
3653 		BTC_TRACE(trace_buf);
3654 
3655 		if (bt_link_info->bt_link_exist)
3656 			miracast_plus_bt = TRUE;
3657 		else
3658 			miracast_plus_bt = FALSE;
3659 
3660 		btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3661 				   &miracast_plus_bt);
3662 
3663 		if (scan || link || roam || under_4way) {
3664 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3665 				"[BTCoex], scan = %d, link = %d, roam = %d 4way = %d!!!\n",
3666 				    scan, link, roam, under_4way);
3667 			BTC_TRACE(trace_buf);
3668 
3669 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3670 				"[BTCoex], wifi is under linkscan process + Multi-Port !!\n");
3671 			BTC_TRACE(trace_buf);
3672 
3673 			halbtc8821c1ant_action_wifi_linkscan_process(btcoexist);
3674 		} else
3675 			halbtc8821c1ant_action_wifi_multi_port(btcoexist);
3676 
3677 		return;
3678 	} else {
3679 
3680 		miracast_plus_bt = FALSE;
3681 		btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3682 				   &miracast_plus_bt);
3683 	}
3684 
3685 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3686 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
3687 
3688 	if ((bt_link_info->bt_link_exist) && (wifi_connected)) {
3689 
3690 		btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer);
3691 
3692 		if (BTC_IOT_PEER_CISCO == iot_peer) {
3693 
3694 			if (BTC_WIFI_BW_HT40 == wifi_bw)
3695 				halbtc8821c1ant_limited_rx(btcoexist,
3696 					   NORMAL_EXEC, FALSE, TRUE, 0x10);
3697 			else
3698 				halbtc8821c1ant_limited_rx(btcoexist,
3699 					   NORMAL_EXEC, FALSE, TRUE, 0x8);
3700 		}
3701 	}
3702 
3703 	/* just print debug message */
3704 	halbtc8821c1ant_run_sw_coexist_mechanism(btcoexist);
3705 
3706 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3707 
3708 	if (bt_hs_on) {
3709 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3710 			    "############# [BTCoex],  BT Is hs\n");
3711 		BTC_TRACE(trace_buf);
3712 		halbtc8821c1ant_action_bt_hs(btcoexist);
3713 		return;
3714 	}
3715 
3716 	if ((BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
3717 	     coex_dm->bt_status) ||
3718 	    (BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE ==
3719 	     coex_dm->bt_status)) {
3720 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3721 			    "############# [BTCoex],  BT Is idle\n");
3722 		BTC_TRACE(trace_buf);
3723 		halbtc8821c1ant_action_bt_idle(btcoexist);
3724 		return;
3725 	}
3726 
3727 	if (scan || link || roam || under_4way) {
3728 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3729 			"[BTCoex], scan = %d, link = %d, roam = %d 4way = %d!!!\n",
3730 			    scan, link, roam, under_4way);
3731 		BTC_TRACE(trace_buf);
3732 
3733 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3734 			    "[BTCoex], wifi is under linkscan process!!\n");
3735 		BTC_TRACE(trace_buf);
3736 
3737 		halbtc8821c1ant_action_wifi_linkscan_process(btcoexist);
3738 	} else if (wifi_connected) {
3739 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3740 			    "[BTCoex], wifi is under connected!!\n");
3741 		BTC_TRACE(trace_buf);
3742 
3743 		halbtc8821c1ant_action_wifi_connected(btcoexist);
3744 	} else {
3745 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3746 			    "[BTCoex], wifi is under not-connected!!\n");
3747 		BTC_TRACE(trace_buf);
3748 
3749 		halbtc8821c1ant_action_wifi_not_connected(btcoexist);
3750 	}
3751 }
3752 
halbtc8821c1ant_init_coex_dm(IN struct btc_coexist * btcoexist)3753 void halbtc8821c1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
3754 {
3755 	/* force to reset coex mechanism */
3756 	halbtc8821c1ant_low_penalty_ra(btcoexist, FORCE_EXEC, FALSE);
3757 
3758 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3759 		    "[BTCoex], Coex Mechanism Init!!\n");
3760 	BTC_TRACE(trace_buf);
3761 
3762 	coex_sta->pop_event_cnt = 0;
3763 	coex_sta->cnt_RemoteNameReq = 0;
3764 	coex_sta->cnt_ReInit = 0;
3765 	coex_sta->cnt_setupLink = 0;
3766 	coex_sta->cnt_IgnWlanAct = 0;
3767 	coex_sta->cnt_Page = 0;
3768 	coex_sta->cnt_RoleSwitch = 0;
3769 	coex_sta->switch_band_notify_to = BTC_NOT_SWITCH;
3770 
3771 	halbtc8821c1ant_query_bt_info(btcoexist);
3772 }
3773 
halbtc8821c1ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean back_up,IN boolean wifi_only)3774 void halbtc8821c1ant_init_hw_config(IN struct btc_coexist *btcoexist,
3775 				    IN boolean back_up, IN boolean wifi_only)
3776 {
3777 	u32			u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
3778 	u16			u16tmp1 = 0;
3779 	u8			i;
3780 	struct  btc_board_info *board_info = &btcoexist->board_info;
3781 
3782 
3783 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3784 		    "[BTCoex], 1Ant Init HW Config!!\n");
3785 	BTC_TRACE(trace_buf);
3786 
3787 	u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
3788 	u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
3789 	u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
3790 
3791 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3792 		"[BTCoex],(Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
3793 		    u32tmp3, u32tmp1, u32tmp2);
3794 	BTC_TRACE(trace_buf);
3795 
3796 
3797 	coex_sta->bt_coex_supported_feature = 0;
3798 	coex_sta->bt_coex_supported_version = 0;
3799 	coex_sta->bt_ble_scan_type = 0;
3800 	coex_sta->bt_ble_scan_para[0] = 0;
3801 	coex_sta->bt_ble_scan_para[1] = 0;
3802 	coex_sta->bt_ble_scan_para[2] = 0;
3803 	coex_sta->bt_reg_vendor_ac = 0xffff;
3804 	coex_sta->bt_reg_vendor_ae = 0xffff;
3805 	coex_sta->isolation_btween_wb = BT_8821C_1ANT_DEFAULT_ISOLATION;
3806 	coex_sta->gnt_error_cnt = 0;
3807 	coex_sta->bt_relink_downcount = 0;
3808 	coex_sta->is_set_ps_state_fail = FALSE;
3809 	coex_sta->cnt_set_ps_state_fail = 0;
3810 	coex_sta->wl_rx_rate = BTC_UNKNOWN;
3811 	coex_sta->wl_rts_rx_rate = BTC_UNKNOWN;
3812 	coex_sta->wl_center_channel = 0;
3813 
3814 	for (i = 0; i <= 9; i++)
3815 		coex_sta->bt_afh_map[i] = 0;
3816 
3817 	/* Setup RF front end type */
3818 	halbtc8821c1ant_set_rfe_type(btcoexist);
3819 
3820 	/* 0xf0[15:12] --> Chip Cut information */
3821 	coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
3822 				 0xf1) & 0xf0) >> 4;
3823 
3824 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
3825 					   0x1);  /* enable TBTT nterrupt */
3826 
3827 	/* BT report packet sample rate	 */
3828 	btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5);
3829 
3830 	/* Init 0x778 = 0x1 for 1-Ant */
3831 	btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
3832 
3833 	/* Enable PTA (3-wire function form BT side) */
3834 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
3835 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1);
3836 
3837 	/* Enable PTA (tx/rx signal form WiFi side) */
3838 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1);
3839 
3840 	/* set GNT_BT=1 for coex table select both */
3841 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0x763, 0x10, 0x1);
3842 
3843 	halbtc8821c1ant_enable_gnt_to_gpio(btcoexist, TRUE);
3844 
3845 #if 0
3846 	/* check if WL firmware download ok */
3847 	/*if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6)*/
3848 	 halbtc8821c1ant_post_state_to_bt(btcoexist,
3849 					BT_8821C_1ANT_SCOREBOARD_ONOFF, TRUE);
3850 #endif
3851 
3852 	/* PTA parameter */
3853 	halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
3854 	halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, FALSE, 8);
3855 
3856 	psd_scan->ant_det_is_ant_det_available = TRUE;
3857 
3858 	/* Antenna config */
3859 	if (coex_sta->is_rf_state_off) {
3860 
3861 		halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3862 					     FORCE_EXEC,
3863 					     BT_8821C_1ANT_PHASE_WLAN_OFF);
3864 
3865 		btcoexist->stop_coex_dm = TRUE;
3866 
3867 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3868 			"[BTCoex], **********  halbtc8821c1ant_init_hw_config (RF Off)**********\n");
3869 		BTC_TRACE(trace_buf);
3870 	} else if (wifi_only) {
3871 		coex_sta->concurrent_rx_mode_on = FALSE;
3872 		halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI,
3873 					     FORCE_EXEC,
3874 					     BT_8821C_1ANT_PHASE_WLANONLY_INIT);
3875 
3876 		btcoexist->stop_coex_dm = TRUE;
3877 	} else {
3878 		/*Set BT polluted packet on for Tx rate adaptive not including Tx retry break by PTA, 0x45c[19] =1 */
3879 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
3880 
3881 		coex_sta->concurrent_rx_mode_on = TRUE;
3882 		btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0x2, 0x0);
3883 
3884 		halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3885 					     FORCE_EXEC,
3886 					     BT_8821C_1ANT_PHASE_COEX_INIT);
3887 
3888 		btcoexist->stop_coex_dm = FALSE;
3889 	}
3890 
3891 	u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
3892 	u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
3893 	u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
3894 
3895 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3896 		"[BTCoex], (After Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
3897 		    u32tmp3, u32tmp1, u32tmp2);
3898 	BTC_TRACE(trace_buf);
3899 
3900 }
3901 
3902 
3903 /* ************************************************************
3904  * work around function start with wa_halbtc8821c1ant_
3905  * ************************************************************
3906  * ************************************************************
3907  * extern function start with ex_halbtc8821c1ant_
3908  * ************************************************************ */
ex_halbtc8821c1ant_power_on_setting(IN struct btc_coexist * btcoexist)3909 void ex_halbtc8821c1ant_power_on_setting(IN struct btc_coexist *btcoexist)
3910 {
3911 	struct  btc_board_info	*board_info = &btcoexist->board_info;
3912 	u8 u8tmp = 0x0;
3913 	u16 u16tmp = 0x0;
3914 	u32	value = 0;
3915 
3916 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3917 		"xxxxxxxxxxxxxxxx Execute 8821c 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n");
3918 	BTC_TRACE(trace_buf);
3919 
3920 
3921 	btcoexist->stop_coex_dm = TRUE;
3922 	coex_sta->is_rf_state_off = FALSE;
3923 	psd_scan->ant_det_is_ant_det_available = FALSE;
3924 
3925 	/* enable BB, REG_SYS_FUNC_EN such that we can write BB Register correctly. */
3926 	u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
3927 	btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
3928 
3929 	/* Local setting bit define */
3930 	/*	BIT0: "0" for no antenna inverse; "1" for antenna inverse  */
3931 	/*	BIT1: "0" for internal switch; "1" for external switch */
3932 	/*	BIT2: "0" for one antenna; "1" for two antenna */
3933 	/* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */
3934 
3935 	/* Set Antenna Path to BT side */
3936 	/* Check efuse 0xc3[6] for Single Antenna Path */
3937 	if (board_info->single_ant_path == 0) {
3938 
3939 		board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
3940 		u8tmp = 1;
3941 	} else if (board_info->single_ant_path == 1) {
3942 
3943 		board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
3944 		u8tmp = 0;
3945 	}
3946 
3947 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3948 		"[BTCoex], ********** (Power On) single_ant_path  = %d, btdm_ant_pos = %d\n",
3949 		    board_info->single_ant_path , board_info->btdm_ant_pos);
3950 	BTC_TRACE(trace_buf);
3951 
3952 	/* Setup RF front end type */
3953 	halbtc8821c1ant_set_rfe_type(btcoexist);
3954 
3955 	/* Set Antenna Path to BT side */
3956 	halbtc8821c1ant_set_ant_path(btcoexist,
3957 				     BTC_ANT_PATH_AUTO,
3958 				     FORCE_EXEC,
3959 				     BT_8821C_1ANT_PHASE_COEX_POWERON);
3960 
3961 	/* Save"single antenna position" info in Local register setting for FW reading, because FW may not ready at  power on */
3962 	if (btcoexist->chip_interface == BTC_INTF_PCI)
3963 		btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, u8tmp);
3964 	else if (btcoexist->chip_interface == BTC_INTF_USB)
3965 		btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
3966 	else if (btcoexist->chip_interface == BTC_INTF_SDIO)
3967 		btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp);
3968 
3969 	/* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */
3970 	halbtc8821c1ant_enable_gnt_to_gpio(btcoexist, TRUE);
3971 
3972 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3973 		"[BTCoex], **********  LTE coex Reg 0x38 (Power-On) = 0x%x\n",
3974 		    halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38));
3975 	BTC_TRACE(trace_buf);
3976 
3977 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3978 		"[BTCoex], **********  MAC Reg 0x70/ BB Reg 0xcb4 (Power-On) = 0x%x / 0x%x\n",
3979 		    btcoexist->btc_read_4byte(btcoexist, 0x70),
3980 		    btcoexist->btc_read_4byte(btcoexist, 0xcb4));
3981 	BTC_TRACE(trace_buf);
3982 
3983 }
3984 
ex_halbtc8821c1ant_pre_load_firmware(IN struct btc_coexist * btcoexist)3985 void ex_halbtc8821c1ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
3986 {
3987 }
3988 
ex_halbtc8821c1ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean wifi_only)3989 void ex_halbtc8821c1ant_init_hw_config(IN struct btc_coexist *btcoexist,
3990 				       IN boolean wifi_only)
3991 {
3992 	halbtc8821c1ant_init_hw_config(btcoexist, TRUE, wifi_only);
3993 }
3994 
ex_halbtc8821c1ant_init_coex_dm(IN struct btc_coexist * btcoexist)3995 void ex_halbtc8821c1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
3996 {
3997 	halbtc8821c1ant_init_coex_dm(btcoexist);
3998 }
3999 
ex_halbtc8821c1ant_display_simple_coex_info(IN struct btc_coexist * btcoexist)4000 void ex_halbtc8821c1ant_display_simple_coex_info(IN struct btc_coexist *btcoexist)
4001 {
4002 	struct  btc_board_info		*board_info = &btcoexist->board_info;
4003 	struct  btc_bt_link_info	*bt_link_info = &btcoexist->bt_link_info;
4004 
4005 	u8		*cli_buf = btcoexist->cli_buf;
4006 	u32		bt_patch_ver = 0, bt_coex_ver = 0;
4007 	static u8	cnt = 0;
4008 
4009 
4010 	if (!coex_sta->bt_disabled) {
4011 		if (coex_sta->bt_coex_supported_feature == 0)
4012 			btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE,
4013 						&coex_sta->bt_coex_supported_feature);
4014 
4015 		if ((coex_sta->bt_coex_supported_version == 0) ||
4016 			(coex_sta->bt_coex_supported_version == 0xffff))
4017 			btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION,
4018 						&coex_sta->bt_coex_supported_version);
4019 
4020 		if (coex_sta->bt_reg_vendor_ac == 0xffff)
4021 			coex_sta->bt_reg_vendor_ac = (u16)(
4022 					btcoexist->btc_get_bt_reg(btcoexist, 3,
4023 					0xac) & 0xffff);
4024 
4025 		if (coex_sta->bt_reg_vendor_ae == 0xffff)
4026 			coex_sta->bt_reg_vendor_ae = (u16)(
4027 					btcoexist->btc_get_bt_reg(btcoexist, 3,
4028 					0xae) & 0xffff);
4029 
4030 		btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
4031 						&bt_patch_ver);
4032 		btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
4033 
4034 		if (coex_sta->num_of_profile > 0) {
4035 			cnt++;
4036 
4037 			if (cnt >= 3) {
4038 				btcoexist->btc_get_bt_afh_map_from_bt(btcoexist, 0,
4039 					&coex_sta->bt_afh_map[0]);
4040 				cnt = 0;
4041 			}
4042 		}
4043 	}
4044 
4045 	// BT coex. info.
4046 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4047 			   "\r\n _____[BT Coexist info]____");
4048 	CL_PRINTF(cli_buf);
4049 
4050 	if (btcoexist->manual_control) {
4051 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4052 			"\r\n __[Under Manual Control]_");
4053 	CL_PRINTF(cli_buf);
4054 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4055 			"\r\n _________________________");
4056 		CL_PRINTF(cli_buf);
4057 	}
4058 	if (btcoexist->stop_coex_dm) {
4059 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4060 			   "\r\n ____[Coex is STOPPED]____");
4061 		CL_PRINTF(cli_buf);
4062 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4063 			   "\r\n _________________________");
4064 		CL_PRINTF(cli_buf);
4065 	}
4066 
4067 	if (psd_scan->ant_det_try_count == 0) {
4068 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4069 			   "\r\n %-35s = %d/ %d/ %s / 0x%x",
4070 			   "Ant PG Num/ Mech/ Pos/ RFE",
4071 			   board_info->pg_ant_num, board_info->btdm_ant_num,
4072 			   (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4073 			    ? "Main" : "Aux"),
4074 			   board_info->rfe_type);
4075 		CL_PRINTF(cli_buf);
4076 	} else {
4077 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4078 			   "\r\n %-35s = %d/ %d/ %s/ 0x%x  (%d/%d/%d)",
4079 			   "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
4080 			   board_info->pg_ant_num,
4081 			   board_info->btdm_ant_num_by_ant_det,
4082 			   (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4083 			    ? "Main" : "Aux"),
4084 			   board_info->rfe_type,
4085 			   psd_scan->ant_det_try_count,
4086 			   psd_scan->ant_det_fail_count,
4087 			   psd_scan->ant_det_result);
4088 		CL_PRINTF(cli_buf);
4089 
4090 		if (board_info->btdm_ant_det_finish) {
4091 
4092 			if (psd_scan->ant_det_result != 12)
4093 				CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4094 					   "\r\n %-35s = %s",
4095 					   "Ant Det PSD Value",
4096 					   psd_scan->ant_det_peak_val);
4097 			else
4098 				CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4099 					   "\r\n %-35s = %d",
4100 					   "Ant Det PSD Value",
4101 					   psd_scan->ant_det_psd_scan_peak_val
4102 					   / 100);
4103 			CL_PRINTF(cli_buf);
4104 		}
4105 	}
4106 
4107 	bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8);
4108 
4109 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4110 			"\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
4111 			"CoexVer WL/  BT_Desired/ BT_Report",
4112 			glcoex_ver_date_8821c_1ant, glcoex_ver_8821c_1ant,
4113 			glcoex_ver_btdesired_8821c_1ant,
4114 			bt_coex_ver,
4115 			(bt_coex_ver == 0xff ? "Unknown" :
4116 			(coex_sta->bt_disabled ? "BT-disable" :
4117 			(bt_coex_ver >= glcoex_ver_btdesired_8821c_1ant ?
4118 			"Match" : "Mis-Match"))));
4119 	CL_PRINTF(cli_buf);
4120 
4121 	// BT Status
4122 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s ", "BT status",
4123 			((coex_sta->bt_disabled) ? ("disabled") :	((
4124 			coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page")
4125 			: ((BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
4126 			coex_dm->bt_status) ? "non-connected idle" :
4127 			((BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE ==
4128 			coex_dm->bt_status) ? "connected-idle" : "busy")))));
4129 	CL_PRINTF(cli_buf);
4130 
4131 	// HW settings
4132 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4133 			   "0x770(Hi-pri rx/tx)",
4134 			   coex_sta->high_priority_rx, coex_sta->high_priority_tx);
4135 	CL_PRINTF(cli_buf);
4136 
4137 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s",
4138 			   "0x774(Lo-pri rx/tx)",
4139 			   coex_sta->low_priority_rx, coex_sta->low_priority_tx,
4140 			   (bt_link_info->slave_role ? "(Slave!!)" : (
4141 			   coex_sta->is_tdma_btautoslot_hang ? "(auto-slot hang!!)" : "")));
4142 	CL_PRINTF(cli_buf);
4143 
4144 }
4145 
ex_halbtc8821c1ant_display_coex_info(IN struct btc_coexist * btcoexist)4146 void ex_halbtc8821c1ant_display_coex_info(IN struct btc_coexist *btcoexist)
4147 {
4148 	struct  btc_board_info		*board_info = &btcoexist->board_info;
4149 	struct  btc_stack_info		*stack_info = &btcoexist->stack_info;
4150 	struct  btc_bt_link_info	*bt_link_info = &btcoexist->bt_link_info;
4151 
4152 	u8				*cli_buf = btcoexist->cli_buf;
4153 	u8				u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
4154 	u16				u16tmp[4];
4155 	u32				u32tmp[4];
4156 	u32				fa_ofdm, fa_cck, cca_ofdm, cca_cck;
4157 	u32				fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0;
4158 	static u8			pop_report_in_10s = 0;
4159 	u32			phyver = 0;
4160 	boolean			lte_coex_on = FALSE;
4161 	static u8 cnt = 0;
4162 
4163 
4164 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4165 		   "\r\n ============[BT Coexist info]============");
4166 	CL_PRINTF(cli_buf);
4167 
4168 	if (btcoexist->manual_control) {
4169 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4170 			"\r\n ============[Under Manual Control]============");
4171 		CL_PRINTF(cli_buf);
4172 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4173 			   "\r\n ==========================================");
4174 		CL_PRINTF(cli_buf);
4175 	}
4176 	if (btcoexist->stop_coex_dm) {
4177 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4178 			   "\r\n ============[Coex is STOPPED]============");
4179 		CL_PRINTF(cli_buf);
4180 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4181 			   "\r\n ==========================================");
4182 		CL_PRINTF(cli_buf);
4183 	}
4184 
4185 	if (!coex_sta->bt_disabled) {
4186 		if (coex_sta->bt_coex_supported_feature == 0)
4187 			btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE,
4188 						&coex_sta->bt_coex_supported_feature);
4189 
4190 		if ((coex_sta->bt_coex_supported_version == 0) ||
4191 			(coex_sta->bt_coex_supported_version == 0xffff))
4192 			btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION,
4193 						&coex_sta->bt_coex_supported_version);
4194 
4195 		if (coex_sta->bt_reg_vendor_ac == 0xffff)
4196 			coex_sta->bt_reg_vendor_ac = (u16)(
4197 					btcoexist->btc_get_bt_reg(btcoexist, 3,
4198 					0xac) & 0xffff);
4199 
4200 		if (coex_sta->bt_reg_vendor_ae == 0xffff)
4201 			coex_sta->bt_reg_vendor_ae = (u16)(
4202 					btcoexist->btc_get_bt_reg(btcoexist, 3,
4203 					0xae) & 0xffff);
4204 
4205 		btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
4206 						&bt_patch_ver);
4207 		btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
4208 
4209 		if (coex_sta->num_of_profile > 0) {
4210 			cnt++;
4211 
4212 			if (cnt >= 3) {
4213 				btcoexist->btc_get_bt_afh_map_from_bt(btcoexist, 0,
4214 					&coex_sta->bt_afh_map[0]);
4215 				cnt = 0;
4216 			}
4217 		}
4218 	}
4219 
4220 	if (psd_scan->ant_det_try_count == 0) {
4221 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4222 			   "\r\n %-35s = %d/ %d/ %s / 0x%x",
4223 			   "Ant PG Num/ Mech/ Pos/ RFE",
4224 			   board_info->pg_ant_num, board_info->btdm_ant_num,
4225 			   (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4226 			    ? "Main" : "Aux"),
4227 			   board_info->rfe_type);
4228 		CL_PRINTF(cli_buf);
4229 	} else {
4230 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4231 			   "\r\n %-35s = %d/ %d/ %s/ 0x%x  (%d/%d/%d)",
4232 			   "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
4233 			   board_info->pg_ant_num,
4234 			   board_info->btdm_ant_num_by_ant_det,
4235 			   (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4236 			    ? "Main" : "Aux"),
4237 			   board_info->rfe_type,
4238 			   psd_scan->ant_det_try_count,
4239 			   psd_scan->ant_det_fail_count,
4240 			   psd_scan->ant_det_result);
4241 		CL_PRINTF(cli_buf);
4242 
4243 		if (board_info->btdm_ant_det_finish) {
4244 
4245 			if (psd_scan->ant_det_result != 12)
4246 				CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4247 					   "\r\n %-35s = %s",
4248 					   "Ant Det PSD Value",
4249 					   psd_scan->ant_det_peak_val);
4250 			else
4251 				CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4252 					   "\r\n %-35s = %d",
4253 					   "Ant Det PSD Value",
4254 					   psd_scan->ant_det_psd_scan_peak_val
4255 					   / 100);
4256 			CL_PRINTF(cli_buf);
4257 		}
4258 	}
4259 
4260 	bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
4261 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
4262 	phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
4263 
4264 	bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8);
4265 
4266 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4267 		   "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
4268 		   "CoexVer WL/  BT_Desired/ BT_Report",
4269 		   glcoex_ver_date_8821c_1ant, glcoex_ver_8821c_1ant,
4270 		   glcoex_ver_btdesired_8821c_1ant,
4271 		   bt_coex_ver,
4272 		   (bt_coex_ver == 0xff ? "Unknown" :
4273 		    (coex_sta->bt_disabled ? "BT-disable" :
4274 		     (bt_coex_ver >= glcoex_ver_btdesired_8821c_1ant ?
4275 		      "Match" : "Mis-Match"))));
4276 	CL_PRINTF(cli_buf);
4277 
4278 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4279 		   "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c",
4280 		   "W_FW/ B_FW/ Phy/ Kt",
4281 		   fw_ver, bt_patch_ver, phyver,
4282 		   coex_sta->cut_version + 65);
4283 	CL_PRINTF(cli_buf);
4284 
4285 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x (RF-Ch = %d)",
4286 		   "AFH Map to BT",
4287 		   coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
4288 		   coex_dm->wifi_chnl_info[2], coex_sta->wl_center_channel);
4289 	CL_PRINTF(cli_buf);
4290 
4291 	/* wifi status */
4292 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4293 		   "============[Wifi Status]============");
4294 	CL_PRINTF(cli_buf);
4295 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
4296 
4297 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4298 		   "============[BT Status]============");
4299 	CL_PRINTF(cli_buf);
4300 
4301 	pop_report_in_10s++;
4302 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4303 		   "\r\n %-35s = [%s/ %d dBm/ %d/ %d] ",
4304 		   "BT [status/ rssi/ retryCnt/ popCnt]",
4305 		   ((coex_sta->bt_disabled) ? ("disabled") :	((
4306 			   coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page")
4307 			   : ((BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
4308 			       coex_dm->bt_status) ? "non-connected idle" :
4309 		((BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
4310 				       ? "connected-idle" : "busy")))),
4311 		   coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
4312 		   coex_sta->pop_event_cnt);
4313 	CL_PRINTF(cli_buf);
4314 
4315 	if (pop_report_in_10s >= 5) {
4316 		coex_sta->pop_event_cnt = 0;
4317 		pop_report_in_10s = 0;
4318 	}
4319 
4320 	if (coex_sta->num_of_profile != 0)
4321 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4322 			   "\r\n %-35s = %s%s%s%s%s",
4323 			   "Profiles",
4324 			   ((bt_link_info->a2dp_exist) ?
4325 			   ((coex_sta->is_bt_a2dp_sink) ? "A2DP sink," :
4326 			    "A2DP,") : ""),
4327 			   ((bt_link_info->sco_exist) ?  "HFP," : ""),
4328 			   ((bt_link_info->hid_exist) ?
4329 			    ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," :
4330 			     "HID(2/18),") : ""),
4331 			   ((bt_link_info->pan_exist) ?  "PAN," : ""),
4332 			   ((coex_sta->voice_over_HOGP) ? "Voice" : ""));
4333 	else
4334 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4335 			   "\r\n %-35s = None", "Profiles");
4336 
4337 	CL_PRINTF(cli_buf);
4338 
4339 	if (bt_link_info->a2dp_exist) {
4340 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s",
4341 			   "A2DP Rate/Bitpool/Auto_Slot",
4342 			   ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"),
4343 			   coex_sta->a2dp_bit_pool,
4344 			   ((coex_sta->is_autoslot) ? "On" : "Off")
4345 			  );
4346 		CL_PRINTF(cli_buf);
4347 	}
4348 
4349 	if (bt_link_info->hid_exist) {
4350 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4351 			   "HID PairNum/Forbid_Slot",
4352 			   coex_sta->hid_pair_cnt,
4353 			   coex_sta->forbidden_slot
4354 			  );
4355 		CL_PRINTF(cli_buf);
4356 	}
4357 
4358 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s/ 0x%x",
4359 				"Role/RoleSwCnt/IgnWlact/Feature",
4360 				((bt_link_info->slave_role) ? "Slave" : "Master"),
4361 				coex_sta->cnt_RoleSwitch,
4362 				((coex_dm->cur_ignore_wlan_act) ? "Yes" : "No"),
4363 				coex_sta->bt_coex_supported_feature);
4364 	CL_PRINTF(cli_buf);
4365 
4366 	if ((coex_sta->bt_ble_scan_type & 0x7) != 0x0) {
4367 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4368 			"\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4369 			"BLEScan Type/TV/Init/Ble",
4370 			coex_sta->bt_ble_scan_type,
4371 			(coex_sta->bt_ble_scan_type & 0x1 ?
4372 			coex_sta->bt_ble_scan_para[0] : 0x0),
4373 			(coex_sta->bt_ble_scan_type & 0x2 ?
4374 			coex_sta->bt_ble_scan_para[1] : 0x0),
4375 			(coex_sta->bt_ble_scan_type & 0x4 ?
4376 			coex_sta->bt_ble_scan_para[2] : 0x0));
4377 		CL_PRINTF(cli_buf);
4378 	}
4379 
4380 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
4381 		   "ReInit/ReLink/IgnWlact/Page/NameReq",
4382 		   coex_sta->cnt_ReInit,
4383 		   coex_sta->cnt_setupLink,
4384 		   coex_sta->cnt_IgnWlanAct,
4385 		   coex_sta->cnt_Page,
4386 		   coex_sta->cnt_RemoteNameReq
4387 		  );
4388 	CL_PRINTF(cli_buf);
4389 
4390 	halbtc8821c1ant_read_score_board(btcoexist,	&u16tmp[0]);
4391 
4392 	if ((coex_sta->bt_reg_vendor_ae == 0xffff) ||
4393 	    (coex_sta->bt_reg_vendor_ac == 0xffff))
4394 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = x/ x/ %04x",
4395 			   "0xae[4]/0xac[1:0]/Scoreboard(B->W)", u16tmp[0]);
4396 	else
4397 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4398 			   "\r\n %-35s = 0x%x/ 0x%x/ %04x",
4399 			   "0xae[4]/0xac[1:0]/Scoreboard",
4400 			   ((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4),
4401 			   coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]);
4402 	CL_PRINTF(cli_buf);
4403 
4404 	if (coex_sta->num_of_profile > 0) {
4405 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4406 			"\r\n %-35s = %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x",
4407 			"AFH MAP",
4408 			coex_sta->bt_afh_map[0],
4409 			coex_sta->bt_afh_map[1],
4410 			coex_sta->bt_afh_map[2],
4411 			coex_sta->bt_afh_map[3],
4412 			coex_sta->bt_afh_map[4],
4413 			coex_sta->bt_afh_map[5],
4414 			coex_sta->bt_afh_map[6],
4415 			coex_sta->bt_afh_map[7],
4416 			coex_sta->bt_afh_map[8],
4417 			coex_sta->bt_afh_map[9]
4418 			   );
4419 		CL_PRINTF(cli_buf);
4420 	}
4421 
4422 	for (i = 0; i < BT_INFO_SRC_8821C_1ANT_MAX; i++) {
4423 		if (coex_sta->bt_info_c2h_cnt[i]) {
4424 			CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4425 				"\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
4426 				   glbt_info_src_8821c_1ant[i],
4427 				   coex_sta->bt_info_c2h[i][0],
4428 				   coex_sta->bt_info_c2h[i][1],
4429 				   coex_sta->bt_info_c2h[i][2],
4430 				   coex_sta->bt_info_c2h[i][3],
4431 				   coex_sta->bt_info_c2h[i][4],
4432 				   coex_sta->bt_info_c2h[i][5],
4433 				   coex_sta->bt_info_c2h[i][6],
4434 				   coex_sta->bt_info_c2h_cnt[i]);
4435 			CL_PRINTF(cli_buf);
4436 		}
4437 	}
4438 
4439 
4440 	if (btcoexist->manual_control)
4441 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4442 			"============[mechanisms] (before Manual)============");
4443 	else
4444 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4445 			   "============[Mechanisms]============");
4446 
4447 	CL_PRINTF(cli_buf);
4448 
4449 	ps_tdma_case = coex_dm->cur_ps_tdma;
4450 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4451 		   "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s)",
4452 		   "TDMA",
4453 		   coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
4454 		   coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
4455 		   coex_dm->ps_tdma_para[4], ps_tdma_case,
4456 		   (coex_dm->cur_ps_tdma_on ? "TDMA On" : "TDMA Off"));
4457 
4458 	CL_PRINTF(cli_buf);
4459 
4460 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
4461 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
4462 	u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
4463 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4464 		   "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x",
4465 		   "Table/0x6c0/0x6c4/0x6c8",
4466 		   coex_sta->coex_table_type, u32tmp[0], u32tmp[1], u32tmp[2]);
4467 	CL_PRINTF(cli_buf);
4468 
4469 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
4470 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
4471 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4472 		   "\r\n %-35s = 0x%x/ 0x%x/ %04x",
4473 		   "0x778/0x6cc/Scoreboard(W->B)",
4474 		   u8tmp[0], u32tmp[0], coex_sta->score_board_WB);
4475 	CL_PRINTF(cli_buf);
4476 
4477 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s/ %d",
4478 		   "AntDiv/BtCtrlLPS/LPRA/PsFail",
4479 		   ((board_info->ant_div_cfg) ? "On" : "Off"),
4480 		   ((coex_sta->force_lps_ctrl) ? "On" : "Off"),
4481 		   ((coex_dm->cur_low_penalty_ra) ? "On" : "Off"),
4482 		   coex_sta->cnt_set_ps_state_fail);
4483 	CL_PRINTF(cli_buf);
4484 
4485 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
4486 		   "Null All/Retry/Ack/BT_Empty/BT_Late",
4487 		   coex_sta->wl_fw_dbg_info[1],
4488 		   coex_sta->wl_fw_dbg_info[2],
4489 		   coex_sta->wl_fw_dbg_info[3],
4490 		   coex_sta->wl_fw_dbg_info[4],
4491 		   coex_sta->wl_fw_dbg_info[5]);
4492 	CL_PRINTF(cli_buf);
4493 
4494 	u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
4495 	lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ?  TRUE : FALSE;
4496 
4497 	if (lte_coex_on) {
4498 
4499 		u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
4500 				0xa0);
4501 		u32tmp[1] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
4502 				0xa4);
4503 
4504 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4505 			   "LTE Coex Table W_L/B_L",
4506 			   u32tmp[0] & 0xffff, u32tmp[1] & 0xffff);
4507 		CL_PRINTF(cli_buf);
4508 
4509 		u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
4510 				0xa8);
4511 		u32tmp[1] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
4512 				0xac);
4513 		u32tmp[2] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
4514 				0xb0);
4515 		u32tmp[3] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist,
4516 				0xb4);
4517 
4518 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4519 			   "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4520 			   "LTE Break Table W_L/B_L/L_W/L_B",
4521 			   u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
4522 			   u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
4523 		CL_PRINTF(cli_buf);
4524 	}
4525 
4526 	/* Hw setting		 */
4527 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4528 		   "============[Hw setting]============");
4529 	CL_PRINTF(cli_buf);
4530 
4531 	u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
4532 	u32tmp[1] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
4533 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73);
4534 
4535 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s",
4536 		   "LTE Coex/Path Owner",
4537 		   ((lte_coex_on) ? "On" : "Off") ,
4538 		   ((u8tmp[0] & BIT(2)) ? "WL" : "BT"));
4539 	CL_PRINTF(cli_buf);
4540 
4541 	if (lte_coex_on) {
4542 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4543 			   "\r\n %-35s = %d/ %d/ %d/ %d",
4544 			   "LTE 3Wire/OPMode/UART/UARTMode",
4545 			   (int)((u32tmp[0] & BIT(6)) >> 6),
4546 			   (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
4547 			   (int)((u32tmp[0] & BIT(3)) >> 3),
4548 			   (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
4549 		CL_PRINTF(cli_buf);
4550 
4551 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4552 			   "LTE_Busy/UART_Busy",
4553 			   (int)((u32tmp[1] & BIT(1)) >> 1),
4554 			   (int)(u32tmp[1] & BIT(0)));
4555 		CL_PRINTF(cli_buf);
4556 	}
4557 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4558 		   "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s %d",
4559 		   "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg",
4560 		   ((u32tmp[0] & BIT(12)) ? "SW" : "HW"),
4561 		   ((u32tmp[0] & BIT(8)) ?  "SW" : "HW"),
4562 		   ((u32tmp[0] & BIT(14)) ? "SW" : "HW"),
4563 		   ((u32tmp[0] & BIT(10)) ?  "SW" : "HW"),
4564 		   ((u8tmp[0] & BIT(3)) ? "On" : "Off"),
4565 		   coex_sta->gnt_error_cnt);
4566 	CL_PRINTF(cli_buf);
4567 
4568 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ 0x%x",
4569 		   "GNT_WL/GNT_BT/ RF_0x1",
4570 		   (int)((u32tmp[1] & BIT(2)) >> 2),
4571 		   (int)((u32tmp[1] & BIT(3)) >> 3),
4572 		   btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff));
4573 	CL_PRINTF(cli_buf);
4574 
4575 
4576 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb0);
4577 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
4578 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcba);
4579 
4580 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4581 		   "\r\n %-35s = 0x%04x/ 0x%04x/ 0x%02x %s",
4582 		   "0xcb0/0xcb4/0xcb8[23:16]",
4583 		   u32tmp[0], u32tmp[1], u8tmp[0],
4584 		   ((u8tmp[0] & 0x1) == 0x1 ?  "(BTG)" :   "(WL_A+G)"));
4585 	CL_PRINTF(cli_buf);
4586 
4587 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
4588 	u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
4589 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6);
4590 	u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
4591 
4592 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4593 		   "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4594 		   "4c[24:23]/64[0]/4c6[4]/40[5]",
4595 		   (u32tmp[0] & (BIT(24) | BIT(23))) >> 23 , u8tmp[2] & 0x1 ,
4596 		   (int)((u8tmp[0] & BIT(4)) >> 4),
4597 		   (int)((u8tmp[1] & BIT(5)) >> 5));
4598 	CL_PRINTF(cli_buf);
4599 
4600 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
4601 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
4602 	u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953);
4603 	u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50);
4604 	u8tmp[3] = btcoexist->btc_read_1byte(btcoexist, 0x60a);
4605 
4606 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4607 		   "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x/ 0x%x",
4608 		   "0x550/0x522/4-RxAGC/0xc50/0x60a",
4609 		u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off",
4610 		u8tmp[2], u8tmp[3]);
4611 	CL_PRINTF(cli_buf);
4612 
4613 	fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
4614 			PHYDM_INFO_FA_OFDM);
4615 	fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
4616 			PHYDM_INFO_FA_CCK);
4617 	cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
4618 			PHYDM_INFO_CCA_OFDM);
4619 	cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
4620 			PHYDM_INFO_CCA_CCK);
4621 
4622 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4623 		   "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4624 		   "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
4625 		   cca_cck, fa_cck, cca_ofdm, fa_ofdm);
4626 	CL_PRINTF(cli_buf);
4627 
4628 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d (Rx_rate Data/RTS= %d/%d)",
4629 		   "CRC_OK CCK/11g/11n/11ac",
4630 		   coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
4631 		   coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht,
4632 		   coex_sta->wl_rx_rate, coex_sta->wl_rts_rx_rate);
4633 	CL_PRINTF(cli_buf);
4634 
4635 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
4636 		   "CRC_Err CCK/11g/11n/11ac",
4637 		   coex_sta->crc_err_cck, coex_sta->crc_err_11g,
4638 		   coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
4639 	CL_PRINTF(cli_buf);
4640 
4641 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s/ %s/ %d",
4642 		   "HiPr/ Locking/ warn/ Locked/ Noisy",
4643 		   (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"),
4644 		   (coex_sta->cck_lock ? "Yes" : "No"),
4645 		   (coex_sta->cck_lock_warn ? "Yes" : "No"),
4646 		   (coex_sta->cck_lock_ever ? "Yes" : "No"),
4647 		   coex_sta->wl_noisy_level);
4648 	CL_PRINTF(cli_buf);
4649 
4650 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4651 		   "0x770(Hi-pri rx/tx)",
4652 		   coex_sta->high_priority_rx, coex_sta->high_priority_tx);
4653 	CL_PRINTF(cli_buf);
4654 
4655 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s",
4656 		   "0x774(Lo-pri rx/tx)",
4657 		   coex_sta->low_priority_rx, coex_sta->low_priority_tx,
4658 		   (bt_link_info->slave_role ? "(Slave!!)" : (
4659 		   coex_sta->is_tdma_btautoslot_hang ? "(auto-slot hang!!)" : "")));
4660 	CL_PRINTF(cli_buf);
4661 
4662 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
4663 }
4664 
4665 
ex_halbtc8821c1ant_ips_notify(IN struct btc_coexist * btcoexist,IN u8 type)4666 void ex_halbtc8821c1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
4667 {
4668 	if (btcoexist->manual_control ||	btcoexist->stop_coex_dm)
4669 		return;
4670 
4671 	if (type == BTC_IPS_ENTER) {
4672 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4673 			    "[BTCoex], IPS ENTER notify\n");
4674 		BTC_TRACE(trace_buf);
4675 		coex_sta->under_ips = TRUE;
4676 
4677 		/* Write WL "Active" in Score-board for LPS off */
4678 		halbtc8821c1ant_post_state_to_bt(btcoexist,
4679 				BT_8821C_1ANT_SCOREBOARD_ACTIVE |
4680 				BT_8821C_1ANT_SCOREBOARD_ONOFF |
4681 				BT_8821C_1ANT_SCOREBOARD_SCAN |
4682 				BT_8821C_1ANT_SCOREBOARD_UNDERTEST,
4683 				FALSE);
4684 
4685 		halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4686 					     FORCE_EXEC,
4687 					     BT_8821C_1ANT_PHASE_WLAN_OFF);
4688 		halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
4689 		halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, FALSE, 0);
4690 	} else if (type == BTC_IPS_LEAVE) {
4691 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4692 			    "[BTCoex], IPS LEAVE notify\n");
4693 		BTC_TRACE(trace_buf);
4694 #if 0
4695 		halbtc8821c1ant_post_state_to_bt(btcoexist,
4696 				BT_8821C_1ANT_SCOREBOARD_ACTIVE, TRUE);
4697 
4698 		halbtc8821c1ant_post_state_to_bt(btcoexist,
4699 				BT_8821C_1ANT_SCOREBOARD_ONOFF, TRUE);
4700 #endif
4701 		halbtc8821c1ant_init_hw_config(btcoexist, FALSE, FALSE);
4702 		halbtc8821c1ant_init_coex_dm(btcoexist);
4703 
4704 		coex_sta->under_ips = FALSE;
4705 	}
4706 }
4707 
ex_halbtc8821c1ant_lps_notify(IN struct btc_coexist * btcoexist,IN u8 type)4708 void ex_halbtc8821c1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
4709 {
4710 	static boolean  pre_force_lps_on = FALSE;
4711 
4712 	if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4713 		return;
4714 
4715 	if (type == BTC_LPS_ENABLE) {
4716 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4717 			    "[BTCoex], LPS ENABLE notify\n");
4718 		BTC_TRACE(trace_buf);
4719 		coex_sta->under_lps = TRUE;
4720 
4721 		if (coex_sta->force_lps_ctrl == TRUE) { /* LPS No-32K */
4722 			/* Write WL "Active" in Score-board for PS-TDMA */
4723 			pre_force_lps_on = TRUE;
4724 			halbtc8821c1ant_post_state_to_bt(btcoexist,
4725 					 BT_8821C_1ANT_SCOREBOARD_ACTIVE, TRUE);
4726 		} else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */
4727 			/* Write WL "Non-Active" in Score-board for Native-PS */
4728 			pre_force_lps_on = FALSE;
4729 			halbtc8821c1ant_post_state_to_bt(btcoexist,
4730 				 BT_8821C_1ANT_SCOREBOARD_ACTIVE, FALSE);
4731 
4732 			halbtc8821c1ant_action_wifi_native_lps(btcoexist);
4733 		}
4734 	} else if (type == BTC_LPS_DISABLE) {
4735 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4736 			    "[BTCoex], LPS DISABLE notify\n");
4737 		BTC_TRACE(trace_buf);
4738 		coex_sta->under_lps = FALSE;
4739 
4740 		/* Write WL "Active" in Score-board for LPS off */
4741 		halbtc8821c1ant_post_state_to_bt(btcoexist,
4742 				BT_8821C_1ANT_SCOREBOARD_ACTIVE, TRUE);
4743 
4744 		if ((!pre_force_lps_on) && (!coex_sta->force_lps_ctrl))
4745 			halbtc8821c1ant_query_bt_info(btcoexist);
4746 	}
4747 }
4748 
ex_halbtc8821c1ant_scan_notify(IN struct btc_coexist * btcoexist,IN u8 type)4749 void ex_halbtc8821c1ant_scan_notify(IN struct btc_coexist *btcoexist,
4750 				    IN u8 type)
4751 {
4752 	boolean wifi_connected = FALSE;
4753 	boolean wifi_under_5g = FALSE;
4754 
4755 	if (btcoexist->manual_control ||
4756 	    btcoexist->stop_coex_dm)
4757 		return;
4758 
4759 	coex_sta->freeze_coexrun_by_btinfo = FALSE;
4760 
4761 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
4762 
4763 	if (wifi_connected)
4764 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4765 			"[BTCoex], ********** WL connected before SCAN\n");
4766 	else
4767 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4768 			"[BTCoex], **********  WL is not connected before SCAN\n");
4769 
4770 	BTC_TRACE(trace_buf);
4771 
4772 	if ((type == BTC_SCAN_START) || (type == BTC_SCAN_START_2G)) {
4773 
4774 		halbtc8821c1ant_post_state_to_bt(btcoexist,
4775 					BT_8821C_1ANT_SCOREBOARD_ACTIVE |
4776 					BT_8821C_1ANT_SCOREBOARD_SCAN |
4777 					BT_8821C_1ANT_SCOREBOARD_ONOFF,
4778 					TRUE);
4779 
4780 		halbtc8821c1ant_query_bt_info(btcoexist);
4781 	}
4782 
4783 
4784 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4785 
4786 	if ((type == BTC_SCAN_START) && (wifi_under_5g)) {
4787 
4788 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4789 			"[BTCoex], SCAN START notify (5G)\n");
4790 		BTC_TRACE(trace_buf);
4791 
4792 		halbtc8821c1ant_action_wifi_under5g(btcoexist);
4793 	} else if ((type == BTC_SCAN_START_2G) || (type == BTC_SCAN_START)) {
4794 
4795 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4796 			    "[BTCoex], SCAN START notify (2G)\n");
4797 		BTC_TRACE(trace_buf);
4798 
4799 		if (!wifi_connected)
4800 			coex_sta->wifi_is_high_pri_task = TRUE;
4801 
4802 		/* Force antenna setup for no scan result issue */
4803 		halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4804 					     FORCE_EXEC,
4805 					     BT_8821C_1ANT_PHASE_2G_RUNTIME);
4806 
4807 		halbtc8821c1ant_run_coexist_mechanism(btcoexist);
4808 	} else {
4809 
4810 		btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
4811 				   &coex_sta->scan_ap_num);
4812 
4813 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4814 			    "[BTCoex], SCAN FINISH notify  (Scan-AP = %d)\n",
4815 			    coex_sta->scan_ap_num);
4816 		BTC_TRACE(trace_buf);
4817 
4818 		coex_sta->wifi_is_high_pri_task = FALSE;
4819 
4820 		halbtc8821c1ant_run_coexist_mechanism(btcoexist);
4821 	}
4822 
4823 }
4824 
ex_halbtc8821c1ant_switchband_notify(IN struct btc_coexist * btcoexist,IN u8 type)4825 void ex_halbtc8821c1ant_switchband_notify(IN struct btc_coexist *btcoexist,
4826 		IN u8 type)
4827 {
4828 
4829 	boolean wifi_connected = FALSE, bt_hs_on = FALSE;
4830 	u32	wifi_link_status = 0;
4831 	u32	num_of_wifi_link = 0;
4832 	boolean	bt_ctrl_agg_buf_size = FALSE;
4833 	u8	agg_buf_size = 5;
4834 
4835 
4836 	if (btcoexist->manual_control ||
4837 	    btcoexist->stop_coex_dm)
4838 		return;
4839 
4840 	coex_sta->switch_band_notify_to = type;
4841 
4842 	if (type == BTC_SWITCH_TO_5G) {
4843 
4844 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4845 			    "[BTCoex], switchband_notify ---  switch to 5G\n");
4846 		BTC_TRACE(trace_buf);
4847 
4848 		halbtc8821c1ant_action_wifi_under5g(btcoexist);
4849 
4850 	} else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
4851 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4852 			"[BTCoex], switchband_notify --- BTC_SWITCH_TO_2G (no for scan)\n");
4853 		BTC_TRACE(trace_buf);
4854 
4855 		halbtc8821c1ant_run_coexist_mechanism(btcoexist);
4856 
4857 	} else {
4858 
4859 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4860 			    "[BTCoex], switchband_notify ---  switch to 2G\n");
4861 		BTC_TRACE(trace_buf);
4862 
4863 		ex_halbtc8821c1ant_scan_notify(btcoexist,
4864 					       BTC_SCAN_START_2G);
4865 	}
4866 
4867 	coex_sta->switch_band_notify_to = BTC_NOT_SWITCH;
4868 }
4869 
4870 
ex_halbtc8821c1ant_connect_notify(IN struct btc_coexist * btcoexist,IN u8 type)4871 void ex_halbtc8821c1ant_connect_notify(IN struct btc_coexist *btcoexist,
4872 				       IN u8 type)
4873 {
4874 
4875 	if (btcoexist->manual_control ||
4876 	    btcoexist->stop_coex_dm)
4877 		return;
4878 
4879 	halbtc8821c1ant_post_state_to_bt(btcoexist,
4880 					 BT_8821C_1ANT_SCOREBOARD_ACTIVE |
4881 					 BT_8821C_1ANT_SCOREBOARD_SCAN |
4882 					 BT_8821C_1ANT_SCOREBOARD_ONOFF,
4883 					 TRUE);
4884 
4885 	if ((type == BTC_ASSOCIATE_5G_START) ||
4886 	    (type == BTC_ASSOCIATE_5G_FINISH)) {
4887 
4888 		if (type == BTC_ASSOCIATE_5G_START)
4889 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4890 				"[BTCoex], connect_notify ---  5G start\n");
4891 		else
4892 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4893 				"[BTCoex], connect_notify ---  5G finish\n");
4894 
4895 		BTC_TRACE(trace_buf);
4896 
4897 		halbtc8821c1ant_action_wifi_under5g(btcoexist);
4898 	} else if (type == BTC_ASSOCIATE_START) {
4899 
4900 		coex_sta->wifi_is_high_pri_task = TRUE;
4901 		coex_dm->arp_cnt = 0;
4902 
4903 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4904 			    "[BTCoex], CONNECT START notify (2G)\n");
4905 		BTC_TRACE(trace_buf);
4906 
4907 		/* Force antenna setup for no scan result issue */
4908 		halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4909 					     FORCE_EXEC,
4910 					     BT_8821C_1ANT_PHASE_2G_RUNTIME);
4911 
4912 		halbtc8821c1ant_run_coexist_mechanism(btcoexist);
4913 
4914 		/* To keep TDMA case during connect process,
4915 		to avoid changed by Btinfo and runcoexmechanism */
4916 		coex_sta->freeze_coexrun_by_btinfo = TRUE;
4917 	} else {
4918 
4919 		coex_sta->wifi_is_high_pri_task = FALSE;
4920 		coex_sta->freeze_coexrun_by_btinfo = FALSE;
4921 
4922 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4923 			    "[BTCoex], CONNECT FINISH notify (2G)\n");
4924 		BTC_TRACE(trace_buf);
4925 
4926 		halbtc8821c1ant_run_coexist_mechanism(btcoexist);
4927 	}
4928 
4929 }
4930 
ex_halbtc8821c1ant_media_status_notify(IN struct btc_coexist * btcoexist,IN u8 type)4931 void ex_halbtc8821c1ant_media_status_notify(IN struct btc_coexist *btcoexist,
4932 		IN u8 type)
4933 {
4934 	boolean			wifi_under_b_mode = FALSE, wifi_under_5g = FALSE;
4935 
4936 
4937 	if (btcoexist->manual_control ||
4938 	    btcoexist->stop_coex_dm)
4939 		return;
4940 
4941 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4942 
4943 	if (type == BTC_MEDIA_CONNECT) {
4944 
4945 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4946 			    "[BTCoex], MEDIA connect notify\n");
4947 		BTC_TRACE(trace_buf);
4948 
4949 		halbtc8821c1ant_post_state_to_bt(btcoexist,
4950 					 BT_8821C_1ANT_SCOREBOARD_ACTIVE |
4951 					 BT_8821C_1ANT_SCOREBOARD_ONOFF,
4952 					 TRUE);
4953 
4954 		if (wifi_under_5g) {
4955 
4956 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4957 				    "[BTCoex], WiFi is under 5G!!!\n");
4958 			BTC_TRACE(trace_buf);
4959 
4960 			halbtc8821c1ant_action_wifi_under5g(btcoexist);
4961 		} else {
4962 
4963 			/* Force antenna setup for no scan result issue */
4964 			halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4965 						     FORCE_EXEC,
4966 						     BT_8821C_1ANT_PHASE_2G_RUNTIME);
4967 
4968 			btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
4969 					   &wifi_under_b_mode);
4970 
4971 			/* Set CCK Tx/Rx high Pri except 11b mode */
4972 			if (wifi_under_b_mode) {
4973 				btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x00); /* CCK Tx */
4974 				btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x00); /* CCK Rx */
4975 			} else {
4976 				btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x00); /* CCK Tx */
4977 				btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x10); /* CCK Rx */
4978 			}
4979 		}
4980 	} else {
4981 
4982 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4983 			    "[BTCoex], MEDIA disconnect notify\n");
4984 		BTC_TRACE(trace_buf);
4985 
4986 		halbtc8821c1ant_post_state_to_bt(btcoexist,
4987 				 BT_8821C_1ANT_SCOREBOARD_ACTIVE, FALSE);
4988 
4989 		btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
4990 		btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
4991 
4992 		coex_sta->cck_lock_ever = FALSE;
4993 		coex_sta->cck_lock_warn = FALSE;
4994 		coex_sta->cck_lock = FALSE;
4995 	}
4996 
4997 	halbtc8821c1ant_update_wifi_channel_info(btcoexist, type);
4998 
4999 }
5000 
ex_halbtc8821c1ant_specific_packet_notify(IN struct btc_coexist * btcoexist,IN u8 type)5001 void ex_halbtc8821c1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
5002 		IN u8 type)
5003 {
5004 	boolean	under_4way = FALSE, wifi_under_5g = FALSE;
5005 
5006 	if (btcoexist->manual_control ||
5007 	    btcoexist->stop_coex_dm)
5008 		return;
5009 
5010 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
5011 
5012 	if (wifi_under_5g) {
5013 
5014 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5015 			    "[BTCoex], WiFi is under 5G!!!\n");
5016 		BTC_TRACE(trace_buf);
5017 
5018 		halbtc8821c1ant_action_wifi_under5g(btcoexist);
5019 		return;
5020 	}
5021 
5022 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &under_4way);
5023 
5024 	if (under_4way) {
5025 
5026 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5027 			    "[BTCoex], specific Packet ---- under_4way!!\n");
5028 		BTC_TRACE(trace_buf);
5029 
5030 		coex_sta->wifi_is_high_pri_task = TRUE;
5031 		coex_sta->specific_pkt_period_cnt = 2;
5032 	} else if (type == BTC_PACKET_ARP) {
5033 
5034 		coex_dm->arp_cnt++;
5035 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5036 			    "[BTCoex], specific Packet ARP notify -cnt = %d\n",
5037 			    coex_dm->arp_cnt);
5038 		BTC_TRACE(trace_buf);
5039 
5040 	} else {
5041 
5042 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5043 			"[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n",
5044 			    type);
5045 		BTC_TRACE(trace_buf);
5046 
5047 		coex_sta->wifi_is_high_pri_task = TRUE;
5048 		coex_sta->specific_pkt_period_cnt = 2;
5049 	}
5050 
5051 	if (coex_sta->wifi_is_high_pri_task) {
5052 		halbtc8821c1ant_post_state_to_bt(btcoexist,
5053 					 BT_8821C_1ANT_SCOREBOARD_SCAN, TRUE);
5054 		halbtc8821c1ant_run_coexist_mechanism(btcoexist);
5055 	}
5056 
5057 }
5058 
ex_halbtc8821c1ant_bt_info_notify(IN struct btc_coexist * btcoexist,IN u8 * tmp_buf,IN u8 length)5059 void ex_halbtc8821c1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
5060 				       IN u8 *tmp_buf, IN u8 length)
5061 {
5062 	u8				i, rsp_source = 0;
5063 	boolean				wifi_connected = FALSE;
5064 	boolean	wifi_scan = FALSE, wifi_link = FALSE, wifi_roam = FALSE,
5065 			wifi_busy = FALSE;
5066 	static boolean is_scoreboard_scan = FALSE;
5067 
5068 	if (psd_scan->is_AntDet_running == TRUE) {
5069 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5070 			"[BTCoex], bt_info_notify return for AntDet is running\n");
5071 		BTC_TRACE(trace_buf);
5072 		return;
5073 	}
5074 
5075 	rsp_source = tmp_buf[0] & 0xf;
5076 	if (rsp_source >= BT_INFO_SRC_8821C_1ANT_MAX)
5077 		rsp_source = BT_INFO_SRC_8821C_1ANT_WIFI_FW;
5078 	coex_sta->bt_info_c2h_cnt[rsp_source]++;
5079 
5080 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5081 		    "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source,
5082 		    length);
5083 	BTC_TRACE(trace_buf);
5084 
5085 	for (i = 0; i < length; i++) {
5086 		coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
5087 
5088 		if (i == length - 1) {
5089 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
5090 				    tmp_buf[i]);
5091 			BTC_TRACE(trace_buf);
5092 		} else {
5093 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
5094 				    tmp_buf[i]);
5095 			BTC_TRACE(trace_buf);
5096 		}
5097 	}
5098 
5099 	coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1];
5100 	coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4];
5101 	coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5];
5102 
5103 	if (BT_INFO_SRC_8821C_1ANT_WIFI_FW != rsp_source) {
5104 
5105 		/* if 0xff, it means BT is under WHCK test */
5106 		coex_sta->bt_whck_test = ((coex_sta->bt_info == 0xff) ? TRUE :
5107 					  FALSE);
5108 
5109 		coex_sta->bt_create_connection = ((
5110 			coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? TRUE :
5111 						  FALSE);
5112 
5113 		/* unit: %, value-100 to translate to unit: dBm */
5114 		coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 +
5115 				    10;
5116 
5117 		coex_sta->c2h_bt_remote_name_req = ((
5118 			coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? TRUE :
5119 						    FALSE);
5120 
5121 		coex_sta->is_A2DP_3M = ((coex_sta->bt_info_c2h[rsp_source][2] &
5122 					 0x10) ? TRUE : FALSE);
5123 
5124 		coex_sta->acl_busy = ((coex_sta->bt_info_c2h[rsp_source][1] &
5125 				       0x8) ? TRUE : FALSE);
5126 
5127 		coex_sta->voice_over_HOGP = ((coex_sta->bt_info_ext & 0x10) ?
5128 					     TRUE : FALSE);
5129 
5130 		coex_sta->c2h_bt_inquiry_page = ((coex_sta->bt_info &
5131 			  BT_INFO_8821C_1ANT_B_INQ_PAGE) ? TRUE : FALSE);
5132 
5133 		coex_sta->a2dp_bit_pool = (((
5134 			coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) ?
5135 				   (coex_sta->bt_info_c2h[rsp_source][6] & 0x7f) : 0);
5136 
5137 		coex_sta->is_bt_a2dp_sink = (coex_sta->bt_info_c2h[rsp_source][6] & 0x80) ?
5138 									TRUE : FALSE;
5139 
5140 		coex_sta->bt_retry_cnt = coex_sta->bt_info_c2h[rsp_source][2] &
5141 					 0xf;
5142 
5143 		coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8;
5144 
5145 		coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7;
5146 
5147 		coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4;
5148 
5149 		coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6;
5150 
5151 		if (coex_sta->bt_retry_cnt >= 1)
5152 			coex_sta->pop_event_cnt++;
5153 
5154 		if (coex_sta->c2h_bt_remote_name_req)
5155 			coex_sta->cnt_RemoteNameReq++;
5156 
5157 		if (coex_sta->bt_info_ext & BIT(1))
5158 			coex_sta->cnt_ReInit++;
5159 
5160 		if (coex_sta->bt_info_ext & BIT(2)) {
5161 			coex_sta->cnt_setupLink++;
5162 			coex_sta->is_setupLink = TRUE;
5163 			coex_sta->bt_relink_downcount = 2;
5164 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5165 				    "[BTCoex], Re-Link start in BT info!!\n");
5166 			BTC_TRACE(trace_buf);
5167 		} else {
5168 			coex_sta->is_setupLink = FALSE;
5169 			coex_sta->bt_relink_downcount = 0;
5170 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5171 				    "[BTCoex], Re-Link stop in BT info!!\n");
5172 			BTC_TRACE(trace_buf);
5173 		}
5174 
5175 		if (coex_sta->bt_info_ext & BIT(3))
5176 			coex_sta->cnt_IgnWlanAct++;
5177 
5178 		if (coex_sta->bt_info_ext & BIT(6))
5179 			coex_sta->cnt_RoleSwitch++;
5180 
5181 		if (coex_sta->bt_info_ext & BIT(7))
5182 			coex_sta->is_bt_multi_link = TRUE;
5183 		else
5184 			coex_sta->is_bt_multi_link = FALSE;
5185 
5186 		if (coex_sta->bt_create_connection) {
5187 			coex_sta->cnt_Page++;
5188 
5189 			btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
5190 			btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
5191 			btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link);
5192 			btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam);
5193 
5194 			if ((wifi_link) || (wifi_roam) || (wifi_scan) ||
5195 			    (coex_sta->wifi_is_high_pri_task) || (wifi_busy)) {
5196 
5197 				is_scoreboard_scan = TRUE;
5198 				halbtc8821c1ant_post_state_to_bt(btcoexist,
5199 					 BT_8821C_1ANT_SCOREBOARD_SCAN, TRUE);
5200 
5201 			} else
5202 				halbtc8821c1ant_post_state_to_bt(btcoexist,
5203 					 BT_8821C_1ANT_SCOREBOARD_SCAN, FALSE);
5204 
5205 		} else {
5206 				if (is_scoreboard_scan) {
5207 					halbtc8821c1ant_post_state_to_bt(btcoexist,
5208 						 BT_8821C_1ANT_SCOREBOARD_SCAN, FALSE);
5209 					is_scoreboard_scan = FALSE;
5210 				}
5211 		}
5212 
5213 		/* Here we need to resend some wifi info to BT */
5214 		/* because bt is reset and loss of the info. */
5215 
5216 		if ((!btcoexist->manual_control) &&
5217 		    (!btcoexist->stop_coex_dm)) {
5218 
5219 			btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
5220 					   &wifi_connected);
5221 
5222 			/*  Re-Init */
5223 			if ((coex_sta->bt_info_ext & BIT(1))) {
5224 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5225 					"[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
5226 				BTC_TRACE(trace_buf);
5227 				if (wifi_connected)
5228 					halbtc8821c1ant_update_wifi_channel_info(
5229 						btcoexist, BTC_MEDIA_CONNECT);
5230 				else
5231 					halbtc8821c1ant_update_wifi_channel_info(
5232 						btcoexist,
5233 						BTC_MEDIA_DISCONNECT);
5234 			}
5235 
5236 			/*  If Ignore_WLanAct && not SetUp_Link */
5237 			if ((coex_sta->bt_info_ext & BIT(3)) &&
5238 			    (!(coex_sta->bt_info_ext & BIT(2)))) {
5239 
5240 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5241 					"[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
5242 				BTC_TRACE(trace_buf);
5243 				halbtc8821c1ant_ignore_wlan_act(btcoexist,
5244 							FORCE_EXEC, FALSE);
5245 			}
5246 		}
5247 
5248 	}
5249 
5250 	if ((coex_sta->bt_info_ext & BIT(5))) {
5251 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5252 			"[BTCoex], BT ext info bit4 check, query BLE Scan type!!\n");
5253 		BTC_TRACE(trace_buf);
5254 		coex_sta->bt_ble_scan_type = btcoexist->btc_get_ble_scan_type_from_bt(
5255 						     btcoexist);
5256 
5257 		if ((coex_sta->bt_ble_scan_type & 0x1) == 0x1)
5258 			coex_sta->bt_ble_scan_para[0]  =
5259 				btcoexist->btc_get_ble_scan_para_from_bt(btcoexist,
5260 						0x1);
5261 		if ((coex_sta->bt_ble_scan_type & 0x2) == 0x2)
5262 			coex_sta->bt_ble_scan_para[1]  =
5263 				btcoexist->btc_get_ble_scan_para_from_bt(btcoexist,
5264 						0x2);
5265 		if ((coex_sta->bt_ble_scan_type & 0x4) == 0x4)
5266 			coex_sta->bt_ble_scan_para[2]  =
5267 				btcoexist->btc_get_ble_scan_para_from_bt(btcoexist,
5268 						0x4);
5269 
5270 	}
5271 
5272 	halbtc8821c1ant_update_bt_link_info(btcoexist);
5273 
5274 	halbtc8821c1ant_run_coexist_mechanism(btcoexist);
5275 }
5276 
ex_halbtc8821c1ant_wl_fwdbginfo_notify(IN struct btc_coexist * btcoexist,IN u8 * tmp_buf,IN u8 length)5277 void ex_halbtc8821c1ant_wl_fwdbginfo_notify(IN struct btc_coexist *btcoexist,
5278 				       IN u8 *tmp_buf, IN u8 length)
5279 {
5280 	u8 i = 0;
5281 	static u8 tmp_buf_pre[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
5282 
5283 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5284 				"[BTCoex], WiFi Fw Dbg info = %d %d %d %d %d %d (len = %d)\n",
5285 			    tmp_buf[0], tmp_buf[1],
5286 				tmp_buf[2], tmp_buf[3],
5287 				tmp_buf[4], tmp_buf[5], length);
5288 	BTC_TRACE(trace_buf);
5289 
5290 	if (tmp_buf[0] == 0x8) {
5291 		for (i = 1; i <= 5; i++) {
5292 			coex_sta->wl_fw_dbg_info[i] =
5293 				(tmp_buf[i] >= tmp_buf_pre[i]) ?
5294 				(tmp_buf[i] - tmp_buf_pre[i]) :
5295 				(255 - tmp_buf_pre[i] + tmp_buf[i]);
5296 
5297 			tmp_buf_pre[i] = tmp_buf[i];
5298 		}
5299 	}
5300 }
5301 
5302 
ex_halbtc8821c1ant_rx_rate_change_notify(IN struct btc_coexist * btcoexist,IN BOOLEAN is_data_frame,IN u8 btc_rate_id)5303 void ex_halbtc8821c1ant_rx_rate_change_notify(IN struct btc_coexist *btcoexist,
5304 		IN BOOLEAN is_data_frame, IN u8 btc_rate_id)
5305 {
5306 	BOOLEAN wifi_connected = FALSE;
5307 
5308 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
5309 			   &wifi_connected);
5310 
5311 	if (is_data_frame) {
5312 		coex_sta->wl_rx_rate = btc_rate_id;
5313 
5314 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5315 			"[BTCoex], rx_rate_change_notify data rate id = %d, RTS_Rate = %d\n",
5316 			coex_sta->wl_rx_rate, coex_sta->wl_rts_rx_rate);
5317 		BTC_TRACE(trace_buf);
5318 	} else {
5319 		coex_sta->wl_rts_rx_rate = btc_rate_id;
5320 
5321 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5322 			"[BTCoex], rts_rate_change_notify RTS rate id = %d, RTS_Rate = %d\n",
5323 			coex_sta->wl_rts_rx_rate, coex_sta->wl_rts_rx_rate);
5324 		BTC_TRACE(trace_buf);
5325 	}
5326 
5327 	if ((wifi_connected) &&
5328 		((coex_dm->bt_status ==  BT_8821C_1ANT_BT_STATUS_ACL_BUSY) ||
5329 		(coex_dm->bt_status ==  BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
5330 		(coex_dm->bt_status == BT_8821C_1ANT_BT_STATUS_SCO_BUSY))) {
5331 
5332 		if ((coex_sta->wl_rx_rate == BTC_CCK_5_5) ||
5333 			(coex_sta->wl_rx_rate == BTC_OFDM_6) ||
5334 			(coex_sta->wl_rx_rate == BTC_MCS_0)) {
5335 
5336 			coex_sta->cck_lock_warn = TRUE;
5337 
5338 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5339 				"[BTCoex], cck lock warning...\n");
5340 			BTC_TRACE(trace_buf);
5341 		} else if ((coex_sta->wl_rx_rate == BTC_CCK_1) ||
5342 			(coex_sta->wl_rx_rate == BTC_CCK_2) ||
5343 			(coex_sta->wl_rts_rx_rate == BTC_CCK_1) ||
5344 			(coex_sta->wl_rts_rx_rate == BTC_CCK_2)) {
5345 
5346 			coex_sta->cck_lock = TRUE;
5347 
5348 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5349 				"[BTCoex], cck locking...\n");
5350 			BTC_TRACE(trace_buf);
5351 		} else {
5352 			coex_sta->cck_lock_warn = FALSE;
5353 			coex_sta->cck_lock = FALSE;
5354 
5355 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5356 				"[BTCoex], cck unlock...\n");
5357 			BTC_TRACE(trace_buf);
5358 		}
5359 	} else {
5360 		if ((coex_dm->bt_status ==
5361 			BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE) ||
5362 			(coex_dm->bt_status ==
5363 			BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE)) {
5364 			coex_sta->cck_lock_warn = FALSE;
5365 			coex_sta->cck_lock = FALSE;
5366 		}
5367 	}
5368 
5369 }
5370 
ex_halbtc8821c1ant_rf_status_notify(IN struct btc_coexist * btcoexist,IN u8 type)5371 void ex_halbtc8821c1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
5372 		IN u8 type)
5373 {
5374 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
5375 	BTC_TRACE(trace_buf);
5376 
5377 	if (type == BTC_RF_ON) {
5378 
5379 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5380 			    "[BTCoex], RF is turned ON!!\n");
5381 		BTC_TRACE(trace_buf);
5382 
5383 		btcoexist->stop_coex_dm = FALSE;
5384 		coex_sta->is_rf_state_off = FALSE;
5385 #if 0
5386 		halbtc8821c1ant_post_state_to_bt(btcoexist,
5387 					 BT_8821C_1ANT_SCOREBOARD_ACTIVE |
5388 					 BT_8821C_1ANT_SCOREBOARD_ONOFF,
5389 					 TRUE);
5390 #endif
5391 	} else if (type == BTC_RF_OFF) {
5392 
5393 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5394 			    "[BTCoex], RF is turned OFF!!\n");
5395 		BTC_TRACE(trace_buf);
5396 
5397 		halbtc8821c1ant_post_state_to_bt(btcoexist,
5398 				BT_8821C_1ANT_SCOREBOARD_ACTIVE |
5399 				BT_8821C_1ANT_SCOREBOARD_ONOFF |
5400 				BT_8821C_1ANT_SCOREBOARD_SCAN |
5401 				BT_8821C_1ANT_SCOREBOARD_UNDERTEST,
5402 				FALSE);
5403 
5404 		halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
5405 					     FORCE_EXEC,
5406 					     BT_8821C_1ANT_PHASE_WLAN_OFF);
5407 		halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, FALSE, 0);
5408 
5409 		btcoexist->stop_coex_dm = TRUE;
5410 		coex_sta->is_rf_state_off = TRUE;
5411 	}
5412 }
5413 
ex_halbtc8821c1ant_halt_notify(IN struct btc_coexist * btcoexist)5414 void ex_halbtc8821c1ant_halt_notify(IN struct btc_coexist *btcoexist)
5415 {
5416 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
5417 	BTC_TRACE(trace_buf);
5418 
5419 	halbtc8821c1ant_post_state_to_bt(btcoexist,
5420 				BT_8821C_1ANT_SCOREBOARD_ACTIVE |
5421 				BT_8821C_1ANT_SCOREBOARD_ONOFF |
5422 				BT_8821C_1ANT_SCOREBOARD_SCAN |
5423 				BT_8821C_1ANT_SCOREBOARD_UNDERTEST,
5424 				FALSE);
5425 
5426 	halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
5427 				     BT_8821C_1ANT_PHASE_WLAN_OFF);
5428 
5429 	ex_halbtc8821c1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
5430 
5431 	halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, FALSE, 0);
5432 
5433 	btcoexist->stop_coex_dm = TRUE;
5434 }
5435 
ex_halbtc8821c1ant_pnp_notify(IN struct btc_coexist * btcoexist,IN u8 pnp_state)5436 void ex_halbtc8821c1ant_pnp_notify(IN struct btc_coexist *btcoexist,
5437 				   IN u8 pnp_state)
5438 {
5439 	boolean wifi_under_5g = FALSE;
5440 
5441 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
5442 	BTC_TRACE(trace_buf);
5443 
5444 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
5445 
5446 	if ((BTC_WIFI_PNP_SLEEP == pnp_state) ||
5447 	    (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state)) {
5448 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5449 			    "[BTCoex], Pnp notify to SLEEP\n");
5450 		BTC_TRACE(trace_buf);
5451 
5452 		halbtc8821c1ant_post_state_to_bt(btcoexist,
5453 				BT_8821C_1ANT_SCOREBOARD_ACTIVE |
5454 				BT_8821C_1ANT_SCOREBOARD_ONOFF |
5455 				BT_8821C_1ANT_SCOREBOARD_SCAN |
5456 				BT_8821C_1ANT_SCOREBOARD_UNDERTEST,
5457 				FALSE);
5458 
5459 		if (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state) {
5460 
5461 			if (wifi_under_5g)
5462 				halbtc8821c1ant_set_ant_path(btcoexist,
5463 						BTC_ANT_PATH_AUTO, FORCE_EXEC,
5464 						BT_8821C_1ANT_PHASE_5G_RUNTIME);
5465 			else
5466 				halbtc8821c1ant_set_ant_path(btcoexist,
5467 						BTC_ANT_PATH_AUTO, FORCE_EXEC,
5468 						BT_8821C_1ANT_PHASE_2G_RUNTIME);
5469 		} else {
5470 
5471 			halbtc8821c1ant_set_ant_path(btcoexist,
5472 						BTC_ANT_PATH_AUTO,
5473 						FORCE_EXEC,
5474 						BT_8821C_1ANT_PHASE_WLAN_OFF);
5475 		}
5476 
5477 		btcoexist->stop_coex_dm = TRUE;
5478 	} else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
5479 
5480 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5481 			    "[BTCoex], Pnp notify to WAKE UP\n");
5482 		BTC_TRACE(trace_buf);
5483 #if 0
5484 		halbtc8821c1ant_post_state_to_bt(btcoexist,
5485 					 BT_8821C_1ANT_SCOREBOARD_ACTIVE |
5486 					 BT_8821C_1ANT_SCOREBOARD_ONOFF,
5487 					 TRUE);
5488 #endif
5489 		btcoexist->stop_coex_dm = FALSE;
5490 	}
5491 }
5492 
5493 
ex_halbtc8821c1ant_coex_dm_reset(IN struct btc_coexist * btcoexist)5494 void ex_halbtc8821c1ant_coex_dm_reset(IN struct btc_coexist *btcoexist)
5495 {
5496 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5497 		"[BTCoex], *****************Coex DM Reset*****************\n");
5498 	BTC_TRACE(trace_buf);
5499 
5500 	halbtc8821c1ant_init_hw_config(btcoexist, FALSE, FALSE);
5501 	halbtc8821c1ant_init_coex_dm(btcoexist);
5502 }
5503 
ex_halbtc8821c1ant_periodical(IN struct btc_coexist * btcoexist)5504 void ex_halbtc8821c1ant_periodical(IN struct btc_coexist *btcoexist)
5505 {
5506 
5507 	struct  btc_board_info	*board_info = &btcoexist->board_info;
5508 	boolean wifi_busy = FALSE;
5509 	u16 bt_scoreboard_val = 0;
5510 	boolean bt_relink_finish = FALSE;
5511 
5512 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5513 		    "[BTCoex], ************* Periodical *************\n");
5514 	BTC_TRACE(trace_buf);
5515 
5516 #if (BT_AUTO_REPORT_ONLY_8821C_1ANT == 0)
5517 	halbtc8821c1ant_query_bt_info(btcoexist);
5518 
5519 #endif
5520 
5521 	halbtc8821c1ant_monitor_bt_ctr(btcoexist);
5522 	halbtc8821c1ant_monitor_wifi_ctr(btcoexist);
5523 
5524 	halbtc8821c1ant_monitor_bt_enable_disable(btcoexist);
5525 
5526 #if 0
5527 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
5528 
5529 	/* halbtc8821c1ant_read_score_board(btcoexist, &bt_scoreboard_val); */
5530 
5531 	if (wifi_busy) {
5532 		halbtc8821c1ant_post_state_to_bt(btcoexist,
5533 				BT_8821C_1ANT_SCOREBOARD_UNDERTEST, TRUE);
5534 		/*
5535 		halbtc8821c1ant_post_state_to_bt(btcoexist,
5536 					 BT_8821C_1ANT_SCOREBOARD_WLBUSY, TRUE);
5537 
5538 		if (bt_scoreboard_val & BIT(6))
5539 			halbtc8821c1ant_query_bt_info(btcoexist); */
5540 	} else {
5541 		halbtc8821c1ant_post_state_to_bt(btcoexist,
5542 					BT_8821C_1ANT_SCOREBOARD_UNDERTEST, FALSE);
5543 	}
5544 #endif
5545 
5546 	if (coex_sta->bt_relink_downcount != 0) {
5547 		coex_sta->bt_relink_downcount--;
5548 
5549 		if (coex_sta->bt_relink_downcount == 0) {
5550 			coex_sta->is_setupLink = FALSE;
5551 			bt_relink_finish = TRUE;
5552 
5553 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5554 				"[BTCoex], Re-Link stop by periodical count-down!!\n");
5555 			BTC_TRACE(trace_buf);
5556 		}
5557 	}
5558 
5559 	/* for 4-way, DHCP, EAPOL packet */
5560 	if (coex_sta->specific_pkt_period_cnt > 0) {
5561 
5562 		coex_sta->specific_pkt_period_cnt--;
5563 
5564 		if ((coex_sta->specific_pkt_period_cnt == 0) &&
5565 		    (coex_sta->wifi_is_high_pri_task))
5566 			coex_sta->wifi_is_high_pri_task = FALSE;
5567 
5568 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5569 			    "[BTCoex], ***************** Hi-Pri Task = %s\n",
5570 			    (coex_sta->wifi_is_high_pri_task ? "Yes" :
5571 			     "No"));
5572 		BTC_TRACE(trace_buf);
5573 
5574 	}
5575 
5576 	if (halbtc8821c1ant_is_wifibt_status_changed(btcoexist) || (bt_relink_finish)
5577 		|| (coex_sta->is_set_ps_state_fail))
5578 		halbtc8821c1ant_run_coexist_mechanism(btcoexist);
5579 
5580 }
5581 
5582 /*#pragma optimize( "", off )*/
ex_halbtc8821c1ant_antenna_detection(IN struct btc_coexist * btcoexist,IN u32 cent_freq,IN u32 offset,IN u32 span,IN u32 seconds)5583 void ex_halbtc8821c1ant_antenna_detection(IN struct btc_coexist *btcoexist,
5584 		IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
5585 {
5586 
5587 }
5588 
5589 
ex_halbtc8821c1ant_display_ant_detection(IN struct btc_coexist * btcoexist)5590 void ex_halbtc8821c1ant_display_ant_detection(IN struct btc_coexist *btcoexist)
5591 {
5592 
5593 }
5594 
ex_halbtc8821c1ant_antenna_isolation(IN struct btc_coexist * btcoexist,IN u32 cent_freq,IN u32 offset,IN u32 span,IN u32 seconds)5595 void ex_halbtc8821c1ant_antenna_isolation(IN struct btc_coexist *btcoexist,
5596 		IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
5597 {
5598 
5599 
5600 }
5601 
ex_halbtc8821c1ant_psd_scan(IN struct btc_coexist * btcoexist,IN u32 cent_freq,IN u32 offset,IN u32 span,IN u32 seconds)5602 void ex_halbtc8821c1ant_psd_scan(IN struct btc_coexist *btcoexist,
5603 		 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
5604 {
5605 
5606 
5607 }
5608 
5609 
5610 #endif
5611 
5612 #endif	/* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */
5613 
5614 
5615