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