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