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