xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8723bu/hal/btc/HalBtc8812a2Ant.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* ************************************************************
3  * Description:
4  *
5  * This file is for RTL8812A Co-exist mechanism
6  *
7  * History
8  * 2012/08/22 Cosa first check in.
9  * 2012/11/14 Cosa Revise for 8812A 2Ant out sourcing.
10  *
11  * ************************************************************ */
12 
13 /* ************************************************************
14  * include files
15  * ************************************************************ */
16 #include "Mp_Precomp.h"
17 
18 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
19 
20 #if (RTL8812A_SUPPORT == 1)
21 /* ************************************************************
22  * Global variables, these are static variables
23  * ************************************************************ */
24 static u8	 *trace_buf = &gl_btc_trace_buf[0];
25 static struct  coex_dm_8812a_2ant	glcoex_dm_8812a_2ant;
26 static struct  coex_dm_8812a_2ant	*coex_dm = &glcoex_dm_8812a_2ant;
27 static struct  coex_sta_8812a_2ant	glcoex_sta_8812a_2ant;
28 static struct  coex_sta_8812a_2ant	*coex_sta = &glcoex_sta_8812a_2ant;
29 
30 const char *const glbt_info_src_8812a_2ant[] = {
31 	"BT Info[wifi fw]",
32 	"BT Info[bt rsp]",
33 	"BT Info[bt auto report]",
34 };
35 
36 u32	glcoex_ver_date_8812a_2ant = 20150724;
37 u32	glcoex_ver_8812a_2ant = 0x37;
38 
39 /* ************************************************************
40  * local function proto type if needed
41  * ************************************************************
42  * ************************************************************
43  * local function start with halbtc8812a2ant_
44  * ************************************************************ */
halbtc8812a2ant_bt_rssi_state(u8 level_num,u8 rssi_thresh,u8 rssi_thresh1)45 u8 halbtc8812a2ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
46 {
47 	s32			bt_rssi = 0;
48 	u8			bt_rssi_state = coex_sta->pre_bt_rssi_state;
49 
50 	bt_rssi = coex_sta->bt_rssi;
51 
52 	if (level_num == 2) {
53 		if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
54 		    (coex_sta->pre_bt_rssi_state ==
55 		     BTC_RSSI_STATE_STAY_LOW)) {
56 			if (bt_rssi >= (rssi_thresh +
57 					BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
58 				bt_rssi_state = BTC_RSSI_STATE_HIGH;
59 			else
60 				bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
61 		} else {
62 			if (bt_rssi < rssi_thresh)
63 				bt_rssi_state = BTC_RSSI_STATE_LOW;
64 			else
65 				bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
66 		}
67 	} else if (level_num == 3) {
68 		if (rssi_thresh > rssi_thresh1) {
69 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
70 				    "[BTCoex], BT Rssi thresh error!!\n");
71 			BTC_TRACE(trace_buf);
72 			return coex_sta->pre_bt_rssi_state;
73 		}
74 
75 		if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
76 		    (coex_sta->pre_bt_rssi_state ==
77 		     BTC_RSSI_STATE_STAY_LOW)) {
78 			if (bt_rssi >= (rssi_thresh +
79 					BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
80 				bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
81 			else
82 				bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
83 		} else if ((coex_sta->pre_bt_rssi_state ==
84 			    BTC_RSSI_STATE_MEDIUM) ||
85 			   (coex_sta->pre_bt_rssi_state ==
86 			    BTC_RSSI_STATE_STAY_MEDIUM)) {
87 			if (bt_rssi >= (rssi_thresh1 +
88 					BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
89 				bt_rssi_state = BTC_RSSI_STATE_HIGH;
90 			else if (bt_rssi < rssi_thresh)
91 				bt_rssi_state = BTC_RSSI_STATE_LOW;
92 			else
93 				bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
94 		} else {
95 			if (bt_rssi < rssi_thresh1)
96 				bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
97 			else
98 				bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
99 		}
100 	}
101 
102 	coex_sta->pre_bt_rssi_state = bt_rssi_state;
103 
104 	return bt_rssi_state;
105 }
106 
halbtc8812a2ant_wifi_rssi_state(IN struct btc_coexist * btcoexist,IN u8 index,IN u8 level_num,IN u8 rssi_thresh,IN u8 rssi_thresh1)107 u8 halbtc8812a2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
108 	   IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
109 {
110 	s32			wifi_rssi = 0;
111 	u8			wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
112 
113 	btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
114 
115 	if (level_num == 2) {
116 		if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
117 		    ||
118 		    (coex_sta->pre_wifi_rssi_state[index] ==
119 		     BTC_RSSI_STATE_STAY_LOW)) {
120 			if (wifi_rssi >= (rssi_thresh +
121 					  BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
122 				wifi_rssi_state = BTC_RSSI_STATE_HIGH;
123 			else
124 				wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
125 		} else {
126 			if (wifi_rssi < rssi_thresh)
127 				wifi_rssi_state = BTC_RSSI_STATE_LOW;
128 			else
129 				wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
130 		}
131 	} else if (level_num == 3) {
132 		if (rssi_thresh > rssi_thresh1) {
133 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
134 				    "[BTCoex], wifi RSSI thresh error!!\n");
135 			BTC_TRACE(trace_buf);
136 			return coex_sta->pre_wifi_rssi_state[index];
137 		}
138 
139 		if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
140 		    ||
141 		    (coex_sta->pre_wifi_rssi_state[index] ==
142 		     BTC_RSSI_STATE_STAY_LOW)) {
143 			if (wifi_rssi >= (rssi_thresh +
144 					  BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
145 				wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
146 			else
147 				wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
148 		} else if ((coex_sta->pre_wifi_rssi_state[index] ==
149 			    BTC_RSSI_STATE_MEDIUM) ||
150 			   (coex_sta->pre_wifi_rssi_state[index] ==
151 			    BTC_RSSI_STATE_STAY_MEDIUM)) {
152 			if (wifi_rssi >= (rssi_thresh1 +
153 					  BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
154 				wifi_rssi_state = BTC_RSSI_STATE_HIGH;
155 			else if (wifi_rssi < rssi_thresh)
156 				wifi_rssi_state = BTC_RSSI_STATE_LOW;
157 			else
158 				wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
159 		} else {
160 			if (wifi_rssi < rssi_thresh1)
161 				wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
162 			else
163 				wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
164 		}
165 	}
166 
167 	coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
168 
169 	return wifi_rssi_state;
170 }
171 
halbtc8812a2ant_monitor_bt_enable_disable(IN struct btc_coexist * btcoexist)172 void halbtc8812a2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
173 {
174 	struct  btc_stack_info	*stack_info = &btcoexist->stack_info;
175 	static u32	bt_disable_cnt = 0;
176 	boolean			bt_active = true, bt_disabled = false;
177 
178 	/* This function check if bt is disabled */
179 
180 	/* only 8812a need to consider if core stack is installed. */
181 	if (!stack_info->hci_version)
182 		bt_active = false;
183 
184 	if (coex_sta->high_priority_tx == 0 &&
185 	    coex_sta->high_priority_rx == 0 &&
186 	    coex_sta->low_priority_tx == 0 &&
187 	    coex_sta->low_priority_rx == 0)
188 		bt_active = false;
189 	if (coex_sta->high_priority_tx == 0xffff &&
190 	    coex_sta->high_priority_rx == 0xffff &&
191 	    coex_sta->low_priority_tx == 0xffff &&
192 	    coex_sta->low_priority_rx == 0xffff)
193 		bt_active = false;
194 	if (bt_active) {
195 		bt_disable_cnt = 0;
196 		bt_disabled = false;
197 		btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
198 				   &bt_disabled);
199 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
200 			    "[BTCoex], BT is enabled !!\n");
201 		BTC_TRACE(trace_buf);
202 	} else {
203 		bt_disable_cnt++;
204 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
205 			    "[BTCoex], bt is detected as disabled %d times!!\n",
206 			    bt_disable_cnt);
207 		BTC_TRACE(trace_buf);
208 		if (bt_disable_cnt >= 2) {
209 			bt_disabled = true;
210 			btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
211 					   &bt_disabled);
212 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
213 				    "[BTCoex], BT is disabled !!\n");
214 			BTC_TRACE(trace_buf);
215 		}
216 	}
217 	if (coex_sta->bt_disabled != bt_disabled) {
218 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
219 			    "[BTCoex], BT is from %s to %s!!\n",
220 			    (coex_sta->bt_disabled ? "disabled" : "enabled"),
221 			    (bt_disabled ? "disabled" : "enabled"));
222 		BTC_TRACE(trace_buf);
223 		coex_sta->bt_disabled = bt_disabled;
224 		if (!bt_disabled) {
225 		} else {
226 		}
227 	}
228 }
229 
halbtc8812a2ant_decide_ra_mask(IN struct btc_coexist * btcoexist,IN u32 ra_mask_type)230 u32 halbtc8812a2ant_decide_ra_mask(IN struct btc_coexist *btcoexist,
231 				   IN u32 ra_mask_type)
232 {
233 	u32	dis_ra_mask = 0x0;
234 
235 	switch (ra_mask_type) {
236 	case 0: /* normal mode */
237 		dis_ra_mask = 0x0;
238 		break;
239 	case 1: /* disable cck 1/2 */
240 		dis_ra_mask = 0x00000003;
241 		break;
242 	case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4			 */
243 		dis_ra_mask = 0x0001f1f7;
244 		break;
245 	default:
246 		break;
247 	}
248 
249 	return dis_ra_mask;
250 }
251 
halbtc8812a2ant_update_ra_mask(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u32 dis_rate_mask)252 void halbtc8812a2ant_update_ra_mask(IN struct btc_coexist *btcoexist,
253 				    IN boolean force_exec, IN u32 dis_rate_mask)
254 {
255 	coex_dm->cur_ra_mask = dis_rate_mask;
256 
257 	if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
258 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
259 				   &coex_dm->cur_ra_mask);
260 	coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
261 }
262 
halbtc8812a2ant_auto_rate_fallback_retry(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)263 void halbtc8812a2ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
264 		IN boolean force_exec, IN u8 type)
265 {
266 	boolean	wifi_under_b_mode = false;
267 
268 	coex_dm->cur_arfr_type = type;
269 
270 	if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
271 		switch (coex_dm->cur_arfr_type) {
272 		case 0:	/* normal mode */
273 			btcoexist->btc_write_4byte(btcoexist, 0x430,
274 						   coex_dm->backup_arfr_cnt1);
275 			btcoexist->btc_write_4byte(btcoexist, 0x434,
276 						   coex_dm->backup_arfr_cnt2);
277 			break;
278 		case 1:
279 			btcoexist->btc_get(btcoexist,
280 					   BTC_GET_BL_WIFI_UNDER_B_MODE,
281 					   &wifi_under_b_mode);
282 			if (wifi_under_b_mode) {
283 				btcoexist->btc_write_4byte(btcoexist,
284 							   0x430, 0x0);
285 				btcoexist->btc_write_4byte(btcoexist,
286 							   0x434, 0x01010101);
287 			} else {
288 				btcoexist->btc_write_4byte(btcoexist,
289 							   0x430, 0x0);
290 				btcoexist->btc_write_4byte(btcoexist,
291 							   0x434, 0x04030201);
292 			}
293 			break;
294 		default:
295 			break;
296 		}
297 	}
298 
299 	coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
300 }
301 
halbtc8812a2ant_retry_limit(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)302 void halbtc8812a2ant_retry_limit(IN struct btc_coexist *btcoexist,
303 				 IN boolean force_exec, IN u8 type)
304 {
305 	coex_dm->cur_retry_limit_type = type;
306 
307 	if (force_exec ||
308 	    (coex_dm->pre_retry_limit_type !=
309 	     coex_dm->cur_retry_limit_type)) {
310 		switch (coex_dm->cur_retry_limit_type) {
311 		case 0:	/* normal mode */
312 			btcoexist->btc_write_2byte(btcoexist, 0x42a,
313 						   coex_dm->backup_retry_limit);
314 			break;
315 		case 1:	/* retry limit=8 */
316 			btcoexist->btc_write_2byte(btcoexist, 0x42a,
317 						   0x0808);
318 			break;
319 		default:
320 			break;
321 		}
322 	}
323 
324 	coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
325 }
326 
halbtc8812a2ant_ampdu_max_time(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)327 void halbtc8812a2ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
328 				    IN boolean force_exec, IN u8 type)
329 {
330 	coex_dm->cur_ampdu_time_type = type;
331 
332 	if (force_exec ||
333 	    (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
334 		switch (coex_dm->cur_ampdu_time_type) {
335 		case 0:	/* normal mode */
336 			btcoexist->btc_write_1byte(btcoexist, 0x456,
337 					   coex_dm->backup_ampdu_max_time);
338 			break;
339 		case 1:	/* AMPDU timw = 0x38 * 32us */
340 			btcoexist->btc_write_1byte(btcoexist, 0x456,
341 						   0x38);
342 			break;
343 		default:
344 			break;
345 		}
346 	}
347 
348 	coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
349 }
350 
halbtc8812a2ant_limited_tx(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 ra_mask_type,IN u8 arfr_type,IN u8 retry_limit_type,IN u8 ampdu_time_type)351 void halbtc8812a2ant_limited_tx(IN struct btc_coexist *btcoexist,
352 		IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
353 				IN u8 retry_limit_type, IN u8 ampdu_time_type)
354 {
355 	u32	dis_ra_mask = 0x0;
356 
357 	coex_dm->cur_ra_mask_type = ra_mask_type;
358 	dis_ra_mask = halbtc8812a2ant_decide_ra_mask(btcoexist, ra_mask_type);
359 	halbtc8812a2ant_update_ra_mask(btcoexist, force_exec, dis_ra_mask);
360 
361 	halbtc8812a2ant_auto_rate_fallback_retry(btcoexist, force_exec,
362 			arfr_type);
363 	halbtc8812a2ant_retry_limit(btcoexist, force_exec, retry_limit_type);
364 	halbtc8812a2ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
365 }
366 
halbtc8812a2ant_limited_rx(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean rej_ap_agg_pkt,IN boolean bt_ctrl_agg_buf_size,IN u8 agg_buf_size)367 void halbtc8812a2ant_limited_rx(IN struct btc_coexist *btcoexist,
368 			IN boolean force_exec, IN boolean rej_ap_agg_pkt,
369 			IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
370 {
371 	boolean	reject_rx_agg = rej_ap_agg_pkt;
372 	boolean	bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
373 	u8	rx_agg_size = agg_buf_size;
374 
375 	/* ============================================ */
376 	/*	Rx Aggregation related setting */
377 	/* ============================================ */
378 	btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
379 			   &reject_rx_agg);
380 	/* decide BT control aggregation buf size or not */
381 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
382 			   &bt_ctrl_rx_agg_size);
383 	/* aggregation buf size, only work when BT control Rx aggregation size. */
384 	btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
385 	/* real update aggregation setting */
386 	btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
387 
388 
389 }
390 
halbtc8812a2ant_monitor_bt_ctr(IN struct btc_coexist * btcoexist)391 void halbtc8812a2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
392 {
393 	u32			reg_hp_txrx, reg_lp_txrx, u32tmp;
394 	u32			reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
395 
396 	reg_hp_txrx = 0x770;
397 	reg_lp_txrx = 0x774;
398 
399 	u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
400 	reg_hp_tx = u32tmp & MASKLWORD;
401 	reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
402 
403 	u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
404 	reg_lp_tx = u32tmp & MASKLWORD;
405 	reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
406 
407 	coex_sta->high_priority_tx = reg_hp_tx;
408 	coex_sta->high_priority_rx = reg_hp_rx;
409 	coex_sta->low_priority_tx = reg_lp_tx;
410 	coex_sta->low_priority_rx = reg_lp_rx;
411 
412 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
413 		"[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
414 		    reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx);
415 	BTC_TRACE(trace_buf);
416 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
417 		"[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
418 		    reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx);
419 	BTC_TRACE(trace_buf);
420 
421 	/* reset counter */
422 	btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
423 }
424 
halbtc8812a2ant_query_bt_info(IN struct btc_coexist * btcoexist)425 void halbtc8812a2ant_query_bt_info(IN struct btc_coexist *btcoexist)
426 {
427 	u8	data_len = 3;
428 	u8	buf[5] = {0};
429 
430 	if (!coex_sta->bt_disabled) {
431 		if (!coex_sta->bt_info_query_cnt ||
432 		    (coex_sta->bt_info_c2h_cnt[BT_INFO_SRC_8812A_2ANT_BT_RSP]
433 		     - coex_sta->bt_info_query_cnt) > 2) {
434 			buf[0] = data_len;
435 			buf[1] = 0x1;	/* polling enable, 1=enable, 0=disable */
436 			buf[2] = 0x2;	/* polling time in seconds */
437 			buf[3] = 0x1;	/* auto report enable, 1=enable, 0=disable */
438 
439 			btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_INFO,
440 					   (void *)&buf[0]);
441 		}
442 	}
443 	coex_sta->bt_info_query_cnt++;
444 }
445 
halbtc8812a2ant_is_wifi_status_changed(IN struct btc_coexist * btcoexist)446 boolean halbtc8812a2ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
447 {
448 	static boolean	pre_wifi_busy = false, pre_under_4way = false,
449 			pre_bt_hs_on = false;
450 	boolean	wifi_busy = false, under_4way = false, bt_hs_on = false;
451 	boolean	wifi_connected = false;
452 
453 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
454 			   &wifi_connected);
455 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
456 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
457 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
458 			   &under_4way);
459 
460 	if (wifi_connected) {
461 		if (wifi_busy != pre_wifi_busy) {
462 			pre_wifi_busy = wifi_busy;
463 			return true;
464 		}
465 		if (under_4way != pre_under_4way) {
466 			pre_under_4way = under_4way;
467 			return true;
468 		}
469 		if (bt_hs_on != pre_bt_hs_on) {
470 			pre_bt_hs_on = bt_hs_on;
471 			return true;
472 		}
473 	}
474 
475 	return false;
476 }
477 
halbtc8812a2ant_update_bt_link_info(IN struct btc_coexist * btcoexist)478 void halbtc8812a2ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
479 {
480 	struct  btc_bt_link_info	*bt_link_info = &btcoexist->bt_link_info;
481 	boolean				bt_hs_on = false;
482 
483 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
484 
485 	bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
486 	bt_link_info->sco_exist = coex_sta->sco_exist;
487 	bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
488 	bt_link_info->pan_exist = coex_sta->pan_exist;
489 	bt_link_info->hid_exist = coex_sta->hid_exist;
490 	bt_link_info->acl_busy = coex_sta->acl_busy;
491 
492 	/* work around for HS mode. */
493 	if (bt_hs_on) {
494 		bt_link_info->pan_exist = true;
495 		bt_link_info->bt_link_exist = true;
496 	}
497 
498 	/* check if Sco only */
499 	if (bt_link_info->sco_exist &&
500 	    !bt_link_info->a2dp_exist &&
501 	    !bt_link_info->pan_exist &&
502 	    !bt_link_info->hid_exist)
503 		bt_link_info->sco_only = true;
504 	else
505 		bt_link_info->sco_only = false;
506 
507 	/* check if A2dp only */
508 	if (!bt_link_info->sco_exist &&
509 	    bt_link_info->a2dp_exist &&
510 	    !bt_link_info->pan_exist &&
511 	    !bt_link_info->hid_exist)
512 		bt_link_info->a2dp_only = true;
513 	else
514 		bt_link_info->a2dp_only = false;
515 
516 	/* check if Pan only */
517 	if (!bt_link_info->sco_exist &&
518 	    !bt_link_info->a2dp_exist &&
519 	    bt_link_info->pan_exist &&
520 	    !bt_link_info->hid_exist)
521 		bt_link_info->pan_only = true;
522 	else
523 		bt_link_info->pan_only = false;
524 
525 	/* check if Hid only */
526 	if (!bt_link_info->sco_exist &&
527 	    !bt_link_info->a2dp_exist &&
528 	    !bt_link_info->pan_exist &&
529 	    bt_link_info->hid_exist)
530 		bt_link_info->hid_only = true;
531 	else
532 		bt_link_info->hid_only = false;
533 }
534 
halbtc8812a2ant_action_algorithm(IN struct btc_coexist * btcoexist)535 u8 halbtc8812a2ant_action_algorithm(IN struct btc_coexist *btcoexist)
536 {
537 	struct  btc_bt_link_info	*bt_link_info = &btcoexist->bt_link_info;
538 	struct  btc_stack_info	*stack_info = &btcoexist->stack_info;
539 	boolean				bt_hs_on = false;
540 	u8				algorithm = BT_8812A_2ANT_COEX_ALGO_UNDEFINED;
541 	u8				num_of_diff_profile = 0;
542 
543 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
544 
545 	if (!bt_link_info->bt_link_exist) {
546 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
547 			    "[BTCoex], No BT link exists!!!\n");
548 		BTC_TRACE(trace_buf);
549 		return algorithm;
550 	}
551 
552 	if (bt_link_info->sco_exist)
553 		num_of_diff_profile++;
554 	if (bt_link_info->hid_exist)
555 		num_of_diff_profile++;
556 	if (bt_link_info->pan_exist)
557 		num_of_diff_profile++;
558 	if (bt_link_info->a2dp_exist)
559 		num_of_diff_profile++;
560 
561 	if (num_of_diff_profile == 0) {
562 		if (bt_link_info->acl_busy) {
563 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
564 				    "[BTCoex], ACL Busy only\n");
565 			BTC_TRACE(trace_buf);
566 			algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR;
567 		}
568 	} else if (num_of_diff_profile == 1) {
569 		if (bt_link_info->sco_exist) {
570 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
571 				    "[BTCoex], SCO only\n");
572 			BTC_TRACE(trace_buf);
573 			algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
574 		} else {
575 			if (bt_link_info->hid_exist) {
576 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
577 					    "[BTCoex], HID only\n");
578 				BTC_TRACE(trace_buf);
579 				algorithm = BT_8812A_2ANT_COEX_ALGO_HID;
580 			} else if (bt_link_info->a2dp_exist) {
581 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
582 					    "[BTCoex], A2DP only\n");
583 				BTC_TRACE(trace_buf);
584 				algorithm = BT_8812A_2ANT_COEX_ALGO_A2DP;
585 			} else if (bt_link_info->pan_exist) {
586 				if (bt_hs_on) {
587 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
588 						    "[BTCoex], PAN(HS) only\n");
589 					BTC_TRACE(trace_buf);
590 					algorithm =
591 						BT_8812A_2ANT_COEX_ALGO_PANHS;
592 				} else {
593 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
594 						"[BTCoex], PAN(EDR) only\n");
595 					BTC_TRACE(trace_buf);
596 					algorithm =
597 						BT_8812A_2ANT_COEX_ALGO_PANEDR;
598 				}
599 			}
600 		}
601 	} else if (num_of_diff_profile == 2) {
602 		if (bt_link_info->sco_exist) {
603 			if (bt_link_info->hid_exist) {
604 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
605 					    "[BTCoex], SCO + HID\n");
606 				BTC_TRACE(trace_buf);
607 				algorithm = BT_8812A_2ANT_COEX_ALGO_SCO_HID;
608 			} else if (bt_link_info->a2dp_exist) {
609 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
610 					    "[BTCoex], SCO + A2DP ==> SCO\n");
611 				BTC_TRACE(trace_buf);
612 				algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
613 			} else if (bt_link_info->pan_exist) {
614 				if (bt_hs_on) {
615 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
616 						"[BTCoex], SCO + PAN(HS)\n");
617 					BTC_TRACE(trace_buf);
618 					algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
619 				} else {
620 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
621 						"[BTCoex], SCO + PAN(EDR)\n");
622 					BTC_TRACE(trace_buf);
623 					algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
624 				}
625 			}
626 		} else {
627 			if (bt_link_info->hid_exist &&
628 			    bt_link_info->a2dp_exist) {
629 				if (stack_info->num_of_hid >= 2) {
630 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
631 						    "[BTCoex], HID*2 + A2DP\n");
632 					BTC_TRACE(trace_buf);
633 					algorithm =
634 						BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
635 				} else {
636 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
637 						    "[BTCoex], HID + A2DP\n");
638 					BTC_TRACE(trace_buf);
639 					algorithm =
640 						BT_8812A_2ANT_COEX_ALGO_HID_A2DP;
641 				}
642 			} else if (bt_link_info->hid_exist &&
643 				   bt_link_info->pan_exist) {
644 				if (bt_hs_on) {
645 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
646 						"[BTCoex], HID + PAN(HS)\n");
647 					BTC_TRACE(trace_buf);
648 					algorithm =
649 						BT_8812A_2ANT_COEX_ALGO_HID;
650 				} else {
651 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
652 						"[BTCoex], HID + PAN(EDR)\n");
653 					BTC_TRACE(trace_buf);
654 					algorithm =
655 						BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
656 				}
657 			} else if (bt_link_info->pan_exist &&
658 				   bt_link_info->a2dp_exist) {
659 				if (bt_hs_on) {
660 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
661 						"[BTCoex], A2DP + PAN(HS)\n");
662 					BTC_TRACE(trace_buf);
663 					algorithm =
664 						BT_8812A_2ANT_COEX_ALGO_A2DP_PANHS;
665 				} else {
666 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
667 						"[BTCoex], A2DP + PAN(EDR)\n");
668 					BTC_TRACE(trace_buf);
669 					algorithm =
670 						BT_8812A_2ANT_COEX_ALGO_PANEDR_A2DP;
671 				}
672 			}
673 		}
674 	} else if (num_of_diff_profile == 3) {
675 		if (bt_link_info->sco_exist) {
676 			if (bt_link_info->hid_exist &&
677 			    bt_link_info->a2dp_exist) {
678 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
679 					"[BTCoex], SCO + HID + A2DP ==> HID\n");
680 				BTC_TRACE(trace_buf);
681 				algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
682 			} else if (bt_link_info->hid_exist &&
683 				   bt_link_info->pan_exist) {
684 				if (bt_hs_on) {
685 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
686 						"[BTCoex], SCO + HID + PAN(HS)\n");
687 					BTC_TRACE(trace_buf);
688 					algorithm =
689 						BT_8812A_2ANT_COEX_ALGO_SCO_HID;
690 				} else {
691 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
692 						"[BTCoex], SCO + HID + PAN(EDR)\n");
693 					BTC_TRACE(trace_buf);
694 					algorithm =
695 						BT_8812A_2ANT_COEX_ALGO_SCO_HID;
696 				}
697 			} else if (bt_link_info->pan_exist &&
698 				   bt_link_info->a2dp_exist) {
699 				if (bt_hs_on) {
700 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
701 						"[BTCoex], SCO + A2DP + PAN(HS)\n");
702 					BTC_TRACE(trace_buf);
703 					algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
704 				} else {
705 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
706 						"[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
707 					BTC_TRACE(trace_buf);
708 					algorithm =
709 						BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
710 				}
711 			}
712 		} else {
713 			if (bt_link_info->hid_exist &&
714 			    bt_link_info->pan_exist &&
715 			    bt_link_info->a2dp_exist) {
716 				if (bt_hs_on) {
717 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
718 						"[BTCoex], HID + A2DP + PAN(HS)\n");
719 					BTC_TRACE(trace_buf);
720 					algorithm =
721 						BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANHS;
722 				} else {
723 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
724 						"[BTCoex], HID + A2DP + PAN(EDR)\n");
725 					BTC_TRACE(trace_buf);
726 					algorithm =
727 						BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
728 				}
729 			}
730 		}
731 	} else if (num_of_diff_profile >= 3) {
732 		if (bt_link_info->sco_exist) {
733 			if (bt_link_info->hid_exist &&
734 			    bt_link_info->pan_exist &&
735 			    bt_link_info->a2dp_exist) {
736 				if (bt_hs_on) {
737 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
738 						"[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
739 					BTC_TRACE(trace_buf);
740 				} else {
741 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
742 						"[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
743 					BTC_TRACE(trace_buf);
744 					algorithm =
745 						BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
746 				}
747 			}
748 		}
749 	}
750 
751 	return algorithm;
752 }
753 
halbtc8812a2ant_set_fw_dac_swing_level(IN struct btc_coexist * btcoexist,IN u8 dac_swing_lvl)754 void halbtc8812a2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist,
755 		IN u8 dac_swing_lvl)
756 {
757 	u8			h2c_parameter[1] = {0};
758 
759 	/* There are several type of dacswing */
760 	/* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */
761 	h2c_parameter[0] = dac_swing_lvl;
762 
763 	btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
764 }
765 
halbtc8812a2ant_set_fw_dec_bt_pwr(IN struct btc_coexist * btcoexist,IN u8 dec_bt_pwr_lvl)766 void halbtc8812a2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist,
767 				       IN u8 dec_bt_pwr_lvl)
768 {
769 	u8	data_len = 4;
770 	u8	buf[6] = {0};
771 
772 	buf[0] = data_len;
773 	buf[1] = 0x3;		/* OP_Code */
774 	buf[2] = 0x2;		/* OP_Code_Length */
775 	if (dec_bt_pwr_lvl)
776 		buf[3] = 0x1;	/* OP_Code_Content */
777 	else
778 		buf[3] = 0x0;
779 	buf[4] = dec_bt_pwr_lvl;/* pwr_level */
780 
781 	btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
782 			   (void *)&buf[0]);
783 }
784 
halbtc8812a2ant_dec_bt_pwr(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 dec_bt_pwr_lvl)785 void halbtc8812a2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist,
786 				IN boolean force_exec, IN u8 dec_bt_pwr_lvl)
787 {
788 	coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl;
789 
790 	if (!force_exec) {
791 		if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl)
792 			return;
793 	}
794 	halbtc8812a2ant_set_fw_dec_bt_pwr(btcoexist,
795 					  coex_dm->cur_bt_dec_pwr_lvl);
796 
797 	coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl;
798 }
799 
halbtc8812a2ant_fw_dac_swing_lvl(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 fw_dac_swing_lvl)800 void halbtc8812a2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist,
801 			      IN boolean force_exec, IN u8 fw_dac_swing_lvl)
802 {
803 	coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
804 
805 	if (!force_exec) {
806 		if (coex_dm->pre_fw_dac_swing_lvl ==
807 		    coex_dm->cur_fw_dac_swing_lvl)
808 			return;
809 	}
810 
811 	halbtc8812a2ant_set_fw_dac_swing_level(btcoexist,
812 					       coex_dm->cur_fw_dac_swing_lvl);
813 
814 	coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
815 }
816 
halbtc8812a2ant_set_sw_rf_rx_lpf_corner(IN struct btc_coexist * btcoexist,IN boolean rx_rf_shrink_on)817 void halbtc8812a2ant_set_sw_rf_rx_lpf_corner(IN struct btc_coexist *btcoexist,
818 		IN boolean rx_rf_shrink_on)
819 {
820 	if (rx_rf_shrink_on) {
821 		/* Shrink RF Rx LPF corner */
822 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
823 			    "[BTCoex], Shrink RF Rx LPF corner!!\n");
824 		BTC_TRACE(trace_buf);
825 		btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff,
826 					  0xffffc);
827 	} else {
828 		/* Resume RF Rx LPF corner */
829 		/* After initialized, we can use coex_dm->bt_rf_0x1e_backup */
830 		if (btcoexist->initilized) {
831 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
832 				    "[BTCoex], Resume RF Rx LPF corner!!\n");
833 			BTC_TRACE(trace_buf);
834 			btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
835 					  0xfffff, coex_dm->bt_rf_0x1e_backup);
836 		}
837 	}
838 }
839 
halbtc8812a2ant_rf_shrink(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean rx_rf_shrink_on)840 void halbtc8812a2ant_rf_shrink(IN struct btc_coexist *btcoexist,
841 		       IN boolean force_exec, IN boolean rx_rf_shrink_on)
842 {
843 	coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on;
844 
845 	if (!force_exec) {
846 		if (coex_dm->pre_rf_rx_lpf_shrink ==
847 		    coex_dm->cur_rf_rx_lpf_shrink)
848 			return;
849 	}
850 	halbtc8812a2ant_set_sw_rf_rx_lpf_corner(btcoexist,
851 						coex_dm->cur_rf_rx_lpf_shrink);
852 
853 	coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink;
854 }
855 
halbtc8812a2ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist * btcoexist,IN boolean low_penalty_ra)856 void halbtc8812a2ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
857 		*btcoexist, IN boolean low_penalty_ra)
858 {
859 	u8	tmp_u1;
860 
861 	tmp_u1 = btcoexist->btc_read_1byte(btcoexist, 0x4fd);
862 	tmp_u1 |= BIT(0);
863 	if (low_penalty_ra) {
864 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
865 			    "[BTCoex], Tx rate adaptive, set low penalty!!\n");
866 		BTC_TRACE(trace_buf);
867 		tmp_u1 &= ~BIT(2);
868 	} else {
869 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
870 			    "[BTCoex], Tx rate adaptive, set normal!!\n");
871 		BTC_TRACE(trace_buf);
872 		tmp_u1 |= BIT(2);
873 	}
874 
875 	btcoexist->btc_write_1byte(btcoexist, 0x4fd, tmp_u1);
876 }
877 
halbtc8812a2ant_low_penalty_ra(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean low_penalty_ra)878 void halbtc8812a2ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
879 			    IN boolean force_exec, IN boolean low_penalty_ra)
880 {
881 	return;
882 	coex_dm->cur_low_penalty_ra = low_penalty_ra;
883 
884 	if (!force_exec) {
885 		if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
886 			return;
887 	}
888 	halbtc8812a2ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
889 			coex_dm->cur_low_penalty_ra);
890 
891 	coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
892 }
893 
halbtc8812a2ant_set_dac_swing_reg(IN struct btc_coexist * btcoexist,IN u32 level)894 void halbtc8812a2ant_set_dac_swing_reg(IN struct btc_coexist *btcoexist,
895 				       IN u32 level)
896 {
897 	u8	val = (u8)level;
898 
899 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
900 		    "[BTCoex], Write SwDacSwing = 0x%x\n", level);
901 	BTC_TRACE(trace_buf);
902 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc5b, 0x3e, val);
903 }
904 
halbtc8812a2ant_set_sw_full_time_dac_swing(IN struct btc_coexist * btcoexist,IN boolean sw_dac_swing_on,IN u32 sw_dac_swing_lvl)905 void halbtc8812a2ant_set_sw_full_time_dac_swing(IN struct btc_coexist
906 		*btcoexist, IN boolean sw_dac_swing_on, IN u32 sw_dac_swing_lvl)
907 {
908 	if (sw_dac_swing_on)
909 		halbtc8812a2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl);
910 	else
911 		halbtc8812a2ant_set_dac_swing_reg(btcoexist, 0x18);
912 }
913 
914 
halbtc8812a2ant_dac_swing(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean dac_swing_on,IN u32 dac_swing_lvl)915 void halbtc8812a2ant_dac_swing(IN struct btc_coexist *btcoexist,
916 	IN boolean force_exec, IN boolean dac_swing_on, IN u32 dac_swing_lvl)
917 {
918 	coex_dm->cur_dac_swing_on = dac_swing_on;
919 	coex_dm->cur_dac_swing_lvl = dac_swing_lvl;
920 
921 	if (!force_exec) {
922 		if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) &&
923 		    (coex_dm->pre_dac_swing_lvl ==
924 		     coex_dm->cur_dac_swing_lvl))
925 			return;
926 	}
927 	delay_ms(30);
928 	halbtc8812a2ant_set_sw_full_time_dac_swing(btcoexist, dac_swing_on,
929 			dac_swing_lvl);
930 
931 	coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on;
932 	coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl;
933 }
934 
halbtc8812a2ant_set_adc_back_off(IN struct btc_coexist * btcoexist,IN boolean adc_back_off)935 void halbtc8812a2ant_set_adc_back_off(IN struct btc_coexist *btcoexist,
936 				      IN boolean adc_back_off)
937 {
938 	if (adc_back_off) {
939 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
940 			    "[BTCoex], BB BackOff Level On!\n");
941 		BTC_TRACE(trace_buf);
942 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x3);
943 	} else {
944 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
945 			    "[BTCoex], BB BackOff Level Off!\n");
946 		BTC_TRACE(trace_buf);
947 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x1);
948 	}
949 }
950 
halbtc8812a2ant_adc_back_off(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean adc_back_off)951 void halbtc8812a2ant_adc_back_off(IN struct btc_coexist *btcoexist,
952 			  IN boolean force_exec, IN boolean adc_back_off)
953 {
954 	coex_dm->cur_adc_back_off = adc_back_off;
955 
956 	if (!force_exec) {
957 		if (coex_dm->pre_adc_back_off == coex_dm->cur_adc_back_off)
958 			return;
959 	}
960 	halbtc8812a2ant_set_adc_back_off(btcoexist, coex_dm->cur_adc_back_off);
961 
962 	coex_dm->pre_adc_back_off = coex_dm->cur_adc_back_off;
963 }
964 
halbtc8812a2ant_set_agc_table(IN struct btc_coexist * btcoexist,IN boolean agc_table_en)965 void halbtc8812a2ant_set_agc_table(IN struct btc_coexist *btcoexist,
966 				   IN boolean agc_table_en)
967 {
968 	u8		rssi_adjust_val = 0;
969 
970 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);
971 	if (agc_table_en) {
972 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
973 			    "[BTCoex], Agc Table On!\n");
974 		BTC_TRACE(trace_buf);
975 		btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
976 					  0x28F4B);
977 		btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
978 					  0x10AB2);
979 		rssi_adjust_val = 8;
980 	} else {
981 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
982 			    "[BTCoex], Agc Table Off!\n");
983 		BTC_TRACE(trace_buf);
984 		btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
985 					  0x2884B);
986 		btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
987 					  0x104B2);
988 	}
989 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);
990 
991 	/* set rssi_adjust_val for wifi module. */
992 	btcoexist->btc_set(btcoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON,
993 			   &rssi_adjust_val);
994 }
995 
halbtc8812a2ant_agc_table(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean agc_table_en)996 void halbtc8812a2ant_agc_table(IN struct btc_coexist *btcoexist,
997 			       IN boolean force_exec, IN boolean agc_table_en)
998 {
999 	coex_dm->cur_agc_table_en = agc_table_en;
1000 
1001 	if (!force_exec) {
1002 		if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en)
1003 			return;
1004 	}
1005 	halbtc8812a2ant_set_agc_table(btcoexist, agc_table_en);
1006 
1007 	coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en;
1008 }
1009 
halbtc8812a2ant_set_coex_table(IN struct btc_coexist * btcoexist,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)1010 void halbtc8812a2ant_set_coex_table(IN struct btc_coexist *btcoexist,
1011 	    IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
1012 {
1013 	btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
1014 
1015 	btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
1016 
1017 	btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
1018 
1019 	btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
1020 }
1021 
halbtc8812a2ant_coex_table(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u32 val0x6c0,IN u32 val0x6c4,IN u32 val0x6c8,IN u8 val0x6cc)1022 void halbtc8812a2ant_coex_table(IN struct btc_coexist *btcoexist,
1023 			IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
1024 				IN u32 val0x6c8, IN u8 val0x6cc)
1025 {
1026 	coex_dm->cur_val0x6c0 = val0x6c0;
1027 	coex_dm->cur_val0x6c4 = val0x6c4;
1028 	coex_dm->cur_val0x6c8 = val0x6c8;
1029 	coex_dm->cur_val0x6cc = val0x6cc;
1030 
1031 	if (!force_exec) {
1032 		if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
1033 		    (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
1034 		    (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
1035 		    (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
1036 			return;
1037 	}
1038 	halbtc8812a2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
1039 				       val0x6cc);
1040 
1041 	coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
1042 	coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
1043 	coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
1044 	coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
1045 }
1046 
halbtc8812a2ant_coex_table_with_type(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 type)1047 void halbtc8812a2ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
1048 		IN boolean force_exec, IN u8 type)
1049 {
1050 	switch (type) {
1051 	case 0:
1052 		halbtc8812a2ant_coex_table(btcoexist, force_exec,
1053 				   0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
1054 		break;
1055 	case 1:
1056 		halbtc8812a2ant_coex_table(btcoexist, force_exec,
1057 				   0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
1058 		break;
1059 	case 2:
1060 		halbtc8812a2ant_coex_table(btcoexist, force_exec,
1061 				   0x55555555, 0x5ffb5ffb, 0xffffff, 0x3);
1062 		break;
1063 	case 3:
1064 		halbtc8812a2ant_coex_table(btcoexist, force_exec,
1065 				   0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3);
1066 		break;
1067 	case 4:
1068 		halbtc8812a2ant_coex_table(btcoexist, force_exec,
1069 				   0xdfffdfff, 0x5fdb5fdb, 0xffffff, 0x3);
1070 		break;
1071 	case 5:
1072 		halbtc8812a2ant_coex_table(btcoexist, force_exec,
1073 				   0x5ddd5ddd, 0x5fdb5fdb, 0xffffff, 0x3);
1074 		break;
1075 
1076 	default:
1077 		break;
1078 	}
1079 }
1080 
halbtc8812a2ant_set_fw_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean enable)1081 void halbtc8812a2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1082 		IN boolean enable)
1083 {
1084 	u8	data_len = 3;
1085 	u8	buf[5] = {0};
1086 
1087 	buf[0] = data_len;
1088 	buf[1] = 0x1;			/* OP_Code */
1089 	buf[2] = 0x1;			/* OP_Code_Length */
1090 	if (enable)
1091 		buf[3] = 0x1;		/* OP_Code_Content */
1092 	else
1093 		buf[3] = 0x0;
1094 
1095 	btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
1096 			   (void *)&buf[0]);
1097 }
1098 
halbtc8812a2ant_ignore_wlan_act(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean enable)1099 void halbtc8812a2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
1100 				     IN boolean force_exec, IN boolean enable)
1101 {
1102 	coex_dm->cur_ignore_wlan_act = enable;
1103 
1104 	if (!force_exec) {
1105 		if (coex_dm->pre_ignore_wlan_act ==
1106 		    coex_dm->cur_ignore_wlan_act)
1107 			return;
1108 	}
1109 	halbtc8812a2ant_set_fw_ignore_wlan_act(btcoexist, enable);
1110 
1111 	coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1112 }
1113 
halbtc8812a2ant_set_fw_pstdma(IN struct btc_coexist * btcoexist,IN u8 byte1,IN u8 byte2,IN u8 byte3,IN u8 byte4,IN u8 byte5)1114 void halbtc8812a2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
1115 	   IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
1116 {
1117 	u8			h2c_parameter[5] = {0};
1118 	u8			real_byte1 = byte1, real_byte5 = byte5;
1119 	boolean			ap_enable = false;
1120 
1121 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1122 			   &ap_enable);
1123 
1124 	if (ap_enable) {
1125 		if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1126 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1127 				    "[BTCoex], FW for 1Ant AP mode\n");
1128 			BTC_TRACE(trace_buf);
1129 			real_byte1 &= ~BIT(4);
1130 			real_byte1 |= BIT(5);
1131 
1132 			real_byte5 |= BIT(5);
1133 			real_byte5 &= ~BIT(6);
1134 		}
1135 	}
1136 
1137 	h2c_parameter[0] = real_byte1;
1138 	h2c_parameter[1] = byte2;
1139 	h2c_parameter[2] = byte3;
1140 	h2c_parameter[3] = byte4;
1141 	h2c_parameter[4] = real_byte5;
1142 
1143 
1144 	coex_dm->ps_tdma_para[0] = real_byte1;
1145 	coex_dm->ps_tdma_para[1] = byte2;
1146 	coex_dm->ps_tdma_para[2] = byte3;
1147 	coex_dm->ps_tdma_para[3] = byte4;
1148 	coex_dm->ps_tdma_para[4] = real_byte5;
1149 
1150 	btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1151 }
1152 
halbtc8812a2ant_set_lps_rpwm(IN struct btc_coexist * btcoexist,IN u8 lps_val,IN u8 rpwm_val)1153 void halbtc8812a2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
1154 				  IN u8 lps_val, IN u8 rpwm_val)
1155 {
1156 	u8	lps = lps_val;
1157 	u8	rpwm = rpwm_val;
1158 
1159 	btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
1160 	btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1161 }
1162 
halbtc8812a2ant_lps_rpwm(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN u8 lps_val,IN u8 rpwm_val)1163 void halbtc8812a2ant_lps_rpwm(IN struct btc_coexist *btcoexist,
1164 		      IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
1165 {
1166 	coex_dm->cur_lps = lps_val;
1167 	coex_dm->cur_rpwm = rpwm_val;
1168 
1169 	if (!force_exec) {
1170 		if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
1171 		    (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
1172 			return;
1173 	}
1174 	halbtc8812a2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
1175 
1176 	coex_dm->pre_lps = coex_dm->cur_lps;
1177 	coex_dm->pre_rpwm = coex_dm->cur_rpwm;
1178 }
1179 
halbtc8812a2ant_sw_mechanism1(IN struct btc_coexist * btcoexist,IN boolean shrink_rx_lpf,IN boolean low_penalty_ra,IN boolean limited_dig,IN boolean bt_lna_constrain)1180 void halbtc8812a2ant_sw_mechanism1(IN struct btc_coexist *btcoexist,
1181 			   IN boolean shrink_rx_lpf, IN boolean low_penalty_ra,
1182 			   IN boolean limited_dig, IN boolean bt_lna_constrain)
1183 {
1184 	/*
1185 	u32	wifi_bw;
1186 
1187 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
1188 
1189 	if(BTC_WIFI_BW_HT40 != wifi_bw)
1190 	{
1191 		if (shrink_rx_lpf)
1192 			shrink_rx_lpf = false;
1193 	}
1194 	*/
1195 
1196 	halbtc8812a2ant_rf_shrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf);
1197 	/* halbtc8812a2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); */
1198 }
1199 
halbtc8812a2ant_sw_mechanism2(IN struct btc_coexist * btcoexist,IN boolean agc_table_shift,IN boolean adc_back_off,IN boolean sw_dac_swing,IN u32 dac_swing_lvl)1200 void halbtc8812a2ant_sw_mechanism2(IN struct btc_coexist *btcoexist,
1201 			   IN boolean agc_table_shift, IN boolean adc_back_off,
1202 			   IN boolean sw_dac_swing, IN u32 dac_swing_lvl)
1203 {
1204 	/* halbtc8812a2ant_agc_table(btcoexist, NORMAL_EXEC, agc_table_shift); */
1205 	halbtc8812a2ant_adc_back_off(btcoexist, NORMAL_EXEC, adc_back_off);
1206 	halbtc8812a2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing,
1207 				  dac_swing_lvl);
1208 }
1209 
halbtc8812a2ant_set_ant_path(IN struct btc_coexist * btcoexist,IN u8 ant_pos_type,IN boolean init_hwcfg,IN boolean wifi_off)1210 void halbtc8812a2ant_set_ant_path(IN struct btc_coexist *btcoexist,
1211 	  IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
1212 {
1213 	u8			u8tmp = 0;
1214 
1215 	if (init_hwcfg) {
1216 		btcoexist->btc_write_4byte(btcoexist, 0x900, 0x00000400);
1217 		btcoexist->btc_write_1byte(btcoexist, 0x76d, 0x1);
1218 	} else if (wifi_off) {
1219 
1220 	}
1221 
1222 	/* ext switch setting */
1223 	switch (ant_pos_type) {
1224 	case BTC_ANT_WIFI_AT_CPL_MAIN:
1225 		break;
1226 	case BTC_ANT_WIFI_AT_CPL_AUX:
1227 		u8tmp = btcoexist->btc_read_1byte(btcoexist, 0xcb7);
1228 		u8tmp &= ~BIT(3);
1229 		u8tmp |= BIT(2);
1230 		btcoexist->btc_write_1byte(btcoexist, 0xcb7, u8tmp);
1231 		break;
1232 	default:
1233 		break;
1234 	}
1235 }
1236 
halbtc8812a2ant_ps_tdma(IN struct btc_coexist * btcoexist,IN boolean force_exec,IN boolean turn_on,IN u8 type)1237 void halbtc8812a2ant_ps_tdma(IN struct btc_coexist *btcoexist,
1238 		     IN boolean force_exec, IN boolean turn_on, IN u8 type)
1239 {
1240 	coex_dm->cur_ps_tdma_on = turn_on;
1241 	coex_dm->cur_ps_tdma = type;
1242 
1243 	if (!force_exec) {
1244 		if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1245 		    (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1246 			return;
1247 	}
1248 	if (turn_on) {
1249 		switch (type) {
1250 		case 1:
1251 		default:
1252 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1253 						      0x1a, 0x1a, 0xa1, 0x90);
1254 			break;
1255 		case 2:
1256 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1257 						      0x12, 0x12, 0xa1, 0x90);
1258 			break;
1259 		case 3:
1260 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1261 						      0x1c, 0x3, 0xb1, 0x90);
1262 			break;
1263 		case 4:
1264 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1265 						      0x10, 0x3, 0xb1, 0x90);
1266 			break;
1267 		case 5:
1268 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1269 						      0x1a, 0x1a, 0x21, 0x10);
1270 			break;
1271 		case 6:
1272 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1273 						      0x12, 0x12, 0x21, 0x10);
1274 			break;
1275 		case 7:
1276 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1277 						      0x1c, 0x3, 0x21, 0x10);
1278 			break;
1279 		case 8:
1280 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1281 						      0x10, 0x3, 0x21, 0x10);
1282 			break;
1283 		case 9:
1284 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1285 						      0x1a, 0x1a, 0xa1, 0x10);
1286 			break;
1287 		case 10:
1288 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1289 						      0x12, 0x12, 0xa1, 0x10);
1290 			break;
1291 		case 11:
1292 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1293 						      0x1c, 0x3, 0xb1, 0x10);
1294 			break;
1295 		case 12:
1296 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1297 						      0x10, 0x3, 0xb1, 0x10);
1298 			break;
1299 		case 13:
1300 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1301 						      0x1a, 0x1a, 0x21, 0x10);
1302 			break;
1303 		case 14:
1304 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1305 						      0x12, 0x12, 0x21, 0x10);
1306 			break;
1307 		case 15:
1308 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1309 						      0x1c, 0x3, 0x21, 0x10);
1310 			break;
1311 		case 16:
1312 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1313 						      0x10, 0x3, 0x21, 0x10);
1314 			break;
1315 		case 17:
1316 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1317 						      0x35, 0x3, 0xb1, 0x11);
1318 			break;
1319 		case 18:
1320 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1321 						      0x5, 0x5, 0xe1, 0x90);
1322 			break;
1323 		case 19:
1324 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1325 						      0x25, 0x25, 0xe1, 0x90);
1326 			break;
1327 		case 20:
1328 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1329 						      0x25, 0x25, 0x60, 0x90);
1330 			break;
1331 		case 21:
1332 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1333 						      0x15, 0x3, 0x70, 0x90);
1334 			break;
1335 		case 22:
1336 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x61,
1337 						      0x1a, 0x1a, 0x21, 0x10);
1338 			break;
1339 		case 23:
1340 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1341 						      0x1c, 0x03, 0x31, 0x10);
1342 			break;
1343 
1344 		case 71:
1345 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
1346 						      0x1a, 0x1a, 0xe1, 0x90);
1347 			break;
1348 
1349 		/* following cases is for wifi rssi low, started from 81 */
1350 		case 81:
1351 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1352 						      0x3a, 0x3, 0x90, 0x50);
1353 			break;
1354 		case 82:
1355 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1356 						      0x2b, 0x3, 0x90, 0x50);
1357 			break;
1358 		case 83:
1359 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1360 						      0x21, 0x3, 0x90, 0x50);
1361 			break;
1362 		case 84:
1363 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1364 						      0x15, 0x3, 0x90, 0x50);
1365 			break;
1366 		case 85:
1367 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1368 						      0x1d, 0x1d, 0x80, 0x50);
1369 			break;
1370 		case 86:
1371 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xd3,
1372 						      0x15, 0x15, 0x80, 0x50);
1373 			break;
1374 		}
1375 	} else {
1376 		/* disable PS tdma */
1377 		switch (type) {
1378 		case 0: /* ANT2PTA, 0x778=0x1 */
1379 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x8,
1380 						      0x0, 0x0, 0x0, 0x0);
1381 			break;
1382 		case 1: /* ANT2BT, 0x778=3 */
1383 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x0,
1384 						      0x0, 0x0, 0x8, 0x0);
1385 			delay_ms(5);
1386 			halbtc8812a2ant_set_ant_path(btcoexist,
1387 				     BTC_ANT_WIFI_AT_CPL_AUX, false, false);
1388 			break;
1389 		default:
1390 			halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x0,
1391 						      0x0, 0x0, 0x0, 0x0);
1392 			break;
1393 		}
1394 	}
1395 
1396 	/* update pre state */
1397 	coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1398 	coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1399 }
1400 
halbtc8812a2ant_coex_all_off(IN struct btc_coexist * btcoexist)1401 void halbtc8812a2ant_coex_all_off(IN struct btc_coexist *btcoexist)
1402 {
1403 	/* fw all off */
1404 	halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1405 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1406 	halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1407 
1408 	/* sw all off */
1409 	halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1410 	halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1411 
1412 	/* hw all off */
1413 	halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1414 }
1415 
halbtc8812a2ant_init_coex_dm(IN struct btc_coexist * btcoexist)1416 void halbtc8812a2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
1417 {
1418 	/* force to reset coex mechanism */
1419 
1420 	halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
1421 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
1422 	halbtc8812a2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, 0);
1423 
1424 	halbtc8812a2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
1425 
1426 	halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1427 	halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1428 }
1429 
halbtc8812a2ant_ps_tdma_check_for_power_save_state(IN struct btc_coexist * btcoexist,IN boolean new_ps_state)1430 void halbtc8812a2ant_ps_tdma_check_for_power_save_state(
1431 	IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
1432 {
1433 	u8	lps_mode = 0x0;
1434 
1435 	btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1436 
1437 	if (lps_mode) {	/* already under LPS state */
1438 		if (new_ps_state) {
1439 			/* keep state under LPS, do nothing. */
1440 		} else {
1441 			/* will leave LPS state, turn off psTdma first */
1442 			halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1443 						0);
1444 		}
1445 	} else {					/* NO PS state */
1446 		if (new_ps_state) {
1447 			/* will enter LPS state, turn off psTdma first */
1448 			halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1449 						0);
1450 		} else {
1451 			/* keep state under NO PS state, do nothing. */
1452 		}
1453 	}
1454 }
1455 
halbtc8812a2ant_power_save_state(IN struct btc_coexist * btcoexist,IN u8 ps_type,IN boolean low_pwr_disable,IN u8 lps_val,IN u8 rpwm_val)1456 void halbtc8812a2ant_power_save_state(IN struct btc_coexist *btcoexist,
1457 		      IN u8 ps_type, IN boolean low_pwr_disable, IN u8 lps_val,
1458 				      IN u8 rpwm_val)
1459 {
1460 	switch (ps_type) {
1461 	case BTC_PS_WIFI_NATIVE:
1462 		btcoexist->btc_set(btcoexist,
1463 				   BTC_SET_ACT_DISABLE_LOW_POWER,
1464 				   &low_pwr_disable);
1465 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1466 				   NULL);
1467 		break;
1468 	case BTC_PS_LPS_ON:
1469 		halbtc8812a2ant_ps_tdma_check_for_power_save_state(
1470 			btcoexist, true);
1471 		halbtc8812a2ant_lps_rpwm(btcoexist, NORMAL_EXEC,
1472 					 lps_val, rpwm_val);
1473 		btcoexist->btc_set(btcoexist,
1474 				   BTC_SET_ACT_DISABLE_LOW_POWER,
1475 				   &low_pwr_disable);
1476 		/* power save must executed before psTdma. */
1477 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
1478 				   NULL);
1479 		break;
1480 	default:
1481 		break;
1482 	}
1483 }
1484 
halbtc8812a2ant_action_bt_inquiry(IN struct btc_coexist * btcoexist)1485 void halbtc8812a2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
1486 {
1487 	halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
1488 					 0x0, 0x0);
1489 
1490 	halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1491 	halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1492 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1493 	halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1494 
1495 	halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1496 	halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1497 }
1498 
halbtc8812a2ant_is_common_action(IN struct btc_coexist * btcoexist)1499 boolean halbtc8812a2ant_is_common_action(IN struct btc_coexist *btcoexist)
1500 {
1501 	struct  btc_bt_link_info	*bt_link_info = &btcoexist->bt_link_info;
1502 	boolean				common = false, wifi_connected = false, wifi_busy = false;
1503 	boolean				bt_hs_on = false;
1504 
1505 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
1506 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1507 			   &wifi_connected);
1508 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1509 
1510 
1511 	if (coex_sta->c2h_bt_inquiry_page) {
1512 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1513 			    "[BTCoex], BT is under inquiry/page scan !!\n");
1514 		BTC_TRACE(trace_buf);
1515 		halbtc8812a2ant_action_bt_inquiry(btcoexist);
1516 		return true;
1517 	}
1518 
1519 	if (bt_link_info->sco_exist || bt_link_info->hid_exist)
1520 		halbtc8812a2ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 0, 0, 0);
1521 	else
1522 		halbtc8812a2ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
1523 
1524 	if (!wifi_connected) {
1525 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1526 						 false, 0x0, 0x0);
1527 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
1528 					   0x8);
1529 
1530 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1531 			    "[BTCoex], Wifi non-connected idle!!\n");
1532 		BTC_TRACE(trace_buf);
1533 
1534 		if ((BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1535 		     coex_dm->bt_status) ||
1536 		    (BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE ==
1537 		     coex_dm->bt_status)) {
1538 			halbtc8812a2ant_coex_table_with_type(btcoexist,
1539 							     NORMAL_EXEC, 1);
1540 			halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1541 						0);
1542 		} else {
1543 			halbtc8812a2ant_coex_table_with_type(btcoexist,
1544 							     NORMAL_EXEC, 0);
1545 			halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1546 						1);
1547 		}
1548 
1549 		halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1550 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1551 
1552 		halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false,
1553 					      false);
1554 		halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false,
1555 					      0x18);
1556 
1557 		common = true;
1558 	} else {
1559 		if (BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1560 		    coex_dm->bt_status) {
1561 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1562 				"[BTCoex], Wifi connected + BT non connected-idle!!\n");
1563 			BTC_TRACE(trace_buf);
1564 			halbtc8812a2ant_power_save_state(btcoexist,
1565 					 BTC_PS_WIFI_NATIVE, false, 0x0, 0x0);
1566 			halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC,
1567 						   false, false, 0x8);
1568 
1569 			halbtc8812a2ant_coex_table_with_type(btcoexist,
1570 							     NORMAL_EXEC, 0);
1571 			halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1572 						0);
1573 			halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1574 							 6);
1575 			halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1576 
1577 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
1578 						      false, false);
1579 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
1580 						      false, 0x18);
1581 
1582 			common = true;
1583 		} else if (BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE ==
1584 			   coex_dm->bt_status) {
1585 			if (bt_hs_on)
1586 				return false;
1587 
1588 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1589 				"[BTCoex], Wifi connected + BT connected-idle!!\n");
1590 			BTC_TRACE(trace_buf);
1591 			halbtc8812a2ant_power_save_state(btcoexist,
1592 					 BTC_PS_WIFI_NATIVE, true, 0x0, 0x0);
1593 			halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC,
1594 						   false, false, 0x8);
1595 
1596 			halbtc8812a2ant_coex_table_with_type(btcoexist,
1597 							     NORMAL_EXEC, 0);
1598 			halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
1599 						0);
1600 			halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1601 							 6);
1602 			halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1603 
1604 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
1605 						      false, false);
1606 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
1607 						      false, 0x18);
1608 
1609 			common = true;
1610 		} else {
1611 			if (wifi_busy) {
1612 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1613 					"[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1614 				BTC_TRACE(trace_buf);
1615 				common = false;
1616 			} else {
1617 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1618 					"[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1619 				BTC_TRACE(trace_buf);
1620 
1621 				halbtc8812a2ant_power_save_state(btcoexist,
1622 					 BTC_PS_WIFI_NATIVE, true, 0x0, 0x0);
1623 
1624 				halbtc8812a2ant_limited_rx(btcoexist,
1625 					   NORMAL_EXEC, false, false, 0x8);
1626 
1627 				halbtc8812a2ant_coex_table_with_type(btcoexist,
1628 							     NORMAL_EXEC, 0);
1629 
1630 				halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
1631 							true, 17);
1632 
1633 				halbtc8812a2ant_fw_dac_swing_lvl(btcoexist,
1634 							 NORMAL_EXEC, 6);
1635 				halbtc8812a2ant_dec_bt_pwr(btcoexist,
1636 							   NORMAL_EXEC, 0);
1637 				halbtc8812a2ant_sw_mechanism1(btcoexist, false,
1638 						      false, false, false);
1639 				halbtc8812a2ant_sw_mechanism2(btcoexist, false,
1640 						      false, false, 0x18);
1641 				common = true;
1642 			}
1643 		}
1644 	}
1645 
1646 	return common;
1647 }
1648 
halbtc8812a2ant_tdma_duration_adjust(IN struct btc_coexist * btcoexist,IN boolean sco_hid,IN boolean tx_pause,IN u8 max_interval)1649 void halbtc8812a2ant_tdma_duration_adjust(IN struct btc_coexist *btcoexist,
1650 		IN boolean sco_hid, IN boolean tx_pause, IN u8 max_interval)
1651 {
1652 	static s32		up, dn, m, n, wait_count;
1653 	s32			result;   /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1654 	u8			retry_count = 0;
1655 
1656 	coex_dm->auto_tdma_adjust_low_rssi = false;
1657 
1658 	if (!coex_dm->auto_tdma_adjust) {
1659 		coex_dm->auto_tdma_adjust = true;
1660 		{
1661 			if (sco_hid) {
1662 				if (tx_pause) {
1663 					if (max_interval == 1) {
1664 						halbtc8812a2ant_ps_tdma(
1665 							btcoexist, NORMAL_EXEC,
1666 							true, 13);
1667 						coex_dm->ps_tdma_du_adj_type =
1668 							13;
1669 					} else if (max_interval == 2) {
1670 						halbtc8812a2ant_ps_tdma(
1671 							btcoexist, NORMAL_EXEC,
1672 							true, 14);
1673 						coex_dm->ps_tdma_du_adj_type =
1674 							14;
1675 					} else if (max_interval == 3) {
1676 						halbtc8812a2ant_ps_tdma(
1677 							btcoexist, NORMAL_EXEC,
1678 							true, 15);
1679 						coex_dm->ps_tdma_du_adj_type =
1680 							15;
1681 					} else {
1682 						halbtc8812a2ant_ps_tdma(
1683 							btcoexist, NORMAL_EXEC,
1684 							true, 15);
1685 						coex_dm->ps_tdma_du_adj_type =
1686 							15;
1687 					}
1688 				} else {
1689 					if (max_interval == 1) {
1690 						halbtc8812a2ant_ps_tdma(
1691 							btcoexist, NORMAL_EXEC,
1692 							true, 9);
1693 						coex_dm->ps_tdma_du_adj_type =
1694 							9;
1695 					} else if (max_interval == 2) {
1696 						halbtc8812a2ant_ps_tdma(
1697 							btcoexist, NORMAL_EXEC,
1698 							true, 10);
1699 						coex_dm->ps_tdma_du_adj_type =
1700 							10;
1701 					} else if (max_interval == 3) {
1702 						halbtc8812a2ant_ps_tdma(
1703 							btcoexist, NORMAL_EXEC,
1704 							true, 11);
1705 						coex_dm->ps_tdma_du_adj_type =
1706 							11;
1707 					} else {
1708 						halbtc8812a2ant_ps_tdma(
1709 							btcoexist, NORMAL_EXEC,
1710 							true, 11);
1711 						coex_dm->ps_tdma_du_adj_type =
1712 							11;
1713 					}
1714 				}
1715 			} else {
1716 				if (tx_pause) {
1717 					if (max_interval == 1) {
1718 						halbtc8812a2ant_ps_tdma(
1719 							btcoexist, NORMAL_EXEC,
1720 							true, 5);
1721 						coex_dm->ps_tdma_du_adj_type =
1722 							5;
1723 					} else if (max_interval == 2) {
1724 						halbtc8812a2ant_ps_tdma(
1725 							btcoexist, NORMAL_EXEC,
1726 							true, 6);
1727 						coex_dm->ps_tdma_du_adj_type =
1728 							6;
1729 					} else if (max_interval == 3) {
1730 						halbtc8812a2ant_ps_tdma(
1731 							btcoexist, NORMAL_EXEC,
1732 							true, 7);
1733 						coex_dm->ps_tdma_du_adj_type =
1734 							7;
1735 					} else {
1736 						halbtc8812a2ant_ps_tdma(
1737 							btcoexist, NORMAL_EXEC,
1738 							true, 7);
1739 						coex_dm->ps_tdma_du_adj_type =
1740 							7;
1741 					}
1742 				} else {
1743 					if (max_interval == 1) {
1744 						halbtc8812a2ant_ps_tdma(
1745 							btcoexist, NORMAL_EXEC,
1746 							true, 1);
1747 						coex_dm->ps_tdma_du_adj_type =
1748 							1;
1749 					} else if (max_interval == 2) {
1750 						halbtc8812a2ant_ps_tdma(
1751 							btcoexist, NORMAL_EXEC,
1752 							true, 2);
1753 						coex_dm->ps_tdma_du_adj_type =
1754 							2;
1755 					} else if (max_interval == 3) {
1756 						halbtc8812a2ant_ps_tdma(
1757 							btcoexist, NORMAL_EXEC,
1758 							true, 3);
1759 						coex_dm->ps_tdma_du_adj_type =
1760 							3;
1761 					} else {
1762 						halbtc8812a2ant_ps_tdma(
1763 							btcoexist, NORMAL_EXEC,
1764 							true, 3);
1765 						coex_dm->ps_tdma_du_adj_type =
1766 							3;
1767 					}
1768 				}
1769 			}
1770 		}
1771 		/* ============ */
1772 		up = 0;
1773 		dn = 0;
1774 		m = 1;
1775 		n = 3;
1776 		result = 0;
1777 		wait_count = 0;
1778 	} else {
1779 		/* accquire the BT TRx retry count from BT_Info byte2 */
1780 		retry_count = coex_sta->bt_retry_cnt;
1781 		result = 0;
1782 		wait_count++;
1783 
1784 		if (retry_count ==
1785 		    0) { /* no retry in the last 2-second duration */
1786 			up++;
1787 			dn--;
1788 
1789 			if (dn <= 0)
1790 				dn = 0;
1791 
1792 			if (up >= n) {	/* if �s�� n ��2�� retry count��0, �h�ռeWiFi duration */
1793 				wait_count = 0;
1794 				n = 3;
1795 				up = 0;
1796 				dn = 0;
1797 				result = 1;
1798 			}
1799 		} else if (retry_count <=
1800 			   3) {	/* <=3 retry in the last 2-second duration */
1801 			up--;
1802 			dn++;
1803 
1804 			if (up <= 0)
1805 				up = 0;
1806 
1807 			if (dn == 2) {	/* if �s�� 2 ��2�� retry count< 3, �h�կ�WiFi duration */
1808 				if (wait_count <= 2)
1809 					m++; /* �קK�@���b���level���Ӧ^ */
1810 				else
1811 					m = 1;
1812 
1813 				if (m >= 20)  /* m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration. */
1814 					m = 20;
1815 
1816 				n = 3 * m;
1817 				up = 0;
1818 				dn = 0;
1819 				wait_count = 0;
1820 				result = -1;
1821 			}
1822 		} else { /* retry count > 3, �u�n1�� retry count > 3, �h�կ�WiFi duration */
1823 			if (wait_count == 1)
1824 				m++; /* �קK�@���b���level���Ӧ^ */
1825 			else
1826 				m = 1;
1827 
1828 			if (m >= 20)  /* m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration. */
1829 				m = 20;
1830 
1831 			n = 3 * m;
1832 			up = 0;
1833 			dn = 0;
1834 			wait_count = 0;
1835 			result = -1;
1836 		}
1837 
1838 		if (max_interval == 1) {
1839 			if (tx_pause) {
1840 				if (coex_dm->cur_ps_tdma == 71) {
1841 					halbtc8812a2ant_ps_tdma(btcoexist,
1842 							NORMAL_EXEC, true, 5);
1843 					coex_dm->ps_tdma_du_adj_type = 5;
1844 				} else if (coex_dm->cur_ps_tdma == 1) {
1845 					halbtc8812a2ant_ps_tdma(btcoexist,
1846 							NORMAL_EXEC, true, 5);
1847 					coex_dm->ps_tdma_du_adj_type = 5;
1848 				} else if (coex_dm->cur_ps_tdma == 2) {
1849 					halbtc8812a2ant_ps_tdma(btcoexist,
1850 							NORMAL_EXEC, true, 6);
1851 					coex_dm->ps_tdma_du_adj_type = 6;
1852 				} else if (coex_dm->cur_ps_tdma == 3) {
1853 					halbtc8812a2ant_ps_tdma(btcoexist,
1854 							NORMAL_EXEC, true, 7);
1855 					coex_dm->ps_tdma_du_adj_type = 7;
1856 				} else if (coex_dm->cur_ps_tdma == 4) {
1857 					halbtc8812a2ant_ps_tdma(btcoexist,
1858 							NORMAL_EXEC, true, 8);
1859 					coex_dm->ps_tdma_du_adj_type = 8;
1860 				}
1861 				if (coex_dm->cur_ps_tdma == 9) {
1862 					halbtc8812a2ant_ps_tdma(btcoexist,
1863 							NORMAL_EXEC, true, 13);
1864 					coex_dm->ps_tdma_du_adj_type = 13;
1865 				} else if (coex_dm->cur_ps_tdma == 10) {
1866 					halbtc8812a2ant_ps_tdma(btcoexist,
1867 							NORMAL_EXEC, true, 14);
1868 					coex_dm->ps_tdma_du_adj_type = 14;
1869 				} else if (coex_dm->cur_ps_tdma == 11) {
1870 					halbtc8812a2ant_ps_tdma(btcoexist,
1871 							NORMAL_EXEC, true, 15);
1872 					coex_dm->ps_tdma_du_adj_type = 15;
1873 				} else if (coex_dm->cur_ps_tdma == 12) {
1874 					halbtc8812a2ant_ps_tdma(btcoexist,
1875 							NORMAL_EXEC, true, 16);
1876 					coex_dm->ps_tdma_du_adj_type = 16;
1877 				}
1878 
1879 				if (result == -1) {
1880 					if (coex_dm->cur_ps_tdma == 5) {
1881 						halbtc8812a2ant_ps_tdma(
1882 							btcoexist, NORMAL_EXEC,
1883 							true, 6);
1884 						coex_dm->ps_tdma_du_adj_type =
1885 							6;
1886 					} else if (coex_dm->cur_ps_tdma == 6) {
1887 						halbtc8812a2ant_ps_tdma(
1888 							btcoexist, NORMAL_EXEC,
1889 							true, 7);
1890 						coex_dm->ps_tdma_du_adj_type =
1891 							7;
1892 					} else if (coex_dm->cur_ps_tdma == 7) {
1893 						halbtc8812a2ant_ps_tdma(
1894 							btcoexist, NORMAL_EXEC,
1895 							true, 8);
1896 						coex_dm->ps_tdma_du_adj_type =
1897 							8;
1898 					} else if (coex_dm->cur_ps_tdma == 13) {
1899 						halbtc8812a2ant_ps_tdma(
1900 							btcoexist, NORMAL_EXEC,
1901 							true, 14);
1902 						coex_dm->ps_tdma_du_adj_type =
1903 							14;
1904 					} else if (coex_dm->cur_ps_tdma == 14) {
1905 						halbtc8812a2ant_ps_tdma(
1906 							btcoexist, NORMAL_EXEC,
1907 							true, 15);
1908 						coex_dm->ps_tdma_du_adj_type =
1909 							15;
1910 					} else if (coex_dm->cur_ps_tdma == 15) {
1911 						halbtc8812a2ant_ps_tdma(
1912 							btcoexist, NORMAL_EXEC,
1913 							true, 16);
1914 						coex_dm->ps_tdma_du_adj_type =
1915 							16;
1916 					}
1917 				} else if (result == 1) {
1918 					if (coex_dm->cur_ps_tdma == 8) {
1919 						halbtc8812a2ant_ps_tdma(
1920 							btcoexist, NORMAL_EXEC,
1921 							true, 7);
1922 						coex_dm->ps_tdma_du_adj_type =
1923 							7;
1924 					} else if (coex_dm->cur_ps_tdma == 7) {
1925 						halbtc8812a2ant_ps_tdma(
1926 							btcoexist, NORMAL_EXEC,
1927 							true, 6);
1928 						coex_dm->ps_tdma_du_adj_type =
1929 							6;
1930 					} else if (coex_dm->cur_ps_tdma == 6) {
1931 						halbtc8812a2ant_ps_tdma(
1932 							btcoexist, NORMAL_EXEC,
1933 							true, 5);
1934 						coex_dm->ps_tdma_du_adj_type =
1935 							5;
1936 					} else if (coex_dm->cur_ps_tdma == 16) {
1937 						halbtc8812a2ant_ps_tdma(
1938 							btcoexist, NORMAL_EXEC,
1939 							true, 15);
1940 						coex_dm->ps_tdma_du_adj_type =
1941 							15;
1942 					} else if (coex_dm->cur_ps_tdma == 15) {
1943 						halbtc8812a2ant_ps_tdma(
1944 							btcoexist, NORMAL_EXEC,
1945 							true, 14);
1946 						coex_dm->ps_tdma_du_adj_type =
1947 							14;
1948 					} else if (coex_dm->cur_ps_tdma == 14) {
1949 						halbtc8812a2ant_ps_tdma(
1950 							btcoexist, NORMAL_EXEC,
1951 							true, 13);
1952 						coex_dm->ps_tdma_du_adj_type =
1953 							13;
1954 					}
1955 				}
1956 			} else {
1957 				if (coex_dm->cur_ps_tdma == 5) {
1958 					halbtc8812a2ant_ps_tdma(btcoexist,
1959 							NORMAL_EXEC, true, 71);
1960 					coex_dm->ps_tdma_du_adj_type = 71;
1961 				} else if (coex_dm->cur_ps_tdma == 6) {
1962 					halbtc8812a2ant_ps_tdma(btcoexist,
1963 							NORMAL_EXEC, true, 2);
1964 					coex_dm->ps_tdma_du_adj_type = 2;
1965 				} else if (coex_dm->cur_ps_tdma == 7) {
1966 					halbtc8812a2ant_ps_tdma(btcoexist,
1967 							NORMAL_EXEC, true, 3);
1968 					coex_dm->ps_tdma_du_adj_type = 3;
1969 				} else if (coex_dm->cur_ps_tdma == 8) {
1970 					halbtc8812a2ant_ps_tdma(btcoexist,
1971 							NORMAL_EXEC, true, 4);
1972 					coex_dm->ps_tdma_du_adj_type = 4;
1973 				}
1974 				if (coex_dm->cur_ps_tdma == 13) {
1975 					halbtc8812a2ant_ps_tdma(btcoexist,
1976 							NORMAL_EXEC, true, 9);
1977 					coex_dm->ps_tdma_du_adj_type = 9;
1978 				} else if (coex_dm->cur_ps_tdma == 14) {
1979 					halbtc8812a2ant_ps_tdma(btcoexist,
1980 							NORMAL_EXEC, true, 10);
1981 					coex_dm->ps_tdma_du_adj_type = 10;
1982 				} else if (coex_dm->cur_ps_tdma == 15) {
1983 					halbtc8812a2ant_ps_tdma(btcoexist,
1984 							NORMAL_EXEC, true, 11);
1985 					coex_dm->ps_tdma_du_adj_type = 11;
1986 				} else if (coex_dm->cur_ps_tdma == 16) {
1987 					halbtc8812a2ant_ps_tdma(btcoexist,
1988 							NORMAL_EXEC, true, 12);
1989 					coex_dm->ps_tdma_du_adj_type = 12;
1990 				}
1991 
1992 				if (result == -1) {
1993 					if (coex_dm->cur_ps_tdma == 71) {
1994 						halbtc8812a2ant_ps_tdma(
1995 							btcoexist, NORMAL_EXEC,
1996 							true, 1);
1997 						coex_dm->ps_tdma_du_adj_type =
1998 							1;
1999 					} else if (coex_dm->cur_ps_tdma == 1) {
2000 						halbtc8812a2ant_ps_tdma(
2001 							btcoexist, NORMAL_EXEC,
2002 							true, 2);
2003 						coex_dm->ps_tdma_du_adj_type =
2004 							2;
2005 					} else if (coex_dm->cur_ps_tdma == 2) {
2006 						halbtc8812a2ant_ps_tdma(
2007 							btcoexist, NORMAL_EXEC,
2008 							true, 3);
2009 						coex_dm->ps_tdma_du_adj_type =
2010 							3;
2011 					} else if (coex_dm->cur_ps_tdma == 3) {
2012 						halbtc8812a2ant_ps_tdma(
2013 							btcoexist, NORMAL_EXEC,
2014 							true, 4);
2015 						coex_dm->ps_tdma_du_adj_type =
2016 							4;
2017 					} else if (coex_dm->cur_ps_tdma == 9) {
2018 						halbtc8812a2ant_ps_tdma(
2019 							btcoexist, NORMAL_EXEC,
2020 							true, 10);
2021 						coex_dm->ps_tdma_du_adj_type =
2022 							10;
2023 					} else if (coex_dm->cur_ps_tdma == 10) {
2024 						halbtc8812a2ant_ps_tdma(
2025 							btcoexist, NORMAL_EXEC,
2026 							true, 11);
2027 						coex_dm->ps_tdma_du_adj_type =
2028 							11;
2029 					} else if (coex_dm->cur_ps_tdma == 11) {
2030 						halbtc8812a2ant_ps_tdma(
2031 							btcoexist, NORMAL_EXEC,
2032 							true, 12);
2033 						coex_dm->ps_tdma_du_adj_type =
2034 							12;
2035 					}
2036 				} else if (result == 1) {
2037 					if (coex_dm->cur_ps_tdma == 4) {
2038 						halbtc8812a2ant_ps_tdma(
2039 							btcoexist, NORMAL_EXEC,
2040 							true, 3);
2041 						coex_dm->ps_tdma_du_adj_type =
2042 							3;
2043 					} else if (coex_dm->cur_ps_tdma == 3) {
2044 						halbtc8812a2ant_ps_tdma(
2045 							btcoexist, NORMAL_EXEC,
2046 							true, 2);
2047 						coex_dm->ps_tdma_du_adj_type =
2048 							2;
2049 					} else if (coex_dm->cur_ps_tdma == 2) {
2050 						halbtc8812a2ant_ps_tdma(
2051 							btcoexist, NORMAL_EXEC,
2052 							true, 1);
2053 						coex_dm->ps_tdma_du_adj_type =
2054 							1;
2055 					} else if (coex_dm->cur_ps_tdma == 1) {
2056 						halbtc8812a2ant_ps_tdma(
2057 							btcoexist, NORMAL_EXEC,
2058 							true, 71);
2059 						coex_dm->ps_tdma_du_adj_type =
2060 							71;
2061 					} else if (coex_dm->cur_ps_tdma == 12) {
2062 						halbtc8812a2ant_ps_tdma(
2063 							btcoexist, NORMAL_EXEC,
2064 							true, 11);
2065 						coex_dm->ps_tdma_du_adj_type =
2066 							11;
2067 					} else if (coex_dm->cur_ps_tdma == 11) {
2068 						halbtc8812a2ant_ps_tdma(
2069 							btcoexist, NORMAL_EXEC,
2070 							true, 10);
2071 						coex_dm->ps_tdma_du_adj_type =
2072 							10;
2073 					} else if (coex_dm->cur_ps_tdma == 10) {
2074 						halbtc8812a2ant_ps_tdma(
2075 							btcoexist, NORMAL_EXEC,
2076 							true, 9);
2077 						coex_dm->ps_tdma_du_adj_type =
2078 							9;
2079 					}
2080 				}
2081 			}
2082 		} else if (max_interval == 2) {
2083 			if (tx_pause) {
2084 				if (coex_dm->cur_ps_tdma == 1) {
2085 					halbtc8812a2ant_ps_tdma(btcoexist,
2086 							NORMAL_EXEC, true, 6);
2087 					coex_dm->ps_tdma_du_adj_type = 6;
2088 				} else if (coex_dm->cur_ps_tdma == 2) {
2089 					halbtc8812a2ant_ps_tdma(btcoexist,
2090 							NORMAL_EXEC, true, 6);
2091 					coex_dm->ps_tdma_du_adj_type = 6;
2092 				} else if (coex_dm->cur_ps_tdma == 3) {
2093 					halbtc8812a2ant_ps_tdma(btcoexist,
2094 							NORMAL_EXEC, true, 7);
2095 					coex_dm->ps_tdma_du_adj_type = 7;
2096 				} else if (coex_dm->cur_ps_tdma == 4) {
2097 					halbtc8812a2ant_ps_tdma(btcoexist,
2098 							NORMAL_EXEC, true, 8);
2099 					coex_dm->ps_tdma_du_adj_type = 8;
2100 				}
2101 				if (coex_dm->cur_ps_tdma == 9) {
2102 					halbtc8812a2ant_ps_tdma(btcoexist,
2103 							NORMAL_EXEC, true, 14);
2104 					coex_dm->ps_tdma_du_adj_type = 14;
2105 				} else if (coex_dm->cur_ps_tdma == 10) {
2106 					halbtc8812a2ant_ps_tdma(btcoexist,
2107 							NORMAL_EXEC, true, 14);
2108 					coex_dm->ps_tdma_du_adj_type = 14;
2109 				} else if (coex_dm->cur_ps_tdma == 11) {
2110 					halbtc8812a2ant_ps_tdma(btcoexist,
2111 							NORMAL_EXEC, true, 15);
2112 					coex_dm->ps_tdma_du_adj_type = 15;
2113 				} else if (coex_dm->cur_ps_tdma == 12) {
2114 					halbtc8812a2ant_ps_tdma(btcoexist,
2115 							NORMAL_EXEC, true, 16);
2116 					coex_dm->ps_tdma_du_adj_type = 16;
2117 				}
2118 				if (result == -1) {
2119 					if (coex_dm->cur_ps_tdma == 5) {
2120 						halbtc8812a2ant_ps_tdma(
2121 							btcoexist, NORMAL_EXEC,
2122 							true, 6);
2123 						coex_dm->ps_tdma_du_adj_type =
2124 							6;
2125 					} else if (coex_dm->cur_ps_tdma == 6) {
2126 						halbtc8812a2ant_ps_tdma(
2127 							btcoexist, NORMAL_EXEC,
2128 							true, 7);
2129 						coex_dm->ps_tdma_du_adj_type =
2130 							7;
2131 					} else if (coex_dm->cur_ps_tdma == 7) {
2132 						halbtc8812a2ant_ps_tdma(
2133 							btcoexist, NORMAL_EXEC,
2134 							true, 8);
2135 						coex_dm->ps_tdma_du_adj_type =
2136 							8;
2137 					} else if (coex_dm->cur_ps_tdma == 13) {
2138 						halbtc8812a2ant_ps_tdma(
2139 							btcoexist, NORMAL_EXEC,
2140 							true, 14);
2141 						coex_dm->ps_tdma_du_adj_type =
2142 							14;
2143 					} else if (coex_dm->cur_ps_tdma == 14) {
2144 						halbtc8812a2ant_ps_tdma(
2145 							btcoexist, NORMAL_EXEC,
2146 							true, 15);
2147 						coex_dm->ps_tdma_du_adj_type =
2148 							15;
2149 					} else if (coex_dm->cur_ps_tdma == 15) {
2150 						halbtc8812a2ant_ps_tdma(
2151 							btcoexist, NORMAL_EXEC,
2152 							true, 16);
2153 						coex_dm->ps_tdma_du_adj_type =
2154 							16;
2155 					}
2156 				} else if (result == 1) {
2157 					if (coex_dm->cur_ps_tdma == 8) {
2158 						halbtc8812a2ant_ps_tdma(
2159 							btcoexist, NORMAL_EXEC,
2160 							true, 7);
2161 						coex_dm->ps_tdma_du_adj_type =
2162 							7;
2163 					} else if (coex_dm->cur_ps_tdma == 7) {
2164 						halbtc8812a2ant_ps_tdma(
2165 							btcoexist, NORMAL_EXEC,
2166 							true, 6);
2167 						coex_dm->ps_tdma_du_adj_type =
2168 							6;
2169 					} else if (coex_dm->cur_ps_tdma == 6) {
2170 						halbtc8812a2ant_ps_tdma(
2171 							btcoexist, NORMAL_EXEC,
2172 							true, 6);
2173 						coex_dm->ps_tdma_du_adj_type =
2174 							6;
2175 					} else if (coex_dm->cur_ps_tdma == 16) {
2176 						halbtc8812a2ant_ps_tdma(
2177 							btcoexist, NORMAL_EXEC,
2178 							true, 15);
2179 						coex_dm->ps_tdma_du_adj_type =
2180 							15;
2181 					} else if (coex_dm->cur_ps_tdma == 15) {
2182 						halbtc8812a2ant_ps_tdma(
2183 							btcoexist, NORMAL_EXEC,
2184 							true, 14);
2185 						coex_dm->ps_tdma_du_adj_type =
2186 							14;
2187 					} else if (coex_dm->cur_ps_tdma == 14) {
2188 						halbtc8812a2ant_ps_tdma(
2189 							btcoexist, NORMAL_EXEC,
2190 							true, 14);
2191 						coex_dm->ps_tdma_du_adj_type =
2192 							14;
2193 					}
2194 				}
2195 			} else {
2196 				if (coex_dm->cur_ps_tdma == 5) {
2197 					halbtc8812a2ant_ps_tdma(btcoexist,
2198 							NORMAL_EXEC, true, 2);
2199 					coex_dm->ps_tdma_du_adj_type = 2;
2200 				} else if (coex_dm->cur_ps_tdma == 6) {
2201 					halbtc8812a2ant_ps_tdma(btcoexist,
2202 							NORMAL_EXEC, true, 2);
2203 					coex_dm->ps_tdma_du_adj_type = 2;
2204 				} else if (coex_dm->cur_ps_tdma == 7) {
2205 					halbtc8812a2ant_ps_tdma(btcoexist,
2206 							NORMAL_EXEC, true, 3);
2207 					coex_dm->ps_tdma_du_adj_type = 3;
2208 				} else if (coex_dm->cur_ps_tdma == 8) {
2209 					halbtc8812a2ant_ps_tdma(btcoexist,
2210 							NORMAL_EXEC, true, 4);
2211 					coex_dm->ps_tdma_du_adj_type = 4;
2212 				}
2213 				if (coex_dm->cur_ps_tdma == 13) {
2214 					halbtc8812a2ant_ps_tdma(btcoexist,
2215 							NORMAL_EXEC, true, 10);
2216 					coex_dm->ps_tdma_du_adj_type = 10;
2217 				} else if (coex_dm->cur_ps_tdma == 14) {
2218 					halbtc8812a2ant_ps_tdma(btcoexist,
2219 							NORMAL_EXEC, true, 10);
2220 					coex_dm->ps_tdma_du_adj_type = 10;
2221 				} else if (coex_dm->cur_ps_tdma == 15) {
2222 					halbtc8812a2ant_ps_tdma(btcoexist,
2223 							NORMAL_EXEC, true, 11);
2224 					coex_dm->ps_tdma_du_adj_type = 11;
2225 				} else if (coex_dm->cur_ps_tdma == 16) {
2226 					halbtc8812a2ant_ps_tdma(btcoexist,
2227 							NORMAL_EXEC, true, 12);
2228 					coex_dm->ps_tdma_du_adj_type = 12;
2229 				}
2230 				if (result == -1) {
2231 					if (coex_dm->cur_ps_tdma == 1) {
2232 						halbtc8812a2ant_ps_tdma(
2233 							btcoexist, NORMAL_EXEC,
2234 							true, 2);
2235 						coex_dm->ps_tdma_du_adj_type =
2236 							2;
2237 					} else if (coex_dm->cur_ps_tdma == 2) {
2238 						halbtc8812a2ant_ps_tdma(
2239 							btcoexist, NORMAL_EXEC,
2240 							true, 3);
2241 						coex_dm->ps_tdma_du_adj_type =
2242 							3;
2243 					} else if (coex_dm->cur_ps_tdma == 3) {
2244 						halbtc8812a2ant_ps_tdma(
2245 							btcoexist, NORMAL_EXEC,
2246 							true, 4);
2247 						coex_dm->ps_tdma_du_adj_type =
2248 							4;
2249 					} else if (coex_dm->cur_ps_tdma == 9) {
2250 						halbtc8812a2ant_ps_tdma(
2251 							btcoexist, NORMAL_EXEC,
2252 							true, 10);
2253 						coex_dm->ps_tdma_du_adj_type =
2254 							10;
2255 					} else if (coex_dm->cur_ps_tdma == 10) {
2256 						halbtc8812a2ant_ps_tdma(
2257 							btcoexist, NORMAL_EXEC,
2258 							true, 11);
2259 						coex_dm->ps_tdma_du_adj_type =
2260 							11;
2261 					} else if (coex_dm->cur_ps_tdma == 11) {
2262 						halbtc8812a2ant_ps_tdma(
2263 							btcoexist, NORMAL_EXEC,
2264 							true, 12);
2265 						coex_dm->ps_tdma_du_adj_type =
2266 							12;
2267 					}
2268 				} else if (result == 1) {
2269 					if (coex_dm->cur_ps_tdma == 4) {
2270 						halbtc8812a2ant_ps_tdma(
2271 							btcoexist, NORMAL_EXEC,
2272 							true, 3);
2273 						coex_dm->ps_tdma_du_adj_type =
2274 							3;
2275 					} else if (coex_dm->cur_ps_tdma == 3) {
2276 						halbtc8812a2ant_ps_tdma(
2277 							btcoexist, NORMAL_EXEC,
2278 							true, 2);
2279 						coex_dm->ps_tdma_du_adj_type =
2280 							2;
2281 					} else if (coex_dm->cur_ps_tdma == 2) {
2282 						halbtc8812a2ant_ps_tdma(
2283 							btcoexist, NORMAL_EXEC,
2284 							true, 2);
2285 						coex_dm->ps_tdma_du_adj_type =
2286 							2;
2287 					} else if (coex_dm->cur_ps_tdma == 12) {
2288 						halbtc8812a2ant_ps_tdma(
2289 							btcoexist, NORMAL_EXEC,
2290 							true, 11);
2291 						coex_dm->ps_tdma_du_adj_type =
2292 							11;
2293 					} else if (coex_dm->cur_ps_tdma == 11) {
2294 						halbtc8812a2ant_ps_tdma(
2295 							btcoexist, NORMAL_EXEC,
2296 							true, 10);
2297 						coex_dm->ps_tdma_du_adj_type =
2298 							10;
2299 					} else if (coex_dm->cur_ps_tdma == 10) {
2300 						halbtc8812a2ant_ps_tdma(
2301 							btcoexist, NORMAL_EXEC,
2302 							true, 10);
2303 						coex_dm->ps_tdma_du_adj_type =
2304 							10;
2305 					}
2306 				}
2307 			}
2308 		} else if (max_interval == 3) {
2309 			if (tx_pause) {
2310 				if (coex_dm->cur_ps_tdma == 1) {
2311 					halbtc8812a2ant_ps_tdma(btcoexist,
2312 							NORMAL_EXEC, true, 7);
2313 					coex_dm->ps_tdma_du_adj_type = 7;
2314 				} else if (coex_dm->cur_ps_tdma == 2) {
2315 					halbtc8812a2ant_ps_tdma(btcoexist,
2316 							NORMAL_EXEC, true, 7);
2317 					coex_dm->ps_tdma_du_adj_type = 7;
2318 				} else if (coex_dm->cur_ps_tdma == 3) {
2319 					halbtc8812a2ant_ps_tdma(btcoexist,
2320 							NORMAL_EXEC, true, 7);
2321 					coex_dm->ps_tdma_du_adj_type = 7;
2322 				} else if (coex_dm->cur_ps_tdma == 4) {
2323 					halbtc8812a2ant_ps_tdma(btcoexist,
2324 							NORMAL_EXEC, true, 8);
2325 					coex_dm->ps_tdma_du_adj_type = 8;
2326 				}
2327 				if (coex_dm->cur_ps_tdma == 9) {
2328 					halbtc8812a2ant_ps_tdma(btcoexist,
2329 							NORMAL_EXEC, true, 15);
2330 					coex_dm->ps_tdma_du_adj_type = 15;
2331 				} else if (coex_dm->cur_ps_tdma == 10) {
2332 					halbtc8812a2ant_ps_tdma(btcoexist,
2333 							NORMAL_EXEC, true, 15);
2334 					coex_dm->ps_tdma_du_adj_type = 15;
2335 				} else if (coex_dm->cur_ps_tdma == 11) {
2336 					halbtc8812a2ant_ps_tdma(btcoexist,
2337 							NORMAL_EXEC, true, 15);
2338 					coex_dm->ps_tdma_du_adj_type = 15;
2339 				} else if (coex_dm->cur_ps_tdma == 12) {
2340 					halbtc8812a2ant_ps_tdma(btcoexist,
2341 							NORMAL_EXEC, true, 16);
2342 					coex_dm->ps_tdma_du_adj_type = 16;
2343 				}
2344 				if (result == -1) {
2345 					if (coex_dm->cur_ps_tdma == 5) {
2346 						halbtc8812a2ant_ps_tdma(
2347 							btcoexist, NORMAL_EXEC,
2348 							true, 7);
2349 						coex_dm->ps_tdma_du_adj_type =
2350 							7;
2351 					} else if (coex_dm->cur_ps_tdma == 6) {
2352 						halbtc8812a2ant_ps_tdma(
2353 							btcoexist, NORMAL_EXEC,
2354 							true, 7);
2355 						coex_dm->ps_tdma_du_adj_type =
2356 							7;
2357 					} else if (coex_dm->cur_ps_tdma == 7) {
2358 						halbtc8812a2ant_ps_tdma(
2359 							btcoexist, NORMAL_EXEC,
2360 							true, 8);
2361 						coex_dm->ps_tdma_du_adj_type =
2362 							8;
2363 					} else if (coex_dm->cur_ps_tdma == 13) {
2364 						halbtc8812a2ant_ps_tdma(
2365 							btcoexist, NORMAL_EXEC,
2366 							true, 15);
2367 						coex_dm->ps_tdma_du_adj_type =
2368 							15;
2369 					} else if (coex_dm->cur_ps_tdma == 14) {
2370 						halbtc8812a2ant_ps_tdma(
2371 							btcoexist, NORMAL_EXEC,
2372 							true, 15);
2373 						coex_dm->ps_tdma_du_adj_type =
2374 							15;
2375 					} else if (coex_dm->cur_ps_tdma == 15) {
2376 						halbtc8812a2ant_ps_tdma(
2377 							btcoexist, NORMAL_EXEC,
2378 							true, 16);
2379 						coex_dm->ps_tdma_du_adj_type =
2380 							16;
2381 					}
2382 				} else if (result == 1) {
2383 					if (coex_dm->cur_ps_tdma == 8) {
2384 						halbtc8812a2ant_ps_tdma(
2385 							btcoexist, NORMAL_EXEC,
2386 							true, 7);
2387 						coex_dm->ps_tdma_du_adj_type =
2388 							7;
2389 					} else if (coex_dm->cur_ps_tdma == 7) {
2390 						halbtc8812a2ant_ps_tdma(
2391 							btcoexist, NORMAL_EXEC,
2392 							true, 7);
2393 						coex_dm->ps_tdma_du_adj_type =
2394 							7;
2395 					} else if (coex_dm->cur_ps_tdma == 6) {
2396 						halbtc8812a2ant_ps_tdma(
2397 							btcoexist, NORMAL_EXEC,
2398 							true, 7);
2399 						coex_dm->ps_tdma_du_adj_type =
2400 							7;
2401 					} else if (coex_dm->cur_ps_tdma == 16) {
2402 						halbtc8812a2ant_ps_tdma(
2403 							btcoexist, NORMAL_EXEC,
2404 							true, 15);
2405 						coex_dm->ps_tdma_du_adj_type =
2406 							15;
2407 					} else if (coex_dm->cur_ps_tdma == 15) {
2408 						halbtc8812a2ant_ps_tdma(
2409 							btcoexist, NORMAL_EXEC,
2410 							true, 15);
2411 						coex_dm->ps_tdma_du_adj_type =
2412 							15;
2413 					} else if (coex_dm->cur_ps_tdma == 14) {
2414 						halbtc8812a2ant_ps_tdma(
2415 							btcoexist, NORMAL_EXEC,
2416 							true, 15);
2417 						coex_dm->ps_tdma_du_adj_type =
2418 							15;
2419 					}
2420 				}
2421 			} else {
2422 				if (coex_dm->cur_ps_tdma == 5) {
2423 					halbtc8812a2ant_ps_tdma(btcoexist,
2424 							NORMAL_EXEC, true, 3);
2425 					coex_dm->ps_tdma_du_adj_type = 3;
2426 				} else if (coex_dm->cur_ps_tdma == 6) {
2427 					halbtc8812a2ant_ps_tdma(btcoexist,
2428 							NORMAL_EXEC, true, 3);
2429 					coex_dm->ps_tdma_du_adj_type = 3;
2430 				} else if (coex_dm->cur_ps_tdma == 7) {
2431 					halbtc8812a2ant_ps_tdma(btcoexist,
2432 							NORMAL_EXEC, true, 3);
2433 					coex_dm->ps_tdma_du_adj_type = 3;
2434 				} else if (coex_dm->cur_ps_tdma == 8) {
2435 					halbtc8812a2ant_ps_tdma(btcoexist,
2436 							NORMAL_EXEC, true, 4);
2437 					coex_dm->ps_tdma_du_adj_type = 4;
2438 				}
2439 				if (coex_dm->cur_ps_tdma == 13) {
2440 					halbtc8812a2ant_ps_tdma(btcoexist,
2441 							NORMAL_EXEC, true, 11);
2442 					coex_dm->ps_tdma_du_adj_type = 11;
2443 				} else if (coex_dm->cur_ps_tdma == 14) {
2444 					halbtc8812a2ant_ps_tdma(btcoexist,
2445 							NORMAL_EXEC, true, 11);
2446 					coex_dm->ps_tdma_du_adj_type = 11;
2447 				} else if (coex_dm->cur_ps_tdma == 15) {
2448 					halbtc8812a2ant_ps_tdma(btcoexist,
2449 							NORMAL_EXEC, true, 11);
2450 					coex_dm->ps_tdma_du_adj_type = 11;
2451 				} else if (coex_dm->cur_ps_tdma == 16) {
2452 					halbtc8812a2ant_ps_tdma(btcoexist,
2453 							NORMAL_EXEC, true, 12);
2454 					coex_dm->ps_tdma_du_adj_type = 12;
2455 				}
2456 				if (result == -1) {
2457 					if (coex_dm->cur_ps_tdma == 1) {
2458 						halbtc8812a2ant_ps_tdma(
2459 							btcoexist, NORMAL_EXEC,
2460 							true, 3);
2461 						coex_dm->ps_tdma_du_adj_type =
2462 							3;
2463 					} else if (coex_dm->cur_ps_tdma == 2) {
2464 						halbtc8812a2ant_ps_tdma(
2465 							btcoexist, NORMAL_EXEC,
2466 							true, 3);
2467 						coex_dm->ps_tdma_du_adj_type =
2468 							3;
2469 					} else if (coex_dm->cur_ps_tdma == 3) {
2470 						halbtc8812a2ant_ps_tdma(
2471 							btcoexist, NORMAL_EXEC,
2472 							true, 4);
2473 						coex_dm->ps_tdma_du_adj_type =
2474 							4;
2475 					} else if (coex_dm->cur_ps_tdma == 9) {
2476 						halbtc8812a2ant_ps_tdma(
2477 							btcoexist, NORMAL_EXEC,
2478 							true, 11);
2479 						coex_dm->ps_tdma_du_adj_type =
2480 							11;
2481 					} else if (coex_dm->cur_ps_tdma == 10) {
2482 						halbtc8812a2ant_ps_tdma(
2483 							btcoexist, NORMAL_EXEC,
2484 							true, 11);
2485 						coex_dm->ps_tdma_du_adj_type =
2486 							11;
2487 					} else if (coex_dm->cur_ps_tdma == 11) {
2488 						halbtc8812a2ant_ps_tdma(
2489 							btcoexist, NORMAL_EXEC,
2490 							true, 12);
2491 						coex_dm->ps_tdma_du_adj_type =
2492 							12;
2493 					}
2494 				} else if (result == 1) {
2495 					if (coex_dm->cur_ps_tdma == 4) {
2496 						halbtc8812a2ant_ps_tdma(
2497 							btcoexist, NORMAL_EXEC,
2498 							true, 3);
2499 						coex_dm->ps_tdma_du_adj_type =
2500 							3;
2501 					} else if (coex_dm->cur_ps_tdma == 3) {
2502 						halbtc8812a2ant_ps_tdma(
2503 							btcoexist, NORMAL_EXEC,
2504 							true, 3);
2505 						coex_dm->ps_tdma_du_adj_type =
2506 							3;
2507 					} else if (coex_dm->cur_ps_tdma == 2) {
2508 						halbtc8812a2ant_ps_tdma(
2509 							btcoexist, NORMAL_EXEC,
2510 							true, 3);
2511 						coex_dm->ps_tdma_du_adj_type =
2512 							3;
2513 					} else if (coex_dm->cur_ps_tdma == 12) {
2514 						halbtc8812a2ant_ps_tdma(
2515 							btcoexist, NORMAL_EXEC,
2516 							true, 11);
2517 						coex_dm->ps_tdma_du_adj_type =
2518 							11;
2519 					} else if (coex_dm->cur_ps_tdma == 11) {
2520 						halbtc8812a2ant_ps_tdma(
2521 							btcoexist, NORMAL_EXEC,
2522 							true, 11);
2523 						coex_dm->ps_tdma_du_adj_type =
2524 							11;
2525 					} else if (coex_dm->cur_ps_tdma == 10) {
2526 						halbtc8812a2ant_ps_tdma(
2527 							btcoexist, NORMAL_EXEC,
2528 							true, 11);
2529 						coex_dm->ps_tdma_du_adj_type =
2530 							11;
2531 					}
2532 				}
2533 			}
2534 		}
2535 	}
2536 
2537 	/* if current PsTdma not match with the recorded one (when scan, dhcp...), */
2538 	/* then we have to adjust it back to the previous record one. */
2539 	if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) {
2540 		boolean	scan = false, link = false, roam = false;
2541 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2542 			"[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma=%d, recordPsTdma=%d\n",
2543 			    coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type);
2544 		BTC_TRACE(trace_buf);
2545 
2546 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2547 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2548 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2549 
2550 		if (!scan && !link && !roam)
2551 			halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2552 						coex_dm->ps_tdma_du_adj_type);
2553 		else {
2554 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2555 				"[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
2556 			BTC_TRACE(trace_buf);
2557 		}
2558 	}
2559 }
2560 
2561 /* ******************
2562  * pstdma for wifi rssi low
2563  * ****************** */
halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(IN struct btc_coexist * btcoexist)2564 void halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
2565 	IN struct btc_coexist *btcoexist/* , */ /* IN u8 wifi_status */)
2566 {
2567 	static s32		up, dn, m, n, wait_count;
2568 	s32			result;   /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
2569 	u8			retry_count = 0, bt_info_ext;
2570 
2571 	coex_dm->auto_tdma_adjust = false;
2572 
2573 	retry_count = coex_sta->bt_retry_cnt;
2574 	bt_info_ext = coex_sta->bt_info_ext;
2575 
2576 	if (!coex_dm->auto_tdma_adjust_low_rssi) {
2577 		coex_dm->auto_tdma_adjust_low_rssi = true;
2578 
2579 		if (BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) {
2580 			halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2581 						83);
2582 			coex_dm->ps_tdma_du_adj_type = 83;
2583 		} else {
2584 			halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 82);
2585 			coex_dm->ps_tdma_du_adj_type = 82;
2586 		}
2587 		/* ============ */
2588 		up = 0;
2589 		dn = 0;
2590 		m = 1;
2591 		n = 3;
2592 		result = 0;
2593 		wait_count = 0;
2594 	} else {
2595 		/* accquire the BT TRx retry count from BT_Info byte2
2596 		*		retry_count = coex_sta->bt_retry_cnt;
2597 		*		bt_info_ext = coex_sta->bt_info_ext; */
2598 		result = 0;
2599 		wait_count++;
2600 
2601 		if ((coex_sta->low_priority_tx) > 1150 ||
2602 		    (coex_sta->low_priority_rx) > 1250)
2603 			retry_count++;
2604 
2605 		if (retry_count ==
2606 		    0) { /* no retry in the last 2-second duration */
2607 			up++;
2608 			dn--;
2609 
2610 			if (dn <= 0)
2611 				dn = 0;
2612 
2613 			if (up >= n) {	/* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */
2614 				wait_count = 0;
2615 				n = 3;
2616 				up = 0;
2617 				dn = 0;
2618 				result = 1;
2619 			}
2620 		} else if (retry_count <=
2621 			   3) {	/* <=3 retry in the last 2-second duration */
2622 			up--;
2623 			dn++;
2624 
2625 			if (up <= 0)
2626 				up = 0;
2627 
2628 			if (dn == 2) {	/* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */
2629 				if (wait_count <= 2)
2630 					m++; /* to avoid loop between the two levels */
2631 				else
2632 					m = 1;
2633 
2634 				if (m >= 20)  /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
2635 					m = 20;
2636 
2637 				n = 3 * m;
2638 				up = 0;
2639 				dn = 0;
2640 				wait_count = 0;
2641 				result = -1;
2642 			}
2643 		} else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */
2644 			if (wait_count == 1)
2645 				m++; /* to avoid loop between the two levels */
2646 			else
2647 				m = 1;
2648 
2649 			if (m >= 20)  /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
2650 				m = 20;
2651 
2652 			n = 3 * m;
2653 			up = 0;
2654 			dn = 0;
2655 			wait_count = 0;
2656 			result = -1;
2657 		}
2658 
2659 		if (result == -1) {
2660 			if ((BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
2661 			    ((coex_dm->cur_ps_tdma == 81) ||
2662 			     (coex_dm->cur_ps_tdma == 82))) {
2663 				halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2664 							true, 84);
2665 				coex_dm->ps_tdma_du_adj_type = 84;
2666 			} else if (coex_dm->cur_ps_tdma == 81) {
2667 				halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2668 							true, 82);
2669 				coex_dm->ps_tdma_du_adj_type = 82;
2670 			} else if (coex_dm->cur_ps_tdma == 82) {
2671 				halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2672 							true, 83);
2673 				coex_dm->ps_tdma_du_adj_type = 83;
2674 			} else if (coex_dm->cur_ps_tdma == 83) {
2675 				halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2676 							true, 84);
2677 				coex_dm->ps_tdma_du_adj_type = 84;
2678 			}
2679 		} else if (result == 1) {
2680 			if ((BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
2681 			    ((coex_dm->cur_ps_tdma == 81) ||
2682 			     (coex_dm->cur_ps_tdma == 82))) {
2683 				halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2684 							true, 83);
2685 				coex_dm->ps_tdma_du_adj_type = 83;
2686 			} else if (coex_dm->cur_ps_tdma == 84) {
2687 				halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2688 							true, 83);
2689 				coex_dm->ps_tdma_du_adj_type = 83;
2690 			} else if (coex_dm->cur_ps_tdma == 83) {
2691 				halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2692 							true, 82);
2693 				coex_dm->ps_tdma_du_adj_type = 82;
2694 			} else if (coex_dm->cur_ps_tdma == 82) {
2695 				halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
2696 							true, 81);
2697 				coex_dm->ps_tdma_du_adj_type = 81;
2698 			}
2699 		}
2700 
2701 		if (coex_dm->cur_ps_tdma != 81 &&
2702 		    coex_dm->cur_ps_tdma != 82 &&
2703 		    coex_dm->cur_ps_tdma != 83 &&
2704 		    coex_dm->cur_ps_tdma != 84) {
2705 			/* recover to previous adjust type */
2706 			halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2707 						coex_dm->ps_tdma_du_adj_type);
2708 		}
2709 	}
2710 }
2711 
halbtc8812a2ant_get_bt_rssi_threshold(IN struct btc_coexist * btcoexist,IN u8 * pThres0,IN u8 * pThres1)2712 void halbtc8812a2ant_get_bt_rssi_threshold(IN struct btc_coexist *btcoexist,
2713 		IN u8 *pThres0, IN u8 *pThres1)
2714 {
2715 	u8 ant_type;
2716 
2717 	btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &ant_type);
2718 
2719 	switch (ant_type) {
2720 	case BTC_ANT_TYPE_0:
2721 		*pThres0 = 100;
2722 		*pThres1 = 100;
2723 		break;
2724 	case BTC_ANT_TYPE_1:
2725 		*pThres0 = 34;
2726 		*pThres1 = 42;
2727 		break;
2728 	case BTC_ANT_TYPE_2:
2729 		*pThres0 = 34;
2730 		*pThres1 = 42;
2731 		break;
2732 	case BTC_ANT_TYPE_3:
2733 		*pThres0 = 34;
2734 		*pThres1 = 42;
2735 		break;
2736 	case BTC_ANT_TYPE_4:
2737 		*pThres0 = 34;
2738 		*pThres1 = 42;
2739 		break;
2740 	default:
2741 		break;
2742 	}
2743 }
2744 
2745 
2746 
halbtc8812a2ant_action_sco(IN struct btc_coexist * btcoexist)2747 void halbtc8812a2ant_action_sco(IN struct btc_coexist *btcoexist)
2748 {
2749 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
2750 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
2751 	u32		wifi_bw;
2752 	u8		bt_thresh0 = 0, bt_thresh1 = 0;
2753 
2754 
2755 	halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
2756 					      &bt_thresh1);
2757 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
2758 			bt_thresh1);
2759 
2760 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
2761 			  0);
2762 	/*	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
2763 
2764 	/* power save state */
2765 	halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
2766 					 0x0, 0x0);
2767 
2768 	/* coex table */
2769 	if (BTC_RSSI_LOW(bt_rssi_state))
2770 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2771 	else
2772 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2773 
2774 	/* pstdma */
2775 	if (BTC_RSSI_LOW(bt_rssi_state))
2776 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
2777 	else
2778 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
2779 
2780 	/* decrease BT power */
2781 	if (BTC_RSSI_LOW(bt_rssi_state))
2782 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2783 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
2784 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2785 	else
2786 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
2787 
2788 	/* limited Rx */
2789 	halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2790 
2791 	/* fw dac swing level */
2792 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2793 
2794 
2795 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2796 	/* sw mechanism */
2797 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
2798 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2799 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2800 						      false, false);
2801 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2802 						      true, 0x6);
2803 		} else {
2804 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2805 						      false, false);
2806 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2807 						      true, 0x6);
2808 		}
2809 	} else {
2810 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2811 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2812 						      false, false);
2813 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2814 						      true, 0x6);
2815 		} else {
2816 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2817 						      false, false);
2818 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2819 						      true, 0x6);
2820 		}
2821 	}
2822 }
2823 
halbtc8812a2ant_action_sco_hid(IN struct btc_coexist * btcoexist)2824 void halbtc8812a2ant_action_sco_hid(IN struct btc_coexist *btcoexist)
2825 {
2826 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
2827 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
2828 	u32		wifi_bw;
2829 	u8		bt_thresh0 = 0, bt_thresh1 = 0;
2830 
2831 	halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
2832 					      &bt_thresh1);
2833 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
2834 			bt_thresh1);
2835 
2836 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
2837 			  0);
2838 	/*	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
2839 
2840 	/* power save state */
2841 	halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
2842 					 0x0, 0x0);
2843 
2844 	/* coex table */
2845 	halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2846 
2847 	/* pstdma */
2848 	if (BTC_RSSI_LOW(bt_rssi_state))
2849 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
2850 	else
2851 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
2852 
2853 	/* decrease BT power	 */
2854 	if (BTC_RSSI_LOW(bt_rssi_state))
2855 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2856 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
2857 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2858 	else
2859 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
2860 
2861 	/* limited Rx */
2862 	halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x8);
2863 
2864 	/* fw dac swing level */
2865 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2866 
2867 
2868 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2869 	/* sw mechanism */
2870 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
2871 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2872 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2873 						      false, false);
2874 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2875 						      false, 0x6);
2876 		} else {
2877 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2878 						      false, false);
2879 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2880 						      false, 0x6);
2881 		}
2882 	} else {
2883 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2884 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2885 						      false, false);
2886 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2887 						      false, 0x6);
2888 		} else {
2889 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2890 						      false, false);
2891 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2892 						      false, 0x6);
2893 		}
2894 	}
2895 }
2896 
halbtc8812a2ant_action_hid(IN struct btc_coexist * btcoexist)2897 void halbtc8812a2ant_action_hid(IN struct btc_coexist *btcoexist)
2898 {
2899 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
2900 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
2901 	u32		wifi_bw;
2902 	u8		bt_thresh0 = 0, bt_thresh1 = 0;
2903 
2904 	halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
2905 					      &bt_thresh1);
2906 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
2907 			bt_thresh1);
2908 
2909 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
2910 			  0);
2911 	/*	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
2912 
2913 	/* power save state */
2914 	halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
2915 					 0x0, 0x0);
2916 
2917 	/* coex table */
2918 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
2919 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
2920 	else
2921 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2922 
2923 	/* pstdma */
2924 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
2925 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
2926 	else
2927 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2928 
2929 	/* decrease BT power */
2930 	if (BTC_RSSI_LOW(bt_rssi_state))
2931 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2932 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
2933 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2934 	else
2935 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
2936 
2937 	/* limited Rx */
2938 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
2939 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
2940 					   0x8);
2941 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
2942 		 (!BTC_RSSI_LOW(bt_rssi_state)))
2943 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
2944 					   0x8);
2945 	else
2946 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
2947 					   0x8);
2948 
2949 
2950 	/* fw dac swing level */
2951 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2952 
2953 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2954 	/* sw mechanism */
2955 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
2956 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2957 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2958 						      false, false);
2959 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2960 						      false, 0x18);
2961 		} else {
2962 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
2963 						      false, false);
2964 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2965 						      false, 0x18);
2966 		}
2967 	} else {
2968 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
2969 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2970 						      false, false);
2971 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
2972 						      false, 0x18);
2973 		} else {
2974 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
2975 						      false, false);
2976 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
2977 						      false, 0x18);
2978 		}
2979 	}
2980 }
2981 
2982 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
halbtc8812a2ant_action_a2dp(IN struct btc_coexist * btcoexist)2983 void halbtc8812a2ant_action_a2dp(IN struct btc_coexist *btcoexist)
2984 {
2985 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
2986 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
2987 	u32		wifi_bw;
2988 	u8		bt_thresh0 = 0, bt_thresh1 = 0;
2989 	boolean			ap_enable = false;
2990 
2991 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
2992 			   &ap_enable);
2993 
2994 	halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
2995 					      &bt_thresh1);
2996 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
2997 			bt_thresh1);
2998 
2999 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3000 			  0);
3001 	/* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3002 
3003 	/* power save state */
3004 	if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3005 				    (!BTC_RSSI_LOW(bt_rssi_state))))
3006 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3007 						 true, 0x0, 0x0);
3008 	else
3009 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3010 						 0x50, 0x4);
3011 
3012 	/* coex table */
3013 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3014 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3015 	else
3016 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3017 
3018 	/* pstdma */
3019 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3020 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, false,
3021 						     1);
3022 	else
3023 		halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
3024 			btcoexist);
3025 
3026 	/* decrease BT power */
3027 	if (BTC_RSSI_LOW(bt_rssi_state))
3028 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3029 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3030 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3031 	else
3032 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3033 
3034 	/* limited Rx */
3035 	halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3036 
3037 	/* fw dac swing level */
3038 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3039 
3040 
3041 	/* sw mechanism */
3042 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3043 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
3044 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3045 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3046 						      false, false);
3047 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3048 						      false, 0x18);
3049 		} else {
3050 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3051 						      false, false);
3052 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3053 						      false, 0x18);
3054 		}
3055 	} else {
3056 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3057 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3058 						      false, false);
3059 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3060 						      false, 0x18);
3061 		} else {
3062 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3063 						      false, false);
3064 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3065 						      false, 0x18);
3066 		}
3067 	}
3068 }
3069 
halbtc8812a2ant_action_a2dp_pan_hs(IN struct btc_coexist * btcoexist)3070 void halbtc8812a2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
3071 {
3072 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3073 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
3074 	u32		wifi_bw;
3075 	u8		bt_thresh0 = 0, bt_thresh1 = 0;
3076 
3077 	halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3078 					      &bt_thresh1);
3079 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3080 			bt_thresh1);
3081 
3082 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3083 			  0);
3084 	/*	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3085 
3086 	/* power save state */
3087 	halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
3088 					 0x0, 0x0);
3089 
3090 	/* coex table	 */
3091 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3092 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3093 	else
3094 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3095 
3096 	/* pstdma	 */
3097 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3098 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, false,
3099 						     2);
3100 	else
3101 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, true, 2);
3102 
3103 	/* decrease BT power */
3104 	if (BTC_RSSI_LOW(bt_rssi_state))
3105 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3106 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3107 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3108 	else
3109 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3110 
3111 	/* limited Rx */
3112 	halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3113 
3114 	/* fw dac swing level */
3115 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3116 
3117 
3118 	/* sw mechanism */
3119 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3120 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
3121 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3122 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3123 						      false, false);
3124 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3125 						      true, 0x6);
3126 		} else {
3127 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3128 						      false, false);
3129 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3130 						      true, 0x6);
3131 		}
3132 	} else {
3133 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3134 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3135 						      false, false);
3136 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3137 						      true, 0x6);
3138 		} else {
3139 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3140 						      false, false);
3141 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3142 						      true, 0x6);
3143 		}
3144 	}
3145 }
3146 
halbtc8812a2ant_action_pan_edr(IN struct btc_coexist * btcoexist)3147 void halbtc8812a2ant_action_pan_edr(IN struct btc_coexist *btcoexist)
3148 {
3149 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3150 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
3151 	u32		wifi_bw;
3152 	u8		bt_thresh0 = 0, bt_thresh1 = 0;
3153 	boolean		ap_enable = false;
3154 
3155 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3156 			   &ap_enable);
3157 
3158 
3159 	halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3160 					      &bt_thresh1);
3161 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3162 			bt_thresh1);
3163 
3164 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3165 			  0);
3166 	/*	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3167 
3168 	/* power save state */
3169 	if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3170 				    (!BTC_RSSI_LOW(bt_rssi_state))))
3171 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3172 						 true, 0x0, 0x0);
3173 	else
3174 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3175 						 0x50, 0x4);
3176 
3177 	/* coex table */
3178 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3179 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3180 	else
3181 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3182 
3183 	/* pstdma */
3184 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3185 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1);
3186 	else
3187 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 85);
3188 
3189 	/* decrease BT power */
3190 	if (BTC_RSSI_LOW(bt_rssi_state))
3191 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3192 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3193 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3194 	else
3195 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3196 
3197 	/* limited Rx */
3198 	halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3199 
3200 	/* fw dac swing level */
3201 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3202 
3203 
3204 	/* sw mechanism */
3205 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3206 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
3207 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3208 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3209 						      false, false);
3210 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3211 						      false, 0x18);
3212 		} else {
3213 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3214 						      false, false);
3215 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3216 						      false, 0x18);
3217 		}
3218 	} else {
3219 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3220 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3221 						      false, false);
3222 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3223 						      false, 0x18);
3224 		} else {
3225 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3226 						      false, false);
3227 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3228 						      false, 0x18);
3229 		}
3230 	}
3231 }
3232 
3233 /* PAN(HS) only */
halbtc8812a2ant_action_pan_hs(IN struct btc_coexist * btcoexist)3234 void halbtc8812a2ant_action_pan_hs(IN struct btc_coexist *btcoexist)
3235 {
3236 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3237 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
3238 	u32		wifi_bw;
3239 
3240 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3241 			  0);
3242 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42);
3243 
3244 	/* power save state */
3245 	halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
3246 					 0x0, 0x0);
3247 
3248 	/* coex table */
3249 	halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3250 
3251 	/* pstdma */
3252 	halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
3253 
3254 	/* decrease BT power */
3255 	if (BTC_RSSI_LOW(bt_rssi_state))
3256 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3257 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3258 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3259 	else
3260 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3261 
3262 	/* limited Rx */
3263 	halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3264 
3265 	/* fw dac swing level */
3266 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3267 
3268 
3269 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3270 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
3271 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3272 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3273 						      false, false);
3274 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3275 						      false, 0x18);
3276 		} else {
3277 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3278 						      false, false);
3279 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3280 						      false, 0x18);
3281 		}
3282 	} else {
3283 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3284 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3285 						      false, false);
3286 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3287 						      false, 0x18);
3288 		} else {
3289 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3290 						      false, false);
3291 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3292 						      false, 0x18);
3293 		}
3294 	}
3295 }
3296 
3297 /* PAN(EDR)+A2DP */
halbtc8812a2ant_action_pan_edr_a2dp(IN struct btc_coexist * btcoexist)3298 void halbtc8812a2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
3299 {
3300 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3301 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
3302 	u32		wifi_bw;
3303 	u8		bt_thresh0 = 0, bt_thresh1 = 0;
3304 	boolean			ap_enable = false;
3305 
3306 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3307 			   &ap_enable);
3308 
3309 	halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3310 					      &bt_thresh1);
3311 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3312 			bt_thresh1);
3313 
3314 
3315 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3316 			  0);
3317 	/*	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3318 
3319 	/* power save state	 */
3320 	if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3321 				    (!BTC_RSSI_LOW(bt_rssi_state))))
3322 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3323 						 true, 0x0, 0x0);
3324 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3325 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3326 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3327 						 true, 0x0, 0x0);
3328 	else
3329 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3330 						 0x50, 0x4);
3331 
3332 	/* coex table */
3333 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3334 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3335 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3336 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3337 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3338 	else
3339 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3340 
3341 	/* pstdma */
3342 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3343 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, false,
3344 						     3);
3345 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3346 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3347 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, true, 3);
3348 	else {
3349 		coex_dm->auto_tdma_adjust = false;
3350 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86);
3351 	}
3352 
3353 	/* decrease BT power */
3354 	if (BTC_RSSI_LOW(bt_rssi_state))
3355 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3356 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3357 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3358 	else
3359 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3360 
3361 	/* limited Rx */
3362 	halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3363 
3364 	/* fw dac swing level */
3365 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3366 
3367 
3368 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3369 	/* sw mechanism	 */
3370 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
3371 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3372 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3373 						      false, false);
3374 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3375 						      false, 0x18);
3376 		} else {
3377 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
3378 						      false, false);
3379 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3380 						      false, 0x18);
3381 		}
3382 	} else {
3383 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3384 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3385 						      false, false);
3386 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3387 						      false, 0x18);
3388 		} else {
3389 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
3390 						      false, false);
3391 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3392 						      false, 0x18);
3393 		}
3394 	}
3395 }
3396 
halbtc8812a2ant_action_pan_edr_hid(IN struct btc_coexist * btcoexist)3397 void halbtc8812a2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
3398 {
3399 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3400 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
3401 	u32		wifi_bw;
3402 	u8		bt_thresh0 = 0, bt_thresh1 = 0;
3403 	boolean			ap_enable = false;
3404 
3405 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3406 			   &ap_enable);
3407 
3408 	halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3409 					      &bt_thresh1);
3410 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3411 			bt_thresh1);
3412 
3413 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3414 			  0);
3415 	/*	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3416 
3417 	/* power save state */
3418 	if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3419 				    (!BTC_RSSI_LOW(bt_rssi_state))))
3420 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3421 						 true, 0x0, 0x0);
3422 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3423 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3424 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3425 						 true, 0x0, 0x0);
3426 	else
3427 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3428 						 0x50, 0x4);
3429 
3430 	/* coex table */
3431 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3432 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3433 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3434 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3435 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3436 	else
3437 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3438 
3439 	/* pstdma */
3440 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3441 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
3442 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3443 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3444 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
3445 	else
3446 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 85);
3447 
3448 	/* decrease BT power */
3449 	if (BTC_RSSI_LOW(bt_rssi_state))
3450 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3451 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3452 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3453 	else
3454 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3455 
3456 	/* limited Rx */
3457 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3458 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3459 					   0x8);
3460 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3461 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3462 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3463 					   0x8);
3464 	else
3465 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
3466 					   0x8);
3467 
3468 	/* fw dac swing level */
3469 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3470 
3471 
3472 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3473 	/* sw mechanism */
3474 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
3475 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3476 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3477 						      false, false);
3478 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3479 						      false, 0x18);
3480 		} else {
3481 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3482 						      false, false);
3483 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3484 						      false, 0x18);
3485 		}
3486 	} else {
3487 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3488 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3489 						      false, false);
3490 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3491 						      false, 0x18);
3492 		} else {
3493 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3494 						      false, false);
3495 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3496 						      false, 0x18);
3497 		}
3498 	}
3499 }
3500 
3501 /* HID+A2DP+PAN(EDR) */
halbtc8812a2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist * btcoexist)3502 void halbtc8812a2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
3503 {
3504 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3505 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
3506 	u32		wifi_bw;
3507 	u8		bt_thresh0 = 0, bt_thresh1 = 0;
3508 	boolean			ap_enable = false;
3509 
3510 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3511 			   &ap_enable);
3512 
3513 	halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3514 					      &bt_thresh1);
3515 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3516 			bt_thresh1);
3517 
3518 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3519 			  0);
3520 	/*	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3521 
3522 	/* power save state */
3523 	if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3524 				    (!BTC_RSSI_LOW(bt_rssi_state))))
3525 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3526 						 true, 0x0, 0x0);
3527 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3528 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3529 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3530 						 true, 0x0, 0x0);
3531 	else
3532 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3533 						 0x50, 0x4);
3534 
3535 	/* coex table */
3536 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3537 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3538 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3539 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3540 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3541 	else
3542 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3543 
3544 	/* pstdma */
3545 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3546 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, false, 3);
3547 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3548 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3549 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 3);
3550 	else {
3551 		coex_dm->auto_tdma_adjust = false;
3552 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86);
3553 	}
3554 
3555 	/* decrease BT power */
3556 	if (BTC_RSSI_LOW(bt_rssi_state))
3557 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3558 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3559 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3560 	else
3561 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3562 
3563 	/* limited Rx */
3564 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3565 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3566 					   0x8);
3567 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3568 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3569 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3570 					   0x8);
3571 	else
3572 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
3573 					   0x8);
3574 
3575 
3576 	/* fw dac swing level */
3577 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3578 
3579 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3580 	/* sw mechanism */
3581 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
3582 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3583 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3584 						      false, false);
3585 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3586 						      false, 0x18);
3587 		} else {
3588 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3589 						      false, false);
3590 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3591 						      false, 0x18);
3592 		}
3593 	} else {
3594 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3595 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3596 						      false, false);
3597 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3598 						      false, 0x18);
3599 		} else {
3600 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3601 						      false, false);
3602 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3603 						      false, 0x18);
3604 		}
3605 	}
3606 }
3607 
halbtc8812a2ant_action_hid_a2dp_pan_hs(IN struct btc_coexist * btcoexist)3608 void halbtc8812a2ant_action_hid_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
3609 {
3610 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3611 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
3612 	u32		wifi_bw;
3613 	u8		bt_thresh0 = 0, bt_thresh1 = 0;
3614 
3615 	halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3616 					      &bt_thresh1);
3617 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3618 			bt_thresh1);
3619 
3620 
3621 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3622 			  0);
3623 	/*	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3624 
3625 	/* power save state */
3626 	halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, true,
3627 					 0x0, 0x0);
3628 
3629 	/* coex table */
3630 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3631 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3632 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3633 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3634 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3635 	else
3636 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3637 
3638 	/* pstdma */
3639 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3640 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, false, 2);
3641 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3642 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3643 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 2);
3644 	else
3645 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 2);
3646 
3647 	/* decrease BT power */
3648 	if (BTC_RSSI_LOW(bt_rssi_state))
3649 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3650 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3651 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3652 	else
3653 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3654 
3655 	/* limited Rx */
3656 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3657 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3658 					   0x8);
3659 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3660 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3661 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3662 					   0x8);
3663 	else
3664 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
3665 					   0x8);
3666 
3667 	/* fw dac swing level */
3668 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3669 
3670 
3671 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3672 	/* sw mechanism */
3673 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
3674 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3675 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3676 						      false, false);
3677 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3678 						      false, 0x18);
3679 		} else {
3680 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3681 						      false, false);
3682 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3683 						      false, 0x18);
3684 		}
3685 	} else {
3686 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3687 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3688 						      false, false);
3689 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3690 						      false, 0x18);
3691 		} else {
3692 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3693 						      false, false);
3694 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3695 						      false, 0x18);
3696 		}
3697 	}
3698 }
3699 
halbtc8812a2ant_action_hid_a2dp(IN struct btc_coexist * btcoexist)3700 void halbtc8812a2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
3701 {
3702 	u8		wifi_rssi_state = BTC_RSSI_STATE_HIGH,
3703 			bt_rssi_state = BTC_RSSI_STATE_HIGH;
3704 	u32		wifi_bw;
3705 	u8		bt_thresh0 = 0, bt_thresh1 = 0;
3706 	boolean			ap_enable = false;
3707 
3708 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
3709 			   &ap_enable);
3710 
3711 	halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
3712 					      &bt_thresh1);
3713 	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
3714 			bt_thresh1);
3715 
3716 	wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
3717 			  0);
3718 	/*	bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
3719 
3720 	/* power save state	 */
3721 	if ((ap_enable == true) || (BTC_RSSI_HIGH(wifi_rssi_state) &&
3722 				    (!BTC_RSSI_LOW(bt_rssi_state))))
3723 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3724 						 true, 0x0, 0x0);
3725 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3726 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3727 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3728 						 true, 0x0, 0x0);
3729 	else
3730 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, true,
3731 						 0x50, 0x4);
3732 
3733 	/* coex table */
3734 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3735 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
3736 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3737 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3738 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3739 	else
3740 		halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3741 
3742 	/* pstdma */
3743 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3744 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, false, 2);
3745 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3746 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3747 		halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 2);
3748 	else {
3749 		coex_dm->auto_tdma_adjust = false;
3750 		halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 82);
3751 	}
3752 
3753 	/* decrease BT power */
3754 	if (BTC_RSSI_LOW(bt_rssi_state))
3755 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3756 	else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3757 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3758 	else
3759 		halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
3760 
3761 	/* limited Rx */
3762 	if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
3763 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3764 					   0x8);
3765 	else if (BTC_RSSI_LOW(wifi_rssi_state) &&
3766 		 (!BTC_RSSI_LOW(bt_rssi_state)))
3767 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
3768 					   0x8);
3769 	else
3770 		halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
3771 					   0x8);
3772 
3773 	/* fw dac swing level */
3774 	halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3775 
3776 
3777 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3778 	/* sw mechanism */
3779 	if (BTC_WIFI_BW_HT40 == wifi_bw) {
3780 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3781 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3782 						      false, false);
3783 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3784 						      false, 0x18);
3785 		} else {
3786 			halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
3787 						      false, false);
3788 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3789 						      false, 0x18);
3790 		}
3791 	} else {
3792 		if (BTC_RSSI_HIGH(wifi_rssi_state)) {
3793 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3794 						      false, false);
3795 			halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
3796 						      false, 0x18);
3797 		} else {
3798 			halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
3799 						      false, false);
3800 			halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
3801 						      false, 0x18);
3802 		}
3803 	}
3804 }
3805 
3806 
halbtc8812a2ant_coex_under_5g(IN struct btc_coexist * btcoexist)3807 void halbtc8812a2ant_coex_under_5g(IN struct btc_coexist *btcoexist)
3808 {
3809 	halbtc8812a2ant_coex_all_off(btcoexist);
3810 
3811 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3812 		"[BTCoex], Under 5G, force set BT to ignore Wlan active!!\n");
3813 	BTC_TRACE(trace_buf);
3814 	halbtc8812a2ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
3815 }
3816 /* **************************************************** */
halbtc8812a2ant_run_coexist_mechanism(IN struct btc_coexist * btcoexist)3817 void halbtc8812a2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
3818 {
3819 	boolean				wifi_under_5g = false;
3820 	u8				algorithm = 0;
3821 
3822 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3823 		    "[BTCoex], RunCoexistMechanism()===>\n");
3824 	BTC_TRACE(trace_buf);
3825 
3826 	if (btcoexist->manual_control) {
3827 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3828 			"[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
3829 		BTC_TRACE(trace_buf);
3830 		return;
3831 	}
3832 
3833 	if (btcoexist->stop_coex_dm) {
3834 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3835 			"[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
3836 		BTC_TRACE(trace_buf);
3837 		return;
3838 	}
3839 
3840 	if (coex_sta->under_ips) {
3841 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3842 			    "[BTCoex], wifi is under IPS !!!\n");
3843 		BTC_TRACE(trace_buf);
3844 		return;
3845 	}
3846 
3847 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3848 	if (wifi_under_5g) {
3849 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3850 			"[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n");
3851 		BTC_TRACE(trace_buf);
3852 		halbtc8812a2ant_coex_under_5g(btcoexist);
3853 		return;
3854 	}
3855 
3856 
3857 	algorithm = halbtc8812a2ant_action_algorithm(btcoexist);
3858 	if (coex_sta->c2h_bt_inquiry_page &&
3859 	    (BT_8812A_2ANT_COEX_ALGO_PANHS != algorithm)) {
3860 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3861 			    "[BTCoex], BT is under inquiry/page scan !!\n");
3862 		BTC_TRACE(trace_buf);
3863 		halbtc8812a2ant_action_bt_inquiry(btcoexist);
3864 		return;
3865 	}
3866 
3867 	coex_dm->cur_algorithm = algorithm;
3868 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n",
3869 		    coex_dm->cur_algorithm);
3870 	BTC_TRACE(trace_buf);
3871 
3872 	if (halbtc8812a2ant_is_common_action(btcoexist)) {
3873 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3874 			    "[BTCoex], Action 2-Ant common.\n");
3875 		BTC_TRACE(trace_buf);
3876 		coex_dm->auto_tdma_adjust = false;
3877 		coex_dm->auto_tdma_adjust_low_rssi = false;
3878 	} else {
3879 		if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
3880 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3881 				"[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n",
3882 				coex_dm->pre_algorithm, coex_dm->cur_algorithm);
3883 			BTC_TRACE(trace_buf);
3884 			coex_dm->auto_tdma_adjust = false;
3885 			coex_dm->auto_tdma_adjust_low_rssi = false;
3886 		}
3887 		switch (coex_dm->cur_algorithm) {
3888 		case BT_8812A_2ANT_COEX_ALGO_SCO:
3889 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3890 				"[BTCoex], Action 2-Ant, algorithm = SCO.\n");
3891 			BTC_TRACE(trace_buf);
3892 			halbtc8812a2ant_action_sco(btcoexist);
3893 			break;
3894 		case BT_8812A_2ANT_COEX_ALGO_SCO_HID:
3895 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3896 				"[BTCoex], Action 2-Ant, algorithm = SCO+HID.\n");
3897 			BTC_TRACE(trace_buf);
3898 			halbtc8812a2ant_action_sco_hid(btcoexist);
3899 			break;
3900 		case BT_8812A_2ANT_COEX_ALGO_HID:
3901 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3902 				"[BTCoex], Action 2-Ant, algorithm = HID.\n");
3903 			BTC_TRACE(trace_buf);
3904 			halbtc8812a2ant_action_hid(btcoexist);
3905 			break;
3906 		case BT_8812A_2ANT_COEX_ALGO_A2DP:
3907 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3908 				"[BTCoex], Action 2-Ant, algorithm = A2DP.\n");
3909 			BTC_TRACE(trace_buf);
3910 			halbtc8812a2ant_action_a2dp(btcoexist);
3911 			break;
3912 		case BT_8812A_2ANT_COEX_ALGO_A2DP_PANHS:
3913 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3914 				"[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n");
3915 			BTC_TRACE(trace_buf);
3916 			halbtc8812a2ant_action_a2dp_pan_hs(btcoexist);
3917 			break;
3918 		case BT_8812A_2ANT_COEX_ALGO_PANEDR:
3919 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3920 				"[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n");
3921 			BTC_TRACE(trace_buf);
3922 			halbtc8812a2ant_action_pan_edr(btcoexist);
3923 			break;
3924 		case BT_8812A_2ANT_COEX_ALGO_PANHS:
3925 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3926 				"[BTCoex], Action 2-Ant, algorithm = HS mode.\n");
3927 			BTC_TRACE(trace_buf);
3928 			halbtc8812a2ant_action_pan_hs(btcoexist);
3929 			break;
3930 		case BT_8812A_2ANT_COEX_ALGO_PANEDR_A2DP:
3931 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3932 				"[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n");
3933 			BTC_TRACE(trace_buf);
3934 			halbtc8812a2ant_action_pan_edr_a2dp(btcoexist);
3935 			break;
3936 		case BT_8812A_2ANT_COEX_ALGO_PANEDR_HID:
3937 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3938 				"[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n");
3939 			BTC_TRACE(trace_buf);
3940 			halbtc8812a2ant_action_pan_edr_hid(btcoexist);
3941 			break;
3942 		case BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
3943 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3944 				"[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n");
3945 			BTC_TRACE(trace_buf);
3946 			halbtc8812a2ant_action_hid_a2dp_pan_edr(
3947 				btcoexist);
3948 			break;
3949 		case BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANHS:
3950 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3951 				"[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN(HS).\n");
3952 			BTC_TRACE(trace_buf);
3953 			halbtc8812a2ant_action_hid_a2dp_pan_hs(
3954 				btcoexist);
3955 			break;
3956 		case BT_8812A_2ANT_COEX_ALGO_HID_A2DP:
3957 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3958 				"[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n");
3959 			BTC_TRACE(trace_buf);
3960 			halbtc8812a2ant_action_hid_a2dp(btcoexist);
3961 			break;
3962 		default:
3963 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3964 				"[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3965 			BTC_TRACE(trace_buf);
3966 			halbtc8812a2ant_coex_all_off(btcoexist);
3967 			break;
3968 		}
3969 		coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3970 	}
3971 
3972 }
3973 
halbtc8812a2ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean back_up)3974 void halbtc8812a2ant_init_hw_config(IN struct btc_coexist *btcoexist,
3975 				    IN boolean back_up)
3976 {
3977 	u8	u8tmp = 0;
3978 
3979 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3980 		    "[BTCoex], 2Ant Init HW Config!!\n");
3981 	BTC_TRACE(trace_buf);
3982 
3983 	if (back_up) {
3984 		/* backup rf 0x1e value */
3985 		coex_dm->bt_rf_0x1e_backup =
3986 			btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e,
3987 						  0xfffff);
3988 
3989 		coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
3990 					    0x430);
3991 		coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
3992 					    0x434);
3993 		coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
3994 						      btcoexist, 0x42a);
3995 		coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
3996 				btcoexist, 0x456);
3997 	}
3998 
3999 	/* ant sw control to BT */
4000 	halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX, true,
4001 				     false);
4002 
4003 	/* 0x790[5:0]=0x5 */
4004 	u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
4005 	u8tmp &= 0xc0;
4006 	u8tmp |= 0x5;
4007 	btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
4008 
4009 	/* PTA parameter */
4010 	btcoexist->btc_write_1byte(btcoexist, 0x6cc, 0x0);
4011 	btcoexist->btc_write_4byte(btcoexist, 0x6c8, 0xffff);
4012 	btcoexist->btc_write_4byte(btcoexist, 0x6c4, 0x55555555);
4013 	btcoexist->btc_write_4byte(btcoexist, 0x6c0, 0x55555555);
4014 
4015 	/* coex parameters */
4016 	btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
4017 
4018 	/* enable counter statistics */
4019 	btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
4020 
4021 	/* enable PTA */
4022 	btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20);
4023 
4024 	/* bt clock related */
4025 	u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x4);
4026 	u8tmp |= BIT(7);
4027 	btcoexist->btc_write_1byte(btcoexist, 0x4, u8tmp);
4028 
4029 	/* bt clock related */
4030 	u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7);
4031 	u8tmp |= BIT(1);
4032 	btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp);
4033 }
4034 
4035 /* ************************************************************
4036  * work around function start with wa_halbtc8812a2ant_
4037  * ************************************************************
4038  * ************************************************************
4039  * extern function start with ex_halbtc8812a2ant_
4040  * ************************************************************ */
ex_halbtc8812a2ant_power_on_setting(IN struct btc_coexist * btcoexist)4041 void ex_halbtc8812a2ant_power_on_setting(IN struct btc_coexist *btcoexist)
4042 {
4043 }
4044 
ex_halbtc8812a2ant_init_hw_config(IN struct btc_coexist * btcoexist,IN boolean wifi_only)4045 void ex_halbtc8812a2ant_init_hw_config(IN struct btc_coexist *btcoexist,
4046 				       IN boolean wifi_only)
4047 {
4048 	halbtc8812a2ant_init_hw_config(btcoexist, true);
4049 	btcoexist->stop_coex_dm = false;
4050 }
4051 
ex_halbtc8812a2ant_init_coex_dm(IN struct btc_coexist * btcoexist)4052 void ex_halbtc8812a2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
4053 {
4054 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4055 		    "[BTCoex], Coex Mechanism Init!!\n");
4056 	BTC_TRACE(trace_buf);
4057 	btcoexist->stop_coex_dm = false;
4058 	halbtc8812a2ant_init_coex_dm(btcoexist);
4059 }
4060 
ex_halbtc8812a2ant_display_coex_info(IN struct btc_coexist * btcoexist)4061 void ex_halbtc8812a2ant_display_coex_info(IN struct btc_coexist *btcoexist)
4062 {
4063 	struct  btc_board_info		*board_info = &btcoexist->board_info;
4064 	struct  btc_bt_link_info	*bt_link_info = &btcoexist->bt_link_info;
4065 	u8				*cli_buf = btcoexist->cli_buf;
4066 	u8				u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
4067 	u16				u16tmp[4];
4068 	u32				u32tmp[4];
4069 	u32				fw_ver = 0, bt_patch_ver = 0;
4070 
4071 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4072 		   "\r\n ============[BT Coexist info]============");
4073 	CL_PRINTF(cli_buf);
4074 
4075 	if (btcoexist->manual_control) {
4076 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4077 			"\r\n ============[Under Manual Control]============");
4078 		CL_PRINTF(cli_buf);
4079 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4080 			   "\r\n ==========================================");
4081 		CL_PRINTF(cli_buf);
4082 	}
4083 
4084 	if (btcoexist->stop_coex_dm) {
4085 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4086 			   "\r\n ============[Coex is STOPPED]============");
4087 		CL_PRINTF(cli_buf);
4088 		CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4089 			   "\r\n ==========================================");
4090 		CL_PRINTF(cli_buf);
4091 	}
4092 
4093 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
4094 		   "Ant PG number/ Ant mechanism:",
4095 		   board_info->pg_ant_num, board_info->btdm_ant_num);
4096 	CL_PRINTF(cli_buf);
4097 
4098 	btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
4099 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
4100 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4101 		   "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
4102 		   "CoexVer/ FwVer/ PatchVer",
4103 		   glcoex_ver_date_8812a_2ant, glcoex_ver_8812a_2ant, fw_ver,
4104 		   bt_patch_ver, bt_patch_ver);
4105 	CL_PRINTF(cli_buf);
4106 
4107 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
4108 		   "Wifi channel informed to BT",
4109 		   coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
4110 		   coex_dm->wifi_chnl_info[2]);
4111 	CL_PRINTF(cli_buf);
4112 
4113 	/* wifi status */
4114 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4115 		   "============[Wifi Status]============");
4116 	CL_PRINTF(cli_buf);
4117 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
4118 
4119 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4120 		   "============[BT Status]============");
4121 	CL_PRINTF(cli_buf);
4122 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
4123 		   "BT [status/ rssi/ retryCnt]",
4124 		   ((coex_sta->bt_disabled) ? ("disabled") :	((
4125 		   coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
4126 			   : ((BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
4127 			       coex_dm->bt_status) ? "non-connected idle" :
4128 		((BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
4129 				       ? "connected-idle" : "busy")))),
4130 		   coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
4131 	CL_PRINTF(cli_buf);
4132 
4133 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
4134 		   "SCO/HID/PAN/A2DP",
4135 		   bt_link_info->sco_exist, bt_link_info->hid_exist,
4136 		   bt_link_info->pan_exist, bt_link_info->a2dp_exist);
4137 	CL_PRINTF(cli_buf);
4138 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
4139 
4140 	bt_info_ext = coex_sta->bt_info_ext;
4141 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
4142 		   "BT Info A2DP rate",
4143 		   (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
4144 	CL_PRINTF(cli_buf);
4145 
4146 	for (i = 0; i < BT_INFO_SRC_8812A_2ANT_MAX; i++) {
4147 		if (coex_sta->bt_info_c2h_cnt[i]) {
4148 			CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4149 				"\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
4150 				   glbt_info_src_8812a_2ant[i],
4151 				   coex_sta->bt_info_c2h[i][0],
4152 				   coex_sta->bt_info_c2h[i][1],
4153 				   coex_sta->bt_info_c2h[i][2],
4154 				   coex_sta->bt_info_c2h[i][3],
4155 				   coex_sta->bt_info_c2h[i][4],
4156 				   coex_sta->bt_info_c2h[i][5],
4157 				   coex_sta->bt_info_c2h[i][6],
4158 				   coex_sta->bt_info_c2h_cnt[i]);
4159 			CL_PRINTF(cli_buf);
4160 		}
4161 	}
4162 
4163 	/* Sw mechanism	 */
4164 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4165 		   "============[Sw mechanism]============");
4166 	CL_PRINTF(cli_buf);
4167 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ",
4168 		   "SM1[ShRf/ LpRA/ LimDig]",
4169 		   coex_dm->cur_rf_rx_lpf_shrink, coex_dm->cur_low_penalty_ra,
4170 		   coex_dm->limited_dig);
4171 	CL_PRINTF(cli_buf);
4172 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ",
4173 		   "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
4174 		   coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
4175 		   coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
4176 	CL_PRINTF(cli_buf);
4177 
4178 	/* Fw mechanism		 */
4179 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4180 		   "============[Fw mechanism]============");
4181 	CL_PRINTF(cli_buf);
4182 
4183 	ps_tdma_case = coex_dm->cur_ps_tdma;
4184 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4185 		"\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d/%d)",
4186 		   "PS TDMA",
4187 		   coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
4188 		   coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
4189 		   coex_dm->ps_tdma_para[4],
4190 		   ps_tdma_case, coex_dm->auto_tdma_adjust,
4191 		   coex_dm->auto_tdma_adjust_low_rssi);
4192 	CL_PRINTF(cli_buf);
4193 
4194 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
4195 		   "DecBtPwr/ IgnWlanAct",
4196 		   coex_dm->cur_bt_dec_pwr_lvl, coex_dm->cur_ignore_wlan_act);
4197 	CL_PRINTF(cli_buf);
4198 
4199 	/* Hw setting		 */
4200 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4201 		   "============[Hw setting]============");
4202 	CL_PRINTF(cli_buf);
4203 
4204 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x",
4205 		   "RF-A, 0x1e initVal",
4206 		   coex_dm->bt_rf_0x1e_backup);
4207 	CL_PRINTF(cli_buf);
4208 
4209 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
4210 		   "backup ARFR1/ARFR2/RL/AMaxTime",
4211 		   coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2,
4212 		   coex_dm->backup_retry_limit,
4213 		   coex_dm->backup_ampdu_max_time);
4214 	CL_PRINTF(cli_buf);
4215 
4216 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
4217 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
4218 	u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
4219 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
4220 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
4221 		   "0x430/0x434/0x42a/0x456",
4222 		   u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
4223 	CL_PRINTF(cli_buf);
4224 
4225 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
4226 	u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
4227 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x ",
4228 		   "0x778 (W_Act)/ 0x6cc (CoTab Sel)",
4229 		   u8tmp[0], u8tmp[1]);
4230 	CL_PRINTF(cli_buf);
4231 
4232 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
4233 	u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xc5b);
4234 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4235 		   "0x8db(ADC)/0xc5b[29:25](DAC)",
4236 		   ((u8tmp[0] & 0x60) >> 5), ((u8tmp[1] & 0x3e) >> 1));
4237 	CL_PRINTF(cli_buf);
4238 
4239 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcb3);
4240 	u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xcb7);
4241 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4242 		   "0xcb3/ 0xcb7",
4243 		   u8tmp[0], u8tmp[1]);
4244 	CL_PRINTF(cli_buf);
4245 
4246 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
4247 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
4248 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x974);
4249 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
4250 		   "0x40/ 0x4c[24:23]/ 0x974",
4251 		   u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u32tmp[1]);
4252 	CL_PRINTF(cli_buf);
4253 
4254 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
4255 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
4256 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4257 		   "0x550(bcn ctrl)/0x522",
4258 		   u32tmp[0], u8tmp[0]);
4259 	CL_PRINTF(cli_buf);
4260 
4261 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
4262 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa0a);
4263 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4264 		   "0xc50(DIG)/0xa0a(CCK-TH)",
4265 		   u32tmp[0], u8tmp[0]);
4266 	CL_PRINTF(cli_buf);
4267 
4268 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48);
4269 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
4270 	u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
4271 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4272 		   "0xf48/ 0xa5b (FA cnt-- OFDM : CCK)",
4273 		   u32tmp[0], (u8tmp[0] << 8) + u8tmp[1]);
4274 	CL_PRINTF(cli_buf);
4275 
4276 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
4277 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
4278 	u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
4279 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
4280 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4281 		   "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4282 		   "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
4283 		   u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
4284 	CL_PRINTF(cli_buf);
4285 
4286 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4287 		   "0x770(high-pri rx/tx)",
4288 		   coex_sta->high_priority_rx, coex_sta->high_priority_tx);
4289 	CL_PRINTF(cli_buf);
4290 	CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4291 		   "0x774(low-pri rx/tx)",
4292 		   coex_sta->low_priority_rx, coex_sta->low_priority_tx);
4293 	CL_PRINTF(cli_buf);
4294 #if (BT_AUTO_REPORT_ONLY_8812A_2ANT == 1)
4295 	halbtc8812a2ant_monitor_bt_ctr(btcoexist);
4296 #endif
4297 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
4298 }
4299 
4300 
ex_halbtc8812a2ant_ips_notify(IN struct btc_coexist * btcoexist,IN u8 type)4301 void ex_halbtc8812a2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
4302 {
4303 	boolean	wifi_under_5g = false;
4304 
4305 	if (btcoexist->manual_control ||	btcoexist->stop_coex_dm)
4306 		return;
4307 
4308 	if (BTC_IPS_ENTER == type) {
4309 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4310 			    "[BTCoex], IPS ENTER notify\n");
4311 		BTC_TRACE(trace_buf);
4312 		coex_sta->under_ips = true;
4313 		halbtc8812a2ant_coex_all_off(btcoexist);
4314 		halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX,
4315 					     false, true);
4316 
4317 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4318 			"[BTCoex], IPS notify, force set BT to ignore Wlan active!!\n");
4319 		BTC_TRACE(trace_buf);
4320 		halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
4321 		ex_halbtc8812a2ant_media_status_notify(btcoexist,
4322 						       BTC_MEDIA_DISCONNECT);
4323 	} else if (BTC_IPS_LEAVE == type) {
4324 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4325 			    "[BTCoex], IPS LEAVE notify\n");
4326 		BTC_TRACE(trace_buf);
4327 		coex_sta->under_ips = false;
4328 
4329 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
4330 				   &wifi_under_5g);
4331 		if (!wifi_under_5g) {
4332 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4333 				"[BTCoex], IPS notify, force set BT NOT to ignore Wlan active!!\n");
4334 			BTC_TRACE(trace_buf);
4335 			halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC,
4336 							false);
4337 		}
4338 	}
4339 }
4340 
ex_halbtc8812a2ant_lps_notify(IN struct btc_coexist * btcoexist,IN u8 type)4341 void ex_halbtc8812a2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
4342 {
4343 
4344 	if (btcoexist->manual_control ||	btcoexist->stop_coex_dm)
4345 		return;
4346 
4347 	if (BTC_LPS_ENABLE == type) {
4348 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4349 			    "[BTCoex], LPS ENABLE notify\n");
4350 		BTC_TRACE(trace_buf);
4351 		coex_sta->under_lps = true;
4352 	} else if (BTC_LPS_DISABLE == type) {
4353 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4354 			    "[BTCoex], LPS DISABLE notify\n");
4355 		BTC_TRACE(trace_buf);
4356 		coex_sta->under_lps = false;
4357 	}
4358 }
4359 
ex_halbtc8812a2ant_scan_notify(IN struct btc_coexist * btcoexist,IN u8 type)4360 void ex_halbtc8812a2ant_scan_notify(IN struct btc_coexist *btcoexist,
4361 				    IN u8 type)
4362 {
4363 	if (BTC_SCAN_START == type) {
4364 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4365 			    "[BTCoex], SCAN START notify\n");
4366 		BTC_TRACE(trace_buf);
4367 	} else if (BTC_SCAN_FINISH == type) {
4368 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4369 			    "[BTCoex], SCAN FINISH notify\n");
4370 		BTC_TRACE(trace_buf);
4371 	}
4372 }
4373 
ex_halbtc8812a2ant_connect_notify(IN struct btc_coexist * btcoexist,IN u8 type)4374 void ex_halbtc8812a2ant_connect_notify(IN struct btc_coexist *btcoexist,
4375 				       IN u8 type)
4376 {
4377 	if (BTC_ASSOCIATE_START == type) {
4378 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4379 			    "[BTCoex], CONNECT START notify\n");
4380 		BTC_TRACE(trace_buf);
4381 	} else if (BTC_ASSOCIATE_FINISH == type) {
4382 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4383 			    "[BTCoex], CONNECT FINISH notify\n");
4384 		BTC_TRACE(trace_buf);
4385 	}
4386 }
4387 
ex_halbtc8812a2ant_media_status_notify(IN struct btc_coexist * btcoexist,IN u8 type)4388 void ex_halbtc8812a2ant_media_status_notify(IN struct btc_coexist *btcoexist,
4389 		IN u8 type)
4390 {
4391 	u8			data_len = 5;
4392 	u8			buf[6] = {0};
4393 	u8			h2c_parameter[3] = {0};
4394 	u32			wifi_bw;
4395 	u8			wifi_central_chnl;
4396 
4397 	if (btcoexist->manual_control ||
4398 	    btcoexist->stop_coex_dm ||
4399 	    coex_sta->bt_disabled)
4400 		return;
4401 
4402 	if (BTC_MEDIA_CONNECT == type) {
4403 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4404 			    "[BTCoex], MEDIA connect notify\n");
4405 		BTC_TRACE(trace_buf);
4406 	} else {
4407 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4408 			    "[BTCoex], MEDIA disconnect notify\n");
4409 		BTC_TRACE(trace_buf);
4410 	}
4411 
4412 	/* only 2.4G we need to inform bt the chnl mask */
4413 	btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
4414 			   &wifi_central_chnl);
4415 	if ((BTC_MEDIA_CONNECT == type) &&
4416 	    (wifi_central_chnl <= 14)) {
4417 		h2c_parameter[0] = 0x1;
4418 		h2c_parameter[1] = wifi_central_chnl;
4419 		btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
4420 		if (BTC_WIFI_BW_HT40 == wifi_bw)
4421 			h2c_parameter[2] = 0x30;
4422 		else
4423 			h2c_parameter[2] = 0x20;
4424 	}
4425 
4426 	coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
4427 	coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
4428 	coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
4429 
4430 	buf[0] = data_len;
4431 	buf[1] = 0x5;				/* OP_Code */
4432 	buf[2] = 0x3;				/* OP_Code_Length */
4433 	buf[3] = h2c_parameter[0];	/* OP_Code_Content */
4434 	buf[4] = h2c_parameter[1];
4435 	buf[5] = h2c_parameter[2];
4436 
4437 	btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
4438 			   (void *)&buf[0]);
4439 }
4440 
ex_halbtc8812a2ant_specific_packet_notify(IN struct btc_coexist * btcoexist,IN u8 type)4441 void ex_halbtc8812a2ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
4442 		IN u8 type)
4443 {
4444 	if (type == BTC_PACKET_DHCP) {
4445 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4446 			    "[BTCoex], DHCP Packet notify\n");
4447 		BTC_TRACE(trace_buf);
4448 	}
4449 
4450 }
4451 
ex_halbtc8812a2ant_bt_info_notify(IN struct btc_coexist * btcoexist,IN u8 * tmp_buf,IN u8 length)4452 void ex_halbtc8812a2ant_bt_info_notify(IN struct btc_coexist *btcoexist,
4453 				       IN u8 *tmp_buf, IN u8 length)
4454 {
4455 	u8			bt_info = 0;
4456 	u8			i, rsp_source = 0;
4457 	boolean			bt_busy = false, limited_dig = false;
4458 	boolean			wifi_connected = false, wifi_under_5g = false;
4459 
4460 	coex_sta->c2h_bt_info_req_sent = false;
4461 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4462 
4463 	rsp_source = tmp_buf[0] & 0xf;
4464 	if (rsp_source >= BT_INFO_SRC_8812A_2ANT_MAX)
4465 		rsp_source = BT_INFO_SRC_8812A_2ANT_WIFI_FW;
4466 	coex_sta->bt_info_c2h_cnt[rsp_source]++;
4467 
4468 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4469 		    "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
4470 		    length);
4471 	BTC_TRACE(trace_buf);
4472 	for (i = 0; i < length; i++) {
4473 		coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
4474 		if (i == 1)
4475 			bt_info = tmp_buf[i];
4476 		if (i == length - 1) {
4477 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
4478 				    tmp_buf[i]);
4479 			BTC_TRACE(trace_buf);
4480 		} else {
4481 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
4482 				    tmp_buf[i]);
4483 			BTC_TRACE(trace_buf);
4484 		}
4485 	}
4486 
4487 	if (BT_INFO_SRC_8812A_2ANT_WIFI_FW != rsp_source) {
4488 		coex_sta->bt_retry_cnt =	/* [3:0] */
4489 			coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
4490 
4491 		coex_sta->bt_rssi =
4492 			coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
4493 
4494 		coex_sta->bt_info_ext =
4495 			coex_sta->bt_info_c2h[rsp_source][4];
4496 
4497 		/* Here we need to resend some wifi info to BT */
4498 		/* because bt is reset and loss of the info. */
4499 		if ((coex_sta->bt_info_ext & BIT(1))) {
4500 			BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4501 				"[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
4502 			BTC_TRACE(trace_buf);
4503 			btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
4504 					   &wifi_connected);
4505 			if (wifi_connected)
4506 				ex_halbtc8812a2ant_media_status_notify(
4507 					btcoexist, BTC_MEDIA_CONNECT);
4508 			else
4509 				ex_halbtc8812a2ant_media_status_notify(
4510 					btcoexist, BTC_MEDIA_DISCONNECT);
4511 		}
4512 
4513 		if ((coex_sta->bt_info_ext & BIT(3)) && !wifi_under_5g) {
4514 			/* BT already ignored WlanAct */
4515 			if (!btcoexist->manual_control &&
4516 			    !btcoexist->stop_coex_dm) {
4517 				if (!coex_sta->under_ips) {
4518 					BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4519 						"[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
4520 					BTC_TRACE(trace_buf);
4521 					halbtc8812a2ant_ignore_wlan_act(
4522 						btcoexist, FORCE_EXEC, false);
4523 				}
4524 			}
4525 		} else {
4526 			/* BT already NOT ignore Wlan active, do nothing here. */
4527 
4528 			if (coex_sta->under_ips) {
4529 				/* work around for 8812a combo hw bug => when IPS, wlanAct is always high. */
4530 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4531 					"[BTCoex], wifi is under IPS, set BT to ignore Wlan active!!\n");
4532 				BTC_TRACE(trace_buf);
4533 				halbtc8812a2ant_ignore_wlan_act(btcoexist,
4534 							FORCE_EXEC, true);
4535 			}
4536 		}
4537 	}
4538 
4539 	/* check BIT2 first ==> check if bt is under inquiry or page scan */
4540 	if (bt_info & BT_INFO_8812A_2ANT_B_INQ_PAGE)
4541 		coex_sta->c2h_bt_inquiry_page = true;
4542 	else
4543 		coex_sta->c2h_bt_inquiry_page = false;
4544 
4545 	/* set link exist status */
4546 	if (!(bt_info & BT_INFO_8812A_2ANT_B_CONNECTION)) {
4547 		coex_sta->bt_link_exist = false;
4548 		coex_sta->pan_exist = false;
4549 		coex_sta->a2dp_exist = false;
4550 		coex_sta->hid_exist = false;
4551 		coex_sta->sco_exist = false;
4552 		coex_sta->acl_busy = false;
4553 	} else {	/* connection exists */
4554 		coex_sta->bt_link_exist = true;
4555 		if (bt_info & BT_INFO_8812A_2ANT_B_FTP)
4556 			coex_sta->pan_exist = true;
4557 		else
4558 			coex_sta->pan_exist = false;
4559 		if (bt_info & BT_INFO_8812A_2ANT_B_A2DP)
4560 			coex_sta->a2dp_exist = true;
4561 		else
4562 			coex_sta->a2dp_exist = false;
4563 		if (bt_info & BT_INFO_8812A_2ANT_B_HID)
4564 			coex_sta->hid_exist = true;
4565 		else
4566 			coex_sta->hid_exist = false;
4567 		if (bt_info & BT_INFO_8812A_2ANT_B_SCO_ESCO)
4568 			coex_sta->sco_exist = true;
4569 		else
4570 			coex_sta->sco_exist = false;
4571 		if (bt_info & BT_INFO_8812A_2ANT_B_ACL_BUSY)
4572 			coex_sta->acl_busy = true;
4573 		else
4574 			coex_sta->acl_busy = false;
4575 
4576 	}
4577 
4578 	halbtc8812a2ant_update_bt_link_info(btcoexist);
4579 
4580 	if (!(bt_info & BT_INFO_8812A_2ANT_B_CONNECTION)) {
4581 		coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
4582 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4583 			"[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
4584 		BTC_TRACE(trace_buf);
4585 	} else if (bt_info ==
4586 		BT_INFO_8812A_2ANT_B_CONNECTION) {	/* connection exists but no busy */
4587 		coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE;
4588 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4589 			    "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
4590 		BTC_TRACE(trace_buf);
4591 	} else if ((bt_info & BT_INFO_8812A_2ANT_B_SCO_ESCO) ||
4592 		   (bt_info & BT_INFO_8812A_2ANT_B_SCO_BUSY)) {
4593 		coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_SCO_BUSY;
4594 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4595 			    "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
4596 		BTC_TRACE(trace_buf);
4597 	} else if (bt_info & BT_INFO_8812A_2ANT_B_ACL_BUSY) {
4598 		coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_ACL_BUSY;
4599 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4600 			    "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
4601 		BTC_TRACE(trace_buf);
4602 	} else {
4603 		coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_MAX;
4604 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4605 			"[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
4606 		BTC_TRACE(trace_buf);
4607 	}
4608 
4609 	if ((BT_8812A_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
4610 	    (BT_8812A_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
4611 	    (BT_8812A_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) {
4612 		bt_busy = true;
4613 		if (!wifi_under_5g)
4614 			limited_dig = true;
4615 	} else {
4616 		bt_busy = false;
4617 		limited_dig = false;
4618 	}
4619 
4620 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
4621 
4622 	coex_dm->limited_dig = limited_dig;
4623 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
4624 
4625 	halbtc8812a2ant_run_coexist_mechanism(btcoexist);
4626 }
4627 
ex_halbtc8812a2ant_rf_status_notify(IN struct btc_coexist * btcoexist,IN u8 type)4628 void ex_halbtc8812a2ant_rf_status_notify(IN struct btc_coexist *btcoexist,
4629 		IN u8 type)
4630 {
4631 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
4632 	BTC_TRACE(trace_buf);
4633 
4634 	if (BTC_RF_ON == type) {
4635 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4636 			    "[BTCoex], RF is turned ON!!\n");
4637 		BTC_TRACE(trace_buf);
4638 		btcoexist->stop_coex_dm = false;
4639 	}
4640 	if (BTC_RF_OFF == type) {
4641 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4642 			    "[BTCoex], RF is turned OFF!!\n");
4643 		BTC_TRACE(trace_buf);
4644 
4645 		halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
4646 						 true, 0x0, 0x0);
4647 		halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
4648 		/* halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, FORCE_EXEC, false, true); */
4649 		halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
4650 		btcoexist->stop_coex_dm = true;
4651 
4652 	}
4653 }
4654 
4655 
ex_halbtc8812a2ant_halt_notify(IN struct btc_coexist * btcoexist)4656 void ex_halbtc8812a2ant_halt_notify(IN struct btc_coexist *btcoexist)
4657 {
4658 
4659 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
4660 	BTC_TRACE(trace_buf);
4661 
4662 	halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX, false,
4663 				     true);
4664 	BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4665 		"[BTCoex], Halt notify, force set BT to ignore Wlan active!!\n");
4666 	BTC_TRACE(trace_buf);
4667 	halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
4668 	ex_halbtc8812a2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
4669 
4670 	/* 0x522=0xff, pause tx */
4671 	btcoexist->btc_write_1byte(btcoexist, 0x522, 0xff);
4672 	/* 0x40[7:6]=2'b01, modify BT mode. */
4673 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0xc0, 0x2);
4674 	btcoexist->stop_coex_dm = true;
4675 }
4676 
ex_halbtc8812a2ant_periodical(IN struct btc_coexist * btcoexist)4677 void ex_halbtc8812a2ant_periodical(IN struct btc_coexist *btcoexist)
4678 {
4679 #if (BT_AUTO_REPORT_ONLY_8812A_2ANT == 0)
4680 	halbtc8812a2ant_query_bt_info(btcoexist);
4681 	halbtc8812a2ant_monitor_bt_ctr(btcoexist);
4682 	halbtc8812a2ant_monitor_bt_enable_disable(btcoexist);
4683 #else
4684 	if (halbtc8812a2ant_is_wifi_status_changed(btcoexist) ||
4685 	    coex_dm->auto_tdma_adjust ||
4686 	    coex_dm->auto_tdma_adjust_low_rssi)
4687 		halbtc8812a2ant_run_coexist_mechanism(btcoexist);
4688 #endif
4689 }
4690 
ex_halbtc8812a2ant_dbg_control(IN struct btc_coexist * btcoexist,IN u8 op_code,IN u8 op_len,IN u8 * pdata)4691 void ex_halbtc8812a2ant_dbg_control(IN struct btc_coexist *btcoexist,
4692 				    IN u8 op_code, IN u8 op_len, IN u8 *pdata)
4693 {
4694 	switch (op_code) {
4695 	case BTC_DBG_SET_COEX_DEC_BT_PWR:
4696 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4697 			    "[BTCoex], Set Dec BT power\n");
4698 		BTC_TRACE(trace_buf);
4699 		{
4700 			u8	data_len = 4;
4701 			u8	buf[6] = {0};
4702 			u8	dec_bt_pwr = 0, pwr_level = 0;
4703 			if (op_len == 2) {
4704 				dec_bt_pwr = pdata[0];
4705 				pwr_level = pdata[1];
4706 
4707 				buf[0] = data_len;
4708 				buf[1] = 0x3;		/* OP_Code */
4709 				buf[2] = 0x2;		/* OP_Code_Length */
4710 
4711 				buf[3] = dec_bt_pwr;	/* OP_Code_Content */
4712 				buf[4] = pwr_level;
4713 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4714 					"[BTCoex], Set Dec BT power=%d, pwr_level=%d\n",
4715 					    dec_bt_pwr, pwr_level);
4716 				BTC_TRACE(trace_buf);
4717 				btcoexist->btc_set(btcoexist,
4718 						   BTC_SET_ACT_CTRL_BT_COEX,
4719 						   (void *)&buf[0]);
4720 			}
4721 		}
4722 		break;
4723 
4724 	case BTC_DBG_SET_COEX_BT_AFH_MAP:
4725 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4726 			    "[BTCoex], Set BT AFH Map\n");
4727 		BTC_TRACE(trace_buf);
4728 		{
4729 			u8	data_len = 5;
4730 			u8	buf[6] = {0};
4731 			if (op_len == 3) {
4732 				buf[0] = data_len;
4733 				buf[1] = 0x5;				/* OP_Code */
4734 				buf[2] = 0x3;				/* OP_Code_Length */
4735 
4736 				buf[3] = pdata[0];			/* OP_Code_Content */
4737 				buf[4] = pdata[1];
4738 				buf[5] = pdata[2];
4739 
4740 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4741 					"[BTCoex], Set BT AFH Map = %02x %02x %02x\n",
4742 					    pdata[0], pdata[1], pdata[2]);
4743 				BTC_TRACE(trace_buf);
4744 				btcoexist->btc_set(btcoexist,
4745 						   BTC_SET_ACT_CTRL_BT_COEX,
4746 						   (void *)&buf[0]);
4747 			}
4748 		}
4749 		break;
4750 
4751 	case BTC_DBG_SET_COEX_BT_IGNORE_WLAN_ACT:
4752 		BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4753 			    "[BTCoex], Set BT Ignore Wlan Active\n");
4754 		BTC_TRACE(trace_buf);
4755 		{
4756 			u8	data_len = 3;
4757 			u8	buf[6] = {0};
4758 			if (op_len == 1) {
4759 				buf[0] = data_len;
4760 				buf[1] = 0x1;			/* OP_Code */
4761 				buf[2] = 0x1;			/* OP_Code_Length */
4762 
4763 				buf[3] = pdata[0];		/* OP_Code_Content */
4764 				BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4765 					"[BTCoex], Set BT Ignore Wlan Active = 0x%x\n",
4766 					    pdata[0]);
4767 				BTC_TRACE(trace_buf);
4768 
4769 				btcoexist->btc_set(btcoexist,
4770 						   BTC_SET_ACT_CTRL_BT_COEX,
4771 						   (void *)&buf[0]);
4772 			}
4773 		}
4774 		break;
4775 
4776 	default:
4777 		break;
4778 	}
4779 }
4780 
4781 #endif
4782 
4783 #endif	/* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */