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 	u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
1452 	bool wifi_connected = false;
1453 	bool low_pwr_disable = true;
1454 	bool scan = false, link = false, roam = false;
1455 
1456 	wifi_rssi_state =
1457 		btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
1458 	wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
1459 				BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
1460 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
1461 		2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
1462 
1463 	btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1464 			   &low_pwr_disable);
1465 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1466 			   &wifi_connected);
1467 
1468 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1469 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1470 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1471 
1472 	btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1473 
1474 	if (scan || link || roam) {
1475 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1476 			"[BTCoex], Wifi link process + BT Inq/Page!!\n");
1477 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 15);
1478 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
1479 	} else if (wifi_connected) {
1480 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1481 			"[BTCoex], Wifi connected + BT Inq/Page!!\n");
1482 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 15);
1483 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
1484 	} else {
1485 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1486 			"[BTCoex], Wifi no-link + BT Inq/Page!!\n");
1487 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1488 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1489 	}
1490 
1491 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
1492 	btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1493 
1494 	btc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1495 	btc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1496 }
1497 
1498 static void btc8821a2ant_action_wifi_link_process(struct btc_coexist *btcoexist)
1499 {
1500 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1501 	u8 u8tmpa, u8tmpb;
1502 
1503 	btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 15);
1504 	btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
1505 
1506 	btc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
1507 	btc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
1508 
1509 	u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
1510 	u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e);
1511 
1512 	rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1513 		"[BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u8tmpa, u8tmpb);
1514 }
1515 
1516 static bool btc8821a2ant_action_wifi_idle_process(struct btc_coexist *btcoexist)
1517 {
1518 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1519 	u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
1520 	u8 ap_num = 0;
1521 
1522 	wifi_rssi_state =
1523 		btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
1524 	wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
1525 			BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 20, 0);
1526 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
1527 			2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
1528 
1529 	btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
1530 
1531 	/* define the office environment */
1532 	if (BTC_RSSI_HIGH(wifi_rssi_state1) && (coex_sta->hid_exist) &&
1533 	    (coex_sta->a2dp_exist)) {
1534 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1535 			"[BTCoex], Wifi  idle process for BT HID+A2DP exist!!\n");
1536 
1537 		btc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6);
1538 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1539 
1540 		/* sw all off */
1541 		btc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
1542 					   false);
1543 		btc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
1544 					   0x18);
1545 
1546 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1547 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1548 					      0x0, 0x0);
1549 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1550 
1551 		return true;
1552 	} else if (coex_sta->pan_exist) {
1553 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1554 			"[BTCoex], Wifi  idle process for BT PAN exist!!\n");
1555 
1556 		btc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6);
1557 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1558 
1559 		/* sw all off */
1560 		btc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
1561 					   false);
1562 		btc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
1563 					   0x18);
1564 
1565 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1566 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1567 					      0x0, 0x0);
1568 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1569 
1570 		return true;
1571 	}
1572 	btc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x18);
1573 	return false;
1574 }
1575 
1576 static bool btc8821a2ant_is_common_action(struct btc_coexist *btcoexist)
1577 {
1578 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1579 	bool common = false, wifi_connected = false, wifi_busy = false;
1580 	bool low_pwr_disable = false;
1581 	bool bt_hs_on = false;
1582 
1583 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
1584 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1585 			   &wifi_connected);
1586 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1587 
1588 	if (!wifi_connected) {
1589 		low_pwr_disable = false;
1590 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1591 				   &low_pwr_disable);
1592 		btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
1593 					0x8);
1594 
1595 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1596 			"[BTCoex], Wifi non-connected idle!!\n");
1597 
1598 		btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
1599 					  0x0);
1600 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1601 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1602 					      0x0, 0x0);
1603 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1604 		btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
1605 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1606 
1607 		btc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
1608 					   false);
1609 		btc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
1610 					   0x18);
1611 
1612 		common = true;
1613 	} else {
1614 		if (BT_8821A_2ANT_BT_STATUS_IDLE ==
1615 		    coex_dm->bt_status) {
1616 			low_pwr_disable = false;
1617 			btcoexist->btc_set(btcoexist,
1618 					   BTC_SET_ACT_DISABLE_LOW_POWER,
1619 					   &low_pwr_disable);
1620 			btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC,
1621 						false, false, 0x8);
1622 
1623 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1624 				"[BTCoex], Wifi connected + BT non connected-idle!!\n");
1625 
1626 			btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
1627 						  0xfffff, 0x0);
1628 			btc8821a2ant_coex_table_with_type(btcoexist,
1629 							  NORMAL_EXEC, 0);
1630 
1631 			btc8821a2ant_power_save_state(
1632 				btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1633 			btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1634 			btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1635 						      0xb);
1636 			btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1637 
1638 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
1639 						   false, false);
1640 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
1641 						   false, 0x18);
1642 
1643 			common = true;
1644 		} else if (BT_8821A_2ANT_BT_STATUS_CON_IDLE ==
1645 			   coex_dm->bt_status) {
1646 			low_pwr_disable = true;
1647 			btcoexist->btc_set(btcoexist,
1648 					   BTC_SET_ACT_DISABLE_LOW_POWER,
1649 					   &low_pwr_disable);
1650 
1651 			if (bt_hs_on)
1652 				return false;
1653 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1654 				"[BTCoex], Wifi connected + BT connected-idle!!\n");
1655 			btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC,
1656 						false, false, 0x8);
1657 
1658 			btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
1659 						  0xfffff, 0x0);
1660 			btc8821a2ant_coex_table_with_type(btcoexist,
1661 							  NORMAL_EXEC, 0);
1662 
1663 			btc8821a2ant_power_save_state(
1664 				btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1665 			btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
1666 			btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
1667 						      0xb);
1668 			btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
1669 
1670 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
1671 						   false, false);
1672 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
1673 						   false, 0x18);
1674 			common = true;
1675 		} else {
1676 			low_pwr_disable = true;
1677 			btcoexist->btc_set(btcoexist,
1678 					   BTC_SET_ACT_DISABLE_LOW_POWER,
1679 					   &low_pwr_disable);
1680 
1681 			if (wifi_busy) {
1682 				rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1683 					"[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1684 				common = false;
1685 			} else {
1686 				rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1687 					"[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1688 				common =
1689 				    btc8821a2ant_action_wifi_idle_process(
1690 					     btcoexist);
1691 			}
1692 		}
1693 	}
1694 	return common;
1695 }
1696 
1697 static void btc8821a2ant_tdma_duration_adjust(struct btc_coexist *btcoexist,
1698 					      bool sco_hid, bool tx_pause,
1699 					      u8 max_interval)
1700 {
1701 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1702 	static long up, dn, m, n, wait_count;
1703 	 /* 0 : no change
1704 	  * +1: increase WiFi duration
1705 	  * -1: decrease WiFi duration
1706 	  */
1707 	int result;
1708 	u8 retry_count = 0;
1709 
1710 	rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1711 		"[BTCoex], TdmaDurationAdjust()\n");
1712 
1713 	if (coex_dm->auto_tdma_adjust) {
1714 		coex_dm->auto_tdma_adjust = false;
1715 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1716 			"[BTCoex], first run TdmaDurationAdjust()!!\n");
1717 		if (sco_hid) {
1718 			if (tx_pause) {
1719 				if (max_interval == 1) {
1720 					btc8821a2ant_ps_tdma(btcoexist,
1721 							NORMAL_EXEC, true, 13);
1722 					coex_dm->ps_tdma_du_adj_type = 13;
1723 				} else if (max_interval == 2) {
1724 					btc8821a2ant_ps_tdma(btcoexist,
1725 							NORMAL_EXEC, true, 14);
1726 					coex_dm->ps_tdma_du_adj_type = 14;
1727 				} else if (max_interval == 3) {
1728 					btc8821a2ant_ps_tdma(btcoexist,
1729 							NORMAL_EXEC, true, 15);
1730 					coex_dm->ps_tdma_du_adj_type = 15;
1731 				} else {
1732 					btc8821a2ant_ps_tdma(btcoexist,
1733 							NORMAL_EXEC, true, 15);
1734 					coex_dm->ps_tdma_du_adj_type = 15;
1735 				}
1736 			} else {
1737 				if (max_interval == 1) {
1738 					btc8821a2ant_ps_tdma(btcoexist,
1739 							NORMAL_EXEC, true, 9);
1740 					coex_dm->ps_tdma_du_adj_type = 9;
1741 				} else if (max_interval == 2) {
1742 					btc8821a2ant_ps_tdma(btcoexist,
1743 							NORMAL_EXEC, true, 10);
1744 					coex_dm->ps_tdma_du_adj_type = 10;
1745 				} else if (max_interval == 3) {
1746 					btc8821a2ant_ps_tdma(btcoexist,
1747 							NORMAL_EXEC, true, 11);
1748 					coex_dm->ps_tdma_du_adj_type = 11;
1749 				} else {
1750 					btc8821a2ant_ps_tdma(btcoexist,
1751 							NORMAL_EXEC, true, 11);
1752 					coex_dm->ps_tdma_du_adj_type = 11;
1753 				}
1754 			}
1755 		} else {
1756 			if (tx_pause) {
1757 				if (max_interval == 1) {
1758 					btc8821a2ant_ps_tdma(btcoexist,
1759 							NORMAL_EXEC, true, 5);
1760 					coex_dm->ps_tdma_du_adj_type = 5;
1761 				} else if (max_interval == 2) {
1762 					btc8821a2ant_ps_tdma(btcoexist,
1763 							NORMAL_EXEC, true, 6);
1764 					coex_dm->ps_tdma_du_adj_type = 6;
1765 				} else if (max_interval == 3) {
1766 					btc8821a2ant_ps_tdma(btcoexist,
1767 							NORMAL_EXEC, true, 7);
1768 					coex_dm->ps_tdma_du_adj_type = 7;
1769 				} else {
1770 					btc8821a2ant_ps_tdma(btcoexist,
1771 							NORMAL_EXEC, true, 7);
1772 					coex_dm->ps_tdma_du_adj_type = 7;
1773 				}
1774 			} else {
1775 				if (max_interval == 1) {
1776 					btc8821a2ant_ps_tdma(btcoexist,
1777 							NORMAL_EXEC, true, 1);
1778 					coex_dm->ps_tdma_du_adj_type = 1;
1779 				} else if (max_interval == 2) {
1780 					btc8821a2ant_ps_tdma(btcoexist,
1781 							NORMAL_EXEC, true, 2);
1782 					coex_dm->ps_tdma_du_adj_type = 2;
1783 				} else if (max_interval == 3) {
1784 					btc8821a2ant_ps_tdma(btcoexist,
1785 							NORMAL_EXEC, true, 3);
1786 					coex_dm->ps_tdma_du_adj_type = 3;
1787 				} else {
1788 					btc8821a2ant_ps_tdma(btcoexist,
1789 							NORMAL_EXEC, true, 3);
1790 					coex_dm->ps_tdma_du_adj_type = 3;
1791 				}
1792 			}
1793 		}
1794 
1795 		up = 0;
1796 		dn = 0;
1797 		m = 1;
1798 		n = 3;
1799 		result = 0;
1800 		wait_count = 0;
1801 	} else {
1802 		/* accquire the BT TRx retry count from BT_Info byte2 */
1803 		retry_count = coex_sta->bt_retry_cnt;
1804 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1805 			"[BTCoex], retry_count = %d\n", retry_count);
1806 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1807 			"[BTCoex], up = %d, dn = %d, m = %d, n = %d, wait_count = %d\n",
1808 			(int)up, (int)dn, (int)m, (int)n, (int)wait_count);
1809 		result = 0;
1810 		wait_count++;
1811 
1812 		if (retry_count == 0) {
1813 			/* no retry in the last 2-second duration */
1814 			up++;
1815 			dn--;
1816 
1817 			if (dn <= 0)
1818 				dn = 0;
1819 
1820 			if (up >= n) {
1821 				/* if (retry count == 0) for 2*n seconds,
1822 				 * make WiFi duration wider
1823 				 */
1824 				wait_count = 0;
1825 				n = 3;
1826 				up = 0;
1827 				dn = 0;
1828 				result = 1;
1829 				rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1830 					"[BTCoex], Increase wifi duration!!\n");
1831 			}
1832 		} else if (retry_count <= 3) {
1833 			/* <=3 retry in the last 2-second duration */
1834 			up--;
1835 			dn++;
1836 
1837 			if (up <= 0)
1838 				up = 0;
1839 
1840 			if (dn == 2) {
1841 				/* if retry count < 3 for 2*2 seconds,
1842 				 * shrink wifi duration
1843 				 */
1844 				if (wait_count <= 2)
1845 					m++; /* avoid bounce in two levels */
1846 				else
1847 					m = 1;
1848 				/* m max value is 20, max time is 120 second,
1849 				 * recheck if adjust WiFi duration.
1850 				 */
1851 				if (m >= 20)
1852 					m = 20;
1853 
1854 				n = 3 * m;
1855 				up = 0;
1856 				dn = 0;
1857 				wait_count = 0;
1858 				result = -1;
1859 				rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1860 					"[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
1861 			}
1862 		} else {
1863 			/* retry count > 3, if retry count > 3 happens once,
1864 			 * shrink WiFi duration
1865 			 */
1866 			if (wait_count == 1)
1867 				m++; /* avoid bounce in two levels */
1868 			else
1869 				m = 1;
1870 			/* m max value is 20, max time is 120 second,
1871 			 * recheck if adjust WiFi duration.
1872 			 */
1873 			if (m >= 20)
1874 				m = 20;
1875 
1876 			n = 3 * m;
1877 			up = 0;
1878 			dn = 0;
1879 			wait_count = 0;
1880 			result = -1;
1881 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1882 				"[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
1883 		}
1884 
1885 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1886 			"[BTCoex], max Interval = %d\n", max_interval);
1887 
1888 		if (max_interval == 1) {
1889 			if (tx_pause) {
1890 				if (coex_dm->cur_ps_tdma == 71) {
1891 					btc8821a2ant_ps_tdma(btcoexist,
1892 							NORMAL_EXEC, true, 5);
1893 					coex_dm->ps_tdma_du_adj_type = 5;
1894 				} else if (coex_dm->cur_ps_tdma == 1) {
1895 					btc8821a2ant_ps_tdma(btcoexist,
1896 							NORMAL_EXEC, true, 5);
1897 					coex_dm->ps_tdma_du_adj_type = 5;
1898 				} else if (coex_dm->cur_ps_tdma == 2) {
1899 					btc8821a2ant_ps_tdma(btcoexist,
1900 							NORMAL_EXEC, true, 6);
1901 					coex_dm->ps_tdma_du_adj_type = 6;
1902 				} else if (coex_dm->cur_ps_tdma == 3) {
1903 					btc8821a2ant_ps_tdma(btcoexist,
1904 							NORMAL_EXEC, true, 7);
1905 					coex_dm->ps_tdma_du_adj_type = 7;
1906 				} else if (coex_dm->cur_ps_tdma == 4) {
1907 					btc8821a2ant_ps_tdma(btcoexist,
1908 							NORMAL_EXEC, true, 8);
1909 					coex_dm->ps_tdma_du_adj_type = 8;
1910 				}
1911 				if (coex_dm->cur_ps_tdma == 9) {
1912 					btc8821a2ant_ps_tdma(btcoexist,
1913 							NORMAL_EXEC, true, 13);
1914 					coex_dm->ps_tdma_du_adj_type = 13;
1915 				} else if (coex_dm->cur_ps_tdma == 10) {
1916 					btc8821a2ant_ps_tdma(btcoexist,
1917 							NORMAL_EXEC, true, 14);
1918 					coex_dm->ps_tdma_du_adj_type = 14;
1919 				} else if (coex_dm->cur_ps_tdma == 11) {
1920 					btc8821a2ant_ps_tdma(btcoexist,
1921 							NORMAL_EXEC, true, 15);
1922 					coex_dm->ps_tdma_du_adj_type = 15;
1923 				} else if (coex_dm->cur_ps_tdma == 12) {
1924 					btc8821a2ant_ps_tdma(btcoexist,
1925 							NORMAL_EXEC, true, 16);
1926 					coex_dm->ps_tdma_du_adj_type = 16;
1927 				}
1928 
1929 				if (result == -1) {
1930 					if (coex_dm->cur_ps_tdma == 5) {
1931 						btc8821a2ant_ps_tdma(
1932 							btcoexist, NORMAL_EXEC,
1933 							true, 6);
1934 						coex_dm->ps_tdma_du_adj_type =
1935 							6;
1936 					} else if (coex_dm->cur_ps_tdma == 6) {
1937 						btc8821a2ant_ps_tdma(
1938 							btcoexist, NORMAL_EXEC,
1939 							true, 7);
1940 						coex_dm->ps_tdma_du_adj_type =
1941 							7;
1942 					} else if (coex_dm->cur_ps_tdma == 7) {
1943 						btc8821a2ant_ps_tdma(
1944 							btcoexist, NORMAL_EXEC,
1945 							true, 8);
1946 						coex_dm->ps_tdma_du_adj_type =
1947 							8;
1948 					} else if (coex_dm->cur_ps_tdma == 13) {
1949 						btc8821a2ant_ps_tdma(
1950 							btcoexist, NORMAL_EXEC,
1951 							true, 14);
1952 						coex_dm->ps_tdma_du_adj_type =
1953 							14;
1954 					} else if (coex_dm->cur_ps_tdma == 14) {
1955 						btc8821a2ant_ps_tdma(
1956 							btcoexist, NORMAL_EXEC,
1957 							true, 15);
1958 						coex_dm->ps_tdma_du_adj_type =
1959 							15;
1960 					} else if (coex_dm->cur_ps_tdma == 15) {
1961 						btc8821a2ant_ps_tdma(
1962 							btcoexist, NORMAL_EXEC,
1963 							true, 16);
1964 						coex_dm->ps_tdma_du_adj_type =
1965 							16;
1966 					}
1967 				} else if (result == 1) {
1968 					if (coex_dm->cur_ps_tdma == 8) {
1969 						btc8821a2ant_ps_tdma(
1970 							btcoexist, NORMAL_EXEC,
1971 							true, 7);
1972 						coex_dm->ps_tdma_du_adj_type =
1973 							7;
1974 					} else if (coex_dm->cur_ps_tdma == 7) {
1975 						btc8821a2ant_ps_tdma(
1976 							btcoexist, NORMAL_EXEC,
1977 							true, 6);
1978 						coex_dm->ps_tdma_du_adj_type =
1979 							6;
1980 					} else if (coex_dm->cur_ps_tdma == 6) {
1981 						btc8821a2ant_ps_tdma(
1982 							btcoexist, NORMAL_EXEC,
1983 							true, 5);
1984 						coex_dm->ps_tdma_du_adj_type =
1985 							5;
1986 					} else if (coex_dm->cur_ps_tdma == 16) {
1987 						btc8821a2ant_ps_tdma(
1988 							btcoexist, NORMAL_EXEC,
1989 							true, 15);
1990 						coex_dm->ps_tdma_du_adj_type =
1991 							15;
1992 					} else if (coex_dm->cur_ps_tdma == 15) {
1993 						btc8821a2ant_ps_tdma(
1994 							btcoexist, NORMAL_EXEC,
1995 							true, 14);
1996 						coex_dm->ps_tdma_du_adj_type =
1997 							14;
1998 					} else if (coex_dm->cur_ps_tdma == 14) {
1999 						btc8821a2ant_ps_tdma(
2000 							btcoexist, NORMAL_EXEC,
2001 							true, 13);
2002 						coex_dm->ps_tdma_du_adj_type =
2003 							13;
2004 					}
2005 				}
2006 			} else {
2007 				if (coex_dm->cur_ps_tdma == 5) {
2008 					btc8821a2ant_ps_tdma(btcoexist,
2009 							NORMAL_EXEC, true, 71);
2010 					coex_dm->ps_tdma_du_adj_type = 71;
2011 				} else if (coex_dm->cur_ps_tdma == 6) {
2012 					btc8821a2ant_ps_tdma(btcoexist,
2013 							NORMAL_EXEC, true, 2);
2014 					coex_dm->ps_tdma_du_adj_type = 2;
2015 				} else if (coex_dm->cur_ps_tdma == 7) {
2016 					btc8821a2ant_ps_tdma(btcoexist,
2017 							NORMAL_EXEC, true, 3);
2018 					coex_dm->ps_tdma_du_adj_type = 3;
2019 				} else if (coex_dm->cur_ps_tdma == 8) {
2020 					btc8821a2ant_ps_tdma(btcoexist,
2021 							NORMAL_EXEC, true, 4);
2022 					coex_dm->ps_tdma_du_adj_type = 4;
2023 				}
2024 				if (coex_dm->cur_ps_tdma == 13) {
2025 					btc8821a2ant_ps_tdma(btcoexist,
2026 							NORMAL_EXEC, true, 9);
2027 					coex_dm->ps_tdma_du_adj_type = 9;
2028 				} else if (coex_dm->cur_ps_tdma == 14) {
2029 					btc8821a2ant_ps_tdma(btcoexist,
2030 							NORMAL_EXEC, true, 10);
2031 					coex_dm->ps_tdma_du_adj_type = 10;
2032 				} else if (coex_dm->cur_ps_tdma == 15) {
2033 					btc8821a2ant_ps_tdma(btcoexist,
2034 							NORMAL_EXEC, true, 11);
2035 					coex_dm->ps_tdma_du_adj_type = 11;
2036 				} else if (coex_dm->cur_ps_tdma == 16) {
2037 					btc8821a2ant_ps_tdma(btcoexist,
2038 							NORMAL_EXEC, true, 12);
2039 					coex_dm->ps_tdma_du_adj_type = 12;
2040 				}
2041 
2042 				if (result == -1) {
2043 					if (coex_dm->cur_ps_tdma == 71) {
2044 						btc8821a2ant_ps_tdma(
2045 							btcoexist, NORMAL_EXEC,
2046 							true, 1);
2047 						coex_dm->ps_tdma_du_adj_type =
2048 							1;
2049 					} else if (coex_dm->cur_ps_tdma == 1) {
2050 						btc8821a2ant_ps_tdma(
2051 							btcoexist, NORMAL_EXEC,
2052 							true, 2);
2053 						coex_dm->ps_tdma_du_adj_type =
2054 							2;
2055 					} else if (coex_dm->cur_ps_tdma == 2) {
2056 						btc8821a2ant_ps_tdma(
2057 							btcoexist, NORMAL_EXEC,
2058 							true, 3);
2059 						coex_dm->ps_tdma_du_adj_type =
2060 							3;
2061 					} else if (coex_dm->cur_ps_tdma == 3) {
2062 						btc8821a2ant_ps_tdma(
2063 							btcoexist, NORMAL_EXEC,
2064 							true, 4);
2065 						coex_dm->ps_tdma_du_adj_type =
2066 							4;
2067 					} else if (coex_dm->cur_ps_tdma == 9) {
2068 						btc8821a2ant_ps_tdma(
2069 							btcoexist, NORMAL_EXEC,
2070 							true, 10);
2071 						coex_dm->ps_tdma_du_adj_type =
2072 							10;
2073 					} else if (coex_dm->cur_ps_tdma == 10) {
2074 						btc8821a2ant_ps_tdma(
2075 							btcoexist, NORMAL_EXEC,
2076 							true, 11);
2077 						coex_dm->ps_tdma_du_adj_type =
2078 							11;
2079 					} else if (coex_dm->cur_ps_tdma == 11) {
2080 						btc8821a2ant_ps_tdma(
2081 							btcoexist, NORMAL_EXEC,
2082 							true, 12);
2083 						coex_dm->ps_tdma_du_adj_type =
2084 							12;
2085 					}
2086 				} else if (result == 1) {
2087 					if (coex_dm->cur_ps_tdma == 4) {
2088 						btc8821a2ant_ps_tdma(
2089 							btcoexist, NORMAL_EXEC,
2090 							true, 3);
2091 						coex_dm->ps_tdma_du_adj_type =
2092 							3;
2093 					} else if (coex_dm->cur_ps_tdma == 3) {
2094 						btc8821a2ant_ps_tdma(
2095 							btcoexist, NORMAL_EXEC,
2096 							true, 2);
2097 						coex_dm->ps_tdma_du_adj_type =
2098 							2;
2099 					} else if (coex_dm->cur_ps_tdma == 2) {
2100 						btc8821a2ant_ps_tdma(
2101 							btcoexist, NORMAL_EXEC,
2102 							true, 1);
2103 						coex_dm->ps_tdma_du_adj_type =
2104 							1;
2105 					} else if (coex_dm->cur_ps_tdma == 1) {
2106 						btc8821a2ant_ps_tdma(
2107 							btcoexist, NORMAL_EXEC,
2108 							true, 71);
2109 						coex_dm->ps_tdma_du_adj_type =
2110 							71;
2111 					} else if (coex_dm->cur_ps_tdma == 12) {
2112 						btc8821a2ant_ps_tdma(
2113 							btcoexist, NORMAL_EXEC,
2114 							true, 11);
2115 						coex_dm->ps_tdma_du_adj_type =
2116 							11;
2117 					} else if (coex_dm->cur_ps_tdma == 11) {
2118 						btc8821a2ant_ps_tdma(
2119 							btcoexist, NORMAL_EXEC,
2120 							true, 10);
2121 						coex_dm->ps_tdma_du_adj_type =
2122 							10;
2123 					} else if (coex_dm->cur_ps_tdma == 10) {
2124 						btc8821a2ant_ps_tdma(
2125 							btcoexist, NORMAL_EXEC,
2126 							true, 9);
2127 						coex_dm->ps_tdma_du_adj_type =
2128 							9;
2129 					}
2130 				}
2131 			}
2132 		} else if (max_interval == 2) {
2133 			if (tx_pause) {
2134 				if (coex_dm->cur_ps_tdma == 1) {
2135 					btc8821a2ant_ps_tdma(btcoexist,
2136 							NORMAL_EXEC, true, 6);
2137 					coex_dm->ps_tdma_du_adj_type = 6;
2138 				} else if (coex_dm->cur_ps_tdma == 2) {
2139 					btc8821a2ant_ps_tdma(btcoexist,
2140 							NORMAL_EXEC, true, 6);
2141 					coex_dm->ps_tdma_du_adj_type = 6;
2142 				} else if (coex_dm->cur_ps_tdma == 3) {
2143 					btc8821a2ant_ps_tdma(btcoexist,
2144 							NORMAL_EXEC, true, 7);
2145 					coex_dm->ps_tdma_du_adj_type = 7;
2146 				} else if (coex_dm->cur_ps_tdma == 4) {
2147 					btc8821a2ant_ps_tdma(btcoexist,
2148 							NORMAL_EXEC, true, 8);
2149 					coex_dm->ps_tdma_du_adj_type = 8;
2150 				}
2151 				if (coex_dm->cur_ps_tdma == 9) {
2152 					btc8821a2ant_ps_tdma(btcoexist,
2153 							NORMAL_EXEC, true, 14);
2154 					coex_dm->ps_tdma_du_adj_type = 14;
2155 				} else if (coex_dm->cur_ps_tdma == 10) {
2156 					btc8821a2ant_ps_tdma(btcoexist,
2157 							NORMAL_EXEC, true, 14);
2158 					coex_dm->ps_tdma_du_adj_type = 14;
2159 				} else if (coex_dm->cur_ps_tdma == 11) {
2160 					btc8821a2ant_ps_tdma(btcoexist,
2161 							NORMAL_EXEC, true, 15);
2162 					coex_dm->ps_tdma_du_adj_type = 15;
2163 				} else if (coex_dm->cur_ps_tdma == 12) {
2164 					btc8821a2ant_ps_tdma(btcoexist,
2165 							NORMAL_EXEC, true, 16);
2166 					coex_dm->ps_tdma_du_adj_type = 16;
2167 				}
2168 				if (result == -1) {
2169 					if (coex_dm->cur_ps_tdma == 5) {
2170 						btc8821a2ant_ps_tdma(
2171 							btcoexist, NORMAL_EXEC,
2172 							true, 6);
2173 						coex_dm->ps_tdma_du_adj_type =
2174 							6;
2175 					} else if (coex_dm->cur_ps_tdma == 6) {
2176 						btc8821a2ant_ps_tdma(
2177 							btcoexist, NORMAL_EXEC,
2178 							true, 7);
2179 						coex_dm->ps_tdma_du_adj_type =
2180 							7;
2181 					} else if (coex_dm->cur_ps_tdma == 7) {
2182 						btc8821a2ant_ps_tdma(
2183 							btcoexist, NORMAL_EXEC,
2184 							true, 8);
2185 						coex_dm->ps_tdma_du_adj_type =
2186 							8;
2187 					} else if (coex_dm->cur_ps_tdma == 13) {
2188 						btc8821a2ant_ps_tdma(
2189 							btcoexist, NORMAL_EXEC,
2190 							true, 14);
2191 						coex_dm->ps_tdma_du_adj_type =
2192 							14;
2193 					} else if (coex_dm->cur_ps_tdma == 14) {
2194 						btc8821a2ant_ps_tdma(
2195 							btcoexist, NORMAL_EXEC,
2196 							true, 15);
2197 						coex_dm->ps_tdma_du_adj_type =
2198 							15;
2199 					} else if (coex_dm->cur_ps_tdma == 15) {
2200 						btc8821a2ant_ps_tdma(
2201 							btcoexist, NORMAL_EXEC,
2202 							true, 16);
2203 						coex_dm->ps_tdma_du_adj_type =
2204 							16;
2205 					}
2206 				} else if (result == 1) {
2207 					if (coex_dm->cur_ps_tdma == 8) {
2208 						btc8821a2ant_ps_tdma(
2209 							btcoexist, NORMAL_EXEC,
2210 							true, 7);
2211 						coex_dm->ps_tdma_du_adj_type =
2212 							7;
2213 					} else if (coex_dm->cur_ps_tdma == 7) {
2214 						btc8821a2ant_ps_tdma(
2215 							btcoexist, NORMAL_EXEC,
2216 							true, 6);
2217 						coex_dm->ps_tdma_du_adj_type =
2218 							6;
2219 					} else if (coex_dm->cur_ps_tdma == 6) {
2220 						btc8821a2ant_ps_tdma(
2221 							btcoexist, NORMAL_EXEC,
2222 							true, 6);
2223 						coex_dm->ps_tdma_du_adj_type =
2224 							6;
2225 					} else if (coex_dm->cur_ps_tdma == 16) {
2226 						btc8821a2ant_ps_tdma(
2227 							btcoexist, NORMAL_EXEC,
2228 							true, 15);
2229 						coex_dm->ps_tdma_du_adj_type =
2230 							15;
2231 					} else if (coex_dm->cur_ps_tdma == 15) {
2232 						btc8821a2ant_ps_tdma(
2233 							btcoexist, NORMAL_EXEC,
2234 							true, 14);
2235 						coex_dm->ps_tdma_du_adj_type =
2236 							14;
2237 					} else if (coex_dm->cur_ps_tdma == 14) {
2238 						btc8821a2ant_ps_tdma(
2239 							btcoexist, NORMAL_EXEC,
2240 							true, 14);
2241 						coex_dm->ps_tdma_du_adj_type =
2242 							14;
2243 					}
2244 				}
2245 			} else {
2246 				if (coex_dm->cur_ps_tdma == 5) {
2247 					btc8821a2ant_ps_tdma(btcoexist,
2248 							NORMAL_EXEC, true, 2);
2249 					coex_dm->ps_tdma_du_adj_type = 2;
2250 				} else if (coex_dm->cur_ps_tdma == 6) {
2251 					btc8821a2ant_ps_tdma(btcoexist,
2252 							NORMAL_EXEC, true, 2);
2253 					coex_dm->ps_tdma_du_adj_type = 2;
2254 				} else if (coex_dm->cur_ps_tdma == 7) {
2255 					btc8821a2ant_ps_tdma(btcoexist,
2256 							NORMAL_EXEC, true, 3);
2257 					coex_dm->ps_tdma_du_adj_type = 3;
2258 				} else if (coex_dm->cur_ps_tdma == 8) {
2259 					btc8821a2ant_ps_tdma(btcoexist,
2260 							NORMAL_EXEC, true, 4);
2261 					coex_dm->ps_tdma_du_adj_type = 4;
2262 				}
2263 				if (coex_dm->cur_ps_tdma == 13) {
2264 					btc8821a2ant_ps_tdma(btcoexist,
2265 							NORMAL_EXEC, true, 10);
2266 					coex_dm->ps_tdma_du_adj_type = 10;
2267 				} else if (coex_dm->cur_ps_tdma == 14) {
2268 					btc8821a2ant_ps_tdma(btcoexist,
2269 							NORMAL_EXEC, true, 10);
2270 					coex_dm->ps_tdma_du_adj_type = 10;
2271 				} else if (coex_dm->cur_ps_tdma == 15) {
2272 					btc8821a2ant_ps_tdma(btcoexist,
2273 							NORMAL_EXEC, true, 11);
2274 					coex_dm->ps_tdma_du_adj_type = 11;
2275 				} else if (coex_dm->cur_ps_tdma == 16) {
2276 					btc8821a2ant_ps_tdma(btcoexist,
2277 							NORMAL_EXEC, true, 12);
2278 					coex_dm->ps_tdma_du_adj_type = 12;
2279 				}
2280 				if (result == -1) {
2281 					if (coex_dm->cur_ps_tdma == 1) {
2282 						btc8821a2ant_ps_tdma(
2283 							btcoexist, NORMAL_EXEC,
2284 							true, 2);
2285 						coex_dm->ps_tdma_du_adj_type =
2286 							2;
2287 					} else if (coex_dm->cur_ps_tdma == 2) {
2288 						btc8821a2ant_ps_tdma(
2289 							btcoexist, NORMAL_EXEC,
2290 							true, 3);
2291 						coex_dm->ps_tdma_du_adj_type =
2292 							3;
2293 					} else if (coex_dm->cur_ps_tdma == 3) {
2294 						btc8821a2ant_ps_tdma(
2295 							btcoexist, NORMAL_EXEC,
2296 							true, 4);
2297 						coex_dm->ps_tdma_du_adj_type =
2298 							4;
2299 					} else if (coex_dm->cur_ps_tdma == 9) {
2300 						btc8821a2ant_ps_tdma(
2301 							btcoexist, NORMAL_EXEC,
2302 							true, 10);
2303 						coex_dm->ps_tdma_du_adj_type =
2304 							10;
2305 					} else if (coex_dm->cur_ps_tdma == 10) {
2306 						btc8821a2ant_ps_tdma(
2307 							btcoexist, NORMAL_EXEC,
2308 							true, 11);
2309 						coex_dm->ps_tdma_du_adj_type =
2310 							11;
2311 					} else if (coex_dm->cur_ps_tdma == 11) {
2312 						btc8821a2ant_ps_tdma(
2313 							btcoexist, NORMAL_EXEC,
2314 							true, 12);
2315 						coex_dm->ps_tdma_du_adj_type =
2316 							12;
2317 					}
2318 				} else if (result == 1) {
2319 					if (coex_dm->cur_ps_tdma == 4) {
2320 						btc8821a2ant_ps_tdma(
2321 							btcoexist, NORMAL_EXEC,
2322 							true, 3);
2323 						coex_dm->ps_tdma_du_adj_type =
2324 							3;
2325 					} else if (coex_dm->cur_ps_tdma == 3) {
2326 						btc8821a2ant_ps_tdma(
2327 							btcoexist, NORMAL_EXEC,
2328 							true, 2);
2329 						coex_dm->ps_tdma_du_adj_type =
2330 							2;
2331 					} else if (coex_dm->cur_ps_tdma == 2) {
2332 						btc8821a2ant_ps_tdma(
2333 							btcoexist, NORMAL_EXEC,
2334 							true, 2);
2335 						coex_dm->ps_tdma_du_adj_type =
2336 							2;
2337 					} else if (coex_dm->cur_ps_tdma == 12) {
2338 						btc8821a2ant_ps_tdma(
2339 							btcoexist, NORMAL_EXEC,
2340 							true, 11);
2341 						coex_dm->ps_tdma_du_adj_type =
2342 							11;
2343 					} else if (coex_dm->cur_ps_tdma == 11) {
2344 						btc8821a2ant_ps_tdma(
2345 							btcoexist, NORMAL_EXEC,
2346 							true, 10);
2347 						coex_dm->ps_tdma_du_adj_type =
2348 							10;
2349 					} else if (coex_dm->cur_ps_tdma == 10) {
2350 						btc8821a2ant_ps_tdma(
2351 							btcoexist, NORMAL_EXEC,
2352 							true, 10);
2353 						coex_dm->ps_tdma_du_adj_type =
2354 							10;
2355 					}
2356 				}
2357 			}
2358 		} else if (max_interval == 3) {
2359 			if (tx_pause) {
2360 				if (coex_dm->cur_ps_tdma == 1) {
2361 					btc8821a2ant_ps_tdma(btcoexist,
2362 							NORMAL_EXEC, true, 7);
2363 					coex_dm->ps_tdma_du_adj_type = 7;
2364 				} else if (coex_dm->cur_ps_tdma == 2) {
2365 					btc8821a2ant_ps_tdma(btcoexist,
2366 							NORMAL_EXEC, true, 7);
2367 					coex_dm->ps_tdma_du_adj_type = 7;
2368 				} else if (coex_dm->cur_ps_tdma == 3) {
2369 					btc8821a2ant_ps_tdma(btcoexist,
2370 							NORMAL_EXEC, true, 7);
2371 					coex_dm->ps_tdma_du_adj_type = 7;
2372 				} else if (coex_dm->cur_ps_tdma == 4) {
2373 					btc8821a2ant_ps_tdma(btcoexist,
2374 							NORMAL_EXEC, true, 8);
2375 					coex_dm->ps_tdma_du_adj_type = 8;
2376 				}
2377 				if (coex_dm->cur_ps_tdma == 9) {
2378 					btc8821a2ant_ps_tdma(btcoexist,
2379 							NORMAL_EXEC, true, 15);
2380 					coex_dm->ps_tdma_du_adj_type = 15;
2381 				} else if (coex_dm->cur_ps_tdma == 10) {
2382 					btc8821a2ant_ps_tdma(btcoexist,
2383 							NORMAL_EXEC, true, 15);
2384 					coex_dm->ps_tdma_du_adj_type = 15;
2385 				} else if (coex_dm->cur_ps_tdma == 11) {
2386 					btc8821a2ant_ps_tdma(btcoexist,
2387 							NORMAL_EXEC, true, 15);
2388 					coex_dm->ps_tdma_du_adj_type = 15;
2389 				} else if (coex_dm->cur_ps_tdma == 12) {
2390 					btc8821a2ant_ps_tdma(btcoexist,
2391 							NORMAL_EXEC, true, 16);
2392 					coex_dm->ps_tdma_du_adj_type = 16;
2393 				}
2394 				if (result == -1) {
2395 					if (coex_dm->cur_ps_tdma == 5) {
2396 						btc8821a2ant_ps_tdma(
2397 							btcoexist, NORMAL_EXEC,
2398 							true, 7);
2399 						coex_dm->ps_tdma_du_adj_type =
2400 							7;
2401 					} else if (coex_dm->cur_ps_tdma == 6) {
2402 						btc8821a2ant_ps_tdma(
2403 							btcoexist, NORMAL_EXEC,
2404 							true, 7);
2405 						coex_dm->ps_tdma_du_adj_type =
2406 							7;
2407 					} else if (coex_dm->cur_ps_tdma == 7) {
2408 						btc8821a2ant_ps_tdma(
2409 							btcoexist, NORMAL_EXEC,
2410 							true, 8);
2411 						coex_dm->ps_tdma_du_adj_type =
2412 							8;
2413 					} else if (coex_dm->cur_ps_tdma == 13) {
2414 						btc8821a2ant_ps_tdma(
2415 							btcoexist, NORMAL_EXEC,
2416 							true, 15);
2417 						coex_dm->ps_tdma_du_adj_type =
2418 							15;
2419 					} else if (coex_dm->cur_ps_tdma == 14) {
2420 						btc8821a2ant_ps_tdma(
2421 							btcoexist, NORMAL_EXEC,
2422 							true, 15);
2423 						coex_dm->ps_tdma_du_adj_type =
2424 							15;
2425 					} else if (coex_dm->cur_ps_tdma == 15) {
2426 						btc8821a2ant_ps_tdma(
2427 							btcoexist, NORMAL_EXEC,
2428 							true, 16);
2429 						coex_dm->ps_tdma_du_adj_type =
2430 							16;
2431 					}
2432 				} else if (result == 1) {
2433 					if (coex_dm->cur_ps_tdma == 8) {
2434 						btc8821a2ant_ps_tdma(
2435 							btcoexist, NORMAL_EXEC,
2436 							true, 7);
2437 						coex_dm->ps_tdma_du_adj_type =
2438 							7;
2439 					} else if (coex_dm->cur_ps_tdma == 7) {
2440 						btc8821a2ant_ps_tdma(
2441 							btcoexist, NORMAL_EXEC,
2442 							true, 7);
2443 						coex_dm->ps_tdma_du_adj_type =
2444 							7;
2445 					} else if (coex_dm->cur_ps_tdma == 6) {
2446 						btc8821a2ant_ps_tdma(
2447 							btcoexist, NORMAL_EXEC,
2448 							true, 7);
2449 						coex_dm->ps_tdma_du_adj_type =
2450 							7;
2451 					} else if (coex_dm->cur_ps_tdma == 16) {
2452 						btc8821a2ant_ps_tdma(
2453 							btcoexist, NORMAL_EXEC,
2454 							true, 15);
2455 						coex_dm->ps_tdma_du_adj_type =
2456 							15;
2457 					} else if (coex_dm->cur_ps_tdma == 15) {
2458 						btc8821a2ant_ps_tdma(
2459 							btcoexist, NORMAL_EXEC,
2460 							true, 15);
2461 						coex_dm->ps_tdma_du_adj_type =
2462 							15;
2463 					} else if (coex_dm->cur_ps_tdma == 14) {
2464 						btc8821a2ant_ps_tdma(
2465 							btcoexist, NORMAL_EXEC,
2466 							true, 15);
2467 						coex_dm->ps_tdma_du_adj_type =
2468 							15;
2469 					}
2470 				}
2471 			} else {
2472 				if (coex_dm->cur_ps_tdma == 5) {
2473 					btc8821a2ant_ps_tdma(btcoexist,
2474 							NORMAL_EXEC, true, 3);
2475 					coex_dm->ps_tdma_du_adj_type = 3;
2476 				} else if (coex_dm->cur_ps_tdma == 6) {
2477 					btc8821a2ant_ps_tdma(btcoexist,
2478 							NORMAL_EXEC, true, 3);
2479 					coex_dm->ps_tdma_du_adj_type = 3;
2480 				} else if (coex_dm->cur_ps_tdma == 7) {
2481 					btc8821a2ant_ps_tdma(btcoexist,
2482 							NORMAL_EXEC, true, 3);
2483 					coex_dm->ps_tdma_du_adj_type = 3;
2484 				} else if (coex_dm->cur_ps_tdma == 8) {
2485 					btc8821a2ant_ps_tdma(btcoexist,
2486 							NORMAL_EXEC, true, 4);
2487 					coex_dm->ps_tdma_du_adj_type = 4;
2488 				}
2489 				if (coex_dm->cur_ps_tdma == 13) {
2490 					btc8821a2ant_ps_tdma(btcoexist,
2491 							NORMAL_EXEC, true, 11);
2492 					coex_dm->ps_tdma_du_adj_type = 11;
2493 				} else if (coex_dm->cur_ps_tdma == 14) {
2494 					btc8821a2ant_ps_tdma(btcoexist,
2495 							NORMAL_EXEC, true, 11);
2496 					coex_dm->ps_tdma_du_adj_type = 11;
2497 				} else if (coex_dm->cur_ps_tdma == 15) {
2498 					btc8821a2ant_ps_tdma(btcoexist,
2499 							NORMAL_EXEC, true, 11);
2500 					coex_dm->ps_tdma_du_adj_type = 11;
2501 				} else if (coex_dm->cur_ps_tdma == 16) {
2502 					btc8821a2ant_ps_tdma(btcoexist,
2503 							NORMAL_EXEC, true, 12);
2504 					coex_dm->ps_tdma_du_adj_type = 12;
2505 				}
2506 				if (result == -1) {
2507 					if (coex_dm->cur_ps_tdma == 1) {
2508 						btc8821a2ant_ps_tdma(
2509 							btcoexist, NORMAL_EXEC,
2510 							true, 3);
2511 						coex_dm->ps_tdma_du_adj_type =
2512 							3;
2513 					} else if (coex_dm->cur_ps_tdma == 2) {
2514 						btc8821a2ant_ps_tdma(
2515 							btcoexist, NORMAL_EXEC,
2516 							true, 3);
2517 						coex_dm->ps_tdma_du_adj_type =
2518 							3;
2519 					} else if (coex_dm->cur_ps_tdma == 3) {
2520 						btc8821a2ant_ps_tdma(
2521 							btcoexist, NORMAL_EXEC,
2522 							true, 4);
2523 						coex_dm->ps_tdma_du_adj_type =
2524 							4;
2525 					} else if (coex_dm->cur_ps_tdma == 9) {
2526 						btc8821a2ant_ps_tdma(
2527 							btcoexist, NORMAL_EXEC,
2528 							true, 11);
2529 						coex_dm->ps_tdma_du_adj_type =
2530 							11;
2531 					} else if (coex_dm->cur_ps_tdma == 10) {
2532 						btc8821a2ant_ps_tdma(
2533 							btcoexist, NORMAL_EXEC,
2534 							true, 11);
2535 						coex_dm->ps_tdma_du_adj_type =
2536 							11;
2537 					} else if (coex_dm->cur_ps_tdma == 11) {
2538 						btc8821a2ant_ps_tdma(
2539 							btcoexist, NORMAL_EXEC,
2540 							true, 12);
2541 						coex_dm->ps_tdma_du_adj_type =
2542 							12;
2543 					}
2544 				} else if (result == 1) {
2545 					if (coex_dm->cur_ps_tdma == 4) {
2546 						btc8821a2ant_ps_tdma(
2547 							btcoexist, NORMAL_EXEC,
2548 							true, 3);
2549 						coex_dm->ps_tdma_du_adj_type =
2550 							3;
2551 					} else if (coex_dm->cur_ps_tdma == 3) {
2552 						btc8821a2ant_ps_tdma(
2553 							btcoexist, NORMAL_EXEC,
2554 							true, 3);
2555 						coex_dm->ps_tdma_du_adj_type =
2556 							3;
2557 					} else if (coex_dm->cur_ps_tdma == 2) {
2558 						btc8821a2ant_ps_tdma(
2559 							btcoexist, NORMAL_EXEC,
2560 							true, 3);
2561 						coex_dm->ps_tdma_du_adj_type =
2562 							3;
2563 					} else if (coex_dm->cur_ps_tdma == 12) {
2564 						btc8821a2ant_ps_tdma(
2565 							btcoexist, NORMAL_EXEC,
2566 							true, 11);
2567 						coex_dm->ps_tdma_du_adj_type =
2568 							11;
2569 					} else if (coex_dm->cur_ps_tdma == 11) {
2570 						btc8821a2ant_ps_tdma(
2571 							btcoexist, NORMAL_EXEC,
2572 							true, 11);
2573 						coex_dm->ps_tdma_du_adj_type =
2574 							11;
2575 					} else if (coex_dm->cur_ps_tdma == 10) {
2576 						btc8821a2ant_ps_tdma(
2577 							btcoexist, NORMAL_EXEC,
2578 							true, 11);
2579 						coex_dm->ps_tdma_du_adj_type =
2580 							11;
2581 					}
2582 				}
2583 			}
2584 		}
2585 	}
2586 
2587 	/* if current PsTdma not match with the recorded one
2588 	 * (when scan, dhcp...), then we have to adjust it back to
2589 	 * the previous recorded one.
2590 	 */
2591 	if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) {
2592 		bool scan = false, link = false, roam = false;
2593 
2594 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2595 			"[BTCoex], PsTdma type mismatch!!!, cur_ps_tdma = %d, recordPsTdma = %d\n",
2596 			coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type);
2597 
2598 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2599 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2600 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2601 
2602 		if (!scan && !link && !roam) {
2603 			btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2604 					     coex_dm->ps_tdma_du_adj_type);
2605 		} else {
2606 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2607 				"[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
2608 		}
2609 	}
2610 }
2611 
2612 /* SCO only or SCO+PAN(HS)*/
2613 static void btc8821a2ant_action_sco(struct btc_coexist *btcoexist)
2614 {
2615 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2616 	u8 wifi_rssi_state, bt_rssi_state;
2617 	u32 wifi_bw;
2618 
2619 	wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
2620 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist, 2, 35, 0);
2621 
2622 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2623 
2624 	btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2625 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 4);
2626 
2627 	if (BTC_RSSI_HIGH(bt_rssi_state))
2628 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2629 	else
2630 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2631 
2632 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2633 
2634 	if (wifi_bw == BTC_WIFI_BW_LEGACY) {
2635 		/* for SCO quality at 11b/g mode */
2636 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2637 	} else {
2638 		/* for SCO quality & wifi performance balance at 11n mode */
2639 		if (wifi_bw == BTC_WIFI_BW_HT40) {
2640 			btc8821a2ant_coex_table_with_type(btcoexist,
2641 							  NORMAL_EXEC, 8);
2642 		} else {
2643 			if (bt_link_info->sco_only)
2644 				btc8821a2ant_coex_table_with_type(
2645 					btcoexist, NORMAL_EXEC, 17);
2646 			else
2647 				btc8821a2ant_coex_table_with_type(
2648 					btcoexist, NORMAL_EXEC, 12);
2649 		}
2650 	}
2651 
2652 	btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2653 	/* for voice quality */
2654 	btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2655 
2656 	/* sw mechanism */
2657 	if (wifi_bw == BTC_WIFI_BW_HT40) {
2658 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2659 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2660 			btc8821a2ant_sw_mechanism1(btcoexist, true, true,
2661 						   false, false);
2662 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2663 						   true, 0x18);
2664 		} else {
2665 			btc8821a2ant_sw_mechanism1(btcoexist, true, true,
2666 						   false, false);
2667 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2668 						   true, 0x18);
2669 		}
2670 	} else {
2671 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2672 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2673 			btc8821a2ant_sw_mechanism1(btcoexist, false, true,
2674 						   false, false);
2675 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2676 						   true, 0x18);
2677 		} else {
2678 			btc8821a2ant_sw_mechanism1(btcoexist, false, true,
2679 						   false, false);
2680 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2681 						   true, 0x18);
2682 		}
2683 	}
2684 }
2685 
2686 static void btc8821a2ant_action_hid(struct btc_coexist *btcoexist)
2687 {
2688 	u8 wifi_rssi_state, bt_rssi_state;
2689 	u32 wifi_bw;
2690 
2691 	wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
2692 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
2693 		2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2694 
2695 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2696 
2697 	btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2698 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2699 
2700 	if (BTC_RSSI_HIGH(bt_rssi_state))
2701 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2702 	else
2703 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2704 
2705 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2706 
2707 	if (wifi_bw == BTC_WIFI_BW_LEGACY) {
2708 		/* for HID at 11b/g mode */
2709 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
2710 	} else {
2711 		/* for HID quality & wifi performance balance at 11n mode */
2712 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2713 	}
2714 
2715 	btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2716 	btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 24);
2717 
2718 	if (wifi_bw == BTC_WIFI_BW_HT40) {
2719 		/* sw mechanism */
2720 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2721 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2722 			btc8821a2ant_sw_mechanism1(btcoexist, true, true,
2723 						   false, false);
2724 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2725 						   false, 0x18);
2726 		} else {
2727 			btc8821a2ant_sw_mechanism1(btcoexist, true, true,
2728 						   false, false);
2729 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2730 						   false, 0x18);
2731 		}
2732 	} else {
2733 		/* sw mechanism */
2734 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2735 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2736 			btc8821a2ant_sw_mechanism1(btcoexist, false, true,
2737 						   false, false);
2738 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2739 						   false, 0x18);
2740 		} else {
2741 			btc8821a2ant_sw_mechanism1(btcoexist, false, true,
2742 						   false, false);
2743 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2744 						   false, 0x18);
2745 		}
2746 	}
2747 }
2748 
2749 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
2750 static void btc8821a2ant_action_a2dp(struct btc_coexist *btcoexist)
2751 {
2752 	u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
2753 	u8 ap_num = 0;
2754 	u32 wifi_bw;
2755 
2756 	wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
2757 	wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
2758 				BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
2759 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
2760 		2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2761 
2762 	if ((ap_num >= 10) && BTC_RSSI_HIGH(wifi_rssi_state1) &&
2763 	    BTC_RSSI_HIGH(bt_rssi_state)) {
2764 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2765 					      0x0, 0x0);
2766 
2767 		btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
2768 					  0x0);
2769 		btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
2770 					0x8);
2771 		btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2772 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2773 
2774 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2775 
2776 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2777 					      0x0, 0x0);
2778 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
2779 
2780 		/* sw mechanism */
2781 		btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2782 		if (wifi_bw == BTC_WIFI_BW_HT40) {
2783 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2784 						   false, false);
2785 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2786 						   true, 0x6);
2787 		} else {
2788 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2789 						   false, false);
2790 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2791 						   true, 0x6);
2792 		}
2793 		return;
2794 	}
2795 
2796 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2797 	btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2798 
2799 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2800 
2801 	if (BTC_RSSI_HIGH(bt_rssi_state))
2802 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2803 	else
2804 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2805 
2806 	if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
2807 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
2808 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2809 					      0x0, 0x0);
2810 	} else {
2811 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
2812 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
2813 					      0x4);
2814 	}
2815 
2816 	if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2817 	    (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2818 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
2819 	} else {
2820 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
2821 	}
2822 
2823 	/* sw mechanism */
2824 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2825 	if (wifi_bw == BTC_WIFI_BW_HT40) {
2826 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2827 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2828 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2829 						   false, false);
2830 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2831 						   false, 0x18);
2832 		} else {
2833 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2834 						   false, false);
2835 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2836 						   false, 0x18);
2837 		}
2838 	} else {
2839 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2840 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2841 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2842 						   false, false);
2843 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2844 						   false, 0x18);
2845 		} else {
2846 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2847 						   false, false);
2848 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2849 						   false, 0x18);
2850 		}
2851 	}
2852 }
2853 
2854 static void btc8821a2ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist)
2855 {
2856 	u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
2857 	u32 wifi_bw;
2858 
2859 	wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
2860 	wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
2861 				BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
2862 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
2863 		2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2864 
2865 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2866 
2867 	btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2868 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2869 
2870 	if (BTC_RSSI_HIGH(bt_rssi_state))
2871 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2872 	else
2873 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2874 
2875 	if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
2876 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
2877 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2878 					      0x0, 0x0);
2879 	} else {
2880 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
2881 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
2882 					      0x4);
2883 	}
2884 
2885 	btc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 2);
2886 
2887 	/* sw mechanism */
2888 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2889 	if (wifi_bw == BTC_WIFI_BW_HT40) {
2890 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2891 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2892 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2893 						   false, false);
2894 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2895 						   false, 0x18);
2896 		} else {
2897 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2898 						   false, false);
2899 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2900 						   false, 0x18);
2901 		}
2902 	} else {
2903 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2904 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2905 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2906 						   false, false);
2907 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2908 						   false, 0x18);
2909 		} else {
2910 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2911 						   false, false);
2912 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2913 						   false, 0x18);
2914 		}
2915 	}
2916 }
2917 
2918 static void btc8821a2ant_action_pan_edr(struct btc_coexist *btcoexist)
2919 {
2920 	u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
2921 	u32 wifi_bw;
2922 
2923 	wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
2924 	wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
2925 				BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
2926 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
2927 				2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2928 
2929 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2930 
2931 	btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
2932 
2933 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
2934 
2935 	if (BTC_RSSI_HIGH(bt_rssi_state))
2936 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
2937 	else
2938 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
2939 
2940 	if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
2941 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 10);
2942 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2943 					      0x0, 0x0);
2944 	} else {
2945 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
2946 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
2947 					      0x4);
2948 	}
2949 
2950 	if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
2951 	    (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
2952 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 26);
2953 	else
2954 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 26);
2955 
2956 	/* sw mechanism */
2957 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2958 	if (wifi_bw == BTC_WIFI_BW_HT40) {
2959 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2960 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2961 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2962 						   false, false);
2963 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2964 						   false, 0x18);
2965 		} else {
2966 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
2967 						   false, false);
2968 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2969 						   false, 0x18);
2970 		}
2971 	} else {
2972 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
2973 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
2974 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2975 						   false, false);
2976 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
2977 						   false, 0x18);
2978 		} else {
2979 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
2980 						   false, false);
2981 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
2982 						   false, 0x18);
2983 		}
2984 	}
2985 }
2986 
2987 /* PAN(HS) only */
2988 static void btc8821a2ant_action_pan_hs(struct btc_coexist *btcoexist)
2989 {
2990 	u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
2991 	u32 wifi_bw;
2992 
2993 	wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
2994 	wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
2995 				BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
2996 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
2997 				2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
2998 
2999 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3000 
3001 	btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3002 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3003 
3004 	if (BTC_RSSI_HIGH(bt_rssi_state))
3005 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3006 	else
3007 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3008 
3009 	btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3010 	btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3011 	btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
3012 
3013 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3014 	if (wifi_bw == BTC_WIFI_BW_HT40) {
3015 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3016 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3017 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
3018 						   false, false);
3019 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3020 						   false, 0x18);
3021 		} else {
3022 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
3023 						   false, false);
3024 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3025 						   false, 0x18);
3026 		}
3027 	} else {
3028 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3029 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3030 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
3031 						   false, false);
3032 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3033 						   false, 0x18);
3034 		} else {
3035 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
3036 						   false, false);
3037 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3038 						   false, 0x18);
3039 		}
3040 	}
3041 }
3042 
3043 /* PAN(EDR)+A2DP */
3044 static void btc8821a2ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist)
3045 {
3046 	u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3047 	u32 wifi_bw;
3048 
3049 	wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
3050 	wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3051 				BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3052 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
3053 				2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3054 
3055 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3056 
3057 	btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3058 
3059 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3060 
3061 	if (BTC_RSSI_HIGH(bt_rssi_state))
3062 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3063 	else
3064 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3065 
3066 	if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state))
3067 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3068 					      0x0, 0x0);
3069 	else
3070 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3071 					      0x4);
3072 
3073 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3074 
3075 	if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3076 	    (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3077 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 12);
3078 
3079 		if (wifi_bw == BTC_WIFI_BW_HT40)
3080 			btc8821a2ant_tdma_duration_adjust(btcoexist, false,
3081 							  true, 3);
3082 		else
3083 			btc8821a2ant_tdma_duration_adjust(btcoexist, false,
3084 							  false, 3);
3085 	} else {
3086 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13);
3087 		btc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 3);
3088 	}
3089 
3090 	/* sw mechanism	 */
3091 	if (wifi_bw == BTC_WIFI_BW_HT40) {
3092 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3093 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3094 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
3095 						   false, false);
3096 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3097 						   false, 0x18);
3098 		} else {
3099 			btc8821a2ant_sw_mechanism1(btcoexist, true, false,
3100 						   false, false);
3101 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3102 						   false, 0x18);
3103 		}
3104 	} else {
3105 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3106 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3107 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
3108 						   false, false);
3109 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3110 						   false, 0x18);
3111 		} else {
3112 			btc8821a2ant_sw_mechanism1(btcoexist, false, false,
3113 						   false, false);
3114 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3115 						   false, 0x18);
3116 		}
3117 	}
3118 }
3119 
3120 static void btc8821a2ant_action_pan_edr_hid(struct btc_coexist *btcoexist)
3121 {
3122 	u8 wifi_rssi_state, bt_rssi_state;
3123 	u32 wifi_bw;
3124 
3125 	wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
3126 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
3127 				2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3128 
3129 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3130 
3131 	if (BTC_RSSI_HIGH(bt_rssi_state))
3132 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
3133 	else
3134 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
3135 
3136 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3137 
3138 	if (wifi_bw == BTC_WIFI_BW_LEGACY) {
3139 		/* for HID at 11b/g mode */
3140 		btc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
3141 					0x5a5f5a5f, 0xffff, 0x3);
3142 	} else {
3143 		/* for HID quality & wifi performance balance at 11n mode */
3144 		btc8821a2ant_coex_table(btcoexist, NORMAL_EXEC, 0x55ff55ff,
3145 					0x5a5f5a5f, 0xffff, 0x3);
3146 	}
3147 
3148 	if (wifi_bw == BTC_WIFI_BW_HT40) {
3149 		btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 3);
3150 		/* fw mechanism */
3151 		if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3152 		    (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3153 			btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3154 					     true, 10);
3155 		} else {
3156 			btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
3157 		}
3158 
3159 		/* sw mechanism */
3160 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3161 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3162 			btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3163 						   false, false);
3164 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3165 						   false, 0x18);
3166 		} else {
3167 			btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3168 						   false, false);
3169 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3170 						   false, 0x18);
3171 		}
3172 	} else {
3173 		btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3174 		/* fw mechanism */
3175 		if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3176 		    (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3177 			btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
3178 		} else {
3179 			btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
3180 		}
3181 
3182 		/* sw mechanism */
3183 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3184 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3185 			btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3186 						   false, false);
3187 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3188 						   false, 0x18);
3189 		} else {
3190 			btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3191 						   false, false);
3192 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3193 						   false, 0x18);
3194 		}
3195 	}
3196 }
3197 
3198 /* HID+A2DP+PAN(EDR) */
3199 static void btc8821a2ant_act_hid_a2dp_pan_edr(struct btc_coexist *btcoexist)
3200 {
3201 	u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3202 	u32 wifi_bw;
3203 
3204 	wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
3205 	wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3206 				BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3207 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
3208 				2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
3209 
3210 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3211 
3212 	btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
3213 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3214 
3215 	if (BTC_RSSI_HIGH(bt_rssi_state))
3216 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3217 	else
3218 		btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3219 
3220 	if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
3221 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3222 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3223 					      0x0, 0x0);
3224 	} else {
3225 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14);
3226 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3227 					      0x4);
3228 	}
3229 
3230 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3231 
3232 	if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3233 	    (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3234 		if (wifi_bw == BTC_WIFI_BW_HT40)
3235 			btc8821a2ant_tdma_duration_adjust(btcoexist, true,
3236 							  true, 3);
3237 		else
3238 			btc8821a2ant_tdma_duration_adjust(btcoexist, true,
3239 							  false, 3);
3240 	} else {
3241 		btc8821a2ant_tdma_duration_adjust(btcoexist, true, true, 3);
3242 	}
3243 
3244 	/* sw mechanism */
3245 	if (wifi_bw == BTC_WIFI_BW_HT40) {
3246 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3247 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3248 			btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3249 						   false, false);
3250 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3251 						   false, 0x18);
3252 		} else {
3253 			btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3254 						   false, false);
3255 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3256 						   false, 0x18);
3257 		}
3258 	} else {
3259 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3260 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3261 			btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3262 						   false, false);
3263 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3264 						   false, 0x18);
3265 		} else {
3266 			btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3267 						   false, false);
3268 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3269 						   false, 0x18);
3270 		}
3271 	}
3272 }
3273 
3274 static void btc8821a2ant_action_hid_a2dp(struct btc_coexist *btcoexist)
3275 {
3276 	u32 wifi_bw;
3277 	u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
3278 	u8 ap_num = 0;
3279 
3280 	wifi_rssi_state = btc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0);
3281 	wifi_rssi_state1 = btc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
3282 				BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
3283 	bt_rssi_state = btc8821a2ant_bt_rssi_state(btcoexist,
3284 				3, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 37);
3285 
3286 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3287 
3288 	btc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x5);
3289 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3290 
3291 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3292 	if (wifi_bw == BTC_WIFI_BW_LEGACY) {
3293 		if (BTC_RSSI_HIGH(bt_rssi_state))
3294 			btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3295 		else if (BTC_RSSI_MEDIUM(bt_rssi_state))
3296 			btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3297 		else
3298 			btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3299 	} else {
3300 		/* only 802.11N mode we have to dec bt power to 4 degree */
3301 		if (BTC_RSSI_HIGH(bt_rssi_state)) {
3302 			btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
3303 					   &ap_num);
3304 			if (ap_num < 10)
3305 				btc8821a2ant_dec_bt_pwr(btcoexist,
3306 							NORMAL_EXEC, 4);
3307 			else
3308 				btc8821a2ant_dec_bt_pwr(btcoexist,
3309 							NORMAL_EXEC, 2);
3310 		} else if (BTC_RSSI_MEDIUM(bt_rssi_state)) {
3311 			btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3312 		} else {
3313 			btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3314 		}
3315 	}
3316 
3317 	if (wifi_bw == BTC_WIFI_BW_LEGACY) {
3318 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
3319 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3320 					      0x0, 0x0);
3321 	} else {
3322 		btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14);
3323 		btc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
3324 					      0x4);
3325 	}
3326 
3327 	if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
3328 	    (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3329 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
3330 	} else {
3331 		btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
3332 	}
3333 
3334 	/* sw mechanism */
3335 	if (wifi_bw == BTC_WIFI_BW_HT40) {
3336 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3337 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3338 			btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3339 						   false, false);
3340 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3341 						   false, 0x18);
3342 		} else {
3343 			btc8821a2ant_sw_mechanism1(btcoexist, true, true,
3344 						   false, false);
3345 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3346 						   false, 0x18);
3347 		}
3348 	} else {
3349 		if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
3350 		    (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
3351 			btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3352 						   false, false);
3353 			btc8821a2ant_sw_mechanism2(btcoexist, true, false,
3354 						   false, 0x18);
3355 		} else {
3356 			btc8821a2ant_sw_mechanism1(btcoexist, false, true,
3357 						   false, false);
3358 			btc8821a2ant_sw_mechanism2(btcoexist, false, false,
3359 						   false, 0x18);
3360 		}
3361 	}
3362 }
3363 
3364 static void btc8821a2ant_action_wifi_multi_port(struct btc_coexist *btcoexist)
3365 {
3366 	btc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
3367 	btc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3368 
3369 	/* sw all off */
3370 	btc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
3371 	btc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
3372 
3373 	/* hw all off */
3374 	btc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3375 
3376 	btc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3377 	btc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
3378 }
3379 
3380 static void btc8821a2ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
3381 {
3382 	struct rtl_priv *rtlpriv = btcoexist->adapter;
3383 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3384 	bool wifi_under_5g = false;
3385 	u8 algorithm = 0;
3386 	u32 num_of_wifi_link = 0;
3387 	u32 wifi_link_status = 0;
3388 	bool miracast_plus_bt = false;
3389 	bool scan = false, link = false, roam = false;
3390 
3391 	if (btcoexist->manual_control) {
3392 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3393 			"[BTCoex], Manual control!!!\n");
3394 		return;
3395 	}
3396 
3397 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3398 
3399 	if (wifi_under_5g) {
3400 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3401 			"[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n");
3402 		btc8821a2ant_coex_under_5g(btcoexist);
3403 		return;
3404 	}
3405 
3406 	if (coex_sta->under_ips) {
3407 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3408 			"[BTCoex], wifi is under IPS !!!\n");
3409 		return;
3410 	}
3411 
3412 	algorithm = btc8821a2ant_action_algorithm(btcoexist);
3413 	if (coex_sta->c2h_bt_inquiry_page &&
3414 	    (BT_8821A_2ANT_COEX_ALGO_PANHS != algorithm)) {
3415 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3416 			"[BTCoex], BT is under inquiry/page scan !!\n");
3417 		btc8821a2ant_action_bt_inquiry(btcoexist);
3418 		return;
3419 	}
3420 
3421 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3422 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3423 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3424 
3425 	if (scan || link || roam) {
3426 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3427 			"[BTCoex], WiFi is under Link Process !!\n");
3428 		btc8821a2ant_action_wifi_link_process(btcoexist);
3429 		return;
3430 	}
3431 
3432 	/* for P2P */
3433 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3434 			   &wifi_link_status);
3435 	num_of_wifi_link = wifi_link_status >> 16;
3436 
3437 	if ((num_of_wifi_link >= 2) ||
3438 	    (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
3439 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3440 			"############# [BTCoex],  Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
3441 			num_of_wifi_link, wifi_link_status);
3442 
3443 		if (bt_link_info->bt_link_exist)
3444 			miracast_plus_bt = true;
3445 		else
3446 			miracast_plus_bt = false;
3447 
3448 		btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3449 				   &miracast_plus_bt);
3450 		btc8821a2ant_action_wifi_multi_port(btcoexist);
3451 
3452 		return;
3453 	}
3454 
3455 	miracast_plus_bt = false;
3456 	btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3457 			   &miracast_plus_bt);
3458 
3459 	coex_dm->cur_algorithm = algorithm;
3460 	rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3461 		"[BTCoex], Algorithm = %d\n", coex_dm->cur_algorithm);
3462 
3463 	if (btc8821a2ant_is_common_action(btcoexist)) {
3464 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3465 			"[BTCoex], Action 2-Ant common\n");
3466 		coex_dm->auto_tdma_adjust = true;
3467 	} else {
3468 		if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
3469 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3470 				"[BTCoex], pre_algorithm = %d, cur_algorithm = %d\n",
3471 				coex_dm->pre_algorithm,
3472 				coex_dm->cur_algorithm);
3473 			coex_dm->auto_tdma_adjust = false;
3474 		}
3475 		switch (coex_dm->cur_algorithm) {
3476 		case BT_8821A_2ANT_COEX_ALGO_SCO:
3477 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3478 				"[BTCoex], Action 2-Ant, algorithm = SCO\n");
3479 			btc8821a2ant_action_sco(btcoexist);
3480 			break;
3481 		case BT_8821A_2ANT_COEX_ALGO_HID:
3482 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3483 				"[BTCoex], Action 2-Ant, algorithm = HID\n");
3484 			btc8821a2ant_action_hid(btcoexist);
3485 			break;
3486 		case BT_8821A_2ANT_COEX_ALGO_A2DP:
3487 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3488 				"[BTCoex], Action 2-Ant, algorithm = A2DP\n");
3489 			btc8821a2ant_action_a2dp(btcoexist);
3490 			break;
3491 		case BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS:
3492 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3493 				"[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS)\n");
3494 			btc8821a2ant_action_a2dp_pan_hs(btcoexist);
3495 			break;
3496 		case BT_8821A_2ANT_COEX_ALGO_PANEDR:
3497 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3498 				"[BTCoex], Action 2-Ant, algorithm = PAN(EDR)\n");
3499 			btc8821a2ant_action_pan_edr(btcoexist);
3500 			break;
3501 		case BT_8821A_2ANT_COEX_ALGO_PANHS:
3502 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3503 				"[BTCoex], Action 2-Ant, algorithm = HS mode\n");
3504 			btc8821a2ant_action_pan_hs(btcoexist);
3505 			break;
3506 		case BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP:
3507 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3508 				"[BTCoex], Action 2-Ant, algorithm = PAN+A2DP\n");
3509 			btc8821a2ant_action_pan_edr_a2dp(btcoexist);
3510 			break;
3511 		case BT_8821A_2ANT_COEX_ALGO_PANEDR_HID:
3512 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3513 				"[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID\n");
3514 			btc8821a2ant_action_pan_edr_hid(btcoexist);
3515 			break;
3516 		case BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
3517 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3518 				"[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN\n");
3519 			btc8821a2ant_act_hid_a2dp_pan_edr(btcoexist);
3520 			break;
3521 		case BT_8821A_2ANT_COEX_ALGO_HID_A2DP:
3522 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3523 				"[BTCoex], Action 2-Ant, algorithm = HID+A2DP\n");
3524 			btc8821a2ant_action_hid_a2dp(btcoexist);
3525 			break;
3526 		default:
3527 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3528 				"[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3529 			btc8821a2ant_coex_all_off(btcoexist);
3530 			break;
3531 		}
3532 		coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3533 	}
3534 }
3535 
3536 static void btc8821a2ant_wifi_off_hw_cfg(struct btc_coexist *btcoexist)
3537 {
3538 	u8 h2c_parameter[2] = {0};
3539 	u32 fw_ver = 0;
3540 
3541 	/* set wlan_act to low */
3542 	btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
3543 
3544 	/* WiFi goto standby while GNT_BT 0-->1 */
3545 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
3546 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3547 	if (fw_ver >= 0x180000) {
3548 		/* Use H2C to set GNT_BT to HIGH */
3549 		h2c_parameter[0] = 1;
3550 		btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, h2c_parameter);
3551 	} else {
3552 		btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18);
3553 	}
3554 }
3555 
3556 /**************************************************************
3557  * extern function start with ex_btc8821a2ant_
3558  **************************************************************/
3559 void ex_btc8821a2ant_init_hwconfig(struct btc_coexist *btcoexist)
3560 {
3561 	struct rtl_priv *rtlpriv = btcoexist->adapter;
3562 	u8 u1tmp = 0;
3563 
3564 	rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3565 		"[BTCoex], 2Ant Init HW Config!!\n");
3566 
3567 	/* backup rf 0x1e value */
3568 	coex_dm->bt_rf0x1e_backup =
3569 		btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff);
3570 
3571 	/* 0x790[5:0] = 0x5 */
3572 	u1tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
3573 	u1tmp &= 0xc0;
3574 	u1tmp |= 0x5;
3575 	btcoexist->btc_write_1byte(btcoexist, 0x790, u1tmp);
3576 
3577 	/* Antenna config */
3578 	btc8821a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_MAIN, true, false);
3579 	coex_sta->dis_ver_info_cnt = 0;
3580 
3581 	/* PTA parameter */
3582 	btc8821a2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
3583 
3584 	/* Enable counter statistics */
3585 	/* 0x76e[3] = 1, WLAN_Act control by PTA */
3586 	btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
3587 	btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
3588 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
3589 }
3590 
3591 void ex_btc8821a2ant_pre_load_firmware(struct btc_coexist *btcoexist)
3592 {
3593 	struct btc_board_info *board_info = &btcoexist->board_info;
3594 	u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */
3595 
3596 	/**
3597 	 * S0 or S1 setting and Local register setting(By the setting fw can get
3598 	 * ant number, S0/S1, ... info)
3599 	 *
3600 	 * Local setting bit define
3601 	 *	BIT0: "0" for no antenna inverse; "1" for antenna inverse
3602 	 *	BIT1: "0" for internal switch; "1" for external switch
3603 	 *	BIT2: "0" for one antenna; "1" for two antenna
3604 	 * NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and
3605 	 * BIT2=0
3606 	 */
3607 	if (btcoexist->chip_interface == BTC_INTF_USB) {
3608 		/* fixed at S0 for USB interface */
3609 		u8tmp |= 0x1; /* antenna inverse */
3610 		btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
3611 	} else {
3612 		/* for PCIE and SDIO interface, we check efuse 0xc3[6] */
3613 		if (board_info->single_ant_path == 0) {
3614 		} else if (board_info->single_ant_path == 1) {
3615 			/* set to S0 */
3616 			u8tmp |= 0x1; /* antenna inverse */
3617 		}
3618 
3619 		if (btcoexist->chip_interface == BTC_INTF_PCI)
3620 			btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384,
3621 							     u8tmp);
3622 		else if (btcoexist->chip_interface == BTC_INTF_SDIO)
3623 			btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60,
3624 							     u8tmp);
3625 	}
3626 }
3627 
3628 void ex_btc8821a2ant_init_coex_dm(struct btc_coexist *btcoexist)
3629 {
3630 	struct rtl_priv *rtlpriv = btcoexist->adapter;
3631 
3632 	rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3633 		"[BTCoex], Coex Mechanism Init!!\n");
3634 
3635 	btc8821a2ant_init_coex_dm(btcoexist);
3636 }
3637 
3638 void ex_btc8821a2ant_display_coex_info(struct btc_coexist *btcoexist,
3639 				       struct seq_file *m)
3640 {
3641 	struct btc_board_info *board_info = &btcoexist->board_info;
3642 	struct btc_stack_info *stack_info = &btcoexist->stack_info;
3643 	u8 u1tmp[4], i, bt_info_ext, ps_tdma_case = 0;
3644 	u32 u4tmp[4];
3645 	bool roam = false, scan = false, link = false, wifi_under_5g = false;
3646 	bool bt_hs_on = false, wifi_busy = false;
3647 	long wifi_rssi = 0, bt_hs_rssi = 0;
3648 	u32 wifi_bw, wifi_traffic_dir;
3649 	u8 wifi_dot_11_chnl, wifi_hs_chnl;
3650 	u32 fw_ver = 0, bt_patch_ver = 0;
3651 
3652 	seq_puts(m, "\n ============[BT Coexist info]============");
3653 
3654 	seq_printf(m, "\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:",
3655 		   board_info->pg_ant_num, board_info->btdm_ant_num);
3656 
3657 	if (btcoexist->manual_control) {
3658 		seq_printf(m, "\n %-35s", "[Action Manual control]!!");
3659 	}
3660 
3661 	seq_printf(m, "\n %-35s = %s / %d", "BT stack/ hci ext ver",
3662 		   ((stack_info->profile_notified) ? "Yes" : "No"),
3663 		   stack_info->hci_version);
3664 
3665 	btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3666 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
3667 	seq_printf(m, "\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
3668 		   "CoexVer/ FwVer/ PatchVer",
3669 		   glcoex_ver_date_8821a_2ant, glcoex_ver_8821a_2ant,
3670 		   fw_ver, bt_patch_ver, bt_patch_ver);
3671 
3672 	btcoexist->btc_get(btcoexist,
3673 		BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3674 	btcoexist->btc_get(btcoexist,
3675 		BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_dot_11_chnl);
3676 	btcoexist->btc_get(btcoexist,
3677 		BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
3678 	seq_printf(m, "\n %-35s = %d / %d(%d)",
3679 		   "Dot11 channel / HsMode(HsChnl)",
3680 		   wifi_dot_11_chnl, bt_hs_on, wifi_hs_chnl);
3681 
3682 	seq_printf(m, "\n %-35s = %3ph ",
3683 		   "H2C Wifi inform bt chnl Info",
3684 		   coex_dm->wifi_chnl_info);
3685 
3686 	btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
3687 	btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
3688 	seq_printf(m, "\n %-35s = %ld/ %ld", "Wifi rssi/ HS rssi",
3689 		   wifi_rssi, bt_hs_rssi);
3690 
3691 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3692 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3693 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3694 	seq_printf(m, "\n %-35s = %d/ %d/ %d ", "Wifi link/ roam/ scan",
3695 		   link, roam, scan);
3696 
3697 	btcoexist->btc_get(btcoexist,
3698 		BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3699 	btcoexist->btc_get(btcoexist,
3700 		BTC_GET_U4_WIFI_BW, &wifi_bw);
3701 	btcoexist->btc_get(btcoexist,
3702 		BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3703 	btcoexist->btc_get(btcoexist,
3704 		BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifi_traffic_dir);
3705 	seq_printf(m, "\n %-35s = %s / %s/ %s ", "Wifi status",
3706 		   (wifi_under_5g ? "5G" : "2.4G"),
3707 		   ((BTC_WIFI_BW_LEGACY == wifi_bw) ? "Legacy" :
3708 		    (((BTC_WIFI_BW_HT40 == wifi_bw) ? "HT40" : "HT20"))),
3709 		   ((!wifi_busy) ? "idle" :
3710 		    ((BTC_WIFI_TRAFFIC_TX == wifi_traffic_dir) ?
3711 		     "uplink" : "downlink")));
3712 
3713 	if (stack_info->profile_notified) {
3714 		seq_printf(m, "\n %-35s = %d / %d / %d / %d",
3715 			   "SCO/HID/PAN/A2DP",
3716 			   stack_info->sco_exist, stack_info->hid_exist,
3717 			   stack_info->pan_exist, stack_info->a2dp_exist);
3718 
3719 		btcoexist->btc_disp_dbg_msg(btcoexist,
3720 					    BTC_DBG_DISP_BT_LINK_INFO,
3721 					    m);
3722 	}
3723 
3724 	bt_info_ext = coex_sta->bt_info_ext;
3725 	seq_printf(m, "\n %-35s = %s", "BT Info A2DP rate",
3726 		   (bt_info_ext&BIT0) ? "Basic rate" : "EDR rate");
3727 
3728 	for (i = 0; i < BT_INFO_SRC_8821A_2ANT_MAX; i++) {
3729 		if (coex_sta->bt_info_c2h_cnt[i]) {
3730 			seq_printf(m, "\n %-35s = %7ph(%d)",
3731 				   glbt_info_src_8821a_2ant[i],
3732 				   coex_sta->bt_info_c2h[i],
3733 				   coex_sta->bt_info_c2h_cnt[i]);
3734 		}
3735 	}
3736 
3737 	seq_printf(m, "\n %-35s = %s/%s",
3738 		   "PS state, IPS/LPS",
3739 		   ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
3740 		   ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")));
3741 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD, m);
3742 
3743 	/* Sw mechanism*/
3744 	seq_printf(m, "\n %-35s",
3745 		   "============[Sw mechanism]============");
3746 	seq_printf(m, "\n %-35s = %d/ %d/ %d(0x%x) ",
3747 		   "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
3748 		   coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
3749 		   coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
3750 
3751 	/* Fw mechanism*/
3752 	seq_printf(m, "\n %-35s",
3753 		   "============[Fw mechanism]============");
3754 
3755 	if (!btcoexist->manual_control) {
3756 		ps_tdma_case = coex_dm->cur_ps_tdma;
3757 		seq_printf(m, "\n %-35s = %5ph case-%d",
3758 			   "PS TDMA",
3759 			   coex_dm->ps_tdma_para, ps_tdma_case);
3760 
3761 		seq_printf(m, "\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct",
3762 			   coex_dm->cur_dec_bt_pwr_lvl,
3763 			   coex_dm->cur_ignore_wlan_act);
3764 	}
3765 
3766 	/* Hw setting*/
3767 	seq_printf(m, "\n %-35s", "============[Hw setting]============");
3768 
3769 	seq_printf(m, "\n %-35s = 0x%x", "RF-A, 0x1e initVal",
3770 		   coex_dm->bt_rf0x1e_backup);
3771 
3772 	u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
3773 	u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
3774 	seq_printf(m, "\n %-35s = 0x%x/ 0x%x ",
3775 		   "0x778 (W_Act)/ 0x6cc (CoTab Sel)",
3776 		   u1tmp[0], u1tmp[1]);
3777 
3778 	u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
3779 	u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xc5b);
3780 	seq_printf(m, "\n %-35s = 0x%x/ 0x%x",
3781 		   "0x8db(ADC)/0xc5b[29:25](DAC)",
3782 		   ((u1tmp[0] & 0x60) >> 5), ((u1tmp[1] & 0x3e) >> 1));
3783 
3784 	u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
3785 	seq_printf(m, "\n %-35s = 0x%x/ 0x%x",
3786 		   "0xcb4[7:0](ctrl)/ 0xcb4[29:28](val)",
3787 		   u4tmp[0] & 0xff, ((u4tmp[0] & 0x30000000) >> 28));
3788 
3789 	u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
3790 	u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
3791 	u4tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x974);
3792 	seq_printf(m, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
3793 		   "0x40/ 0x4c[24:23]/ 0x974",
3794 		   u1tmp[0], ((u4tmp[0] & 0x01800000) >> 23), u4tmp[1]);
3795 
3796 	u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
3797 	u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
3798 	seq_printf(m, "\n %-35s = 0x%x/ 0x%x",
3799 		   "0x550(bcn ctrl)/0x522",
3800 		   u4tmp[0], u1tmp[0]);
3801 
3802 	u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
3803 	u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa0a);
3804 	seq_printf(m, "\n %-35s = 0x%x/ 0x%x",
3805 		   "0xc50(DIG)/0xa0a(CCK-TH)",
3806 		   u4tmp[0], u1tmp[0]);
3807 
3808 	u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48);
3809 	u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
3810 	u1tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
3811 	seq_printf(m, "\n %-35s = 0x%x/ 0x%x",
3812 		   "OFDM-FA/ CCK-FA",
3813 		   u4tmp[0], (u1tmp[0] << 8) + u1tmp[1]);
3814 
3815 	u4tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
3816 	u4tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
3817 	u4tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
3818 	seq_printf(m, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
3819 		   "0x6c0/0x6c4/0x6c8",
3820 		   u4tmp[0], u4tmp[1], u4tmp[2]);
3821 
3822 	seq_printf(m, "\n %-35s = %d/ %d",
3823 		   "0x770 (hi-pri Rx/Tx)",
3824 		   coex_sta->high_priority_rx, coex_sta->high_priority_tx);
3825 	seq_printf(m, "\n %-35s = %d/ %d",
3826 		   "0x774(low-pri Rx/Tx)",
3827 		   coex_sta->low_priority_rx, coex_sta->low_priority_tx);
3828 
3829 	/* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang*/
3830 	u1tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x41b);
3831 	seq_printf(m, "\n %-35s = 0x%x",
3832 		   "0x41b (mgntQ hang chk == 0xf)",
3833 		   u1tmp[0]);
3834 
3835 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS, m);
3836 }
3837 
3838 void ex_btc8821a2ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
3839 {
3840 	struct rtl_priv *rtlpriv = btcoexist->adapter;
3841 
3842 	if (BTC_IPS_ENTER == type) {
3843 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3844 			"[BTCoex], IPS ENTER notify\n");
3845 		coex_sta->under_ips = true;
3846 		btc8821a2ant_wifi_off_hw_cfg(btcoexist);
3847 		btc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3848 		btc8821a2ant_coex_all_off(btcoexist);
3849 	} else if (BTC_IPS_LEAVE == type) {
3850 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3851 			"[BTCoex], IPS LEAVE notify\n");
3852 		coex_sta->under_ips = false;
3853 		ex_btc8821a2ant_init_hwconfig(btcoexist);
3854 		btc8821a2ant_init_coex_dm(btcoexist);
3855 		btc8821a2ant_query_bt_info(btcoexist);
3856 	}
3857 }
3858 
3859 void ex_btc8821a2ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
3860 {
3861 	struct rtl_priv *rtlpriv = btcoexist->adapter;
3862 
3863 	if (BTC_LPS_ENABLE == type) {
3864 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3865 			"[BTCoex], LPS ENABLE notify\n");
3866 		coex_sta->under_lps = true;
3867 	} else if (BTC_LPS_DISABLE == type) {
3868 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3869 			"[BTCoex], LPS DISABLE notify\n");
3870 		coex_sta->under_lps = false;
3871 	}
3872 }
3873 
3874 void ex_btc8821a2ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
3875 {
3876 	struct rtl_priv *rtlpriv = btcoexist->adapter;
3877 
3878 	if (BTC_SCAN_START == type) {
3879 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3880 			"[BTCoex], SCAN START notify\n");
3881 	} else if (BTC_SCAN_FINISH == type) {
3882 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3883 			"[BTCoex], SCAN FINISH notify\n");
3884 	}
3885 }
3886 
3887 void ex_btc8821a2ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
3888 {
3889 	struct rtl_priv *rtlpriv = btcoexist->adapter;
3890 
3891 	if (BTC_ASSOCIATE_START == type) {
3892 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3893 			"[BTCoex], CONNECT START notify\n");
3894 	} else if (BTC_ASSOCIATE_FINISH == type) {
3895 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3896 			"[BTCoex], CONNECT FINISH notify\n");
3897 	}
3898 }
3899 
3900 void ex_btc8821a2ant_media_status_notify(struct btc_coexist *btcoexist,
3901 					 u8 type)
3902 {
3903 	struct rtl_priv *rtlpriv = btcoexist->adapter;
3904 	u8 h2c_parameter[3] = {0};
3905 	u32 wifi_bw;
3906 	u8 wifi_central_chnl;
3907 	u8 ap_num = 0;
3908 
3909 	if (BTC_MEDIA_CONNECT == type) {
3910 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3911 			"[BTCoex], MEDIA connect notify\n");
3912 	} else {
3913 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3914 			"[BTCoex], MEDIA disconnect notify\n");
3915 	}
3916 
3917 	/* only 2.4G we need to inform bt the chnl mask */
3918 	btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
3919 			   &wifi_central_chnl);
3920 	if ((BTC_MEDIA_CONNECT == type) &&
3921 	    (wifi_central_chnl <= 14)) {
3922 		h2c_parameter[0] = 0x1;
3923 		h2c_parameter[1] = wifi_central_chnl;
3924 		btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3925 		if (wifi_bw == BTC_WIFI_BW_HT40) {
3926 			h2c_parameter[2] = 0x30;
3927 		} else {
3928 			h2c_parameter[2] = 0x20;
3929 			if (ap_num < 10)
3930 				h2c_parameter[2] = 0x30;
3931 			else
3932 				h2c_parameter[2] = 0x20;
3933 		}
3934 	}
3935 
3936 	coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
3937 	coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
3938 	coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
3939 
3940 	rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3941 		"[BTCoex], FW write 0x66 = 0x%x\n",
3942 		h2c_parameter[0] << 16 |
3943 		h2c_parameter[1] << 8 |
3944 		h2c_parameter[2]);
3945 
3946 	btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
3947 }
3948 
3949 void ex_btc8821a2ant_special_packet_notify(struct btc_coexist *btcoexist,
3950 					   u8 type)
3951 {
3952 	struct rtl_priv *rtlpriv = btcoexist->adapter;
3953 
3954 	if (type == BTC_PACKET_DHCP) {
3955 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3956 			"[BTCoex], DHCP Packet notify\n");
3957 	}
3958 }
3959 
3960 void ex_btc8821a2ant_bt_info_notify(struct btc_coexist *btcoexist,
3961 				    u8 *tmp_buf, u8 length)
3962 {
3963 	struct rtl_priv *rtlpriv = btcoexist->adapter;
3964 	u8 bt_info = 0;
3965 	u8 i, rsp_source = 0;
3966 	bool bt_busy = false, limited_dig = false;
3967 	bool wifi_connected = false, wifi_under_5g = false;
3968 
3969 	coex_sta->c2h_bt_info_req_sent = false;
3970 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3971 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3972 			   &wifi_connected);
3973 
3974 	rsp_source = tmp_buf[0] & 0xf;
3975 	if (rsp_source >= BT_INFO_SRC_8821A_2ANT_MAX)
3976 		rsp_source = BT_INFO_SRC_8821A_2ANT_WIFI_FW;
3977 	coex_sta->bt_info_c2h_cnt[rsp_source]++;
3978 
3979 	rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3980 		"[BTCoex], Bt info[%d], length = %d, hex data = [",
3981 		rsp_source, length);
3982 	for (i = 0; i < length; i++) {
3983 		coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
3984 		if (i == 1)
3985 			bt_info = tmp_buf[i];
3986 		if (i == length - 1) {
3987 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3988 				"0x%02x]\n", tmp_buf[i]);
3989 		} else {
3990 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3991 				"0x%02x, ", tmp_buf[i]);
3992 		}
3993 	}
3994 
3995 	if (btcoexist->manual_control) {
3996 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3997 			"[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n");
3998 		return;
3999 	}
4000 
4001 	if (BT_INFO_SRC_8821A_2ANT_WIFI_FW != rsp_source) {
4002 		/* [3:0] */
4003 		coex_sta->bt_retry_cnt =
4004 			coex_sta->bt_info_c2h[rsp_source][2]&0xf;
4005 
4006 		coex_sta->bt_rssi =
4007 			coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
4008 
4009 		coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4];
4010 
4011 		coex_sta->bt_tx_rx_mask =
4012 			(coex_sta->bt_info_c2h[rsp_source][2] & 0x40);
4013 		btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
4014 				   &coex_sta->bt_tx_rx_mask);
4015 		if (coex_sta->bt_tx_rx_mask) {
4016 			/* BT into is responded by BT FW and BT RF REG 0x3C !=
4017 			 * 0x01 => Need to switch BT TRx Mask
4018 			 */
4019 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4020 				"[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n");
4021 			btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
4022 						  0x3c, 0x01);
4023 		}
4024 
4025 		/* Here we need to resend some wifi info to BT
4026 		 * because bt is reset and loss of the info
4027 		 */
4028 		if ((coex_sta->bt_info_ext & BIT1)) {
4029 			btcoexist->btc_get(btcoexist,
4030 				BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
4031 			if (wifi_connected) {
4032 				ex_btc8821a2ant_media_status_notify(btcoexist,
4033 					BTC_MEDIA_CONNECT);
4034 			} else {
4035 				ex_btc8821a2ant_media_status_notify(btcoexist,
4036 					BTC_MEDIA_DISCONNECT);
4037 			}
4038 
4039 		}
4040 
4041 		if (!btcoexist->manual_control && !wifi_under_5g) {
4042 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4043 				"[BTCoex], BT ext info = 0x%x!!\n",
4044 				coex_sta->bt_info_ext);
4045 			if ((coex_sta->bt_info_ext & BIT(3))) {
4046 				rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4047 					"[BTCoex], BT ext info bit3=1, wifi_connected=%d\n",
4048 					wifi_connected);
4049 				if (wifi_connected) {
4050 					rtl_dbg(rtlpriv, COMP_BT_COEXIST,
4051 						DBG_LOUD,
4052 						"[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
4053 					btc8821a2ant_ignore_wlan_act(btcoexist,
4054 								     FORCE_EXEC,
4055 								     false);
4056 				}
4057 			} else {
4058 				rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4059 					"[BTCoex], BT ext info bit3=0, wifi_connected=%d\n",
4060 					wifi_connected);
4061 				/* BT already NOT ignore Wlan active, do nothing
4062 				 * here.
4063 				 */
4064 				if (!wifi_connected) {
4065 					rtl_dbg(rtlpriv, COMP_BT_COEXIST,
4066 						DBG_LOUD,
4067 						"[BTCoex], BT ext info bit3 check, set BT to ignore Wlan active!!\n");
4068 					btc8821a2ant_ignore_wlan_act(
4069 						btcoexist, FORCE_EXEC, true);
4070 				}
4071 			}
4072 		}
4073 	}
4074 
4075 	/* check BIT2 first ==> check if bt is under inquiry or page scan*/
4076 	if (bt_info & BT_INFO_8821A_2ANT_B_INQ_PAGE) {
4077 		coex_sta->c2h_bt_inquiry_page = true;
4078 	} else {
4079 		coex_sta->c2h_bt_inquiry_page = false;
4080 	}
4081 	/* set link exist status */
4082 	if (!(bt_info & BT_INFO_8821A_2ANT_B_CONNECTION)) {
4083 		coex_sta->bt_link_exist = false;
4084 		coex_sta->pan_exist = false;
4085 		coex_sta->a2dp_exist = false;
4086 		coex_sta->hid_exist = false;
4087 		coex_sta->sco_exist = false;
4088 	} else { /* connection exists */
4089 		coex_sta->bt_link_exist = true;
4090 		if (bt_info & BT_INFO_8821A_2ANT_B_FTP)
4091 			coex_sta->pan_exist = true;
4092 		else
4093 			coex_sta->pan_exist = false;
4094 		if (bt_info & BT_INFO_8821A_2ANT_B_A2DP)
4095 			coex_sta->a2dp_exist = true;
4096 		else
4097 			coex_sta->a2dp_exist = false;
4098 		if (bt_info & BT_INFO_8821A_2ANT_B_HID)
4099 			coex_sta->hid_exist = true;
4100 		else
4101 			coex_sta->hid_exist = false;
4102 		if (bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO)
4103 			coex_sta->sco_exist = true;
4104 		else
4105 			coex_sta->sco_exist = false;
4106 
4107 		if ((!coex_sta->hid_exist) &&
4108 		    (!coex_sta->c2h_bt_inquiry_page) &&
4109 		    (!coex_sta->sco_exist)) {
4110 			if (coex_sta->high_priority_tx +
4111 				    coex_sta->high_priority_rx >= 160)
4112 				coex_sta->hid_exist = true;
4113 		}
4114 	}
4115 
4116 	btc8821a2ant_update_bt_link_info(btcoexist);
4117 
4118 	if (!(bt_info & BT_INFO_8821A_2ANT_B_CONNECTION)) {
4119 		coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_IDLE;
4120 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4121 			"[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
4122 	} else if (bt_info == BT_INFO_8821A_2ANT_B_CONNECTION) {
4123 		/* connection exists but no busy */
4124 		coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_CON_IDLE;
4125 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4126 			"[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
4127 	} else if ((bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO) ||
4128 		   (bt_info & BT_INFO_8821A_2ANT_B_SCO_BUSY)) {
4129 		coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_SCO_BUSY;
4130 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4131 			"[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
4132 	} else if (bt_info & BT_INFO_8821A_2ANT_B_ACL_BUSY) {
4133 		coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_ACL_BUSY;
4134 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4135 			"[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
4136 	} else {
4137 		coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_MAX;
4138 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4139 			"[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
4140 	}
4141 
4142 	if ((coex_dm->bt_status == BT_8821A_2ANT_BT_STATUS_ACL_BUSY) ||
4143 	    (coex_dm->bt_status == BT_8821A_2ANT_BT_STATUS_SCO_BUSY) ||
4144 	    (coex_dm->bt_status == BT_8821A_2ANT_BT_STATUS_ACL_SCO_BUSY)) {
4145 		bt_busy = true;
4146 		limited_dig = true;
4147 	} else {
4148 		bt_busy = false;
4149 		limited_dig = false;
4150 	}
4151 
4152 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
4153 
4154 	coex_dm->limited_dig = limited_dig;
4155 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
4156 
4157 	btc8821a2ant_run_coexist_mechanism(btcoexist);
4158 }
4159 
4160 void ex_btc8821a2ant_halt_notify(struct btc_coexist *btcoexist)
4161 {
4162 	struct rtl_priv *rtlpriv = btcoexist->adapter;
4163 
4164 	rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4165 		"[BTCoex], Halt notify\n");
4166 
4167 	btc8821a2ant_wifi_off_hw_cfg(btcoexist);
4168 	btc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
4169 	ex_btc8821a2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
4170 }
4171 
4172 void ex_btc8821a2ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
4173 {
4174 	struct rtl_priv *rtlpriv = btcoexist->adapter;
4175 
4176 	rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Pnp notify\n");
4177 
4178 	if (pnp_state == BTC_WIFI_PNP_SLEEP) {
4179 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4180 			"[BTCoex], Pnp notify to SLEEP\n");
4181 	} else if (pnp_state == BTC_WIFI_PNP_WAKE_UP) {
4182 		rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4183 			"[BTCoex], Pnp notify to WAKE UP\n");
4184 		ex_btc8821a2ant_init_hwconfig(btcoexist);
4185 		btc8821a2ant_init_coex_dm(btcoexist);
4186 		btc8821a2ant_query_bt_info(btcoexist);
4187 	}
4188 }
4189 
4190 void ex_btc8821a2ant_periodical(struct btc_coexist *btcoexist)
4191 {
4192 	struct rtl_priv *rtlpriv = btcoexist->adapter;
4193 
4194 	rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4195 		"[BTCoex], ==========================Periodical===========================\n");
4196 
4197 	if (coex_sta->dis_ver_info_cnt <= 5) {
4198 		coex_sta->dis_ver_info_cnt += 1;
4199 		if (coex_sta->dis_ver_info_cnt == 3) {
4200 			/* Antenna config to set 0x765 = 0x0 (GNT_BT control by
4201 			 * PTA) after initial
4202 			 */
4203 			rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4204 				"[BTCoex], Set GNT_BT control by PTA\n");
4205 			btc8821a2ant_set_ant_path(btcoexist,
4206 					BTC_ANT_WIFI_AT_MAIN, false, false);
4207 		}
4208 	}
4209 
4210 	if (btcoexist->auto_report_2ant) {
4211 		btc8821a2ant_query_bt_info(btcoexist);
4212 	} else {
4213 		btc8821a2ant_monitor_bt_ctr(btcoexist);
4214 		btc8821a2ant_monitor_wifi_ctr(btcoexist);
4215 
4216 		if (btc8821a2ant_is_wifi_status_changed(btcoexist) ||
4217 		    coex_dm->auto_tdma_adjust)
4218 			btc8821a2ant_run_coexist_mechanism(btcoexist);
4219 	}
4220 }
4221