1 /******************************************************************************
2  *
3  * Copyright(c) 2012  Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * The full GNU General Public License is included in this distribution in the
15  * file called LICENSE.
16  *
17  * Contact Information:
18  * wlanfae <wlanfae@realtek.com>
19  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20  * Hsinchu 300, Taiwan.
21  *
22  * Larry Finger <Larry.Finger@lwfinger.net>
23  *
24  *****************************************************************************/
25 
26 /***************************************************************
27  * Description:
28  *
29  * This file is for RTL8723B Co-exist mechanism
30  *
31  * History
32  * 2012/11/15 Cosa first check in.
33  *
34  ***************************************************************/
35 
36 /***************************************************************
37  * include files
38  ***************************************************************/
39 #include "halbt_precomp.h"
40 /***************************************************************
41  * Global variables, these are static variables
42  ***************************************************************/
43 static struct coex_dm_8723b_1ant glcoex_dm_8723b_1ant;
44 static struct coex_dm_8723b_1ant *coex_dm = &glcoex_dm_8723b_1ant;
45 static struct coex_sta_8723b_1ant glcoex_sta_8723b_1ant;
46 static struct coex_sta_8723b_1ant *coex_sta = &glcoex_sta_8723b_1ant;
47 
48 static const char *const glbt_info_src_8723b_1ant[] = {
49 	"BT Info[wifi fw]",
50 	"BT Info[bt rsp]",
51 	"BT Info[bt auto report]",
52 };
53 
54 static u32 glcoex_ver_date_8723b_1ant = 20130918;
55 static u32 glcoex_ver_8723b_1ant = 0x47;
56 
57 /***************************************************************
58  * local function proto type if needed
59  ***************************************************************/
60 /***************************************************************
61  * local function start with halbtc8723b1ant_
62  ***************************************************************/
63 
64 static void halbtc8723b1ant_updatera_mask(struct btc_coexist *btcoexist,
65 					  bool force_exec, u32 dis_rate_mask)
66 {
67 	coex_dm->curra_mask = dis_rate_mask;
68 
69 	if (force_exec || (coex_dm->prera_mask != coex_dm->curra_mask))
70 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
71 				   &coex_dm->curra_mask);
72 
73 	coex_dm->prera_mask = coex_dm->curra_mask;
74 }
75 
76 static void btc8723b1ant_auto_rate_fb_retry(struct btc_coexist *btcoexist,
77 					    bool force_exec, u8 type)
78 {
79 	bool wifi_under_bmode = false;
80 
81 	coex_dm->cur_arfr_type = type;
82 
83 	if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
84 		switch (coex_dm->cur_arfr_type) {
85 		case 0:	/* normal mode */
86 			btcoexist->btc_write_4byte(btcoexist, 0x430,
87 						   coex_dm->backup_arfr_cnt1);
88 			btcoexist->btc_write_4byte(btcoexist, 0x434,
89 						   coex_dm->backup_arfr_cnt2);
90 			break;
91 		case 1:
92 			btcoexist->btc_get(btcoexist,
93 					   BTC_GET_BL_WIFI_UNDER_B_MODE,
94 					   &wifi_under_bmode);
95 			if (wifi_under_bmode) {
96 				btcoexist->btc_write_4byte(btcoexist,
97 							   0x430, 0x0);
98 				btcoexist->btc_write_4byte(btcoexist,
99 							   0x434, 0x01010101);
100 			} else {
101 				btcoexist->btc_write_4byte(btcoexist,
102 							   0x430, 0x0);
103 				btcoexist->btc_write_4byte(btcoexist,
104 							   0x434, 0x04030201);
105 			}
106 			break;
107 		default:
108 			break;
109 		}
110 	}
111 
112 	coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
113 }
114 
115 static void halbtc8723b1ant_retry_limit(struct btc_coexist *btcoexist,
116 					bool force_exec, u8 type)
117 {
118 	coex_dm->cur_retry_limit_type = type;
119 
120 	if (force_exec || (coex_dm->pre_retry_limit_type !=
121 			   coex_dm->cur_retry_limit_type)) {
122 		switch (coex_dm->cur_retry_limit_type) {
123 		case 0:	/* normal mode */
124 			btcoexist->btc_write_2byte(btcoexist, 0x42a,
125 						   coex_dm->backup_retry_limit);
126 			break;
127 		case 1:	/* retry limit = 8 */
128 			btcoexist->btc_write_2byte(btcoexist, 0x42a, 0x0808);
129 			break;
130 		default:
131 			break;
132 		}
133 	}
134 
135 	coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
136 }
137 
138 static void halbtc8723b1ant_ampdu_maxtime(struct btc_coexist *btcoexist,
139 					  bool force_exec, u8 type)
140 {
141 	coex_dm->cur_ampdu_time_type = type;
142 
143 	if (force_exec || (coex_dm->pre_ampdu_time_type !=
144 		coex_dm->cur_ampdu_time_type)) {
145 		switch (coex_dm->cur_ampdu_time_type) {
146 		case 0:	/* normal mode */
147 			btcoexist->btc_write_1byte(btcoexist, 0x456,
148 					coex_dm->backup_ampdu_max_time);
149 			break;
150 		case 1:	/* AMPDU timw = 0x38 * 32us */
151 			btcoexist->btc_write_1byte(btcoexist, 0x456, 0x38);
152 			break;
153 		default:
154 			break;
155 		}
156 	}
157 
158 	coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
159 }
160 
161 static void halbtc8723b1ant_limited_tx(struct btc_coexist *btcoexist,
162 				       bool force_exec, u8 ra_masktype,
163 				       u8 arfr_type, u8 retry_limit_type,
164 				       u8 ampdu_time_type)
165 {
166 	switch (ra_masktype) {
167 	case 0:	/* normal mode */
168 		halbtc8723b1ant_updatera_mask(btcoexist, force_exec, 0x0);
169 		break;
170 	case 1:	/* disable cck 1/2 */
171 		halbtc8723b1ant_updatera_mask(btcoexist, force_exec,
172 					      0x00000003);
173 		break;
174 	/* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
175 	case 2:
176 		halbtc8723b1ant_updatera_mask(btcoexist, force_exec,
177 					      0x0001f1f7);
178 		break;
179 	default:
180 		break;
181 	}
182 
183 	btc8723b1ant_auto_rate_fb_retry(btcoexist, force_exec, arfr_type);
184 	halbtc8723b1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
185 	halbtc8723b1ant_ampdu_maxtime(btcoexist, force_exec, ampdu_time_type);
186 }
187 
188 static void halbtc8723b1ant_limited_rx(struct btc_coexist *btcoexist,
189 				       bool force_exec, bool rej_ap_agg_pkt,
190 				       bool bt_ctrl_agg_buf_size,
191 				       u8 agg_buf_size)
192 {
193 	bool reject_rx_agg = rej_ap_agg_pkt;
194 	bool bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
195 	u8 rxaggsize = agg_buf_size;
196 
197 	/**********************************************
198 	 *	Rx Aggregation related setting
199 	 **********************************************/
200 	btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
201 			   &reject_rx_agg);
202 	/* decide BT control aggregation buf size or not  */
203 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
204 			   &bt_ctrl_rx_agg_size);
205 	/* aggregation buf size, only work
206 	 * when BT control Rx aggregation size.
207 	 */
208 	btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxaggsize);
209 	/* real update aggregation setting  */
210 	btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
211 }
212 
213 static void halbtc8723b1ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
214 {
215 	u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
216 	u32 reg_hp_tx = 0, reg_hp_rx = 0;
217 	u32 reg_lp_tx = 0, reg_lp_rx = 0;
218 
219 	reg_hp_txrx = 0x770;
220 	reg_lp_txrx = 0x774;
221 
222 	u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
223 	reg_hp_tx = u32tmp & MASKLWORD;
224 	reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
225 
226 	u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
227 	reg_lp_tx = u32tmp & MASKLWORD;
228 	reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
229 
230 	coex_sta->high_priority_tx = reg_hp_tx;
231 	coex_sta->high_priority_rx = reg_hp_rx;
232 	coex_sta->low_priority_tx = reg_lp_tx;
233 	coex_sta->low_priority_rx = reg_lp_rx;
234 
235 	/* reset counter */
236 	btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
237 }
238 
239 static void halbtc8723b1ant_query_bt_info(struct btc_coexist *btcoexist)
240 {
241 	struct rtl_priv *rtlpriv = btcoexist->adapter;
242 	u8 h2c_parameter[1] = {0};
243 
244 	coex_sta->c2h_bt_info_req_sent = true;
245 
246 	/* trigger */
247 	h2c_parameter[0] |= BIT0;
248 
249 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
250 		 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
251 		 h2c_parameter[0]);
252 
253 	btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
254 }
255 
256 static bool btc8723b1ant_is_wifi_status_changed(struct btc_coexist *btcoexist)
257 {
258 	static bool pre_wifi_busy;
259 	static bool pre_under_4way, pre_bt_hs_on;
260 	bool wifi_busy = false, under_4way = false, bt_hs_on = false;
261 	bool wifi_connected = false;
262 
263 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
264 			   &wifi_connected);
265 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
266 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
267 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
268 			   &under_4way);
269 
270 	if (wifi_connected) {
271 		if (wifi_busy != pre_wifi_busy) {
272 			pre_wifi_busy = wifi_busy;
273 			return true;
274 		}
275 		if (under_4way != pre_under_4way) {
276 			pre_under_4way = under_4way;
277 			return true;
278 		}
279 		if (bt_hs_on != pre_bt_hs_on) {
280 			pre_bt_hs_on = bt_hs_on;
281 			return true;
282 		}
283 	}
284 
285 	return false;
286 }
287 
288 static void halbtc8723b1ant_update_bt_link_info(struct btc_coexist *btcoexist)
289 {
290 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
291 	bool bt_hs_on = false;
292 
293 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
294 
295 	bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
296 	bt_link_info->sco_exist = coex_sta->sco_exist;
297 	bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
298 	bt_link_info->pan_exist = coex_sta->pan_exist;
299 	bt_link_info->hid_exist = coex_sta->hid_exist;
300 
301 	/* work around for HS mode. */
302 	if (bt_hs_on) {
303 		bt_link_info->pan_exist = true;
304 		bt_link_info->bt_link_exist = true;
305 	}
306 
307 	/* check if Sco only */
308 	if (bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
309 	    !bt_link_info->pan_exist && !bt_link_info->hid_exist)
310 		bt_link_info->sco_only = true;
311 	else
312 		bt_link_info->sco_only = false;
313 
314 	/* check if A2dp only */
315 	if (!bt_link_info->sco_exist && bt_link_info->a2dp_exist &&
316 	    !bt_link_info->pan_exist && !bt_link_info->hid_exist)
317 		bt_link_info->a2dp_only = true;
318 	else
319 		bt_link_info->a2dp_only = false;
320 
321 	/* check if Pan only */
322 	if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
323 	    bt_link_info->pan_exist && !bt_link_info->hid_exist)
324 		bt_link_info->pan_only = true;
325 	else
326 		bt_link_info->pan_only = false;
327 
328 	/* check if Hid only */
329 	if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
330 	    !bt_link_info->pan_exist && bt_link_info->hid_exist)
331 		bt_link_info->hid_only = true;
332 	else
333 		bt_link_info->hid_only = false;
334 }
335 
336 static void btc8723b1ant_set_sw_pen_tx_rate_adapt(struct btc_coexist *btcoexist,
337 						  bool low_penalty_ra)
338 {
339 	struct rtl_priv *rtlpriv = btcoexist->adapter;
340 	u8 h2c_parameter[6] = {0};
341 
342 	h2c_parameter[0] = 0x6;	/* opCode, 0x6= Retry_Penalty */
343 
344 	if (low_penalty_ra) {
345 		h2c_parameter[1] |= BIT0;
346 		/* normal rate except MCS7/6/5, OFDM54/48/36 */
347 		h2c_parameter[2] = 0x00;
348 		h2c_parameter[3] = 0xf7;  /* MCS7 or OFDM54 */
349 		h2c_parameter[4] = 0xf8;  /* MCS6 or OFDM48 */
350 		h2c_parameter[5] = 0xf9;  /* MCS5 or OFDM36 */
351 	}
352 
353 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
354 		 "[BTCoex], set WiFi Low-Penalty Retry: %s",
355 		 (low_penalty_ra ? "ON!!" : "OFF!!"));
356 
357 	btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
358 }
359 
360 static void halbtc8723b1ant_low_penalty_ra(struct btc_coexist *btcoexist,
361 					   bool force_exec, bool low_penalty_ra)
362 {
363 	coex_dm->cur_low_penalty_ra = low_penalty_ra;
364 
365 	if (!force_exec) {
366 		if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
367 			return;
368 	}
369 	btc8723b1ant_set_sw_pen_tx_rate_adapt(btcoexist,
370 					      coex_dm->cur_low_penalty_ra);
371 
372 	coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
373 }
374 
375 static void halbtc8723b1ant_set_coex_table(struct btc_coexist *btcoexist,
376 					   u32 val0x6c0, u32 val0x6c4,
377 					   u32 val0x6c8, u8 val0x6cc)
378 {
379 	struct rtl_priv *rtlpriv = btcoexist->adapter;
380 
381 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
382 		 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0);
383 	btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
384 
385 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
386 		 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4);
387 	btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
388 
389 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
390 		 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8);
391 	btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
392 
393 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
394 		 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc);
395 	btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
396 }
397 
398 static void halbtc8723b1ant_coex_table(struct btc_coexist *btcoexist,
399 				       bool force_exec, u32 val0x6c0,
400 				       u32 val0x6c4, u32 val0x6c8,
401 				       u8 val0x6cc)
402 {
403 	struct rtl_priv *rtlpriv = btcoexist->adapter;
404 
405 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
406 		 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6cc = 0x%x\n",
407 		 (force_exec ? "force to" : ""),
408 		 val0x6c0, val0x6c4, val0x6cc);
409 	coex_dm->cur_val0x6c0 = val0x6c0;
410 	coex_dm->cur_val0x6c4 = val0x6c4;
411 	coex_dm->cur_val0x6c8 = val0x6c8;
412 	coex_dm->cur_val0x6cc = val0x6cc;
413 
414 	if (!force_exec) {
415 		if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
416 		    (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
417 		    (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
418 		    (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
419 			return;
420 	}
421 	halbtc8723b1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4,
422 				       val0x6c8, val0x6cc);
423 
424 	coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
425 	coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
426 	coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
427 	coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
428 }
429 
430 static void halbtc8723b1ant_coex_table_with_type(struct btc_coexist *btcoexist,
431 						 bool force_exec, u8 type)
432 {
433 	switch (type) {
434 	case 0:
435 		halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
436 					   0x55555555, 0xffffff, 0x3);
437 		break;
438 	case 1:
439 		halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
440 					   0x5a5a5a5a, 0xffffff, 0x3);
441 		break;
442 	case 2:
443 		halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
444 					   0x5a5a5a5a, 0xffffff, 0x3);
445 		break;
446 	case 3:
447 		halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
448 					   0xaaaaaaaa, 0xffffff, 0x3);
449 		break;
450 	case 4:
451 		halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
452 					   0x5aaa5aaa, 0xffffff, 0x3);
453 		break;
454 	case 5:
455 		halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
456 					   0xaaaa5a5a, 0xffffff, 0x3);
457 		break;
458 	case 6:
459 		halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
460 					   0xaaaa5a5a, 0xffffff, 0x3);
461 		break;
462 	case 7:
463 		halbtc8723b1ant_coex_table(btcoexist, force_exec, 0xaaaaaaaa,
464 					   0xaaaaaaaa, 0xffffff, 0x3);
465 		break;
466 	default:
467 		break;
468 	}
469 }
470 
471 static void
472 halbtc8723b1ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoexist,
473 				       bool enable)
474 {
475 	struct rtl_priv *rtlpriv = btcoexist->adapter;
476 	u8 h2c_parameter[1] = {0};
477 
478 	if (enable)
479 		h2c_parameter[0] |= BIT0;	/* function enable */
480 
481 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
482 		 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
483 		 h2c_parameter[0]);
484 
485 	btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
486 }
487 
488 static void halbtc8723b1ant_ignore_wlan_act(struct btc_coexist *btcoexist,
489 					    bool force_exec, bool enable)
490 {
491 	struct rtl_priv *rtlpriv = btcoexist->adapter;
492 
493 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
494 		 "[BTCoex], %s turn Ignore WlanAct %s\n",
495 		 (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
496 	coex_dm->cur_ignore_wlan_act = enable;
497 
498 	if (!force_exec) {
499 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
500 			 "[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
501 			 coex_dm->pre_ignore_wlan_act,
502 			 coex_dm->cur_ignore_wlan_act);
503 
504 		if (coex_dm->pre_ignore_wlan_act ==
505 		    coex_dm->cur_ignore_wlan_act)
506 			return;
507 	}
508 	halbtc8723b1ant_set_fw_ignore_wlan_act(btcoexist, enable);
509 
510 	coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
511 }
512 
513 static void halbtc8723b1ant_set_fw_ps_tdma(struct btc_coexist *btcoexist,
514 					   u8 byte1, u8 byte2, u8 byte3,
515 					   u8 byte4, u8 byte5)
516 {
517 	struct rtl_priv *rtlpriv = btcoexist->adapter;
518 	u8 h2c_parameter[5] = {0};
519 	u8 real_byte1 = byte1, real_byte5 = byte5;
520 	bool ap_enable = false;
521 
522 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
523 			   &ap_enable);
524 
525 	if (ap_enable) {
526 		if ((byte1 & BIT4) && !(byte1 & BIT5)) {
527 			RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
528 				 "[BTCoex], FW for 1Ant AP mode\n");
529 			real_byte1 &= ~BIT4;
530 			real_byte1 |= BIT5;
531 
532 			real_byte5 |= BIT5;
533 			real_byte5 &= ~BIT6;
534 		}
535 	}
536 
537 	h2c_parameter[0] = real_byte1;
538 	h2c_parameter[1] = byte2;
539 	h2c_parameter[2] = byte3;
540 	h2c_parameter[3] = byte4;
541 	h2c_parameter[4] = real_byte5;
542 
543 	coex_dm->ps_tdma_para[0] = real_byte1;
544 	coex_dm->ps_tdma_para[1] = byte2;
545 	coex_dm->ps_tdma_para[2] = byte3;
546 	coex_dm->ps_tdma_para[3] = byte4;
547 	coex_dm->ps_tdma_para[4] = real_byte5;
548 
549 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
550 		 "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
551 		    h2c_parameter[0],
552 		    h2c_parameter[1] << 24 |
553 		    h2c_parameter[2] << 16 |
554 		    h2c_parameter[3] << 8 |
555 		    h2c_parameter[4]);
556 
557 	btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
558 }
559 
560 static void halbtc8723b1ant_set_lps_rpwm(struct btc_coexist *btcoexist,
561 					 u8 lps_val, u8 rpwm_val)
562 {
563 	u8 lps = lps_val;
564 	u8 rpwm = rpwm_val;
565 
566 	btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
567 	btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
568 }
569 
570 static void halbtc8723b1ant_lps_rpwm(struct btc_coexist *btcoexist,
571 				     bool force_exec,
572 				     u8 lps_val, u8 rpwm_val)
573 {
574 	struct rtl_priv *rtlpriv = btcoexist->adapter;
575 
576 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
577 		 "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n",
578 		 (force_exec ? "force to" : ""), lps_val, rpwm_val);
579 	coex_dm->cur_lps = lps_val;
580 	coex_dm->cur_rpwm = rpwm_val;
581 
582 	if (!force_exec) {
583 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
584 			 "[BTCoex], LPS-RxBeaconMode = 0x%x , LPS-RPWM = 0x%x!!\n",
585 			 coex_dm->cur_lps, coex_dm->cur_rpwm);
586 
587 		if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
588 		    (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) {
589 			RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
590 				 "[BTCoex], LPS-RPWM_Last = 0x%x , LPS-RPWM_Now = 0x%x!!\n",
591 				 coex_dm->pre_rpwm, coex_dm->cur_rpwm);
592 
593 			return;
594 		}
595 	}
596 	halbtc8723b1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
597 
598 	coex_dm->pre_lps = coex_dm->cur_lps;
599 	coex_dm->pre_rpwm = coex_dm->cur_rpwm;
600 }
601 
602 static void halbtc8723b1ant_sw_mechanism(struct btc_coexist *btcoexist,
603 					 bool low_penalty_ra)
604 {
605 	struct rtl_priv *rtlpriv = btcoexist->adapter;
606 
607 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
608 		 "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra);
609 
610 	halbtc8723b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
611 }
612 
613 static void halbtc8723b1ant_set_ant_path(struct btc_coexist *btcoexist,
614 					 u8 ant_pos_type, bool init_hw_cfg,
615 					 bool wifi_off)
616 {
617 	struct btc_board_info *board_info = &btcoexist->board_info;
618 	u32 fw_ver = 0, u32tmp = 0;
619 	bool pg_ext_switch = false;
620 	bool use_ext_switch = false;
621 	u8 h2c_parameter[2] = {0};
622 
623 	btcoexist->btc_get(btcoexist, BTC_GET_BL_EXT_SWITCH, &pg_ext_switch);
624 	/* [31:16] = fw ver, [15:0] = fw sub ver */
625 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
626 
627 	if ((fw_ver < 0xc0000) || pg_ext_switch)
628 		use_ext_switch = true;
629 
630 	if (init_hw_cfg) {
631 		/*BT select s0/s1 is controlled by WiFi */
632 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x1);
633 
634 		/*Force GNT_BT to Normal */
635 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x0);
636 	} else if (wifi_off) {
637 		/*Force GNT_BT to High */
638 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
639 		/*BT select s0/s1 is controlled by BT */
640 		btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x0);
641 
642 		/* 0x4c[24:23] = 00, Set Antenna control by BT_RFE_CTRL
643 		 * BT Vendor 0xac = 0xf002
644 		 */
645 		u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
646 		u32tmp &= ~BIT23;
647 		u32tmp &= ~BIT24;
648 		btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
649 	}
650 
651 	if (use_ext_switch) {
652 		if (init_hw_cfg) {
653 			/* 0x4c[23] = 0, 0x4c[24] = 1
654 			 * Antenna control by WL/BT
655 			 */
656 			u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
657 			u32tmp &= ~BIT23;
658 			u32tmp |= BIT24;
659 			btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
660 
661 			if (board_info->btdm_ant_pos ==
662 			    BTC_ANTENNA_AT_MAIN_PORT) {
663 				/* Main Ant to BT for IPS case 0x4c[23] = 1 */
664 				btcoexist->btc_write_1byte_bitmask(btcoexist,
665 								   0x64, 0x1,
666 								   0x1);
667 
668 				/* tell firmware "no antenna inverse" */
669 				h2c_parameter[0] = 0;
670 				h2c_parameter[1] = 1;  /*ext switch type*/
671 				btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
672 							h2c_parameter);
673 			} else {
674 				/* Aux Ant to  BT for IPS case 0x4c[23] = 1 */
675 				btcoexist->btc_write_1byte_bitmask(btcoexist,
676 								   0x64, 0x1,
677 								   0x0);
678 
679 				/* tell firmware "antenna inverse" */
680 				h2c_parameter[0] = 1;
681 				h2c_parameter[1] = 1; /* ext switch type */
682 				btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
683 							h2c_parameter);
684 			}
685 		}
686 
687 		/* fixed internal switch first
688 		 * fixed internal switch S1->WiFi, S0->BT
689 		 */
690 		if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT)
691 			btcoexist->btc_write_2byte(btcoexist, 0x948, 0x0);
692 		else	/* fixed internal switch S0->WiFi, S1->BT */
693 			btcoexist->btc_write_2byte(btcoexist, 0x948, 0x280);
694 
695 		/* ext switch setting */
696 		switch (ant_pos_type) {
697 		case BTC_ANT_PATH_WIFI:
698 			if (board_info->btdm_ant_pos ==
699 			    BTC_ANTENNA_AT_MAIN_PORT)
700 				btcoexist->btc_write_1byte_bitmask(btcoexist,
701 								   0x92c, 0x3,
702 								   0x1);
703 			else
704 				btcoexist->btc_write_1byte_bitmask(btcoexist,
705 								   0x92c, 0x3,
706 								   0x2);
707 			break;
708 		case BTC_ANT_PATH_BT:
709 			if (board_info->btdm_ant_pos ==
710 			    BTC_ANTENNA_AT_MAIN_PORT)
711 				btcoexist->btc_write_1byte_bitmask(btcoexist,
712 								   0x92c, 0x3,
713 								   0x2);
714 			else
715 				btcoexist->btc_write_1byte_bitmask(btcoexist,
716 								   0x92c, 0x3,
717 								   0x1);
718 			break;
719 		default:
720 		case BTC_ANT_PATH_PTA:
721 			if (board_info->btdm_ant_pos ==
722 			    BTC_ANTENNA_AT_MAIN_PORT)
723 				btcoexist->btc_write_1byte_bitmask(btcoexist,
724 								   0x92c, 0x3,
725 								   0x1);
726 			else
727 				btcoexist->btc_write_1byte_bitmask(btcoexist,
728 								   0x92c, 0x3,
729 								   0x2);
730 			break;
731 		}
732 
733 	} else {
734 		if (init_hw_cfg) {
735 			/* 0x4c[23] = 1, 0x4c[24] = 0 Antenna control by 0x64 */
736 			u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
737 			u32tmp |= BIT23;
738 			u32tmp &= ~BIT24;
739 			btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
740 
741 			if (board_info->btdm_ant_pos ==
742 			    BTC_ANTENNA_AT_MAIN_PORT) {
743 				/* Main Ant to WiFi for IPS case 0x4c[23] = 1 */
744 				btcoexist->btc_write_1byte_bitmask(btcoexist,
745 								   0x64, 0x1,
746 								   0x0);
747 
748 				/* tell firmware "no antenna inverse" */
749 				h2c_parameter[0] = 0;
750 				h2c_parameter[1] = 0; /* internal switch type */
751 				btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
752 							h2c_parameter);
753 			} else {
754 				/* Aux Ant to BT for IPS case 0x4c[23] = 1 */
755 				btcoexist->btc_write_1byte_bitmask(btcoexist,
756 								   0x64, 0x1,
757 								   0x1);
758 
759 				/* tell firmware "antenna inverse" */
760 				h2c_parameter[0] = 1;
761 				h2c_parameter[1] = 0; /* internal switch type */
762 				btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
763 							h2c_parameter);
764 			}
765 		}
766 
767 		/* fixed external switch first
768 		 * Main->WiFi, Aux->BT
769 		 */
770 		if (board_info->btdm_ant_pos ==
771 			BTC_ANTENNA_AT_MAIN_PORT)
772 			btcoexist->btc_write_1byte_bitmask(btcoexist, 0x92c,
773 							   0x3, 0x1);
774 		else	/* Main->BT, Aux->WiFi */
775 			btcoexist->btc_write_1byte_bitmask(btcoexist, 0x92c,
776 							   0x3, 0x2);
777 
778 		/* internal switch setting */
779 		switch (ant_pos_type) {
780 		case BTC_ANT_PATH_WIFI:
781 			if (board_info->btdm_ant_pos ==
782 				BTC_ANTENNA_AT_MAIN_PORT)
783 				btcoexist->btc_write_2byte(btcoexist, 0x948,
784 							   0x0);
785 			else
786 				btcoexist->btc_write_2byte(btcoexist, 0x948,
787 							   0x280);
788 			break;
789 		case BTC_ANT_PATH_BT:
790 			if (board_info->btdm_ant_pos ==
791 				BTC_ANTENNA_AT_MAIN_PORT)
792 				btcoexist->btc_write_2byte(btcoexist, 0x948,
793 							   0x280);
794 			else
795 				btcoexist->btc_write_2byte(btcoexist, 0x948,
796 							   0x0);
797 			break;
798 		default:
799 		case BTC_ANT_PATH_PTA:
800 			if (board_info->btdm_ant_pos ==
801 				BTC_ANTENNA_AT_MAIN_PORT)
802 				btcoexist->btc_write_2byte(btcoexist, 0x948,
803 							   0x200);
804 			else
805 				btcoexist->btc_write_2byte(btcoexist, 0x948,
806 							   0x80);
807 			break;
808 		}
809 	}
810 }
811 
812 static void halbtc8723b1ant_ps_tdma(struct btc_coexist *btcoexist,
813 				    bool force_exec, bool turn_on, u8 type)
814 {
815 	struct rtl_priv *rtlpriv = btcoexist->adapter;
816 	bool wifi_busy = false;
817 	u8 rssi_adjust_val = 0;
818 
819 	coex_dm->cur_ps_tdma_on = turn_on;
820 	coex_dm->cur_ps_tdma = type;
821 
822 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
823 
824 	if (!force_exec) {
825 		if (coex_dm->cur_ps_tdma_on)
826 			RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
827 				 "[BTCoex], ******** TDMA(on, %d) *********\n",
828 				 coex_dm->cur_ps_tdma);
829 		else
830 			RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
831 				 "[BTCoex], ******** TDMA(off, %d) ********\n",
832 				 coex_dm->cur_ps_tdma);
833 
834 		if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
835 		    (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
836 			return;
837 	}
838 	if (turn_on) {
839 		switch (type) {
840 		default:
841 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1a,
842 						       0x1a, 0x0, 0x50);
843 			break;
844 		case 1:
845 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x3a,
846 						       0x03, 0x10, 0x50);
847 
848 			rssi_adjust_val = 11;
849 			break;
850 		case 2:
851 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x2b,
852 						       0x03, 0x10, 0x50);
853 			rssi_adjust_val = 14;
854 			break;
855 		case 3:
856 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1d,
857 						       0x1d, 0x0, 0x52);
858 			break;
859 		case 4:
860 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15,
861 						       0x3, 0x14, 0x0);
862 			rssi_adjust_val = 17;
863 			break;
864 		case 5:
865 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x15,
866 						       0x3, 0x11, 0x10);
867 			break;
868 		case 6:
869 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x20,
870 						       0x3, 0x11, 0x13);
871 			break;
872 		case 7:
873 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xc,
874 						       0x5, 0x0, 0x0);
875 			break;
876 		case 8:
877 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25,
878 						       0x3, 0x10, 0x0);
879 			break;
880 		case 9:
881 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51,  0x21,
882 						       0x3, 0x10, 0x50);
883 			rssi_adjust_val = 18;
884 			break;
885 		case 10:
886 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa,
887 						       0xa, 0x0, 0x40);
888 			break;
889 		case 11:
890 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x15,
891 						       0x03, 0x10, 0x50);
892 			rssi_adjust_val = 20;
893 			break;
894 		case 12:
895 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x0a,
896 						       0x0a, 0x0, 0x50);
897 			break;
898 		case 13:
899 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x15,
900 						       0x15, 0x0, 0x50);
901 			break;
902 		case 14:
903 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x21,
904 						       0x3, 0x10, 0x52);
905 			break;
906 		case 15:
907 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa,
908 						       0x3, 0x8, 0x0);
909 			break;
910 		case 16:
911 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15,
912 						       0x3, 0x10, 0x0);
913 			rssi_adjust_val = 18;
914 			break;
915 		case 18:
916 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25,
917 						       0x3, 0x10, 0x0);
918 			rssi_adjust_val = 14;
919 			break;
920 		case 20:
921 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x35,
922 						       0x03, 0x11, 0x10);
923 			break;
924 		case 21:
925 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x25,
926 						       0x03, 0x11, 0x11);
927 			break;
928 		case 22:
929 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x25,
930 						       0x03, 0x11, 0x10);
931 			break;
932 		case 23:
933 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
934 						       0x3, 0x31, 0x18);
935 			rssi_adjust_val = 22;
936 			break;
937 		case 24:
938 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15,
939 						       0x3, 0x31, 0x18);
940 			rssi_adjust_val = 22;
941 			break;
942 		case 25:
943 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
944 						       0x3, 0x31, 0x18);
945 			rssi_adjust_val = 22;
946 			break;
947 		case 26:
948 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
949 						       0x3, 0x31, 0x18);
950 			rssi_adjust_val = 22;
951 			break;
952 		case 27:
953 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
954 						       0x3, 0x31, 0x98);
955 			rssi_adjust_val = 22;
956 			break;
957 		case 28:
958 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x69, 0x25,
959 						       0x3, 0x31, 0x0);
960 			break;
961 		case 29:
962 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xab, 0x1a,
963 						       0x1a, 0x1, 0x10);
964 			break;
965 		case 30:
966 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x14,
967 						       0x3, 0x10, 0x50);
968 			break;
969 		case 31:
970 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x1a,
971 						       0x1a, 0, 0x58);
972 			break;
973 		case 32:
974 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0xa,
975 						       0x3, 0x10, 0x0);
976 			break;
977 		case 33:
978 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x25,
979 						       0x3, 0x30, 0x90);
980 			break;
981 		case 34:
982 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x53, 0x1a,
983 						       0x1a, 0x0, 0x10);
984 			break;
985 		case 35:
986 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x63, 0x1a,
987 						       0x1a, 0x0, 0x10);
988 			break;
989 		case 36:
990 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x12,
991 						       0x3, 0x14, 0x50);
992 			break;
993 		/* SoftAP only with no sta associated, BT disable,
994 		 * TDMA mode for power saving
995 		 * here softap mode screen off will cost 70-80mA for phone
996 		 */
997 		case 40:
998 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x23, 0x18,
999 						       0x00, 0x10, 0x24);
1000 			break;
1001 		}
1002 	} else {
1003 		switch (type) {
1004 		case 8: /* PTA Control */
1005 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x8, 0x0,
1006 						       0x0, 0x0, 0x0);
1007 			halbtc8723b1ant_set_ant_path(btcoexist,
1008 						     BTC_ANT_PATH_PTA,
1009 						     false, false);
1010 			break;
1011 		case 0:
1012 		default:
1013 			/* Software control, Antenna at BT side */
1014 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0,
1015 						       0x0, 0x0, 0x0);
1016 			halbtc8723b1ant_set_ant_path(btcoexist,
1017 						     BTC_ANT_PATH_BT,
1018 						     false, false);
1019 			break;
1020 		case 9:
1021 			/* Software control, Antenna at WiFi side */
1022 			halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0,
1023 						       0x0, 0x0, 0x0);
1024 			halbtc8723b1ant_set_ant_path(btcoexist,
1025 						     BTC_ANT_PATH_WIFI,
1026 						     false, false);
1027 			break;
1028 		}
1029 	}
1030 	rssi_adjust_val = 0;
1031 	btcoexist->btc_set(btcoexist,
1032 			   BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE,
1033 			   &rssi_adjust_val);
1034 
1035 	/* update pre state */
1036 	coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1037 	coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1038 }
1039 
1040 static void halbtc8723b1ant_ps_tdma_chk_pwr_save(struct btc_coexist *btcoexist,
1041 						 bool new_ps_state)
1042 {
1043 	u8 lps_mode = 0x0;
1044 
1045 	btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1046 
1047 	if (lps_mode) {
1048 		/* already under LPS state */
1049 		if (new_ps_state) {
1050 			/* keep state under LPS, do nothing. */
1051 		} else {
1052 			/* will leave LPS state, turn off psTdma first */
1053 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1054 						false, 0);
1055 		}
1056 	} else {
1057 		/* NO PS state */
1058 		if (new_ps_state) {
1059 			/* will enter LPS state, turn off psTdma first */
1060 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1061 						false, 0);
1062 		} else {
1063 			/* keep state under NO PS state, do nothing. */
1064 		}
1065 	}
1066 }
1067 
1068 static void halbtc8723b1ant_power_save_state(struct btc_coexist *btcoexist,
1069 					     u8 ps_type, u8 lps_val,
1070 					     u8 rpwm_val)
1071 {
1072 	bool low_pwr_disable = false;
1073 
1074 	switch (ps_type) {
1075 	case BTC_PS_WIFI_NATIVE:
1076 		/* recover to original 32k low power setting */
1077 		low_pwr_disable = false;
1078 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1079 				   &low_pwr_disable);
1080 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1081 		break;
1082 	case BTC_PS_LPS_ON:
1083 		halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist, true);
1084 		halbtc8723b1ant_lps_rpwm(btcoexist, NORMAL_EXEC, lps_val,
1085 					 rpwm_val);
1086 		/* when coex force to enter LPS, do not enter 32k low power */
1087 		low_pwr_disable = true;
1088 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1089 				   &low_pwr_disable);
1090 		/* power save must executed before psTdma */
1091 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1092 		break;
1093 	case BTC_PS_LPS_OFF:
1094 		halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist, false);
1095 		btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
1096 		break;
1097 	default:
1098 		break;
1099 	}
1100 }
1101 
1102 /*****************************************************
1103  *
1104  *	Non-Software Coex Mechanism start
1105  *
1106  *****************************************************/
1107 static void halbtc8723b1ant_action_wifi_multiport(struct btc_coexist *btcoexist)
1108 {
1109 	halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1110 					 0x0, 0x0);
1111 
1112 	halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1113 	halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1114 }
1115 
1116 static void halbtc8723b1ant_action_hs(struct btc_coexist *btcoexist)
1117 {
1118 	halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1119 	halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1120 }
1121 
1122 static void halbtc8723b1ant_action_bt_inquiry(struct btc_coexist *btcoexist)
1123 {
1124 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1125 	bool wifi_connected = false, ap_enable = false;
1126 
1127 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1128 			   &ap_enable);
1129 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1130 			   &wifi_connected);
1131 
1132 	if (!wifi_connected) {
1133 		halbtc8723b1ant_power_save_state(btcoexist,
1134 						 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1135 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1136 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1137 	} else if (bt_link_info->sco_exist || bt_link_info->hid_only) {
1138 		/* SCO/HID-only busy */
1139 		halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1140 						 0x0, 0x0);
1141 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1142 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1143 	} else {
1144 		if (ap_enable)
1145 			halbtc8723b1ant_power_save_state(btcoexist,
1146 							 BTC_PS_WIFI_NATIVE,
1147 							 0x0, 0x0);
1148 		else
1149 			halbtc8723b1ant_power_save_state(btcoexist,
1150 							 BTC_PS_LPS_ON,
1151 							 0x50, 0x4);
1152 
1153 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 30);
1154 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1155 	}
1156 }
1157 
1158 static void btc8723b1ant_act_bt_sco_hid_only_busy(struct btc_coexist *btcoexist,
1159 						  u8 wifi_status)
1160 {
1161 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1162 	bool wifi_connected = false;
1163 
1164 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1165 			   &wifi_connected);
1166 
1167 	/* tdma and coex table */
1168 	if (bt_link_info->sco_exist) {
1169 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1170 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1171 	} else {
1172 		/* HID */
1173 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
1174 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
1175 	}
1176 }
1177 
1178 static void halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
1179 					struct btc_coexist *btcoexist,
1180 					u8 wifi_status)
1181 {
1182 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1183 
1184 
1185 	if (bt_link_info->hid_only) { /* HID */
1186 		btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist, wifi_status);
1187 		coex_dm->auto_tdma_adjust = false;
1188 		return;
1189 	} else if (bt_link_info->a2dp_only) { /* A2DP */
1190 		if (wifi_status == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE) {
1191 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1192 						false, 8);
1193 			halbtc8723b1ant_coex_table_with_type(btcoexist,
1194 							     NORMAL_EXEC, 2);
1195 			coex_dm->auto_tdma_adjust = false;
1196 		} else { /* for low BT RSSI */
1197 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1198 						true, 11);
1199 			halbtc8723b1ant_coex_table_with_type(btcoexist,
1200 							     NORMAL_EXEC, 1);
1201 			coex_dm->auto_tdma_adjust = false;
1202 		}
1203 	} else if (bt_link_info->hid_exist &&
1204 		bt_link_info->a2dp_exist) { /* HID + A2DP */
1205 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,	true, 14);
1206 		coex_dm->auto_tdma_adjust = false;
1207 
1208 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
1209 	 /* PAN(OPP,FTP), HID + PAN(OPP,FTP) */
1210 	} else if (bt_link_info->pan_only ||
1211 		   (bt_link_info->hid_exist && bt_link_info->pan_exist)) {
1212 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1213 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
1214 		coex_dm->auto_tdma_adjust = false;
1215 	 /* A2DP + PAN(OPP,FTP), HID + A2DP + PAN(OPP,FTP) */
1216 	} else if ((bt_link_info->a2dp_exist && bt_link_info->pan_exist) ||
1217 		   (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
1218 		    bt_link_info->pan_exist)) {
1219 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
1220 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1221 		coex_dm->auto_tdma_adjust = false;
1222 	} else {
1223 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1224 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1225 		coex_dm->auto_tdma_adjust = false;
1226 	}
1227 }
1228 
1229 static void btc8723b1ant_action_wifi_not_conn(struct btc_coexist *btcoexist)
1230 {
1231 	/* power save state */
1232 	halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1233 					 0x0, 0x0);
1234 
1235 	/* tdma and coex table */
1236 	halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1237 	halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1238 }
1239 
1240 static void
1241 btc8723b1ant_action_wifi_not_conn_scan(struct btc_coexist *btcoexist)
1242 {
1243 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1244 
1245 	halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1246 					 0x0, 0x0);
1247 
1248 	/* tdma and coex table */
1249 	if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1250 		if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
1251 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1252 						true, 22);
1253 			halbtc8723b1ant_coex_table_with_type(btcoexist,
1254 							     NORMAL_EXEC, 1);
1255 		} else if (bt_link_info->pan_only) {
1256 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1257 						true, 20);
1258 			halbtc8723b1ant_coex_table_with_type(btcoexist,
1259 							     NORMAL_EXEC, 2);
1260 		} else {
1261 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1262 						true, 20);
1263 			halbtc8723b1ant_coex_table_with_type(btcoexist,
1264 							     NORMAL_EXEC, 1);
1265 		}
1266 	} else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1267 		   (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1268 		    coex_dm->bt_status)){
1269 		btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
1270 				BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1271 	} else {
1272 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1273 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1274 	}
1275 }
1276 
1277 static void
1278 btc8723b1ant_act_wifi_not_conn_asso_auth(struct btc_coexist *btcoexist)
1279 {
1280 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1281 
1282 	halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1283 					 0x0, 0x0);
1284 
1285 	if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) ||
1286 	    (bt_link_info->sco_exist) || (bt_link_info->hid_only) ||
1287 	    (bt_link_info->a2dp_only) || (bt_link_info->pan_only)) {
1288 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1289 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1290 	} else {
1291 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1292 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1293 	}
1294 }
1295 
1296 static void btc8723b1ant_action_wifi_conn_scan(struct btc_coexist *btcoexist)
1297 {
1298 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1299 
1300 	halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1301 					 0x0, 0x0);
1302 
1303 	/* tdma and coex table */
1304 	if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1305 		if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
1306 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1307 						true, 22);
1308 			halbtc8723b1ant_coex_table_with_type(btcoexist,
1309 							     NORMAL_EXEC, 1);
1310 		} else if (bt_link_info->pan_only) {
1311 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1312 						true, 20);
1313 			halbtc8723b1ant_coex_table_with_type(btcoexist,
1314 							     NORMAL_EXEC, 2);
1315 		} else {
1316 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1317 						true, 20);
1318 			halbtc8723b1ant_coex_table_with_type(btcoexist,
1319 							     NORMAL_EXEC, 1);
1320 		}
1321 	} else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1322 		   (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1323 		    coex_dm->bt_status)) {
1324 		btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
1325 				BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1326 	} else {
1327 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1328 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1329 	}
1330 }
1331 
1332 static void halbtc8723b1ant_action_wifi_connected_special_packet(
1333 						struct btc_coexist *btcoexist)
1334 {
1335 	bool hs_connecting = false;
1336 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1337 
1338 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_CONNECTING, &hs_connecting);
1339 
1340 	halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1341 					 0x0, 0x0);
1342 
1343 	/* tdma and coex table */
1344 	if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) ||
1345 	    (bt_link_info->sco_exist) || (bt_link_info->hid_only) ||
1346 	    (bt_link_info->a2dp_only) || (bt_link_info->pan_only)) {
1347 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1348 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1349 	} else {
1350 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1351 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1352 	}
1353 }
1354 
1355 static void halbtc8723b1ant_action_wifi_connected(struct btc_coexist *btcoexist)
1356 {
1357 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1358 	bool wifi_busy = false;
1359 	bool scan = false, link = false, roam = false;
1360 	bool under_4way = false, ap_enable = false;
1361 
1362 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1363 		 "[BTCoex], CoexForWifiConnect()===>\n");
1364 
1365 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
1366 			   &under_4way);
1367 	if (under_4way) {
1368 		halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist);
1369 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1370 			 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
1371 		return;
1372 	}
1373 
1374 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1375 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1376 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1377 
1378 	if (scan || link || roam) {
1379 		if (scan)
1380 			btc8723b1ant_action_wifi_conn_scan(btcoexist);
1381 		else
1382 			halbtc8723b1ant_action_wifi_connected_special_packet(
1383 								     btcoexist);
1384 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1385 			 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
1386 		return;
1387 	}
1388 
1389 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1390 			   &ap_enable);
1391 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1392 	/* power save state */
1393 	if (!ap_enable &&
1394 	    BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status &&
1395 	    !btcoexist->bt_link_info.hid_only) {
1396 		if (!wifi_busy && btcoexist->bt_link_info.a2dp_only)
1397 			halbtc8723b1ant_power_save_state(btcoexist,
1398 							 BTC_PS_WIFI_NATIVE,
1399 							 0x0, 0x0);
1400 		else
1401 			halbtc8723b1ant_power_save_state(btcoexist,
1402 							 BTC_PS_LPS_ON,
1403 							 0x50, 0x4);
1404 	} else {
1405 		halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1406 						 0x0, 0x0);
1407 	}
1408 	/* tdma and coex table */
1409 	if (!wifi_busy) {
1410 		if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1411 			halbtc8723b1ant_action_wifi_connected_bt_acl_busy(btcoexist,
1412 				      BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1413 		} else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY ==
1414 						coex_dm->bt_status) ||
1415 			   (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1416 						coex_dm->bt_status)) {
1417 			btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
1418 				     BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1419 		} else {
1420 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1421 						false, 8);
1422 			halbtc8723b1ant_coex_table_with_type(btcoexist,
1423 							     NORMAL_EXEC, 2);
1424 		}
1425 	} else {
1426 		if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1427 			halbtc8723b1ant_action_wifi_connected_bt_acl_busy(btcoexist,
1428 				    BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
1429 		} else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY ==
1430 			   coex_dm->bt_status) ||
1431 			   (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1432 			    coex_dm->bt_status)) {
1433 			btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
1434 				    BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
1435 		} else {
1436 			halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1437 						false, 8);
1438 			halbtc8723b1ant_coex_table_with_type(btcoexist,
1439 							     NORMAL_EXEC, 2);
1440 		}
1441 	}
1442 }
1443 
1444 static void halbtc8723b1ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
1445 {
1446 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1447 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1448 	bool wifi_connected = false, bt_hs_on = false;
1449 	bool increase_scan_dev_num = false;
1450 	bool bt_ctrl_agg_buf_size = false;
1451 	u8 agg_buf_size = 5;
1452 	u32 wifi_link_status = 0;
1453 	u32 num_of_wifi_link = 0;
1454 
1455 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1456 		 "[BTCoex], RunCoexistMechanism()===>\n");
1457 
1458 	if (btcoexist->manual_control) {
1459 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1460 			 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
1461 		return;
1462 	}
1463 
1464 	if (btcoexist->stop_coex_dm) {
1465 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1466 			 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
1467 		return;
1468 	}
1469 
1470 	if (coex_sta->under_ips) {
1471 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1472 			 "[BTCoex], wifi is under IPS !!!\n");
1473 		return;
1474 	}
1475 
1476 	if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
1477 	    (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1478 	    (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) {
1479 		increase_scan_dev_num = true;
1480 	}
1481 
1482 	btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
1483 			   &increase_scan_dev_num);
1484 
1485 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1486 			   &wifi_connected);
1487 
1488 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
1489 			   &wifi_link_status);
1490 	num_of_wifi_link = wifi_link_status >> 16;
1491 	if (num_of_wifi_link >= 2) {
1492 		halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
1493 		halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
1494 					   bt_ctrl_agg_buf_size,
1495 					   agg_buf_size);
1496 		halbtc8723b1ant_action_wifi_multiport(btcoexist);
1497 		return;
1498 	}
1499 
1500 	if (!bt_link_info->sco_exist && !bt_link_info->hid_exist) {
1501 		halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
1502 	} else {
1503 		if (wifi_connected)
1504 			halbtc8723b1ant_limited_tx(btcoexist,
1505 						   NORMAL_EXEC, 1, 1, 1, 1);
1506 		else
1507 			halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC,
1508 						   0, 0, 0, 0);
1509 	}
1510 
1511 	if (bt_link_info->sco_exist) {
1512 		bt_ctrl_agg_buf_size = true;
1513 		agg_buf_size = 0x3;
1514 	} else if (bt_link_info->hid_exist) {
1515 		bt_ctrl_agg_buf_size = true;
1516 		agg_buf_size = 0x5;
1517 	} else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) {
1518 		bt_ctrl_agg_buf_size = true;
1519 		agg_buf_size = 0x8;
1520 	}
1521 	halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
1522 				   bt_ctrl_agg_buf_size, agg_buf_size);
1523 
1524 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
1525 
1526 	if (coex_sta->c2h_bt_inquiry_page) {
1527 		halbtc8723b1ant_action_bt_inquiry(btcoexist);
1528 		return;
1529 	} else if (bt_hs_on) {
1530 		halbtc8723b1ant_action_hs(btcoexist);
1531 		return;
1532 	}
1533 
1534 	if (!wifi_connected) {
1535 		bool scan = false, link = false, roam = false;
1536 
1537 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1538 			 "[BTCoex], wifi is non connected-idle !!!\n");
1539 
1540 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1541 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1542 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1543 
1544 		if (scan || link || roam) {
1545 			if (scan)
1546 				btc8723b1ant_action_wifi_not_conn_scan(
1547 								     btcoexist);
1548 			else
1549 				btc8723b1ant_act_wifi_not_conn_asso_auth(
1550 								     btcoexist);
1551 		} else {
1552 			btc8723b1ant_action_wifi_not_conn(btcoexist);
1553 		}
1554 	} else { /* wifi LPS/Busy */
1555 		halbtc8723b1ant_action_wifi_connected(btcoexist);
1556 	}
1557 }
1558 
1559 static void halbtc8723b1ant_init_coex_dm(struct btc_coexist *btcoexist)
1560 {
1561 	/* sw all off */
1562 	halbtc8723b1ant_sw_mechanism(btcoexist, false);
1563 
1564 	halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
1565 	halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
1566 }
1567 
1568 static void halbtc8723b1ant_init_hw_config(struct btc_coexist *btcoexist,
1569 					   bool backup)
1570 {
1571 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1572 	u32 u32tmp = 0;
1573 	u8 u8tmp = 0;
1574 	u32 cnt_bt_cal_chk = 0;
1575 
1576 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1577 		 "[BTCoex], 1Ant Init HW Config!!\n");
1578 
1579 	if (backup) {/* backup rf 0x1e value */
1580 		coex_dm->backup_arfr_cnt1 =
1581 			btcoexist->btc_read_4byte(btcoexist, 0x430);
1582 		coex_dm->backup_arfr_cnt2 =
1583 			btcoexist->btc_read_4byte(btcoexist, 0x434);
1584 		coex_dm->backup_retry_limit =
1585 			btcoexist->btc_read_2byte(btcoexist, 0x42a);
1586 		coex_dm->backup_ampdu_max_time =
1587 			btcoexist->btc_read_1byte(btcoexist, 0x456);
1588 	}
1589 
1590 	/* WiFi goto standby while GNT_BT 0-->1 */
1591 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
1592 	/* BT goto standby while GNT_BT 1-->0 */
1593 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x2, 0xfffff, 0x500);
1594 
1595 	btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
1596 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0x944, 0x3, 0x3);
1597 	btcoexist->btc_write_1byte(btcoexist, 0x930, 0x77);
1598 
1599 	/* BT calibration check */
1600 	while (cnt_bt_cal_chk <= 20) {
1601 		u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x49d);
1602 		cnt_bt_cal_chk++;
1603 		if (u32tmp & BIT0) {
1604 			RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1605 				 "[BTCoex], ########### BT calibration(cnt=%d) ###########\n",
1606 				      cnt_bt_cal_chk);
1607 			mdelay(50);
1608 		} else {
1609 			RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1610 				 "[BTCoex], ********** BT NOT calibration (cnt=%d)**********\n",
1611 				      cnt_bt_cal_chk);
1612 			break;
1613 		}
1614 	}
1615 
1616 	/* 0x790[5:0] = 0x5 */
1617 	u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
1618 	u8tmp &= 0xc0;
1619 	u8tmp |= 0x5;
1620 	btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
1621 
1622 	/* Enable counter statistics */
1623 	/*0x76e[3] = 1, WLAN_Act control by PTA */
1624 	btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
1625 	btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
1626 	btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
1627 
1628 	/* Antenna config */
1629 	halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, true, false);
1630 	/* PTA parameter */
1631 	halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
1632 }
1633 
1634 /**************************************************************
1635  * extern function start with ex_halbtc8723b1ant_
1636  **************************************************************/
1637 
1638 void ex_halbtc8723b1ant_init_hwconfig(struct btc_coexist *btcoexist)
1639 {
1640 	halbtc8723b1ant_init_hw_config(btcoexist, true);
1641 }
1642 
1643 void ex_halbtc8723b1ant_init_coex_dm(struct btc_coexist *btcoexist)
1644 {
1645 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1646 
1647 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1648 		 "[BTCoex], Coex Mechanism Init!!\n");
1649 
1650 	btcoexist->stop_coex_dm = false;
1651 
1652 	halbtc8723b1ant_init_coex_dm(btcoexist);
1653 
1654 	halbtc8723b1ant_query_bt_info(btcoexist);
1655 }
1656 
1657 void ex_halbtc8723b1ant_display_coex_info(struct btc_coexist *btcoexist)
1658 {
1659 	struct btc_board_info *board_info = &btcoexist->board_info;
1660 	struct btc_stack_info *stack_info = &btcoexist->stack_info;
1661 	struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1662 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1663 	u8 u8tmp[4], i, bt_info_ext, pstdmacase = 0;
1664 	u16 u16tmp[4];
1665 	u32 u32tmp[4];
1666 	bool roam = false, scan = false;
1667 	bool link = false, wifi_under_5g = false;
1668 	bool bt_hs_on = false, wifi_busy = false;
1669 	s32 wifi_rssi = 0, bt_hs_rssi = 0;
1670 	u32 wifi_bw, wifi_traffic_dir, fa_ofdm, fa_cck, wifi_link_status;
1671 	u8 wifi_dot11_chnl, wifi_hs_chnl;
1672 	u32 fw_ver = 0, bt_patch_ver = 0;
1673 
1674 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1675 		 "\r\n ============[BT Coexist info]============");
1676 
1677 	if (btcoexist->manual_control) {
1678 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1679 			 "\r\n ============[Under Manual Control]==========");
1680 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1681 			 "\r\n ==========================================");
1682 	}
1683 	if (btcoexist->stop_coex_dm) {
1684 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1685 			 "\r\n ============[Coex is STOPPED]============");
1686 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1687 			 "\r\n ==========================================");
1688 	}
1689 
1690 	if (!board_info->bt_exist) {
1691 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n BT not exists !!!");
1692 		return;
1693 	}
1694 
1695 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d",
1696 		 "Ant PG Num/ Ant Mech/ Ant Pos:",
1697 		 board_info->pg_ant_num, board_info->btdm_ant_num,
1698 		 board_info->btdm_ant_pos);
1699 
1700 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %d",
1701 		 "BT stack/ hci ext ver",
1702 		 ((stack_info->profile_notified) ? "Yes" : "No"),
1703 		 stack_info->hci_version);
1704 
1705 	btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
1706 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
1707 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1708 		 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
1709 		 "CoexVer/ FwVer/ PatchVer",
1710 		 glcoex_ver_date_8723b_1ant, glcoex_ver_8723b_1ant,
1711 		 fw_ver, bt_patch_ver, bt_patch_ver);
1712 
1713 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
1714 	btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL,
1715 			   &wifi_dot11_chnl);
1716 	btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
1717 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d / %d(%d)",
1718 		 "Dot11 channel / HsChnl(HsMode)",
1719 		 wifi_dot11_chnl, wifi_hs_chnl, bt_hs_on);
1720 
1721 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %3ph ",
1722 		 "H2C Wifi inform bt chnl Info",
1723 		 coex_dm->wifi_chnl_info);
1724 
1725 	btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
1726 	btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
1727 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
1728 		 "Wifi rssi/ HS rssi", wifi_rssi, bt_hs_rssi);
1729 
1730 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1731 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1732 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1733 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d ",
1734 		 "Wifi link/ roam/ scan", link, roam, scan);
1735 
1736 	btcoexist->btc_get(btcoexist , BTC_GET_BL_WIFI_UNDER_5G,
1737 			   &wifi_under_5g);
1738 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
1739 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1740 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
1741 			   &wifi_traffic_dir);
1742 
1743 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %s/ %s ",
1744 		 "Wifi status", (wifi_under_5g ? "5G" : "2.4G"),
1745 		 ((wifi_bw == BTC_WIFI_BW_LEGACY) ? "Legacy" :
1746 		  ((wifi_bw == BTC_WIFI_BW_HT40) ? "HT40" : "HT20")),
1747 		  ((!wifi_busy) ? "idle" :
1748 		   ((wifi_traffic_dir == BTC_WIFI_TRAFFIC_TX) ?
1749 		   "uplink" : "downlink")));
1750 
1751 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
1752 			   &wifi_link_status);
1753 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
1754 		 "sta/vwifi/hs/p2pGo/p2pGc",
1755 		 ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
1756 		 ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
1757 		 ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
1758 		 ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
1759 		 ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
1760 
1761 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = [%s/ %d/ %d] ",
1762 		 "BT [status/ rssi/ retryCnt]",
1763 		 ((btcoexist->bt_info.bt_disabled) ? ("disabled") :
1764 		  ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") :
1765 		   ((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1766 		     coex_dm->bt_status) ?
1767 		    "non-connected idle" :
1768 		    ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE ==
1769 		      coex_dm->bt_status) ?
1770 		     "connected-idle" : "busy")))),
1771 		     coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
1772 
1773 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1774 		 "\r\n %-35s = %d / %d / %d / %d",
1775 		 "SCO/HID/PAN/A2DP", bt_link_info->sco_exist,
1776 		 bt_link_info->hid_exist, bt_link_info->pan_exist,
1777 		 bt_link_info->a2dp_exist);
1778 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
1779 
1780 	bt_info_ext = coex_sta->bt_info_ext;
1781 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s",
1782 		 "BT Info A2DP rate",
1783 		 (bt_info_ext & BIT0) ? "Basic rate" : "EDR rate");
1784 
1785 	for (i = 0; i < BT_INFO_SRC_8723B_1ANT_MAX; i++) {
1786 		if (coex_sta->bt_info_c2h_cnt[i]) {
1787 			RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1788 				 "\r\n %-35s = %7ph(%d)",
1789 				 glbt_info_src_8723b_1ant[i],
1790 				 coex_sta->bt_info_c2h[i],
1791 				 coex_sta->bt_info_c2h_cnt[i]);
1792 		}
1793 	}
1794 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1795 		 "\r\n %-35s = %s/%s, (0x%x/0x%x)",
1796 		 "PS state, IPS/LPS, (lps/rpwm)",
1797 		 ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
1798 		 ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")),
1799 		 btcoexist->bt_info.lps_val,
1800 		 btcoexist->bt_info.rpwm_val);
1801 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
1802 
1803 	if (!btcoexist->manual_control) {
1804 		/* Sw mechanism	*/
1805 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
1806 			 "============[Sw mechanism]============");
1807 
1808 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/",
1809 			 "SM[LowPenaltyRA]", coex_dm->cur_low_penalty_ra);
1810 
1811 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s/ %s/ %d ",
1812 			 "DelBA/ BtCtrlAgg/ AggSize",
1813 			   (btcoexist->bt_info.reject_agg_pkt ? "Yes" : "No"),
1814 			   (btcoexist->bt_info.bt_ctrl_buf_size ? "Yes" : "No"),
1815 			   btcoexist->bt_info.agg_buf_size);
1816 
1817 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ",
1818 			 "Rate Mask", btcoexist->bt_info.ra_mask);
1819 
1820 		/* Fw mechanism	*/
1821 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
1822 			 "============[Fw mechanism]============");
1823 
1824 		pstdmacase = coex_dm->cur_ps_tdma;
1825 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1826 			 "\r\n %-35s = %5ph case-%d (auto:%d)",
1827 			   "PS TDMA", coex_dm->ps_tdma_para,
1828 			   pstdmacase, coex_dm->auto_tdma_adjust);
1829 
1830 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d ",
1831 			 "IgnWlanAct", coex_dm->cur_ignore_wlan_act);
1832 
1833 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ",
1834 			 "Latest error condition(should be 0)",
1835 			   coex_dm->error_condition);
1836 	}
1837 
1838 	/* Hw setting */
1839 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
1840 		 "============[Hw setting]============");
1841 
1842 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
1843 		 "backup ARFR1/ARFR2/RL/AMaxTime", coex_dm->backup_arfr_cnt1,
1844 		   coex_dm->backup_arfr_cnt2, coex_dm->backup_retry_limit,
1845 		   coex_dm->backup_ampdu_max_time);
1846 
1847 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
1848 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
1849 	u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
1850 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
1851 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
1852 		 "0x430/0x434/0x42a/0x456",
1853 		 u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
1854 
1855 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
1856 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
1857 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x880);
1858 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
1859 		 "0x778/0x6cc/0x880[29:25]", u8tmp[0], u32tmp[0],
1860 		 (u32tmp[1] & 0x3e000000) >> 25);
1861 
1862 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x948);
1863 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67);
1864 	u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x765);
1865 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
1866 		 "0x948/ 0x67[5] / 0x765",
1867 		 u32tmp[0], ((u8tmp[0] & 0x20) >> 5), u8tmp[1]);
1868 
1869 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x92c);
1870 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x930);
1871 	u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x944);
1872 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
1873 		 "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
1874 		 u32tmp[0] & 0x3, u32tmp[1] & 0xff, u32tmp[2] & 0x3);
1875 
1876 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x39);
1877 	u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
1878 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
1879 	u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
1880 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1881 		 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
1882 		 "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
1883 		 ((u8tmp[0] & 0x8) >> 3), u8tmp[1],
1884 		  ((u32tmp[0] & 0x01800000) >> 23), u8tmp[2] & 0x1);
1885 
1886 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
1887 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
1888 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
1889 		 "0x550(bcn ctrl)/0x522", u32tmp[0], u8tmp[0]);
1890 
1891 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
1892 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c);
1893 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
1894 		 "0xc50(dig)/0x49c(null-drop)", u32tmp[0] & 0xff, u8tmp[0]);
1895 
1896 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0);
1897 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4);
1898 	u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8);
1899 	u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0);
1900 
1901 	u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
1902 	u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
1903 
1904 	fa_ofdm = ((u32tmp[0] & 0xffff0000) >> 16) +
1905 		  ((u32tmp[1] & 0xffff0000) >> 16) +
1906 		   (u32tmp[1] & 0xffff) +
1907 		   (u32tmp[2] & 0xffff) +
1908 		  ((u32tmp[3] & 0xffff0000) >> 16) +
1909 		   (u32tmp[3] & 0xffff);
1910 	fa_cck = (u8tmp[0] << 8) + u8tmp[1];
1911 
1912 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
1913 		 "OFDM-CCA/OFDM-FA/CCK-FA",
1914 		 u32tmp[0] & 0xffff, fa_ofdm, fa_cck);
1915 
1916 	u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
1917 	u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
1918 	u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
1919 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
1920 		 "0x6c0/0x6c4/0x6c8(coexTable)",
1921 		 u32tmp[0], u32tmp[1], u32tmp[2]);
1922 
1923 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
1924 		 "0x770(high-pri rx/tx)", coex_sta->high_priority_rx,
1925 		 coex_sta->high_priority_tx);
1926 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
1927 		 "0x774(low-pri rx/tx)", coex_sta->low_priority_rx,
1928 		 coex_sta->low_priority_tx);
1929 #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 1)
1930 	halbtc8723b1ant_monitor_bt_ctr(btcoexist);
1931 #endif
1932 	btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
1933 }
1934 
1935 void ex_halbtc8723b1ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
1936 {
1937 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1938 
1939 	if (btcoexist->manual_control || btcoexist->stop_coex_dm)
1940 		return;
1941 
1942 	if (BTC_IPS_ENTER == type) {
1943 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1944 			 "[BTCoex], IPS ENTER notify\n");
1945 		coex_sta->under_ips = true;
1946 
1947 		halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
1948 					     false, true);
1949 		/* set PTA control */
1950 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
1951 		halbtc8723b1ant_coex_table_with_type(btcoexist,
1952 						     NORMAL_EXEC, 0);
1953 	} else if (BTC_IPS_LEAVE == type) {
1954 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1955 			 "[BTCoex], IPS LEAVE notify\n");
1956 		coex_sta->under_ips = false;
1957 
1958 		halbtc8723b1ant_init_hw_config(btcoexist, false);
1959 		halbtc8723b1ant_init_coex_dm(btcoexist);
1960 		halbtc8723b1ant_query_bt_info(btcoexist);
1961 	}
1962 }
1963 
1964 void ex_halbtc8723b1ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
1965 {
1966 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1967 
1968 	if (btcoexist->manual_control || btcoexist->stop_coex_dm)
1969 		return;
1970 
1971 	if (BTC_LPS_ENABLE == type) {
1972 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1973 			 "[BTCoex], LPS ENABLE notify\n");
1974 		coex_sta->under_lps = true;
1975 	} else if (BTC_LPS_DISABLE == type) {
1976 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1977 			 "[BTCoex], LPS DISABLE notify\n");
1978 		coex_sta->under_lps = false;
1979 	}
1980 }
1981 
1982 void ex_halbtc8723b1ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
1983 {
1984 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1985 	bool wifi_connected = false, bt_hs_on = false;
1986 	u32 wifi_link_status = 0;
1987 	u32 num_of_wifi_link = 0;
1988 	bool bt_ctrl_agg_buf_size = false;
1989 	u8 agg_buf_size = 5;
1990 
1991 	if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
1992 	    btcoexist->bt_info.bt_disabled)
1993 		return;
1994 
1995 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
1996 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1997 			   &wifi_connected);
1998 
1999 	halbtc8723b1ant_query_bt_info(btcoexist);
2000 
2001 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2002 			   &wifi_link_status);
2003 	num_of_wifi_link = wifi_link_status >> 16;
2004 	if (num_of_wifi_link >= 2) {
2005 		halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2006 		halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2007 					   bt_ctrl_agg_buf_size, agg_buf_size);
2008 		halbtc8723b1ant_action_wifi_multiport(btcoexist);
2009 		return;
2010 	}
2011 
2012 	if (coex_sta->c2h_bt_inquiry_page) {
2013 		halbtc8723b1ant_action_bt_inquiry(btcoexist);
2014 		return;
2015 	} else if (bt_hs_on) {
2016 		halbtc8723b1ant_action_hs(btcoexist);
2017 		return;
2018 	}
2019 
2020 	if (BTC_SCAN_START == type) {
2021 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2022 			 "[BTCoex], SCAN START notify\n");
2023 		if (!wifi_connected)
2024 			/* non-connected scan */
2025 			btc8723b1ant_action_wifi_not_conn_scan(btcoexist);
2026 		else
2027 			/* wifi is connected */
2028 			btc8723b1ant_action_wifi_conn_scan(btcoexist);
2029 	} else if (BTC_SCAN_FINISH == type) {
2030 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2031 			 "[BTCoex], SCAN FINISH notify\n");
2032 		if (!wifi_connected)
2033 			/* non-connected scan */
2034 			btc8723b1ant_action_wifi_not_conn(btcoexist);
2035 		else
2036 			halbtc8723b1ant_action_wifi_connected(btcoexist);
2037 	}
2038 }
2039 
2040 void ex_halbtc8723b1ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
2041 {
2042 	struct rtl_priv *rtlpriv = btcoexist->adapter;
2043 	bool wifi_connected = false, bt_hs_on = false;
2044 	u32 wifi_link_status = 0;
2045 	u32 num_of_wifi_link = 0;
2046 	bool bt_ctrl_agg_buf_size = false;
2047 	u8 agg_buf_size = 5;
2048 
2049 	if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
2050 	    btcoexist->bt_info.bt_disabled)
2051 		return;
2052 
2053 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2054 			   &wifi_link_status);
2055 	num_of_wifi_link = wifi_link_status>>16;
2056 	if (num_of_wifi_link >= 2) {
2057 		halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2058 		halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2059 					   bt_ctrl_agg_buf_size, agg_buf_size);
2060 		halbtc8723b1ant_action_wifi_multiport(btcoexist);
2061 		return;
2062 	}
2063 
2064 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2065 	if (coex_sta->c2h_bt_inquiry_page) {
2066 		halbtc8723b1ant_action_bt_inquiry(btcoexist);
2067 		return;
2068 	} else if (bt_hs_on) {
2069 		halbtc8723b1ant_action_hs(btcoexist);
2070 		return;
2071 	}
2072 
2073 	if (BTC_ASSOCIATE_START == type) {
2074 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2075 			 "[BTCoex], CONNECT START notify\n");
2076 		btc8723b1ant_act_wifi_not_conn_asso_auth(btcoexist);
2077 	} else if (BTC_ASSOCIATE_FINISH == type) {
2078 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2079 			 "[BTCoex], CONNECT FINISH notify\n");
2080 
2081 		btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2082 				   &wifi_connected);
2083 		if (!wifi_connected)
2084 			/* non-connected scan */
2085 			btc8723b1ant_action_wifi_not_conn(btcoexist);
2086 		else
2087 			halbtc8723b1ant_action_wifi_connected(btcoexist);
2088 	}
2089 }
2090 
2091 void ex_halbtc8723b1ant_media_status_notify(struct btc_coexist *btcoexist,
2092 					    u8 type)
2093 {
2094 	struct rtl_priv *rtlpriv = btcoexist->adapter;
2095 	u8 h2c_parameter[3] = {0};
2096 	u32 wifi_bw;
2097 	u8 wifiCentralChnl;
2098 
2099 	if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
2100 	    btcoexist->bt_info.bt_disabled)
2101 		return;
2102 
2103 	if (BTC_MEDIA_CONNECT == type)
2104 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2105 			 "[BTCoex], MEDIA connect notify\n");
2106 	else
2107 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2108 			 "[BTCoex], MEDIA disconnect notify\n");
2109 
2110 	/* only 2.4G we need to inform bt the chnl mask */
2111 	btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
2112 			   &wifiCentralChnl);
2113 
2114 	if ((BTC_MEDIA_CONNECT == type) &&
2115 	    (wifiCentralChnl <= 14)) {
2116 		h2c_parameter[0] = 0x0;
2117 		h2c_parameter[1] = wifiCentralChnl;
2118 		btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2119 		if (BTC_WIFI_BW_HT40 == wifi_bw)
2120 			h2c_parameter[2] = 0x30;
2121 		else
2122 			h2c_parameter[2] = 0x20;
2123 	}
2124 
2125 	coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
2126 	coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
2127 	coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
2128 
2129 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2130 		 "[BTCoex], FW write 0x66 = 0x%x\n",
2131 		 h2c_parameter[0] << 16 | h2c_parameter[1] << 8 |
2132 		 h2c_parameter[2]);
2133 
2134 	btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
2135 }
2136 
2137 void ex_halbtc8723b1ant_special_packet_notify(struct btc_coexist *btcoexist,
2138 					      u8 type)
2139 {
2140 	struct rtl_priv *rtlpriv = btcoexist->adapter;
2141 	bool bt_hs_on = false;
2142 	u32 wifi_link_status = 0;
2143 	u32 num_of_wifi_link = 0;
2144 	bool bt_ctrl_agg_buf_size = false;
2145 	u8 agg_buf_size = 5;
2146 
2147 	if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
2148 	    btcoexist->bt_info.bt_disabled)
2149 		return;
2150 
2151 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2152 		&wifi_link_status);
2153 	num_of_wifi_link = wifi_link_status >> 16;
2154 	if (num_of_wifi_link >= 2) {
2155 		halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2156 		halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2157 					   bt_ctrl_agg_buf_size, agg_buf_size);
2158 		halbtc8723b1ant_action_wifi_multiport(btcoexist);
2159 		return;
2160 	}
2161 
2162 	coex_sta->special_pkt_period_cnt = 0;
2163 
2164 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2165 	if (coex_sta->c2h_bt_inquiry_page) {
2166 		halbtc8723b1ant_action_bt_inquiry(btcoexist);
2167 		return;
2168 	} else if (bt_hs_on) {
2169 		halbtc8723b1ant_action_hs(btcoexist);
2170 		return;
2171 	}
2172 
2173 	if (BTC_PACKET_DHCP == type ||
2174 	    BTC_PACKET_EAPOL == type) {
2175 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2176 			 "[BTCoex], special Packet(%d) notify\n", type);
2177 		halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist);
2178 	}
2179 }
2180 
2181 void ex_halbtc8723b1ant_bt_info_notify(struct btc_coexist *btcoexist,
2182 				       u8 *tmp_buf, u8 length)
2183 {
2184 	struct rtl_priv *rtlpriv = btcoexist->adapter;
2185 	u8 bt_info = 0;
2186 	u8 i, rsp_source = 0;
2187 	bool wifi_connected = false;
2188 	bool bt_busy = false;
2189 
2190 	coex_sta->c2h_bt_info_req_sent = false;
2191 
2192 	rsp_source = tmp_buf[0] & 0xf;
2193 	if (rsp_source >= BT_INFO_SRC_8723B_1ANT_MAX)
2194 		rsp_source = BT_INFO_SRC_8723B_1ANT_WIFI_FW;
2195 	coex_sta->bt_info_c2h_cnt[rsp_source]++;
2196 
2197 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2198 		 "[BTCoex], Bt info[%d], length=%d, hex data = [",
2199 		 rsp_source, length);
2200 	for (i = 0; i < length; i++) {
2201 		coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
2202 		if (i == 1)
2203 			bt_info = tmp_buf[i];
2204 		if (i == length - 1)
2205 			RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2206 				 "0x%02x]\n", tmp_buf[i]);
2207 		else
2208 			RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2209 				 "0x%02x, ", tmp_buf[i]);
2210 	}
2211 
2212 	if (BT_INFO_SRC_8723B_1ANT_WIFI_FW != rsp_source) {
2213 		coex_sta->bt_retry_cnt =	/* [3:0] */
2214 			coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
2215 
2216 		coex_sta->bt_rssi =
2217 			coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
2218 
2219 		coex_sta->bt_info_ext =
2220 			coex_sta->bt_info_c2h[rsp_source][4];
2221 
2222 		/* Here we need to resend some wifi info to BT
2223 		 * because bt is reset and loss of the info.
2224 		 */
2225 		if (coex_sta->bt_info_ext & BIT1) {
2226 			RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2227 				 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
2228 			btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2229 					   &wifi_connected);
2230 			if (wifi_connected)
2231 				ex_halbtc8723b1ant_media_status_notify(btcoexist,
2232 							     BTC_MEDIA_CONNECT);
2233 			else
2234 				ex_halbtc8723b1ant_media_status_notify(btcoexist,
2235 							  BTC_MEDIA_DISCONNECT);
2236 		}
2237 
2238 		if (coex_sta->bt_info_ext & BIT3) {
2239 			if (!btcoexist->manual_control &&
2240 			    !btcoexist->stop_coex_dm) {
2241 				RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2242 					 "[BTCoex], BT ext info bit3 check, set BT NOT ignore Wlan active!!\n");
2243 				halbtc8723b1ant_ignore_wlan_act(btcoexist,
2244 								FORCE_EXEC,
2245 								false);
2246 			}
2247 		} else {
2248 			/* BT already NOT ignore Wlan active, do nothing here.*/
2249 		}
2250 #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)
2251 		if (coex_sta->bt_info_ext & BIT4) {
2252 			/* BT auto report already enabled, do nothing */
2253 		} else {
2254 			halbtc8723b1ant_bt_auto_report(btcoexist, FORCE_EXEC,
2255 						       true);
2256 		}
2257 #endif
2258 	}
2259 
2260 	/* check BIT2 first ==> check if bt is under inquiry or page scan */
2261 	if (bt_info & BT_INFO_8723B_1ANT_B_INQ_PAGE)
2262 		coex_sta->c2h_bt_inquiry_page = true;
2263 	else
2264 		coex_sta->c2h_bt_inquiry_page = false;
2265 
2266 	/* set link exist status */
2267 	if (!(bt_info & BT_INFO_8723B_1ANT_B_CONNECTION)) {
2268 		coex_sta->bt_link_exist = false;
2269 		coex_sta->pan_exist = false;
2270 		coex_sta->a2dp_exist = false;
2271 		coex_sta->hid_exist = false;
2272 		coex_sta->sco_exist = false;
2273 	} else {
2274 		/* connection exists */
2275 		coex_sta->bt_link_exist = true;
2276 		if (bt_info & BT_INFO_8723B_1ANT_B_FTP)
2277 			coex_sta->pan_exist = true;
2278 		else
2279 			coex_sta->pan_exist = false;
2280 		if (bt_info & BT_INFO_8723B_1ANT_B_A2DP)
2281 			coex_sta->a2dp_exist = true;
2282 		else
2283 			coex_sta->a2dp_exist = false;
2284 		if (bt_info & BT_INFO_8723B_1ANT_B_HID)
2285 			coex_sta->hid_exist = true;
2286 		else
2287 			coex_sta->hid_exist = false;
2288 		if (bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO)
2289 			coex_sta->sco_exist = true;
2290 		else
2291 			coex_sta->sco_exist = false;
2292 	}
2293 
2294 	halbtc8723b1ant_update_bt_link_info(btcoexist);
2295 
2296 	if (!(bt_info&BT_INFO_8723B_1ANT_B_CONNECTION)) {
2297 		coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
2298 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2299 			 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!\n");
2300 	/* connection exists but no busy */
2301 	} else if (bt_info == BT_INFO_8723B_1ANT_B_CONNECTION) {
2302 		coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE;
2303 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2304 			 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
2305 	} else if ((bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO) ||
2306 		(bt_info & BT_INFO_8723B_1ANT_B_SCO_BUSY)) {
2307 		coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_SCO_BUSY;
2308 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2309 			 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
2310 	} else if (bt_info & BT_INFO_8723B_1ANT_B_ACL_BUSY) {
2311 		if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
2312 			coex_dm->auto_tdma_adjust = false;
2313 
2314 		coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_ACL_BUSY;
2315 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2316 			 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
2317 	} else {
2318 		coex_dm->bt_status =
2319 			BT_8723B_1ANT_BT_STATUS_MAX;
2320 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2321 			 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!\n");
2322 	}
2323 
2324 	if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
2325 	    (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2326 	    (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
2327 		bt_busy = true;
2328 	else
2329 		bt_busy = false;
2330 	btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
2331 
2332 	halbtc8723b1ant_run_coexist_mechanism(btcoexist);
2333 }
2334 
2335 void ex_halbtc8723b1ant_halt_notify(struct btc_coexist *btcoexist)
2336 {
2337 	struct rtl_priv *rtlpriv = btcoexist->adapter;
2338 
2339 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Halt notify\n");
2340 
2341 	btcoexist->stop_coex_dm = true;
2342 
2343 	halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true);
2344 
2345 	halbtc8723b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
2346 
2347 	halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2348 					 0x0, 0x0);
2349 	halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
2350 
2351 	ex_halbtc8723b1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
2352 }
2353 
2354 void ex_halbtc8723b1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
2355 {
2356 	struct rtl_priv *rtlpriv = btcoexist->adapter;
2357 
2358 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Pnp notify\n");
2359 
2360 	if (BTC_WIFI_PNP_SLEEP == pnp_state) {
2361 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2362 			 "[BTCoex], Pnp notify to SLEEP\n");
2363 		btcoexist->stop_coex_dm = true;
2364 		halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
2365 					     true);
2366 		halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2367 						 0x0, 0x0);
2368 		halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2369 		halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
2370 	} else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
2371 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2372 			 "[BTCoex], Pnp notify to WAKE UP\n");
2373 		btcoexist->stop_coex_dm = false;
2374 		halbtc8723b1ant_init_hw_config(btcoexist, false);
2375 		halbtc8723b1ant_init_coex_dm(btcoexist);
2376 		halbtc8723b1ant_query_bt_info(btcoexist);
2377 	}
2378 }
2379 
2380 void ex_halbtc8723b1ant_coex_dm_reset(struct btc_coexist *btcoexist)
2381 {
2382 	struct rtl_priv *rtlpriv = btcoexist->adapter;
2383 
2384 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2385 		 "[BTCoex], *****************Coex DM Reset****************\n");
2386 
2387 	halbtc8723b1ant_init_hw_config(btcoexist, false);
2388 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2389 	btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x2, 0xfffff, 0x0);
2390 	halbtc8723b1ant_init_coex_dm(btcoexist);
2391 }
2392 
2393 void ex_halbtc8723b1ant_periodical(struct btc_coexist *btcoexist)
2394 {
2395 	struct rtl_priv *rtlpriv = btcoexist->adapter;
2396 	struct btc_board_info *board_info = &btcoexist->board_info;
2397 	struct btc_stack_info *stack_info = &btcoexist->stack_info;
2398 	static u8 dis_ver_info_cnt;
2399 	u32 fw_ver = 0, bt_patch_ver = 0;
2400 
2401 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2402 		 "[BTCoex], ==========================Periodical===========================\n");
2403 
2404 	if (dis_ver_info_cnt <= 5) {
2405 		dis_ver_info_cnt += 1;
2406 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2407 			 "[BTCoex], ****************************************************************\n");
2408 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2409 			 "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
2410 			 board_info->pg_ant_num, board_info->btdm_ant_num,
2411 			 board_info->btdm_ant_pos);
2412 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2413 			 "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
2414 			 stack_info->profile_notified ? "Yes" : "No",
2415 			 stack_info->hci_version);
2416 		btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
2417 				   &bt_patch_ver);
2418 		btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
2419 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2420 			 "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
2421 			 glcoex_ver_date_8723b_1ant,
2422 			 glcoex_ver_8723b_1ant, fw_ver,
2423 			 bt_patch_ver, bt_patch_ver);
2424 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2425 			 "[BTCoex], ****************************************************************\n");
2426 	}
2427 
2428 #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)
2429 	halbtc8723b1ant_query_bt_info(btcoexist);
2430 	halbtc8723b1ant_monitor_bt_ctr(btcoexist);
2431 	halbtc8723b1ant_monitor_bt_enable_disable(btcoexist);
2432 #else
2433 	if (btc8723b1ant_is_wifi_status_changed(btcoexist) ||
2434 	    coex_dm->auto_tdma_adjust) {
2435 		halbtc8723b1ant_run_coexist_mechanism(btcoexist);
2436 	}
2437 
2438 	coex_sta->special_pkt_period_cnt++;
2439 #endif
2440 }
2441