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