GNU Linux-libre 4.14.313-gnu1
[releases.git] / drivers / staging / rtlwifi / btcoexist / halbtc8822b2ant.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2016  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  * Description:
27  *
28  * This file is for RTL8822B Co-exist mechanism
29  *
30  * History
31  * 2012/11/15 Cosa first check in.
32  *
33  * *************************************************************/
34
35 /* ************************************************************
36  * include files
37  * *************************************************************/
38 #include "halbt_precomp.h"
39
40 /* ************************************************************
41  * Global variables, these are static variables
42  * *************************************************************/
43 static struct coex_dm_8822b_2ant glcoex_dm_8822b_2ant;
44 static struct coex_dm_8822b_2ant *coex_dm = &glcoex_dm_8822b_2ant;
45 static struct coex_sta_8822b_2ant glcoex_sta_8822b_2ant;
46 static struct coex_sta_8822b_2ant *coex_sta = &glcoex_sta_8822b_2ant;
47 static struct psdscan_sta_8822b_2ant gl_psd_scan_8822b_2ant;
48 static struct psdscan_sta_8822b_2ant *psd_scan = &gl_psd_scan_8822b_2ant;
49 static struct rfe_type_8822b_2ant gl_rfe_type_8822b_2ant;
50 static struct rfe_type_8822b_2ant *rfe_type = &gl_rfe_type_8822b_2ant;
51
52 static const char *const glbt_info_src_8822b_2ant[] = {
53         "BT Info[wifi fw]", "BT Info[bt rsp]", "BT Info[bt auto report]",
54 };
55
56 static u32 glcoex_ver_date_8822b_2ant = 20170327;
57 static u32 glcoex_ver_8822b_2ant = 0x44;
58 static u32 glcoex_ver_btdesired_8822b_2ant = 0x42;
59
60 /* ************************************************************
61  * local function proto type if needed
62  * ************************************************************
63  * ************************************************************
64  * local function start with halbtc8822b2ant_
65  * *************************************************************/
66 static u8 halbtc8822b2ant_bt_rssi_state(struct btc_coexist *btcoexist,
67                                         u8 *ppre_bt_rssi_state, u8 level_num,
68                                         u8 rssi_thresh, u8 rssi_thresh1)
69 {
70         struct rtl_priv *rtlpriv = btcoexist->adapter;
71         s32 bt_rssi = 0;
72         u8 bt_rssi_state = *ppre_bt_rssi_state;
73
74         bt_rssi = coex_sta->bt_rssi;
75
76         if (level_num == 2) {
77                 if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
78                     (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
79                         if (bt_rssi >=
80                             (rssi_thresh + BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
81                                 bt_rssi_state = BTC_RSSI_STATE_HIGH;
82                         else
83                                 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
84                 } else {
85                         if (bt_rssi < rssi_thresh)
86                                 bt_rssi_state = BTC_RSSI_STATE_LOW;
87                         else
88                                 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
89                 }
90         } else if (level_num == 3) {
91                 if (rssi_thresh > rssi_thresh1) {
92                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
93                                  "[BTCoex], BT Rssi thresh error!!\n");
94                         return *ppre_bt_rssi_state;
95                 }
96
97                 if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
98                     (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
99                         if (bt_rssi >=
100                             (rssi_thresh + BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
101                                 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
102                         else
103                                 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
104                 } else if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_MEDIUM) ||
105                            (*ppre_bt_rssi_state ==
106                             BTC_RSSI_STATE_STAY_MEDIUM)) {
107                         if (bt_rssi >= (rssi_thresh1 +
108                                         BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
109                                 bt_rssi_state = BTC_RSSI_STATE_HIGH;
110                         else if (bt_rssi < rssi_thresh)
111                                 bt_rssi_state = BTC_RSSI_STATE_LOW;
112                         else
113                                 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
114                 } else {
115                         if (bt_rssi < rssi_thresh1)
116                                 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
117                         else
118                                 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
119                 }
120         }
121
122         *ppre_bt_rssi_state = bt_rssi_state;
123
124         return bt_rssi_state;
125 }
126
127 static u8 halbtc8822b2ant_wifi_rssi_state(struct btc_coexist *btcoexist,
128                                           u8 *pprewifi_rssi_state, u8 level_num,
129                                           u8 rssi_thresh, u8 rssi_thresh1)
130 {
131         struct rtl_priv *rtlpriv = btcoexist->adapter;
132         s32 wifi_rssi = 0;
133         u8 wifi_rssi_state = *pprewifi_rssi_state;
134
135         btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
136
137         if (level_num == 2) {
138                 if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) ||
139                     (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
140                         if (wifi_rssi >=
141                             (rssi_thresh + BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
142                                 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
143                         else
144                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
145                 } else {
146                         if (wifi_rssi < rssi_thresh)
147                                 wifi_rssi_state = BTC_RSSI_STATE_LOW;
148                         else
149                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
150                 }
151         } else if (level_num == 3) {
152                 if (rssi_thresh > rssi_thresh1) {
153                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
154                                  "[BTCoex], wifi RSSI thresh error!!\n");
155                         return *pprewifi_rssi_state;
156                 }
157
158                 if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) ||
159                     (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
160                         if (wifi_rssi >=
161                             (rssi_thresh + BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
162                                 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
163                         else
164                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
165                 } else if ((*pprewifi_rssi_state == BTC_RSSI_STATE_MEDIUM) ||
166                            (*pprewifi_rssi_state ==
167                             BTC_RSSI_STATE_STAY_MEDIUM)) {
168                         if (wifi_rssi >= (rssi_thresh1 +
169                                           BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
170                                 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
171                         else if (wifi_rssi < rssi_thresh)
172                                 wifi_rssi_state = BTC_RSSI_STATE_LOW;
173                         else
174                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
175                 } else {
176                         if (wifi_rssi < rssi_thresh1)
177                                 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
178                         else
179                                 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
180                 }
181         }
182
183         *pprewifi_rssi_state = wifi_rssi_state;
184
185         return wifi_rssi_state;
186 }
187
188 static void halbtc8822b2ant_coex_switch_threshold(struct btc_coexist *btcoexist,
189                                                   u8 isolation_measuared)
190 {
191         s8 interference_wl_tx = 0, interference_bt_tx = 0;
192
193         interference_wl_tx =
194                 BT_8822B_2ANT_WIFI_MAX_TX_POWER - isolation_measuared;
195         interference_bt_tx =
196                 BT_8822B_2ANT_BT_MAX_TX_POWER - isolation_measuared;
197
198         coex_sta->wifi_coex_thres = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1;
199         coex_sta->wifi_coex_thres2 = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES2;
200
201         coex_sta->bt_coex_thres = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1;
202         coex_sta->bt_coex_thres2 = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES2;
203 }
204
205 static void halbtc8822b2ant_query_bt_info(struct btc_coexist *btcoexist)
206 {
207         struct rtl_priv *rtlpriv = btcoexist->adapter;
208         u8 h2c_parameter[1] = {0};
209
210         if (coex_sta->bt_disabled) {
211                 RT_TRACE(
212                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
213                         "[BTCoex], No query BT info because BT is disabled!\n");
214                 return;
215         }
216
217         h2c_parameter[0] |= BIT(0); /* trigger */
218
219         btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
220 }
221
222 static void halbtc8822b2ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
223 {
224         u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
225         u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
226         static u8 num_of_bt_counter_chk, cnt_slave, cnt_autoslot_hang;
227
228         struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
229
230         reg_hp_txrx = 0x770;
231         reg_lp_txrx = 0x774;
232
233         u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
234         reg_hp_tx = u32tmp & MASKLWORD;
235         reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
236
237         u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
238         reg_lp_tx = u32tmp & MASKLWORD;
239         reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
240
241         coex_sta->high_priority_tx = reg_hp_tx;
242         coex_sta->high_priority_rx = reg_hp_rx;
243         coex_sta->low_priority_tx = reg_lp_tx;
244         coex_sta->low_priority_rx = reg_lp_rx;
245
246         /* reset counter */
247         btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
248
249         if ((coex_sta->low_priority_tx > 1050) &&
250             (!coex_sta->c2h_bt_inquiry_page))
251                 coex_sta->pop_event_cnt++;
252
253         if ((coex_sta->low_priority_rx >= 950) &&
254             (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) &&
255             (!coex_sta->under_ips) && (!coex_sta->c2h_bt_inquiry_page) &&
256             (coex_sta->bt_link_exist)) {
257                 if (cnt_slave >= 2) {
258                         bt_link_info->slave_role = true;
259                         cnt_slave = 2;
260                 } else {
261                         cnt_slave++;
262                 }
263         } else {
264                 if (cnt_slave == 0) {
265                         bt_link_info->slave_role = false;
266                         cnt_slave = 0;
267                 } else {
268                         cnt_slave--;
269                 }
270         }
271
272         if (coex_sta->is_tdma_btautoslot) {
273                 if ((coex_sta->low_priority_tx >= 1300) &&
274                     (coex_sta->low_priority_rx <= 150)) {
275                         if (cnt_autoslot_hang >= 2) {
276                                 coex_sta->is_tdma_btautoslot_hang = true;
277                                 cnt_autoslot_hang = 2;
278                         } else {
279                                 cnt_autoslot_hang++;
280                         }
281                 } else {
282                         if (cnt_autoslot_hang == 0) {
283                                 coex_sta->is_tdma_btautoslot_hang = false;
284                                 cnt_autoslot_hang = 0;
285                         } else {
286                                 cnt_autoslot_hang--;
287                         }
288                 }
289         }
290
291         if (coex_sta->sco_exist) {
292                 if ((coex_sta->high_priority_tx >= 400) &&
293                     (coex_sta->high_priority_rx >= 400))
294                         coex_sta->is_esco_mode = false;
295                 else
296                         coex_sta->is_esco_mode = true;
297         }
298
299         if (bt_link_info->hid_only) {
300                 if (coex_sta->low_priority_rx > 50)
301                         coex_sta->is_hid_low_pri_tx_overhead = true;
302                 else
303                         coex_sta->is_hid_low_pri_tx_overhead = false;
304         }
305
306         if ((coex_sta->high_priority_tx == 0) &&
307             (coex_sta->high_priority_rx == 0) &&
308             (coex_sta->low_priority_tx == 0) &&
309             (coex_sta->low_priority_rx == 0)) {
310                 num_of_bt_counter_chk++;
311                 if (num_of_bt_counter_chk >= 3) {
312                         halbtc8822b2ant_query_bt_info(btcoexist);
313                         num_of_bt_counter_chk = 0;
314                 }
315         }
316 }
317
318 static void halbtc8822b2ant_monitor_wifi_ctr(struct btc_coexist *btcoexist)
319 {
320         s32 wifi_rssi = 0;
321         bool wifi_busy = false, wifi_under_b_mode = false, wifi_scan = false;
322         bool bt_idle = false;
323         static u8 cck_lock_counter, wl_noisy_count0, wl_noisy_count1 = 3,
324                                                      wl_noisy_count2;
325         u32 total_cnt, cck_cnt;
326         u32 cnt_crcok = 0, cnt_crcerr = 0;
327         static u8 cnt;
328
329         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
330         btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
331         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
332                            &wifi_under_b_mode);
333
334         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
335
336         coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_phy_counter(
337                 btcoexist, "PHYDM_INFO_CRC32_OK_CCK");
338         coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_phy_counter(
339                 btcoexist, "PHYDM_INFO_CRC32_OK_LEGACY");
340         coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_phy_counter(
341                 btcoexist, "PHYDM_INFO_CRC32_OK_HT");
342         coex_sta->crc_ok_11n_vht = btcoexist->btc_phydm_query_phy_counter(
343                 btcoexist, "PHYDM_INFO_CRC32_OK_VHT");
344
345         coex_sta->crc_err_cck = btcoexist->btc_phydm_query_phy_counter(
346                 btcoexist, "PHYDM_INFO_CRC32_ERROR_CCK");
347         coex_sta->crc_err_11g = btcoexist->btc_phydm_query_phy_counter(
348                 btcoexist, "PHYDM_INFO_CRC32_ERROR_LEGACY");
349         coex_sta->crc_err_11n = btcoexist->btc_phydm_query_phy_counter(
350                 btcoexist, "PHYDM_INFO_CRC32_ERROR_HT");
351         coex_sta->crc_err_11n_vht = btcoexist->btc_phydm_query_phy_counter(
352                 btcoexist, "PHYDM_INFO_CRC32_ERROR_VHT");
353
354         cnt_crcok = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g +
355                     coex_sta->crc_ok_11n + coex_sta->crc_ok_11n_vht;
356
357         cnt_crcerr = coex_sta->crc_err_cck + coex_sta->crc_err_11g +
358                      coex_sta->crc_err_11n + coex_sta->crc_err_11n_vht;
359
360         if ((wifi_busy) && (cnt_crcerr != 0)) {
361                 coex_sta->now_crc_ratio = cnt_crcok / cnt_crcerr;
362
363                 if (cnt == 0)
364                         coex_sta->acc_crc_ratio = coex_sta->now_crc_ratio;
365                 else
366                         coex_sta->acc_crc_ratio =
367                                 (coex_sta->acc_crc_ratio * 7 +
368                                  coex_sta->now_crc_ratio * 3) /
369                                 10;
370
371                 if (cnt >= 10)
372                         cnt = 0;
373                 else
374                         cnt++;
375         }
376
377         cck_cnt = coex_sta->crc_ok_cck + coex_sta->crc_err_cck;
378
379         if ((coex_dm->bt_status ==
380              BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE) ||
381             (coex_dm->bt_status == BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE) ||
382             (coex_sta->bt_disabled))
383                 bt_idle = true;
384
385         if (cck_cnt > 250) {
386                 if (wl_noisy_count2 < 3)
387                         wl_noisy_count2++;
388
389                 if (wl_noisy_count2 == 3) {
390                         wl_noisy_count0 = 0;
391                         wl_noisy_count1 = 0;
392                 }
393
394         } else if (cck_cnt < 50) {
395                 if (wl_noisy_count0 < 3)
396                         wl_noisy_count0++;
397
398                 if (wl_noisy_count0 == 3) {
399                         wl_noisy_count1 = 0;
400                         wl_noisy_count2 = 0;
401                 }
402
403         } else {
404                 if (wl_noisy_count1 < 3)
405                         wl_noisy_count1++;
406
407                 if (wl_noisy_count1 == 3) {
408                         wl_noisy_count0 = 0;
409                         wl_noisy_count2 = 0;
410                 }
411         }
412
413         if (wl_noisy_count2 == 3)
414                 coex_sta->wl_noisy_level = 2;
415         else if (wl_noisy_count1 == 3)
416                 coex_sta->wl_noisy_level = 1;
417         else
418                 coex_sta->wl_noisy_level = 0;
419
420         if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
421                 total_cnt = cnt_crcok;
422
423                 if ((coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_ACL_BUSY) ||
424                     (coex_dm->bt_status ==
425                      BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
426                     (coex_dm->bt_status == BT_8822B_1ANT_BT_STATUS_SCO_BUSY)) {
427                         if (coex_sta->crc_ok_cck >
428                             (total_cnt - coex_sta->crc_ok_cck)) {
429                                 if (cck_lock_counter < 3)
430                                         cck_lock_counter++;
431                         } else {
432                                 if (cck_lock_counter > 0)
433                                         cck_lock_counter--;
434                         }
435
436                 } else {
437                         if (cck_lock_counter > 0)
438                                 cck_lock_counter--;
439                 }
440         } else {
441                 if (cck_lock_counter > 0)
442                         cck_lock_counter--;
443         }
444
445         if (!coex_sta->pre_ccklock) {
446                 if (cck_lock_counter >= 3)
447                         coex_sta->cck_lock = true;
448                 else
449                         coex_sta->cck_lock = false;
450         } else {
451                 if (cck_lock_counter == 0)
452                         coex_sta->cck_lock = false;
453                 else
454                         coex_sta->cck_lock = true;
455         }
456
457         if (coex_sta->cck_lock)
458                 coex_sta->cck_ever_lock = true;
459
460         coex_sta->pre_ccklock = coex_sta->cck_lock;
461 }
462
463 static bool
464 halbtc8822b2ant_is_wifibt_status_changed(struct btc_coexist *btcoexist)
465 {
466         struct rtl_priv *rtlpriv = btcoexist->adapter;
467         static bool pre_wifi_busy, pre_under_4way, pre_bt_hs_on, pre_bt_off,
468                 pre_bt_slave, pre_hid_low_pri_tx_overhead, pre_wifi_under_lps,
469                 pre_bt_setup_link;
470         static u8 pre_hid_busy_num, pre_wl_noisy_level;
471         bool wifi_busy = false, under_4way = false, bt_hs_on = false;
472         bool wifi_connected = false;
473         struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
474
475         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
476                            &wifi_connected);
477         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
478         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
479         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
480                            &under_4way);
481
482         if (coex_sta->bt_disabled != pre_bt_off) {
483                 pre_bt_off = coex_sta->bt_disabled;
484
485                 if (coex_sta->bt_disabled)
486                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
487                                  "[BTCoex], BT is disabled !!\n");
488                 else
489                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
490                                  "[BTCoex], BT is enabled !!\n");
491
492                 coex_sta->bt_coex_supported_feature = 0;
493                 coex_sta->bt_coex_supported_version = 0;
494                 coex_sta->bt_ble_scan_type = 0;
495                 coex_sta->bt_ble_scan_para[0] = 0;
496                 coex_sta->bt_ble_scan_para[1] = 0;
497                 coex_sta->bt_ble_scan_para[2] = 0;
498                 coex_sta->bt_reg_vendor_ac = 0xffff;
499                 coex_sta->bt_reg_vendor_ae = 0xffff;
500                 return true;
501         }
502
503         if (wifi_connected) {
504                 if (wifi_busy != pre_wifi_busy) {
505                         pre_wifi_busy = wifi_busy;
506                         return true;
507                 }
508                 if (under_4way != pre_under_4way) {
509                         pre_under_4way = under_4way;
510                         return true;
511                 }
512                 if (bt_hs_on != pre_bt_hs_on) {
513                         pre_bt_hs_on = bt_hs_on;
514                         return true;
515                 }
516                 if (coex_sta->wl_noisy_level != pre_wl_noisy_level) {
517                         pre_wl_noisy_level = coex_sta->wl_noisy_level;
518                         return true;
519                 }
520                 if (coex_sta->under_lps != pre_wifi_under_lps) {
521                         pre_wifi_under_lps = coex_sta->under_lps;
522                         if (coex_sta->under_lps)
523                                 return true;
524                 }
525         }
526
527         if (!coex_sta->bt_disabled) {
528                 if (coex_sta->hid_busy_num != pre_hid_busy_num) {
529                         pre_hid_busy_num = coex_sta->hid_busy_num;
530                         return true;
531                 }
532
533                 if (bt_link_info->slave_role != pre_bt_slave) {
534                         pre_bt_slave = bt_link_info->slave_role;
535                         return true;
536                 }
537
538                 if (pre_hid_low_pri_tx_overhead !=
539                     coex_sta->is_hid_low_pri_tx_overhead) {
540                         pre_hid_low_pri_tx_overhead =
541                                 coex_sta->is_hid_low_pri_tx_overhead;
542                         return true;
543                 }
544
545                 if (pre_bt_setup_link != coex_sta->is_setup_link) {
546                         pre_bt_setup_link = coex_sta->is_setup_link;
547                         return true;
548                 }
549         }
550
551         return false;
552 }
553
554 static void halbtc8822b2ant_update_bt_link_info(struct btc_coexist *btcoexist)
555 {
556         struct rtl_priv *rtlpriv = btcoexist->adapter;
557         struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
558         bool bt_hs_on = false;
559         bool bt_busy = false;
560
561         coex_sta->num_of_profile = 0;
562
563         /* set link exist status */
564         if (!(coex_sta->bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) {
565                 coex_sta->bt_link_exist = false;
566                 coex_sta->pan_exist = false;
567                 coex_sta->a2dp_exist = false;
568                 coex_sta->hid_exist = false;
569                 coex_sta->sco_exist = false;
570         } else { /* connection exists */
571                 coex_sta->bt_link_exist = true;
572                 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_FTP) {
573                         coex_sta->pan_exist = true;
574                         coex_sta->num_of_profile++;
575                 } else {
576                         coex_sta->pan_exist = false;
577                 }
578
579                 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_A2DP) {
580                         coex_sta->a2dp_exist = true;
581                         coex_sta->num_of_profile++;
582                 } else {
583                         coex_sta->a2dp_exist = false;
584                 }
585
586                 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_HID) {
587                         coex_sta->hid_exist = true;
588                         coex_sta->num_of_profile++;
589                 } else {
590                         coex_sta->hid_exist = false;
591                 }
592
593                 if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) {
594                         coex_sta->sco_exist = true;
595                         coex_sta->num_of_profile++;
596                 } else {
597                         coex_sta->sco_exist = false;
598                 }
599         }
600
601         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
602
603         bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
604         bt_link_info->sco_exist = coex_sta->sco_exist;
605         bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
606         bt_link_info->pan_exist = coex_sta->pan_exist;
607         bt_link_info->hid_exist = coex_sta->hid_exist;
608         bt_link_info->acl_busy = coex_sta->acl_busy;
609
610         /* work around for HS mode. */
611         if (bt_hs_on) {
612                 bt_link_info->pan_exist = true;
613                 bt_link_info->bt_link_exist = true;
614         }
615
616         /* check if Sco only */
617         if (bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
618             !bt_link_info->pan_exist && !bt_link_info->hid_exist)
619                 bt_link_info->sco_only = true;
620         else
621                 bt_link_info->sco_only = false;
622
623         /* check if A2dp only */
624         if (!bt_link_info->sco_exist && bt_link_info->a2dp_exist &&
625             !bt_link_info->pan_exist && !bt_link_info->hid_exist)
626                 bt_link_info->a2dp_only = true;
627         else
628                 bt_link_info->a2dp_only = false;
629
630         /* check if Pan only */
631         if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
632             bt_link_info->pan_exist && !bt_link_info->hid_exist)
633                 bt_link_info->pan_only = true;
634         else
635                 bt_link_info->pan_only = false;
636
637         /* check if Hid only */
638         if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
639             !bt_link_info->pan_exist && bt_link_info->hid_exist)
640                 bt_link_info->hid_only = true;
641         else
642                 bt_link_info->hid_only = false;
643
644         if (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_INQ_PAGE) {
645                 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_INQ_PAGE;
646                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
647                          "[BTCoex], BtInfoNotify(), BT Inq/page!!!\n");
648         } else if (!(coex_sta->bt_info & BT_INFO_8822B_2ANT_B_CONNECTION)) {
649                 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
650                 RT_TRACE(
651                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
652                         "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
653         } else if (coex_sta->bt_info == BT_INFO_8822B_2ANT_B_CONNECTION) {
654                 /* connection exists but no busy */
655                 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE;
656                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
657                          "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
658         } else if (((coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_ESCO) ||
659                     (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_BUSY)) &&
660                    (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_ACL_BUSY)) {
661                 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY;
662                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
663                          "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n");
664         } else if ((coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_ESCO) ||
665                    (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_BUSY)) {
666                 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_SCO_BUSY;
667                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
668                          "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
669         } else if (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_ACL_BUSY) {
670                 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_ACL_BUSY;
671                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
672                          "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
673         } else {
674                 coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_MAX;
675                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
676                          "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
677         }
678
679         if ((coex_dm->bt_status == BT_8822B_2ANT_BT_STATUS_ACL_BUSY) ||
680             (coex_dm->bt_status == BT_8822B_2ANT_BT_STATUS_SCO_BUSY) ||
681             (coex_dm->bt_status == BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY))
682                 bt_busy = true;
683         else
684                 bt_busy = false;
685
686         btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
687 }
688
689 static void halbtc8822b2ant_update_wifi_ch_info(struct btc_coexist *btcoexist,
690                                                 u8 type)
691 {
692         u8 h2c_parameter[3] = {0};
693         u32 wifi_bw;
694         u8 wifi_central_chnl;
695         u32 RTL97F_8822B = 0;
696
697         if (RTL97F_8822B)
698                 return;
699
700         /* only 2.4G we need to inform bt the chnl mask */
701         btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
702                            &wifi_central_chnl);
703         if ((type == BTC_MEDIA_CONNECT) && (wifi_central_chnl <= 14)) {
704                 /* enable BT AFH skip WL channel for 8822b
705                  * because BT Rx LO interference
706                  */
707                 h2c_parameter[0] = 0x1;
708                 h2c_parameter[1] = wifi_central_chnl;
709                 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
710                 if (wifi_bw == BTC_WIFI_BW_HT40)
711                         h2c_parameter[2] = 0x30;
712                 else
713                         h2c_parameter[2] = 0x20;
714         }
715
716         coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
717         coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
718         coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
719
720         btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
721 }
722
723 static void
724 halbtc8822b2ant_set_fw_dac_swing_level(struct btc_coexist *btcoexist,
725                                        u8 dac_swing_lvl)
726 {
727         u8 h2c_parameter[1] = {0};
728         u32 RTL97F_8822B = 0;
729
730         if (RTL97F_8822B)
731                 return;
732
733         /* There are several type of dacswing */
734         /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */
735         h2c_parameter[0] = dac_swing_lvl;
736
737         btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
738 }
739
740 static void halbtc8822b2ant_fw_dac_swing_lvl(struct btc_coexist *btcoexist,
741                                              bool force_exec,
742                                              u8 fw_dac_swing_lvl)
743 {
744         u32 RTL97F_8822B = 0;
745
746         if (RTL97F_8822B)
747                 return;
748
749         coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
750
751         if (!force_exec) {
752                 if (coex_dm->pre_fw_dac_swing_lvl ==
753                     coex_dm->cur_fw_dac_swing_lvl)
754                         return;
755         }
756
757         halbtc8822b2ant_set_fw_dac_swing_level(btcoexist,
758                                                coex_dm->cur_fw_dac_swing_lvl);
759
760         coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
761 }
762
763 static void halbtc8822b2ant_set_fw_dec_bt_pwr(struct btc_coexist *btcoexist,
764                                               u8 dec_bt_pwr_lvl)
765 {
766         u32 RTL97F_8822B = 0;
767         u8 h2c_parameter[1] = {0};
768
769         if (RTL97F_8822B)
770                 return;
771
772         h2c_parameter[0] = dec_bt_pwr_lvl;
773
774         btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter);
775 }
776
777 static void halbtc8822b2ant_dec_bt_pwr(struct btc_coexist *btcoexist,
778                                        bool force_exec, u8 dec_bt_pwr_lvl)
779 {
780         coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl;
781
782         if (!force_exec) {
783                 if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl)
784                         return;
785         }
786         halbtc8822b2ant_set_fw_dec_bt_pwr(btcoexist,
787                                           coex_dm->cur_bt_dec_pwr_lvl);
788
789         coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl;
790 }
791
792 static void halbtc8822b2ant_low_penalty_ra(struct btc_coexist *btcoexist,
793                                            bool force_exec, bool low_penalty_ra)
794 {
795         coex_dm->cur_low_penalty_ra = low_penalty_ra;
796
797         if (!force_exec) {
798                 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
799                         return;
800         }
801
802         if (low_penalty_ra)
803                 btcoexist->btc_phydm_modify_ra_pcr_threshold(btcoexist, 0, 50);
804         else
805                 btcoexist->btc_phydm_modify_ra_pcr_threshold(btcoexist, 0, 0);
806
807         coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
808 }
809
810 static void halbtc8822b2ant_write_score_board(struct btc_coexist *btcoexist,
811                                               u16 bitpos, bool state)
812 {
813         static u16 originalval = 0x8002;
814
815         if (state)
816                 originalval = originalval | bitpos;
817         else
818                 originalval = originalval & (~bitpos);
819
820         btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval);
821 }
822
823 static void halbtc8822b2ant_read_score_board(struct btc_coexist *btcoexist,
824                                              u16 *score_board_val)
825 {
826         *score_board_val =
827                 (btcoexist->btc_read_2byte(btcoexist, 0xaa)) & 0x7fff;
828 }
829
830 static void halbtc8822b2ant_post_state_to_bt(struct btc_coexist *btcoexist,
831                                              u16 type, bool state)
832 {
833         halbtc8822b2ant_write_score_board(btcoexist, (u16)type, state);
834 }
835
836 static void
837 halbtc8822b2ant_monitor_bt_enable_disable(struct btc_coexist *btcoexist)
838 {
839         struct rtl_priv *rtlpriv = btcoexist->adapter;
840         static u32 bt_disable_cnt;
841         bool bt_active = true, bt_disabled = false, wifi_under_5g = false;
842         u16 u16tmp;
843
844         /* This function check if bt is disabled */
845
846         /* Read BT on/off status from scoreboard[1],
847          * enable this only if BT patch support this feature
848          */
849         halbtc8822b2ant_read_score_board(btcoexist, &u16tmp);
850
851         bt_active = u16tmp & BIT(1);
852
853         if (bt_active) {
854                 bt_disable_cnt = 0;
855                 bt_disabled = false;
856                 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
857                                    &bt_disabled);
858         } else {
859                 bt_disable_cnt++;
860                 if (bt_disable_cnt >= 10) {
861                         bt_disabled = true;
862                         bt_disable_cnt = 10;
863                 }
864
865                 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
866                                    &bt_disabled);
867         }
868
869         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
870
871         if ((wifi_under_5g) || (bt_disabled))
872                 halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false);
873         else
874                 halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, true);
875
876         if (coex_sta->bt_disabled != bt_disabled) {
877                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
878                          "[BTCoex], BT is from %s to %s!!\n",
879                          (coex_sta->bt_disabled ? "disabled" : "enabled"),
880                          (bt_disabled ? "disabled" : "enabled"));
881                 coex_sta->bt_disabled = bt_disabled;
882         }
883 }
884
885 static void halbtc8822b2ant_enable_gnt_to_gpio(struct btc_coexist *btcoexist,
886                                                bool isenable)
887 {
888         struct rtl_priv *rtlpriv = btcoexist->adapter;
889         static u8 bit_val[5] = {0, 0, 0, 0, 0};
890
891         if (!btcoexist->dbg_mode_2ant)
892                 return;
893
894         if (isenable) {
895                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
896                          "[BTCoex], enable_gnt_to_gpio!!\n");
897
898                 /* enable GNT_WL, GNT_BT to GPIO for debug */
899                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1);
900
901                 /* store original value */
902                 bit_val[0] =
903                         (btcoexist->btc_read_1byte(btcoexist, 0x66) & BIT(4)) >>
904                         4; /*0x66[4] */
905                 bit_val[1] = (btcoexist->btc_read_1byte(btcoexist, 0x67) &
906                               BIT(0)); /*0x66[8] */
907                 bit_val[2] =
908                         (btcoexist->btc_read_1byte(btcoexist, 0x42) & BIT(3)) >>
909                         3; /*0x40[19] */
910                 bit_val[3] =
911                         (btcoexist->btc_read_1byte(btcoexist, 0x65) & BIT(7)) >>
912                         7; /*0x64[15] */
913                 bit_val[4] =
914                         (btcoexist->btc_read_1byte(btcoexist, 0x72) & BIT(2)) >>
915                         2; /*0x70[18] */
916
917                 /*  switch GPIO Mux */
918                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
919                                                    0x0); /*0x66[4] = 0 */
920                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
921                                                    0x0); /*0x66[8] = 0 */
922                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
923                                                    0x0); /*0x40[19] = 0 */
924                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
925                                                    0x0); /*0x64[15] = 0 */
926                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
927                                                    0x0); /*0x70[18] = 0 */
928
929         } else {
930                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
931                          "[BTCoex], disable_gnt_to_gpio!!\n");
932
933                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0);
934
935                 /*  Restore original value  */
936                 /*  switch GPIO Mux */
937                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
938                                                    bit_val[0]); /*0x66[4] = 0 */
939                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
940                                                    bit_val[1]); /*0x66[8] = 0 */
941                 btcoexist->btc_write_1byte_bitmask(
942                         btcoexist, 0x42, BIT(3), bit_val[2]); /*0x40[19] = 0 */
943                 btcoexist->btc_write_1byte_bitmask(
944                         btcoexist, 0x65, BIT(7), bit_val[3]); /*0x64[15] = 0 */
945                 btcoexist->btc_write_1byte_bitmask(
946                         btcoexist, 0x72, BIT(2), bit_val[4]); /*0x70[18] = 0 */
947         }
948 }
949
950 static u32
951 halbtc8822b2ant_ltecoex_indirect_read_reg(struct btc_coexist *btcoexist,
952                                           u16 reg_addr)
953 {
954         u32 delay_count = 0;
955
956         while (1) {
957                 if ((btcoexist->btc_read_1byte(btcoexist, 0x1703) & BIT(5)) ==
958                     0) {
959                         mdelay(50);
960                         delay_count++;
961                         if (delay_count >= 10) {
962                                 delay_count = 0;
963                                 break;
964                         }
965                 } else {
966                         break;
967                 }
968         }
969
970         /* wait for ready bit before access 0x1700               */
971         btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr);
972
973         return btcoexist->btc_read_4byte(btcoexist, 0x1708); /* get read data */
974 }
975
976 static void
977 halbtc8822b2ant_ltecoex_indirect_write_reg(struct btc_coexist *btcoexist,
978                                            u16 reg_addr, u32 bit_mask,
979                                            u32 reg_value)
980 {
981         u32 val, i = 0, bitpos = 0, delay_count = 0;
982
983         if (bit_mask == 0x0)
984                 return;
985         if (bit_mask == 0xffffffff) {
986                 /* wait for ready bit before access 0x1700/0x1704 */
987                 while (1) {
988                         if ((btcoexist->btc_read_1byte(btcoexist, 0x1703) &
989                              BIT(5)) == 0) {
990                                 mdelay(50);
991                                 delay_count++;
992                                 if (delay_count >= 10) {
993                                         delay_count = 0;
994                                         break;
995                                 }
996                         } else {
997                                 break;
998                         }
999                 }
1000
1001                 btcoexist->btc_write_4byte(btcoexist, 0x1704,
1002                                            reg_value); /* put write data */
1003
1004                 btcoexist->btc_write_4byte(btcoexist, 0x1700,
1005                                            0xc00F0000 | reg_addr);
1006         } else {
1007                 for (i = 0; i <= 31; i++) {
1008                         if (((bit_mask >> i) & 0x1) == 0x1) {
1009                                 bitpos = i;
1010                                 break;
1011                         }
1012                 }
1013
1014                 /* read back register value before write */
1015                 val = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
1016                                                                 reg_addr);
1017                 val = (val & (~bit_mask)) | (reg_value << bitpos);
1018
1019                 /* wait for ready bit before access 0x1700/0x1704 */
1020                 while (1) {
1021                         if ((btcoexist->btc_read_1byte(btcoexist, 0x1703) &
1022                              BIT(5)) == 0) {
1023                                 mdelay(50);
1024                                 delay_count++;
1025                                 if (delay_count >= 10) {
1026                                         delay_count = 0;
1027                                         break;
1028                                 }
1029                         } else {
1030                                 break;
1031                         }
1032                 }
1033
1034                 btcoexist->btc_write_4byte(btcoexist, 0x1704,
1035                                            val); /* put write data */
1036
1037                 btcoexist->btc_write_4byte(btcoexist, 0x1700,
1038                                            0xc00F0000 | reg_addr);
1039         }
1040 }
1041
1042 static void halbtc8822b2ant_ltecoex_enable(struct btc_coexist *btcoexist,
1043                                            bool enable)
1044 {
1045         u8 val;
1046
1047         val = (enable) ? 1 : 0;
1048         halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80,
1049                                                    val); /* 0x38[7] */
1050 }
1051
1052 static void
1053 halbtc8822b2ant_ltecoex_pathcontrol_owner(struct btc_coexist *btcoexist,
1054                                           bool wifi_control)
1055 {
1056         u8 val;
1057
1058         val = (wifi_control) ? 1 : 0;
1059         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4,
1060                                            val); /* 0x70[26] */
1061 }
1062
1063 static void halbtc8822b2ant_ltecoex_set_gnt_bt(struct btc_coexist *btcoexist,
1064                                                u8 control_block,
1065                                                bool sw_control, u8 state)
1066 {
1067         u32 val = 0, bit_mask;
1068
1069         state = state & 0x1;
1070         val = (sw_control) ? ((state << 1) | 0x1) : 0;
1071
1072         switch (control_block) {
1073         case BT_8822B_2ANT_GNT_BLOCK_RFC_BB:
1074         default:
1075                 bit_mask = 0xc000;
1076                 halbtc8822b2ant_ltecoex_indirect_write_reg(
1077                         btcoexist, 0x38, bit_mask, val); /* 0x38[15:14] */
1078                 bit_mask = 0x0c00;
1079                 halbtc8822b2ant_ltecoex_indirect_write_reg(
1080                         btcoexist, 0x38, bit_mask, val); /* 0x38[11:10] */
1081                 break;
1082         case BT_8822B_2ANT_GNT_BLOCK_RFC:
1083                 bit_mask = 0xc000;
1084                 halbtc8822b2ant_ltecoex_indirect_write_reg(
1085                         btcoexist, 0x38, bit_mask, val); /* 0x38[15:14] */
1086                 break;
1087         case BT_8822B_2ANT_GNT_BLOCK_BB:
1088                 bit_mask = 0x0c00;
1089                 halbtc8822b2ant_ltecoex_indirect_write_reg(
1090                         btcoexist, 0x38, bit_mask, val); /* 0x38[11:10] */
1091                 break;
1092         }
1093 }
1094
1095 static void halbtc8822b2ant_ltecoex_set_gnt_wl(struct btc_coexist *btcoexist,
1096                                                u8 control_block,
1097                                                bool sw_control, u8 state)
1098 {
1099         u32 val = 0, bit_mask;
1100
1101         state = state & 0x1;
1102         val = (sw_control) ? ((state << 1) | 0x1) : 0;
1103
1104         switch (control_block) {
1105         case BT_8822B_2ANT_GNT_BLOCK_RFC_BB:
1106         default:
1107                 bit_mask = 0x3000;
1108                 halbtc8822b2ant_ltecoex_indirect_write_reg(
1109                         btcoexist, 0x38, bit_mask, val); /* 0x38[13:12] */
1110                 bit_mask = 0x0300;
1111                 halbtc8822b2ant_ltecoex_indirect_write_reg(
1112                         btcoexist, 0x38, bit_mask, val); /* 0x38[9:8] */
1113                 break;
1114         case BT_8822B_2ANT_GNT_BLOCK_RFC:
1115                 bit_mask = 0x3000;
1116                 halbtc8822b2ant_ltecoex_indirect_write_reg(
1117                         btcoexist, 0x38, bit_mask, val); /* 0x38[13:12] */
1118                 break;
1119         case BT_8822B_2ANT_GNT_BLOCK_BB:
1120                 bit_mask = 0x0300;
1121                 halbtc8822b2ant_ltecoex_indirect_write_reg(
1122                         btcoexist, 0x38, bit_mask, val); /* 0x38[9:8] */
1123                 break;
1124         }
1125 }
1126
1127 static void
1128 halbtc8822b2ant_ltecoex_set_coex_table(struct btc_coexist *btcoexist,
1129                                        u8 table_type, u16 table_content)
1130 {
1131         u16 reg_addr = 0x0000;
1132
1133         switch (table_type) {
1134         case BT_8822B_2ANT_CTT_WL_VS_LTE:
1135                 reg_addr = 0xa0;
1136                 break;
1137         case BT_8822B_2ANT_CTT_BT_VS_LTE:
1138                 reg_addr = 0xa4;
1139                 break;
1140         }
1141
1142         if (reg_addr != 0x0000)
1143                 halbtc8822b2ant_ltecoex_indirect_write_reg(
1144                         btcoexist, reg_addr, 0xffff,
1145                         table_content); /* 0xa0[15:0] or 0xa4[15:0] */
1146 }
1147
1148 static void halbtc8822b2ant_set_wltoggle_coex_table(
1149         struct btc_coexist *btcoexist, bool force_exec, u8 interval,
1150         u8 val0x6c4_b0, u8 val0x6c4_b1, u8 val0x6c4_b2, u8 val0x6c4_b3)
1151 {
1152         static u8 pre_h2c_parameter[6] = {0};
1153         u8 cur_h2c_parameter[6] = {0};
1154         u8 i, match_cnt = 0;
1155
1156         cur_h2c_parameter[0] = 0x7; /* op_code, 0x7= wlan toggle slot*/
1157
1158         cur_h2c_parameter[1] = interval;
1159         cur_h2c_parameter[2] = val0x6c4_b0;
1160         cur_h2c_parameter[3] = val0x6c4_b1;
1161         cur_h2c_parameter[4] = val0x6c4_b2;
1162         cur_h2c_parameter[5] = val0x6c4_b3;
1163
1164         if (!force_exec) {
1165                 for (i = 1; i <= 5; i++) {
1166                         if (cur_h2c_parameter[i] != pre_h2c_parameter[i])
1167                                 break;
1168
1169                         match_cnt++;
1170                 }
1171
1172                 if (match_cnt == 5)
1173                         return;
1174         }
1175
1176         for (i = 1; i <= 5; i++)
1177                 pre_h2c_parameter[i] = cur_h2c_parameter[i];
1178
1179         btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter);
1180 }
1181
1182 static void halbtc8822b2ant_set_coex_table(struct btc_coexist *btcoexist,
1183                                            u32 val0x6c0, u32 val0x6c4,
1184                                            u32 val0x6c8, u8 val0x6cc)
1185 {
1186         btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
1187
1188         btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
1189
1190         btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
1191
1192         btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
1193 }
1194
1195 static void halbtc8822b2ant_coex_table(struct btc_coexist *btcoexist,
1196                                        bool force_exec, u32 val0x6c0,
1197                                        u32 val0x6c4, u32 val0x6c8, u8 val0x6cc)
1198 {
1199         coex_dm->cur_val0x6c0 = val0x6c0;
1200         coex_dm->cur_val0x6c4 = val0x6c4;
1201         coex_dm->cur_val0x6c8 = val0x6c8;
1202         coex_dm->cur_val0x6cc = val0x6cc;
1203
1204         if (!force_exec) {
1205                 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
1206                     (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
1207                     (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
1208                     (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
1209                         return;
1210         }
1211         halbtc8822b2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
1212                                        val0x6cc);
1213
1214         coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
1215         coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
1216         coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
1217         coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
1218 }
1219
1220 static void halbtc8822b2ant_coex_table_with_type(struct btc_coexist *btcoexist,
1221                                                  bool force_exec, u8 type)
1222 {
1223         u32 break_table;
1224         u8 select_table;
1225
1226         coex_sta->coex_table_type = type;
1227
1228         if (coex_sta->concurrent_rx_mode_on) {
1229                 break_table = 0xf0ffffff; /* set WL hi-pri can break BT */
1230                 /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */
1231                 select_table = 0xb;
1232         } else {
1233                 break_table = 0xffffff;
1234                 select_table = 0x3;
1235         }
1236
1237         switch (type) {
1238         case 0:
1239                 halbtc8822b2ant_coex_table(btcoexist, force_exec, 0xffffffff,
1240                                            0xffffffff, break_table,
1241                                            select_table);
1242                 break;
1243         case 1:
1244                 halbtc8822b2ant_coex_table(btcoexist, force_exec, 0x55555555,
1245                                            0x5a5a5a5a, break_table,
1246                                            select_table);
1247                 break;
1248         case 2:
1249                 halbtc8822b2ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
1250                                            0x5a5a5a5a, break_table,
1251                                            select_table);
1252                 break;
1253         case 3:
1254                 halbtc8822b2ant_coex_table(btcoexist, force_exec, 0x55555555,
1255                                            0x5a5a5a5a, break_table,
1256                                            select_table);
1257                 break;
1258         case 4:
1259                 halbtc8822b2ant_coex_table(btcoexist, force_exec, 0x55555555,
1260                                            0x5a5a5a5a, break_table,
1261                                            select_table);
1262                 break;
1263         case 5:
1264                 halbtc8822b2ant_coex_table(btcoexist, force_exec, 0x55555555,
1265                                            0x55555555, break_table,
1266                                            select_table);
1267                 break;
1268         case 6:
1269                 halbtc8822b2ant_coex_table(btcoexist, force_exec, 0xa5555555,
1270                                            0xfafafafa, break_table,
1271                                            select_table);
1272                 break;
1273         case 7:
1274                 halbtc8822b2ant_coex_table(btcoexist, force_exec, 0xa5555555,
1275                                            0xaa5a5a5a, break_table,
1276                                            select_table);
1277                 break;
1278         case 8:
1279                 halbtc8822b2ant_coex_table(btcoexist, force_exec, 0xa5555555,
1280                                            0xfafafafa, break_table,
1281                                            select_table);
1282                 break;
1283         case 9:
1284                 halbtc8822b2ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
1285                                            0xaaaa5aaa, break_table,
1286                                            select_table);
1287                 break;
1288         case 10:
1289                 halbtc8822b2ant_coex_table(btcoexist, force_exec, 0x55555555,
1290                                            0x5a5a555a, break_table,
1291                                            select_table);
1292                 break;
1293         default:
1294                 break;
1295         }
1296 }
1297
1298 static void
1299 halbtc8822b2ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoexist,
1300                                        bool enable)
1301 {
1302         u8 h2c_parameter[1] = {0};
1303         u32 RTL97F_8822B = 0;
1304
1305         if (RTL97F_8822B)
1306                 return;
1307
1308         if (enable)
1309                 h2c_parameter[0] |= BIT(0); /* function enable */
1310
1311         btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
1312 }
1313
1314 static void halbtc8822b2ant_ignore_wlan_act(struct btc_coexist *btcoexist,
1315                                             bool force_exec, bool enable)
1316 {
1317         coex_dm->cur_ignore_wlan_act = enable;
1318
1319         if (!force_exec) {
1320                 if (coex_dm->pre_ignore_wlan_act ==
1321                     coex_dm->cur_ignore_wlan_act)
1322                         return;
1323         }
1324         halbtc8822b2ant_set_fw_ignore_wlan_act(btcoexist, enable);
1325
1326         coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
1327 }
1328
1329 static void halbtc8822b2ant_set_lps_rpwm(struct btc_coexist *btcoexist,
1330                                          u8 lps_val, u8 rpwm_val)
1331 {
1332         u8 lps = lps_val;
1333         u8 rpwm = rpwm_val;
1334
1335         btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
1336         btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1337 }
1338
1339 static void halbtc8822b2ant_lps_rpwm(struct btc_coexist *btcoexist,
1340                                      bool force_exec, u8 lps_val, u8 rpwm_val)
1341 {
1342         coex_dm->cur_lps = lps_val;
1343         coex_dm->cur_rpwm = rpwm_val;
1344
1345         if (!force_exec) {
1346                 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
1347                     (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
1348                         return;
1349         }
1350         halbtc8822b2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
1351
1352         coex_dm->pre_lps = coex_dm->cur_lps;
1353         coex_dm->pre_rpwm = coex_dm->cur_rpwm;
1354 }
1355
1356 static void halbtc8822b2ant_ps_tdma_check_for_power_save_state(
1357         struct btc_coexist *btcoexist, bool new_ps_state)
1358 {
1359         u8 lps_mode = 0x0;
1360         u8 h2c_parameter[5] = {0, 0, 0, 0x40, 0};
1361         u32 RTL97F_8822B = 0;
1362
1363         if (RTL97F_8822B)
1364                 return;
1365
1366         btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1367
1368         if (lps_mode) { /* already under LPS state */
1369                 if (new_ps_state) {
1370                         /* keep state under LPS, do nothing. */
1371                 } else {
1372                         /* will leave LPS state, turn off psTdma first */
1373                         btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1374                                                 h2c_parameter);
1375                 }
1376         } else { /* NO PS state */
1377                 if (new_ps_state) {
1378                         /* will enter LPS state, turn off psTdma first */
1379                         btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
1380                                                 h2c_parameter);
1381                 } else {
1382                         /* keep state under NO PS state, do nothing. */
1383                 }
1384         }
1385 }
1386
1387 static bool halbtc8822b2ant_power_save_state(struct btc_coexist *btcoexist,
1388                                              u8 ps_type, u8 lps_val,
1389                                              u8 rpwm_val)
1390 {
1391         struct rtl_priv *rtlpriv = btcoexist->adapter;
1392         bool low_pwr_disable = false, result = true;
1393
1394         switch (ps_type) {
1395         case BTC_PS_WIFI_NATIVE:
1396                 coex_sta->force_lps_ctrl = false;
1397                 /* recover to original 32k low power setting */
1398                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1399                          "[BTCoex], %s == BTC_PS_WIFI_NATIVE\n", __func__);
1400
1401                 low_pwr_disable = false;
1402                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1403                                    &low_pwr_disable);
1404                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1405                 break;
1406         case BTC_PS_LPS_ON:
1407                 coex_sta->force_lps_ctrl = true;
1408                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1409                          "[BTCoex], %s == BTC_PS_LPS_ON\n", __func__);
1410
1411                 halbtc8822b2ant_ps_tdma_check_for_power_save_state(btcoexist,
1412                                                                    true);
1413                 halbtc8822b2ant_lps_rpwm(btcoexist, NORMAL_EXEC, lps_val,
1414                                          rpwm_val);
1415                 /* when coex force to enter LPS, do not enter 32k low power. */
1416                 low_pwr_disable = true;
1417                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1418                                    &low_pwr_disable);
1419                 /* power save must executed before psTdma. */
1420                 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1421                 break;
1422         case BTC_PS_LPS_OFF:
1423                 coex_sta->force_lps_ctrl = true;
1424                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1425                          "[BTCoex], %s == BTC_PS_LPS_OFF\n", __func__);
1426
1427                 halbtc8822b2ant_ps_tdma_check_for_power_save_state(btcoexist,
1428                                                                    false);
1429                 result = btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1430                                             NULL);
1431                 break;
1432         default:
1433                 break;
1434         }
1435
1436         return result;
1437 }
1438
1439 static void halbtc8822b2ant_set_fw_pstdma(struct btc_coexist *btcoexist,
1440                                           u8 byte1, u8 byte2, u8 byte3,
1441                                           u8 byte4, u8 byte5)
1442 {
1443         struct rtl_priv *rtlpriv = btcoexist->adapter;
1444         u8 h2c_parameter[5] = {0};
1445         u8 real_byte1 = byte1, real_byte5 = byte5;
1446         bool ap_enable = false, result = false;
1447         struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1448
1449         if (byte5 & BIT(2))
1450                 coex_sta->is_tdma_btautoslot = true;
1451         else
1452                 coex_sta->is_tdma_btautoslot = false;
1453
1454         /* release bt-auto slot for auto-slot hang is detected!! */
1455         if (coex_sta->is_tdma_btautoslot)
1456                 if ((coex_sta->is_tdma_btautoslot_hang) ||
1457                     (bt_link_info->slave_role))
1458                         byte5 = byte5 & 0xfb;
1459
1460         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1461                            &ap_enable);
1462
1463         if ((ap_enable) && (byte1 & BIT(4) && !(byte1 & BIT(5)))) {
1464                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1465                          "[BTCoex], %s == FW for AP mode\n", __func__);
1466
1467                 real_byte1 &= ~BIT(4);
1468                 real_byte1 |= BIT(5);
1469
1470                 real_byte5 |= BIT(5);
1471                 real_byte5 &= ~BIT(6);
1472
1473                 halbtc8822b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1474                                                  0x0, 0x0);
1475         } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
1476                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1477                          "[BTCoex], %s == Force LPS (byte1 = 0x%x)\n",
1478                          __func__, byte1);
1479
1480                 if (!halbtc8822b2ant_power_save_state(btcoexist, BTC_PS_LPS_OFF,
1481                                                       0x50, 0x4))
1482                         result = true;
1483         } else {
1484                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1485                          "[BTCoex], %s == Native LPS (byte1 = 0x%x)\n",
1486                          __func__, byte1);
1487
1488                 halbtc8822b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1489                                                  0x0, 0x0);
1490         }
1491
1492         coex_sta->is_set_ps_state_fail = result;
1493
1494         if (!coex_sta->is_set_ps_state_fail) {
1495                 h2c_parameter[0] = real_byte1;
1496                 h2c_parameter[1] = byte2;
1497                 h2c_parameter[2] = byte3;
1498                 h2c_parameter[3] = byte4;
1499                 h2c_parameter[4] = real_byte5;
1500
1501                 coex_dm->ps_tdma_para[0] = real_byte1;
1502                 coex_dm->ps_tdma_para[1] = byte2;
1503                 coex_dm->ps_tdma_para[2] = byte3;
1504                 coex_dm->ps_tdma_para[3] = byte4;
1505                 coex_dm->ps_tdma_para[4] = real_byte5;
1506
1507                 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
1508         } else {
1509                 coex_sta->cnt_set_ps_state_fail++;
1510                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1511                          "[BTCoex], %s == Force Leave LPS Fail (cnt = %d)\n",
1512                          __func__, coex_sta->cnt_set_ps_state_fail);
1513         }
1514 }
1515
1516 static void halbtc8822b2ant_ps_tdma(struct btc_coexist *btcoexist,
1517                                     bool force_exec, bool turn_on, u8 type)
1518 {
1519         struct rtl_priv *rtlpriv = btcoexist->adapter;
1520         static u8 ps_tdma_byte4_modify, pre_ps_tdma_byte4_modify;
1521         struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1522
1523         coex_dm->cur_ps_tdma_on = turn_on;
1524         coex_dm->cur_ps_tdma = type;
1525
1526         /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1527         if (bt_link_info->slave_role)
1528                 ps_tdma_byte4_modify = 0x1;
1529         else
1530                 ps_tdma_byte4_modify = 0x0;
1531
1532         if (pre_ps_tdma_byte4_modify != ps_tdma_byte4_modify) {
1533                 force_exec = true;
1534                 pre_ps_tdma_byte4_modify = ps_tdma_byte4_modify;
1535         }
1536
1537         if (!force_exec) {
1538                 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1539                     (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) {
1540                         RT_TRACE(
1541                                 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1542                                 "[BTCoex], Skip TDMA because no change TDMA(%s, %d)\n",
1543                                 (coex_dm->cur_ps_tdma_on ? "on" : "off"),
1544                                 coex_dm->cur_ps_tdma);
1545                         return;
1546                 }
1547         }
1548
1549         if (coex_dm->cur_ps_tdma_on) {
1550                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1551                          "[BTCoex], ********** TDMA(on, %d) **********\n",
1552                          coex_dm->cur_ps_tdma);
1553
1554                 btcoexist->btc_write_1byte_bitmask(
1555                         btcoexist, 0x550, 0x8, 0x1); /* enable TBTT nterrupt */
1556         } else {
1557                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1558                          "[BTCoex], ********** TDMA(off, %d) **********\n",
1559                          coex_dm->cur_ps_tdma);
1560         }
1561
1562         if (turn_on) {
1563                 switch (type) {
1564                 case 1:
1565                         halbtc8822b2ant_set_fw_pstdma(
1566                                 btcoexist, 0x61, 0x10, 0x03, 0x91,
1567                                 0x54 | ps_tdma_byte4_modify);
1568                         break;
1569                 case 2:
1570                 default:
1571                         halbtc8822b2ant_set_fw_pstdma(
1572                                 btcoexist, 0x61, 0x35, 0x03, 0x11,
1573                                 0x11 | ps_tdma_byte4_modify);
1574                         break;
1575                 case 3:
1576                         halbtc8822b2ant_set_fw_pstdma(
1577                                 btcoexist, 0x61, 0x3a, 0x3, 0x91,
1578                                 0x10 | ps_tdma_byte4_modify);
1579                         break;
1580                 case 4:
1581                         halbtc8822b2ant_set_fw_pstdma(
1582                                 btcoexist, 0x61, 0x21, 0x3, 0x91,
1583                                 0x10 | ps_tdma_byte4_modify);
1584                         break;
1585                 case 5:
1586                         halbtc8822b2ant_set_fw_pstdma(
1587                                 btcoexist, 0x61, 0x25, 0x3, 0x91,
1588                                 0x10 | ps_tdma_byte4_modify);
1589                         break;
1590                 case 6:
1591                         halbtc8822b2ant_set_fw_pstdma(
1592                                 btcoexist, 0x61, 0x10, 0x3, 0x91,
1593                                 0x10 | ps_tdma_byte4_modify);
1594                         break;
1595                 case 7:
1596                         halbtc8822b2ant_set_fw_pstdma(
1597                                 btcoexist, 0x61, 0x20, 0x3, 0x91,
1598                                 0x10 | ps_tdma_byte4_modify);
1599                         break;
1600                 case 8:
1601                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61, 0x15,
1602                                                       0x03, 0x11, 0x11);
1603                         break;
1604                 case 10:
1605                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61, 0x30,
1606                                                       0x03, 0x11, 0x10);
1607                         break;
1608                 case 11:
1609                         halbtc8822b2ant_set_fw_pstdma(
1610                                 btcoexist, 0x61, 0x35, 0x03, 0x11,
1611                                 0x10 | ps_tdma_byte4_modify);
1612                         break;
1613                 case 12:
1614                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61, 0x35,
1615                                                       0x03, 0x11, 0x11);
1616                         break;
1617                 case 13:
1618                         halbtc8822b2ant_set_fw_pstdma(
1619                                 btcoexist, 0x61, 0x1c, 0x03, 0x11,
1620                                 0x10 | ps_tdma_byte4_modify);
1621                         break;
1622                 case 14:
1623                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61, 0x20,
1624                                                       0x03, 0x11, 0x11);
1625                         break;
1626                 case 15:
1627                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61, 0x10,
1628                                                       0x03, 0x11, 0x14);
1629                         break;
1630                 case 16:
1631                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61, 0x10,
1632                                                       0x03, 0x11, 0x15);
1633                         break;
1634                 case 21:
1635                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61, 0x30,
1636                                                       0x03, 0x11, 0x10);
1637                         break;
1638                 case 22:
1639                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61, 0x25,
1640                                                       0x03, 0x11, 0x10);
1641                         break;
1642                 case 23:
1643                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x61, 0x10,
1644                                                       0x03, 0x11, 0x10);
1645                         break;
1646                 case 51:
1647                         halbtc8822b2ant_set_fw_pstdma(
1648                                 btcoexist, 0x61, 0x10, 0x03, 0x91,
1649                                 0x10 | ps_tdma_byte4_modify);
1650                         break;
1651                 case 101:
1652                         halbtc8822b2ant_set_fw_pstdma(
1653                                 btcoexist, 0x61, 0x25, 0x03, 0x11,
1654                                 0x11 | ps_tdma_byte4_modify);
1655                         break;
1656                 case 102:
1657                         halbtc8822b2ant_set_fw_pstdma(
1658                                 btcoexist, 0x61, 0x35, 0x03, 0x11,
1659                                 0x11 | ps_tdma_byte4_modify);
1660                         break;
1661                 case 103:
1662                         halbtc8822b2ant_set_fw_pstdma(
1663                                 btcoexist, 0x51, 0x3a, 0x3, 0x10,
1664                                 0x50 | ps_tdma_byte4_modify);
1665                         break;
1666                 case 104:
1667                         halbtc8822b2ant_set_fw_pstdma(
1668                                 btcoexist, 0x51, 0x21, 0x3, 0x10,
1669                                 0x50 | ps_tdma_byte4_modify);
1670                         break;
1671                 case 105:
1672                         halbtc8822b2ant_set_fw_pstdma(
1673                                 btcoexist, 0x51, 0x30, 0x3, 0x10,
1674                                 0x50 | ps_tdma_byte4_modify);
1675                         break;
1676                 case 106:
1677                         halbtc8822b2ant_set_fw_pstdma(
1678                                 btcoexist, 0x51, 0x10, 0x3, 0x10,
1679                                 0x50 | ps_tdma_byte4_modify);
1680                         break;
1681                 case 107:
1682                         halbtc8822b2ant_set_fw_pstdma(
1683                                 btcoexist, 0x51, 0x10, 0x7, 0x10,
1684                                 0x54 | ps_tdma_byte4_modify);
1685                         break;
1686                 case 108:
1687                         halbtc8822b2ant_set_fw_pstdma(
1688                                 btcoexist, 0x51, 0x30, 0x3, 0x10,
1689                                 0x50 | ps_tdma_byte4_modify);
1690                         break;
1691                 case 109:
1692                         halbtc8822b2ant_set_fw_pstdma(
1693                                 btcoexist, 0x51, 0x10, 0x03, 0x10,
1694                                 0x54 | ps_tdma_byte4_modify);
1695                         break;
1696                 case 110:
1697                         halbtc8822b2ant_set_fw_pstdma(
1698                                 btcoexist, 0x55, 0x30, 0x03, 0x10,
1699                                 0x50 | ps_tdma_byte4_modify);
1700                         break;
1701                 case 111:
1702                         halbtc8822b2ant_set_fw_pstdma(
1703                                 btcoexist, 0x61, 0x25, 0x03, 0x11,
1704                                 0x11 | ps_tdma_byte4_modify);
1705                         break;
1706                 case 151:
1707                         halbtc8822b2ant_set_fw_pstdma(
1708                                 btcoexist, 0x51, 0x10, 0x03, 0x10,
1709                                 0x50 | ps_tdma_byte4_modify);
1710                         break;
1711                 }
1712         } else {
1713                 /* disable PS tdma */
1714                 switch (type) {
1715                 case 0:
1716                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1717                                                       0x40, 0x0);
1718                         break;
1719                 case 1:
1720                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1721                                                       0x48, 0x0);
1722                         break;
1723                 default:
1724                         halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
1725                                                       0x40, 0x0);
1726                         break;
1727                 }
1728         }
1729
1730         if (!coex_sta->is_set_ps_state_fail) {
1731                 /* update pre state */
1732                 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1733                 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1734         }
1735 }
1736
1737 /*anttenna control by bb mac bt antdiv pta to write 0x4c 0xcb4,0xcbd*/
1738 static void halbtc8822b2ant_set_ext_ant_switch(struct btc_coexist *btcoexist,
1739                                                bool force_exec, u8 ctrl_type,
1740                                                u8 pos_type)
1741 {
1742         struct rtl_priv *rtlpriv = btcoexist->adapter;
1743         bool switch_polatiry_inverse = false;
1744         u8 regval_0xcbc = 0, regval_0x64;
1745         u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
1746
1747         if (!rfe_type->ext_ant_switch_exist)
1748                 return;
1749
1750         coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type;
1751
1752         if (!force_exec) {
1753                 if (coex_dm->pre_ext_ant_switch_status ==
1754                     coex_dm->cur_ext_ant_switch_status)
1755                         return;
1756         }
1757         coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status;
1758
1759         /* Ext switch buffer mux */
1760         btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
1761         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
1762         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
1763
1764         switch (ctrl_type) {
1765         default:
1766         case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW:
1767                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80,
1768                                                    0x0); /*  0x4c[23] = 0 */
1769                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01,
1770                                                    0x1); /* 0x4c[24] = 1 */
1771                 /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
1772                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff,
1773                                                    0x77);
1774
1775                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x03, 01);
1776
1777                 break;
1778         case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_PTA:
1779                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80,
1780                                                    0x0); /* 0x4c[23] = 0 */
1781                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01,
1782                                                    0x1); /* 0x4c[24] = 1 */
1783                 /* PTA,  DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
1784                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff,
1785                                                    0x66);
1786
1787                 /* 0xcb4[29:28] = 2b'10 for no switch_polatiry_inverse,
1788                  * DPDT_SEL_N =1, DPDT_SEL_P =0  @ GNT_BT=1
1789                  */
1790                 regval_0xcbc = (!switch_polatiry_inverse ? 0x2 : 0x1);
1791                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbc, 0x03,
1792                                                    regval_0xcbc);
1793
1794                 break;
1795         case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV:
1796                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80,
1797                                                    0x0); /* 0x4c[23] = 0 */
1798                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01,
1799                                                    0x1); /* 0x4c[24] = 1 */
1800                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff,
1801                                                    0x88);
1802                 break;
1803         case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_MAC:
1804                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80,
1805                                                    0x1); /*  0x4c[23] = 1 */
1806
1807                 /* 0x64[0] = 1b'0 for no switch_polatiry_inverse,
1808                  * DPDT_SEL_N =1, DPDT_SEL_P =0
1809                  */
1810                 regval_0x64 = (!switch_polatiry_inverse ? 0x0 : 0x1);
1811                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1,
1812                                                    regval_0x64);
1813                 break;
1814         case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT:
1815                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80,
1816                                                    0x0); /* 0x4c[23] = 0 */
1817                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01,
1818                                                    0x0); /* 0x4c[24] = 0 */
1819
1820                 /* no setup required, because  antenna switch control value by
1821                  * BT vendor 0x1c[1:0]
1822                  */
1823                 break;
1824         }
1825
1826         /* PAPE, LNA_ON control by BT while WLAN off for current leakage issue*/
1827         if (ctrl_type == BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT) {
1828                 btcoexist->btc_write_1byte_bitmask(
1829                         btcoexist, 0x67, 0x20, 0x0); /* PAPE   0x64[29] = 0 */
1830                 btcoexist->btc_write_1byte_bitmask(
1831                         btcoexist, 0x67, 0x10, 0x0); /* LNA_ON 0x64[28] = 0 */
1832         } else {
1833                 btcoexist->btc_write_1byte_bitmask(
1834                         btcoexist, 0x67, 0x20, 0x1); /* PAPE   0x64[29] = 1 */
1835                 btcoexist->btc_write_1byte_bitmask(
1836                         btcoexist, 0x67, 0x10, 0x1); /* LNA_ON 0x64[28] = 1 */
1837         }
1838
1839         if (btcoexist->dbg_mode_2ant) {
1840                 u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
1841                 u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c);
1842                 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff;
1843
1844                 RT_TRACE(
1845                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1846                         "[BTCoex], (After Ext Ant switch setup) 0xcb4 = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x\n",
1847                         u32tmp1, u32tmp2, u32tmp3);
1848         }
1849 }
1850
1851 /* rf4 type by efuse, and for ant at main aux inverse use,
1852  * because is 2x2, and control types are the same, does not need
1853  */
1854 static void halbtc8822b2ant_set_rfe_type(struct btc_coexist *btcoexist)
1855 {
1856         struct btc_board_info *board_info = &btcoexist->board_info;
1857
1858         rfe_type->ext_band_switch_exist = false;
1859         rfe_type->ext_band_switch_type =
1860                 BT_8822B_2ANT_EXT_BAND_SWITCH_USE_SPDT; /* SPDT; */
1861         rfe_type->ext_band_switch_ctrl_polarity = 0;
1862         /* Ext switch buffer mux */
1863         btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
1864         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
1865         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
1866
1867         if (rfe_type->ext_band_switch_exist) {
1868                 /* band switch use RFE_ctrl1 (pin name: PAPE_A) and
1869                  * RFE_ctrl3 (pin name: LNAON_A)
1870                  */
1871
1872                 /* set RFE_ctrl1 as software control */
1873                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb0, 0xf0, 0x7);
1874
1875                 /* set RFE_ctrl3 as software control */
1876                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb1, 0xf0, 0x7);
1877         }
1878
1879         /* the following setup should be got from Efuse in the future */
1880         rfe_type->rfe_module_type = board_info->rfe_type;
1881
1882         rfe_type->ext_ant_switch_ctrl_polarity = 0;
1883
1884         switch (rfe_type->rfe_module_type) {
1885         case 0:
1886         default:
1887                 rfe_type->ext_ant_switch_exist = true;
1888                 rfe_type->ext_ant_switch_type =
1889                         BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
1890                 break;
1891         case 1:
1892                 rfe_type->ext_ant_switch_exist = true;
1893                 rfe_type->ext_ant_switch_type =
1894                         BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
1895                 break;
1896         case 2:
1897                 rfe_type->ext_ant_switch_exist = true;
1898                 rfe_type->ext_ant_switch_type =
1899                         BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
1900                 break;
1901         case 3:
1902                 rfe_type->ext_ant_switch_exist = true;
1903                 rfe_type->ext_ant_switch_type =
1904                         BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
1905                 break;
1906         case 4:
1907                 rfe_type->ext_ant_switch_exist = true;
1908                 rfe_type->ext_ant_switch_type =
1909                         BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
1910                 break;
1911         case 5:
1912                 rfe_type->ext_ant_switch_exist = true;
1913                 rfe_type->ext_ant_switch_type =
1914                         BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
1915                 break;
1916         case 6:
1917                 rfe_type->ext_ant_switch_exist = true;
1918                 rfe_type->ext_ant_switch_type =
1919                         BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
1920                 break;
1921         case 7:
1922                 rfe_type->ext_ant_switch_exist = true;
1923                 rfe_type->ext_ant_switch_type =
1924                         BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
1925                 break;
1926         }
1927 }
1928
1929 /* set gnt_wl gnt_bt control by sw high low, or hwpta while in
1930  * power on, ini, wlan off, wlan only, wl2g non-currrent, wl2g current, wl5g
1931  */
1932 static void halbtc8822b2ant_set_ant_path(struct btc_coexist *btcoexist,
1933                                          u8 ant_pos_type, bool force_exec,
1934                                          u8 phase)
1935 {
1936         struct rtl_priv *rtlpriv = btcoexist->adapter;
1937         u8 u8tmp = 0;
1938         u32 u32tmp1 = 0;
1939         u32 u32tmp2 = 0, u32tmp3 = 0;
1940
1941         u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
1942
1943         /* To avoid indirect access fail  */
1944         if (((u32tmp1 & 0xf000) >> 12) != ((u32tmp1 & 0x0f00) >> 8)) {
1945                 force_exec = true;
1946                 coex_sta->gnt_error_cnt++;
1947         }
1948
1949         /* Ext switch buffer mux */
1950         btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
1951         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
1952         btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
1953         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80,
1954                                            0x0); /*  0x4c[23] = 0 */
1955         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01,
1956                                            0x1); /* 0x4c[24] = 1 */
1957
1958         coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase;
1959
1960         if (!force_exec) {
1961                 if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type)
1962                         return;
1963         }
1964
1965         coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type;
1966
1967         if (btcoexist->dbg_mode_2ant) {
1968                 u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
1969                                                                     0x38);
1970                 u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
1971                                                                     0x54);
1972                 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
1973
1974                 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
1975
1976                 RT_TRACE(
1977                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1978                         "[BTCoex], (Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
1979                         u32tmp3, u8tmp, u32tmp1, u32tmp2);
1980         }
1981
1982         switch (phase) {
1983         case BT_8822B_2ANT_PHASE_COEX_POWERON:
1984
1985                 /* set Path control owner to WL at initial step */
1986                 halbtc8822b2ant_ltecoex_pathcontrol_owner(
1987                         btcoexist, BT_8822B_2ANT_PCO_BTSIDE);
1988
1989                 /* set GNT_BT to SW high */
1990                 halbtc8822b2ant_ltecoex_set_gnt_bt(
1991                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
1992                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
1993                         BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
1994                 /* Set GNT_WL to SW high */
1995                 halbtc8822b2ant_ltecoex_set_gnt_wl(
1996                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
1997                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
1998                         BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
1999
2000                 coex_sta->run_time_state = false;
2001
2002                 break;
2003         case BT_8822B_2ANT_PHASE_COEX_INIT:
2004                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80,
2005                                                    0x0); /*  0x4c[23] = 0 */
2006                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01,
2007                                                    0x1); /* 0x4c[24] = 1 */
2008                 /* Disable LTE Coex Function in WiFi side
2009                  * (this should be on if LTE coex is required)
2010                  */
2011                 halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
2012
2013                 /* GNT_WL_LTE always = 1
2014                  * (this should be config if LTE coex is required)
2015                  */
2016                 halbtc8822b2ant_ltecoex_set_coex_table(
2017                         btcoexist, BT_8822B_2ANT_CTT_WL_VS_LTE, 0xffff);
2018
2019                 /* GNT_BT_LTE always = 1
2020                  * (this should be config if LTE coex is required)
2021                  */
2022                 halbtc8822b2ant_ltecoex_set_coex_table(
2023                         btcoexist, BT_8822B_2ANT_CTT_BT_VS_LTE, 0xffff);
2024
2025                 /* set Path control owner to WL at initial step */
2026                 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2027                         btcoexist, BT_8822B_2ANT_PCO_WLSIDE);
2028
2029                 /* set GNT_BT to SW high */
2030                 halbtc8822b2ant_ltecoex_set_gnt_bt(
2031                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2032                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2033                         BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2034                 /* Set GNT_WL to SW high */
2035                 halbtc8822b2ant_ltecoex_set_gnt_wl(
2036                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2037                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2038                         BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2039
2040                 coex_sta->run_time_state = false;
2041
2042                 break;
2043         case BT_8822B_2ANT_PHASE_WLANONLY_INIT:
2044                 /* Disable LTE Coex Function in WiFi side
2045                  * (this should be on if LTE coex is required)
2046                  */
2047                 halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
2048
2049                 /* GNT_WL_LTE always = 1
2050                  * (this should be config if LTE coex is required)
2051                  */
2052                 halbtc8822b2ant_ltecoex_set_coex_table(
2053                         btcoexist, BT_8822B_2ANT_CTT_WL_VS_LTE, 0xffff);
2054
2055                 /* GNT_BT_LTE always = 1
2056                  * (this should be config if LTE coex is required)
2057                  */
2058                 halbtc8822b2ant_ltecoex_set_coex_table(
2059                         btcoexist, BT_8822B_2ANT_CTT_BT_VS_LTE, 0xffff);
2060
2061                 /* set Path control owner to WL at initial step */
2062                 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2063                         btcoexist, BT_8822B_2ANT_PCO_WLSIDE);
2064
2065                 /* set GNT_BT to SW Low */
2066                 halbtc8822b2ant_ltecoex_set_gnt_bt(
2067                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2068                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2069                         BT_8822B_2ANT_SIG_STA_SET_TO_LOW);
2070                 /* Set GNT_WL to SW high */
2071                 halbtc8822b2ant_ltecoex_set_gnt_wl(
2072                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2073                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2074                         BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2075
2076                 coex_sta->run_time_state = false;
2077
2078                 break;
2079         case BT_8822B_2ANT_PHASE_WLAN_OFF:
2080                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80,
2081                                                    0x0); /* 0x4c[23] = 0 */
2082                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01,
2083                                                    0x0); /* 0x4c[24] = 0 */
2084                 /* Disable LTE Coex Function in WiFi side */
2085                 halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
2086
2087                 /* set Path control owner to BT */
2088                 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2089                         btcoexist, BT_8822B_2ANT_PCO_BTSIDE);
2090
2091                 /* Set Ext Ant Switch to BT control at wifi off step */
2092                 halbtc8822b2ant_set_ext_ant_switch(
2093                         btcoexist, FORCE_EXEC,
2094                         BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT,
2095                         BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE);
2096                 coex_sta->run_time_state = false;
2097                 break;
2098         case BT_8822B_2ANT_PHASE_2G_RUNTIME:
2099         case BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT:
2100
2101                 /* set Path control owner to WL at runtime step */
2102                 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2103                         btcoexist, BT_8822B_2ANT_PCO_WLSIDE);
2104                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff,
2105                                                    0x66);
2106                 if (phase == BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT) {
2107                         /* set GNT_BT to PTA */
2108                         halbtc8822b2ant_ltecoex_set_gnt_bt(
2109                                 btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2110                                 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA,
2111                                 BT_8822B_2ANT_SIG_STA_SET_BY_HW);
2112
2113                         /* Set GNT_WL to SW High */
2114                         halbtc8822b2ant_ltecoex_set_gnt_wl(
2115                                 btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2116                                 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2117                                 BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2118                 } else {
2119                         /* set GNT_BT to PTA */
2120                         halbtc8822b2ant_ltecoex_set_gnt_bt(
2121                                 btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2122                                 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA,
2123                                 BT_8822B_2ANT_SIG_STA_SET_BY_HW);
2124
2125                         /* Set GNT_WL to PTA */
2126                         halbtc8822b2ant_ltecoex_set_gnt_wl(
2127                                 btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2128                                 BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA,
2129                                 BT_8822B_2ANT_SIG_STA_SET_BY_HW);
2130                 }
2131
2132                 RT_TRACE(
2133                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2134                         "[BTCoex], ************* under2g 0xcbd setting =2 *************\n");
2135
2136                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x03, 02);
2137                 break;
2138
2139         case BT_8822B_2ANT_PHASE_5G_RUNTIME:
2140
2141                 /* set Path control owner to WL at runtime step */
2142                 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2143                         btcoexist, BT_8822B_2ANT_PCO_WLSIDE);
2144
2145                 /* set GNT_BT to SW Hi */
2146                 halbtc8822b2ant_ltecoex_set_gnt_bt(
2147                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2148                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2149                         BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2150                 /* Set GNT_WL to SW Hi */
2151                 halbtc8822b2ant_ltecoex_set_gnt_wl(
2152                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2153                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2154                         BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2155                 coex_sta->run_time_state = true;
2156
2157                 RT_TRACE(
2158                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2159                         "[BTCoex], ************* under5g 0xcbd setting =1 *************\n");
2160
2161                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x03, 01);
2162
2163                 break;
2164         case BT_8822B_2ANT_PHASE_BTMPMODE:
2165                 /* Disable LTE Coex Function in WiFi side */
2166                 halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
2167
2168                 /* set Path control owner to WL */
2169                 halbtc8822b2ant_ltecoex_pathcontrol_owner(
2170                         btcoexist, BT_8822B_2ANT_PCO_WLSIDE);
2171
2172                 /* set GNT_BT to SW Hi */
2173                 halbtc8822b2ant_ltecoex_set_gnt_bt(
2174                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2175                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2176                         BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
2177
2178                 /* Set GNT_WL to SW Lo */
2179                 halbtc8822b2ant_ltecoex_set_gnt_wl(
2180                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
2181                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
2182                         BT_8822B_2ANT_SIG_STA_SET_TO_LOW);
2183
2184                 coex_sta->run_time_state = false;
2185                 break;
2186         }
2187
2188         if (btcoexist->dbg_mode_2ant) {
2189                 u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
2190                                                                     0x38);
2191                 u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
2192                                                                     0x54);
2193                 u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
2194                 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
2195
2196                 RT_TRACE(
2197                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2198                         "[BTCoex], (After Ant-Setup phase---%d) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
2199                         phase, u32tmp3, u8tmp, u32tmp1, u32tmp2);
2200         }
2201 }
2202
2203 static u8 halbtc8822b2ant_action_algorithm(struct btc_coexist *btcoexist)
2204 {
2205         struct rtl_priv *rtlpriv = btcoexist->adapter;
2206         struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2207         bool bt_hs_on = false;
2208         u8 algorithm = BT_8822B_2ANT_COEX_ALGO_UNDEFINED;
2209         u8 num_of_diff_profile = 0;
2210
2211         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2212
2213         if (!bt_link_info->bt_link_exist) {
2214                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2215                          "[BTCoex], No BT link exists!!!\n");
2216                 return algorithm;
2217         }
2218
2219         if (bt_link_info->sco_exist)
2220                 num_of_diff_profile++;
2221         if (bt_link_info->hid_exist)
2222                 num_of_diff_profile++;
2223         if (bt_link_info->pan_exist)
2224                 num_of_diff_profile++;
2225         if (bt_link_info->a2dp_exist)
2226                 num_of_diff_profile++;
2227
2228         if (num_of_diff_profile == 0) {
2229                 if (bt_link_info->acl_busy) {
2230                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2231                                  "[BTCoex], No-Profile busy\n");
2232                         algorithm = BT_8822B_2ANT_COEX_ALGO_NOPROFILEBUSY;
2233                 }
2234         } else if ((bt_link_info->a2dp_exist) && (coex_sta->is_bt_a2dp_sink)) {
2235                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2236                          "[BTCoex], A2DP Sink\n");
2237                 algorithm = BT_8822B_2ANT_COEX_ALGO_A2DPSINK;
2238         } else if (num_of_diff_profile == 1) {
2239                 if (bt_link_info->sco_exist) {
2240                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2241                                  "[BTCoex], SCO only\n");
2242                         algorithm = BT_8822B_2ANT_COEX_ALGO_SCO;
2243                 } else {
2244                         if (bt_link_info->hid_exist) {
2245                                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2246                                          "[BTCoex], HID only\n");
2247                                 algorithm = BT_8822B_2ANT_COEX_ALGO_HID;
2248                         } else if (bt_link_info->a2dp_exist) {
2249                                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2250                                          "[BTCoex], A2DP only\n");
2251                                 algorithm = BT_8822B_2ANT_COEX_ALGO_A2DP;
2252                         } else if (bt_link_info->pan_exist) {
2253                                 if (bt_hs_on) {
2254                                         RT_TRACE(rtlpriv, COMP_BT_COEXIST,
2255                                                  DBG_LOUD,
2256                                                  "[BTCoex], PAN(HS) only\n");
2257                                         algorithm =
2258                                                 BT_8822B_2ANT_COEX_ALGO_PANHS;
2259                                 } else {
2260                                         RT_TRACE(rtlpriv, COMP_BT_COEXIST,
2261                                                  DBG_LOUD,
2262                                                  "[BTCoex], PAN(EDR) only\n");
2263                                         algorithm =
2264                                                 BT_8822B_2ANT_COEX_ALGO_PANEDR;
2265                                 }
2266                         }
2267                 }
2268         } else if (num_of_diff_profile == 2) {
2269                 if (bt_link_info->sco_exist) {
2270                         if (bt_link_info->hid_exist) {
2271                                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2272                                          "[BTCoex], SCO + HID\n");
2273                                 algorithm = BT_8822B_2ANT_COEX_ALGO_SCO;
2274                         } else if (bt_link_info->a2dp_exist) {
2275                                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2276                                          "[BTCoex], SCO + A2DP ==> A2DP\n");
2277                                 algorithm = BT_8822B_2ANT_COEX_ALGO_A2DP;
2278                         } else if (bt_link_info->pan_exist) {
2279                                 if (bt_hs_on) {
2280                                         RT_TRACE(rtlpriv, COMP_BT_COEXIST,
2281                                                  DBG_LOUD,
2282                                                  "[BTCoex], SCO + PAN(HS)\n");
2283                                         algorithm = BT_8822B_2ANT_COEX_ALGO_SCO;
2284                                 } else {
2285                                         RT_TRACE(rtlpriv, COMP_BT_COEXIST,
2286                                                  DBG_LOUD,
2287                                                  "[BTCoex], SCO + PAN(EDR)\n");
2288                                         algorithm =
2289                                                 BT_8822B_2ANT_COEX_ALGO_PANEDR;
2290                                 }
2291                         }
2292                 } else {
2293                         if (bt_link_info->hid_exist &&
2294                             bt_link_info->a2dp_exist) {
2295                                 {
2296                                         RT_TRACE(rtlpriv, COMP_BT_COEXIST,
2297                                                  DBG_LOUD,
2298                                                  "[BTCoex], HID + A2DP\n");
2299                                         algorithm =
2300                                             BT_8822B_2ANT_COEX_ALGO_HID_A2DP;
2301                                 }
2302                         } else if (bt_link_info->hid_exist &&
2303                                    bt_link_info->pan_exist) {
2304                                 if (bt_hs_on) {
2305                                         RT_TRACE(rtlpriv, COMP_BT_COEXIST,
2306                                                  DBG_LOUD,
2307                                                  "[BTCoex], HID + PAN(HS)\n");
2308                                         algorithm = BT_8822B_2ANT_COEX_ALGO_HID;
2309                                 } else {
2310                                         RT_TRACE(rtlpriv, COMP_BT_COEXIST,
2311                                                  DBG_LOUD,
2312                                                  "[BTCoex], HID + PAN(EDR)\n");
2313                                         algorithm =
2314                                             BT_8822B_2ANT_COEX_ALGO_PANEDR_HID;
2315                                 }
2316                         } else if (bt_link_info->pan_exist &&
2317                                    bt_link_info->a2dp_exist) {
2318                                 if (bt_hs_on) {
2319                                         RT_TRACE(rtlpriv, COMP_BT_COEXIST,
2320                                                  DBG_LOUD,
2321                                                  "[BTCoex], A2DP + PAN(HS)\n");
2322                                         algorithm =
2323                                             BT_8822B_2ANT_COEX_ALGO_A2DP_PANHS;
2324                                 } else {
2325                                         RT_TRACE(rtlpriv, COMP_BT_COEXIST,
2326                                                  DBG_LOUD,
2327                                                  "[BTCoex], A2DP + PAN(EDR)\n");
2328                                         algorithm =
2329                                             BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP;
2330                                 }
2331                         }
2332                 }
2333         } else if (num_of_diff_profile == 3) {
2334                 if (bt_link_info->sco_exist) {
2335                         if (bt_link_info->hid_exist &&
2336                             bt_link_info->a2dp_exist) {
2337                                 RT_TRACE(
2338                                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2339                                         "[BTCoex], SCO + HID + A2DP ==> HID + A2DP\n");
2340                                 algorithm = BT_8822B_2ANT_COEX_ALGO_HID_A2DP;
2341                         } else if (bt_link_info->hid_exist &&
2342                                    bt_link_info->pan_exist) {
2343                                 if (bt_hs_on) {
2344                                         RT_TRACE(
2345                                                 rtlpriv, COMP_BT_COEXIST,
2346                                                 DBG_LOUD,
2347                                                 "[BTCoex], SCO + HID + PAN(HS)\n");
2348                                         algorithm =
2349                                             BT_8822B_2ANT_COEX_ALGO_PANEDR_HID;
2350                                 } else {
2351                                         RT_TRACE(
2352                                                 rtlpriv, COMP_BT_COEXIST,
2353                                                 DBG_LOUD,
2354                                                 "[BTCoex], SCO + HID + PAN(EDR)\n");
2355                                         algorithm =
2356                                             BT_8822B_2ANT_COEX_ALGO_PANEDR_HID;
2357                                 }
2358                         } else if (bt_link_info->pan_exist &&
2359                                    bt_link_info->a2dp_exist) {
2360                                 if (bt_hs_on) {
2361                                         RT_TRACE(
2362                                                 rtlpriv, COMP_BT_COEXIST,
2363                                                 DBG_LOUD,
2364                                                 "[BTCoex], SCO + A2DP + PAN(HS)\n");
2365                                         algorithm =
2366                                             BT_8822B_2ANT_COEX_ALGO_A2DP_PANHS;
2367                                 } else {
2368                                         RT_TRACE(
2369                                                 rtlpriv, COMP_BT_COEXIST,
2370                                                 DBG_LOUD,
2371                                                 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
2372                                         algorithm =
2373                                             BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP;
2374                                 }
2375                         }
2376                 } else {
2377                         if (bt_link_info->hid_exist &&
2378                             bt_link_info->pan_exist &&
2379                             bt_link_info->a2dp_exist) {
2380                                 if (bt_hs_on) {
2381                                         RT_TRACE(
2382                                                 rtlpriv, COMP_BT_COEXIST,
2383                                                 DBG_LOUD,
2384                                                 "[BTCoex], HID + A2DP + PAN(HS)\n");
2385                                         algorithm =
2386                                         BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
2387                                 } else {
2388                                         RT_TRACE(
2389                                                 rtlpriv, COMP_BT_COEXIST,
2390                                                 DBG_LOUD,
2391                                                 "[BTCoex], HID + A2DP + PAN(EDR)\n");
2392                                         algorithm =
2393                                         BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
2394                                 }
2395                         }
2396                 }
2397         } else if (num_of_diff_profile >= 3) {
2398                 if (bt_link_info->sco_exist) {
2399                         if (bt_link_info->hid_exist &&
2400                             bt_link_info->pan_exist &&
2401                             bt_link_info->a2dp_exist) {
2402                                 if (bt_hs_on) {
2403                                         RT_TRACE(
2404                                                 rtlpriv, COMP_BT_COEXIST,
2405                                                 DBG_LOUD,
2406                                                 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
2407                                         algorithm =
2408                                         BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
2409                                 } else {
2410                                         RT_TRACE(
2411                                                 rtlpriv, COMP_BT_COEXIST,
2412                                                 DBG_LOUD,
2413                                                 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
2414                                         algorithm =
2415                                         BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
2416                                 }
2417                         }
2418                 }
2419         }
2420
2421         return algorithm;
2422 }
2423
2424 static void halbtc8822b2ant_action_coex_all_off(struct btc_coexist *btcoexist)
2425 {
2426         halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2427
2428         /* fw all off */
2429         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2430
2431         halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2432 }
2433
2434 static void halbtc8822b2ant_action_wifi_under5g(struct btc_coexist *btcoexist)
2435 {
2436         struct rtl_priv *rtlpriv = btcoexist->adapter;
2437
2438         /* fw all off */
2439         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2440                  "[BTCoex], ************* under5g *************\n");
2441         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2442         halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2443
2444         halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2445
2446         halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
2447                                      BT_8822B_2ANT_PHASE_5G_RUNTIME);
2448 }
2449
2450 static void
2451 halbtc8822b2ant_action_wifi_native_lps(struct btc_coexist *btcoexist)
2452 {
2453         halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2454
2455         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2456 }
2457
2458 static void halbtc8822b2ant_action_bt_inquiry(struct btc_coexist *btcoexist)
2459 {
2460         struct rtl_priv *rtlpriv = btcoexist->adapter;
2461         bool wifi_connected = false;
2462         bool wifi_scan = false, wifi_link = false, wifi_roam = false;
2463         bool wifi_busy = false;
2464         struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2465
2466         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2467
2468         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2469                            &wifi_connected);
2470
2471         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
2472         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link);
2473         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam);
2474
2475         if ((coex_sta->bt_create_connection) &&
2476             ((wifi_link) || (wifi_roam) || (wifi_scan) || (wifi_busy) ||
2477              (coex_sta->wifi_is_high_pri_task))) {
2478                 RT_TRACE(
2479                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2480                         "[BTCoex], Wifi link/roam/Scan/busy/hi-pri-task + BT Inq/Page!!\n");
2481
2482                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2483
2484                 if ((bt_link_info->a2dp_exist) && (!bt_link_info->pan_exist))
2485                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2486                                                 15);
2487                 else
2488                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2489                                                 11);
2490         } else if ((!wifi_connected) && (!wifi_scan)) {
2491                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2492                          "[BTCoex], Wifi no-link + no-scan + BT Inq/Page!!\n");
2493
2494                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2495
2496                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2497         } else if (bt_link_info->pan_exist) {
2498                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2499
2500                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2501
2502         } else if (bt_link_info->a2dp_exist) {
2503                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 8);
2504
2505                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
2506                                                      10);
2507         } else {
2508                 if ((wifi_link) || (wifi_roam) || (wifi_scan) || (wifi_busy) ||
2509                     (coex_sta->wifi_is_high_pri_task))
2510                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2511                                                 21);
2512                 else
2513                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2514                                                 23);
2515
2516                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2517         }
2518
2519         halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd8);
2520 }
2521
2522 static void
2523 halbtc8822b2ant_action_wifi_link_process(struct btc_coexist *btcoexist)
2524 {
2525         struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2526
2527         halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd4);
2528
2529         halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2530
2531         if (bt_link_info->pan_exist) {
2532                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
2533
2534                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2535
2536         } else if (bt_link_info->a2dp_exist) {
2537                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 16);
2538
2539                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2540         } else {
2541                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21);
2542
2543                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2544         }
2545 }
2546
2547 static void
2548 halbtc8822b2ant_action_wifi_nonconnected(struct btc_coexist *btcoexist)
2549 {
2550         halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2551
2552         /* fw all off */
2553         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2554
2555         halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2556 }
2557
2558 static void halbtc8822b2ant_action_bt_relink(struct btc_coexist *btcoexist)
2559 {
2560         struct rtl_priv *rtlpriv = btcoexist->adapter;
2561
2562         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2563                  "[BTCoex], run bt multi link function\n");
2564
2565         if (coex_sta->is_bt_multi_link)
2566                 return;
2567         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2568                  "[BTCoex], run bt re-link function\n");
2569
2570         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2571         halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2572 }
2573
2574 static void halbtc8822b2ant_action_bt_idle(struct btc_coexist *btcoexist)
2575 {
2576         bool wifi_busy = false;
2577
2578         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2579
2580         if (!wifi_busy) {
2581                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2582
2583                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
2584         } else { /* if wl busy */
2585
2586                 if (BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2587                     coex_dm->bt_status) {
2588                         halbtc8822b2ant_coex_table_with_type(btcoexist,
2589                                                              NORMAL_EXEC, 0);
2590
2591                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
2592                                                 0);
2593                 } else {
2594                         halbtc8822b2ant_coex_table_with_type(btcoexist,
2595                                                              NORMAL_EXEC, 8);
2596                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2597                                                 12);
2598                 }
2599         }
2600
2601         halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd8);
2602 }
2603
2604 /* SCO only or SCO+PAN(HS) */
2605 static void halbtc8822b2ant_action_sco(struct btc_coexist *btcoexist)
2606 {
2607         static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
2608         static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
2609         u8 wifi_rssi_state, bt_rssi_state;
2610
2611         static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
2612         static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
2613         u8 wifi_rssi_state2, bt_rssi_state2;
2614         bool wifi_busy = false;
2615         u32 wifi_bw = 1;
2616
2617         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2618
2619         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2620
2621         wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(
2622                 btcoexist, &prewifi_rssi_state, 2, coex_sta->wifi_coex_thres,
2623                 0);
2624
2625         wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(
2626                 btcoexist, &prewifi_rssi_state2, 2, coex_sta->wifi_coex_thres2,
2627                 0);
2628
2629         bt_rssi_state = halbtc8822b2ant_bt_rssi_state(
2630                 btcoexist, &pre_bt_rssi_state, 2, coex_sta->bt_coex_thres, 0);
2631
2632         bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(
2633                 btcoexist, &pre_bt_rssi_state2, 2, coex_sta->bt_coex_thres2, 0);
2634
2635         if (BTC_RSSI_HIGH(wifi_rssi_state) && BTC_RSSI_HIGH(bt_rssi_state)) {
2636                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2637                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2638
2639                 coex_dm->is_switch_to_1dot5_ant = false;
2640
2641                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
2642
2643                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2644         } else {
2645                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2646                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2647
2648                 coex_dm->is_switch_to_1dot5_ant = false;
2649
2650                 if (coex_sta->is_esco_mode)
2651                         halbtc8822b2ant_coex_table_with_type(btcoexist,
2652                                                              NORMAL_EXEC, 1);
2653                 else /* 2-Ant free run if SCO mode */
2654                         halbtc8822b2ant_coex_table_with_type(btcoexist,
2655                                                              NORMAL_EXEC, 0);
2656
2657                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 8);
2658         }
2659 }
2660
2661 static void halbtc8822b2ant_action_hid(struct btc_coexist *btcoexist)
2662 {
2663         static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
2664         static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
2665         u8 wifi_rssi_state, bt_rssi_state;
2666
2667         static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
2668         static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
2669         u8 wifi_rssi_state2, bt_rssi_state2;
2670         bool wifi_busy = false;
2671         u32 wifi_bw = 1;
2672
2673         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2674         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2675
2676         wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(
2677                 btcoexist, &prewifi_rssi_state, 2, coex_sta->wifi_coex_thres,
2678                 0);
2679
2680         wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(
2681                 btcoexist, &prewifi_rssi_state2, 2, coex_sta->wifi_coex_thres2,
2682                 0);
2683
2684         bt_rssi_state = halbtc8822b2ant_bt_rssi_state(
2685                 btcoexist, &pre_bt_rssi_state, 2, coex_sta->bt_coex_thres, 0);
2686
2687         bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(
2688                 btcoexist, &pre_bt_rssi_state2, 2, coex_sta->bt_coex_thres2, 0);
2689
2690         if (BTC_RSSI_HIGH(wifi_rssi_state) && BTC_RSSI_HIGH(bt_rssi_state)) {
2691                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2692                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2693
2694                 coex_dm->is_switch_to_1dot5_ant = false;
2695
2696                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2697
2698                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2699         } else {
2700                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2701                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2702
2703                 coex_dm->is_switch_to_1dot5_ant = false;
2704
2705                 if (coex_sta->is_hid_low_pri_tx_overhead) {
2706                         halbtc8822b2ant_coex_table_with_type(btcoexist,
2707                                                              NORMAL_EXEC, 4);
2708                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2709                                                 108);
2710                 } else if (wifi_bw == 0) { /* if 11bg mode */
2711
2712                         halbtc8822b2ant_coex_table_with_type(btcoexist,
2713                                                              NORMAL_EXEC, 8);
2714                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2715                                                 111);
2716                 } else {
2717                         halbtc8822b2ant_coex_table_with_type(btcoexist,
2718                                                              NORMAL_EXEC, 8);
2719                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2720                                                 111);
2721                 }
2722         }
2723 }
2724
2725 static void halbtc8822b2ant_action_a2dpsink(struct btc_coexist *btcoexist)
2726 {
2727         struct rtl_priv *rtlpriv = btcoexist->adapter;
2728         static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
2729         static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
2730         u8 wifi_rssi_state, bt_rssi_state;
2731
2732         static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
2733         static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
2734         u8 wifi_rssi_state2, bt_rssi_state2;
2735         bool wifi_busy = false, wifi_turbo = false;
2736
2737         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2738         btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
2739                            &coex_sta->scan_ap_num);
2740         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2741                  "############# [BTCoex],  scan_ap_num = %d, wl_noisy = %d\n",
2742                  coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
2743
2744         if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
2745                 wifi_turbo = true;
2746
2747         wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(
2748                 btcoexist, &prewifi_rssi_state, 2, coex_sta->wifi_coex_thres,
2749                 0);
2750
2751         wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(
2752                 btcoexist, &prewifi_rssi_state2, 2, coex_sta->wifi_coex_thres2,
2753                 0);
2754
2755         bt_rssi_state = halbtc8822b2ant_bt_rssi_state(
2756                 btcoexist, &pre_bt_rssi_state, 2, coex_sta->bt_coex_thres, 0);
2757
2758         bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(
2759                 btcoexist, &pre_bt_rssi_state2, 2, coex_sta->bt_coex_thres2, 0);
2760
2761         if (BTC_RSSI_HIGH(wifi_rssi_state) && BTC_RSSI_HIGH(bt_rssi_state)) {
2762                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2763                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2764
2765                 coex_dm->is_switch_to_1dot5_ant = false;
2766
2767                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2768
2769                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2770         } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
2771                    BTC_RSSI_HIGH(bt_rssi_state2)) {
2772                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
2773                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2774
2775                 coex_dm->is_switch_to_1dot5_ant = false;
2776
2777                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2778
2779                 if (wifi_busy)
2780                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2781                                                 1);
2782                 else
2783                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2784                                                 16);
2785         } else {
2786                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2787                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2788
2789                 coex_dm->is_switch_to_1dot5_ant = true;
2790
2791                 if ((coex_sta->bt_relink_downcount != 0) && (wifi_busy)) {
2792                         RT_TRACE(
2793                                 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2794                                 "############# [BTCoex],  BT Re-Link + A2DP + WL busy\n");
2795
2796                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
2797                                                 0);
2798                         halbtc8822b2ant_coex_table_with_type(btcoexist,
2799                                                              NORMAL_EXEC, 5);
2800
2801                 } else {
2802                         halbtc8822b2ant_coex_table_with_type(btcoexist,
2803                                                              NORMAL_EXEC, 8);
2804                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2805                                                 105);
2806                 }
2807         }
2808 }
2809
2810 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
2811 static void halbtc8822b2ant_action_a2dp(struct btc_coexist *btcoexist)
2812 {
2813         struct rtl_priv *rtlpriv = btcoexist->adapter;
2814         static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
2815         static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
2816         u8 wifi_rssi_state, bt_rssi_state;
2817
2818         static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
2819         static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
2820         u8 wifi_rssi_state2, bt_rssi_state2;
2821         bool wifi_busy = false, wifi_turbo = false;
2822
2823         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2824         btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
2825                            &coex_sta->scan_ap_num);
2826         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2827                  "############# [BTCoex],  scan_ap_num = %d, wl_noisy = %d\n",
2828                  coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
2829
2830         if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
2831                 wifi_turbo = true;
2832
2833         wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(
2834                 btcoexist, &prewifi_rssi_state, 2, coex_sta->wifi_coex_thres,
2835                 0);
2836
2837         wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(
2838                 btcoexist, &prewifi_rssi_state2, 2, coex_sta->wifi_coex_thres2,
2839                 0);
2840
2841         bt_rssi_state = halbtc8822b2ant_bt_rssi_state(
2842                 btcoexist, &pre_bt_rssi_state, 2, coex_sta->bt_coex_thres, 0);
2843
2844         bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(
2845                 btcoexist, &pre_bt_rssi_state2, 2, coex_sta->bt_coex_thres2, 0);
2846
2847         if (BTC_RSSI_HIGH(wifi_rssi_state) && BTC_RSSI_HIGH(bt_rssi_state)) {
2848                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2849                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2850
2851                 coex_dm->is_switch_to_1dot5_ant = false;
2852
2853                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2854
2855                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2856         } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
2857                    BTC_RSSI_HIGH(bt_rssi_state2)) {
2858                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
2859                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2860
2861                 coex_dm->is_switch_to_1dot5_ant = false;
2862
2863                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2864
2865                 if (wifi_busy)
2866                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2867                                                 1);
2868                 else
2869                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2870                                                 16);
2871         } else {
2872                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2873                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2874
2875                 coex_dm->is_switch_to_1dot5_ant = true;
2876
2877                 if ((coex_sta->bt_relink_downcount != 0) && (wifi_busy)) {
2878                         RT_TRACE(
2879                                 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2880                                 "############# [BTCoex],  BT Re-Link + A2DP + WL busy\n");
2881
2882                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
2883                                                 0);
2884                         halbtc8822b2ant_coex_table_with_type(btcoexist,
2885                                                              NORMAL_EXEC, 5);
2886
2887                 } else {
2888                         if (wifi_turbo)
2889                                 halbtc8822b2ant_coex_table_with_type(
2890                                         btcoexist, NORMAL_EXEC, 10);
2891                         else
2892                                 halbtc8822b2ant_coex_table_with_type(
2893                                         btcoexist, NORMAL_EXEC, 10);
2894
2895                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2896                                                 109);
2897                 }
2898         }
2899 }
2900
2901 static void halbtc8822b2ant_action_pan_edr(struct btc_coexist *btcoexist)
2902 {
2903         struct rtl_priv *rtlpriv = btcoexist->adapter;
2904         static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
2905         static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
2906         u8 wifi_rssi_state, bt_rssi_state;
2907
2908         static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
2909         static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
2910         u8 wifi_rssi_state2, bt_rssi_state2;
2911         bool wifi_busy = false, wifi_turbo = false;
2912
2913         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2914         btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
2915                            &coex_sta->scan_ap_num);
2916         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2917                  "############# [BTCoex],  scan_ap_num = %d, wl_noisy = %d\n",
2918                  coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
2919
2920         if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
2921                 wifi_turbo = true;
2922
2923         wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(
2924                 btcoexist, &prewifi_rssi_state, 2, coex_sta->wifi_coex_thres,
2925                 0);
2926
2927         wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(
2928                 btcoexist, &prewifi_rssi_state2, 2, coex_sta->wifi_coex_thres2,
2929                 0);
2930
2931         bt_rssi_state = halbtc8822b2ant_bt_rssi_state(
2932                 btcoexist, &pre_bt_rssi_state, 2, coex_sta->bt_coex_thres, 0);
2933
2934         bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(
2935                 btcoexist, &pre_bt_rssi_state2, 2, coex_sta->bt_coex_thres2, 0);
2936
2937         if (BTC_RSSI_HIGH(wifi_rssi_state) && BTC_RSSI_HIGH(bt_rssi_state)) {
2938                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2939                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2940
2941                 coex_dm->is_switch_to_1dot5_ant = false;
2942
2943                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2944
2945                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2946         } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
2947                    BTC_RSSI_HIGH(bt_rssi_state2)) {
2948                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
2949                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
2950
2951                 coex_dm->is_switch_to_1dot5_ant = false;
2952
2953                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
2954
2955                 if (wifi_busy)
2956                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2957                                                 3);
2958                 else
2959                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2960                                                 4);
2961         } else {
2962                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
2963                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
2964
2965                 coex_dm->is_switch_to_1dot5_ant = true;
2966
2967                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
2968
2969                 if (wifi_busy)
2970                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2971                                                 103);
2972                 else
2973                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
2974                                                 104);
2975         }
2976 }
2977
2978 static void halbtc8822b2ant_action_hid_a2dp(struct btc_coexist *btcoexist)
2979 {
2980         struct rtl_priv *rtlpriv = btcoexist->adapter;
2981         static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
2982         static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
2983         u8 wifi_rssi_state, bt_rssi_state;
2984
2985         static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
2986         static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
2987         u8 wifi_rssi_state2, bt_rssi_state2;
2988         bool wifi_busy = false;
2989         u32 wifi_bw = 1;
2990
2991         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2992
2993         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2994
2995         wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(
2996                 btcoexist, &prewifi_rssi_state, 2, coex_sta->wifi_coex_thres,
2997                 0);
2998
2999         wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(
3000                 btcoexist, &prewifi_rssi_state2, 2, coex_sta->wifi_coex_thres2,
3001                 0);
3002
3003         bt_rssi_state = halbtc8822b2ant_bt_rssi_state(
3004                 btcoexist, &pre_bt_rssi_state, 2, coex_sta->bt_coex_thres, 0);
3005
3006         bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(
3007                 btcoexist, &pre_bt_rssi_state2, 2, coex_sta->bt_coex_thres2, 0);
3008
3009         if (BTC_RSSI_HIGH(wifi_rssi_state) && BTC_RSSI_HIGH(bt_rssi_state)) {
3010                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3011                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3012
3013                 coex_dm->is_switch_to_1dot5_ant = false;
3014
3015                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3016                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3017         } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
3018                    BTC_RSSI_HIGH(bt_rssi_state2)) {
3019                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
3020                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3021
3022                 coex_dm->is_switch_to_1dot5_ant = false;
3023
3024                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3025
3026                 if (wifi_busy)
3027                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3028                                                 1);
3029                 else
3030                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3031                                                 16);
3032         } else {
3033                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3034                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3035
3036                 coex_dm->is_switch_to_1dot5_ant = true;
3037
3038                 if ((coex_sta->bt_relink_downcount != 0) && (wifi_busy)) {
3039                         RT_TRACE(
3040                                 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3041                                 "############# [BTCoex],  BT Re-Link + A2DP + WL busy\n");
3042
3043                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
3044                                                 0);
3045                         halbtc8822b2ant_coex_table_with_type(btcoexist,
3046                                                              NORMAL_EXEC, 5);
3047                 } else {
3048                         halbtc8822b2ant_coex_table_with_type(btcoexist,
3049                                                              NORMAL_EXEC, 8);
3050                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3051                                                 109);
3052                 }
3053         }
3054 }
3055
3056 static void halbtc8822b2ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist)
3057 {
3058         struct rtl_priv *rtlpriv = btcoexist->adapter;
3059         static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3060         static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3061         u8 wifi_rssi_state, bt_rssi_state;
3062
3063         static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3064         static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3065         u8 wifi_rssi_state2, bt_rssi_state2;
3066         bool wifi_busy = false, wifi_turbo = false;
3067
3068         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3069         btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
3070                            &coex_sta->scan_ap_num);
3071         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3072                  "############# [BTCoex],  scan_ap_num = %d, wl_noisy = %d\n",
3073                  coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
3074
3075         if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
3076                 wifi_turbo = true;
3077
3078         wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(
3079                 btcoexist, &prewifi_rssi_state, 2, coex_sta->wifi_coex_thres,
3080                 0);
3081
3082         wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(
3083                 btcoexist, &prewifi_rssi_state2, 2, coex_sta->wifi_coex_thres2,
3084                 0);
3085
3086         bt_rssi_state = halbtc8822b2ant_bt_rssi_state(
3087                 btcoexist, &pre_bt_rssi_state, 2, coex_sta->bt_coex_thres, 0);
3088
3089         bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(
3090                 btcoexist, &pre_bt_rssi_state2, 2, coex_sta->bt_coex_thres2, 0);
3091
3092         if (BTC_RSSI_HIGH(wifi_rssi_state) && BTC_RSSI_HIGH(bt_rssi_state)) {
3093                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3094                 /*halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);*/
3095
3096                 coex_dm->is_switch_to_1dot5_ant = false;
3097
3098                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3099
3100                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3101         } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
3102                    BTC_RSSI_HIGH(bt_rssi_state2)) {
3103                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
3104                 /*halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);*/
3105
3106                 coex_dm->is_switch_to_1dot5_ant = false;
3107
3108                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3109
3110                 if (wifi_busy) {
3111                         if ((coex_sta->a2dp_bit_pool > 40) &&
3112                             (coex_sta->a2dp_bit_pool < 255))
3113                                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3114                                                         true, 7);
3115                         else
3116                                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3117                                                         true, 5);
3118                 } else {
3119                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3120                                                 6);
3121                 }
3122         } else {
3123                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3124                 /*halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);*/
3125
3126                 coex_dm->is_switch_to_1dot5_ant = true;
3127
3128                 if (wifi_turbo)
3129                         halbtc8822b2ant_coex_table_with_type(btcoexist,
3130                                                              NORMAL_EXEC, 6);
3131                 else
3132                         halbtc8822b2ant_coex_table_with_type(btcoexist,
3133                                                              NORMAL_EXEC, 7);
3134
3135                 if (wifi_busy) {
3136                         if ((coex_sta->a2dp_bit_pool > 40) &&
3137                             (coex_sta->a2dp_bit_pool < 255))
3138                                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3139                                                         true, 107);
3140                         else
3141                                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3142                                                         true, 105);
3143                 } else {
3144                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3145                                                 106);
3146                 }
3147         }
3148 }
3149
3150 /* PAN(EDR)+A2DP */
3151 static void halbtc8822b2ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist)
3152 {
3153         struct rtl_priv *rtlpriv = btcoexist->adapter;
3154         static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3155         static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3156         u8 wifi_rssi_state, bt_rssi_state;
3157
3158         static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3159         static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3160         u8 wifi_rssi_state2, bt_rssi_state2;
3161         bool wifi_busy = false, wifi_turbo = false;
3162
3163         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3164         btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
3165                            &coex_sta->scan_ap_num);
3166         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3167                  "############# [BTCoex],  scan_ap_num = %d, wl_noisy = %d\n",
3168                  coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
3169
3170         if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
3171                 wifi_turbo = true;
3172
3173         wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(
3174                 btcoexist, &prewifi_rssi_state, 2, coex_sta->wifi_coex_thres,
3175                 0);
3176
3177         wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(
3178                 btcoexist, &prewifi_rssi_state2, 2, coex_sta->wifi_coex_thres2,
3179                 0);
3180
3181         bt_rssi_state = halbtc8822b2ant_bt_rssi_state(
3182                 btcoexist, &pre_bt_rssi_state, 2, coex_sta->bt_coex_thres, 0);
3183
3184         bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(
3185                 btcoexist, &pre_bt_rssi_state2, 2, coex_sta->bt_coex_thres2, 0);
3186
3187         if (BTC_RSSI_HIGH(wifi_rssi_state) && BTC_RSSI_HIGH(bt_rssi_state)) {
3188                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3189                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3190
3191                 coex_dm->is_switch_to_1dot5_ant = false;
3192
3193                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3194                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3195         } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
3196                    BTC_RSSI_HIGH(bt_rssi_state2)) {
3197                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
3198                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3199
3200                 coex_dm->is_switch_to_1dot5_ant = false;
3201
3202                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3203
3204                 if (wifi_busy) {
3205                         if (((coex_sta->a2dp_bit_pool > 40) &&
3206                              (coex_sta->a2dp_bit_pool < 255)) ||
3207                             (!coex_sta->is_A2DP_3M))
3208                                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3209                                                         true, 7);
3210                         else
3211                                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3212                                                         true, 5);
3213                 } else {
3214                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3215                                                 6);
3216                 }
3217         } else {
3218                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3219                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3220
3221                 coex_dm->is_switch_to_1dot5_ant = true;
3222
3223                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3224                 if (wifi_busy)
3225                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3226                                                 107);
3227                 else
3228                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3229                                                 106);
3230         }
3231 }
3232
3233 static void halbtc8822b2ant_action_pan_edr_hid(struct btc_coexist *btcoexist)
3234 {
3235         static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3236         static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3237         u8 wifi_rssi_state, bt_rssi_state;
3238
3239         static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3240         static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3241         u8 wifi_rssi_state2, bt_rssi_state2;
3242         bool wifi_busy = false;
3243         u32 wifi_bw = 1;
3244
3245         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3246
3247         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3248
3249         wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(
3250                 btcoexist, &prewifi_rssi_state, 2, coex_sta->wifi_coex_thres,
3251                 0);
3252
3253         wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(
3254                 btcoexist, &prewifi_rssi_state2, 2, coex_sta->wifi_coex_thres2,
3255                 0);
3256
3257         bt_rssi_state = halbtc8822b2ant_bt_rssi_state(
3258                 btcoexist, &pre_bt_rssi_state, 2, coex_sta->bt_coex_thres, 0);
3259
3260         bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(
3261                 btcoexist, &pre_bt_rssi_state2, 2, coex_sta->bt_coex_thres2, 0);
3262
3263         if (BTC_RSSI_HIGH(wifi_rssi_state) && BTC_RSSI_HIGH(bt_rssi_state)) {
3264                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3265                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3266
3267                 coex_dm->is_switch_to_1dot5_ant = false;
3268
3269                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3270                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3271         } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
3272                    BTC_RSSI_HIGH(bt_rssi_state2)) {
3273                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
3274                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
3275
3276                 coex_dm->is_switch_to_1dot5_ant = false;
3277
3278                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3279
3280                 if (wifi_busy)
3281                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3282                                                 3);
3283                 else
3284                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3285                                                 4);
3286         } else {
3287                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3288                 halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
3289
3290                 coex_dm->is_switch_to_1dot5_ant = true;
3291
3292                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8);
3293
3294                 if (wifi_busy)
3295                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3296                                                 103);
3297                 else
3298                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3299                                                 104);
3300         }
3301 }
3302
3303 /* HID+A2DP+PAN(EDR) */
3304 static void
3305 halbtc8822b2ant_action_hid_a2dp_pan_edr(struct btc_coexist *btcoexist)
3306 {
3307         static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3308         static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3309         u8 wifi_rssi_state, bt_rssi_state;
3310
3311         static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3312         static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3313         u8 wifi_rssi_state2, bt_rssi_state2;
3314         bool wifi_busy = false;
3315         u32 wifi_bw = 1;
3316
3317         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
3318
3319         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3320
3321         wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(
3322                 btcoexist, &prewifi_rssi_state, 2, coex_sta->wifi_coex_thres,
3323                 0);
3324
3325         wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(
3326                 btcoexist, &prewifi_rssi_state2, 2, coex_sta->wifi_coex_thres2,
3327                 0);
3328
3329         bt_rssi_state = halbtc8822b2ant_bt_rssi_state(
3330                 btcoexist, &pre_bt_rssi_state, 2, coex_sta->bt_coex_thres, 0);
3331
3332         bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(
3333                 btcoexist, &pre_bt_rssi_state2, 2, coex_sta->bt_coex_thres2, 0);
3334
3335         if (BTC_RSSI_HIGH(wifi_rssi_state) && BTC_RSSI_HIGH(bt_rssi_state)) {
3336                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3337
3338                 coex_dm->is_switch_to_1dot5_ant = false;
3339
3340                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3341                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3342         } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
3343                    BTC_RSSI_HIGH(bt_rssi_state2)) {
3344                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
3345
3346                 coex_dm->is_switch_to_1dot5_ant = false;
3347
3348                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
3349
3350                 if (wifi_busy) {
3351                         if (((coex_sta->a2dp_bit_pool > 40) &&
3352                              (coex_sta->a2dp_bit_pool < 255)) ||
3353                             (!coex_sta->is_A2DP_3M))
3354                                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3355                                                         true, 7);
3356                         else
3357                                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3358                                                         true, 5);
3359                 } else {
3360                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3361                                                 6);
3362                 }
3363         } else {
3364                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3365
3366                 coex_dm->is_switch_to_1dot5_ant = true;
3367
3368                 if (coex_sta->hid_busy_num >= 2) {
3369                         halbtc8822b2ant_coex_table_with_type(btcoexist,
3370                                                              NORMAL_EXEC, 8);
3371
3372                         if (wifi_bw == 0) {
3373                                 halbtc8822b2ant_set_wltoggle_coex_table(
3374                                         btcoexist, NORMAL_EXEC, 0x1, 0xaa, 0x5a,
3375                                         0xaa, 0xaa);
3376                         } else {
3377                                 halbtc8822b2ant_set_wltoggle_coex_table(
3378                                         btcoexist, NORMAL_EXEC, 0x2, 0xaa, 0x5a,
3379                                         0xaa, 0xaa);
3380                         }
3381                         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
3382                                                 110);
3383                 } else {
3384                         halbtc8822b2ant_coex_table_with_type(btcoexist,
3385                                                              NORMAL_EXEC, 1);
3386
3387                         if (wifi_busy) {
3388                                 if ((coex_sta->a2dp_bit_pool > 40) &&
3389                                     (coex_sta->a2dp_bit_pool < 255))
3390                                         halbtc8822b2ant_ps_tdma(btcoexist,
3391                                                                 NORMAL_EXEC,
3392                                                                 true, 107);
3393                                 else
3394                                         halbtc8822b2ant_ps_tdma(btcoexist,
3395                                                                 NORMAL_EXEC,
3396                                                                 true, 105);
3397                         } else {
3398                                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
3399                                                         true, 106);
3400                         }
3401                 }
3402         }
3403 }
3404
3405 static void halbtc8822b2ant_action_bt_whck_test(struct btc_coexist *btcoexist)
3406 {
3407         halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3408
3409         halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3410
3411         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3412 }
3413
3414 static void halbtc8822b2ant_action_bt_hs(struct btc_coexist *btcoexist)
3415 {
3416         struct rtl_priv *rtlpriv = btcoexist->adapter;
3417         static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
3418         static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
3419         u8 wifi_rssi_state, bt_rssi_state;
3420
3421         static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
3422         static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
3423         u8 wifi_rssi_state2, bt_rssi_state2;
3424         bool wifi_busy = false, wifi_turbo = false;
3425
3426         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3427         btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
3428                            &coex_sta->scan_ap_num);
3429         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3430                  "############# [BTCoex],  scan_ap_num = %d, wl_noisy = %d\n",
3431                  coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
3432
3433         if ((wifi_busy) && (coex_sta->wl_noisy_level == 0))
3434                 wifi_turbo = true;
3435
3436         wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(
3437                 btcoexist, &prewifi_rssi_state, 2, coex_sta->wifi_coex_thres,
3438                 0);
3439
3440         wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(
3441                 btcoexist, &prewifi_rssi_state2, 2, coex_sta->wifi_coex_thres2,
3442                 0);
3443
3444         bt_rssi_state = halbtc8822b2ant_bt_rssi_state(
3445                 btcoexist, &pre_bt_rssi_state, 2, coex_sta->bt_coex_thres, 0);
3446
3447         bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(
3448                 btcoexist, &pre_bt_rssi_state2, 2, coex_sta->bt_coex_thres2, 0);
3449
3450         if (BTC_RSSI_HIGH(wifi_rssi_state) && BTC_RSSI_HIGH(bt_rssi_state)) {
3451                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3452
3453                 coex_dm->is_switch_to_1dot5_ant = false;
3454
3455                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3456
3457                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3458         } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
3459                    BTC_RSSI_HIGH(bt_rssi_state2)) {
3460                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
3461
3462                 coex_dm->is_switch_to_1dot5_ant = false;
3463
3464                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3465
3466                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3467
3468         } else {
3469                 halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3470
3471                 coex_dm->is_switch_to_1dot5_ant = true;
3472
3473                 halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3474
3475                 halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3476         }
3477 }
3478
3479 static void
3480 halbtc8822b2ant_action_wifi_multi_port(struct btc_coexist *btcoexist)
3481 {
3482         halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3483
3484         /* hw all off */
3485         halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
3486
3487         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3488 }
3489
3490 static void halbtc8822b2ant_action_wifi_connected(struct btc_coexist *btcoexist)
3491 {
3492         struct rtl_priv *rtlpriv = btcoexist->adapter;
3493
3494         switch (coex_dm->cur_algorithm) {
3495         case BT_8822B_2ANT_COEX_ALGO_SCO:
3496                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3497                          "[BTCoex], Action 2-Ant, algorithm = SCO.\n");
3498                 halbtc8822b2ant_action_sco(btcoexist);
3499                 break;
3500         case BT_8822B_2ANT_COEX_ALGO_HID:
3501                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3502                          "[BTCoex], Action 2-Ant, algorithm = HID.\n");
3503                 halbtc8822b2ant_action_hid(btcoexist);
3504                 break;
3505         case BT_8822B_2ANT_COEX_ALGO_A2DP:
3506                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3507                          "[BTCoex], Action 2-Ant, algorithm = A2DP.\n");
3508                 halbtc8822b2ant_action_a2dp(btcoexist);
3509                 break;
3510         case BT_8822B_2ANT_COEX_ALGO_A2DPSINK:
3511                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3512                          "[BTCoex], Action 2-Ant, algorithm = A2DP Sink.\n");
3513                 halbtc8822b2ant_action_a2dpsink(btcoexist);
3514                 break;
3515         case BT_8822B_2ANT_COEX_ALGO_A2DP_PANHS:
3516                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3517                          "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n");
3518                 halbtc8822b2ant_action_a2dp_pan_hs(btcoexist);
3519                 break;
3520         case BT_8822B_2ANT_COEX_ALGO_PANEDR:
3521                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3522                          "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n");
3523                 halbtc8822b2ant_action_pan_edr(btcoexist);
3524                 break;
3525         case BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP:
3526                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3527                          "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n");
3528                 halbtc8822b2ant_action_pan_edr_a2dp(btcoexist);
3529                 break;
3530         case BT_8822B_2ANT_COEX_ALGO_PANEDR_HID:
3531                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3532                          "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n");
3533                 halbtc8822b2ant_action_pan_edr_hid(btcoexist);
3534                 break;
3535         case BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
3536                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3537                          "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n");
3538                 halbtc8822b2ant_action_hid_a2dp_pan_edr(btcoexist);
3539                 break;
3540         case BT_8822B_2ANT_COEX_ALGO_HID_A2DP:
3541                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3542                          "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n");
3543                 halbtc8822b2ant_action_hid_a2dp(btcoexist);
3544                 break;
3545         case BT_8822B_2ANT_COEX_ALGO_NOPROFILEBUSY:
3546                 RT_TRACE(
3547                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3548                         "[BTCoex], Action 2-Ant, algorithm = No-Profile busy.\n");
3549                 halbtc8822b2ant_action_bt_idle(btcoexist);
3550                 break;
3551         default:
3552                 RT_TRACE(
3553                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3554                         "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
3555                 halbtc8822b2ant_action_coex_all_off(btcoexist);
3556                 break;
3557         }
3558
3559         coex_dm->pre_algorithm = coex_dm->cur_algorithm;
3560 }
3561
3562 static void halbtc8822b2ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
3563 {
3564         struct rtl_priv *rtlpriv = btcoexist->adapter;
3565         u8 algorithm = 0;
3566         u32 num_of_wifi_link = 0;
3567         u32 wifi_link_status = 0;
3568         struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3569         bool miracast_plus_bt = false;
3570         bool scan = false, link = false, roam = false, under_4way = false,
3571              wifi_connected = false, wifi_under_5g = false, bt_hs_on = false;
3572
3573         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
3574         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
3575         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
3576         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
3577                            &under_4way);
3578
3579         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3580                  "[BTCoex], RunCoexistMechanism()===>\n");
3581
3582         if (btcoexist->manual_control) {
3583                 RT_TRACE(
3584                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3585                         "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
3586                 return;
3587         }
3588
3589         if (btcoexist->stop_coex_dm) {
3590                 RT_TRACE(
3591                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3592                         "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
3593                 return;
3594         }
3595
3596         if (coex_sta->under_ips) {
3597                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3598                          "[BTCoex], wifi is under IPS !!!\n");
3599                 return;
3600         }
3601
3602         if ((coex_sta->under_lps) &&
3603             (coex_dm->bt_status != BT_8822B_2ANT_BT_STATUS_ACL_BUSY)) {
3604                 RT_TRACE(
3605                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3606                         "[BTCoex], RunCoexistMechanism(), wifi is under LPS !!!\n");
3607                 halbtc8822b2ant_action_wifi_native_lps(btcoexist);
3608                 return;
3609         }
3610
3611         if (!coex_sta->run_time_state) {
3612                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3613                          "[BTCoex], return for run_time_state = false !!!\n");
3614                 return;
3615         }
3616
3617         if (coex_sta->freeze_coexrun_by_btinfo) {
3618                 RT_TRACE(
3619                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3620                         "[BTCoex], BtInfoNotify(), return for freeze_coexrun_by_btinfo\n");
3621                 return;
3622         }
3623
3624         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
3625
3626         if ((wifi_under_5g) &&
3627             (coex_sta->switch_band_notify_to != BTC_SWITCH_TO_24G) &&
3628             (coex_sta->switch_band_notify_to != BTC_SWITCH_TO_24G_NOFORSCAN)) {
3629                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3630                          "[BTCoex], WiFi is under 5G!!!\n");
3631
3632                 halbtc8822b2ant_action_wifi_under5g(btcoexist);
3633                 return;
3634         }
3635
3636         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3637                  "[BTCoex], WiFi is under 2G!!!\n");
3638
3639         halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
3640                                      BT_8822B_2ANT_PHASE_2G_RUNTIME);
3641
3642         if (coex_sta->bt_whck_test) {
3643                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3644                          "[BTCoex], BT is under WHCK TEST!!!\n");
3645                 halbtc8822b2ant_action_bt_whck_test(btcoexist);
3646                 return;
3647         }
3648
3649         if (coex_sta->bt_disabled) {
3650                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3651                          "[BTCoex], BT is disabled!!!\n");
3652                 halbtc8822b2ant_action_coex_all_off(btcoexist);
3653                 return;
3654         }
3655
3656         if (coex_sta->c2h_bt_inquiry_page) {
3657                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3658                          "[BTCoex], BT is under inquiry/page scan !!\n");
3659                 halbtc8822b2ant_action_bt_inquiry(btcoexist);
3660                 return;
3661         }
3662
3663         if (coex_sta->is_setup_link) {
3664                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3665                          "[BTCoex], BT is re-link !!!\n");
3666                 halbtc8822b2ant_action_bt_relink(btcoexist);
3667                 return;
3668         }
3669
3670         /* for P2P */
3671         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
3672                            &wifi_link_status);
3673         num_of_wifi_link = wifi_link_status >> 16;
3674
3675         if ((num_of_wifi_link >= 2) ||
3676             (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
3677                 RT_TRACE(
3678                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3679                         "############# [BTCoex],  Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
3680                         num_of_wifi_link, wifi_link_status);
3681
3682                 if (bt_link_info->bt_link_exist)
3683                         miracast_plus_bt = true;
3684                 else
3685                         miracast_plus_bt = false;
3686
3687                 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3688                                    &miracast_plus_bt);
3689
3690                 if (scan || link || roam || under_4way) {
3691                         RT_TRACE(
3692                                 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3693                                 "[BTCoex], scan = %d, link = %d, roam = %d 4way = %d!!!\n",
3694                                 scan, link, roam, under_4way);
3695
3696                         RT_TRACE(
3697                                 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3698                                 "[BTCoex], wifi is under linkscan process + Multi-Port !!\n");
3699
3700                         halbtc8822b2ant_action_wifi_link_process(btcoexist);
3701                 } else {
3702                         halbtc8822b2ant_action_wifi_multi_port(btcoexist);
3703                 }
3704
3705                 return;
3706         }
3707
3708         miracast_plus_bt = false;
3709         btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
3710                            &miracast_plus_bt);
3711
3712         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
3713
3714         if (bt_hs_on) {
3715                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3716                          "############# [BTCoex],  BT Is hs\n");
3717                 halbtc8822b2ant_action_bt_hs(btcoexist);
3718                 return;
3719         }
3720
3721         if ((BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
3722              coex_dm->bt_status) ||
3723             (coex_dm->bt_status == BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE)) {
3724                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3725                          "[BTCoex], Action 2-Ant, bt idle!!.\n");
3726
3727                 halbtc8822b2ant_action_bt_idle(btcoexist);
3728                 return;
3729         }
3730
3731         algorithm = halbtc8822b2ant_action_algorithm(btcoexist);
3732         coex_dm->cur_algorithm = algorithm;
3733         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3734                  "[BTCoex], Algorithm = %d\n", coex_dm->cur_algorithm);
3735
3736         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3737                            &wifi_connected);
3738
3739         if (scan || link || roam || under_4way) {
3740                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3741                          "[BTCoex], WiFi is under Link Process !!\n");
3742                 halbtc8822b2ant_action_wifi_link_process(btcoexist);
3743         } else if (wifi_connected) {
3744                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3745                          "[BTCoex], Action 2-Ant, wifi connected!!.\n");
3746                 halbtc8822b2ant_action_wifi_connected(btcoexist);
3747
3748         } else {
3749                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3750                          "[BTCoex], Action 2-Ant, wifi not-connected!!.\n");
3751                 halbtc8822b2ant_action_wifi_nonconnected(btcoexist);
3752         }
3753 }
3754
3755 static void halbtc8822b2ant_init_coex_dm(struct btc_coexist *btcoexist)
3756 {
3757         struct rtl_priv *rtlpriv = btcoexist->adapter;
3758
3759         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3760                  "[BTCoex], Coex Mechanism Init!!\n");
3761
3762         halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false);
3763
3764         halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
3765
3766         /* fw all off */
3767         halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3768
3769         halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
3770
3771         coex_sta->pop_event_cnt = 0;
3772         coex_sta->cnt_remote_name_req = 0;
3773         coex_sta->cnt_reinit = 0;
3774         coex_sta->cnt_setup_link = 0;
3775         coex_sta->cnt_ign_wlan_act = 0;
3776         coex_sta->cnt_page = 0;
3777         coex_sta->cnt_role_switch = 0;
3778         coex_sta->switch_band_notify_to = BTC_NOT_SWITCH;
3779
3780         halbtc8822b2ant_query_bt_info(btcoexist);
3781 }
3782
3783 static void halbtc8822b2ant_init_hw_config(struct btc_coexist *btcoexist,
3784                                            bool wifi_only)
3785 {
3786         struct rtl_priv *rtlpriv = btcoexist->adapter;
3787         u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
3788         u32 RTL97F_8822B = 0;
3789         u8 i = 0;
3790
3791         u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
3792         u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
3793         u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
3794
3795         if (RTL97F_8822B) {
3796                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, 0x04, 0x0);
3797                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x0);
3798
3799                 /* set GNT_BT to SW high */
3800                 halbtc8822b2ant_ltecoex_set_gnt_bt(
3801                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
3802                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
3803                         BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
3804                 /* Set GNT_WL to SW high */
3805                 halbtc8822b2ant_ltecoex_set_gnt_wl(
3806                         btcoexist, BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
3807                         BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
3808                         BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
3809                 return;
3810         }
3811
3812         RT_TRACE(
3813                 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3814                 "[BTCoex], (Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
3815                 u32tmp3, u32tmp1, u32tmp2);
3816
3817         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3818                  "[BTCoex], 2Ant Init HW Config!!\n");
3819
3820         coex_sta->bt_coex_supported_feature = 0;
3821         coex_sta->bt_coex_supported_version = 0;
3822         coex_sta->bt_ble_scan_type = 0;
3823         coex_sta->bt_ble_scan_para[0] = 0;
3824         coex_sta->bt_ble_scan_para[1] = 0;
3825         coex_sta->bt_ble_scan_para[2] = 0;
3826         coex_sta->bt_reg_vendor_ac = 0xffff;
3827         coex_sta->bt_reg_vendor_ae = 0xffff;
3828         coex_sta->isolation_btween_wb = BT_8822B_2ANT_DEFAULT_ISOLATION;
3829         coex_sta->gnt_error_cnt = 0;
3830         coex_sta->bt_relink_downcount = 0;
3831         coex_sta->is_set_ps_state_fail = false;
3832         coex_sta->cnt_set_ps_state_fail = 0;
3833
3834         for (i = 0; i <= 9; i++)
3835                 coex_sta->bt_afh_map[i] = 0;
3836
3837         /* 0xf0[15:12] --> Chip Cut information */
3838         coex_sta->cut_version =
3839                 (btcoexist->btc_read_1byte(btcoexist, 0xf1) & 0xf0) >> 4;
3840
3841         coex_sta->dis_ver_info_cnt = 0;
3842
3843         halbtc8822b2ant_coex_switch_threshold(btcoexist,
3844                                               coex_sta->isolation_btween_wb);
3845
3846         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
3847                                            0x1); /* enable TBTT nterrupt */
3848
3849         /* BT report packet sample rate  */
3850         btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5);
3851
3852         /* Init 0x778 = 0x1 for 2-Ant */
3853         btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
3854
3855         /* Enable PTA (3-wire function form BT side) */
3856         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
3857         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1);
3858
3859         /* Enable PTA (tx/rx signal form WiFi side) */
3860         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1);
3861
3862         halbtc8822b2ant_enable_gnt_to_gpio(btcoexist, true);
3863
3864         /*GNT_BT=1 while select both */
3865         btcoexist->btc_write_1byte_bitmask(btcoexist, 0x763, 0x10, 0x1);
3866
3867         /* check if WL firmware download ok */
3868         halbtc8822b2ant_post_state_to_bt(btcoexist,
3869                                          BT_8822B_2ANT_SCOREBOARD_ONOFF, true);
3870
3871         /* Enable counter statistics */
3872         btcoexist->btc_write_1byte(
3873                 btcoexist, 0x76e,
3874                 0x4); /* 0x76e[3] =1, WLAN_Act control by PTA */
3875
3876         halbtc8822b2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 5);
3877
3878         halbtc8822b2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3879
3880         psd_scan->ant_det_is_ant_det_available = true;
3881
3882         if (coex_sta->is_rf_state_off) {
3883                 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3884                                              FORCE_EXEC,
3885                                              BT_8822B_2ANT_PHASE_WLAN_OFF);
3886
3887                 btcoexist->stop_coex_dm = true;
3888
3889                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3890                          "[BTCoex], **********  %s (RF Off)**********\n",
3891                          __func__);
3892         } else if (wifi_only) {
3893                 coex_sta->concurrent_rx_mode_on = false;
3894                 /* Path config   */
3895                 /* Set Antenna Path */
3896                 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3897                                              FORCE_EXEC,
3898                                              BT_8822B_2ANT_PHASE_WLANONLY_INIT);
3899
3900                 btcoexist->stop_coex_dm = true;
3901         } else {
3902                 /* Set BT polluted packet on for Tx rate adaptive not including
3903                  * Tx retry break by PTA, 0x45c[19] =1
3904                  */
3905                 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
3906
3907                 coex_sta->concurrent_rx_mode_on = true;
3908
3909                 /* RF 0x1[1] = 0->Set GNT_WL_RF_Rx always = 1 for
3910                  * con-current Rx, mask Tx only
3911                  */
3912                 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0x2, 0x0);
3913
3914                 /* Set Antenna Path */
3915                 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
3916                                              FORCE_EXEC,
3917                                              BT_8822B_2ANT_PHASE_COEX_INIT);
3918
3919                 btcoexist->stop_coex_dm = false;
3920         }
3921 }
3922
3923 /* ************************************************************
3924  * work around function start with wa_halbtc8822b2ant_
3925  * ************************************************************
3926  * ************************************************************
3927  * extern function start with ex_halbtc8822b2ant_
3928  * *************************************************************/
3929 void ex_btc8822b2ant_power_on_setting(struct btc_coexist *btcoexist)
3930 {
3931         struct rtl_priv *rtlpriv = btcoexist->adapter;
3932         struct btc_board_info *board_info = &btcoexist->board_info;
3933         u8 u8tmp = 0x0;
3934         u16 u16tmp = 0x0;
3935
3936         RT_TRACE(
3937                 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3938                 "xxxxxxxxxxxxxxxx Execute 8822b 2-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n");
3939
3940         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3941                  "Ant Det Finish = %s, Ant Det Number  = %d\n",
3942                  (board_info->btdm_ant_det_finish ? "Yes" : "No"),
3943                  board_info->btdm_ant_num_by_ant_det);
3944
3945         btcoexist->dbg_mode_2ant = false;
3946         btcoexist->stop_coex_dm = true;
3947         psd_scan->ant_det_is_ant_det_available = false;
3948
3949         /* enable BB, REG_SYS_FUNC_EN such that we can write BB Reg correctly */
3950         u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
3951         btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
3952
3953         /* Local setting bit define */
3954         /*      BIT0: "0" for no antenna inverse; "1" for antenna inverse  */
3955         /*      BIT1: "0" for internal switch; "1" for external switch */
3956         /*      BIT2: "0" for one antenna; "1" for two antenna */
3957         /* NOTE: here default all internal switch and 1-antenna ==>
3958          * BIT1=0 and BIT2=0
3959          */
3960
3961         /* Check efuse 0xc3[6] for Single Antenna Path */
3962
3963         /* Setup RF front end type */
3964         halbtc8822b2ant_set_rfe_type(btcoexist);
3965
3966         /* Set Antenna Path to BT side */
3967         halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
3968                                      BT_8822B_2ANT_PHASE_COEX_POWERON);
3969
3970         /* Save"single antenna position" info in Local register setting for
3971          * FW reading, because FW may not ready at power on
3972          */
3973         if (btcoexist->chip_interface == BTC_INTF_PCI)
3974                 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, u8tmp);
3975         else if (btcoexist->chip_interface == BTC_INTF_USB)
3976                 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
3977         else if (btcoexist->chip_interface == BTC_INTF_SDIO)
3978                 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp);
3979
3980         /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */
3981         halbtc8822b2ant_enable_gnt_to_gpio(btcoexist, true);
3982
3983         RT_TRACE(
3984                 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3985                 "[BTCoex], **********  LTE coex Reg 0x38 (Power-On) = 0x%x**********\n",
3986                 halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38));
3987
3988         RT_TRACE(
3989                 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3990                 "[BTCoex], **********  MAC Reg 0x70/ BB Reg 0xcb4 (Power-On) = 0x%x / 0x%x\n",
3991                 btcoexist->btc_read_4byte(btcoexist, 0x70),
3992                 btcoexist->btc_read_4byte(btcoexist, 0xcb4));
3993 }
3994
3995 void ex_btc8822b2ant_pre_load_firmware(struct btc_coexist *btcoexist)
3996 {
3997         struct btc_board_info *board_info = &btcoexist->board_info;
3998         u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */
3999
4000         /* */
4001         /* S0 or S1 setting and Local register setting
4002          * (By the setting fw can get ant number, S0/S1, ... info)
4003          */
4004         /* Local setting bit define */
4005         /*      BIT0: "0" for no antenna inverse; "1" for antenna inverse  */
4006         /*      BIT1: "0" for internal switch; "1" for external switch */
4007         /*      BIT2: "0" for one antenna; "1" for two antenna */
4008         /* NOTE: here default all internal switch and 1-antenna ==>
4009          *       BIT1=0 and BIT2=0
4010          */
4011         if (btcoexist->chip_interface == BTC_INTF_USB) {
4012                 /* fixed at S0 for USB interface */
4013                 u8tmp |= 0x1; /* antenna inverse */
4014                 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
4015         } else {
4016                 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
4017                 if (board_info->single_ant_path == 0) {
4018                 } else if (board_info->single_ant_path == 1) {
4019                         /* set to S0 */
4020                         u8tmp |= 0x1; /* antenna inverse */
4021                 }
4022
4023                 if (btcoexist->chip_interface == BTC_INTF_PCI)
4024                         btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0,
4025                                                              u8tmp);
4026                 else if (btcoexist->chip_interface == BTC_INTF_SDIO)
4027                         btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60,
4028                                                              u8tmp);
4029         }
4030 }
4031
4032 void ex_btc8822b2ant_init_hw_config(struct btc_coexist *btcoexist,
4033                                     bool wifi_only)
4034 {
4035         halbtc8822b2ant_init_hw_config(btcoexist, wifi_only);
4036         btcoexist->auto_report_2ant = true;
4037 }
4038
4039 void ex_btc8822b2ant_init_coex_dm(struct btc_coexist *btcoexist)
4040 {
4041         halbtc8822b2ant_init_coex_dm(btcoexist);
4042 }
4043
4044 void ex_btc8822b2ant_display_coex_info(struct btc_coexist *btcoexist,
4045                                        struct seq_file *m)
4046 {
4047         struct btc_board_info *board_info = &btcoexist->board_info;
4048         struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
4049
4050         u8 u8tmp[4], i, ps_tdma_case = 0;
4051         u32 u32tmp[4];
4052         u16 u16tmp[4];
4053         u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck, ratio_ofdm;
4054         u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0;
4055         static u8 pop_report_in_10s;
4056         u32 phyver = 0;
4057         bool lte_coex_on = false;
4058         static u8 cnt;
4059
4060         seq_puts(m, "\r\n ============[BT Coexist info]============");
4061
4062         if (btcoexist->manual_control) {
4063                 seq_puts(m,
4064                          "\r\n ============[Under Manual Control]============");
4065                 seq_puts(m, "\r\n ==========================================");
4066         }
4067
4068         if (!coex_sta->bt_disabled) {
4069                 if (coex_sta->bt_coex_supported_feature == 0)
4070                         btcoexist->btc_get(
4071                                 btcoexist, BTC_GET_U4_SUPPORTED_FEATURE,
4072                                 &coex_sta->bt_coex_supported_feature);
4073
4074                 if ((coex_sta->bt_coex_supported_version == 0) ||
4075                     (coex_sta->bt_coex_supported_version == 0xffff))
4076                         btcoexist->btc_get(
4077                                 btcoexist, BTC_GET_U4_SUPPORTED_VERSION,
4078                                 &coex_sta->bt_coex_supported_version);
4079
4080                 if (coex_sta->bt_reg_vendor_ac == 0xffff)
4081                         coex_sta->bt_reg_vendor_ac = (u16)(
4082                                 btcoexist->btc_get_bt_reg(btcoexist, 3, 0xac) &
4083                                 0xffff);
4084
4085                 if (coex_sta->bt_reg_vendor_ae == 0xffff)
4086                         coex_sta->bt_reg_vendor_ae = (u16)(
4087                                 btcoexist->btc_get_bt_reg(btcoexist, 3, 0xae) &
4088                                 0xffff);
4089
4090                 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
4091                                    &bt_patch_ver);
4092                 btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
4093
4094                 if (coex_sta->num_of_profile > 0) {
4095                         cnt++;
4096
4097                         if (cnt >= 3) {
4098                                 btcoexist->btc_get_bt_afh_map_from_bt(
4099                                         btcoexist, 0, &coex_sta->bt_afh_map[0]);
4100                                 cnt = 0;
4101                         }
4102                 }
4103         }
4104
4105         if (psd_scan->ant_det_try_count == 0) {
4106                 seq_printf(
4107                         m, "\r\n %-35s = %d/ %d/ %s / %d",
4108                         "Ant PG Num/ Mech/ Pos/ RFE", board_info->pg_ant_num,
4109                         board_info->btdm_ant_num,
4110                         (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT ?
4111                                  "Main" :
4112                                  "Aux"),
4113                         rfe_type->rfe_module_type);
4114         } else {
4115                 seq_printf(
4116                         m, "\r\n %-35s = %d/ %d/ %s/ %d  (%d/%d/%d)",
4117                         "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
4118                         board_info->pg_ant_num,
4119                         board_info->btdm_ant_num_by_ant_det,
4120                         (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT ?
4121                                  "Main" :
4122                                  "Aux"),
4123                         rfe_type->rfe_module_type, psd_scan->ant_det_try_count,
4124                         psd_scan->ant_det_fail_count, psd_scan->ant_det_result);
4125
4126                 if (board_info->btdm_ant_det_finish) {
4127                         if (psd_scan->ant_det_result != 12)
4128                                 seq_printf(m, "\r\n %-35s = %s",
4129                                            "Ant Det PSD Value",
4130                                            psd_scan->ant_det_peak_val);
4131                         else
4132                                 seq_printf(m, "\r\n %-35s = %d",
4133                                            "Ant Det PSD Value",
4134                                            psd_scan->ant_det_psd_scan_peak_val /
4135                                                    100);
4136                 }
4137         }
4138
4139         bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
4140         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
4141         phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
4142
4143         bt_coex_ver = (coex_sta->bt_coex_supported_version & 0xff);
4144
4145         seq_printf(
4146                 m, "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
4147                 "CoexVer WL/  BT_Desired/ BT_Report",
4148                 glcoex_ver_date_8822b_2ant, glcoex_ver_8822b_2ant,
4149                 glcoex_ver_btdesired_8822b_2ant, bt_coex_ver,
4150                 (bt_coex_ver == 0xff ?
4151                          "Unknown" :
4152                          (coex_sta->bt_disabled ?  "BT-disable" :
4153                           (bt_coex_ver >= glcoex_ver_btdesired_8822b_2ant ?
4154                                            "Match" :
4155                                            "Mis-Match"))));
4156
4157         seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", "W_FW/ B_FW/ Phy/ Kt",
4158                    fw_ver, bt_patch_ver, phyver, coex_sta->cut_version + 65);
4159
4160         seq_printf(m, "\r\n %-35s = %02x %02x %02x ", "AFH Map to BT",
4161                    coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
4162                    coex_dm->wifi_chnl_info[2]);
4163
4164         seq_printf(m, "\r\n %-35s = %d / %d / %d ",
4165                    "Isolation/WL_Thres/BT_Thres", coex_sta->isolation_btween_wb,
4166                    coex_sta->wifi_coex_thres, coex_sta->bt_coex_thres);
4167
4168         /* wifi status */
4169         seq_printf(m, "\r\n %-35s", "============[Wifi Status]============");
4170         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS, m);
4171
4172         seq_printf(m, "\r\n %-35s", "============[BT Status]============");
4173
4174         pop_report_in_10s++;
4175         seq_printf(
4176                 m, "\r\n %-35s = [%s/ %d dBm/ %d/ %d] ",
4177                 "BT [status/ rssi/ retryCnt/ popCnt]",
4178                 ((coex_sta->bt_disabled) ?
4179                          ("disabled") :
4180                          ((coex_sta->c2h_bt_inquiry_page) ?  ("inquiry/page") :
4181                           ((BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
4182                             coex_dm->bt_status) ?
4183                                    "non-connected idle" :
4184                                    ((coex_dm->bt_status ==
4185                                      BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE) ?
4186                                             "connected-idle" :
4187                                             "busy")))),
4188                 coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
4189                 coex_sta->pop_event_cnt);
4190
4191         if (pop_report_in_10s >= 5) {
4192                 coex_sta->pop_event_cnt = 0;
4193                 pop_report_in_10s = 0;
4194         }
4195
4196         if (coex_sta->num_of_profile != 0)
4197                 seq_printf(
4198                         m, "\r\n %-35s = %s%s%s%s%s", "Profiles",
4199                         ((bt_link_info->a2dp_exist) ?
4200                                  ((coex_sta->is_bt_a2dp_sink) ? "A2DP sink," :
4201                                                                 "A2DP,") :
4202                                  ""),
4203                         ((bt_link_info->sco_exist) ? "HFP," : ""),
4204                         ((bt_link_info->hid_exist) ?
4205                                  ((coex_sta->hid_busy_num >= 2) ?
4206                                           "HID(4/18)," :
4207                                           "HID(2/18),") :
4208                                  ""),
4209                         ((bt_link_info->pan_exist) ? "PAN," : ""),
4210                         ((coex_sta->voice_over_HOGP) ? "Voice" : ""));
4211         else
4212                 seq_printf(m, "\r\n %-35s = None", "Profiles");
4213
4214         if (bt_link_info->a2dp_exist) {
4215                 seq_printf(m, "\r\n %-35s = %s/ %d/ %s",
4216                            "A2DP Rate/Bitpool/Auto_Slot",
4217                            ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"),
4218                            coex_sta->a2dp_bit_pool,
4219                            ((coex_sta->is_autoslot) ? "On" : "Off"));
4220         }
4221
4222         if (bt_link_info->hid_exist) {
4223                 seq_printf(m, "\r\n %-35s = %d/ %d", "HID PairNum/Forbid_Slot",
4224                            coex_sta->hid_pair_cnt, coex_sta->forbidden_slot);
4225         }
4226
4227         seq_printf(m, "\r\n %-35s = %s/ %d/ %s/ 0x%x",
4228                    "Role/RoleSwCnt/IgnWlact/Feature",
4229                    ((bt_link_info->slave_role) ? "Slave" : "Master"),
4230                    coex_sta->cnt_role_switch,
4231                    ((coex_dm->cur_ignore_wlan_act) ? "Yes" : "No"),
4232                    coex_sta->bt_coex_supported_feature);
4233
4234         if ((coex_sta->bt_ble_scan_type & 0x7) != 0x0) {
4235                 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4236                            "BLEScan Type/TV/Init/Ble",
4237                            coex_sta->bt_ble_scan_type,
4238                            (coex_sta->bt_ble_scan_type & 0x1 ?
4239                                     coex_sta->bt_ble_scan_para[0] :
4240                                     0x0),
4241                            (coex_sta->bt_ble_scan_type & 0x2 ?
4242                                     coex_sta->bt_ble_scan_para[1] :
4243                                     0x0),
4244                            (coex_sta->bt_ble_scan_type & 0x4 ?
4245                                     coex_sta->bt_ble_scan_para[2] :
4246                                     0x0));
4247         }
4248
4249         seq_printf(m, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
4250                    "ReInit/ReLink/IgnWlact/Page/NameReq", coex_sta->cnt_reinit,
4251                    coex_sta->cnt_setup_link, coex_sta->cnt_ign_wlan_act,
4252                    coex_sta->cnt_page, coex_sta->cnt_remote_name_req);
4253
4254         halbtc8822b2ant_read_score_board(btcoexist, &u16tmp[0]);
4255
4256         if ((coex_sta->bt_reg_vendor_ae == 0xffff) ||
4257             (coex_sta->bt_reg_vendor_ac == 0xffff))
4258                 seq_printf(m, "\r\n %-35s = x/ x/ %04x",
4259                            "0xae[4]/0xac[1:0]/Scoreboard", u16tmp[0]);
4260         else
4261                 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ %04x",
4262                            "0xae[4]/0xac[1:0]/Scoreboard",
4263                            (int)((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4),
4264                            coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]);
4265
4266         if (coex_sta->num_of_profile > 0) {
4267                 seq_printf(
4268                         m,
4269                         "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
4270                         "AFH MAP", coex_sta->bt_afh_map[0],
4271                         coex_sta->bt_afh_map[1], coex_sta->bt_afh_map[2],
4272                         coex_sta->bt_afh_map[3], coex_sta->bt_afh_map[4],
4273                         coex_sta->bt_afh_map[5], coex_sta->bt_afh_map[6],
4274                         coex_sta->bt_afh_map[7], coex_sta->bt_afh_map[8],
4275                         coex_sta->bt_afh_map[9]);
4276         }
4277
4278         for (i = 0; i < BT_INFO_SRC_8822B_2ANT_MAX; i++) {
4279                 if (coex_sta->bt_info_c2h_cnt[i]) {
4280                         seq_printf(
4281                                 m,
4282                                 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
4283                                 glbt_info_src_8822b_2ant[i],
4284                                 coex_sta->bt_info_c2h[i][0],
4285                                 coex_sta->bt_info_c2h[i][1],
4286                                 coex_sta->bt_info_c2h[i][2],
4287                                 coex_sta->bt_info_c2h[i][3],
4288                                 coex_sta->bt_info_c2h[i][4],
4289                                 coex_sta->bt_info_c2h[i][5],
4290                                 coex_sta->bt_info_c2h[i][6],
4291                                 coex_sta->bt_info_c2h_cnt[i]);
4292                 }
4293         }
4294
4295         /* Sw mechanism  */
4296         if (btcoexist->manual_control)
4297                 seq_printf(
4298                         m, "\r\n %-35s",
4299                         "============[mechanism] (before Manual)============");
4300         else
4301                 seq_printf(m, "\r\n %-35s",
4302                            "============[Mechanism]============");
4303
4304         ps_tdma_case = coex_dm->cur_ps_tdma;
4305
4306         seq_printf(m, "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s, %s)",
4307                    "TDMA", coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
4308                    coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
4309                    coex_dm->ps_tdma_para[4], ps_tdma_case,
4310                    (coex_dm->cur_ps_tdma_on ? "TDMA On" : "TDMA Off"),
4311                    (coex_dm->is_switch_to_1dot5_ant ? "1.5Ant" : "2Ant"));
4312
4313         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
4314         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
4315         u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
4316         seq_printf(m, "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x",
4317                    "Table/0x6c0/0x6c4/0x6c8", coex_sta->coex_table_type,
4318                    u32tmp[0], u32tmp[1], u32tmp[2]);
4319
4320         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
4321         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
4322         seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x", "0x778/0x6cc", u8tmp[0],
4323                    u32tmp[0]);
4324
4325         seq_printf(m, "\r\n %-35s = %s/ %s/ %s/ %d",
4326                    "AntDiv/BtCtrlLPS/LPRA/PsFail",
4327                    ((board_info->ant_div_cfg) ? "On" : "Off"),
4328                    ((coex_sta->force_lps_ctrl) ? "On" : "Off"),
4329                    ((coex_dm->cur_low_penalty_ra) ? "On" : "Off"),
4330                    coex_sta->cnt_set_ps_state_fail);
4331
4332         seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x", "WL_DACSwing/ BT_Dec_Pwr",
4333                    coex_dm->cur_fw_dac_swing_lvl, coex_dm->cur_bt_dec_pwr_lvl);
4334
4335         u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
4336         lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? true : false;
4337
4338         if (lte_coex_on) {
4339                 u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4340                                                                       0xa0);
4341                 u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4342                                                                       0xa4);
4343                 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x",
4344                            "LTE Coex Table W_L/B_L", u32tmp[0] & 0xffff,
4345                            u32tmp[1] & 0xffff);
4346
4347                 u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4348                                                                       0xa8);
4349                 u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4350                                                                       0xac);
4351                 u32tmp[2] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4352                                                                       0xb0);
4353                 u32tmp[3] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
4354                                                                       0xb4);
4355                 seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4356                            "LTE Break Table W_L/B_L/L_W/L_B",
4357                            u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
4358                            u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
4359         }
4360
4361         /* Hw setting            */
4362         seq_printf(m, "\r\n %-35s", "============[Hw setting]============");
4363
4364         u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
4365         u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
4366         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73);
4367
4368         seq_printf(m, "\r\n %-35s = %s/ %s", "LTE Coex/Path Owner",
4369                    ((lte_coex_on) ? "On" : "Off"),
4370                    ((u8tmp[0] & BIT(2)) ? "WL" : "BT"));
4371
4372         if (lte_coex_on) {
4373                 seq_printf(m, "\r\n %-35s = %d/ %d/ %d/ %d",
4374                            "LTE 3Wire/OPMode/UART/UARTMode",
4375                            (int)((u32tmp[0] & BIT(6)) >> 6),
4376                            (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
4377                            (int)((u32tmp[0] & BIT(3)) >> 3),
4378                            (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
4379
4380                 seq_printf(m, "\r\n %-35s = %d/ %d", "LTE_Busy/UART_Busy",
4381                            (int)((u32tmp[1] & BIT(1)) >> 1),
4382                            (int)(u32tmp[1] & BIT(0)));
4383         }
4384         seq_printf(m, "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s %d",
4385                    "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg",
4386                    ((u32tmp[0] & BIT(12)) ? "SW" : "HW"),
4387                    ((u32tmp[0] & BIT(8)) ? "SW" : "HW"),
4388                    ((u32tmp[0] & BIT(14)) ? "SW" : "HW"),
4389                    ((u32tmp[0] & BIT(10)) ? "SW" : "HW"),
4390                    ((u8tmp[0] & BIT(3)) ? "On" : "Off"),
4391                    coex_sta->gnt_error_cnt);
4392
4393         seq_printf(m, "\r\n %-35s = %d/ %d", "GNT_WL/GNT_BT",
4394                    (int)((u32tmp[1] & BIT(2)) >> 2),
4395                    (int)((u32tmp[1] & BIT(3)) >> 3));
4396
4397         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcbc);
4398         u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
4399         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcba);
4400
4401         seq_printf(m, "\r\n %-35s = 0x%04x/ 0x%04x/ 0x%02x %s",
4402                    "0xcbc/0xcb4/0xcb8[23:16]", u32tmp[0], u32tmp[1], u8tmp[0],
4403                    ((u8tmp[0] & 0x1) == 0x1 ? "(BTG)" : "(WL_A+G)"));
4404
4405         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
4406         u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
4407         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6);
4408         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
4409
4410         seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4411                    "4c[24:23]/64[0]/4c6[4]/40[5]",
4412                    (int)(u32tmp[0] & (BIT(24) | BIT(23))) >> 23, u8tmp[2] & 0x1,
4413                    (int)((u8tmp[0] & BIT(4)) >> 4),
4414                    (int)((u8tmp[1] & BIT(5)) >> 5));
4415
4416         u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
4417         u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
4418         u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953);
4419         u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50);
4420
4421         seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x",
4422                    "0x550/0x522/4-RxAGC/0xc50", u32tmp[0], u8tmp[0],
4423                    (u8tmp[1] & 0x2) ? "On" : "Off", u8tmp[2]);
4424
4425         fa_ofdm = btcoexist->btc_phydm_query_phy_counter(btcoexist,
4426                                                          "PHYDM_INFO_FA_OFDM");
4427         fa_cck = btcoexist->btc_phydm_query_phy_counter(btcoexist,
4428                                                         "PHYDM_INFO_FA_CCK");
4429         cca_ofdm = btcoexist->btc_phydm_query_phy_counter(
4430                 btcoexist, "PHYDM_INFO_CCA_OFDM");
4431         cca_cck = btcoexist->btc_phydm_query_phy_counter(btcoexist,
4432                                                          "PHYDM_INFO_CCA_CCK");
4433
4434         ratio_ofdm = (fa_ofdm == 0) ? 1000 : (cca_ofdm / fa_ofdm);
4435
4436         seq_printf(m, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x  (%d)",
4437                    "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", cca_cck, fa_cck, cca_ofdm,
4438                    fa_ofdm, ratio_ofdm);
4439
4440         seq_printf(m, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11ac",
4441                    coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
4442                    coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
4443
4444         seq_printf(m, "\r\n %-35s = %d/ %d/ %d/ %d  (%d, %d)",
4445                    "CRC_Err CCK/11g/11n/11ac", coex_sta->crc_err_cck,
4446                    coex_sta->crc_err_11g, coex_sta->crc_err_11n,
4447                    coex_sta->crc_err_11n_vht, coex_sta->now_crc_ratio,
4448                    coex_sta->acc_crc_ratio);
4449
4450         seq_printf(m, "\r\n %-35s = %s/ %s/ %s/ %d",
4451                    "WlHiPri/ Locking/ Locked/ Noisy",
4452                    (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"),
4453                    (coex_sta->cck_lock ? "Yes" : "No"),
4454                    (coex_sta->cck_ever_lock ? "Yes" : "No"),
4455                    coex_sta->wl_noisy_level);
4456
4457         seq_printf(m, "\r\n %-35s = %d/ %d", "0x770(Hi-pri rx/tx)",
4458                    coex_sta->high_priority_rx, coex_sta->high_priority_tx);
4459
4460         seq_printf(m, "\r\n %-35s = %d/ %d %s", "0x774(Lo-pri rx/tx)",
4461                    coex_sta->low_priority_rx, coex_sta->low_priority_tx,
4462                    (bt_link_info->slave_role ?
4463                             "(Slave!!)" :
4464                             (coex_sta->is_tdma_btautoslot_hang ?
4465                                      "(auto-slot hang!!)" :
4466                                      "")));
4467
4468         btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS, m);
4469 }
4470
4471 void ex_btc8822b2ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
4472 {
4473         struct rtl_priv *rtlpriv = btcoexist->adapter;
4474
4475         if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4476                 return;
4477
4478         if (type == BTC_IPS_ENTER) {
4479                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4480                          "[BTCoex], IPS ENTER notify\n");
4481                 coex_sta->under_ips = true;
4482                 coex_sta->under_lps = false;
4483
4484                 halbtc8822b2ant_post_state_to_bt(
4485                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE, false);
4486
4487                 halbtc8822b2ant_post_state_to_bt(
4488                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ONOFF, false);
4489
4490                 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4491                                              FORCE_EXEC,
4492                                              BT_8822B_2ANT_PHASE_WLAN_OFF);
4493
4494                 halbtc8822b2ant_action_coex_all_off(btcoexist);
4495         } else if (type == BTC_IPS_LEAVE) {
4496                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4497                          "[BTCoex], IPS LEAVE notify\n");
4498                 coex_sta->under_ips = false;
4499
4500                 halbtc8822b2ant_post_state_to_bt(
4501                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
4502                 halbtc8822b2ant_post_state_to_bt(
4503                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ONOFF, true);
4504                 halbtc8822b2ant_init_hw_config(btcoexist, false);
4505                 halbtc8822b2ant_init_coex_dm(btcoexist);
4506                 halbtc8822b2ant_query_bt_info(btcoexist);
4507         }
4508 }
4509
4510 void ex_btc8822b2ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
4511 {
4512         struct rtl_priv *rtlpriv = btcoexist->adapter;
4513         static bool pre_force_lps_on;
4514
4515         if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4516                 return;
4517
4518         if (type == BTC_LPS_ENABLE) {
4519                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4520                          "[BTCoex], LPS ENABLE notify\n");
4521                 coex_sta->under_lps = true;
4522                 coex_sta->under_ips = false;
4523
4524                 if (coex_sta->force_lps_ctrl) { /* LPS No-32K */
4525                         /* Write WL "Active" in Score-board for PS-TDMA */
4526                         pre_force_lps_on = true;
4527                         halbtc8822b2ant_post_state_to_bt(
4528                                 btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE,
4529                                 true);
4530
4531                 } else {
4532                         /* LPS-32K, need check if this h2c 0x71 can work??
4533                          * (2015/08/28)
4534                          */
4535                         /* Write WL "Non-Active" in Score-board for Native-PS */
4536                         pre_force_lps_on = false;
4537                         halbtc8822b2ant_post_state_to_bt(
4538                                 btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE,
4539                                 false);
4540                 }
4541
4542         } else if (type == BTC_LPS_DISABLE) {
4543                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4544                          "[BTCoex], LPS DISABLE notify\n");
4545                 coex_sta->under_lps = false;
4546
4547                 halbtc8822b2ant_post_state_to_bt(
4548                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
4549
4550                 if ((!pre_force_lps_on) && (!coex_sta->force_lps_ctrl))
4551                         halbtc8822b2ant_query_bt_info(btcoexist);
4552         }
4553 }
4554
4555 void ex_btc8822b2ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
4556 {
4557         struct rtl_priv *rtlpriv = btcoexist->adapter;
4558         bool wifi_connected = false;
4559         bool wifi_under_5g = false;
4560
4561         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4562                  "[BTCoex], SCAN notify()\n");
4563
4564         halbtc8822b2ant_post_state_to_bt(btcoexist,
4565                                          BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
4566
4567         if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4568                 return;
4569
4570         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
4571                            &wifi_connected);
4572
4573         /* this can't be removed for RF off_on event, or BT would dis-connect */
4574         halbtc8822b2ant_query_bt_info(btcoexist);
4575
4576         if (type == BTC_SCAN_START) {
4577                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
4578                                    &wifi_under_5g);
4579
4580                 if (wifi_under_5g) {
4581                         RT_TRACE(
4582                                 rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4583                                 "[BTCoex], ********** SCAN START notify (5g)\n");
4584
4585                         halbtc8822b2ant_action_wifi_under5g(btcoexist);
4586                         return;
4587                 }
4588
4589                 coex_sta->wifi_is_high_pri_task = true;
4590
4591                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4592                          "[BTCoex], ********** SCAN START notify (2g)\n");
4593
4594                 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
4595
4596                 return;
4597         }
4598
4599         if (type == BTC_SCAN_START_2G) {
4600                 if (!wifi_connected)
4601                         coex_sta->wifi_is_high_pri_task = true;
4602
4603                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4604                          "[BTCoex], SCAN START notify (2G)\n");
4605
4606                 halbtc8822b2ant_post_state_to_bt(
4607                         btcoexist, BT_8822B_2ANT_SCOREBOARD_SCAN, true);
4608                 halbtc8822b2ant_post_state_to_bt(
4609                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
4610
4611                 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4612                                              FORCE_EXEC,
4613                                              BT_8822B_2ANT_PHASE_2G_RUNTIME);
4614
4615                 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
4616
4617         } else if (type == BTC_SCAN_FINISH) {
4618                 coex_sta->wifi_is_high_pri_task = false;
4619
4620                 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
4621                                    &coex_sta->scan_ap_num);
4622
4623                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4624                          "[BTCoex], SCAN FINISH notify  (Scan-AP = %d)\n",
4625                          coex_sta->scan_ap_num);
4626
4627                 halbtc8822b2ant_post_state_to_bt(
4628                         btcoexist, BT_8822B_2ANT_SCOREBOARD_SCAN, false);
4629
4630                 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
4631         }
4632 }
4633
4634 void ex_btc8822b2ant_switchband_notify(struct btc_coexist *btcoexist, u8 type)
4635 {
4636         struct rtl_priv *rtlpriv = btcoexist->adapter;
4637
4638         if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4639                 return;
4640         coex_sta->switch_band_notify_to = type;
4641
4642         if (type == BTC_SWITCH_TO_5G) {
4643                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4644                          "[BTCoex], switchband_notify ---  switch to 5G\n");
4645
4646                 halbtc8822b2ant_action_wifi_under5g(btcoexist);
4647
4648         } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
4649                 RT_TRACE(
4650                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4651                         "[BTCoex], ********** switchband_notify BTC_SWITCH_TO_2G (no for scan)\n");
4652
4653                 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
4654
4655         } else {
4656                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4657                          "[BTCoex], switchband_notify ---  switch to 2G\n");
4658
4659                 ex_btc8822b2ant_scan_notify(btcoexist, BTC_SCAN_START_2G);
4660         }
4661         coex_sta->switch_band_notify_to = BTC_NOT_SWITCH;
4662 }
4663
4664 void ex_btc8822b2ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
4665 {
4666         struct rtl_priv *rtlpriv = btcoexist->adapter;
4667
4668         halbtc8822b2ant_post_state_to_bt(btcoexist,
4669                                          BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
4670         if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4671                 return;
4672
4673         if ((type == BTC_ASSOCIATE_5G_START) ||
4674             (type == BTC_ASSOCIATE_5G_FINISH)) {
4675                 if (type == BTC_ASSOCIATE_5G_START)
4676                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4677                                  "[BTCoex], connect_notify ---  5G start\n");
4678                 else
4679                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4680                                  "[BTCoex], connect_notify ---  5G finish\n");
4681
4682                 halbtc8822b2ant_action_wifi_under5g(btcoexist);
4683                 return;
4684         }
4685
4686         if (type == BTC_ASSOCIATE_START) {
4687                 coex_sta->wifi_is_high_pri_task = true;
4688
4689                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4690                          "[BTCoex], CONNECT START notify (2G)\n");
4691
4692                 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4693                                              FORCE_EXEC,
4694                                              BT_8822B_2ANT_PHASE_2G_RUNTIME);
4695
4696                 halbtc8822b2ant_action_wifi_link_process(btcoexist);
4697
4698                 /* To keep TDMA case during connect process,
4699                  * to avoid changed by Btinfo and runcoexmechanism
4700                  */
4701                 coex_sta->freeze_coexrun_by_btinfo = true;
4702
4703                 coex_dm->arp_cnt = 0;
4704
4705         } else if (type == BTC_ASSOCIATE_FINISH) {
4706                 coex_sta->wifi_is_high_pri_task = false;
4707                 coex_sta->freeze_coexrun_by_btinfo = false;
4708
4709                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4710                          "[BTCoex], CONNECT FINISH notify       (2G)\n");
4711
4712                 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
4713         }
4714 }
4715
4716 void ex_btc8822b2ant_media_status_notify(struct btc_coexist *btcoexist, u8 type)
4717 {
4718         struct rtl_priv *rtlpriv = btcoexist->adapter;
4719         bool wifi_under_b_mode = false, wifi_under_5g = false;
4720
4721         if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4722                 return;
4723
4724         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4725
4726         if (type == BTC_MEDIA_CONNECT) {
4727                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4728                          "[BTCoex], MEDIA connect notify\n");
4729
4730                 halbtc8822b2ant_post_state_to_bt(
4731                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
4732
4733                 if (wifi_under_5g) {
4734                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4735                                  "[BTCoex], WiFi is under 5G!!!\n");
4736
4737                         halbtc8822b2ant_action_wifi_under5g(btcoexist);
4738                         return;
4739                 }
4740
4741                 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
4742                                              FORCE_EXEC,
4743                                              BT_8822B_2ANT_PHASE_2G_RUNTIME);
4744
4745                 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
4746                                    &wifi_under_b_mode);
4747
4748                 /* Set CCK Tx/Rx high Pri except 11b mode */
4749                 if (wifi_under_b_mode) {
4750                         btcoexist->btc_write_1byte(btcoexist, 0x6cd,
4751                                                    0x00); /* CCK Tx */
4752                         btcoexist->btc_write_1byte(btcoexist, 0x6cf,
4753                                                    0x00); /* CCK Rx */
4754                 } else {
4755                         btcoexist->btc_write_1byte(btcoexist, 0x6cd,
4756                                                    0x00); /* CCK Tx */
4757                         btcoexist->btc_write_1byte(btcoexist, 0x6cf,
4758                                                    0x10); /* CCK Rx */
4759                 }
4760
4761         } else {
4762                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4763                          "[BTCoex], MEDIA disconnect notify\n");
4764
4765                 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
4766                 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
4767
4768                 halbtc8822b2ant_post_state_to_bt(
4769                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE, false);
4770         }
4771
4772         halbtc8822b2ant_update_wifi_ch_info(btcoexist, type);
4773 }
4774
4775 void ex_btc8822b2ant_specific_packet_notify(struct btc_coexist *btcoexist,
4776                                             u8 type)
4777 {
4778         struct rtl_priv *rtlpriv = btcoexist->adapter;
4779         bool under_4way = false, wifi_under_5g = false;
4780
4781         if (btcoexist->manual_control || btcoexist->stop_coex_dm)
4782                 return;
4783
4784         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
4785
4786         if (wifi_under_5g) {
4787                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4788                          "[BTCoex], WiFi is under 5G!!!\n");
4789
4790                 halbtc8822b2ant_action_wifi_under5g(btcoexist);
4791                 return;
4792         }
4793
4794         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
4795                            &under_4way);
4796
4797         if (under_4way) {
4798                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4799                          "[BTCoex], specific Packet ---- under_4way!!\n");
4800
4801                 coex_sta->wifi_is_high_pri_task = true;
4802                 coex_sta->specific_pkt_period_cnt = 2;
4803
4804         } else if (type == BTC_PACKET_ARP) {
4805                 coex_dm->arp_cnt++;
4806                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4807                          "[BTCoex], specific Packet ARP notify -cnt = %d\n",
4808                          coex_dm->arp_cnt);
4809
4810         } else {
4811                 RT_TRACE(
4812                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4813                         "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n",
4814                         type);
4815
4816                 coex_sta->wifi_is_high_pri_task = true;
4817                 coex_sta->specific_pkt_period_cnt = 2;
4818         }
4819
4820         if (coex_sta->wifi_is_high_pri_task)
4821                 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
4822 }
4823
4824 void ex_btc8822b2ant_bt_info_notify(struct btc_coexist *btcoexist, u8 *tmp_buf,
4825                                     u8 length)
4826 {
4827         struct rtl_priv *rtlpriv = btcoexist->adapter;
4828         u8 i, rsp_source = 0;
4829         bool wifi_connected = false;
4830         bool wifi_scan = false, wifi_link = false, wifi_roam = false,
4831              wifi_busy = false;
4832         static bool is_scoreboard_scan;
4833
4834         rsp_source = tmp_buf[0] & 0xf;
4835         if (rsp_source >= BT_INFO_SRC_8822B_2ANT_MAX)
4836                 rsp_source = BT_INFO_SRC_8822B_2ANT_WIFI_FW;
4837         coex_sta->bt_info_c2h_cnt[rsp_source]++;
4838
4839         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4840                  "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source, length);
4841
4842         for (i = 0; i < length; i++) {
4843                 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
4844
4845                 if (i == length - 1) {
4846                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4847                                  "0x%02x]\n", tmp_buf[i]);
4848                 } else {
4849                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "0x%02x, ",
4850                                  tmp_buf[i]);
4851                 }
4852         }
4853
4854         coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1];
4855         coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4];
4856         coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5];
4857
4858         if (rsp_source != BT_INFO_SRC_8822B_2ANT_WIFI_FW) {
4859                 /* if 0xff, it means BT is under WHCK test */
4860                 coex_sta->bt_whck_test =
4861                         ((coex_sta->bt_info == 0xff) ? true : false);
4862
4863                 coex_sta->bt_create_connection =
4864                         ((coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? true :
4865                                                                          false);
4866
4867                 /* unit: %, value-100 to translate to unit: dBm */
4868                 coex_sta->bt_rssi =
4869                         coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
4870
4871                 coex_sta->c2h_bt_remote_name_req =
4872                         ((coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? true :
4873                                                                          false);
4874
4875                 coex_sta->is_A2DP_3M =
4876                         ((coex_sta->bt_info_c2h[rsp_source][2] & 0x10) ? true :
4877                                                                          false);
4878
4879                 coex_sta->acl_busy =
4880                         ((coex_sta->bt_info_c2h[rsp_source][1] & 0x9) ? true :
4881                                                                         false);
4882
4883                 coex_sta->voice_over_HOGP =
4884                         ((coex_sta->bt_info_ext & 0x10) ? true : false);
4885
4886                 coex_sta->c2h_bt_inquiry_page =
4887                         ((coex_sta->bt_info & BT_INFO_8822B_2ANT_B_INQ_PAGE) ?
4888                                  true :
4889                                  false);
4890
4891                 coex_sta->a2dp_bit_pool =
4892                         (((coex_sta->bt_info_c2h[rsp_source][1] & 0x49) ==
4893                           0x49) ?
4894                                  (coex_sta->bt_info_c2h[rsp_source][6] & 0x7f) :
4895                                  0);
4896
4897                 coex_sta->is_bt_a2dp_sink =
4898                         (coex_sta->bt_info_c2h[rsp_source][6] & 0x80) ? true :
4899                                                                         false;
4900
4901                 coex_sta->bt_retry_cnt =
4902                         coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
4903
4904                 coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8;
4905
4906                 coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7;
4907
4908                 coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4;
4909
4910                 coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6;
4911
4912                 if (coex_sta->bt_retry_cnt >= 1)
4913                         coex_sta->pop_event_cnt++;
4914
4915                 if (coex_sta->c2h_bt_remote_name_req)
4916                         coex_sta->cnt_remote_name_req++;
4917
4918                 if (coex_sta->bt_info_ext & BIT(1))
4919                         coex_sta->cnt_reinit++;
4920
4921                 if (coex_sta->bt_info_ext & BIT(2)) {
4922                         coex_sta->cnt_setup_link++;
4923                         coex_sta->is_setup_link = true;
4924                         coex_sta->bt_relink_downcount = 2;
4925                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4926                                  "[BTCoex], Re-Link start in BT info!!\n");
4927                 } else {
4928                         coex_sta->is_setup_link = false;
4929                         coex_sta->bt_relink_downcount = 0;
4930                         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4931                                  "[BTCoex], Re-Link stop in BT info!!\n");
4932                 }
4933
4934                 if (coex_sta->bt_info_ext & BIT(3))
4935                         coex_sta->cnt_ign_wlan_act++;
4936
4937                 if (coex_sta->bt_info_ext & BIT(6))
4938                         coex_sta->cnt_role_switch++;
4939
4940                 if (coex_sta->bt_info_ext & BIT(7))
4941                         coex_sta->is_bt_multi_link = true;
4942                 else
4943                         coex_sta->is_bt_multi_link = false;
4944
4945                 if (coex_sta->bt_create_connection) {
4946                         coex_sta->cnt_page++;
4947
4948                         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY,
4949                                            &wifi_busy);
4950
4951                         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN,
4952                                            &wifi_scan);
4953                         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK,
4954                                            &wifi_link);
4955                         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM,
4956                                            &wifi_roam);
4957
4958                         if ((wifi_link) || (wifi_roam) || (wifi_scan) ||
4959                             (coex_sta->wifi_is_high_pri_task) || (wifi_busy)) {
4960                                 is_scoreboard_scan = true;
4961                                 halbtc8822b2ant_post_state_to_bt(
4962                                         btcoexist,
4963                                         BT_8822B_2ANT_SCOREBOARD_SCAN, true);
4964
4965                         } else {
4966                                 halbtc8822b2ant_post_state_to_bt(
4967                                         btcoexist,
4968                                         BT_8822B_2ANT_SCOREBOARD_SCAN, false);
4969                         }
4970                 } else {
4971                         if (is_scoreboard_scan) {
4972                                 halbtc8822b2ant_post_state_to_bt(
4973                                         btcoexist,
4974                                         BT_8822B_2ANT_SCOREBOARD_SCAN, false);
4975                                 is_scoreboard_scan = false;
4976                         }
4977                 }
4978
4979                 /* Here we need to resend some wifi info to BT */
4980                 /* because bt is reset and loss of the info. */
4981
4982                 if ((!btcoexist->manual_control) &&
4983                     (!btcoexist->stop_coex_dm)) {
4984                         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
4985                                            &wifi_connected);
4986
4987                         /*  Re-Init */
4988                         if ((coex_sta->bt_info_ext & BIT(1))) {
4989                                 RT_TRACE(
4990                                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
4991                                         "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
4992                                 if (wifi_connected)
4993                                         halbtc8822b2ant_update_wifi_ch_info(
4994                                                 btcoexist, BTC_MEDIA_CONNECT);
4995                                 else
4996                                         halbtc8822b2ant_update_wifi_ch_info(
4997                                                 btcoexist,
4998                                                 BTC_MEDIA_DISCONNECT);
4999                         }
5000
5001                         /*  If Ignore_WLanAct && not SetUp_Link */
5002                         if ((coex_sta->bt_info_ext & BIT(3)) &&
5003                             (!(coex_sta->bt_info_ext & BIT(2))) &&
5004                             (!(coex_sta->bt_info_ext & BIT(6)))) {
5005                                 RT_TRACE(
5006                                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5007                                         "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
5008                                 halbtc8822b2ant_ignore_wlan_act(
5009                                         btcoexist, FORCE_EXEC, false);
5010                         } else {
5011                                 if (coex_sta->bt_info_ext & BIT(2)) {
5012                                         RT_TRACE(
5013                                                 rtlpriv, COMP_BT_COEXIST,
5014                                                 DBG_LOUD,
5015                                                 "[BTCoex], BT ignore Wlan active because Re-link!!\n");
5016                                 } else if (coex_sta->bt_info_ext & BIT(6)) {
5017                                         RT_TRACE(
5018                                                 rtlpriv, COMP_BT_COEXIST,
5019                                                 DBG_LOUD,
5020                                                 "[BTCoex], BT ignore Wlan active because Role-Switch!!\n");
5021                                 }
5022                         }
5023                 }
5024         }
5025
5026         if ((coex_sta->bt_info_ext & BIT(5))) {
5027                 RT_TRACE(
5028                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5029                         "[BTCoex], BT ext info bit4 check, query BLE Scan type!!\n");
5030                 coex_sta->bt_ble_scan_type =
5031                         btcoexist->btc_get_ble_scan_type_from_bt(btcoexist);
5032
5033                 if ((coex_sta->bt_ble_scan_type & 0x1) == 0x1)
5034                         coex_sta->bt_ble_scan_para[0] =
5035                                 btcoexist->btc_get_ble_scan_para_from_bt(
5036                                         btcoexist, 0x1);
5037                 if ((coex_sta->bt_ble_scan_type & 0x2) == 0x2)
5038                         coex_sta->bt_ble_scan_para[1] =
5039                                 btcoexist->btc_get_ble_scan_para_from_bt(
5040                                         btcoexist, 0x2);
5041                 if ((coex_sta->bt_ble_scan_type & 0x4) == 0x4)
5042                         coex_sta->bt_ble_scan_para[2] =
5043                                 btcoexist->btc_get_ble_scan_para_from_bt(
5044                                         btcoexist, 0x4);
5045         }
5046
5047         halbtc8822b2ant_update_bt_link_info(btcoexist);
5048
5049         halbtc8822b2ant_run_coexist_mechanism(btcoexist);
5050 }
5051
5052 void ex_btc8822b2ant_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
5053 {
5054         struct rtl_priv *rtlpriv = btcoexist->adapter;
5055
5056         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5057                  "[BTCoex], RF Status notify\n");
5058
5059         if (type == BTC_RF_ON) {
5060                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5061                          "[BTCoex], RF is turned ON!!\n");
5062
5063                 btcoexist->stop_coex_dm = false;
5064                 coex_sta->is_rf_state_off = false;
5065         } else if (type == BTC_RF_OFF) {
5066                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5067                          "[BTCoex], RF is turned OFF!!\n");
5068
5069                 halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
5070                                              FORCE_EXEC,
5071                                              BT_8822B_2ANT_PHASE_WLAN_OFF);
5072
5073                 halbtc8822b2ant_action_coex_all_off(btcoexist);
5074
5075                 halbtc8822b2ant_post_state_to_bt(
5076                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE |
5077                                            BT_8822B_2ANT_SCOREBOARD_ONOFF |
5078                                            BT_8822B_2ANT_SCOREBOARD_SCAN |
5079                                            BT_8822B_2ANT_SCOREBOARD_UNDERTEST,
5080                         false);
5081
5082                 btcoexist->stop_coex_dm = true;
5083                 coex_sta->is_rf_state_off = true;
5084         }
5085 }
5086
5087 void ex_btc8822b2ant_halt_notify(struct btc_coexist *btcoexist)
5088 {
5089         struct rtl_priv *rtlpriv = btcoexist->adapter;
5090
5091         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Halt notify\n");
5092
5093         halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
5094                                      BT_8822B_2ANT_PHASE_WLAN_OFF);
5095
5096         ex_btc8822b2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
5097
5098         halbtc8822b2ant_post_state_to_bt(
5099                 btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE, false);
5100         halbtc8822b2ant_post_state_to_bt(btcoexist,
5101                                          BT_8822B_2ANT_SCOREBOARD_ONOFF, false);
5102 }
5103
5104 void ex_btc8822b2ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
5105 {
5106         struct rtl_priv *rtlpriv = btcoexist->adapter;
5107         bool wifi_under_5g = false;
5108
5109         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Pnp notify\n");
5110
5111         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
5112
5113         if ((pnp_state == BTC_WIFI_PNP_SLEEP) ||
5114             (pnp_state == BTC_WIFI_PNP_SLEEP_KEEP_ANT)) {
5115                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5116                          "[BTCoex], Pnp notify to SLEEP\n");
5117
5118                 /* Sinda 20150819, workaround for driver skip leave IPS/LPS to
5119                  * speed up sleep time.
5120                  * Driver do not leave IPS/LPS when driver is going to sleep,
5121                  * so BTCoexistence think wifi is still under IPS/LPS.
5122                  * BT should clear UnderIPS/UnderLPS state to avoid mismatch
5123                  * state after wakeup.
5124                  */
5125                 coex_sta->under_ips = false;
5126                 coex_sta->under_lps = false;
5127
5128                 halbtc8822b2ant_post_state_to_bt(
5129                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE, false);
5130                 halbtc8822b2ant_post_state_to_bt(
5131                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ONOFF, false);
5132
5133                 if (pnp_state == BTC_WIFI_PNP_SLEEP_KEEP_ANT) {
5134                         if (wifi_under_5g)
5135                                 halbtc8822b2ant_set_ant_path(
5136                                         btcoexist, BTC_ANT_PATH_AUTO,
5137                                         FORCE_EXEC,
5138                                         BT_8822B_2ANT_PHASE_5G_RUNTIME);
5139                         else
5140                                 halbtc8822b2ant_set_ant_path(
5141                                         btcoexist, BTC_ANT_PATH_AUTO,
5142                                         FORCE_EXEC,
5143                                         BT_8822B_2ANT_PHASE_2G_RUNTIME);
5144                 } else {
5145                         halbtc8822b2ant_set_ant_path(
5146                                 btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
5147                                 BT_8822B_2ANT_PHASE_WLAN_OFF);
5148                 }
5149         } else if (pnp_state == BTC_WIFI_PNP_WAKE_UP) {
5150                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5151                          "[BTCoex], Pnp notify to WAKE UP\n");
5152
5153                 halbtc8822b2ant_post_state_to_bt(
5154                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
5155                 halbtc8822b2ant_post_state_to_bt(
5156                         btcoexist, BT_8822B_2ANT_SCOREBOARD_ONOFF, true);
5157         }
5158 }
5159
5160 void ex_btc8822b2ant_periodical(struct btc_coexist *btcoexist)
5161 {
5162         struct rtl_priv *rtlpriv = btcoexist->adapter;
5163         bool wifi_busy = false;
5164         u16 bt_scoreboard_val = 0;
5165         bool bt_relink_finish = false;
5166
5167         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5168                  "[BTCoex], ************* Periodical *************\n");
5169
5170         if (!btcoexist->auto_report_2ant)
5171                 halbtc8822b2ant_query_bt_info(btcoexist);
5172
5173         halbtc8822b2ant_monitor_bt_ctr(btcoexist);
5174         halbtc8822b2ant_monitor_wifi_ctr(btcoexist);
5175         halbtc8822b2ant_monitor_bt_enable_disable(btcoexist);
5176
5177         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
5178         halbtc8822b2ant_read_score_board(btcoexist, &bt_scoreboard_val);
5179
5180         if (wifi_busy) {
5181                 halbtc8822b2ant_post_state_to_bt(
5182                         btcoexist, BT_8822B_2ANT_SCOREBOARD_UNDERTEST, true);
5183                 /*for bt lps32 clock offset*/
5184                 if (bt_scoreboard_val & BIT(6))
5185                         halbtc8822b2ant_query_bt_info(btcoexist);
5186         } else {
5187                 halbtc8822b2ant_post_state_to_bt(
5188                         btcoexist, BT_8822B_2ANT_SCOREBOARD_UNDERTEST, false);
5189         }
5190
5191         if (coex_sta->bt_relink_downcount != 0) {
5192                 coex_sta->bt_relink_downcount--;
5193
5194                 if (coex_sta->bt_relink_downcount == 0) {
5195                         coex_sta->is_setup_link = false;
5196                         bt_relink_finish = true;
5197                 }
5198         }
5199
5200         /* for 4-way, DHCP, EAPOL packet */
5201         if (coex_sta->specific_pkt_period_cnt > 0) {
5202                 coex_sta->specific_pkt_period_cnt--;
5203
5204                 if ((coex_sta->specific_pkt_period_cnt == 0) &&
5205                     (coex_sta->wifi_is_high_pri_task))
5206                         coex_sta->wifi_is_high_pri_task = false;
5207
5208                 RT_TRACE(
5209                         rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
5210                         "[BTCoex], ***************** Hi-Pri Task = %s*****************\n",
5211                         (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"));
5212         }
5213
5214         if (halbtc8822b2ant_is_wifibt_status_changed(btcoexist) ||
5215             (bt_relink_finish) || (coex_sta->is_set_ps_state_fail))
5216                 halbtc8822b2ant_run_coexist_mechanism(btcoexist);
5217 }
5218
5219 void ex_btc8822b2ant_antenna_detection(struct btc_coexist *btcoexist,
5220                                        u32 cent_freq, u32 offset, u32 span,
5221                                        u32 seconds)
5222 {
5223 }
5224
5225 void ex_btc8822b2ant_display_ant_detection(struct btc_coexist *btcoexist) {}