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